@sap/cds 5.7.1 → 5.7.5

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 (31) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/lib/compile/minify.js +1 -1
  3. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js +0 -6
  4. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +0 -4
  5. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +18 -8
  6. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/expandToCQN.js +7 -1
  7. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +4 -0
  8. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriTokenizer.js +3 -3
  9. package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +18 -2
  10. package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +20 -3
  11. package/libx/_runtime/cds-services/services/Service.js +1 -1
  12. package/libx/_runtime/common/generic/auth.js +3 -4
  13. package/libx/_runtime/common/i18n/messages.properties +2 -0
  14. package/libx/_runtime/common/utils/cqn2cqn4sql.js +29 -27
  15. package/libx/_runtime/common/utils/resolveView.js +1 -1
  16. package/libx/_runtime/common/utils/structured.js +1 -1
  17. package/libx/_runtime/db/data-conversion/post-processing.js +22 -22
  18. package/libx/_runtime/db/expand/expandCQNToJoin.js +19 -23
  19. package/libx/_runtime/db/query/read.js +12 -8
  20. package/libx/_runtime/fiori/generic/read.js +7 -1
  21. package/libx/_runtime/hana/localized.js +1 -1
  22. package/libx/_runtime/messaging/AMQPWebhookMessaging.js +3 -1
  23. package/libx/_runtime/messaging/message-queuing-utils/options-messaging.js +1 -0
  24. package/libx/_runtime/messaging/service.js +12 -6
  25. package/libx/_runtime/remote/utils/data.js +1 -1
  26. package/libx/_runtime/sqlite/localized.js +1 -1
  27. package/libx/gql/resolvers/parse/ast2cqn/columns.js +1 -1
  28. package/libx/odata/grammar.pegjs +53 -25
  29. package/libx/odata/index.js +6 -0
  30. package/libx/odata/parser.js +1 -1
  31. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,52 @@
4
4
  - The format is based on [Keep a Changelog](http://keepachangelog.com/).
5
5
  - This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## Version 5.7.5 - 2022-01-14
8
+
9
+ ### Fixed
10
+
11
+ - Instance-based restriction for activation of draft-enabled entities using `or` in restriction
12
+ - Messaging: Duplicate handler execution if application service registered events twice
13
+ - Post of a deeply nested sub-entity with structured parent keys
14
+ - Negating lambda expressions in OData using the `not` operator
15
+ - Event Mesh: Redelivery count when using AMQP
16
+ - OData requests using lambda expressions on localized data
17
+ - `cds.db.exists` wrongly generated a `SELECT * FROM ...` for odata flavor x4
18
+ - Return localized texts on draft activate
19
+ - Unicode characters in unquoted search terms in beta OData to CQN parser
20
+
21
+ ## Version 5.7.4 - 2021-12-22
22
+
23
+ ### Fixed
24
+
25
+ - Complex `@restrict.where: 'exists [...] or (... or ...) or ...'` in draft union scenario no longer crashes the application
26
+ - Sanitization of null values for `cds.RemoteService`
27
+ - Handling of boolean values in draft union scenario with `$expand` query option
28
+ - `_4odata` flag in CQN stays non-enumerable when forwarding to another application service
29
+ - Handling of type references on properties of associations in `cds.minify`
30
+
31
+ ## Version 5.7.3 - 2021-12-16
32
+
33
+ ### Fixed
34
+
35
+ - Message Queuing now accepts `amqp` options
36
+ - OData requests using lambda expressions with `contains` function
37
+ - Result of OData query option `$count=true` when using `$apply`
38
+ - `$filter` with navigation to-one equals value crashes
39
+ - `$skiptoken` query option allows to use arbitrary symbols except of `&` with beta OData URL to CQN parser (`cds.env.features.odata_new_parser`). In this non-integer value case the value will not be parsed into CQN.
40
+ - Function names in `$filter` can now be case insensitive (as per OData 4.01)
41
+ - `$count` in `$expand` caused server to crash
42
+
43
+ ## Version 5.7.2 - 2021-12-09
44
+
45
+ ### Fixed
46
+
47
+ - Instance-based restriction for activation of draft enabled entities
48
+ - `.columns('*')` on projections of remote services using renamed properties
49
+ - GraphQL filters on nested fields are now applied correctly
50
+ - Performance degradation during processing of `where exists`
51
+ - Read drafts via navigation with complex filter expression
52
+
7
53
  ## Version 5.7.1 - 2021-12-06
8
54
 
9
55
  ### Fixed
@@ -35,7 +35,7 @@ module.exports = function cds_minify (csn, _roots = global.cds.env.features.skip
35
35
  if (d.startsWith('cds.')) return
36
36
  else d = all[d]
37
37
  } else if (d.ref) return d.ref.reduce((p,n) => {
38
- let d = p.elements[n.id || n] // > n.id -> view with parameters
38
+ let d = (p.elements || csn.definitions[p.target].elements)[n.id || n] // > n.id -> view with parameters
39
39
  _visit(d)
40
40
  return d
41
41
  },{elements:all})
@@ -50,12 +50,6 @@ const _postProcessDraftActivate = async (req, result, service) => {
50
50
  result.HasActiveEntity = false
51
51
  result.HasDraftEntity = false
52
52
 
53
- // REVISIT: should not be necessary
54
- // remove composition and association stubs
55
- if (!cds.env.effective.odata.structs) {
56
- for (const k in req.target.elements) if (req.target.elements[k].isAssociation) delete result[k]
57
- }
58
-
59
53
  return result
60
54
  }
61
55
 
@@ -377,10 +377,6 @@ const _readAndTransform = (tx, req, odataReq) => {
377
377
  }
378
378
 
379
379
  if (_isCollection(segments)) {
380
- if (odataReq.getUriInfo().getQueryOption(QueryOptions.COUNT)) {
381
- req.query.SELECT.count = true
382
- }
383
-
384
380
  return _readCollection(tx, req, odataReq)
385
381
  }
386
382
 
@@ -58,17 +58,26 @@ class ExpressionToCQN {
58
58
  }
59
59
  }
60
60
 
61
- _lambda(pathSegments) {
61
+ _lambda(pathSegments, operator) {
62
62
  // we don't care about the variable name
63
63
  if (pathSegments[0].getKind() === 'EXPRESSION.VARIABLE') pathSegments = pathSegments.slice(1)
64
64
  const nav =
65
65
  pathSegments.length > 2 ? pathSegments.slice(0, pathSegments.length - 2).map(this._segmentFromMember) : []
66
66
  const navName = this._segmentFromMember(pathSegments[pathSegments.length - 2])
67
- const condition = this._segmentFromMember(pathSegments[pathSegments.length - 1])
67
+ let condition = this._segmentFromMember(pathSegments[pathSegments.length - 1])
68
68
 
69
- return pathSegments[pathSegments.length - 1].getKind() === 'ALL.EXPRESSION'
70
- ? ['not', 'exists', { ref: [...nav, { id: navName, where: ['not', { xpr: condition }] }] }]
71
- : ['exists', { ref: [...nav, { id: navName, where: condition }] }]
69
+ // in case of functions, condition is an object
70
+ if (condition && !Array.isArray(condition)) condition = [condition]
71
+
72
+ if (pathSegments[pathSegments.length - 1].getKind() === 'ALL.EXPRESSION') {
73
+ return [
74
+ ...(operator === 'not' ? [] : ['not']),
75
+ 'exists',
76
+ { ref: [...nav, { id: navName, where: ['not', { xpr: condition }] }] }
77
+ ]
78
+ }
79
+
80
+ return [...(operator === 'not' ? ['not'] : []), 'exists', { ref: [...nav, { id: navName, where: condition }] }]
72
81
  }
73
82
 
74
83
  _segmentFromMember(segment) {
@@ -100,6 +109,7 @@ class ExpressionToCQN {
100
109
  const name = this._segmentFromMember(segment)
101
110
  const where =
102
111
  nextSegments &&
112
+ nextSegments.length &&
103
113
  nextSegments[nextSegments.length - 1].getKind() === ResourceKind.COUNT &&
104
114
  segment.getKeyPredicates().reduce((prev, curr) => {
105
115
  if (prev.length > 0) prev.push('and')
@@ -133,14 +143,14 @@ class ExpressionToCQN {
133
143
  return [this._segmentFromMember(segment)]
134
144
  }
135
145
 
136
- _member(expression) {
146
+ _member(expression, operator) {
137
147
  const pathSegments = expression.getPathSegments()
138
148
  if (
139
149
  pathSegments.some(segment =>
140
150
  [ResourceKind.ANY_EXPRESSION, ResourceKind.ALL_EXPRESSION].includes(segment.getKind())
141
151
  )
142
152
  ) {
143
- return this._lambda(pathSegments)
153
+ return this._lambda(pathSegments, operator)
144
154
  }
145
155
 
146
156
  const members = this._getMemberRecursively(pathSegments)
@@ -305,7 +315,7 @@ class ExpressionToCQN {
305
315
  return this._convert(expression)
306
316
 
307
317
  case ExpressionKind.MEMBER:
308
- return this._member(expression)
318
+ return this._member(expression, operator)
309
319
 
310
320
  case ExpressionKind.METHOD:
311
321
  return this._method(expression, operator)
@@ -12,6 +12,8 @@ const ExpressionToCQN = require('./ExpressionToCQN')
12
12
  const { getColumns } = require('../../../services/utils/columns')
13
13
  const { addLimit, isSameArray } = require('./utils')
14
14
  const { findCsnTargetFor } = require('../../../../common/utils/csn')
15
+ const getError = require('../../../../common/error')
16
+
15
17
  /**
16
18
  * Check which element(s) of the entity has been expanded.
17
19
  *
@@ -28,7 +30,11 @@ const _getExpandItem = (isAll, expandItems, name) => {
28
30
 
29
31
  return expandItems.find(item => {
30
32
  const pathSegments = item.getPathSegments()
31
- return pathSegments[pathSegments.length - 1].getNavigationProperty().getName() === name
33
+ if (pathSegments[pathSegments.length - 1].getKind() === 'COUNT') {
34
+ throw getError(501, 'EXPAND_COUNT_UNSUPPORTED')
35
+ }
36
+ const navigation = pathSegments[pathSegments.length - 1].getNavigationProperty()
37
+ return navigation && navigation.getName() === name
32
38
  })
33
39
  }
34
40
 
@@ -184,6 +184,7 @@ const _extendCqnWithApply = (cqn, apply, entity) => {
184
184
 
185
185
  // REVISIT only execute on HANA?
186
186
  cqn.SELECT.columns = _groupByPathExpressionsToExpand(cqn, entity)
187
+ if (cqn.SELECT.count) cqn.SELECT.__countAggregated = true
187
188
  }
188
189
 
189
190
  const _containsSelectedColumn = (o, selectColumns) => {
@@ -340,6 +341,7 @@ const _handleApply = (apply, select) => {
340
341
  * @param {object} odataReq - OKRA's req
341
342
  * @private
342
343
  */
344
+ // eslint-disable-next-line complexity
343
345
  const readToCQN = (service, target, odataReq) => {
344
346
  const uriInfo = odataReq.getUriInfo()
345
347
  const segments = uriInfo.getPathSegments()
@@ -390,6 +392,8 @@ const readToCQN = (service, target, odataReq) => {
390
392
  const cqn = SELECT.from(isView ? _convertUrlPathToViewCqn(segments) : convertUrlPathToCqn(segments, service), select)
391
393
  addValidationQueryIfRequired(segments, isView, cqn, service, kind)
392
394
 
395
+ if (isCollectionOrToMany && queryOptions && queryOptions[QueryOptions.COUNT]) cqn.SELECT.count = true
396
+
393
397
  if (Object.keys(apply).length) {
394
398
  _extendCqnWithApply(cqn, apply, entity)
395
399
  }
@@ -684,8 +684,8 @@ class UriTokenizer {
684
684
  * @returns {boolean} whether the constant has been found at the current index
685
685
  * @private
686
686
  */
687
- _nextConstant (constant) {
688
- if (this._parseString.startsWith(constant, this._index)) {
687
+ _nextConstant (constant, caseInsensitive) {
688
+ if ((caseInsensitive ? this._parseString.toLowerCase() : this._parseString).startsWith(constant, this._index)) {
689
689
  this._index += constant.length
690
690
  return true
691
691
  }
@@ -784,7 +784,7 @@ class UriTokenizer {
784
784
  * @private
785
785
  */
786
786
  _nextMethod (methodName) {
787
- return this._nextConstant(methodName) && this._nextCharacter('(')
787
+ return this._nextConstant(methodName, true) && this._nextCharacter('(')
788
788
  }
789
789
 
790
790
  /**
@@ -66,10 +66,26 @@ const _getParamData = parameters => {
66
66
  return paramData
67
67
  }
68
68
 
69
+ const _flattenStructureKeys = structureData => {
70
+ const result = {}
71
+ for (const prop in structureData) {
72
+ if (typeof structureData[prop] === 'object') {
73
+ const nested = _flattenStructureKeys(structureData[prop])
74
+ for (const key in nested) {
75
+ result[prop + '_' + key] = nested[key]
76
+ }
77
+ } else {
78
+ result[prop] = structureData[prop]
79
+ }
80
+ }
81
+ return result
82
+ }
83
+
69
84
  // works only for custom on condition working on keys with '=' operator
70
85
  // and combination of multiple conditions connected with 'and'
71
86
  const _addKeysToData = (navSourceKeyValues, onCondition, data) => {
72
- for (const key in navSourceKeyValues) {
87
+ const flattenKeys = _flattenStructureKeys(navSourceKeyValues)
88
+ for (const key in flattenKeys) {
73
89
  // find index of source column
74
90
  const sourceIndex = onCondition.findIndex(e => e.ref && e.ref[0] === 'source' && e.ref[1] === key)
75
91
  if (sourceIndex === -1) {
@@ -82,7 +98,7 @@ const _addKeysToData = (navSourceKeyValues, onCondition, data) => {
82
98
  const {
83
99
  ref: [, target]
84
100
  } = onCondition[sourceIndex + 1] === '=' ? onCondition[sourceIndex + 2] : onCondition[sourceIndex - 2]
85
- data[target] = navSourceKeyValues[key]
101
+ data[target] = flattenKeys[key]
86
102
  }
87
103
  }
88
104
  }
@@ -112,6 +112,13 @@ const addAssociationToRow = (row, foreignKey, foreignKeyElement) => {
112
112
  delete row[foreignKey]
113
113
  }
114
114
 
115
+ const localizeAfterDraftActivate = (row, key, locale) => {
116
+ if (row.texts && Object.prototype.hasOwnProperty.call(row, key)) {
117
+ const texts = row.texts.filter(t => t.locale === locale)[0]
118
+ if (texts && texts[key]) row[key] = texts[key]
119
+ }
120
+ }
121
+
115
122
  const _processCategory = (category, processArgs, req, options, previousResult) => {
116
123
  const { row, key, element } = processArgs
117
124
 
@@ -136,6 +143,10 @@ const _processCategory = (category, processArgs, req, options, previousResult) =
136
143
  if (key !== 'DraftAdministrativeData_DraftUUID') delete row[key]
137
144
  break
138
145
 
146
+ case 'localizeAfterDraftActivate':
147
+ localizeAfterDraftActivate(row, key, req.locale)
148
+ break
149
+
139
150
  // no default
140
151
  }
141
152
  }
@@ -200,13 +211,18 @@ const _pick = options => (element, target, parent) => {
200
211
  if (element.type === 'cds.Decimal') categories.push('@cds.Decimal')
201
212
  categories.push(..._assocs(element, target))
202
213
  if (options.omitValuesPreference) categories.push('@odata.omitValues')
214
+ if (options.event === 'draftActivate' && options.locale && options.locale !== 'en' && element.localized === true) {
215
+ categories.push('localizeAfterDraftActivate')
216
+ }
203
217
  if (categories.length) return { categories }
204
218
  }
205
219
 
206
- const _getOptions = headers => {
220
+ const _getOptions = ({ headers, locale, event }) => {
207
221
  const options = {
208
222
  decimals: null,
209
- omitValuesPreference: null
223
+ omitValuesPreference: null,
224
+ locale,
225
+ event
210
226
  }
211
227
 
212
228
  if (!headers) return options
@@ -232,6 +248,7 @@ const _generateCacheKey = (headers, options) => {
232
248
  let key = 'postProcess' // default template cache key for post processing
233
249
  if (headers.prefer) key += `:${headers.prefer}`
234
250
  if (options.decimals) key += `:exponentialDecimals=true`
251
+ if (options.event === 'draftActivate' && options.locale) key += `:locale=${options.locale}`
235
252
  return key
236
253
  }
237
254
 
@@ -241,7 +258,7 @@ const postProcess = (req, res, service, result, previousResult) => {
241
258
 
242
259
  if (!target || !result || !model || !model.definitions[target.name]) return
243
260
 
244
- const options = _getOptions(headers)
261
+ const options = _getOptions(req)
245
262
  const cacheKey = _generateCacheKey(headers, options)
246
263
  const parent = _getParent(model, target.name)
247
264
  const template = getTemplate(cacheKey, service, target, { pick: _pick(options) }, parent)
@@ -128,7 +128,7 @@ class ApplicationService extends cds.Service {
128
128
  // compat
129
129
  restoreLink(req)
130
130
  if (req.query.SELECT && req.query.SELECT._4odata) {
131
- q.SELECT._4odata = req.query.SELECT._4odata
131
+ Object.defineProperty(q.SELECT, '_4odata', { value: req.query.SELECT._4odata })
132
132
  }
133
133
 
134
134
  // REVISIT: We need to provide target explicitly because it's cached already within ensure_target
@@ -8,7 +8,7 @@ const { SELECT } = cds.ql
8
8
  const { getRequiresAsArray } = require('../utils/auth')
9
9
  const { cqn2cqn4sql } = require('../utils/cqn2cqn4sql')
10
10
  const { isActiveEntityRequested, removeIsActiveEntityRecursively } = require('../../fiori/utils/where')
11
- const { ensureDraftsSuffix, ensureNoDraftsSuffix } = require('../../fiori/utils/handler')
11
+ const { ensureNoDraftsSuffix } = require('../../fiori/utils/handler')
12
12
  const { rewriteExpandAsterisk } = require('../../common/utils/rewriteAsterisks')
13
13
 
14
14
  const WRITE = ['CREATE', 'UPDATE', 'DELETE']
@@ -445,12 +445,11 @@ const _getUnrestrictedCount = async req => {
445
445
  const _getRestrictedCount = async (req, model, resolvedApplicables) => {
446
446
  const dbtx = cds.tx(req)
447
447
 
448
- let target =
448
+ const target =
449
449
  (req.query.UPDATE && req.query.UPDATE.entity) ||
450
450
  (req.query.DELETE && req.query.DELETE.from) ||
451
451
  (req.query.SELECT && req.query.SELECT.from)
452
- // REVISIT: req._ gets set in onDraftActivate to original req
453
- if (req._ && req._.event === 'draftActivate') target = ensureDraftsSuffix(target)
452
+
454
453
  const selectRestricted = SELECT.one(['count(*) as n']).from(target)
455
454
 
456
455
  const whereRestricted = (req.query.UPDATE && req.query.UPDATE.where) || (req.query.DELETE && req.query.DELETE.where)
@@ -73,6 +73,8 @@ ENTITY_IS_NOT_CRUD_VIA_NAVIGATION=Entity "{0}" is not {1} via association "{2}"
73
73
  ENTITY_IS_AUTOEXPOSED=Entity "{0}" is not explicitely exposed as part of the service
74
74
  EXPAND_IS_RESTRICTED=Navigation property "{0}" is not allowed for expand operation
75
75
 
76
+ EXPAND_COUNT_UNSUPPORTED="$count" is not supported for expand operation
77
+
76
78
  # rest protocol adapter
77
79
  INVALID_RESOURCE="{0}" is not a valid resource
78
80
  INVALID_PARAMETER="{0}" is not a valid parameter
@@ -396,7 +396,8 @@ const _getWhereExistsSubSelect = (cqn, where, index, model, options) => {
396
396
  }
397
397
  }
398
398
  // skip for where: [{ val: 1 }]
399
- if (condition.length > 1) subSelect.where(condition)
399
+ // where: [{ func: 'contains', args: [] }] must be evaluated
400
+ if (condition.length > 1 || (condition.length === 1 && !('val' in condition[0]))) subSelect.where(condition)
400
401
  }
401
402
 
402
403
  subSelect.where(queryTarget._relations[navName].join(innerAlias, outerAlias))
@@ -445,35 +446,36 @@ const _ensureExpandedNestedWhereExists = ({ ref }, aliases) => {
445
446
  return { ref: [acc] }
446
447
  }
447
448
 
448
- const convertWhereExists = (cqn, model, options) => {
449
- function _recurse(where) {
450
- where.forEach((element, index) => {
451
- // ensure where exists are fully expanded
452
- if (where && where.some(ele => ele === 'exists')) {
453
- where.forEach((element, index) => {
454
- if (element === 'exists' && where[index + 1].ref) {
455
- const aliases = cqn.SELECT.from.as
456
- ? [cqn.SELECT.from.as]
457
- : cqn.SELECT.from.join
458
- ? cqn.SELECT.from.args.map(arg => arg.as)
459
- : []
460
- where[index + 1] = _ensureExpandedNestedWhereExists(where[index + 1], aliases)
461
- }
462
- })
463
- }
449
+ const _convertWhereExists = (where, cqn, model, options) => {
450
+ for (let i = 0; i < where.length; i++) {
451
+ const element = where[i]
452
+
453
+ // ensure where exists are fully expanded
454
+ if (
455
+ (element === 'exists' && where[i + 1].ref && where[i > 1 ? i - 1 : 0] !== 'not') ||
456
+ (element === 'not' && where[i + 1] === 'exists' && where[i + 2].ref)
457
+ ) {
458
+ const offset = element === 'not' ? 2 : 1
459
+ const aliases = cqn.SELECT.from.as
460
+ ? [cqn.SELECT.from.as]
461
+ : cqn.SELECT.from.join
462
+ ? cqn.SELECT.from.args.map(arg => arg.as)
463
+ : []
464
+ where[i + offset] = _ensureExpandedNestedWhereExists(where[i + offset], aliases)
465
+ }
464
466
 
465
- if (element.xpr) {
466
- _recurse(element.xpr) // recursing into nested {xpr}
467
- } else if (element === 'exists' && _isAny(where[index + 1])) {
468
- where[index + 1] = _getWhereExistsSubSelect(cqn, where, index + 1, model, options)
469
- } else if (element === 'not' && where[index + 1] === 'exists' && _isAll(where[index + 2])) {
470
- where[index + 2] = _getWhereExistsSubSelect(cqn, where, index + 2, model, options)
471
- }
472
- })
467
+ if (element.xpr) {
468
+ _convertWhereExists(element.xpr, cqn, model, options) // > recursing into nested {xpr}
469
+ } else if (element === 'exists' && _isAny(where[i + 1])) {
470
+ where[i + 1] = _getWhereExistsSubSelect(cqn, where, i + 1, model, options)
471
+ } else if (element === 'not' && where[i + 1] === 'exists' && _isAll(where[i + 2])) {
472
+ where[i + 2] = _getWhereExistsSubSelect(cqn, where, i + 2, model, options)
473
+ }
473
474
  }
475
+ }
474
476
 
475
- const where = cqn.SELECT.where
476
- if (where) _recurse(where)
477
+ const convertWhereExists = (cqn, model, options) => {
478
+ if (cqn.SELECT.where) _convertWhereExists(cqn.SELECT.where, cqn, model, options)
477
479
  }
478
480
 
479
481
  const _getRefIndex = (where, index) => {
@@ -338,7 +338,7 @@ const _newSelect = (query, transitions, service) => {
338
338
  if (!newSelect.columns && targetTransition.mapping.size) newSelect.columns = _initialColumns(targetTransition)
339
339
  if (newSelect.columns) {
340
340
  const isDB = service instanceof cds.DatabaseService
341
- rewriteAsterisks({ SELECT: newSelect }, service.model, isDB)
341
+ rewriteAsterisks({ SELECT: query.SELECT }, service.model, isDB)
342
342
  newSelect.columns = _newColumns(newSelect.columns, targetTransition, service, service.kind !== 'app-service')
343
343
  }
344
344
  if (newSelect.having) newSelect.having = _newColumns(newSelect.having, targetTransition)
@@ -284,7 +284,7 @@ const flattenStructuredSelect = ({ SELECT }, model) => {
284
284
  _flattenColumns(SELECT, flattenedElements, toBeDeleted, entity)
285
285
  SELECT.columns = SELECT.columns.filter(column => {
286
286
  const columnName = column.ref ? column.ref[0] : column.as
287
- return (columnName && !toBeDeleted.includes(columnName)) || column.func || column.expand
287
+ return (columnName && !toBeDeleted.includes(columnName)) || column.func || column.expand || 'val' in column
288
288
  })
289
289
  if (flattenedElements.length) SELECT.columns.push(...flattenedElements)
290
290
  }
@@ -1,6 +1,6 @@
1
1
  const cds = require('../../cds')
2
2
 
3
- const { ensureUnlocalized } = require('../../common/utils/draft')
3
+ const { ensureUnlocalized, ensureNoDraftsSuffix } = require('../../common/utils/draft')
4
4
 
5
5
  /**
6
6
  * Check if the value is a function or reference to private function.
@@ -48,45 +48,45 @@ const _getEntityName = (csn, from) => {
48
48
 
49
49
  const _refs = (refs, as) => {
50
50
  const arr = []
51
- const hasOwnProperty = Object.prototype.hasOwnProperty
52
-
53
51
  for (const element of refs) {
54
52
  // multiple join are nested, so we need to find all the table names in there as well
55
- if (hasOwnProperty.call(element, 'join')) {
53
+ if (Object.prototype.hasOwnProperty.call(element, 'join')) {
56
54
  arr.push(..._extractRefs(element))
57
55
  // Likely a union
58
- } else if (hasOwnProperty.call(element, 'SELECT')) {
59
- arr.push(..._extractRefs(element.SELECT.from, as))
56
+ } else if (Object.prototype.hasOwnProperty.call(element, 'SELECT')) {
57
+ arr.push(..._extractRefs(element.SELECT.from, element.as))
60
58
  } else {
61
- arr.push(element)
59
+ arr.push(..._extractRefs(element, as))
62
60
  }
63
61
  }
64
62
 
65
63
  return arr
66
64
  }
67
65
 
66
+ const _getActiveFromUnion = refs => {
67
+ if (refs.length !== 2) return
68
+ const [maybeDraft, maybeActive] = refs
69
+ if (ensureNoDraftsSuffix(maybeDraft.ref[0]) === maybeActive.ref[0]) return maybeActive
70
+ if (ensureNoDraftsSuffix(maybeActive.ref[0]) === maybeDraft.ref[0]) return maybeDraft
71
+ }
72
+
68
73
  const _extractRefs = (from, as) => {
69
74
  if (from.SELECT) {
70
- return _extractRefs(from.SELECT.from, from.SELECT.as)
75
+ return _extractRefs(from.SELECT.from, as || from.SELECT.as)
71
76
  }
72
-
73
- const hasOwnProperty = Object.prototype.hasOwnProperty
74
-
75
- if (hasOwnProperty.call(from, 'join')) {
77
+ if (Object.prototype.hasOwnProperty.call(from, 'join')) {
76
78
  // cqn with join in from
77
79
  return _refs(from.args)
78
80
  }
79
-
80
- if (hasOwnProperty.call(from, 'SET')) {
81
- return _refs(from.SET.args, from.SET.as || from.as)
81
+ if (Object.prototype.hasOwnProperty.call(from, 'SET')) {
82
+ let refs = _refs(from.SET.args).filter(a => !a.as || a.as !== 'filterAdmin')
83
+ refs = _getActiveFromUnion(refs) ? [_getActiveFromUnion(refs)] : refs
84
+ if (as) return refs.map(({ ref }) => ({ as, ref }))
85
+ return refs
82
86
  }
83
-
84
- const ref = { ref: from.ref, as: from.as }
85
-
86
- if (as) {
87
- ref.as = as
88
- }
89
-
87
+ if (!from.ref) return []
88
+ const ref = { ref: [...from.ref] }
89
+ if (as || from.as) ref.as = as || from.as
90
90
  return [ref]
91
91
  }
92
92
 
@@ -626,7 +626,7 @@ class JoinCQNFromExpanded {
626
626
  // if union always only expand with active, otherwise evaluate flag
627
627
  // if flag shows false, we check entity for associations to non draft
628
628
  const activeTableRequired =
629
- readToOneCQN[IS_UNION_DRAFT] ||
629
+ readToOneCQN[IS_UNION_DRAFT] || // > REVISIT: blocks expanding comp2one
630
630
  readToOneCQN[IS_ACTIVE] ||
631
631
  (element && element.type === 'cds.Association' && !element['@odata.draft.enclosed']) ||
632
632
  !this._csn.definitions[target]._isDraftEnabled
@@ -665,9 +665,9 @@ class JoinCQNFromExpanded {
665
665
  readToOneCQN.from.args[1] = {
666
666
  SELECT: {
667
667
  columns: cols,
668
- from: unionFrom,
669
- as: tableAlias
670
- }
668
+ from: unionFrom
669
+ },
670
+ as: tableAlias
671
671
  }
672
672
  }
673
673
 
@@ -755,9 +755,9 @@ class JoinCQNFromExpanded {
755
755
  return {
756
756
  SELECT: {
757
757
  columns: Array.from(readToOneCQN.columns),
758
- from: readToOneCQN.from,
759
- as: readToOneCQN.from.as
760
- }
758
+ from: readToOneCQN.from
759
+ },
760
+ as: readToOneCQN.from.as
761
761
  }
762
762
  }
763
763
 
@@ -858,18 +858,18 @@ class JoinCQNFromExpanded {
858
858
 
859
859
  if (arg.args) {
860
860
  this._addJoinKeyColumnsToUnion(arg.args, on, parentAlias)
861
- } else if (arg.SELECT.from.SET && arg.SELECT.as === parentAlias) {
862
- this._addColumns(arg.SELECT.from.SET.args, on, parentAlias)
861
+ } else if (arg.SELECT.from.SET && (arg.as === parentAlias || arg.SELECT.from.as === parentAlias)) {
862
+ for (const _arg of arg.SELECT.from.SET.args) {
863
+ this._addColumns(_arg.SELECT.columns, on, parentAlias)
864
+ }
865
+ if (arg.SELECT.columns) {
866
+ this._addColumns(arg.SELECT.columns, on, parentAlias, true)
867
+ }
863
868
  }
864
869
  }
865
870
  }
866
871
 
867
- _addColumns(args, on, parentAlias) {
868
- const [
869
- {
870
- SELECT: { columns }
871
- }
872
- ] = args
872
+ _addColumns(columns, on, parentAlias, withAlias = false) {
873
873
  const keyColumns = on
874
874
  .filter(entry => {
875
875
  return (
@@ -878,15 +878,11 @@ class JoinCQNFromExpanded {
878
878
  !columns.some(column => column.ref && column.ref[column.ref.length - 1] === entry.ref[1])
879
879
  )
880
880
  })
881
- .map(entry => ({ ref: [entry.ref[1]] }))
882
-
881
+ .map(entry =>
882
+ withAlias ? { ref: [parentAlias, entry.ref[1]], as: `${parentAlias}_${entry.ref[1]}` } : { ref: [entry.ref[1]] }
883
+ )
883
884
  if (keyColumns.length === 0) return
884
-
885
- for (const {
886
- SELECT: { columns }
887
- } of args) {
888
- columns.push(...keyColumns)
889
- }
885
+ columns.push(...keyColumns)
890
886
  }
891
887
 
892
888
  /**
@@ -10,22 +10,26 @@ function _arrayWithCount(a, count) {
10
10
  }
11
11
 
12
12
  function _createCountQuery(query) {
13
- const _query = JSON.parse(JSON.stringify(query)) // REVISIT: Use query.clone() instead
14
- _query.SELECT.columns = [{ func: 'count', args: [{ val: 1 }], as: '$count' }]
15
- delete _query.SELECT.groupBy
16
- delete _query.SELECT.limit
13
+ let _query = JSON.parse(JSON.stringify(query)) // REVISIT: Use query.clone() instead
17
14
  delete _query.SELECT.orderBy // not necessary to keep that
15
+ delete _query.SELECT.limit
18
16
  // Also change columns in sub queries
19
17
  if (_query.SELECT.from.SET) {
20
18
  _query.SELECT.from.SET.args.forEach(subCountQuery => {
21
19
  subCountQuery.SELECT.columns = [{ val: 1 }]
22
20
  })
23
21
  }
22
+ if (query.SELECT.__countAggregated) {
23
+ _query = SELECT.from(_query)
24
+ }
25
+ _query.SELECT.columns = [{ func: 'count', args: [{ val: 1 }], as: '$count' }]
24
26
  if (query.SELECT._4odata) _query.SELECT._4odata = true
25
27
  return _query
26
28
  }
27
29
 
28
- const countValue = countResult => {
30
+ const countValue = countResults => {
31
+ if (!countResults.length) return 0
32
+ const countResult = countResults[0]
29
33
  if (countResult._counted_ != null) return countResult._counted_
30
34
  if (countResult.$count != null) return countResult.$count
31
35
  }
@@ -50,11 +54,11 @@ const read = (executeSelectCQN, executeStreamCQN) => (model, dbc, query, req) =>
50
54
  const countResultPromise = executeSelectCQN(model, dbc, countQuery, user, locale, isoTs)
51
55
  if (query.SELECT.limit.rows && query.SELECT.limit.rows.val === 0) {
52
56
  // We don't need to perform our result query
53
- return countResultPromise.then(countResult => _arrayWithCount([], countValue(countResult[0])))
57
+ return countResultPromise.then(countResults => _arrayWithCount([], countValue(countResults)))
54
58
  } else {
55
59
  const resultPromise = executeSelectCQN(model, dbc, query, user, locale, isoTs)
56
- return Promise.all([countResultPromise, resultPromise]).then(([countResult, result]) =>
57
- _arrayWithCount(result, countValue(countResult[0]))
60
+ return Promise.all([countResultPromise, resultPromise]).then(([countResults, result]) =>
61
+ _arrayWithCount(result, countValue(countResults))
58
62
  )
59
63
  }
60
64
  } else {
@@ -50,7 +50,8 @@ const _getWhereWithAppendedDraftRestrictions = (where = [], req, scenarioAlias,
50
50
  })
51
51
 
52
52
  if (where.length) where.push('and')
53
- where.push(...xpr)
53
+ // restriction might contain or clause -> use xpr for grouping
54
+ xpr.includes('or') ? where.push({ xpr }) : where.push(...xpr)
54
55
  } else {
55
56
  // > restriction inherited from parent via autoexposure
56
57
  // find inner most sub select if available and append restriction to where clause
@@ -818,6 +819,7 @@ const _getUnionCQN = (req, draftName, columns, subSelect, draftWhere, model) =>
818
819
 
819
820
  const union = SELECT.from({ SET: { op: 'union', all: true, args: [draftDocs, activeDocs] } })
820
821
  if (req.query.SELECT.count) union.SELECT.count = true
822
+ if (req.query.SELECT.__countAggregated) union.SELECT.__countAggregated = true
821
823
 
822
824
  if (req.query.SELECT.from.as) {
823
825
  draftDocs.SELECT.from.as = req.query.SELECT.from.as
@@ -1084,6 +1086,10 @@ const _adaptSubSelects = ({ SELECT: { from, where } }, scenario) => {
1084
1086
  }
1085
1087
  } else if (element.SELECT) {
1086
1088
  _adaptSubSelects(element, scenario)
1089
+ } else if (element.xpr) {
1090
+ for (const ele of element.xpr.filter(e => e.SELECT)) {
1091
+ _adaptSubSelects(ele, scenario)
1092
+ }
1087
1093
  }
1088
1094
  }
1089
1095
  }
@@ -31,7 +31,7 @@ const localizedHandler = function (req) {
31
31
  // suppress localization in "select for update"
32
32
  if (query.SELECT.forUpdate) return
33
33
 
34
- redirect(query.SELECT, getLocalize(req.locale, this.model))
34
+ redirect(query, getLocalize(req.locale, this.model))
35
35
  }
36
36
 
37
37
  localizedHandler._initial = true
@@ -58,7 +58,9 @@ class AMQPWebhookMessaging extends MessagingService {
58
58
  await super.emit(msg)
59
59
  done()
60
60
  } catch (e) {
61
- failed()
61
+ // In case of AMQP and Solace, the `failed` callback must be called
62
+ // with an error, otherwise there are problems with the redelivery count.
63
+ failed(new Error('processing failed'))
62
64
  LOG._error && LOG.error(e)
63
65
  }
64
66
  })
@@ -22,5 +22,6 @@ module.exports = options => {
22
22
  password: options.credentials.amqp10.auth.basic.password
23
23
  }
24
24
  }
25
+ if (options.amqp) amqp.amqp = options.amqp
25
26
  return amqp
26
27
  }
@@ -26,17 +26,24 @@ class MessagingService extends OutboxService {
26
26
  this.subscribedTopics = new Map()
27
27
  // Only for one central `messaging` service, otherwise all technical services would register themselves
28
28
  if (this.name === 'messaging') {
29
+ this._registeredServices = new Map()
29
30
  // listen for all subscriptions to declared events of remote, i.e. connected services
30
31
  cds.on('subscribe', (srv, event) => {
31
32
  const declared = srv.events[event]
32
33
  if (declared && srv.name in cds.requires && !srv.mocked) {
33
34
  // we register self-handlers for declared events, which are supposed
34
35
  // to be calles by subclasses calling this.dispatch on incoming events
36
+ let registeredEvents = this._registeredServices.get(srv.name)
37
+ if (!registeredEvents) {
38
+ registeredEvents = new Set()
39
+ this._registeredServices.set(srv.name, registeredEvents)
40
+ }
41
+ if (registeredEvents.has(event)) return
42
+ registeredEvents.add(event)
35
43
  const topic = _topic(declared)
36
- this.on(topic, async (msg, next) => {
44
+ this.on(topic, msg => {
37
45
  const { data, headers } = msg
38
- await srv.tx(msg).emit({ event, data, headers, __proto__: msg })
39
- return next()
46
+ return srv.tx(msg).emit({ event, data, headers, __proto__: msg })
40
47
  })
41
48
  }
42
49
  })
@@ -48,10 +55,9 @@ class MessagingService extends OutboxService {
48
55
  // calls to srv.emit are forwarded to this.emit, which is expected to
49
56
  // be overwritten by subclasses to write events to message channel
50
57
  const topic = _topic(declared)
51
- srv.on(event, async (msg, next) => {
58
+ srv.on(event, msg => {
52
59
  const { data, headers } = msg
53
- await this.tx(msg).emit({ event: topic, data, headers })
54
- return next()
60
+ return this.tx(msg).emit({ event: topic, data, headers })
55
61
  })
56
62
  }
57
63
  })
@@ -122,7 +122,7 @@ const convertV2ResponseData = (data, target, ieee754Compatible) => {
122
122
 
123
123
  const deepSanitize = arg => {
124
124
  if (Array.isArray(arg)) return arg.map(deepSanitize)
125
- if (typeof arg === 'object')
125
+ if (typeof arg === 'object' && arg !== null)
126
126
  return Object.keys(arg).reduce((acc, cur) => {
127
127
  acc[cur] = deepSanitize(arg[cur])
128
128
  return acc
@@ -41,7 +41,7 @@ const _handler = function (req) {
41
41
 
42
42
  // suppress localization in "select for update" n/a for sqlite
43
43
 
44
- redirect(query.SELECT, getLocalize(req.locale, this.model))
44
+ redirect(query, getLocalize(req.locale, this.model))
45
45
  }
46
46
 
47
47
  _handler._initial = true
@@ -19,7 +19,7 @@ const astToColumns = selections => {
19
19
 
20
20
  const filter = getArgumentByName(selection.arguments, ARGUMENT.FILTER)
21
21
  if (filter) {
22
- column.where = astToWhere(filter).xpr
22
+ column.where = astToWhere(filter)
23
23
  }
24
24
 
25
25
  const orderBy = getArgumentByName(selection.arguments, ARGUMENT.ORDER_BY)
@@ -119,6 +119,22 @@
119
119
  }
120
120
  if (apply.apply) _handleApply(cqn.from.SELECT, apply.apply)
121
121
  }
122
+ const _setLimitOffset = val => {
123
+ if (SELECT.limit && SELECT.limit.offset && SELECT.limit.offset.val) {
124
+ val += SELECT.limit.offset.val
125
+ }
126
+ (SELECT.limit || (SELECT.limit={})).offset = {val}
127
+ }
128
+
129
+ const _removeLambdaPrefix = (prefix, elements) => {
130
+ for (const e of elements) {
131
+ // remove the prefix identifier
132
+ if (e.ref && e.ref[0] === prefix) e.ref.shift()
133
+ if (e.func) _removeLambdaPrefix(prefix, e.args)
134
+ }
135
+
136
+ return elements
137
+ }
122
138
  }
123
139
 
124
140
  // ---------- Entity Paths ---------------
@@ -153,6 +169,7 @@
153
169
  }
154
170
  delete SELECT.expand
155
171
  }
172
+ if (SELECT.count && SELECT.apply) SELECT.__countAggregated = true
156
173
  _handleApply(SELECT, SELECT.apply, onlyColumnsFromExpand)
157
174
  return { SELECT }
158
175
  }
@@ -194,7 +211,14 @@
194
211
  //
195
212
  // ---------- Query Options ------------
196
213
 
197
- QueryOption = ExpandOption
214
+ QueryOption = ExpandOption /
215
+ "$skiptoken=" o skiptoken /
216
+ "$apply=" (o{
217
+ SELECT.apply = {}
218
+ }) apply /
219
+ custom
220
+ // @OData spec for $expand:
221
+ // "Allowed system query options are $filter, $select, $orderby, $skip, $top, $count, $search, and $expand."
198
222
  ExpandOption =
199
223
  "$select=" o select ( COMMA select )* /
200
224
  "$expand=" o expand ( COMMA expand )* /
@@ -202,13 +226,8 @@
202
226
  "$orderby=" o orderby ( COMMA orderby )* /
203
227
  "$top=" o top /
204
228
  "$skip=" o skip /
205
- "$skiptoken=" o skip /
206
229
  "$search=" o s:search {if (s) SELECT.search = s} /
207
- "$count=" o count /
208
- "$apply=" (o{
209
- SELECT.apply = {}
210
- }) apply /
211
- custom
230
+ "$count=" o count
212
231
 
213
232
 
214
233
  select
@@ -251,18 +270,27 @@
251
270
  })
252
271
  )? // --- end of nested query options
253
272
  ( COMMA expand )?
273
+ ("/$count" {
274
+ const err = new Error("EXPAND_COUNT_UNSUPPORTED");
275
+ err.statusCode=501;
276
+ throw err;
277
+ })?
254
278
 
255
279
  top
256
280
  = val:integer {
257
281
  (SELECT.limit || (SELECT.limit={})).rows = {val}
258
282
  }
259
283
 
284
+ skiptoken
285
+ = val:integer? skiptoken:skiptokenChars? {
286
+ // REVISIT ignore non-numeric $skiptoken as not supported by CQN
287
+ if (skiptoken) return
288
+ _setLimitOffset(val)
289
+ }
290
+
260
291
  skip
261
292
  = val:integer {
262
- if (SELECT.limit && SELECT.limit.offset && SELECT.limit.offset.val) {
263
- val += SELECT.limit.offset.val
264
- }
265
- (SELECT.limit || (SELECT.limit={})).offset = {val}
293
+ _setLimitOffset(val)
266
294
  }
267
295
 
268
296
  search
@@ -326,18 +354,14 @@
326
354
  p:( n:NOT? { return n ? [n] : [] } )(
327
355
  OPEN xpr:inner_lambda CLOSE { p.push('(', ...xpr, ')') }
328
356
  / comp:comparison { p.push(...comp) }
357
+ / func:function { p.push(func) }
329
358
  / lambda:lambda { p.push(...lambda)}
330
359
  )
331
360
  ( ao:(AND/OR) more:inner_lambda { p.push(ao, ...more) } )*
332
361
  { return p }
333
362
 
334
363
  lambda_clause = prefix:identifier ":" inner:inner_lambda {
335
- for (const e of inner) {
336
- // remove the prefix identifier
337
- if (e.ref && e.ref[0] === prefix) e.ref.shift()
338
- }
339
-
340
- return inner
364
+ return _removeLambdaPrefix(prefix, inner)
341
365
  }
342
366
 
343
367
  any = "any" OPEN p:lambda_clause? CLOSE { return p }
@@ -411,16 +435,16 @@
411
435
  { return { list: any.replace(/"/g,'').split(',').map(ele => ({ val: ele })) } }
412
436
 
413
437
  function "a function call"
414
- = func:$[a-z]+ OPEN a:operand more:( COMMA o:operand {return o} )* CLOSE {
415
- if (strict && !(func in strict.functions)) {
438
+ = func:$[a-zA-Z]+ OPEN a:operand more:( COMMA o:operand {return o} )* CLOSE {
439
+ if (strict && !(func.toLowerCase() in strict.functions)) {
416
440
  throw Object.assign(new Error(`"${func}" is an unknown function in OData URL spec (strict mode)`), { statusCode: 400 })
417
441
  }
418
- return { func, args:[a,...more] }
442
+ return { func: func.toLowerCase(), args:[a,...more] }
419
443
  }
420
444
 
421
445
  boolish "a boolean function"
422
- = func:("contains"/"endswith"/"startswith") OPEN a:operand COMMA b:operand CLOSE
423
- { return { func, args:[a,b] }}
446
+ = func:("contains"i/"endswith"i/"startswith"i) OPEN a:operand COMMA b:operand CLOSE
447
+ { return { func: func.toLowerCase(), args:[a,b] }}
424
448
 
425
449
  NOT = o "NOT"i _ {return 'not'}
426
450
  AND = _ "AND"i _ {return 'and'}
@@ -443,7 +467,7 @@
443
467
  "search" searchTrafo /
444
468
  "concat" concatTrafo /
445
469
  "compute" computeTrafo /
446
- func:("topcount"/"bottomcount"/"topsum"/"bottomsum"/"toppercent"/"bottompercent") args:commonFuncTrafo {
470
+ func:("topcount"i/"bottomcount"i/"topsum"i/"bottomsum"i/"toppercent"i/"bottompercent"i) args:commonFuncTrafo {
447
471
  const SUPPORTED_APPLY_TRANSFORMATIONS = {
448
472
  "topcount": true,
449
473
  "bottomcount": true,
@@ -452,6 +476,7 @@
452
476
  "toppercent": false,
453
477
  "bottompercent": false
454
478
  }
479
+ func = func.toLowerCase()
455
480
  if (!SUPPORTED_APPLY_TRANSFORMATIONS[func]) {
456
481
  throw Object.assign(new Error(`Transformation "${func}" in $apply is not supported yet.`), { statusCode: 501 })
457
482
  }
@@ -485,7 +510,7 @@
485
510
  / identifier OPEN aggregateExpr CLOSE // needs CAP support
486
511
  // / customAggregate // needs CAP support
487
512
  aggregateWith
488
- = _ "with" _ func:$[a-z]+ { return func; }
513
+ = _ "with" _ func:$[a-zA-Z]+ { return func.toLowerCase(); }
489
514
  aggregateFrom
490
515
  = _ "from" _ ref aggregateWith aggregateFrom? // needs CAP support
491
516
  asAlias
@@ -557,7 +582,7 @@
557
582
  {return s.replace(/\\\\/g,"\\").replace(/\\"/g,'"')}
558
583
 
559
584
  word
560
- = s:$([a-zA-Z0-9.+-]+)
585
+ = $([^ \t\n()"&;]+)
561
586
 
562
587
  date
563
588
  = s:$( [0-9]+"-"[0-9][0-9]"-"[0-9][0-9] // date
@@ -583,6 +608,9 @@
583
608
  segment
584
609
  = val:$([a-zA-Z0-9-"."_~!$&'()*+,;=:@]+){return {val}}
585
610
 
611
+ skiptokenChars
612
+ = $([a-zA-Z0-9-"."_~!$'()*+,;=:@"/""?"]+)
613
+
586
614
  //
587
615
  // ---------- Punctuation ----------
588
616
 
@@ -6,6 +6,7 @@ const cqn2odata = require('./cqn2odata')
6
6
 
7
7
  const afterburner = require('./afterburner')
8
8
  const { getSafeNumber: safeNumber } = require('./utils')
9
+ const getError = require('../_runtime/common/error')
9
10
 
10
11
  const strict = {
11
12
  functions: {
@@ -62,6 +63,11 @@ module.exports = {
62
63
  try {
63
64
  cqn = odata2cqn(url, options)
64
65
  } catch (err) {
66
+ if (err.message === 'EXPAND_COUNT_UNSUPPORTED') {
67
+ throw getError(err.statusCode || 400, err.message)
68
+ }
69
+
70
+ // TODO adjust this to behave like above
65
71
  err.message = 'Parsing URL failed with error: ' + err.message
66
72
  err.statusCode = err.statusCode || 400
67
73
  throw err
@@ -1 +1 @@
1
- "use strict";function peg$subclass(t,r){function e(){this.constructor=t}e.prototype=r.prototype,t.prototype=new e}function peg$SyntaxError(t,r,e,n){this.message=t,this.expected=r,this.found=e,this.location=n,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,peg$SyntaxError)}function peg$parse(t,r){r=void 0!==r?r:{};var e,n={},s={ODataRelativeURI:Fe},a=Fe,u="/",o=Ee("/",!1),c=Ee("?",!1),i=Ee("&",!1),f="$count",l=Ee("$count",!1),h="$ref",p=Ee("$ref",!1),A="$value",d=Ee("$value",!1),g=function(t){return[t]},v=function(t,r){return r},b=Ee("=",!1),y="$select=",m=Ee("$select=",!1),C="$expand=",x=Ee("$expand=",!1),w="$filter=",$=Ee("$filter=",!1),E="$orderby=",S=Ee("$orderby=",!1),B="$top=",z=Ee("$top=",!1),Z="$skip=",O=Ee("$skip=",!1),T="$skiptoken=",F=Ee("$skiptoken=",!1),L="$search=",j=Ee("$search=",!1),k="$count=",R=Ee("$count=",!1),_="$apply=",N=Ee("$apply=",!1),q=Ee("*",!1),I=Ee(";",!1),D=function(t){return t?[t]:[]},U=function(t,r){t.push({xpr:r})},M=function(t,r){t.push({val:r})},P=function(t,r,e){t.push(r,...e)},G=function(t,r){t.push(r)},H=function(t,r,e){t.push(r,...e)},J=":",K=Ee(":",!1),Q="any",V=Ee("any",!1),W="all",X=Ee("all",!1),Y=Ee("asc",!1),tt="desc",rt=Ee("desc",!1),et=/^[a-zA-Z]/,nt=Se([["a","z"],["A","Z"]],!1,!1),st=/^[a-zA-Z0-9\-]/,at=Se([["a","z"],["A","Z"],["0","9"],"-"],!1,!1),ut=/^[^&]/,ot=Se(["&"],!0,!1),ct=Be("a comparison"),it=Ee("eq",!1),ft=Ee("ne",!1),lt=Ee("lt",!1),ht=Ee("gt",!1),pt=Ee("le",!1),At=Ee("ge",!1),dt=(Ee("add",!1),Ee("sub",!1),Ee("mul",!1),Ee("div",!1),Ee("mod",!1),Be("an operand")),gt=Be("navigation with $count"),vt=function(t,r){return r},bt=function(t,r){return r?{id:t,where:r}:t},yt=Be("a reference"),mt=function(t,r){return r},Ct=function(t){return{val:t}},xt=Ee("{",!1),wt=/^[^}]/,$t=Se(["}"],!0,!1),Et=Ee("}",!1),St="[",Bt=Ee("[",!1),zt="]",Zt=Ee("]",!1),Ot=/^[^\]]/,Tt=Se(["]"],!0,!1),Ft=Be("a function call"),Lt=/^[a-z]/,jt=Se([["a","z"]],!1,!1),kt=function(t,r,e){return e},Rt=Be("a boolean function"),_t="contains",Nt=Ee("contains",!1),qt="endswith",It=Ee("endswith",!1),Dt="startswith",Ut=Ee("startswith",!1),Mt=Ee("NOT",!0),Pt=Ee("AND",!0),Gt=Ee("OR",!0),Ht="aggregate",Jt=Ee("aggregate",!1),Kt="groupby",Qt=Ee("groupby",!1),Vt="filter",Wt=Ee("filter",!1),Xt="expand",Yt=Ee("expand",!1),tr="search",rr=Ee("search",!1),er="concat",nr=Ee("concat",!1),sr="compute",ar=Ee("compute",!1),ur="topcount",or=Ee("topcount",!1),cr="bottomcount",ir=Ee("bottomcount",!1),fr="topsum",lr=Ee("topsum",!1),hr="bottomsum",pr=Ee("bottomsum",!1),Ar="toppercent",dr=Ee("toppercent",!1),gr="bottompercent",vr=Ee("bottompercent",!1),br="with",yr=Ee("with",!1),mr="from",Cr=Ee("from",!1),xr=Ee("as",!1),wr="rollup",$r=Ee("rollup",!1),Er="$all",Sr=Ee("$all",!1),Br="identity",zr=Ee("identity",!1),Zr="true",Or=Ee("true",!1),Tr="false",Fr=Ee("false",!1),Lr=Be("Edm.String"),jr=Ee("'",!1),kr="''",Rr=Ee("''",!1),_r=/^[^']/,Nr=Se(["'"],!0,!1),qr='"',Ir=Ee('"',!1),Dr='\\"',Ur=Ee('\\"',!1),Mr=/^[^"]/,Pr=Se(['"'],!0,!1),Gr=/^[a-zA-Z0-9.+\-]/,Hr=Se([["a","z"],["A","Z"],["0","9"],".","+","-"],!1,!1),Jr=/^[0-9]/,Kr=Se([["0","9"]],!1,!1),Qr="-",Vr=Ee("-",!1),Wr=Ee("T",!1),Xr=".",Yr=Ee(".",!1),te=Ee("Z",!1),re=Ee("+",!1),ee=/^[+\-]/,ne=Se(["+","-"],!1,!1),se=Ee("e",!1),ae=/^[_a-zA-Z]/,ue=Se(["_",["a","z"],["A","Z"]],!1,!1),oe=/^[_a-zA-Z0-9"."]/,ce=Se(["_",["a","z"],["A","Z"],["0","9"],'"',".",'"'],!1,!1),ie=/^[0-9a-fA-F]/,fe=Se([["0","9"],["a","f"],["A","F"]],!1,!1),le=/^[a-zA-Z0-9\-"."_~!$&'()*+,;=:@]/,he=Se([["a","z"],["A","Z"],["0","9"],"-",'"',".",'"',"_","~","!","$","&","'","(",")","*","+",",",";","=",":","@"],!1,!1),pe=Ee(",",!1),Ae=Ee("(",!1),de=Ee(")",!1),ge=Be("optional whitespaces"),ve=/^[ \t\n]/,be=Se([" ","\t","\n"],!1,!1),ye=Be("mandatory whitespaces"),me=0,Ce=[{line:1,column:1}],xe=0,we=[],$e=0;if("startRule"in r){if(!(r.startRule in s))throw new Error("Can't start parsing from rule \""+r.startRule+'".');a=s[r.startRule]}function Ee(t,r){return{type:"literal",text:t,ignoreCase:r}}function Se(t,r,e){return{type:"class",parts:t,inverted:r,ignoreCase:e}}function Be(t){return{type:"other",description:t}}function ze(r){var e,n=Ce[r];if(n)return n;for(e=r-1;!Ce[e];)e--;for(n={line:(n=Ce[e]).line,column:n.column};e<r;)10===t.charCodeAt(e)?(n.line++,n.column=1):n.column++,e++;return Ce[r]=n,n}function Ze(t,r){var e=ze(t),n=ze(r);return{start:{offset:t,line:e.line,column:e.column},end:{offset:r,line:n.line,column:n.column}}}function Oe(t){me<xe||(me>xe&&(xe=me,we=[]),we.push(t))}function Te(t,r,e){return new peg$SyntaxError(peg$SyntaxError.buildMessage(t,r),t,r,e)}function Fe(){var r,e,s,a,f,l,h,p,A,d,g,v,b,y;if(r=me,47===t.charCodeAt(me)?(e=u,me++):(e=n,0===$e&&Oe(o)),e===n&&(e=null),e!==n)if(s=me,(a=Le())!==n&&(s,a=void(Fn=a)),(s=a)!==n){if(a=me,(f=Sn())!==n)if(63===t.charCodeAt(me)?(l="?",me++):(l=n,0===$e&&Oe(c)),l!==n)if((h=Sn())!==n)if((p=ke())!==n){for(A=[],d=me,(g=Sn())!==n?(38===t.charCodeAt(me)?(v="&",me++):(v=n,0===$e&&Oe(i)),v!==n&&(b=Sn())!==n&&(y=ke())!==n?d=g=[g,v,b,y]:(me=d,d=n)):(me=d,d=n);d!==n;)A.push(d),d=me,(g=Sn())!==n?(38===t.charCodeAt(me)?(v="&",me++):(v=n,0===$e&&Oe(i)),v!==n&&(b=Sn())!==n&&(y=ke())!==n?d=g=[g,v,b,y]:(me=d,d=n)):(me=d,d=n);A!==n?a=f=[f,l,h,p,A]:(me=a,a=n)}else me=a,a=n;else me=a,a=n;else me=a,a=n;else me=a,a=n;a===n&&(a=null),a!==n&&(f=Sn())!==n?(r,r=e=function(){if(Ln)return Fn.columns=[{args:[{val:1}],as:"$count",func:"count"}],delete Fn.expand,delete Fn.limit,delete Fn.orderBy,Fn.apply&&(Fn.apply={apply:Fn.apply},In(Fn,Fn.apply)),{SELECT:Fn};let t;if(Fn.expand){Fn.columns||(Fn.columns=["*"],t=!0);for(const t of Fn.expand){const r=Fn.columns.findIndex(Rn(t));r>-1&&Fn.columns.splice(r,1),Fn.columns.push(t)}delete Fn.expand}return In(Fn,Fn.apply,t),{SELECT:Fn}}()):(me=r,r=n)}else me=r,r=n;else me=r,r=n;return r}function Le(){var r,e,s,a,c,i,b,y;return r=me,t.substr(me,6)===f?(e=f,me+=6):(e=n,0===$e&&Oe(l)),e!==n&&(r,e=void(Ln=!0)),(r=e)===n&&(r=me,e=me,t.substr(me,4)===h?(s=h,me+=4):(s=n,0===$e&&Oe(p)),s===n&&(t.substr(me,6)===A?(s=A,me+=6):(s=n,0===$e&&Oe(d))),(e=s!==n?t.substring(e,me):s)!==n&&(r,y=e,e=!jn.includes(y)&&{from:{ref:[y]}}),(r=e)===n&&(r=me,e=me,(s=yn())!==n?(a=me,(c=$n())!==n&&(i=En())!==n?a=c=[c,i]:(me=a,a=n),a===n&&(a=me,(c=$n())!==n&&(i=je())!==n&&(b=En())!==n?a=c=[c,i,b]:(me=a,a=n)),a===n&&(a=null),a!==n?(c=me,$e++,i=xn(),$e--,i===n?c=void 0:(me=c,c=n),c!==n?e=s=[s,a,c]:(me=e,e=n)):(me=e,e=n)):(me=e,e=n),e===n&&(e=me,s=me,a=me,c=me,$e++,i=vn(),$e--,i===n?c=void 0:(me=c,c=n),c!==n&&(i=We())!==n?a=c=[c,i]:(me=a,a=n),a!==n&&(s,a=a[1]),(s=a)===n&&(s=xn()),s!==n&&(e,s=g(s)),e=s),e!==n?(s=me,47===t.charCodeAt(me)?(a=u,me++):(a=n,0===$e&&Oe(o)),a!==n&&(c=Le())!==n?(s,s=a=v(0,c)):(me=s,s=n),s===n&&(s=null),s!==n?(r,r=e=function(t,r){const[e,n]=t,s=[n?n.length>2?{id:e,where:n[1].map((t=>t.val&&t.val.match&&t.val.match(/^"(.*)"$/)?{val:t.val.match(/^"(.*)"$/)[1]}:t))}:{id:e,where:[]}:On?`${"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,"val")?e.val:e}`:e];if(r&&r.from){const t=r.from.ref;Object.prototype.hasOwnProperty.call(t[0],"val")&&(s[s.length-1]={id:s[s.length-1],where:[t.shift()]}),s.push(...t)}const a={from:{ref:s}};return r&&r.columns&&(a.columns=r.columns),a}(e,s)):(me=r,r=n)):(me=r,r=n))),r}function je(){var r,e,s,a,u,o,c;return r=me,(e=We())!==n&&(r,e=g(e)),(r=e)===n&&(r=me,(e=Ve())!==n&&Sn()!==n?(61===t.charCodeAt(me)?(s="=",me++):(s=n,0===$e&&Oe(b)),s!==n&&Sn()!==n&&(a=We())!==n?(u=me,(o=wn())!==n&&(c=je())!==n?u=o=[o,c]:(me=u,u=n),u===n&&(u=null),u!==n?(r,r=e=function(t,r,e){const n=[t,"=",r];return e&&n.push("and",...e[1]),n}(e,a,u)):(me=r,r=n)):(me=r,r=n)):(me=r,r=n)),r}function ke(){var r,e,s,a,u,o,c,i,f,l;if(r=me,t.substr(me,8)===y?(e=y,me+=8):(e=n,0===$e&&Oe(m)),e!==n)if((s=Sn())!==n)if((a=Re())!==n){for(u=[],o=me,(c=wn())!==n&&(i=Re())!==n?o=c=[c,i]:(me=o,o=n);o!==n;)u.push(o),o=me,(c=wn())!==n&&(i=Re())!==n?o=c=[c,i]:(me=o,o=n);u!==n?r=e=[e,s,a,u]:(me=r,r=n)}else me=r,r=n;else me=r,r=n;else me=r,r=n;if(r===n){if(r=me,t.substr(me,8)===C?(e=C,me+=8):(e=n,0===$e&&Oe(x)),e!==n)if((s=Sn())!==n)if((a=_e())!==n){for(u=[],o=me,(c=wn())!==n&&(i=_e())!==n?o=c=[c,i]:(me=o,o=n);o!==n;)u.push(o),o=me,(c=wn())!==n&&(i=_e())!==n?o=c=[c,i]:(me=o,o=n);u!==n?r=e=[e,s,a,u]:(me=r,r=n)}else me=r,r=n;else me=r,r=n;else me=r,r=n;if(r===n&&(r=me,t.substr(me,8)===w?(e=w,me+=8):(e=n,0===$e&&Oe($)),e!==n&&(s=Sn())!==n&&(a=De())!==n?(r,l=a,r=e=void(Fn.where=l)):(me=r,r=n),r===n)){if(r=me,t.substr(me,9)===E?(e=E,me+=9):(e=n,0===$e&&Oe(S)),e!==n)if((s=Sn())!==n)if((a=He())!==n){for(u=[],o=me,(c=wn())!==n&&(i=He())!==n?o=c=[c,i]:(me=o,o=n);o!==n;)u.push(o),o=me,(c=wn())!==n&&(i=He())!==n?o=c=[c,i]:(me=o,o=n);u!==n?r=e=[e,s,a,u]:(me=r,r=n)}else me=r,r=n;else me=r,r=n;else me=r,r=n;r===n&&(r=me,t.substr(me,5)===B?(e=B,me+=5):(e=n,0===$e&&Oe(z)),e!==n&&(s=Sn())!==n?(a=function(){var t,r;t=me,(r=bn())!==n&&(t,e=r,r=void((Fn.limit||(Fn.limit={})).rows={val:e}));var e;return t=r}(),a!==n?r=e=[e,s,a]:(me=r,r=n)):(me=r,r=n),r===n&&(r=me,t.substr(me,6)===Z?(e=Z,me+=6):(e=n,0===$e&&Oe(O)),e!==n&&(s=Sn())!==n&&(a=Ne())!==n?r=e=[e,s,a]:(me=r,r=n),r===n&&(r=me,t.substr(me,11)===T?(e=T,me+=11):(e=n,0===$e&&Oe(F)),e!==n&&(s=Sn())!==n&&(a=Ne())!==n?r=e=[e,s,a]:(me=r,r=n),r===n&&(r=me,t.substr(me,8)===L?(e=L,me+=8):(e=n,0===$e&&Oe(j)),e!==n&&(s=Sn())!==n&&(a=qe())!==n?(r,r=e=void((f=a)&&(Fn.search=f))):(me=r,r=n),r===n&&(r=me,t.substr(me,7)===k?(e=k,me+=7):(e=n,0===$e&&Oe(R)),e!==n&&(s=Sn())!==n?(a=function(){var t,r;t=me,(r=gn())!==n&&(t,r=void(r&&(Fn.count=!0)));return t=r}(),a!==n?r=e=[e,s,a]:(me=r,r=n)):(me=r,r=n),r===n&&(r=me,t.substr(me,7)===_?(e=_,me+=7):(e=n,0===$e&&Oe(N)),e!==n?(s=me,(a=Sn())!==n&&(s,a=void(Fn.apply={})),(s=a)!==n&&(a=Je())!==n?r=e=[e,s,a]:(me=r,r=n)):(me=r,r=n),r===n&&(r=function(){var r,e,s,a,u,o;r=me,et.test(t.charAt(me))?(e=t.charAt(me),me++):(e=n,0===$e&&Oe(nt));if(e!==n){for(s=[],st.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(at));a!==n;)s.push(a),st.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(at));if(s!==n)if(61===t.charCodeAt(me)?(a="=",me++):(a=n,0===$e&&Oe(b)),a!==n){for(u=[],ut.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe(ot));o!==n;)u.push(o),ut.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe(ot));u!==n?r=e=[e,s,a,u]:(me=r,r=n)}else me=r,r=n;else me=r,r=n}else me=r,r=n;return r}())))))))}}return r}function Re(){var r,e,s;return r=me,42===t.charCodeAt(me)?(e="*",me++):(e=n,0===$e&&Oe(q)),e===n&&(e=Ve()),e!==n&&(r,s=e,Fn.columns=Array.isArray(Fn.columns)?Fn.columns:[],Fn.columns.find(Rn(s))||Fn.columns.push(s),e=s),r=e}function _e(){var r,e,s,a,u,o,c,i,f,l,h;if(r=me,e=me,42===t.charCodeAt(me)?(s="*",me++):(s=n,0===$e&&Oe(q)),s===n&&(s=Ve()),s!==n&&(e,s=function(t){const r="*"===t?{}:t;return r.expand="*",Array.isArray(Fn.expand)||(Fn.expand=[]),Fn.expand.find(Rn(r))||Fn.expand.push(r),r}(s)),(e=s)!==n){if(s=me,a=me,(u=$n())!==n&&(a,Tn.push(Fn),Fn=Fn.expand[Fn.expand.length-1],u=void(Fn.expand="*")),(a=u)!==n){for(u=me,o=[],c=me,(i=Sn())!==n?(59===t.charCodeAt(me)?(f=";",me++):(f=n,0===$e&&Oe(I)),f===n&&(f=null),f!==n&&(l=Sn())!==n&&(h=ke())!==n?c=i=[i,f,l,h]:(me=c,c=n)):(me=c,c=n);c!==n;)o.push(c),c=me,(i=Sn())!==n?(59===t.charCodeAt(me)?(f=";",me++):(f=n,0===$e&&Oe(I)),f===n&&(f=null),f!==n&&(l=Sn())!==n&&(h=ke())!==n?c=i=[i,f,l,h]:(me=c,c=n)):(me=c,c=n);o!==n&&(u,o=function(t){if(Fn.columns){"*"===Fn.expand&&(Fn.expand=[]);for(const t of Fn.columns)Fn.expand.find(Rn(t))||Fn.expand.push(t);delete Fn.columns}else Array.isArray(Fn.expand)&&-1===Fn.expand.indexOf("*")&&Fn.expand.unshift("*")}()),(u=o)!==n?(o=me,(c=En())!==n&&(o,c=void(Fn=Tn.pop())),(o=c)!==n?s=a=[a,u,o]:(me=s,s=n)):(me=s,s=n)}else me=s,s=n;s===n&&(s=null),s!==n?(a=me,(u=wn())!==n&&(o=_e())!==n?a=u=[u,o]:(me=a,a=n),a===n&&(a=null),a!==n?r=e=[e,s,a]:(me=r,r=n)):(me=r,r=n)}else me=r,r=n;return r}function Ne(){var t,r,e;return t=me,(r=bn())!==n&&(t,e=r,Fn.limit&&Fn.limit.offset&&Fn.limit.offset.val&&(e+=Fn.limit.offset.val),r=void((Fn.limit||(Fn.limit={})).offset={val:e})),t=r}function qe(){var t,r;return t=me,(r=Ie())!==n&&(t,r=r),(t=r)===n&&(t=Sn()),t}function Ie(){var r,e,s,a,u,o,c;if(r=me,e=me,(s=rn())===n&&(s=null),s!==n&&(e,s=D(s)),(e=s)!==n)if(s=me,(a=$n())!==n&&(u=Ie())!==n&&(o=En())!==n?(s,s=a=U(e,u)):(me=s,s=n),s===n&&(s=me,a=function(){var r,e,s,a,u;r=me,34===t.charCodeAt(me)?(e=qr,me++):(e=n,0===$e&&Oe(Ir));if(e!==n){for(s=me,a=[],t.substr(me,2)===Dr?(u=Dr,me+=2):(u=n,0===$e&&Oe(Ur)),u===n&&(Mr.test(t.charAt(me))?(u=t.charAt(me),me++):(u=n,0===$e&&Oe(Pr)));u!==n;)a.push(u),t.substr(me,2)===Dr?(u=Dr,me+=2):(u=n,0===$e&&Oe(Ur)),u===n&&(Mr.test(t.charAt(me))?(u=t.charAt(me),me++):(u=n,0===$e&&Oe(Pr)));(s=a!==n?t.substring(s,me):a)!==n?(34===t.charCodeAt(me)?(a=qr,me++):(a=n,0===$e&&Oe(Ir)),a!==n?(r,r=e=s.replace(/\\\\/g,"\\").replace(/\\"/g,'"')):(me=r,r=n)):(me=r,r=n)}else me=r,r=n;return r}(),a!==n&&(s,a=M(e,a)),(s=a)===n&&(s=me,(a=vn())!==n&&(s,a=M(e,a)),(s=a)===n&&(s=me,a=function(){var r,e,s;r=me,e=[],Gr.test(t.charAt(me))?(s=t.charAt(me),me++):(s=n,0===$e&&Oe(Hr));if(s!==n)for(;s!==n;)e.push(s),Gr.test(t.charAt(me))?(s=t.charAt(me),me++):(s=n,0===$e&&Oe(Hr));else e=n;r=e!==n?t.substring(r,me):e;return r}(),a!==n&&(s,a=M(e,a)),s=a))),s!==n){for(a=[],u=me,(o=en())===n&&(o=sn())===n&&(o=nn()),o!==n&&(c=Ie())!==n?(u,u=o=P(e,o,c)):(me=u,u=n);u!==n;)a.push(u),u=me,(o=en())===n&&(o=sn())===n&&(o=nn()),o!==n&&(c=Ie())!==n?(u,u=o=P(e,o,c)):(me=u,u=n);a!==n?(r,r=e=e):(me=r,r=n)}else me=r,r=n;else me=r,r=n;return r}function De(){var t,r;return t=me,(r=Ue())!==n&&(t,r=r),t=r}function Ue(){var r,e,s,a,u,o,c,i;if(r=me,e=me,(s=rn())===n&&(s=null),s!==n&&(e,s=D(s)),(e=s)!==n)if(s=me,(a=$n())!==n&&(u=Ue())!==n&&(o=En())!==n?(s,s=a=U(e,u)):(me=s,s=n),s===n&&(s=me,(a=Ke())!==n&&(s,i=a,a=void e.push(...i)),(s=a)===n&&(s=me,(a=Me())!==n&&(s,a=function(t,r){t.push(...r)}(e,a)),(s=a)===n&&(s=me,a=function(){var r,e,s,a;$e++,r=me,t.substr(me,8)===_t?(e=_t,me+=8):(e=n,0===$e&&Oe(Nt));e===n&&(t.substr(me,8)===qt?(e=qt,me+=8):(e=n,0===$e&&Oe(It)),e===n&&(t.substr(me,10)===Dt?(e=Dt,me+=10):(e=n,0===$e&&Oe(Ut))));e!==n&&$n()!==n&&(s=Qe())!==n&&wn()!==n&&(a=Qe())!==n&&En()!==n?(r,r=e={func:e,args:[s,a]}):(me=r,r=n);$e--,r===n&&(e=n,0===$e&&Oe(Rt));return r}(),a!==n&&(s,a=function(t,r){t.push(r)}(e,a)),(s=a)===n&&(s=me,(a=gn())!==n&&(s,a=M(e,a)),s=a)))),s!==n){for(a=[],u=me,(o=en())===n&&(o=sn()),o!==n&&(c=Ue())!==n?(u,u=o=P(e,o,c)):(me=u,u=n);u!==n;)a.push(u),u=me,(o=en())===n&&(o=sn()),o!==n&&(c=Ue())!==n?(u,u=o=P(e,o,c)):(me=u,u=n);a!==n?(r,r=e=e):(me=r,r=n)}else me=r,r=n;else me=r,r=n;return r}function Me(){var r,e,s,a,c,i,f;if(r=me,e=me,(s=yn())!==n&&(e,s=[s]),(e=s)!==n)if(47===t.charCodeAt(me)?(s=u,me++):(s=n,0===$e&&Oe(o)),s!==n){for(a=[],c=me,(i=yn())!==n?(47===t.charCodeAt(me)?(f=u,me++):(f=n,0===$e&&Oe(o)),f!==n?(c,c=i=G(e,i)):(me=c,c=n)):(me=c,c=n);c!==n;)a.push(c),c=me,(i=yn())!==n?(47===t.charCodeAt(me)?(f=u,me++):(f=n,0===$e&&Oe(o)),f!==n?(c,c=i=G(e,i)):(me=c,c=n)):(me=c,c=n);a!==n?(c=me,i=function(){var r,e,s;r=me,t.substr(me,3)===Q?(e=Q,me+=3):(e=n,0===$e&&Oe(V));e!==n&&$n()!==n?((s=Ge())===n&&(s=null),s!==n&&En()!==n?(r,r=e=s):(me=r,r=n)):(me=r,r=n);return r}(),i!==n&&(c,i=function(t,r){let e=t.pop();if(!r)return["exists",{ref:[...t,{id:e}]}];let n=[];for(let t=0,s=0;t<r.length;++t){let a=r[t];a.ref&&0===a.ref.length&&"="===r[t+1]?n[s++]={func:"contains",args:[{ref:e},r[t+=2]]}:n[s++]=a}return n.length<r.length?(e=t.pop(),["exists",{ref:[...t,{id:e,where:n}]}]):["exists",{ref:[...t,{id:e,where:r}]}]}(e,i)),(c=i)===n&&(c=me,i=function(){var r,e,s;r=me,t.substr(me,3)===W?(e=W,me+=3):(e=n,0===$e&&Oe(X));e!==n&&$n()!==n&&(s=Ge())!==n&&En()!==n?(r,r=e=s):(me=r,r=n);return r}(),i!==n&&(c,i=function(t,r){let e=t.pop();return["not","exists",{ref:[...t,{id:e,where:["not",{xpr:[...r]}]}]}]}(e,i)),c=i),c!==n?(r,r=e=c):(me=r,r=n)):(me=r,r=n)}else me=r,r=n;else me=r,r=n;return r}function Pe(){var t,r,e,s,a,u,o,c,i;if(t=me,r=me,(e=rn())===n&&(e=null),e!==n&&(r,e=(c=e)?[c]:[]),(r=e)!==n)if(e=me,(s=$n())!==n&&(a=Pe())!==n&&(u=En())!==n?(e,i=a,e=s=void r.push("(",...i,")")):(me=e,e=n),e===n&&(e=me,(s=Ke())!==n&&(e,s=function(t,r){t.push(...r)}(r,s)),(e=s)===n&&(e=me,(s=Me())!==n&&(e,s=function(t,r){t.push(...r)}(r,s)),e=s)),e!==n){for(s=[],a=me,(u=en())===n&&(u=sn()),u!==n&&(o=Pe())!==n?(a,a=u=H(r,u,o)):(me=a,a=n);a!==n;)s.push(a),a=me,(u=en())===n&&(u=sn()),u!==n&&(o=Pe())!==n?(a,a=u=H(r,u,o)):(me=a,a=n);s!==n?(t,t=r=r):(me=t,t=n)}else me=t,t=n;else me=t,t=n;return t}function Ge(){var r,e,s,a;return r=me,(e=yn())!==n?(58===t.charCodeAt(me)?(s=J,me++):(s=n,0===$e&&Oe(K)),s!==n&&(a=Pe())!==n?(r,r=e=function(t,r){for(const e of r)e.ref&&e.ref[0]===t&&e.ref.shift();return r}(e,a)):(me=r,r=n)):(me=r,r=n),r}function He(){var r,e,s,a,u;return r=me,(e=tn())===n&&(e=Ve()),e!==n?(s=me,Bn()!==n?(a=me,"asc"===t.substr(me,3)?(u="asc",me+=3):(u=n,0===$e&&Oe(Y)),u===n&&(t.substr(me,4)===tt?(u=tt,me+=4):(u=n,0===$e&&Oe(rt))),(a=u!==n?t.substring(a,me):u)!==n?(s,s=a):(me=s,s=n)):(me=s,s=n),s===n&&(s=null),s!==n?(r,r=e=function(t,r){const e=zn(t,r&&{sort:r});Fn.orderBy=Fn.orderBy?[...Fn.orderBy,e]:[e]}(e,s)):(me=r,r=n)):(me=r,r=n),r}function Je(){var r,e,s,a,c,i;if(r=me,(e=an())!==n){for(s=[],a=me,47===t.charCodeAt(me)?(c=u,me++):(c=n,0===$e&&Oe(o)),c!==n&&(i=an())!==n?a=c=[c,i]:(me=a,a=n);a!==n;)s.push(a),a=me,47===t.charCodeAt(me)?(c=u,me++):(c=n,0===$e&&Oe(o)),c!==n&&(i=an())!==n?a=c=[c,i]:(me=a,a=n);s!==n?r=e=[e,s]:(me=r,r=n)}else me=r,r=n;return r}function Ke(){var r,e,s,a,u,o;return $e++,r=me,(e=Qe())!==n&&Bn()!==n?(s=me,"eq"===t.substr(me,2)?(a="eq",me+=2):(a=n,0===$e&&Oe(it)),a===n&&("ne"===t.substr(me,2)?(a="ne",me+=2):(a=n,0===$e&&Oe(ft)),a===n&&("lt"===t.substr(me,2)?(a="lt",me+=2):(a=n,0===$e&&Oe(lt)),a===n&&("gt"===t.substr(me,2)?(a="gt",me+=2):(a=n,0===$e&&Oe(ht)),a===n&&("le"===t.substr(me,2)?(a="le",me+=2):(a=n,0===$e&&Oe(pt)),a===n&&("ge"===t.substr(me,2)?(a="ge",me+=2):(a=n,0===$e&&Oe(At))))))),(s=a!==n?t.substring(s,me):a)!==n&&(a=Bn())!==n&&(u=Qe())!==n?(r,r=e=[e,{eq:"=",ne:"!=",lt:"<",gt:">",le:"<=",ge:">="}[o=s]||o,u]):(me=r,r=n)):(me=r,r=n),$e--,r===n&&(e=n,0===$e&&Oe(ct)),r}function Qe(){var r;return $e++,r=function(){var r,e,s,a,c,i,h;$e++,r=me,e=[],s=me,(a=yn())!==n?(c=me,(i=$n())!==n&&(h=je())!==n&&En()!==n?(c,c=i=vt(0,h)):(me=c,c=n),c===n&&(c=null),c!==n?(47===t.charCodeAt(me)?(i=u,me++):(i=n,0===$e&&Oe(o)),i!==n?(s,s=a=bt(a,c)):(me=s,s=n)):(me=s,s=n)):(me=s,s=n);if(s!==n)for(;s!==n;)e.push(s),s=me,(a=yn())!==n?(c=me,(i=$n())!==n&&(h=je())!==n&&En()!==n?(c,c=i=vt(0,h)):(me=c,c=n),c===n&&(c=null),c!==n?(47===t.charCodeAt(me)?(i=u,me++):(i=n,0===$e&&Oe(o)),i!==n?(s,s=a=bt(a,c)):(me=s,s=n)):(me=s,s=n)):(me=s,s=n);else e=n;e!==n?(t.substr(me,6)===f?(s=f,me+=6):(s=n,0===$e&&Oe(l)),s!==n?(r,r=e={func:"count",as:"$count",args:[{ref:e}]}):(me=r,r=n)):(me=r,r=n);$e--,r===n&&(e=n,0===$e&&Oe(gt));return r}(),r===n&&(r=tn())===n&&(r=Ve())===n&&(r=We())===n&&(r=Xe())===n&&(r=Ye())===n&&(r=function(){var r,e,s,a,u;r=me,91===t.charCodeAt(me)?(e=St,me++):(e=n,0===$e&&Oe(Bt));if(e!==n){for(s=me,a=[],Ot.test(t.charAt(me))?(u=t.charAt(me),me++):(u=n,0===$e&&Oe(Tt));u!==n;)a.push(u),Ot.test(t.charAt(me))?(u=t.charAt(me),me++):(u=n,0===$e&&Oe(Tt));(s=a!==n?t.substring(s,me):a)!==n?(93===t.charCodeAt(me)?(a=zt,me++):(a=n,0===$e&&Oe(Zt)),a!==n?(r,r=e={list:s.replace(/"/g,"").split(",").map((t=>({val:t})))}):(me=r,r=n)):(me=r,r=n)}else me=r,r=n;return r}()),$e--,r===n&&(n,0===$e&&Oe(dt)),r}function Ve(){var r,e,s,a,c,i,f,l;if($e++,r=me,(e=yn())!==n){for(s=[],a=me,47===t.charCodeAt(me)?(c=u,me++):(c=n,0===$e&&Oe(o)),c!==n&&(i=yn())!==n?(a,a=c=mt(0,i)):(me=a,a=n);a!==n;)s.push(a),a=me,47===t.charCodeAt(me)?(c=u,me++):(c=n,0===$e&&Oe(o)),c!==n&&(i=yn())!==n?(a,a=c=mt(0,i)):(me=a,a=n);s!==n?(r,l=s,r=e="null"===(f=e)?{val:null}:{ref:[f,...l]}):(me=r,r=n)}else me=r,r=n;return $e--,r===n&&(e=n,0===$e&&Oe(yt)),r}function We(){var r,e,s;return r=me,(e=gn())===n&&(e=function(){var r,e,s,a,u,o,c,i,f,l,h,p,A,d,g,v,b,y,m,C,x,w,$,E;r=me,e=me,s=[],Jr.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(Kr));if(a!==n)for(;a!==n;)s.push(a),Jr.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(Kr));else s=n;if(s!==n)if(45===t.charCodeAt(me)?(a=Qr,me++):(a=n,0===$e&&Oe(Vr)),a!==n)if(Jr.test(t.charAt(me))?(u=t.charAt(me),me++):(u=n,0===$e&&Oe(Kr)),u!==n)if(Jr.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe(Kr)),o!==n)if(45===t.charCodeAt(me)?(c=Qr,me++):(c=n,0===$e&&Oe(Vr)),c!==n)if(Jr.test(t.charAt(me))?(i=t.charAt(me),me++):(i=n,0===$e&&Oe(Kr)),i!==n)if(Jr.test(t.charAt(me))?(f=t.charAt(me),me++):(f=n,0===$e&&Oe(Kr)),f!==n){if(l=me,84===t.charCodeAt(me)?(h="T",me++):(h=n,0===$e&&Oe(Wr)),h!==n)if(Jr.test(t.charAt(me))?(p=t.charAt(me),me++):(p=n,0===$e&&Oe(Kr)),p!==n)if(Jr.test(t.charAt(me))?(A=t.charAt(me),me++):(A=n,0===$e&&Oe(Kr)),A!==n)if(58===t.charCodeAt(me)?(d=J,me++):(d=n,0===$e&&Oe(K)),d!==n)if(Jr.test(t.charAt(me))?(g=t.charAt(me),me++):(g=n,0===$e&&Oe(Kr)),g!==n)if(Jr.test(t.charAt(me))?(v=t.charAt(me),me++):(v=n,0===$e&&Oe(Kr)),v!==n){if(b=me,58===t.charCodeAt(me)?(y=J,me++):(y=n,0===$e&&Oe(K)),y!==n)if(Jr.test(t.charAt(me))?(m=t.charAt(me),me++):(m=n,0===$e&&Oe(Kr)),m!==n)if(Jr.test(t.charAt(me))?(C=t.charAt(me),me++):(C=n,0===$e&&Oe(Kr)),C!==n){if(x=me,46===t.charCodeAt(me)?(w=".",me++):(w=n,0===$e&&Oe(Yr)),w!==n){if($=[],Jr.test(t.charAt(me))?(E=t.charAt(me),me++):(E=n,0===$e&&Oe(Kr)),E!==n)for(;E!==n;)$.push(E),Jr.test(t.charAt(me))?(E=t.charAt(me),me++):(E=n,0===$e&&Oe(Kr));else $=n;$!==n?x=w=[w,$]:(me=x,x=n)}else me=x,x=n;x===n&&(x=null),x!==n?b=y=[y,m,C,x]:(me=b,b=n)}else me=b,b=n;else me=b,b=n;else me=b,b=n;b===n&&(b=null),b!==n?(90===t.charCodeAt(me)?(y="Z",me++):(y=n,0===$e&&Oe(te)),y===n&&(y=me,43===t.charCodeAt(me)?(m="+",me++):(m=n,0===$e&&Oe(re)),m===n&&(45===t.charCodeAt(me)?(m=Qr,me++):(m=n,0===$e&&Oe(Vr))),m!==n?(Jr.test(t.charAt(me))?(C=t.charAt(me),me++):(C=n,0===$e&&Oe(Kr)),C!==n?(Jr.test(t.charAt(me))?(x=t.charAt(me),me++):(x=n,0===$e&&Oe(Kr)),x!==n?(58===t.charCodeAt(me)?(w=J,me++):(w=n,0===$e&&Oe(K)),w!==n?(Jr.test(t.charAt(me))?($=t.charAt(me),me++):($=n,0===$e&&Oe(Kr)),$!==n?(Jr.test(t.charAt(me))?(E=t.charAt(me),me++):(E=n,0===$e&&Oe(Kr)),E!==n?y=m=[m,C,x,w,$,E]:(me=y,y=n)):(me=y,y=n)):(me=y,y=n)):(me=y,y=n)):(me=y,y=n)):(me=y,y=n)),y===n&&(y=null),y!==n?l=h=[h,p,A,d,g,v,b,y]:(me=l,l=n)):(me=l,l=n)}else me=l,l=n;else me=l,l=n;else me=l,l=n;else me=l,l=n;else me=l,l=n;else me=l,l=n;l===n&&(l=null),l!==n?e=s=[s,a,u,o,c,i,f,l]:(me=e,e=n)}else me=e,e=n;else me=e,e=n;else me=e,e=n;else me=e,e=n;else me=e,e=n;else me=e,e=n;else me=e,e=n;r=e!==n?t.substring(r,me):e;return r}()),e!==n&&(r,e=Ct(e)),(r=e)===n&&(r=me,(e=mn())!==n&&(r,e=Ct(e)),(r=e)===n&&(r=me,e=function(){var r,e,s,a,u,o,c,i,f,l;r=me,e=me,s=me,ee.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(ne));a===n&&(a=null);if(a!==n){if(u=[],Jr.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe(Kr)),o!==n)for(;o!==n;)u.push(o),Jr.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe(Kr));else u=n;if(u!==n){if(o=me,46===t.charCodeAt(me)?(c=Xr,me++):(c=n,0===$e&&Oe(Yr)),c!==n){if(i=[],Jr.test(t.charAt(me))?(f=t.charAt(me),me++):(f=n,0===$e&&Oe(Kr)),f!==n)for(;f!==n;)i.push(f),Jr.test(t.charAt(me))?(f=t.charAt(me),me++):(f=n,0===$e&&Oe(Kr));else i=n;i!==n?o=c=[c,i]:(me=o,o=n)}else me=o,o=n;if(o===n&&(o=null),o!==n){if(c=me,101===t.charCodeAt(me)?(i="e",me++):(i=n,0===$e&&Oe(se)),i!==n){if(f=[],Jr.test(t.charAt(me))?(l=t.charAt(me),me++):(l=n,0===$e&&Oe(Kr)),l!==n)for(;l!==n;)f.push(l),Jr.test(t.charAt(me))?(l=t.charAt(me),me++):(l=n,0===$e&&Oe(Kr));else f=n;f!==n?c=i=[i,f]:(me=c,c=n)}else me=c,c=n;c===n&&(c=null),c!==n?s=a=[a,u,o,c]:(me=s,s=n)}else me=s,s=n}else me=s,s=n}else me=s,s=n;e=s!==n?t.substring(e,me):s;e!==n&&(r,e=kn(e));return r=e}(),e!==n&&(r,e="number"==typeof(s=e)?{val:s}:{val:s,literal:"number"}),(r=e)===n&&(r=me,(e=vn())!==n&&(r,e=Ct(e)),r=e))),r}function Xe(){var r,e,s,a,u,o;if(r=me,e=me,s=me,123===t.charCodeAt(me)?(a="{",me++):(a=n,0===$e&&Oe(xt)),a!==n){for(u=[],(o=Xe())===n&&(wt.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe($t)));o!==n;)u.push(o),(o=Xe())===n&&(wt.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe($t)));u!==n?(125===t.charCodeAt(me)?(o="}",me++):(o=n,0===$e&&Oe(Et)),o!==n?s=a=[a,u,o]:(me=s,s=n)):(me=s,s=n)}else me=s,s=n;return(e=s!==n?t.substring(e,me):s)!==n&&(r,e=Ct(e)),r=e}function Ye(){var r,e,s,a,u,o,c,i;if(r=me,e=me,s=me,91===t.charCodeAt(me)?(a=St,me++):(a=n,0===$e&&Oe(Bt)),a!==n&&(u=Sn())!==n?(93===t.charCodeAt(me)?(o=zt,me++):(o=n,0===$e&&Oe(Zt)),o!==n?s=a=[a,u,o]:(me=s,s=n)):(me=s,s=n),s===n)if(s=me,91===t.charCodeAt(me)?(a=St,me++):(a=n,0===$e&&Oe(Bt)),a!==n)if((u=Sn())!==n)if(123===t.charCodeAt(me)?(o="{",me++):(o=n,0===$e&&Oe(xt)),o!==n){for(c=[],(i=Ye())===n&&(Ot.test(t.charAt(me))?(i=t.charAt(me),me++):(i=n,0===$e&&Oe(Tt)));i!==n;)c.push(i),(i=Ye())===n&&(Ot.test(t.charAt(me))?(i=t.charAt(me),me++):(i=n,0===$e&&Oe(Tt)));c!==n?(93===t.charCodeAt(me)?(i=zt,me++):(i=n,0===$e&&Oe(Zt)),i!==n?s=a=[a,u,o,c,i]:(me=s,s=n)):(me=s,s=n)}else me=s,s=n;else me=s,s=n;else me=s,s=n;return(e=s!==n?t.substring(e,me):s)!==n&&(r,e=Ct(e)),r=e}function tn(){var r,e,s,a,u,o,c;if($e++,r=me,e=me,s=[],Lt.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(jt)),a!==n)for(;a!==n;)s.push(a),Lt.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(jt));else s=n;if((e=s!==n?t.substring(e,me):s)!==n)if((s=$n())!==n)if((a=Qe())!==n){for(u=[],o=me,wn()!==n&&(c=Qe())!==n?(o,o=kt(0,0,c)):(me=o,o=n);o!==n;)u.push(o),o=me,wn()!==n&&(c=Qe())!==n?(o,o=kt(0,0,c)):(me=o,o=n);u!==n&&(o=En())!==n?(r,r=e=function(t,r,e){if(Zn&&!(t in Zn.functions))throw Object.assign(new Error(`"${t}" is an unknown function in OData URL spec (strict mode)`),{statusCode:400});return{func:t,args:[r,...e]}}(e,a,u)):(me=r,r=n)}else me=r,r=n;else me=r,r=n;else me=r,r=n;return $e--,r===n&&(e=n,0===$e&&Oe(Ft)),r}function rn(){var r,e;return r=me,Sn()!==n?("not"===t.substr(me,3).toLowerCase()?(e=t.substr(me,3),me+=3):(e=n,0===$e&&Oe(Mt)),e!==n&&Bn()!==n?(r,r="not"):(me=r,r=n)):(me=r,r=n),r}function en(){var r,e;return r=me,Bn()!==n?("and"===t.substr(me,3).toLowerCase()?(e=t.substr(me,3),me+=3):(e=n,0===$e&&Oe(Pt)),e!==n&&Bn()!==n?(r,r="and"):(me=r,r=n)):(me=r,r=n),r}function nn(){var t,r;return t=me,(r=Bn())!==n&&(t,r="and"),t=r}function sn(){var r,e;return r=me,Bn()!==n?("or"===t.substr(me,2).toLowerCase()?(e=t.substr(me,2),me+=2):(e=n,0===$e&&Oe(Gt)),e!==n&&Bn()!==n?(r,r="or"):(me=r,r=n)):(me=r,r=n),r}function an(){var r,e,s;return r=me,t.substr(me,9)===Ht?(e=Ht,me+=9):(e=n,0===$e&&Oe(Jt)),e!==n?(s=function(){var t,r,e,s,a;if(t=me,$n()!==n)if(Sn()!==n)if((r=un())!==n){for(e=[],s=me,Sn()!==n&&wn()!==n&&Sn()!==n&&(a=un())!==n?(s,s=v(0,a)):(me=s,s=n);s!==n;)e.push(s),s=me,Sn()!==n&&wn()!==n&&Sn()!==n&&(a=un())!==n?(s,s=v(0,a)):(me=s,s=n);e!==n&&(s=Sn())!==n&&En()!==n?(t,t=function(t,r){let e=Fn.apply;e.aggregate&&(Fn.apply={apply:e},e.groupBy&&(Fn.apply.groupBy=e.groupBy),e=Fn.apply),e.aggregate=[t,...r]}(r,e)):(me=t,t=n)}else me=t,t=n;else me=t,t=n;else me=t,t=n;return t}(),s!==n?r=e=[e,s]:(me=r,r=n)):(me=r,r=n),r===n&&(r=me,t.substr(me,7)===Kt?(e=Kt,me+=7):(e=n,0===$e&&Oe(Qt)),e!==n?(s=function(){var t,r,e,s,a,u,o,c,i;if(t=me,(r=$n())!==n)if((e=$n())!==n)if((s=hn())!==n){for(a=[],u=me,(o=wn())!==n&&(c=hn())!==n?(u,u=o=v(0,c)):(me=u,u=n);u!==n;)a.push(u),u=me,(o=wn())!==n&&(c=hn())!==n?(u,u=o=v(0,c)):(me=u,u=n);a!==n?(u=me,(o=En())!==n&&(u,o=function(t,r){let e=Fn.apply;(e.groupBy||e.where||e.search)&&(Fn.apply={apply:e},e=Fn.apply),e.groupBy=[t,...r]}(s,a)),(u=o)!==n?(o=me,(c=wn())!==n&&(i=Je())!==n?o=c=[c,i]:(me=o,o=n),o===n&&(o=null),o!==n&&(c=En())!==n?t=r=[r,e,s,a,u,o,c]:(me=t,t=n)):(me=t,t=n)):(me=t,t=n)}else me=t,t=n;else me=t,t=n;else me=t,t=n;return t}(),s!==n?r=e=[e,s]:(me=r,r=n)):(me=r,r=n),r===n&&(r=me,t.substr(me,6)===Vt?(e=Vt,me+=6):(e=n,0===$e&&Oe(Wt)),e!==n&&(s=pn())!==n?r=e=[e,s]:(me=r,r=n),r===n&&(r=me,t.substr(me,6)===Xt?(e=Xt,me+=6):(e=n,0===$e&&Oe(Yt)),e!==n&&(s=An())!==n?r=e=[e,s]:(me=r,r=n),r===n&&(r=me,t.substr(me,6)===tr?(e=tr,me+=6):(e=n,0===$e&&Oe(rr)),e!==n?(s=function(){var t,r,e,s,a,u;t=me,(r=$n())!==n&&(e=Sn())!==n?(s=me,(a=qe())!==n&&(s,a=function(t){if(!t)return;let r=Fn.apply;r.search&&(Fn.apply={apply:r},r=Fn.apply),r.search=t}(a)),(s=a)!==n&&(a=Sn())!==n&&(u=En())!==n?t=r=[r,e,s,a,u]:(me=t,t=n)):(me=t,t=n);return t}(),s!==n?r=e=[e,s]:(me=r,r=n)):(me=r,r=n),r===n&&(r=me,t.substr(me,6)===er?(e=er,me+=6):(e=n,0===$e&&Oe(nr)),e!==n?(s=function(){var t,r,e,s,a,u,o,c,i,f;if(t=me,(r=$n())!==n)if((e=Sn())!==n)if((s=Je())!==n){if(a=[],u=me,(o=Sn())!==n&&(c=wn())!==n&&(i=Sn())!==n&&(f=Je())!==n?u=o=[o,c,i,f]:(me=u,u=n),u!==n)for(;u!==n;)a.push(u),u=me,(o=Sn())!==n&&(c=wn())!==n&&(i=Sn())!==n&&(f=Je())!==n?u=o=[o,c,i,f]:(me=u,u=n);else a=n;a!==n&&(u=Sn())!==n&&(o=En())!==n?t=r=[r,e,s,a,u,o]:(me=t,t=n)}else me=t,t=n;else me=t,t=n;else me=t,t=n;return t}(),s!==n?r=e=[e,s]:(me=r,r=n)):(me=r,r=n),r===n&&(r=me,t.substr(me,7)===sr?(e=sr,me+=7):(e=n,0===$e&&Oe(ar)),e!==n?(s=function(){var t,r,e,s,a,u,o,c,i,f;if(t=me,(r=$n())!==n)if((e=Sn())!==n)if((s=dn())!==n){for(a=[],u=me,(o=Sn())!==n&&(c=wn())!==n&&(i=Sn())!==n&&(f=dn())!==n?u=o=[o,c,i,f]:(me=u,u=n);u!==n;)a.push(u),u=me,(o=Sn())!==n&&(c=wn())!==n&&(i=Sn())!==n&&(f=dn())!==n?u=o=[o,c,i,f]:(me=u,u=n);a!==n&&(u=Sn())!==n&&(o=En())!==n?t=r=[r,e,s,a,u,o]:(me=t,t=n)}else me=t,t=n;else me=t,t=n;else me=t,t=n;return t}(),s!==n?r=e=[e,s]:(me=r,r=n)):(me=r,r=n),r===n&&(r=me,t.substr(me,8)===ur?(e=ur,me+=8):(e=n,0===$e&&Oe(or)),e===n&&(t.substr(me,11)===cr?(e=cr,me+=11):(e=n,0===$e&&Oe(ir)),e===n&&(t.substr(me,6)===fr?(e=fr,me+=6):(e=n,0===$e&&Oe(lr)),e===n&&(t.substr(me,9)===hr?(e=hr,me+=9):(e=n,0===$e&&Oe(pr)),e===n&&(t.substr(me,10)===Ar?(e=Ar,me+=10):(e=n,0===$e&&Oe(dr)),e===n&&(t.substr(me,13)===gr?(e=gr,me+=13):(e=n,0===$e&&Oe(vr))))))),e!==n?(s=function(){var t,r,e;t=me,$n()!==n&&Sn()!==n&&(r=Qe())!==n&&Sn()!==n&&wn()!==n&&Sn()!==n&&(e=Qe())!==n&&Sn()!==n&&En()!==n?(t,t=[r,e]):(me=t,t=n);return t}(),s!==n?(r,r=e=function(t,r){if(!{topcount:!0,bottomcount:!0,topsum:!1,bottomsum:!1,toppercent:!1,bottompercent:!1}[t])throw Object.assign(new Error(`Transformation "${t}" in $apply is not supported yet.`),{statusCode:501});(Fn.apply.aggregate||(Fn.apply.aggregate=[])).push({func:t,args:r})}(e,s)):(me=r,r=n)):(me=r,r=n),r===n&&(r=function(){var r;t.substr(me,8)===Br?(r=Br,me+=8):(r=n,0===$e&&Oe(zr));return r}())))))))),r}function un(){var r,e,s,a;return r=me,e=me,t.substr(me,6)===f?(s=f,me+=6):(s=n,0===$e&&Oe(l)),s!==n&&(a=ln())!==n?(e,e=s={func:"count",args:[{val:1}],as:a}):(me=e,e=n),e===n&&(e=on()),e!==n&&(r,e=e),r=e}function on(){var t,r,e,s,a;return t=me,(r=Ve())!==n&&(e=cn())!==n?((s=fn())===n&&(s=null),s!==n&&(a=ln())!==n?(t,t=r={func:e,args:[r],as:a}):(me=t,t=n)):(me=t,t=n),t===n&&(t=me,(r=yn())!==n&&(e=$n())!==n&&(s=on())!==n&&(a=En())!==n?t=r=[r,e,s,a]:(me=t,t=n)),t}function cn(){var r,e,s,a,u;if(r=me,Bn()!==n)if(t.substr(me,4)===br?(e=br,me+=4):(e=n,0===$e&&Oe(yr)),e!==n)if(Bn()!==n){if(s=me,a=[],Lt.test(t.charAt(me))?(u=t.charAt(me),me++):(u=n,0===$e&&Oe(jt)),u!==n)for(;u!==n;)a.push(u),Lt.test(t.charAt(me))?(u=t.charAt(me),me++):(u=n,0===$e&&Oe(jt));else a=n;(s=a!==n?t.substring(s,me):a)!==n?(r,r=s):(me=r,r=n)}else me=r,r=n;else me=r,r=n;else me=r,r=n;return r}function fn(){var r,e,s,a,u,o,c;return r=me,(e=Bn())!==n?(t.substr(me,4)===mr?(s=mr,me+=4):(s=n,0===$e&&Oe(Cr)),s!==n&&(a=Bn())!==n&&(u=Ve())!==n&&(o=cn())!==n?((c=fn())===n&&(c=null),c!==n?r=e=[e,s,a,u,o,c]:(me=r,r=n)):(me=r,r=n)):(me=r,r=n),r}function ln(){var r,e,s;return r=me,Bn()!==n?("as"===t.substr(me,2)?(e="as",me+=2):(e=n,0===$e&&Oe(xr)),e!==n&&Bn()!==n&&(s=yn())!==n?(r,r=s):(me=r,r=n)):(me=r,r=n),r}function hn(){var r,e;return r=me,e=function(){var r,e,s,a,u,o,c,i,f,l,h;r=me,e=me,t.substr(me,6)===wr?(s=wr,me+=6):(s=n,0===$e&&Oe($r));if(s!==n)if((a=$n())!==n)if((u=Sn())!==n)if(t.substr(me,4)===Er?(o=Er,me+=4):(o=n,0===$e&&Oe(Sr)),o===n&&(o=Ve()),o!==n){if(c=[],i=me,(f=Sn())!==n&&(l=wn())!==n&&(h=Ve())!==n?i=f=[f,l,h]:(me=i,i=n),i!==n)for(;i!==n;)c.push(i),i=me,(f=Sn())!==n&&(l=wn())!==n&&(h=Ve())!==n?i=f=[f,l,h]:(me=i,i=n);else c=n;c!==n&&(i=Sn())!==n&&(f=En())!==n?e=s=[s,a,u,o,c,i,f]:(me=e,e=n)}else me=e,e=n;else me=e,e=n;else me=e,e=n;else me=e,e=n;e!==n&&(r,e=function(t){const r=new Error("Rollup in groupby is not supported yet.");throw r.statusCode=501,r}());return r=e}(),e===n&&(e=Ve()),e!==n&&(r,e=e),r=e}function pn(){var t,r,e,s,a,u;return t=me,(r=$n())!==n&&(e=Sn())!==n?(s=me,(a=De())!==n&&(s,a=function(t){let r=Fn.apply;r.where&&(Fn.apply={apply:r},r=Fn.apply),r.where=t}(a)),(s=a)!==n&&(a=Sn())!==n&&(u=En())!==n?t=r=[r,e,s,a,u]:(me=t,t=n)):(me=t,t=n),t}function An(){var t,r,e,s,a,u,o,c,i,f,l,h,p,A;if(t=me,(r=$n())!==n)if((e=Sn())!==n)if((s=Ve())!==n)if((a=Sn())!==n)if((u=wn())!==n)if((o=Sn())!==n){if(c=me,(i=An())!==n){for(f=[],l=me,(h=Sn())!==n&&(p=wn())!==n&&(A=An())!==n?l=h=[h,p,A]:(me=l,l=n);l!==n;)f.push(l),l=me,(h=Sn())!==n&&(p=wn())!==n&&(A=An())!==n?l=h=[h,p,A]:(me=l,l=n);f!==n?c=i=[i,f]:(me=c,c=n)}else me=c,c=n;if(c===n)if(c=me,(i=pn())!==n){for(f=[],l=me,(h=Sn())!==n&&(p=wn())!==n&&(A=An())!==n?l=h=[h,p,A]:(me=l,l=n);l!==n;)f.push(l),l=me,(h=Sn())!==n&&(p=wn())!==n&&(A=An())!==n?l=h=[h,p,A]:(me=l,l=n);f!==n?c=i=[i,f]:(me=c,c=n)}else me=c,c=n;c!==n&&(i=Sn())!==n&&(f=En())!==n?t=r=[r,e,s,a,u,o,c,i,f]:(me=t,t=n)}else me=t,t=n;else me=t,t=n;else me=t,t=n;else me=t,t=n;else me=t,t=n;else me=t,t=n;return t}function dn(){var t,r,e;return t=me,(r=Ue())!==n&&(e=ln())!==n?t=r=[r,e]:(me=t,t=n),t}function gn(){var r,e;return r=me,t.substr(me,4)===Zr?(e=Zr,me+=4):(e=n,0===$e&&Oe(Or)),e===n&&(t.substr(me,5)===Tr?(e=Tr,me+=5):(e=n,0===$e&&Oe(Fr))),e!==n&&(r,e="true"===e),r=e}function vn(){var r,e,s,a,u;if($e++,r=me,39===t.charCodeAt(me)?(e="'",me++):(e=n,0===$e&&Oe(jr)),e!==n){for(s=me,a=[],t.substr(me,2)===kr?(u=kr,me+=2):(u=n,0===$e&&Oe(Rr)),u===n&&(_r.test(t.charAt(me))?(u=t.charAt(me),me++):(u=n,0===$e&&Oe(Nr)));u!==n;)a.push(u),t.substr(me,2)===kr?(u=kr,me+=2):(u=n,0===$e&&Oe(Rr)),u===n&&(_r.test(t.charAt(me))?(u=t.charAt(me),me++):(u=n,0===$e&&Oe(Nr)));(s=a!==n?t.substring(s,me):a)!==n?(39===t.charCodeAt(me)?(a="'",me++):(a=n,0===$e&&Oe(jr)),a!==n?(r,r=e=s.replace(/''/g,"'")):(me=r,r=n)):(me=r,r=n)}else me=r,r=n;return $e--,r===n&&(e=n,0===$e&&Oe(Lr)),r}function bn(){var r,e,s,a,u,o;if(r=me,e=me,s=me,ee.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(ne)),a===n&&(a=null),a!==n){if(u=[],Jr.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe(Kr)),o!==n)for(;o!==n;)u.push(o),Jr.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe(Kr));else u=n;u!==n?s=a=[a,u]:(me=s,s=n)}else me=s,s=n;return(e=s!==n?t.substring(e,me):s)!==n&&(r,e=parseInt(e)),r=e}function yn(){var r,e,s,a,u,o,c,i;if(r=me,e=me,$e++,s=gn(),$e--,s===n?e=void 0:(me=e,e=n),e!==n)if(s=me,$e++,a=mn(),$e--,a===n?s=void 0:(me=s,s=n),s!==n){if(a=me,u=me,ae.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe(ue)),o!==n){for(c=[],oe.test(t.charAt(me))?(i=t.charAt(me),me++):(i=n,0===$e&&Oe(ce));i!==n;)c.push(i),oe.test(t.charAt(me))?(i=t.charAt(me),me++):(i=n,0===$e&&Oe(ce));c!==n?u=o=[o,c]:(me=u,u=n)}else me=u,u=n;(a=u!==n?t.substring(a,me):u)!==n?(r,r=e=a):(me=r,r=n)}else me=r,r=n;else me=r,r=n;return r}function mn(){var r,e,s,a,u,o,c,i,f,l,h,p,A,d;return r=me,e=me,(s=Cn())!==n&&(a=Cn())!==n?(45===t.charCodeAt(me)?(u=Qr,me++):(u=n,0===$e&&Oe(Vr)),u===n&&(u=null),u!==n&&(o=Cn())!==n?(45===t.charCodeAt(me)?(c=Qr,me++):(c=n,0===$e&&Oe(Vr)),c===n&&(c=null),c!==n&&(i=Cn())!==n?(45===t.charCodeAt(me)?(f=Qr,me++):(f=n,0===$e&&Oe(Vr)),f===n&&(f=null),f!==n&&(l=Cn())!==n?(45===t.charCodeAt(me)?(h=Qr,me++):(h=n,0===$e&&Oe(Vr)),h===n&&(h=null),h!==n&&(p=Cn())!==n&&(A=Cn())!==n&&(d=Cn())!==n?e=s=[s,a,u,o,c,i,f,l,h,p,A,d]:(me=e,e=n)):(me=e,e=n)):(me=e,e=n)):(me=e,e=n)):(me=e,e=n),r=e!==n?t.substring(r,me):e}function Cn(){var r,e,s,a,u,o;return r=me,e=me,ie.test(t.charAt(me))?(s=t.charAt(me),me++):(s=n,0===$e&&Oe(fe)),s!==n?(ie.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(fe)),a!==n?(ie.test(t.charAt(me))?(u=t.charAt(me),me++):(u=n,0===$e&&Oe(fe)),u!==n?(ie.test(t.charAt(me))?(o=t.charAt(me),me++):(o=n,0===$e&&Oe(fe)),o!==n?e=s=[s,a,u,o]:(me=e,e=n)):(me=e,e=n)):(me=e,e=n)):(me=e,e=n),r=e!==n?t.substring(r,me):e}function xn(){var r,e,s,a;if(r=me,e=me,s=[],le.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(he)),a!==n)for(;a!==n;)s.push(a),le.test(t.charAt(me))?(a=t.charAt(me),me++):(a=n,0===$e&&Oe(he));else s=n;return(e=s!==n?t.substring(e,me):s)!==n&&(r,e=Ct(e)),r=e}function wn(){var r,e,s,a;return r=me,(e=Sn())!==n?(44===t.charCodeAt(me)?(s=",",me++):(s=n,0===$e&&Oe(pe)),s!==n&&(a=Sn())!==n?r=e=[e,s,a]:(me=r,r=n)):(me=r,r=n),r}function $n(){var r,e,s,a;return r=me,(e=Sn())!==n?(40===t.charCodeAt(me)?(s="(",me++):(s=n,0===$e&&Oe(Ae)),s!==n&&(a=Sn())!==n?r=e=[e,s,a]:(me=r,r=n)):(me=r,r=n),r}function En(){var r,e,s;return r=me,(e=Sn())!==n?(41===t.charCodeAt(me)?(s=")",me++):(s=n,0===$e&&Oe(de)),s!==n?r=e=[e,s]:(me=r,r=n)):(me=r,r=n),r}function Sn(){var r,e,s;for($e++,r=me,e=[],ve.test(t.charAt(me))?(s=t.charAt(me),me++):(s=n,0===$e&&Oe(be));s!==n;)e.push(s),ve.test(t.charAt(me))?(s=t.charAt(me),me++):(s=n,0===$e&&Oe(be));return r=e!==n?t.substring(r,me):e,$e--,r===n&&(e=n,0===$e&&Oe(ge)),r}function Bn(){var r,e,s;if($e++,r=me,e=[],ve.test(t.charAt(me))?(s=t.charAt(me),me++):(s=n,0===$e&&Oe(be)),s!==n)for(;s!==n;)e.push(s),ve.test(t.charAt(me))?(s=t.charAt(me),me++):(s=n,0===$e&&Oe(be));else e=n;return r=e!==n?t.substring(r,me):e,$e--,r===n&&(e=n,0===$e&&Oe(ye)),r}const zn=Object.assign,{strict:Zn,minimal:On}=r,Tn=[];let Fn,Ln;const jn=["$value"],kn=r.safeNumber||function(t){const r=Number(t);return Number.isSafeInteger(r)?r:t},Rn=t=>r=>t===r||t.as&&r.as&&t.as===r.as||r.as&&t.ref&&r.as===t.ref[t.ref.length-1]||t.ref&&r.ref&&t.ref.join("")===r.ref.join(""),_n=t=>r=>{if(Array.isArray(r))return r.map(_n(t));const e=r.ref&&t.find((t=>t.as&&t.func&&t.as===r.ref[0]));return e||r},Nn=t=>r=>Array.isArray(r)?r.map(Nn(t)):r.ref&&!t.find(Rn(r))?{val:null}:r,qn=(t,r)=>{if(1===r.ref.length)t.find(Rn(r))||t.push(r);else{const e=r.ref.shift(),n=t.find((t=>t.ref&&t.ref[0]===e));if(n)qn(n.expand,r);else{const n={ref:[e],expand:[]};qn(n.expand,r),t.push(n)}}},In=(t,r,e=!1)=>{if(!r)return;if(t.apply&&delete t.apply,(r.apply||r.where&&t.where||r.search&&t.search)&&(t.from={SELECT:{from:t.from}}),r.where&&(t.where?t.from.SELECT.where=r.where:t.where=r.where),r.search&&(t.search?t.from.SELECT.search=r.search:t.search=r.search),r.groupBy){t.groupBy=[];for(const e of r.groupBy)t.groupBy.find(Rn(e))||t.groupBy.push(e)}const n=[...t.groupBy||[],...r.aggregate||[]];n.length&&(t.columns=t.columns&&!e?t.columns.reduce(((t,r)=>{const e=n.find(Rn(r));return e&&t.push(e),t}),[]):n,t.where&&(t.where=t.where.map(_n(t.columns)),t.groupBy&&(t.having=t.where.map(Nn(t.groupBy)),delete t.where)),t.columns=t.columns.reduce(((t,r)=>(r.ref&&r.ref.length>1&&n.find(Rn(r))?qn(t,{ref:[...r.ref]}):t.push(r),t)),[])),r.apply&&In(t.from.SELECT,r.apply)};if((e=a())!==n&&me===t.length)return e;throw e!==n&&me<t.length&&Oe({type:"end"}),Te(we,xe<t.length?t.charAt(xe):null,xe<t.length?Ze(xe,xe+1):Ze(xe,xe))}peg$subclass(peg$SyntaxError,Error),peg$SyntaxError.buildMessage=function(t,r){var e={literal:function(t){return'"'+s(t.text)+'"'},class:function(t){var r,e="";for(r=0;r<t.parts.length;r++)e+=t.parts[r]instanceof Array?a(t.parts[r][0])+"-"+a(t.parts[r][1]):a(t.parts[r]);return"["+(t.inverted?"^":"")+e+"]"},any:function(t){return"any character"},end:function(t){return"end of input"},other:function(t){return t.description}};function n(t){return t.charCodeAt(0).toString(16).toUpperCase()}function s(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}function a(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}return"Expected "+function(t){var r,n,s,a=new Array(t.length);for(r=0;r<t.length;r++)a[r]=(s=t[r],e[s.type](s));if(a.sort(),a.length>0){for(r=1,n=1;r<a.length;r++)a[r-1]!==a[r]&&(a[n]=a[r],n++);a.length=n}switch(a.length){case 1:return a[0];case 2:return a[0]+" or "+a[1];default:return a.slice(0,-1).join(", ")+", or "+a[a.length-1]}}(t)+" but "+function(t){return t?'"'+s(t)+'"':"end of input"}(r)+" found."},module.exports={SyntaxError:peg$SyntaxError,parse:peg$parse};
1
+ "use strict";function peg$subclass(t,r){function e(){this.constructor=t}e.prototype=r.prototype,t.prototype=new e}function peg$SyntaxError(t,r,e,n){this.message=t,this.expected=r,this.found=e,this.location=n,this.name="SyntaxError","function"==typeof Error.captureStackTrace&&Error.captureStackTrace(this,peg$SyntaxError)}function peg$parse(t,r){r=void 0!==r?r:{};var e,n={},s={ODataRelativeURI:Be},a=Be,u="/",o=Ce("/",!1),c=Ce("?",!1),i=Ce("&",!1),f="$count",l=Ce("$count",!1),h="$ref",p=Ce("$ref",!1),A="$value",d=Ce("$value",!1),g=function(t){return[t]},v=function(t,r){return r},b=Ce("=",!1),y="$skiptoken=",m=Ce("$skiptoken=",!1),C="$apply=",w=Ce("$apply=",!1),x="$select=",$=Ce("$select=",!1),E="$expand=",L=Ce("$expand=",!1),S="$filter=",B=Ce("$filter=",!1),O="$orderby=",T=Ce("$orderby=",!1),Z="$top=",z=Ce("$top=",!1),_="$skip=",F=Ce("$skip=",!1),R="$search=",j=Ce("$search=",!1),k="$count=",N=Ce("$count=",!1),U=Ce("*",!1),D=Ce(";",!1),P="/$count",q=Ce("/$count",!1),I=function(t){return t?[t]:[]},M=function(t,r){t.push({xpr:r})},X=function(t,r){t.push({val:r})},G=function(t,r,e){t.push(r,...e)},H=function(t,r){t.push(r)},J=function(t,r,e){t.push(r,...e)},K=":",Q=Ce(":",!1),V="any",W=Ce("any",!1),Y="all",tt=Ce("all",!1),rt=Ce("asc",!1),et="desc",nt=Ce("desc",!1),st=/^[a-zA-Z]/,at=we([["a","z"],["A","Z"]],!1,!1),ut=/^[a-zA-Z0-9\-]/,ot=we([["a","z"],["A","Z"],["0","9"],"-"],!1,!1),ct=/^[^&]/,it=we(["&"],!0,!1),ft=xe("a comparison"),lt=Ce("eq",!1),ht=Ce("ne",!1),pt=Ce("lt",!1),At=Ce("gt",!1),dt=Ce("le",!1),gt=Ce("ge",!1),vt=(Ce("add",!1),Ce("sub",!1),Ce("mul",!1),Ce("div",!1),Ce("mod",!1),xe("an operand")),bt=xe("navigation with $count"),yt=function(t,r){return r},mt=function(t,r){return r?{id:t,where:r}:t},Ct=xe("a reference"),wt=function(t,r){return r},xt=function(t){return{val:t}},$t=Ce("{",!1),Et=/^[^}]/,Lt=we(["}"],!0,!1),St=Ce("}",!1),Bt="[",Ot=Ce("[",!1),Tt="]",Zt=Ce("]",!1),zt=/^[^\]]/,_t=we(["]"],!0,!1),Ft=xe("a function call"),Rt=function(t,r,e){return e},jt=xe("a boolean function"),kt="contains",Nt=Ce("contains",!0),Ut="endswith",Dt=Ce("endswith",!0),Pt="startswith",qt=Ce("startswith",!0),It=Ce("NOT",!0),Mt=Ce("AND",!0),Xt=Ce("OR",!0),Gt="aggregate",Ht=Ce("aggregate",!1),Jt="groupby",Kt=Ce("groupby",!1),Qt="filter",Vt=Ce("filter",!1),Wt="expand",Yt=Ce("expand",!1),tr="search",rr=Ce("search",!1),er="concat",nr=Ce("concat",!1),sr="compute",ar=Ce("compute",!1),ur=Ce("topcount",!0),or=Ce("bottomcount",!0),cr=Ce("topsum",!0),ir=Ce("bottomsum",!0),fr=Ce("toppercent",!0),lr=Ce("bottompercent",!0),hr="with",pr=Ce("with",!1),Ar="from",dr=Ce("from",!1),gr=Ce("as",!1),vr="rollup",br=Ce("rollup",!1),yr="$all",mr=Ce("$all",!1),Cr="identity",wr=Ce("identity",!1),xr="true",$r=Ce("true",!1),Er="false",Lr=Ce("false",!1),Sr=xe("Edm.String"),Br=Ce("'",!1),Or="''",Tr=Ce("''",!1),Zr=/^[^']/,zr=we(["'"],!0,!1),_r='"',Fr=Ce('"',!1),Rr='\\"',jr=Ce('\\"',!1),kr=/^[^"]/,Nr=we(['"'],!0,!1),Ur=/^[^ \t\n()"&;]/,Dr=we([" ","\t","\n","(",")",'"',"&",";"],!0,!1),Pr=/^[0-9]/,qr=we([["0","9"]],!1,!1),Ir="-",Mr=Ce("-",!1),Xr=Ce("T",!1),Gr=".",Hr=Ce(".",!1),Jr=Ce("Z",!1),Kr=Ce("+",!1),Qr=/^[+\-]/,Vr=we(["+","-"],!1,!1),Wr=Ce("e",!1),Yr=/^[_a-zA-Z]/,te=we(["_",["a","z"],["A","Z"]],!1,!1),re=/^[_a-zA-Z0-9"."]/,ee=we(["_",["a","z"],["A","Z"],["0","9"],'"',".",'"'],!1,!1),ne=/^[0-9a-fA-F]/,se=we([["0","9"],["a","f"],["A","F"]],!1,!1),ae=/^[a-zA-Z0-9\-"."_~!$&'()*+,;=:@]/,ue=we([["a","z"],["A","Z"],["0","9"],"-",'"',".",'"',"_","~","!","$","&","'","(",")","*","+",",",";","=",":","@"],!1,!1),oe=/^[a-zA-Z0-9\-"."_~!$'()*+,;=:@"\/""?"]/,ce=we([["a","z"],["A","Z"],["0","9"],"-",'"',".",'"',"_","~","!","$","'","(",")","*","+",",",";","=",":","@",'"',"/",'"','"',"?",'"'],!1,!1),ie=Ce(",",!1),fe=Ce("(",!1),le=Ce(")",!1),he=xe("optional whitespaces"),pe=/^[ \t\n]/,Ae=we([" ","\t","\n"],!1,!1),de=xe("mandatory whitespaces"),ge=0,ve=[{line:1,column:1}],be=0,ye=[],me=0;if("startRule"in r){if(!(r.startRule in s))throw new Error("Can't start parsing from rule \""+r.startRule+'".');a=s[r.startRule]}function Ce(t,r){return{type:"literal",text:t,ignoreCase:r}}function we(t,r,e){return{type:"class",parts:t,inverted:r,ignoreCase:e}}function xe(t){return{type:"other",description:t}}function $e(r){var e,n=ve[r];if(n)return n;for(e=r-1;!ve[e];)e--;for(n={line:(n=ve[e]).line,column:n.column};e<r;)10===t.charCodeAt(e)?(n.line++,n.column=1):n.column++,e++;return ve[r]=n,n}function Ee(t,r){var e=$e(t),n=$e(r);return{start:{offset:t,line:e.line,column:e.column},end:{offset:r,line:n.line,column:n.column}}}function Le(t){ge<be||(ge>be&&(be=ge,ye=[]),ye.push(t))}function Se(t,r,e){return new peg$SyntaxError(peg$SyntaxError.buildMessage(t,r),t,r,e)}function Be(){var r,e,s,a,f,l,h,p,A,d,g,v,b,y;if(r=ge,47===t.charCodeAt(ge)?(e=u,ge++):(e=n,0===me&&Le(o)),e===n&&(e=null),e!==n)if(s=ge,(a=Oe())!==n&&(s,a=void(Bn=a)),(s=a)!==n){if(a=ge,(f=wn())!==n)if(63===t.charCodeAt(ge)?(l="?",ge++):(l=n,0===me&&Le(c)),l!==n)if((h=wn())!==n)if((p=Ze())!==n){for(A=[],d=ge,(g=wn())!==n?(38===t.charCodeAt(ge)?(v="&",ge++):(v=n,0===me&&Le(i)),v!==n&&(b=wn())!==n&&(y=Ze())!==n?d=g=[g,v,b,y]:(ge=d,d=n)):(ge=d,d=n);d!==n;)A.push(d),d=ge,(g=wn())!==n?(38===t.charCodeAt(ge)?(v="&",ge++):(v=n,0===me&&Le(i)),v!==n&&(b=wn())!==n&&(y=Ze())!==n?d=g=[g,v,b,y]:(ge=d,d=n)):(ge=d,d=n);A!==n?a=f=[f,l,h,p,A]:(ge=a,a=n)}else ge=a,a=n;else ge=a,a=n;else ge=a,a=n;else ge=a,a=n;a===n&&(a=null),a!==n&&(f=wn())!==n?(r,r=e=function(){if(On)return Bn.columns=[{args:[{val:1}],as:"$count",func:"count"}],delete Bn.expand,delete Bn.limit,delete Bn.orderBy,Bn.apply&&(Bn.apply={apply:Bn.apply},jn(Bn,Bn.apply)),{SELECT:Bn};let t;if(Bn.expand){Bn.columns||(Bn.columns=["*"],t=!0);for(const t of Bn.expand){const r=Bn.columns.findIndex(zn(t));r>-1&&Bn.columns.splice(r,1),Bn.columns.push(t)}delete Bn.expand}return Bn.count&&Bn.apply&&(Bn.__countAggregated=!0),jn(Bn,Bn.apply,t),{SELECT:Bn}}()):(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n;return r}function Oe(){var r,e,s,a,c,i,b,y;return r=ge,t.substr(ge,6)===f?(e=f,ge+=6):(e=n,0===me&&Le(l)),e!==n&&(r,e=void(On=!0)),(r=e)===n&&(r=ge,e=ge,t.substr(ge,4)===h?(s=h,ge+=4):(s=n,0===me&&Le(p)),s===n&&(t.substr(ge,6)===A?(s=A,ge+=6):(s=n,0===me&&Le(d))),(e=s!==n?t.substring(e,ge):s)!==n&&(r,y=e,e=!Tn.includes(y)&&{from:{ref:[y]}}),(r=e)===n&&(r=ge,e=ge,(s=dn())!==n?(a=ge,(c=mn())!==n&&(i=Cn())!==n?a=c=[c,i]:(ge=a,a=n),a===n&&(a=ge,(c=mn())!==n&&(i=Te())!==n&&(b=Cn())!==n?a=c=[c,i,b]:(ge=a,a=n)),a===n&&(a=null),a!==n?(c=ge,me++,i=bn(),me--,i===n?c=void 0:(ge=c,c=n),c!==n?e=s=[s,a,c]:(ge=e,e=n)):(ge=e,e=n)):(ge=e,e=n),e===n&&(e=ge,s=ge,a=ge,c=ge,me++,i=pn(),me--,i===n?c=void 0:(ge=c,c=n),c!==n&&(i=He())!==n?a=c=[c,i]:(ge=a,a=n),a!==n&&(s,a=a[1]),(s=a)===n&&(s=bn()),s!==n&&(e,s=g(s)),e=s),e!==n?(s=ge,47===t.charCodeAt(ge)?(a=u,ge++):(a=n,0===me&&Le(o)),a!==n&&(c=Oe())!==n?(s,s=a=v(0,c)):(ge=s,s=n),s===n&&(s=null),s!==n?(r,r=e=function(t,r){const[e,n]=t,s=[n?n.length>2?{id:e,where:n[1].map((t=>t.val&&t.val.match&&t.val.match(/^"(.*)"$/)?{val:t.val.match(/^"(.*)"$/)[1]}:t))}:{id:e,where:[]}:Ln?`${"object"==typeof e&&Object.prototype.hasOwnProperty.call(e,"val")?e.val:e}`:e];if(r&&r.from){const t=r.from.ref;Object.prototype.hasOwnProperty.call(t[0],"val")&&(s[s.length-1]={id:s[s.length-1],where:[t.shift()]}),s.push(...t)}const a={from:{ref:s}};return r&&r.columns&&(a.columns=r.columns),a}(e,s)):(ge=r,r=n)):(ge=r,r=n))),r}function Te(){var r,e,s,a,u,o,c;return r=ge,(e=He())!==n&&(r,e=g(e)),(r=e)===n&&(r=ge,(e=Ge())!==n&&wn()!==n?(61===t.charCodeAt(ge)?(s="=",ge++):(s=n,0===me&&Le(b)),s!==n&&wn()!==n&&(a=He())!==n?(u=ge,(o=yn())!==n&&(c=Te())!==n?u=o=[o,c]:(ge=u,u=n),u===n&&(u=null),u!==n?(r,r=e=function(t,r,e){const n=[t,"=",r];return e&&n.push("and",...e[1]),n}(e,a,u)):(ge=r,r=n)):(ge=r,r=n)):(ge=r,r=n)),r}function Ze(){var r,e,s,a;return(r=ze())===n&&(r=ge,t.substr(ge,11)===y?(e=y,ge+=11):(e=n,0===me&&Le(m)),e!==n&&(s=wn())!==n?(a=function(){var r,e,s;r=ge,(e=An())===n&&(e=null);e!==n?(s=function(){var r,e,s;r=ge,e=[],oe.test(t.charAt(ge))?(s=t.charAt(ge),ge++):(s=n,0===me&&Le(ce));if(s!==n)for(;s!==n;)e.push(s),oe.test(t.charAt(ge))?(s=t.charAt(ge),ge++):(s=n,0===me&&Le(ce));else e=n;r=e!==n?t.substring(r,ge):e;return r}(),s===n&&(s=null),s!==n?(r,a=e,r=e=void(s||kn(a))):(ge=r,r=n)):(ge=r,r=n);var a;return r}(),a!==n?r=e=[e,s,a]:(ge=r,r=n)):(ge=r,r=n),r===n&&(r=ge,t.substr(ge,7)===C?(e=C,ge+=7):(e=n,0===me&&Le(w)),e!==n?(s=ge,(a=wn())!==n&&(s,a=void(Bn.apply={})),(s=a)!==n&&(a=Ie())!==n?r=e=[e,s,a]:(ge=r,r=n)):(ge=r,r=n),r===n&&(r=function(){var r,e,s,a,u,o;r=ge,st.test(t.charAt(ge))?(e=t.charAt(ge),ge++):(e=n,0===me&&Le(at));if(e!==n){for(s=[],ut.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(ot));a!==n;)s.push(a),ut.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(ot));if(s!==n)if(61===t.charCodeAt(ge)?(a="=",ge++):(a=n,0===me&&Le(b)),a!==n){for(u=[],ct.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(it));o!==n;)u.push(o),ct.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(it));u!==n?r=e=[e,s,a,u]:(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n}else ge=r,r=n;return r}()))),r}function ze(){var r,e,s,a,u,o,c,i,f,l;if(r=ge,t.substr(ge,8)===x?(e=x,ge+=8):(e=n,0===me&&Le($)),e!==n)if((s=wn())!==n)if((a=_e())!==n){for(u=[],o=ge,(c=yn())!==n&&(i=_e())!==n?o=c=[c,i]:(ge=o,o=n);o!==n;)u.push(o),o=ge,(c=yn())!==n&&(i=_e())!==n?o=c=[c,i]:(ge=o,o=n);u!==n?r=e=[e,s,a,u]:(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n;else ge=r,r=n;if(r===n){if(r=ge,t.substr(ge,8)===E?(e=E,ge+=8):(e=n,0===me&&Le(L)),e!==n)if((s=wn())!==n)if((a=Fe())!==n){for(u=[],o=ge,(c=yn())!==n&&(i=Fe())!==n?o=c=[c,i]:(ge=o,o=n);o!==n;)u.push(o),o=ge,(c=yn())!==n&&(i=Fe())!==n?o=c=[c,i]:(ge=o,o=n);u!==n?r=e=[e,s,a,u]:(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n;else ge=r,r=n;if(r===n&&(r=ge,t.substr(ge,8)===S?(e=S,ge+=8):(e=n,0===me&&Le(B)),e!==n&&(s=wn())!==n&&(a=ke())!==n?(r,l=a,r=e=void(Bn.where=l)):(ge=r,r=n),r===n)){if(r=ge,t.substr(ge,9)===O?(e=O,ge+=9):(e=n,0===me&&Le(T)),e!==n)if((s=wn())!==n)if((a=qe())!==n){for(u=[],o=ge,(c=yn())!==n&&(i=qe())!==n?o=c=[c,i]:(ge=o,o=n);o!==n;)u.push(o),o=ge,(c=yn())!==n&&(i=qe())!==n?o=c=[c,i]:(ge=o,o=n);u!==n?r=e=[e,s,a,u]:(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n;else ge=r,r=n;r===n&&(r=ge,t.substr(ge,5)===Z?(e=Z,ge+=5):(e=n,0===me&&Le(z)),e!==n&&(s=wn())!==n?(a=function(){var t,r;t=ge,(r=An())!==n&&(t,e=r,r=void((Bn.limit||(Bn.limit={})).rows={val:e}));var e;return t=r}(),a!==n?r=e=[e,s,a]:(ge=r,r=n)):(ge=r,r=n),r===n&&(r=ge,t.substr(ge,6)===_?(e=_,ge+=6):(e=n,0===me&&Le(F)),e!==n&&(s=wn())!==n?(a=function(){var t,r;t=ge,(r=An())!==n&&(t,r=void kn(r));return t=r}(),a!==n?r=e=[e,s,a]:(ge=r,r=n)):(ge=r,r=n),r===n&&(r=ge,t.substr(ge,8)===R?(e=R,ge+=8):(e=n,0===me&&Le(j)),e!==n&&(s=wn())!==n&&(a=Re())!==n?(r,r=e=void((f=a)&&(Bn.search=f))):(ge=r,r=n),r===n&&(r=ge,t.substr(ge,7)===k?(e=k,ge+=7):(e=n,0===me&&Le(N)),e!==n&&(s=wn())!==n?(a=function(){var t,r;t=ge,(r=hn())!==n&&(t,r=void(r&&(Bn.count=!0)));return t=r}(),a!==n?r=e=[e,s,a]:(ge=r,r=n)):(ge=r,r=n)))))}}return r}function _e(){var r,e,s;return r=ge,42===t.charCodeAt(ge)?(e="*",ge++):(e=n,0===me&&Le(U)),e===n&&(e=Ge()),e!==n&&(r,s=e,Bn.columns=Array.isArray(Bn.columns)?Bn.columns:[],Bn.columns.find(zn(s))||Bn.columns.push(s),e=s),r=e}function Fe(){var r,e,s,a,u,o,c,i,f,l,h;if(r=ge,e=ge,42===t.charCodeAt(ge)?(s="*",ge++):(s=n,0===me&&Le(U)),s===n&&(s=Ge()),s!==n&&(e,s=function(t){const r="*"===t?{}:t;return r.expand="*",Array.isArray(Bn.expand)||(Bn.expand=[]),Bn.expand.find(zn(r))||Bn.expand.push(r),r}(s)),(e=s)!==n){if(s=ge,a=ge,(u=mn())!==n&&(a,Sn.push(Bn),Bn=Bn.expand[Bn.expand.length-1],u=void(Bn.expand="*")),(a=u)!==n){for(u=ge,o=[],c=ge,(i=wn())!==n?(59===t.charCodeAt(ge)?(f=";",ge++):(f=n,0===me&&Le(D)),f===n&&(f=null),f!==n&&(l=wn())!==n&&(h=ze())!==n?c=i=[i,f,l,h]:(ge=c,c=n)):(ge=c,c=n);c!==n;)o.push(c),c=ge,(i=wn())!==n?(59===t.charCodeAt(ge)?(f=";",ge++):(f=n,0===me&&Le(D)),f===n&&(f=null),f!==n&&(l=wn())!==n&&(h=ze())!==n?c=i=[i,f,l,h]:(ge=c,c=n)):(ge=c,c=n);o!==n&&(u,o=function(t){if(Bn.columns){"*"===Bn.expand&&(Bn.expand=[]);for(const t of Bn.columns)Bn.expand.find(zn(t))||Bn.expand.push(t);delete Bn.columns}else Array.isArray(Bn.expand)&&-1===Bn.expand.indexOf("*")&&Bn.expand.unshift("*")}()),(u=o)!==n?(o=ge,(c=Cn())!==n&&(o,c=void(Bn=Sn.pop())),(o=c)!==n?s=a=[a,u,o]:(ge=s,s=n)):(ge=s,s=n)}else ge=s,s=n;s===n&&(s=null),s!==n?(a=ge,(u=yn())!==n&&(o=Fe())!==n?a=u=[u,o]:(ge=a,a=n),a===n&&(a=null),a!==n?(u=ge,t.substr(ge,7)===P?(o=P,ge+=7):(o=n,0===me&&Le(q)),o!==n&&(u,o=function(){const t=new Error("EXPAND_COUNT_UNSUPPORTED");throw t.statusCode=501,t}()),(u=o)===n&&(u=null),u!==n?r=e=[e,s,a,u]:(ge=r,r=n)):(ge=r,r=n)):(ge=r,r=n)}else ge=r,r=n;return r}function Re(){var t,r;return t=ge,(r=je())!==n&&(t,r=r),(t=r)===n&&(t=wn()),t}function je(){var r,e,s,a,u,o,c;if(r=ge,e=ge,(s=Ve())===n&&(s=null),s!==n&&(e,s=I(s)),(e=s)!==n)if(s=ge,(a=mn())!==n&&(u=je())!==n&&(o=Cn())!==n?(s,s=a=M(e,u)):(ge=s,s=n),s===n&&(s=ge,a=function(){var r,e,s,a,u;r=ge,34===t.charCodeAt(ge)?(e=_r,ge++):(e=n,0===me&&Le(Fr));if(e!==n){for(s=ge,a=[],t.substr(ge,2)===Rr?(u=Rr,ge+=2):(u=n,0===me&&Le(jr)),u===n&&(kr.test(t.charAt(ge))?(u=t.charAt(ge),ge++):(u=n,0===me&&Le(Nr)));u!==n;)a.push(u),t.substr(ge,2)===Rr?(u=Rr,ge+=2):(u=n,0===me&&Le(jr)),u===n&&(kr.test(t.charAt(ge))?(u=t.charAt(ge),ge++):(u=n,0===me&&Le(Nr)));(s=a!==n?t.substring(s,ge):a)!==n?(34===t.charCodeAt(ge)?(a=_r,ge++):(a=n,0===me&&Le(Fr)),a!==n?(r,r=e=s.replace(/\\\\/g,"\\").replace(/\\"/g,'"')):(ge=r,r=n)):(ge=r,r=n)}else ge=r,r=n;return r}(),a!==n&&(s,a=X(e,a)),(s=a)===n&&(s=ge,(a=pn())!==n&&(s,a=X(e,a)),(s=a)===n&&(s=ge,a=function(){var r,e,s;r=ge,e=[],Ur.test(t.charAt(ge))?(s=t.charAt(ge),ge++):(s=n,0===me&&Le(Dr));if(s!==n)for(;s!==n;)e.push(s),Ur.test(t.charAt(ge))?(s=t.charAt(ge),ge++):(s=n,0===me&&Le(Dr));else e=n;r=e!==n?t.substring(r,ge):e;return r}(),a!==n&&(s,a=X(e,a)),s=a))),s!==n){for(a=[],u=ge,(o=We())===n&&(o=tn())===n&&(o=Ye()),o!==n&&(c=je())!==n?(u,u=o=G(e,o,c)):(ge=u,u=n);u!==n;)a.push(u),u=ge,(o=We())===n&&(o=tn())===n&&(o=Ye()),o!==n&&(c=je())!==n?(u,u=o=G(e,o,c)):(ge=u,u=n);a!==n?(r,r=e=e):(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n;return r}function ke(){var t,r;return t=ge,(r=Ne())!==n&&(t,r=r),t=r}function Ne(){var r,e,s,a,u,o,c,i;if(r=ge,e=ge,(s=Ve())===n&&(s=null),s!==n&&(e,s=I(s)),(e=s)!==n)if(s=ge,(a=mn())!==n&&(u=Ne())!==n&&(o=Cn())!==n?(s,s=a=M(e,u)):(ge=s,s=n),s===n&&(s=ge,(a=Me())!==n&&(s,i=a,a=void e.push(...i)),(s=a)===n&&(s=ge,(a=Ue())!==n&&(s,a=function(t,r){t.push(...r)}(e,a)),(s=a)===n&&(s=ge,a=function(){var r,e,s,a;me++,r=ge,t.substr(ge,8).toLowerCase()===kt?(e=t.substr(ge,8),ge+=8):(e=n,0===me&&Le(Nt));e===n&&(t.substr(ge,8).toLowerCase()===Ut?(e=t.substr(ge,8),ge+=8):(e=n,0===me&&Le(Dt)),e===n&&(t.substr(ge,10).toLowerCase()===Pt?(e=t.substr(ge,10),ge+=10):(e=n,0===me&&Le(qt))));e!==n&&mn()!==n&&(s=Xe())!==n&&yn()!==n&&(a=Xe())!==n&&Cn()!==n?(r,u=s,o=a,r=e={func:e.toLowerCase(),args:[u,o]}):(ge=r,r=n);var u,o;me--,r===n&&(e=n,0===me&&Le(jt));return r}(),a!==n&&(s,a=function(t,r){t.push(r)}(e,a)),(s=a)===n&&(s=ge,(a=hn())!==n&&(s,a=X(e,a)),s=a)))),s!==n){for(a=[],u=ge,(o=We())===n&&(o=tn()),o!==n&&(c=Ne())!==n?(u,u=o=G(e,o,c)):(ge=u,u=n);u!==n;)a.push(u),u=ge,(o=We())===n&&(o=tn()),o!==n&&(c=Ne())!==n?(u,u=o=G(e,o,c)):(ge=u,u=n);a!==n?(r,r=e=e):(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n;return r}function Ue(){var r,e,s,a,c,i,f;if(r=ge,e=ge,(s=dn())!==n&&(e,s=[s]),(e=s)!==n)if(47===t.charCodeAt(ge)?(s=u,ge++):(s=n,0===me&&Le(o)),s!==n){for(a=[],c=ge,(i=dn())!==n?(47===t.charCodeAt(ge)?(f=u,ge++):(f=n,0===me&&Le(o)),f!==n?(c,c=i=H(e,i)):(ge=c,c=n)):(ge=c,c=n);c!==n;)a.push(c),c=ge,(i=dn())!==n?(47===t.charCodeAt(ge)?(f=u,ge++):(f=n,0===me&&Le(o)),f!==n?(c,c=i=H(e,i)):(ge=c,c=n)):(ge=c,c=n);a!==n?(c=ge,i=function(){var r,e,s;r=ge,t.substr(ge,3)===V?(e=V,ge+=3):(e=n,0===me&&Le(W));e!==n&&mn()!==n?((s=Pe())===n&&(s=null),s!==n&&Cn()!==n?(r,r=e=s):(ge=r,r=n)):(ge=r,r=n);return r}(),i!==n&&(c,i=function(t,r){let e=t.pop();if(!r)return["exists",{ref:[...t,{id:e}]}];let n=[];for(let t=0,s=0;t<r.length;++t){let a=r[t];a.ref&&0===a.ref.length&&"="===r[t+1]?n[s++]={func:"contains",args:[{ref:e},r[t+=2]]}:n[s++]=a}return n.length<r.length?(e=t.pop(),["exists",{ref:[...t,{id:e,where:n}]}]):["exists",{ref:[...t,{id:e,where:r}]}]}(e,i)),(c=i)===n&&(c=ge,i=function(){var r,e,s;r=ge,t.substr(ge,3)===Y?(e=Y,ge+=3):(e=n,0===me&&Le(tt));e!==n&&mn()!==n&&(s=Pe())!==n&&Cn()!==n?(r,r=e=s):(ge=r,r=n);return r}(),i!==n&&(c,i=function(t,r){let e=t.pop();return["not","exists",{ref:[...t,{id:e,where:["not",{xpr:[...r]}]}]}]}(e,i)),c=i),c!==n?(r,r=e=c):(ge=r,r=n)):(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n;return r}function De(){var t,r,e,s,a,u,o,c,i;if(t=ge,r=ge,(e=Ve())===n&&(e=null),e!==n&&(r,e=(c=e)?[c]:[]),(r=e)!==n)if(e=ge,(s=mn())!==n&&(a=De())!==n&&(u=Cn())!==n?(e,i=a,e=s=void r.push("(",...i,")")):(ge=e,e=n),e===n&&(e=ge,(s=Me())!==n&&(e,s=function(t,r){t.push(...r)}(r,s)),(e=s)===n&&(e=ge,(s=Qe())!==n&&(e,s=function(t,r){t.push(r)}(r,s)),(e=s)===n&&(e=ge,(s=Ue())!==n&&(e,s=function(t,r){t.push(...r)}(r,s)),e=s))),e!==n){for(s=[],a=ge,(u=We())===n&&(u=tn()),u!==n&&(o=De())!==n?(a,a=u=J(r,u,o)):(ge=a,a=n);a!==n;)s.push(a),a=ge,(u=We())===n&&(u=tn()),u!==n&&(o=De())!==n?(a,a=u=J(r,u,o)):(ge=a,a=n);s!==n?(t,t=r=r):(ge=t,t=n)}else ge=t,t=n;else ge=t,t=n;return t}function Pe(){var r,e,s,a;return r=ge,(e=dn())!==n?(58===t.charCodeAt(ge)?(s=K,ge++):(s=n,0===me&&Le(Q)),s!==n&&(a=De())!==n?(r,r=e=Nn(e,a)):(ge=r,r=n)):(ge=r,r=n),r}function qe(){var r,e,s,a,u;return r=ge,(e=Qe())===n&&(e=Ge()),e!==n?(s=ge,xn()!==n?(a=ge,"asc"===t.substr(ge,3)?(u="asc",ge+=3):(u=n,0===me&&Le(rt)),u===n&&(t.substr(ge,4)===et?(u=et,ge+=4):(u=n,0===me&&Le(nt))),(a=u!==n?t.substring(a,ge):u)!==n?(s,s=a):(ge=s,s=n)):(ge=s,s=n),s===n&&(s=null),s!==n?(r,r=e=function(t,r){const e=$n(t,r&&{sort:r});Bn.orderBy=Bn.orderBy?[...Bn.orderBy,e]:[e]}(e,s)):(ge=r,r=n)):(ge=r,r=n),r}function Ie(){var r,e,s,a,c,i;if(r=ge,(e=rn())!==n){for(s=[],a=ge,47===t.charCodeAt(ge)?(c=u,ge++):(c=n,0===me&&Le(o)),c!==n&&(i=rn())!==n?a=c=[c,i]:(ge=a,a=n);a!==n;)s.push(a),a=ge,47===t.charCodeAt(ge)?(c=u,ge++):(c=n,0===me&&Le(o)),c!==n&&(i=rn())!==n?a=c=[c,i]:(ge=a,a=n);s!==n?r=e=[e,s]:(ge=r,r=n)}else ge=r,r=n;return r}function Me(){var r,e,s,a,u,o;return me++,r=ge,(e=Xe())!==n&&xn()!==n?(s=ge,"eq"===t.substr(ge,2)?(a="eq",ge+=2):(a=n,0===me&&Le(lt)),a===n&&("ne"===t.substr(ge,2)?(a="ne",ge+=2):(a=n,0===me&&Le(ht)),a===n&&("lt"===t.substr(ge,2)?(a="lt",ge+=2):(a=n,0===me&&Le(pt)),a===n&&("gt"===t.substr(ge,2)?(a="gt",ge+=2):(a=n,0===me&&Le(At)),a===n&&("le"===t.substr(ge,2)?(a="le",ge+=2):(a=n,0===me&&Le(dt)),a===n&&("ge"===t.substr(ge,2)?(a="ge",ge+=2):(a=n,0===me&&Le(gt))))))),(s=a!==n?t.substring(s,ge):a)!==n&&(a=xn())!==n&&(u=Xe())!==n?(r,r=e=[e,{eq:"=",ne:"!=",lt:"<",gt:">",le:"<=",ge:">="}[o=s]||o,u]):(ge=r,r=n)):(ge=r,r=n),me--,r===n&&(e=n,0===me&&Le(ft)),r}function Xe(){var r;return me++,r=function(){var r,e,s,a,c,i,h;me++,r=ge,e=[],s=ge,(a=dn())!==n?(c=ge,(i=mn())!==n&&(h=Te())!==n&&Cn()!==n?(c,c=i=yt(0,h)):(ge=c,c=n),c===n&&(c=null),c!==n?(47===t.charCodeAt(ge)?(i=u,ge++):(i=n,0===me&&Le(o)),i!==n?(s,s=a=mt(a,c)):(ge=s,s=n)):(ge=s,s=n)):(ge=s,s=n);if(s!==n)for(;s!==n;)e.push(s),s=ge,(a=dn())!==n?(c=ge,(i=mn())!==n&&(h=Te())!==n&&Cn()!==n?(c,c=i=yt(0,h)):(ge=c,c=n),c===n&&(c=null),c!==n?(47===t.charCodeAt(ge)?(i=u,ge++):(i=n,0===me&&Le(o)),i!==n?(s,s=a=mt(a,c)):(ge=s,s=n)):(ge=s,s=n)):(ge=s,s=n);else e=n;e!==n?(t.substr(ge,6)===f?(s=f,ge+=6):(s=n,0===me&&Le(l)),s!==n?(r,r=e={func:"count",as:"$count",args:[{ref:e}]}):(ge=r,r=n)):(ge=r,r=n);me--,r===n&&(e=n,0===me&&Le(bt));return r}(),r===n&&(r=Qe())===n&&(r=Ge())===n&&(r=He())===n&&(r=Je())===n&&(r=Ke())===n&&(r=function(){var r,e,s,a,u;r=ge,91===t.charCodeAt(ge)?(e=Bt,ge++):(e=n,0===me&&Le(Ot));if(e!==n){for(s=ge,a=[],zt.test(t.charAt(ge))?(u=t.charAt(ge),ge++):(u=n,0===me&&Le(_t));u!==n;)a.push(u),zt.test(t.charAt(ge))?(u=t.charAt(ge),ge++):(u=n,0===me&&Le(_t));(s=a!==n?t.substring(s,ge):a)!==n?(93===t.charCodeAt(ge)?(a=Tt,ge++):(a=n,0===me&&Le(Zt)),a!==n?(r,r=e={list:s.replace(/"/g,"").split(",").map((t=>({val:t})))}):(ge=r,r=n)):(ge=r,r=n)}else ge=r,r=n;return r}()),me--,r===n&&(n,0===me&&Le(vt)),r}function Ge(){var r,e,s,a,c,i,f,l;if(me++,r=ge,(e=dn())!==n){for(s=[],a=ge,47===t.charCodeAt(ge)?(c=u,ge++):(c=n,0===me&&Le(o)),c!==n&&(i=dn())!==n?(a,a=c=wt(0,i)):(ge=a,a=n);a!==n;)s.push(a),a=ge,47===t.charCodeAt(ge)?(c=u,ge++):(c=n,0===me&&Le(o)),c!==n&&(i=dn())!==n?(a,a=c=wt(0,i)):(ge=a,a=n);s!==n?(r,l=s,r=e="null"===(f=e)?{val:null}:{ref:[f,...l]}):(ge=r,r=n)}else ge=r,r=n;return me--,r===n&&(e=n,0===me&&Le(Ct)),r}function He(){var r,e,s;return r=ge,(e=hn())===n&&(e=function(){var r,e,s,a,u,o,c,i,f,l,h,p,A,d,g,v,b,y,m,C,w,x,$,E;r=ge,e=ge,s=[],Pr.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(qr));if(a!==n)for(;a!==n;)s.push(a),Pr.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(qr));else s=n;if(s!==n)if(45===t.charCodeAt(ge)?(a=Ir,ge++):(a=n,0===me&&Le(Mr)),a!==n)if(Pr.test(t.charAt(ge))?(u=t.charAt(ge),ge++):(u=n,0===me&&Le(qr)),u!==n)if(Pr.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(qr)),o!==n)if(45===t.charCodeAt(ge)?(c=Ir,ge++):(c=n,0===me&&Le(Mr)),c!==n)if(Pr.test(t.charAt(ge))?(i=t.charAt(ge),ge++):(i=n,0===me&&Le(qr)),i!==n)if(Pr.test(t.charAt(ge))?(f=t.charAt(ge),ge++):(f=n,0===me&&Le(qr)),f!==n){if(l=ge,84===t.charCodeAt(ge)?(h="T",ge++):(h=n,0===me&&Le(Xr)),h!==n)if(Pr.test(t.charAt(ge))?(p=t.charAt(ge),ge++):(p=n,0===me&&Le(qr)),p!==n)if(Pr.test(t.charAt(ge))?(A=t.charAt(ge),ge++):(A=n,0===me&&Le(qr)),A!==n)if(58===t.charCodeAt(ge)?(d=K,ge++):(d=n,0===me&&Le(Q)),d!==n)if(Pr.test(t.charAt(ge))?(g=t.charAt(ge),ge++):(g=n,0===me&&Le(qr)),g!==n)if(Pr.test(t.charAt(ge))?(v=t.charAt(ge),ge++):(v=n,0===me&&Le(qr)),v!==n){if(b=ge,58===t.charCodeAt(ge)?(y=K,ge++):(y=n,0===me&&Le(Q)),y!==n)if(Pr.test(t.charAt(ge))?(m=t.charAt(ge),ge++):(m=n,0===me&&Le(qr)),m!==n)if(Pr.test(t.charAt(ge))?(C=t.charAt(ge),ge++):(C=n,0===me&&Le(qr)),C!==n){if(w=ge,46===t.charCodeAt(ge)?(x=".",ge++):(x=n,0===me&&Le(Hr)),x!==n){if($=[],Pr.test(t.charAt(ge))?(E=t.charAt(ge),ge++):(E=n,0===me&&Le(qr)),E!==n)for(;E!==n;)$.push(E),Pr.test(t.charAt(ge))?(E=t.charAt(ge),ge++):(E=n,0===me&&Le(qr));else $=n;$!==n?w=x=[x,$]:(ge=w,w=n)}else ge=w,w=n;w===n&&(w=null),w!==n?b=y=[y,m,C,w]:(ge=b,b=n)}else ge=b,b=n;else ge=b,b=n;else ge=b,b=n;b===n&&(b=null),b!==n?(90===t.charCodeAt(ge)?(y="Z",ge++):(y=n,0===me&&Le(Jr)),y===n&&(y=ge,43===t.charCodeAt(ge)?(m="+",ge++):(m=n,0===me&&Le(Kr)),m===n&&(45===t.charCodeAt(ge)?(m=Ir,ge++):(m=n,0===me&&Le(Mr))),m!==n?(Pr.test(t.charAt(ge))?(C=t.charAt(ge),ge++):(C=n,0===me&&Le(qr)),C!==n?(Pr.test(t.charAt(ge))?(w=t.charAt(ge),ge++):(w=n,0===me&&Le(qr)),w!==n?(58===t.charCodeAt(ge)?(x=K,ge++):(x=n,0===me&&Le(Q)),x!==n?(Pr.test(t.charAt(ge))?($=t.charAt(ge),ge++):($=n,0===me&&Le(qr)),$!==n?(Pr.test(t.charAt(ge))?(E=t.charAt(ge),ge++):(E=n,0===me&&Le(qr)),E!==n?y=m=[m,C,w,x,$,E]:(ge=y,y=n)):(ge=y,y=n)):(ge=y,y=n)):(ge=y,y=n)):(ge=y,y=n)):(ge=y,y=n)),y===n&&(y=null),y!==n?l=h=[h,p,A,d,g,v,b,y]:(ge=l,l=n)):(ge=l,l=n)}else ge=l,l=n;else ge=l,l=n;else ge=l,l=n;else ge=l,l=n;else ge=l,l=n;else ge=l,l=n;l===n&&(l=null),l!==n?e=s=[s,a,u,o,c,i,f,l]:(ge=e,e=n)}else ge=e,e=n;else ge=e,e=n;else ge=e,e=n;else ge=e,e=n;else ge=e,e=n;else ge=e,e=n;else ge=e,e=n;r=e!==n?t.substring(r,ge):e;return r}()),e!==n&&(r,e=xt(e)),(r=e)===n&&(r=ge,(e=gn())!==n&&(r,e=xt(e)),(r=e)===n&&(r=ge,e=function(){var r,e,s,a,u,o,c,i,f,l;r=ge,e=ge,s=ge,Qr.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(Vr));a===n&&(a=null);if(a!==n){if(u=[],Pr.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(qr)),o!==n)for(;o!==n;)u.push(o),Pr.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(qr));else u=n;if(u!==n){if(o=ge,46===t.charCodeAt(ge)?(c=Gr,ge++):(c=n,0===me&&Le(Hr)),c!==n){if(i=[],Pr.test(t.charAt(ge))?(f=t.charAt(ge),ge++):(f=n,0===me&&Le(qr)),f!==n)for(;f!==n;)i.push(f),Pr.test(t.charAt(ge))?(f=t.charAt(ge),ge++):(f=n,0===me&&Le(qr));else i=n;i!==n?o=c=[c,i]:(ge=o,o=n)}else ge=o,o=n;if(o===n&&(o=null),o!==n){if(c=ge,101===t.charCodeAt(ge)?(i="e",ge++):(i=n,0===me&&Le(Wr)),i!==n){if(f=[],Pr.test(t.charAt(ge))?(l=t.charAt(ge),ge++):(l=n,0===me&&Le(qr)),l!==n)for(;l!==n;)f.push(l),Pr.test(t.charAt(ge))?(l=t.charAt(ge),ge++):(l=n,0===me&&Le(qr));else f=n;f!==n?c=i=[i,f]:(ge=c,c=n)}else ge=c,c=n;c===n&&(c=null),c!==n?s=a=[a,u,o,c]:(ge=s,s=n)}else ge=s,s=n}else ge=s,s=n}else ge=s,s=n;e=s!==n?t.substring(e,ge):s;e!==n&&(r,e=Zn(e));return r=e}(),e!==n&&(r,e="number"==typeof(s=e)?{val:s}:{val:s,literal:"number"}),(r=e)===n&&(r=ge,(e=pn())!==n&&(r,e=xt(e)),r=e))),r}function Je(){var r,e,s,a,u,o;if(r=ge,e=ge,s=ge,123===t.charCodeAt(ge)?(a="{",ge++):(a=n,0===me&&Le($t)),a!==n){for(u=[],(o=Je())===n&&(Et.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(Lt)));o!==n;)u.push(o),(o=Je())===n&&(Et.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(Lt)));u!==n?(125===t.charCodeAt(ge)?(o="}",ge++):(o=n,0===me&&Le(St)),o!==n?s=a=[a,u,o]:(ge=s,s=n)):(ge=s,s=n)}else ge=s,s=n;return(e=s!==n?t.substring(e,ge):s)!==n&&(r,e=xt(e)),r=e}function Ke(){var r,e,s,a,u,o,c,i;if(r=ge,e=ge,s=ge,91===t.charCodeAt(ge)?(a=Bt,ge++):(a=n,0===me&&Le(Ot)),a!==n&&(u=wn())!==n?(93===t.charCodeAt(ge)?(o=Tt,ge++):(o=n,0===me&&Le(Zt)),o!==n?s=a=[a,u,o]:(ge=s,s=n)):(ge=s,s=n),s===n)if(s=ge,91===t.charCodeAt(ge)?(a=Bt,ge++):(a=n,0===me&&Le(Ot)),a!==n)if((u=wn())!==n)if(123===t.charCodeAt(ge)?(o="{",ge++):(o=n,0===me&&Le($t)),o!==n){for(c=[],(i=Ke())===n&&(zt.test(t.charAt(ge))?(i=t.charAt(ge),ge++):(i=n,0===me&&Le(_t)));i!==n;)c.push(i),(i=Ke())===n&&(zt.test(t.charAt(ge))?(i=t.charAt(ge),ge++):(i=n,0===me&&Le(_t)));c!==n?(93===t.charCodeAt(ge)?(i=Tt,ge++):(i=n,0===me&&Le(Zt)),i!==n?s=a=[a,u,o,c,i]:(ge=s,s=n)):(ge=s,s=n)}else ge=s,s=n;else ge=s,s=n;else ge=s,s=n;return(e=s!==n?t.substring(e,ge):s)!==n&&(r,e=xt(e)),r=e}function Qe(){var r,e,s,a,u,o,c;if(me++,r=ge,e=ge,s=[],st.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(at)),a!==n)for(;a!==n;)s.push(a),st.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(at));else s=n;if((e=s!==n?t.substring(e,ge):s)!==n)if((s=mn())!==n)if((a=Xe())!==n){for(u=[],o=ge,yn()!==n&&(c=Xe())!==n?(o,o=Rt(0,0,c)):(ge=o,o=n);o!==n;)u.push(o),o=ge,yn()!==n&&(c=Xe())!==n?(o,o=Rt(0,0,c)):(ge=o,o=n);u!==n&&(o=Cn())!==n?(r,r=e=function(t,r,e){if(En&&!(t.toLowerCase()in En.functions))throw Object.assign(new Error(`"${t}" is an unknown function in OData URL spec (strict mode)`),{statusCode:400});return{func:t.toLowerCase(),args:[r,...e]}}(e,a,u)):(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n;else ge=r,r=n;return me--,r===n&&(e=n,0===me&&Le(Ft)),r}function Ve(){var r,e;return r=ge,wn()!==n?("not"===t.substr(ge,3).toLowerCase()?(e=t.substr(ge,3),ge+=3):(e=n,0===me&&Le(It)),e!==n&&xn()!==n?(r,r="not"):(ge=r,r=n)):(ge=r,r=n),r}function We(){var r,e;return r=ge,xn()!==n?("and"===t.substr(ge,3).toLowerCase()?(e=t.substr(ge,3),ge+=3):(e=n,0===me&&Le(Mt)),e!==n&&xn()!==n?(r,r="and"):(ge=r,r=n)):(ge=r,r=n),r}function Ye(){var t,r;return t=ge,(r=xn())!==n&&(t,r="and"),t=r}function tn(){var r,e;return r=ge,xn()!==n?("or"===t.substr(ge,2).toLowerCase()?(e=t.substr(ge,2),ge+=2):(e=n,0===me&&Le(Xt)),e!==n&&xn()!==n?(r,r="or"):(ge=r,r=n)):(ge=r,r=n),r}function rn(){var r,e,s;return r=ge,t.substr(ge,9)===Gt?(e=Gt,ge+=9):(e=n,0===me&&Le(Ht)),e!==n?(s=function(){var t,r,e,s,a;if(t=ge,mn()!==n)if(wn()!==n)if((r=en())!==n){for(e=[],s=ge,wn()!==n&&yn()!==n&&wn()!==n&&(a=en())!==n?(s,s=v(0,a)):(ge=s,s=n);s!==n;)e.push(s),s=ge,wn()!==n&&yn()!==n&&wn()!==n&&(a=en())!==n?(s,s=v(0,a)):(ge=s,s=n);e!==n&&(s=wn())!==n&&Cn()!==n?(t,t=function(t,r){let e=Bn.apply;e.aggregate&&(Bn.apply={apply:e},e.groupBy&&(Bn.apply.groupBy=e.groupBy),e=Bn.apply),e.aggregate=[t,...r]}(r,e)):(ge=t,t=n)}else ge=t,t=n;else ge=t,t=n;else ge=t,t=n;return t}(),s!==n?r=e=[e,s]:(ge=r,r=n)):(ge=r,r=n),r===n&&(r=ge,t.substr(ge,7)===Jt?(e=Jt,ge+=7):(e=n,0===me&&Le(Kt)),e!==n?(s=function(){var t,r,e,s,a,u,o,c,i;if(t=ge,(r=mn())!==n)if((e=mn())!==n)if((s=on())!==n){for(a=[],u=ge,(o=yn())!==n&&(c=on())!==n?(u,u=o=v(0,c)):(ge=u,u=n);u!==n;)a.push(u),u=ge,(o=yn())!==n&&(c=on())!==n?(u,u=o=v(0,c)):(ge=u,u=n);a!==n?(u=ge,(o=Cn())!==n&&(u,o=function(t,r){let e=Bn.apply;(e.groupBy||e.where||e.search)&&(Bn.apply={apply:e},e=Bn.apply),e.groupBy=[t,...r]}(s,a)),(u=o)!==n?(o=ge,(c=yn())!==n&&(i=Ie())!==n?o=c=[c,i]:(ge=o,o=n),o===n&&(o=null),o!==n&&(c=Cn())!==n?t=r=[r,e,s,a,u,o,c]:(ge=t,t=n)):(ge=t,t=n)):(ge=t,t=n)}else ge=t,t=n;else ge=t,t=n;else ge=t,t=n;return t}(),s!==n?r=e=[e,s]:(ge=r,r=n)):(ge=r,r=n),r===n&&(r=ge,t.substr(ge,6)===Qt?(e=Qt,ge+=6):(e=n,0===me&&Le(Vt)),e!==n&&(s=cn())!==n?r=e=[e,s]:(ge=r,r=n),r===n&&(r=ge,t.substr(ge,6)===Wt?(e=Wt,ge+=6):(e=n,0===me&&Le(Yt)),e!==n&&(s=fn())!==n?r=e=[e,s]:(ge=r,r=n),r===n&&(r=ge,t.substr(ge,6)===tr?(e=tr,ge+=6):(e=n,0===me&&Le(rr)),e!==n?(s=function(){var t,r,e,s,a,u;t=ge,(r=mn())!==n&&(e=wn())!==n?(s=ge,(a=Re())!==n&&(s,a=function(t){if(!t)return;let r=Bn.apply;r.search&&(Bn.apply={apply:r},r=Bn.apply),r.search=t}(a)),(s=a)!==n&&(a=wn())!==n&&(u=Cn())!==n?t=r=[r,e,s,a,u]:(ge=t,t=n)):(ge=t,t=n);return t}(),s!==n?r=e=[e,s]:(ge=r,r=n)):(ge=r,r=n),r===n&&(r=ge,t.substr(ge,6)===er?(e=er,ge+=6):(e=n,0===me&&Le(nr)),e!==n?(s=function(){var t,r,e,s,a,u,o,c,i,f;if(t=ge,(r=mn())!==n)if((e=wn())!==n)if((s=Ie())!==n){if(a=[],u=ge,(o=wn())!==n&&(c=yn())!==n&&(i=wn())!==n&&(f=Ie())!==n?u=o=[o,c,i,f]:(ge=u,u=n),u!==n)for(;u!==n;)a.push(u),u=ge,(o=wn())!==n&&(c=yn())!==n&&(i=wn())!==n&&(f=Ie())!==n?u=o=[o,c,i,f]:(ge=u,u=n);else a=n;a!==n&&(u=wn())!==n&&(o=Cn())!==n?t=r=[r,e,s,a,u,o]:(ge=t,t=n)}else ge=t,t=n;else ge=t,t=n;else ge=t,t=n;return t}(),s!==n?r=e=[e,s]:(ge=r,r=n)):(ge=r,r=n),r===n&&(r=ge,t.substr(ge,7)===sr?(e=sr,ge+=7):(e=n,0===me&&Le(ar)),e!==n?(s=function(){var t,r,e,s,a,u,o,c,i,f;if(t=ge,(r=mn())!==n)if((e=wn())!==n)if((s=ln())!==n){for(a=[],u=ge,(o=wn())!==n&&(c=yn())!==n&&(i=wn())!==n&&(f=ln())!==n?u=o=[o,c,i,f]:(ge=u,u=n);u!==n;)a.push(u),u=ge,(o=wn())!==n&&(c=yn())!==n&&(i=wn())!==n&&(f=ln())!==n?u=o=[o,c,i,f]:(ge=u,u=n);a!==n&&(u=wn())!==n&&(o=Cn())!==n?t=r=[r,e,s,a,u,o]:(ge=t,t=n)}else ge=t,t=n;else ge=t,t=n;else ge=t,t=n;return t}(),s!==n?r=e=[e,s]:(ge=r,r=n)):(ge=r,r=n),r===n&&(r=ge,"topcount"===t.substr(ge,8).toLowerCase()?(e=t.substr(ge,8),ge+=8):(e=n,0===me&&Le(ur)),e===n&&("bottomcount"===t.substr(ge,11).toLowerCase()?(e=t.substr(ge,11),ge+=11):(e=n,0===me&&Le(or)),e===n&&("topsum"===t.substr(ge,6).toLowerCase()?(e=t.substr(ge,6),ge+=6):(e=n,0===me&&Le(cr)),e===n&&("bottomsum"===t.substr(ge,9).toLowerCase()?(e=t.substr(ge,9),ge+=9):(e=n,0===me&&Le(ir)),e===n&&("toppercent"===t.substr(ge,10).toLowerCase()?(e=t.substr(ge,10),ge+=10):(e=n,0===me&&Le(fr)),e===n&&("bottompercent"===t.substr(ge,13).toLowerCase()?(e=t.substr(ge,13),ge+=13):(e=n,0===me&&Le(lr))))))),e!==n?(s=function(){var t,r,e;t=ge,mn()!==n&&wn()!==n&&(r=Xe())!==n&&wn()!==n&&yn()!==n&&wn()!==n&&(e=Xe())!==n&&wn()!==n&&Cn()!==n?(t,t=[r,e]):(ge=t,t=n);return t}(),s!==n?(r,r=e=function(t,r){if(!{topcount:!0,bottomcount:!0,topsum:!1,bottomsum:!1,toppercent:!1,bottompercent:!1}[t=t.toLowerCase()])throw Object.assign(new Error(`Transformation "${t}" in $apply is not supported yet.`),{statusCode:501});(Bn.apply.aggregate||(Bn.apply.aggregate=[])).push({func:t,args:r})}(e,s)):(ge=r,r=n)):(ge=r,r=n),r===n&&(r=function(){var r;t.substr(ge,8)===Cr?(r=Cr,ge+=8):(r=n,0===me&&Le(wr));return r}())))))))),r}function en(){var r,e,s,a;return r=ge,e=ge,t.substr(ge,6)===f?(s=f,ge+=6):(s=n,0===me&&Le(l)),s!==n&&(a=un())!==n?(e,e=s={func:"count",args:[{val:1}],as:a}):(ge=e,e=n),e===n&&(e=nn()),e!==n&&(r,e=e),r=e}function nn(){var t,r,e,s,a;return t=ge,(r=Ge())!==n&&(e=sn())!==n?((s=an())===n&&(s=null),s!==n&&(a=un())!==n?(t,t=r={func:e,args:[r],as:a}):(ge=t,t=n)):(ge=t,t=n),t===n&&(t=ge,(r=dn())!==n&&(e=mn())!==n&&(s=nn())!==n&&(a=Cn())!==n?t=r=[r,e,s,a]:(ge=t,t=n)),t}function sn(){var r,e,s,a,u;if(r=ge,xn()!==n)if(t.substr(ge,4)===hr?(e=hr,ge+=4):(e=n,0===me&&Le(pr)),e!==n)if(xn()!==n){if(s=ge,a=[],st.test(t.charAt(ge))?(u=t.charAt(ge),ge++):(u=n,0===me&&Le(at)),u!==n)for(;u!==n;)a.push(u),st.test(t.charAt(ge))?(u=t.charAt(ge),ge++):(u=n,0===me&&Le(at));else a=n;(s=a!==n?t.substring(s,ge):a)!==n?(r,r=s.toLowerCase()):(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n;else ge=r,r=n;return r}function an(){var r,e,s,a,u,o,c;return r=ge,(e=xn())!==n?(t.substr(ge,4)===Ar?(s=Ar,ge+=4):(s=n,0===me&&Le(dr)),s!==n&&(a=xn())!==n&&(u=Ge())!==n&&(o=sn())!==n?((c=an())===n&&(c=null),c!==n?r=e=[e,s,a,u,o,c]:(ge=r,r=n)):(ge=r,r=n)):(ge=r,r=n),r}function un(){var r,e,s;return r=ge,xn()!==n?("as"===t.substr(ge,2)?(e="as",ge+=2):(e=n,0===me&&Le(gr)),e!==n&&xn()!==n&&(s=dn())!==n?(r,r=s):(ge=r,r=n)):(ge=r,r=n),r}function on(){var r,e;return r=ge,e=function(){var r,e,s,a,u,o,c,i,f,l,h;r=ge,e=ge,t.substr(ge,6)===vr?(s=vr,ge+=6):(s=n,0===me&&Le(br));if(s!==n)if((a=mn())!==n)if((u=wn())!==n)if(t.substr(ge,4)===yr?(o=yr,ge+=4):(o=n,0===me&&Le(mr)),o===n&&(o=Ge()),o!==n){if(c=[],i=ge,(f=wn())!==n&&(l=yn())!==n&&(h=Ge())!==n?i=f=[f,l,h]:(ge=i,i=n),i!==n)for(;i!==n;)c.push(i),i=ge,(f=wn())!==n&&(l=yn())!==n&&(h=Ge())!==n?i=f=[f,l,h]:(ge=i,i=n);else c=n;c!==n&&(i=wn())!==n&&(f=Cn())!==n?e=s=[s,a,u,o,c,i,f]:(ge=e,e=n)}else ge=e,e=n;else ge=e,e=n;else ge=e,e=n;else ge=e,e=n;e!==n&&(r,e=function(t){const r=new Error("Rollup in groupby is not supported yet.");throw r.statusCode=501,r}());return r=e}(),e===n&&(e=Ge()),e!==n&&(r,e=e),r=e}function cn(){var t,r,e,s,a,u;return t=ge,(r=mn())!==n&&(e=wn())!==n?(s=ge,(a=ke())!==n&&(s,a=function(t){let r=Bn.apply;r.where&&(Bn.apply={apply:r},r=Bn.apply),r.where=t}(a)),(s=a)!==n&&(a=wn())!==n&&(u=Cn())!==n?t=r=[r,e,s,a,u]:(ge=t,t=n)):(ge=t,t=n),t}function fn(){var t,r,e,s,a,u,o,c,i,f,l,h,p,A;if(t=ge,(r=mn())!==n)if((e=wn())!==n)if((s=Ge())!==n)if((a=wn())!==n)if((u=yn())!==n)if((o=wn())!==n){if(c=ge,(i=fn())!==n){for(f=[],l=ge,(h=wn())!==n&&(p=yn())!==n&&(A=fn())!==n?l=h=[h,p,A]:(ge=l,l=n);l!==n;)f.push(l),l=ge,(h=wn())!==n&&(p=yn())!==n&&(A=fn())!==n?l=h=[h,p,A]:(ge=l,l=n);f!==n?c=i=[i,f]:(ge=c,c=n)}else ge=c,c=n;if(c===n)if(c=ge,(i=cn())!==n){for(f=[],l=ge,(h=wn())!==n&&(p=yn())!==n&&(A=fn())!==n?l=h=[h,p,A]:(ge=l,l=n);l!==n;)f.push(l),l=ge,(h=wn())!==n&&(p=yn())!==n&&(A=fn())!==n?l=h=[h,p,A]:(ge=l,l=n);f!==n?c=i=[i,f]:(ge=c,c=n)}else ge=c,c=n;c!==n&&(i=wn())!==n&&(f=Cn())!==n?t=r=[r,e,s,a,u,o,c,i,f]:(ge=t,t=n)}else ge=t,t=n;else ge=t,t=n;else ge=t,t=n;else ge=t,t=n;else ge=t,t=n;else ge=t,t=n;return t}function ln(){var t,r,e;return t=ge,(r=Ne())!==n&&(e=un())!==n?t=r=[r,e]:(ge=t,t=n),t}function hn(){var r,e;return r=ge,t.substr(ge,4)===xr?(e=xr,ge+=4):(e=n,0===me&&Le($r)),e===n&&(t.substr(ge,5)===Er?(e=Er,ge+=5):(e=n,0===me&&Le(Lr))),e!==n&&(r,e="true"===e),r=e}function pn(){var r,e,s,a,u;if(me++,r=ge,39===t.charCodeAt(ge)?(e="'",ge++):(e=n,0===me&&Le(Br)),e!==n){for(s=ge,a=[],t.substr(ge,2)===Or?(u=Or,ge+=2):(u=n,0===me&&Le(Tr)),u===n&&(Zr.test(t.charAt(ge))?(u=t.charAt(ge),ge++):(u=n,0===me&&Le(zr)));u!==n;)a.push(u),t.substr(ge,2)===Or?(u=Or,ge+=2):(u=n,0===me&&Le(Tr)),u===n&&(Zr.test(t.charAt(ge))?(u=t.charAt(ge),ge++):(u=n,0===me&&Le(zr)));(s=a!==n?t.substring(s,ge):a)!==n?(39===t.charCodeAt(ge)?(a="'",ge++):(a=n,0===me&&Le(Br)),a!==n?(r,r=e=s.replace(/''/g,"'")):(ge=r,r=n)):(ge=r,r=n)}else ge=r,r=n;return me--,r===n&&(e=n,0===me&&Le(Sr)),r}function An(){var r,e,s,a,u,o;if(r=ge,e=ge,s=ge,Qr.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(Vr)),a===n&&(a=null),a!==n){if(u=[],Pr.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(qr)),o!==n)for(;o!==n;)u.push(o),Pr.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(qr));else u=n;u!==n?s=a=[a,u]:(ge=s,s=n)}else ge=s,s=n;return(e=s!==n?t.substring(e,ge):s)!==n&&(r,e=parseInt(e)),r=e}function dn(){var r,e,s,a,u,o,c,i;if(r=ge,e=ge,me++,s=hn(),me--,s===n?e=void 0:(ge=e,e=n),e!==n)if(s=ge,me++,a=gn(),me--,a===n?s=void 0:(ge=s,s=n),s!==n){if(a=ge,u=ge,Yr.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(te)),o!==n){for(c=[],re.test(t.charAt(ge))?(i=t.charAt(ge),ge++):(i=n,0===me&&Le(ee));i!==n;)c.push(i),re.test(t.charAt(ge))?(i=t.charAt(ge),ge++):(i=n,0===me&&Le(ee));c!==n?u=o=[o,c]:(ge=u,u=n)}else ge=u,u=n;(a=u!==n?t.substring(a,ge):u)!==n?(r,r=e=a):(ge=r,r=n)}else ge=r,r=n;else ge=r,r=n;return r}function gn(){var r,e,s,a,u,o,c,i,f,l,h,p,A,d;return r=ge,e=ge,(s=vn())!==n&&(a=vn())!==n?(45===t.charCodeAt(ge)?(u=Ir,ge++):(u=n,0===me&&Le(Mr)),u===n&&(u=null),u!==n&&(o=vn())!==n?(45===t.charCodeAt(ge)?(c=Ir,ge++):(c=n,0===me&&Le(Mr)),c===n&&(c=null),c!==n&&(i=vn())!==n?(45===t.charCodeAt(ge)?(f=Ir,ge++):(f=n,0===me&&Le(Mr)),f===n&&(f=null),f!==n&&(l=vn())!==n?(45===t.charCodeAt(ge)?(h=Ir,ge++):(h=n,0===me&&Le(Mr)),h===n&&(h=null),h!==n&&(p=vn())!==n&&(A=vn())!==n&&(d=vn())!==n?e=s=[s,a,u,o,c,i,f,l,h,p,A,d]:(ge=e,e=n)):(ge=e,e=n)):(ge=e,e=n)):(ge=e,e=n)):(ge=e,e=n),r=e!==n?t.substring(r,ge):e}function vn(){var r,e,s,a,u,o;return r=ge,e=ge,ne.test(t.charAt(ge))?(s=t.charAt(ge),ge++):(s=n,0===me&&Le(se)),s!==n?(ne.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(se)),a!==n?(ne.test(t.charAt(ge))?(u=t.charAt(ge),ge++):(u=n,0===me&&Le(se)),u!==n?(ne.test(t.charAt(ge))?(o=t.charAt(ge),ge++):(o=n,0===me&&Le(se)),o!==n?e=s=[s,a,u,o]:(ge=e,e=n)):(ge=e,e=n)):(ge=e,e=n)):(ge=e,e=n),r=e!==n?t.substring(r,ge):e}function bn(){var r,e,s,a;if(r=ge,e=ge,s=[],ae.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(ue)),a!==n)for(;a!==n;)s.push(a),ae.test(t.charAt(ge))?(a=t.charAt(ge),ge++):(a=n,0===me&&Le(ue));else s=n;return(e=s!==n?t.substring(e,ge):s)!==n&&(r,e=xt(e)),r=e}function yn(){var r,e,s,a;return r=ge,(e=wn())!==n?(44===t.charCodeAt(ge)?(s=",",ge++):(s=n,0===me&&Le(ie)),s!==n&&(a=wn())!==n?r=e=[e,s,a]:(ge=r,r=n)):(ge=r,r=n),r}function mn(){var r,e,s,a;return r=ge,(e=wn())!==n?(40===t.charCodeAt(ge)?(s="(",ge++):(s=n,0===me&&Le(fe)),s!==n&&(a=wn())!==n?r=e=[e,s,a]:(ge=r,r=n)):(ge=r,r=n),r}function Cn(){var r,e,s;return r=ge,(e=wn())!==n?(41===t.charCodeAt(ge)?(s=")",ge++):(s=n,0===me&&Le(le)),s!==n?r=e=[e,s]:(ge=r,r=n)):(ge=r,r=n),r}function wn(){var r,e,s;for(me++,r=ge,e=[],pe.test(t.charAt(ge))?(s=t.charAt(ge),ge++):(s=n,0===me&&Le(Ae));s!==n;)e.push(s),pe.test(t.charAt(ge))?(s=t.charAt(ge),ge++):(s=n,0===me&&Le(Ae));return r=e!==n?t.substring(r,ge):e,me--,r===n&&(e=n,0===me&&Le(he)),r}function xn(){var r,e,s;if(me++,r=ge,e=[],pe.test(t.charAt(ge))?(s=t.charAt(ge),ge++):(s=n,0===me&&Le(Ae)),s!==n)for(;s!==n;)e.push(s),pe.test(t.charAt(ge))?(s=t.charAt(ge),ge++):(s=n,0===me&&Le(Ae));else e=n;return r=e!==n?t.substring(r,ge):e,me--,r===n&&(e=n,0===me&&Le(de)),r}const $n=Object.assign,{strict:En,minimal:Ln}=r,Sn=[];let Bn,On;const Tn=["$value"],Zn=r.safeNumber||function(t){const r=Number(t);return Number.isSafeInteger(r)?r:t},zn=t=>r=>t===r||t.as&&r.as&&t.as===r.as||r.as&&t.ref&&r.as===t.ref[t.ref.length-1]||t.ref&&r.ref&&t.ref.join("")===r.ref.join(""),_n=t=>r=>{if(Array.isArray(r))return r.map(_n(t));const e=r.ref&&t.find((t=>t.as&&t.func&&t.as===r.ref[0]));return e||r},Fn=t=>r=>Array.isArray(r)?r.map(Fn(t)):r.ref&&!t.find(zn(r))?{val:null}:r,Rn=(t,r)=>{if(1===r.ref.length)t.find(zn(r))||t.push(r);else{const e=r.ref.shift(),n=t.find((t=>t.ref&&t.ref[0]===e));if(n)Rn(n.expand,r);else{const n={ref:[e],expand:[]};Rn(n.expand,r),t.push(n)}}},jn=(t,r,e=!1)=>{if(!r)return;if(t.apply&&delete t.apply,(r.apply||r.where&&t.where||r.search&&t.search)&&(t.from={SELECT:{from:t.from}}),r.where&&(t.where?t.from.SELECT.where=r.where:t.where=r.where),r.search&&(t.search?t.from.SELECT.search=r.search:t.search=r.search),r.groupBy){t.groupBy=[];for(const e of r.groupBy)t.groupBy.find(zn(e))||t.groupBy.push(e)}const n=[...t.groupBy||[],...r.aggregate||[]];n.length&&(t.columns=t.columns&&!e?t.columns.reduce(((t,r)=>{const e=n.find(zn(r));return e&&t.push(e),t}),[]):n,t.where&&(t.where=t.where.map(_n(t.columns)),t.groupBy&&(t.having=t.where.map(Fn(t.groupBy)),delete t.where)),t.columns=t.columns.reduce(((t,r)=>(r.ref&&r.ref.length>1&&n.find(zn(r))?Rn(t,{ref:[...r.ref]}):t.push(r),t)),[])),r.apply&&jn(t.from.SELECT,r.apply)},kn=t=>{Bn.limit&&Bn.limit.offset&&Bn.limit.offset.val&&(t+=Bn.limit.offset.val),(Bn.limit||(Bn.limit={})).offset={val:t}},Nn=(t,r)=>{for(const e of r)e.ref&&e.ref[0]===t&&e.ref.shift(),e.func&&Nn(t,e.args);return r};if((e=a())!==n&&ge===t.length)return e;throw e!==n&&ge<t.length&&Le({type:"end"}),Se(ye,be<t.length?t.charAt(be):null,be<t.length?Ee(be,be+1):Ee(be,be))}peg$subclass(peg$SyntaxError,Error),peg$SyntaxError.buildMessage=function(t,r){var e={literal:function(t){return'"'+s(t.text)+'"'},class:function(t){var r,e="";for(r=0;r<t.parts.length;r++)e+=t.parts[r]instanceof Array?a(t.parts[r][0])+"-"+a(t.parts[r][1]):a(t.parts[r]);return"["+(t.inverted?"^":"")+e+"]"},any:function(t){return"any character"},end:function(t){return"end of input"},other:function(t){return t.description}};function n(t){return t.charCodeAt(0).toString(16).toUpperCase()}function s(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}function a(t){return t.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,(function(t){return"\\x0"+n(t)})).replace(/[\x10-\x1F\x7F-\x9F]/g,(function(t){return"\\x"+n(t)}))}return"Expected "+function(t){var r,n,s,a=new Array(t.length);for(r=0;r<t.length;r++)a[r]=(s=t[r],e[s.type](s));if(a.sort(),a.length>0){for(r=1,n=1;r<a.length;r++)a[r-1]!==a[r]&&(a[n]=a[r],n++);a.length=n}switch(a.length){case 1:return a[0];case 2:return a[0]+" or "+a[1];default:return a.slice(0,-1).join(", ")+", or "+a[a.length-1]}}(t)+" but "+function(t){return t?'"'+s(t)+'"':"end of input"}(r)+" found."},module.exports={SyntaxError:peg$SyntaxError,parse:peg$parse};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sap/cds",
3
- "version": "5.7.1",
3
+ "version": "5.7.5",
4
4
  "description": "SAP Cloud Application Programming Model - CDS for Node.js",
5
5
  "homepage": "https://cap.cloud.sap/",
6
6
  "keywords": [