@sap/cds 5.5.4 → 5.6.2
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.
- package/CHANGELOG.md +138 -1
- package/apis/services.d.ts +27 -1
- package/app/index.js +22 -11
- package/bin/build/buildTaskFactory.js +1 -1
- package/bin/build/provider/buildTaskProviderInternal.js +1 -1
- package/bin/build/provider/fiori/index.js +1 -1
- package/bin/build/provider/hana/2migration.js +8 -7
- package/bin/build/provider/java-cf/index.js +1 -1
- package/bin/deploy/to-hana/hana.js +1 -17
- package/common.cds +8 -0
- package/lib/compile/to/sql.js +22 -2
- package/lib/connect/bindings.js +2 -1
- package/lib/core/reflect.js +4 -1
- package/lib/env/index.js +175 -41
- package/lib/env/requires.js +16 -1
- package/lib/i18n/localize.js +33 -5
- package/lib/index.js +3 -3
- package/lib/log/format/kibana.js +6 -2
- package/lib/ql/Query.js +1 -0
- package/lib/ql/SELECT.js +15 -8
- package/lib/ql/Whereable.js +5 -0
- package/lib/req/context.js +13 -5
- package/lib/serve/Service-dispatch.js +8 -1
- package/lib/serve/Service-methods.js +1 -1
- package/lib/utils/axios.js +7 -0
- package/lib/utils/data.js +1 -1
- package/lib/utils/tests.js +1 -1
- package/libx/_runtime/audit/Service.js +18 -18
- package/libx/_runtime/audit/generic/personal/access.js +1 -1
- package/libx/_runtime/audit/generic/personal/modification.js +3 -2
- package/libx/_runtime/audit/generic/personal/utils.js +23 -63
- package/libx/_runtime/cds-services/adapter/odata-v4/Dispatcher.js +4 -0
- package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +37 -35
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +3 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +5 -5
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +13 -7
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +84 -34
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +10 -4
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/applyToCQN.js +9 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/expandToCQN.js +8 -6
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/index.js +1 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +13 -11
- package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/selectHelper.js +11 -95
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/ResourcePathParser.js +17 -11
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriParser.js +2 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/invocation/SetResponseHeadersCommand.js +1 -0
- package/libx/_runtime/cds-services/adapter/odata-v4/to.js +6 -2
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/data.js +3 -34
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/handlerUtils.js +3 -3
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +64 -31
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/stream.js +10 -5
- package/libx/_runtime/cds-services/adapter/rest/handlers/operation.js +1 -1
- package/libx/_runtime/cds-services/adapter/rest/handlers/update.js +1 -1
- package/libx/_runtime/cds-services/adapter/rest/rest-to-cqn/index.js +1 -3
- package/libx/_runtime/cds-services/adapter/rest/utils/validation-checks.js +20 -21
- package/libx/_runtime/cds-services/services/utils/columns.js +6 -1
- package/libx/_runtime/cds-services/services/utils/compareJson.js +1 -8
- package/libx/_runtime/cds-services/services/utils/differ.js +7 -26
- package/libx/_runtime/cds-services/services/utils/handlerUtils.js +2 -4
- package/libx/_runtime/cds-services/util/assert.js +29 -13
- package/libx/_runtime/cds.js +2 -1
- package/libx/_runtime/common/aspects/Association.js +72 -0
- package/libx/_runtime/common/aspects/any.js +8 -45
- package/libx/_runtime/common/aspects/entity.js +0 -1
- package/libx/_runtime/common/aspects/relation.js +40 -0
- package/libx/_runtime/common/aspects/utils.js +73 -1
- package/libx/_runtime/common/auth/strategies/utils/uaa.js +10 -14
- package/libx/_runtime/common/composition/data.js +3 -2
- package/libx/_runtime/common/composition/delete.js +3 -1
- package/libx/_runtime/common/composition/tree.js +23 -18
- package/libx/_runtime/common/composition/update.js +6 -1
- package/libx/_runtime/common/composition/utils.js +34 -8
- package/libx/_runtime/common/error/frontend.js +6 -1
- package/libx/_runtime/common/generic/auth.js +15 -13
- package/libx/_runtime/common/generic/crud.js +2 -2
- package/libx/_runtime/common/generic/etag.js +11 -8
- package/libx/_runtime/common/generic/input.js +3 -3
- package/libx/_runtime/common/generic/paging.js +9 -5
- package/libx/_runtime/common/generic/put.js +3 -2
- package/libx/_runtime/common/generic/sorting.js +3 -3
- package/libx/_runtime/common/generic/temporal.js +3 -3
- package/libx/_runtime/common/utils/cqn.js +20 -1
- package/libx/_runtime/common/utils/cqn2cqn4sql.js +125 -139
- package/libx/_runtime/common/utils/csn.js +50 -52
- package/libx/_runtime/common/utils/foreignKeyPropagations.js +41 -176
- package/libx/_runtime/common/utils/generateOnCond.js +40 -70
- package/libx/_runtime/common/utils/{enrichWithKeysFromWhere.js → keys.js} +29 -28
- package/libx/_runtime/common/utils/postProcessing.js +3 -0
- package/libx/_runtime/common/utils/propagateForeignKeys.js +84 -0
- package/libx/_runtime/common/utils/resolveStructured.js +1 -1
- package/libx/_runtime/common/utils/resolveView.js +7 -5
- package/libx/_runtime/common/utils/rewriteAsterisks.js +94 -0
- package/libx/_runtime/common/utils/search2cqn4sql.js +9 -8
- package/libx/_runtime/common/utils/template.js +54 -46
- package/libx/_runtime/db/Service.js +9 -2
- package/libx/_runtime/db/expand/expandCQNToJoin.js +54 -33
- package/libx/_runtime/db/expand/rawToExpanded.js +2 -1
- package/libx/_runtime/db/generic/arrayed.js +13 -28
- package/libx/_runtime/db/generic/create.js +1 -0
- package/libx/_runtime/db/generic/input.js +7 -11
- package/libx/_runtime/db/generic/integrity.js +2 -2
- package/libx/_runtime/db/generic/rewrite.js +2 -5
- package/libx/_runtime/db/generic/update.js +1 -0
- package/libx/_runtime/db/query/read.js +9 -4
- package/libx/_runtime/db/sql-builder/ExpressionBuilder.js +6 -0
- package/libx/_runtime/db/sql-builder/SelectBuilder.js +7 -2
- package/libx/_runtime/db/sql-builder/annotations.js +1 -0
- package/libx/_runtime/db/utils/columns.js +14 -43
- package/libx/_runtime/db/utils/deep.js +5 -7
- package/libx/_runtime/fiori/generic/activate.js +3 -2
- package/libx/_runtime/fiori/generic/before.js +2 -2
- package/libx/_runtime/fiori/generic/cancel.js +3 -2
- package/libx/_runtime/fiori/generic/delete.js +3 -2
- package/libx/_runtime/fiori/generic/edit.js +3 -3
- package/libx/_runtime/fiori/generic/new.js +2 -2
- package/libx/_runtime/fiori/generic/patch.js +2 -2
- package/libx/_runtime/fiori/generic/prepare.js +2 -2
- package/libx/_runtime/fiori/generic/read.js +17 -63
- package/libx/_runtime/fiori/generic/readOverDraft.js +4 -4
- package/libx/_runtime/fiori/uiflex/extensibility/index.cds +15 -0
- package/libx/_runtime/fiori/uiflex/extensibility/index.js +148 -0
- package/libx/_runtime/fiori/uiflex/handler/transformREAD.js +119 -0
- package/libx/_runtime/fiori/uiflex/handler/transformRESULT.js +43 -0
- package/libx/_runtime/fiori/uiflex/handler/transformWRITE.js +62 -0
- package/libx/_runtime/fiori/uiflex/index.js +35 -0
- package/libx/_runtime/fiori/uiflex/utils.js +78 -0
- package/libx/_runtime/fiori/utils/handler.js +3 -13
- package/libx/_runtime/fiori/utils/where.js +6 -1
- package/libx/_runtime/hana/pool.js +12 -11
- package/libx/_runtime/hana/search2cqn4sql.js +34 -43
- package/libx/_runtime/hana/searchToContains.js +3 -3
- package/libx/_runtime/index.js +5 -2
- package/libx/_runtime/messaging/AMQPWebhookMessaging.js +1 -1
- package/libx/_runtime/messaging/common-utils/AMQPClient.js +16 -3
- package/libx/_runtime/messaging/common-utils/connections.js +11 -14
- package/libx/_runtime/messaging/common-utils/naming-conventions.js +1 -1
- package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +2 -1
- package/libx/_runtime/messaging/message-queuing.js +18 -0
- package/libx/_runtime/remote/Service.js +20 -4
- package/libx/_runtime/remote/utils/client-types.d.ts +7 -0
- package/libx/_runtime/remote/utils/client.js +117 -23
- package/libx/_runtime/sqlite/Service.js +2 -2
- package/libx/_runtime/sqlite/convertAssocToOneManaged.js +1 -3
- package/libx/gql/GraphQLAdapter.js +33 -0
- package/libx/gql/constants/adapter.js +69 -0
- package/libx/gql/constants/cds.js +18 -0
- package/libx/gql/constants/graphql.js +33 -0
- package/libx/gql/resolvers/crud/create.js +15 -0
- package/libx/gql/resolvers/crud/delete.js +24 -0
- package/libx/gql/resolvers/crud/index.js +6 -0
- package/libx/gql/resolvers/crud/read.js +25 -0
- package/libx/gql/resolvers/crud/update.js +31 -0
- package/libx/gql/resolvers/crud/utils/index.js +36 -0
- package/libx/gql/resolvers/field.js +5 -0
- package/libx/gql/resolvers/index.js +7 -0
- package/libx/gql/resolvers/mutation.js +23 -0
- package/libx/gql/resolvers/parse/ast/enrich.js +51 -0
- package/libx/gql/resolvers/parse/ast/fragment.js +11 -0
- package/libx/gql/resolvers/parse/ast/fromObject.js +39 -0
- package/libx/gql/resolvers/parse/ast/index.js +3 -0
- package/libx/gql/resolvers/parse/ast/meta.js +4 -0
- package/libx/gql/resolvers/parse/ast/variable.js +7 -0
- package/libx/gql/resolvers/parse/ast2cqn/columns.js +42 -0
- package/libx/gql/resolvers/parse/ast2cqn/entries.js +31 -0
- package/libx/gql/resolvers/parse/ast2cqn/index.js +8 -0
- package/libx/gql/resolvers/parse/ast2cqn/limit.js +6 -0
- package/libx/gql/resolvers/parse/ast2cqn/orderBy.js +24 -0
- package/libx/gql/resolvers/parse/ast2cqn/utils/index.js +3 -0
- package/libx/gql/resolvers/parse/ast2cqn/where.js +70 -0
- package/libx/gql/resolvers/parse/utils/index.js +8 -0
- package/libx/gql/resolvers/query.js +13 -0
- package/libx/gql/resolvers/root.js +34 -0
- package/libx/gql/schema/generate.js +18 -0
- package/libx/gql/schema/index.js +5 -0
- package/libx/gql/schema/mutation.js +76 -0
- package/libx/gql/schema/query.js +108 -0
- package/libx/gql/schema/typeDefMap.js +45 -0
- package/libx/gql/schema/utils/index.js +54 -0
- package/libx/gql/utils/index.js +12 -0
- package/libx/{_runtime/odata/cqn2odata.js → odata/cqn2odata/index.js} +39 -100
- package/libx/odata/index.js +80 -0
- package/libx/odata/odata2cqn/afterburner.js +170 -0
- package/libx/{_runtime/odata/odata2cqn.pegjs → odata/odata2cqn/grammar.pegjs} +102 -123
- package/libx/odata/odata2cqn/index.js +3 -0
- package/libx/odata/odata2cqn/parser.js +1 -0
- package/libx/odata/utils/index.js +64 -0
- package/libx/rest/RestAdapter.js +101 -0
- package/libx/rest/RestRequest.js +30 -0
- package/libx/rest/index.js +3 -0
- package/libx/rest/middleware/auth.js +22 -0
- package/libx/rest/middleware/content.js +15 -0
- package/libx/rest/middleware/create.js +40 -0
- package/libx/rest/middleware/delete.js +20 -0
- package/libx/rest/middleware/error.js +56 -0
- package/libx/rest/middleware/operation.js +39 -0
- package/libx/rest/middleware/parse.js +90 -0
- package/libx/rest/middleware/read.js +29 -0
- package/libx/rest/middleware/update.js +42 -0
- package/libx/rest/utils/data.js +65 -0
- package/package.json +4 -1
- package/server.js +29 -7
- package/libx/_runtime/cds-services/services/utils/diff.js +0 -53
- package/libx/_runtime/cds-services/util/auditlog.js +0 -247
- package/libx/_runtime/cds-services/util/xsenv.js +0 -51
- package/libx/_runtime/common/utils/backlinks.js +0 -83
- package/libx/_runtime/common/utils/rewriteAsterisk.js +0 -72
- package/libx/_runtime/odata/index.js +0 -55
- package/libx/_runtime/odata/odata2cqn.js +0 -1
- package/libx/_runtime/odata/readToCqn.js +0 -129
- package/libx/_runtime/remote/cqn2odata/index.js +0 -2
|
@@ -24,12 +24,16 @@
|
|
|
24
24
|
* Books?$select=ID,title&$expand=author($select=name)&$filter=stock gt 1&$orderby=title
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
+
//
|
|
27
28
|
// ---------- JavaScript Helpers -------------
|
|
28
29
|
{
|
|
29
|
-
|
|
30
|
+
const exception = (message, code = 400) => {
|
|
31
|
+
error(JSON.stringify({ code, message }))
|
|
32
|
+
}
|
|
33
|
+
const $ = Object.assign
|
|
30
34
|
const { strict, minimal } = options
|
|
31
|
-
const stack=[]
|
|
32
|
-
let SELECT
|
|
35
|
+
const stack = []
|
|
36
|
+
let SELECT, count
|
|
33
37
|
const TECHNICAL_OPTS = ['$value'] // odata parts to be handled somewhere else
|
|
34
38
|
|
|
35
39
|
// we keep that here to allow for usage in https://pegjs.org/online
|
|
@@ -38,71 +42,17 @@
|
|
|
38
42
|
return Number.isSafeInteger(n) ? n : str
|
|
39
43
|
}
|
|
40
44
|
|
|
41
|
-
// check whether we have any
|
|
42
|
-
// - $select
|
|
43
|
-
// - aggregate(... as someProp)
|
|
44
|
-
const hasNOTAny$select = (columns) => {
|
|
45
|
-
return columns.filter(cur => cur.ref ? !cur.expand : cur.as).length === 0;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const adaptColumns = (SELECT) => {
|
|
49
|
-
const columns = SELECT.columns
|
|
50
|
-
if (!columns) return SELECT
|
|
51
|
-
|
|
52
|
-
// when $select and $expand was NOT defined
|
|
53
|
-
if (!hasNOTAny$select(columns)) {
|
|
54
|
-
const columnsMap = new Map()
|
|
55
|
-
|
|
56
|
-
columns.forEach(column => {
|
|
57
|
-
|
|
58
|
-
if (column === '*') {
|
|
59
|
-
columnsMap.set(column, column)
|
|
60
|
-
return
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (!column.ref) {
|
|
64
|
-
columnsMap.set(column.as, column)
|
|
65
|
-
return
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const columnRefName = column.ref.join('/')
|
|
69
|
-
|
|
70
|
-
if (!columnsMap.has(columnRefName) || column.expand) {
|
|
71
|
-
columnsMap.set(columnRefName, column)
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
if (columnsMap.size > 0) {
|
|
76
|
-
SELECT.columns = Array.from(columnsMap.values())
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return SELECT
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (columns.length === 1 && columns[0] === '*') {
|
|
83
|
-
delete SELECT.columns
|
|
84
|
-
return SELECT
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// in case when have $expand but have NOT $select
|
|
88
|
-
if (!columns.includes('*')) {
|
|
89
|
-
SELECT.columns.unshift('*')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return SELECT
|
|
93
|
-
}
|
|
94
|
-
|
|
95
45
|
// NOTe: mutation of the object property, it's NOT a pure function
|
|
96
46
|
const correctAggAwayWhere = (where, colNames) => {
|
|
97
|
-
|
|
47
|
+
const changedWhere = [...where];
|
|
98
48
|
|
|
99
49
|
for (const item of changedWhere) {
|
|
100
|
-
|
|
101
|
-
|
|
50
|
+
if (item.xpr) {
|
|
51
|
+
item.xpr = correctAggAwayWhere(item.xpr, colNames)
|
|
102
52
|
}
|
|
103
53
|
|
|
104
54
|
if (item.args) {
|
|
105
|
-
|
|
55
|
+
item.args = correctAggAwayWhere(item.args, colNames)
|
|
106
56
|
}
|
|
107
57
|
|
|
108
58
|
// $filter ohne $apply -> input set = entity -> kein null setzen
|
|
@@ -112,7 +62,7 @@
|
|
|
112
62
|
|
|
113
63
|
// TODO fix this for $apply
|
|
114
64
|
if(item.ref && !colNames.includes(item.ref.join(''))) {
|
|
115
|
-
|
|
65
|
+
// item.ref = null;
|
|
116
66
|
}
|
|
117
67
|
// REVISIT: { val:null } for should be also implemented
|
|
118
68
|
}
|
|
@@ -126,7 +76,7 @@
|
|
|
126
76
|
const columns = SELECT.columns || [];
|
|
127
77
|
const aggregates = columns.filter((cur) => cur.as);
|
|
128
78
|
|
|
129
|
-
|
|
79
|
+
let fromAggregate = [];
|
|
130
80
|
let fromGroupBy = [];
|
|
131
81
|
|
|
132
82
|
// handle $apply=aggregate(... as someProp)&$select=someProp,?...
|
|
@@ -138,28 +88,33 @@
|
|
|
138
88
|
|
|
139
89
|
// handle $apply=groupby((someProp,?...))&$select=?...
|
|
140
90
|
if (groupBy) {
|
|
141
|
-
const allowedNames = groupBy.map(({ ref }) => ref.join(''));
|
|
91
|
+
const allowedNames = groupBy.map(({ ref }) => ref && ref.join(''));
|
|
142
92
|
const allowedColumns = columns.filter((cur) =>
|
|
143
|
-
|
|
93
|
+
cur.ref && allowedNames.includes(cur.ref.join(''))
|
|
144
94
|
);
|
|
145
95
|
fromGroupBy = allowedColumns.length === 0 ? [...groupBy] : allowedColumns;
|
|
146
96
|
}
|
|
147
97
|
|
|
148
98
|
const newColumns = fromAggregate.length !== 0 || fromGroupBy.length !== 0
|
|
149
|
-
|
|
99
|
+
? [...fromGroupBy, ...fromAggregate]
|
|
150
100
|
: SELECT.columns;
|
|
151
101
|
|
|
152
|
-
let result = { ...SELECT
|
|
102
|
+
let result = { ...SELECT }
|
|
103
|
+
if (newColumns) result.columns = newColumns
|
|
153
104
|
let newWhere = [];
|
|
154
105
|
|
|
155
106
|
if (where && (groupBy || aggregates.length !== 0)) {
|
|
156
|
-
|
|
157
|
-
|
|
107
|
+
// changing { ref: null } for aggregated-away props
|
|
108
|
+
const colNames = columns.map((cur) => cur.ref && cur.ref.join('') || cur.as);
|
|
158
109
|
result = { ...result, where: correctAggAwayWhere(where, colNames) }
|
|
159
|
-
|
|
110
|
+
}
|
|
160
111
|
|
|
161
112
|
return result;
|
|
162
113
|
}
|
|
114
|
+
|
|
115
|
+
const _compareRefs = col => exp => col === exp ||
|
|
116
|
+
(col.as && exp.as && col.as === exp.as) ||
|
|
117
|
+
(col.ref && exp.ref && col.ref.join('') === exp.ref.join(''))
|
|
163
118
|
}
|
|
164
119
|
|
|
165
120
|
// ---------- Entity Paths ---------------
|
|
@@ -167,42 +122,49 @@
|
|
|
167
122
|
ODataRelativeURI // Note: case-sensitive!
|
|
168
123
|
= '/'? (p:path { SELECT = p })
|
|
169
124
|
( o"?"o QueryOption ( o'&'o QueryOption )* )? o {
|
|
170
|
-
if (
|
|
125
|
+
if (count) {
|
|
171
126
|
// columns set because of $count: ignore $select, $expand, $top, $skip, $orderby
|
|
172
|
-
// REVISIT: don't ignore query options but throw bad request (as okra did)?
|
|
127
|
+
// REVISIT: don't ignore query options but throw bad request (as okra did)?
|
|
128
|
+
SELECT.columns = [{ args: [{ val: 1 }], as: '$count', func: 'count' }]
|
|
173
129
|
delete SELECT.expand
|
|
174
130
|
delete SELECT.limit
|
|
175
131
|
delete SELECT.orderBy
|
|
176
132
|
return { SELECT }
|
|
177
133
|
}
|
|
178
134
|
if (SELECT.expand) {
|
|
179
|
-
|
|
135
|
+
// Books?$expand=author w/o $select=author
|
|
136
|
+
if (!SELECT.columns) SELECT.columns = ['*']
|
|
137
|
+
for (const exp of SELECT.expand) {
|
|
138
|
+
const idx = SELECT.columns.findIndex(_compareRefs(exp))
|
|
139
|
+
if (idx > -1) SELECT.columns.splice(idx, 1)
|
|
140
|
+
SELECT.columns.push(exp)
|
|
141
|
+
}
|
|
180
142
|
delete SELECT.expand
|
|
181
143
|
}
|
|
182
|
-
|
|
183
144
|
SELECT = correctAggAwayColumns(SELECT)
|
|
184
|
-
SELECT = adaptColumns(SELECT)
|
|
185
|
-
|
|
186
|
-
// REVISIT: shouldn't be necessary
|
|
187
|
-
if (!SELECT.columns) delete SELECT.columns
|
|
188
145
|
|
|
189
146
|
return { SELECT }
|
|
190
147
|
}
|
|
191
148
|
|
|
192
149
|
path
|
|
193
|
-
= "$count" {
|
|
150
|
+
= "$count" {count = true}
|
|
194
151
|
/ rv:$("$ref"/"$value") {return !TECHNICAL_OPTS.includes(rv) && {from: {ref: [rv]}}}
|
|
195
|
-
/ head:(identifier/val) filter:(OPEN args CLOSE)? tail:( '/' p:path {return p} )? {
|
|
152
|
+
/ head:(identifier/val) filter:(OPEN CLOSE/OPEN args CLOSE)? tail:( '/' p:path {return p} )? {
|
|
196
153
|
// minimal: val also as path segment
|
|
197
|
-
const ref = [
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
154
|
+
const ref = [
|
|
155
|
+
filter
|
|
156
|
+
? filter.length > 2
|
|
157
|
+
? { id: head, where: filter[1].map(f => f.val && f.val.match && f.val.match(/^"(.*)"$/) ? { val: f.val.match(/^"(.*)"$/)[1] } : f) }
|
|
158
|
+
: { id: head, where: [] }
|
|
159
|
+
: ( minimal ? `${Object.prototype.hasOwnProperty.call(head, 'val') ? head.val : head}` : head )
|
|
160
|
+
]
|
|
161
|
+
if (tail && tail.from) {
|
|
162
|
+
const more = tail.from.ref
|
|
163
|
+
if (Object.prototype.hasOwnProperty.call(more[0], 'val')) ref[ref.length-1] = { id:ref[ref.length-1], where:[more.shift()] }
|
|
164
|
+
ref.push (...more)
|
|
202
165
|
}
|
|
203
|
-
|
|
204
166
|
const res = {from: {ref}}
|
|
205
|
-
if (tail) res.columns = tail.columns
|
|
167
|
+
if (tail && tail.columns) res.columns = tail.columns
|
|
206
168
|
return res
|
|
207
169
|
}
|
|
208
170
|
|
|
@@ -214,45 +176,57 @@
|
|
|
214
176
|
return args
|
|
215
177
|
}
|
|
216
178
|
|
|
217
|
-
|
|
179
|
+
//
|
|
218
180
|
// ---------- Query Options ------------
|
|
219
181
|
|
|
220
182
|
QueryOption = ExpandOption
|
|
221
183
|
ExpandOption =
|
|
222
|
-
"$select="
|
|
223
|
-
"$expand="
|
|
224
|
-
"$filter="
|
|
225
|
-
"$orderby="
|
|
226
|
-
"$top="
|
|
227
|
-
"$skip="
|
|
228
|
-
"$search="
|
|
229
|
-
"$count="
|
|
184
|
+
"$select=" o select ( COMMA select )* /
|
|
185
|
+
"$expand=" o expand ( COMMA expand )* /
|
|
186
|
+
"$filter=" o filter /
|
|
187
|
+
"$orderby=" o orderby ( COMMA orderby )* /
|
|
188
|
+
"$top=" o top /
|
|
189
|
+
"$skip=" o skip /
|
|
190
|
+
"$search=" o search /
|
|
191
|
+
"$count=" o count /
|
|
230
192
|
"$apply=" o apply /
|
|
231
193
|
custom
|
|
232
194
|
|
|
233
195
|
|
|
234
196
|
select
|
|
235
|
-
= col:(
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
) {
|
|
239
|
-
SELECT.expand = SELECT.expand || []
|
|
240
|
-
SELECT.expand.push(col)
|
|
197
|
+
= col:('*'/ref) {
|
|
198
|
+
SELECT.columns = Array.isArray(SELECT.columns) ? SELECT.columns : []
|
|
199
|
+
if (!SELECT.columns.find(_compareRefs(col))) SELECT.columns.push(col)
|
|
241
200
|
return col
|
|
242
201
|
}
|
|
243
202
|
|
|
244
203
|
expand =
|
|
245
|
-
(
|
|
204
|
+
(
|
|
205
|
+
c:('*'/ref) {
|
|
206
|
+
const col = c === '*' ? {} : c
|
|
207
|
+
col.expand = '*'
|
|
208
|
+
if (!Array.isArray(SELECT.expand)) SELECT.expand = []
|
|
209
|
+
if (!SELECT.expand.find(_compareRefs(col))) SELECT.expand.push(col)
|
|
210
|
+
return col
|
|
211
|
+
}
|
|
212
|
+
)
|
|
246
213
|
( // --- nested query options, if any
|
|
247
214
|
(OPEN {
|
|
248
215
|
stack.push (SELECT)
|
|
249
|
-
SELECT = SELECT.expand[SELECT.expand.length
|
|
250
|
-
SELECT.expand =
|
|
216
|
+
SELECT = SELECT.expand[SELECT.expand.length-1]
|
|
217
|
+
SELECT.expand = '*' // by default expand everything
|
|
251
218
|
})(
|
|
252
|
-
|
|
219
|
+
expandOptions:( o ";"? o ExpandOption)*
|
|
253
220
|
{
|
|
254
|
-
|
|
255
|
-
if (
|
|
221
|
+
if (SELECT.columns) {
|
|
222
|
+
if (SELECT.expand === '*') SELECT.expand = []
|
|
223
|
+
for (const col of SELECT.columns) {
|
|
224
|
+
if (!SELECT.expand.find(_compareRefs(col))) SELECT.expand.push(col)
|
|
225
|
+
}
|
|
226
|
+
delete SELECT.columns
|
|
227
|
+
} else {
|
|
228
|
+
if (Array.isArray(SELECT.expand) && SELECT.expand.indexOf('*') === -1) SELECT.expand.unshift('*')
|
|
229
|
+
}
|
|
256
230
|
}
|
|
257
231
|
)(CLOSE {
|
|
258
232
|
SELECT = stack.pop()
|
|
@@ -272,7 +246,7 @@
|
|
|
272
246
|
|
|
273
247
|
search
|
|
274
248
|
= p:search_clause {SELECT.search = p}
|
|
275
|
-
|
|
249
|
+
|
|
276
250
|
search_clause
|
|
277
251
|
= p:( n:NOT? {return n?[n]:[]} )(
|
|
278
252
|
OPEN xpr:search_clause CLOSE {p.push({xpr})}
|
|
@@ -292,6 +266,7 @@
|
|
|
292
266
|
/ comp:comparison {p.push(...comp)}
|
|
293
267
|
/ lambda:lambda {p.push(...lambda)}
|
|
294
268
|
/ func:boolish {p.push(func)}
|
|
269
|
+
/ val:bool {p.push({val})}
|
|
295
270
|
)( ao:(AND/OR) more:where_clause {p.push(ao,...more)} )*
|
|
296
271
|
{return p}
|
|
297
272
|
|
|
@@ -351,7 +326,7 @@
|
|
|
351
326
|
= ref:(function/ref) sort:( _ s:$("asc"/"desc") {return s})? {
|
|
352
327
|
const appendObj = $(ref, sort && {sort});
|
|
353
328
|
SELECT.orderBy = SELECT.orderBy ?
|
|
354
|
-
|
|
329
|
+
[...SELECT.orderBy, appendObj] :
|
|
355
330
|
[appendObj]
|
|
356
331
|
}
|
|
357
332
|
|
|
@@ -390,13 +365,13 @@
|
|
|
390
365
|
}
|
|
391
366
|
|
|
392
367
|
val
|
|
393
|
-
|
|
368
|
+
= val:(bool / date) {return {val}}
|
|
394
369
|
/ guid
|
|
395
370
|
/ val:number {return typeof val === 'number' ? {val} : { val, literal:'number' }}
|
|
396
371
|
/ val:string {return {val}}
|
|
397
372
|
|
|
398
373
|
jsonObject = val:$("{" (jsonObject / [^}])* "}") {return {val}}
|
|
399
|
-
|
|
374
|
+
|
|
400
375
|
jsonArray = val:$("[" o "]" / "[" o "{" (jsonArray / [^\]])* "]") {return {val}}
|
|
401
376
|
|
|
402
377
|
list
|
|
@@ -405,7 +380,7 @@
|
|
|
405
380
|
|
|
406
381
|
function "a function call"
|
|
407
382
|
= func:$[a-z]+ OPEN a:operand more:( COMMA o:operand {return o} )* CLOSE {
|
|
408
|
-
if (strict && !(func in strict.functions))
|
|
383
|
+
if (strict && !(func in strict.functions)) exception("'"+ func +"' is an unknown function in OData URL spec (strict mode)")
|
|
409
384
|
return { func, args:[a,...more] }
|
|
410
385
|
}
|
|
411
386
|
|
|
@@ -419,7 +394,7 @@
|
|
|
419
394
|
OR = _ "OR"i _ {return 'or'}
|
|
420
395
|
|
|
421
396
|
|
|
422
|
-
|
|
397
|
+
//
|
|
423
398
|
// ---------- Transformations ------------
|
|
424
399
|
|
|
425
400
|
applyTrafo
|
|
@@ -448,7 +423,11 @@
|
|
|
448
423
|
aggregateItem
|
|
449
424
|
= res:("$count" alias:asAlias { return { func: 'count', args: ['*'], as: alias } }
|
|
450
425
|
/ aggregateExpr
|
|
451
|
-
) {
|
|
426
|
+
) {
|
|
427
|
+
SELECT.columns = Array.isArray(SELECT.columns) ? SELECT.columns : []
|
|
428
|
+
if (!SELECT.columns.find(_compareRefs(res))) SELECT.columns.push(res)
|
|
429
|
+
return res
|
|
430
|
+
}
|
|
452
431
|
aggregateExpr
|
|
453
432
|
= path:(
|
|
454
433
|
ref
|
|
@@ -470,8 +449,8 @@
|
|
|
470
449
|
groupByElem
|
|
471
450
|
= val:(rollupSpec / ref)
|
|
472
451
|
{ (SELECT.groupBy || (SELECT.groupBy = [])).push(val) }
|
|
473
|
-
rollupSpec //
|
|
474
|
-
= "rollup" OPEN o ('$all' / ref) (o COMMA ref)+ o CLOSE
|
|
452
|
+
rollupSpec // TODO fix this + add CAP support
|
|
453
|
+
= rollup:("rollup" OPEN o ('$all' / ref) (o COMMA ref)+ o CLOSE) {const err = new Error("Rollup in groupby is not supported yet.");err.statusCode=501;throw err;}
|
|
475
454
|
|
|
476
455
|
filterTrafo = OPEN o filter o CLOSE
|
|
477
456
|
|
|
@@ -504,7 +483,7 @@
|
|
|
504
483
|
identityTrafo = "identity"
|
|
505
484
|
|
|
506
485
|
|
|
507
|
-
|
|
486
|
+
//
|
|
508
487
|
// ---------- Literals -----------
|
|
509
488
|
|
|
510
489
|
bool = b:("true" / "false") { return b === 'true'}
|
|
@@ -518,7 +497,7 @@
|
|
|
518
497
|
{return s.replace(/\\\\/g,"\\").replace(/\\"/g,'"')}
|
|
519
498
|
|
|
520
499
|
word
|
|
521
|
-
= s:$([
|
|
500
|
+
= s:$([a-zA-Z0-9.+-]+)
|
|
522
501
|
|
|
523
502
|
date
|
|
524
503
|
= s:$( [0-9]+"-"[0-9][0-9]"-"[0-9][0-9] // date
|
|
@@ -538,9 +517,9 @@
|
|
|
538
517
|
= !bool !guid s:$([_a-zA-Z][_a-zA-Z0-9"."]*) {return s}
|
|
539
518
|
|
|
540
519
|
guid = val:$([0-9a-zA-Z]+ "-" ([0-9a-zA-Z]+ "-"?)+)
|
|
541
|
-
|
|
520
|
+
{return {val}}
|
|
542
521
|
|
|
543
|
-
|
|
522
|
+
//
|
|
544
523
|
// ---------- Punctuation ----------
|
|
545
524
|
|
|
546
525
|
COLON = o":"o
|
|
@@ -549,11 +528,11 @@
|
|
|
549
528
|
OPEN = o"("o
|
|
550
529
|
CLOSE = o")"
|
|
551
530
|
|
|
552
|
-
|
|
531
|
+
//
|
|
553
532
|
// ---------- Whitespaces -----------
|
|
554
533
|
|
|
555
534
|
o "optional whitespaces" = $[ \t\n]*
|
|
556
535
|
_ "mandatory whitespaces" = $[ \t\n]+
|
|
557
536
|
|
|
558
|
-
|
|
537
|
+
//
|
|
559
538
|
// ------------------------------------
|
|
@@ -0,0 +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:we},u=we,a="/",c=ve("/",!1),o=ve("?",!1),i=ve("&",!1),f="$count",l=ve("$count",!1),h="$ref",p=ve("$ref",!1),A="$value",d=ve("$value",!1),g=ve("=",!1),v="$select=",b=ve("$select=",!1),m="$expand=",x=ve("$expand=",!1),C="$filter=",y=ve("$filter=",!1),$="$orderby=",w=ve("$orderby=",!1),E="$top=",S=ve("$top=",!1),z="$skip=",Z=ve("$skip=",!1),j="$search=",O=ve("$search=",!1),B="$count=",R=ve("$count=",!1),F="$apply=",T=ve("$apply=",!1),L=ve("*",!1),N=ve(";",!1),k=function(t){return t?[t]:[]},q=function(t,r){t.push({xpr:r})},I=function(t,r){t.push({val:r})},_=function(t,r,e){t.push(r,...e)},D=function(t,r){t.push(r)},U=function(t,r,e){t.push(r,...e)},M=":",P=ve(":",!1),J="any",G=ve("any",!1),H="all",K=ve("all",!1),Q=ve("asc",!1),V="desc",W=ve("desc",!1),X=/^[a-zA-Z]/,Y=be([["a","z"],["A","Z"]],!1,!1),tt=/^[a-zA-Z0-9\-]/,rt=be([["a","z"],["A","Z"],["0","9"],"-"],!1,!1),et=/^[^&]/,nt=be(["&"],!0,!1),st=me("a comparison"),ut=ve("eq",!1),at=ve("ne",!1),ct=ve("lt",!1),ot=ve("gt",!1),it=ve("le",!1),ft=ve("ge",!1),lt=(ve("add",!1),ve("sub",!1),ve("mul",!1),ve("div",!1),ve("mod",!1),me("an operand")),ht=me("a reference"),pt=function(t,r){return r},At=function(t){return{val:t}},dt=ve("{",!1),gt=/^[^}]/,vt=be(["}"],!0,!1),bt=ve("}",!1),mt="[",xt=ve("[",!1),Ct="]",yt=ve("]",!1),$t=/^[^\]]/,wt=be(["]"],!0,!1),Et=me("a function call"),St=/^[a-z]/,zt=be([["a","z"]],!1,!1),Zt=function(t,r,e){return e},jt=me("a boolean function"),Ot="contains",Bt=ve("contains",!1),Rt="endswith",Ft=ve("endswith",!1),Tt="startswith",Lt=ve("startswith",!1),Nt=ve("NOT",!0),kt=ve("AND",!0),qt=ve("OR",!0),It="aggregate",_t=ve("aggregate",!1),Dt="groupby",Ut=ve("groupby",!1),Mt="filter",Pt=ve("filter",!1),Jt="expand",Gt=ve("expand",!1),Ht="search",Kt=ve("search",!1),Qt="concat",Vt=ve("concat",!1),Wt="compute",Xt=ve("compute",!1),Yt="bottompercent",tr=ve("bottompercent",!1),rr="bottomsum",er=ve("bottomsum",!1),nr="toppercent",sr=ve("toppercent",!1),ur="topsum",ar=ve("topsum",!1),cr="with",or=ve("with",!1),ir="from",fr=ve("from",!1),lr=ve("as",!1),hr="rollup",pr=ve("rollup",!1),Ar="$all",dr=ve("$all",!1),gr="topcount",vr=ve("topcount",!1),br="bottomcount",mr=ve("bottomcount",!1),xr="identity",Cr=ve("identity",!1),yr="true",$r=ve("true",!1),wr="false",Er=ve("false",!1),Sr=me("Edm.String"),zr=ve("'",!1),Zr="''",jr=ve("''",!1),Or=/^[^']/,Br=be(["'"],!0,!1),Rr='"',Fr=ve('"',!1),Tr='\\"',Lr=ve('\\"',!1),Nr=/^[^"]/,kr=be(['"'],!0,!1),qr=/^[a-zA-Z0-9.+\-]/,Ir=be([["a","z"],["A","Z"],["0","9"],".","+","-"],!1,!1),_r=/^[0-9]/,Dr=be([["0","9"]],!1,!1),Ur="-",Mr=ve("-",!1),Pr=ve("T",!1),Jr=ve(".",!1),Gr=ve("Z",!1),Hr=ve("+",!1),Kr=/^[+\-]/,Qr=be(["+","-"],!1,!1),Vr=ve("e",!1),Wr=/^[_a-zA-Z]/,Xr=be(["_",["a","z"],["A","Z"]],!1,!1),Yr=/^[_a-zA-Z0-9"."]/,te=be(["_",["a","z"],["A","Z"],["0","9"],'"',".",'"'],!1,!1),re=/^[0-9a-zA-Z]/,ee=be([["0","9"],["a","z"],["A","Z"]],!1,!1),ne=ve(",",!1),se=ve("(",!1),ue=ve(")",!1),ae=me("optional whitespaces"),ce=/^[ \t\n]/,oe=be([" ","\t","\n"],!1,!1),ie=me("mandatory whitespaces"),fe=0,le=0,he=[{line:1,column:1}],pe=0,Ae=[],de=0;if("startRule"in r){if(!(r.startRule in s))throw new Error("Can't start parsing from rule \""+r.startRule+'".');u=s[r.startRule]}function ge(t,r){throw function(t,r){return new peg$SyntaxError(t,null,null,r)}(t,r=void 0!==r?r:Ce(le,fe))}function ve(t,r){return{type:"literal",text:t,ignoreCase:r}}function be(t,r,e){return{type:"class",parts:t,inverted:r,ignoreCase:e}}function me(t){return{type:"other",description:t}}function xe(r){var e,n=he[r];if(n)return n;for(e=r-1;!he[e];)e--;for(n={line:(n=he[e]).line,column:n.column};e<r;)10===t.charCodeAt(e)?(n.line++,n.column=1):n.column++,e++;return he[r]=n,n}function Ce(t,r){var e=xe(t),n=xe(r);return{start:{offset:t,line:e.line,column:e.column},end:{offset:r,line:n.line,column:n.column}}}function ye(t){fe<pe||(fe>pe&&(pe=fe,Ae=[]),Ae.push(t))}function $e(t,r,e){return new peg$SyntaxError(peg$SyntaxError.buildMessage(t,r),t,r,e)}function we(){var r,e,s,u,f,l,h,p,A,d,g,v,b,m;if(r=fe,47===t.charCodeAt(fe)?(e=a,fe++):(e=n,0===de&&ye(c)),e===n&&(e=null),e!==n)if(s=fe,(u=Ee())!==n&&(le=s,u=void(En=u)),(s=u)!==n){if(u=fe,(f=bn())!==n)if(63===t.charCodeAt(fe)?(l="?",fe++):(l=n,0===de&&ye(o)),l!==n)if((h=bn())!==n)if((p=ze())!==n){for(A=[],d=fe,(g=bn())!==n?(38===t.charCodeAt(fe)?(v="&",fe++):(v=n,0===de&&ye(i)),v!==n&&(b=bn())!==n&&(m=ze())!==n?d=g=[g,v,b,m]:(fe=d,d=n)):(fe=d,d=n);d!==n;)A.push(d),d=fe,(g=bn())!==n?(38===t.charCodeAt(fe)?(v="&",fe++):(v=n,0===de&&ye(i)),v!==n&&(b=bn())!==n&&(m=ze())!==n?d=g=[g,v,b,m]:(fe=d,d=n)):(fe=d,d=n);A!==n?u=f=[f,l,h,p,A]:(fe=u,u=n)}else fe=u,u=n;else fe=u,u=n;else fe=u,u=n;else fe=u,u=n;u===n&&(u=null),u!==n&&(f=bn())!==n?(le=r,r=e=function(){if(Sn)return En.columns=[{args:[{val:1}],as:"$count",func:"count"}],delete En.expand,delete En.limit,delete En.orderBy,{SELECT:En};if(En.expand){En.columns||(En.columns=["*"]);for(const t of En.expand){const r=En.columns.findIndex(Bn(t));r>-1&&En.columns.splice(r,1),En.columns.push(t)}delete En.expand}return En=On(En),{SELECT:En}}()):(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n;return r}function Ee(){var r,e,s,u,o,i,g;return r=fe,t.substr(fe,6)===f?(e=f,fe+=6):(e=n,0===de&&ye(l)),e!==n&&(le=r,e=void(Sn=!0)),(r=e)===n&&(r=fe,e=fe,t.substr(fe,4)===h?(s=h,fe+=4):(s=n,0===de&&ye(p)),s===n&&(t.substr(fe,6)===A?(s=A,fe+=6):(s=n,0===de&&ye(d))),(e=s!==n?t.substring(e,fe):s)!==n&&(le=r,g=e,e=!zn.includes(g)&&{from:{ref:[g]}}),(r=e)===n&&(r=fe,(e=pn())===n&&(e=Ue()),e!==n?(s=fe,(u=gn())!==n&&(o=vn())!==n?s=u=[u,o]:(fe=s,s=n),s===n&&(s=fe,(u=gn())!==n&&(o=Se())!==n&&(i=vn())!==n?s=u=[u,o,i]:(fe=s,s=n)),s===n&&(s=null),s!==n?(u=fe,47===t.charCodeAt(fe)?(o=a,fe++):(o=n,0===de&&ye(c)),o!==n&&(i=Ee())!==n?(le=u,u=o=i):(fe=u,u=n),u===n&&(u=null),u!==n?(le=r,r=e=function(t,r,e){const n=[r?r.length>2?{id:t,where:r[1].map((t=>t.val&&t.val.match&&t.val.match(/^"(.*)"$/)?{val:t.val.match(/^"(.*)"$/)[1]}:t))}:{id:t,where:[]}:$n?`${Object.prototype.hasOwnProperty.call(t,"val")?t.val:t}`:t];if(e&&e.from){const t=e.from.ref;Object.prototype.hasOwnProperty.call(t[0],"val")&&(n[n.length-1]={id:n[n.length-1],where:[t.shift()]}),n.push(...t)}const s={from:{ref:n}};return e&&e.columns&&(s.columns=e.columns),s}(e,s,u)):(fe=r,r=n)):(fe=r,r=n)):(fe=r,r=n))),r}function Se(){var r,e,s,u,a,c,o;return r=fe,(e=Ue())!==n&&(le=r,e=[e]),(r=e)===n&&(r=fe,(e=De())!==n&&bn()!==n?(61===t.charCodeAt(fe)?(s="=",fe++):(s=n,0===de&&ye(g)),s!==n&&bn()!==n?((u=Ue())===n&&(u=fe,(a=fn())!==n&&(le=u,a={val:a}),u=a),u!==n?(a=fe,(c=dn())!==n&&(o=Se())!==n?a=c=[c,o]:(fe=a,a=n),a===n&&(a=null),a!==n?(le=r,e=function(t,r,e){const n=[t,"=",r];return e&&n.push("and",...e[1]),n}(e,u,a),r=e):(fe=r,r=n)):(fe=r,r=n)):(fe=r,r=n)):(fe=r,r=n)),r}function ze(){var r,e,s,u,a,c,o,i;if(r=fe,t.substr(fe,8)===v?(e=v,fe+=8):(e=n,0===de&&ye(b)),e!==n)if((s=bn())!==n)if((u=Ze())!==n){for(a=[],c=fe,(o=dn())!==n&&(i=Ze())!==n?c=o=[o,i]:(fe=c,c=n);c!==n;)a.push(c),c=fe,(o=dn())!==n&&(i=Ze())!==n?c=o=[o,i]:(fe=c,c=n);a!==n?r=e=[e,s,u,a]:(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n;else fe=r,r=n;if(r===n){if(r=fe,t.substr(fe,8)===m?(e=m,fe+=8):(e=n,0===de&&ye(x)),e!==n)if((s=bn())!==n)if((u=je())!==n){for(a=[],c=fe,(o=dn())!==n&&(i=je())!==n?c=o=[o,i]:(fe=c,c=n);c!==n;)a.push(c),c=fe,(o=dn())!==n&&(i=je())!==n?c=o=[o,i]:(fe=c,c=n);a!==n?r=e=[e,s,u,a]:(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n;else fe=r,r=n;if(r===n&&(r=fe,t.substr(fe,8)===C?(e=C,fe+=8):(e=n,0===de&&ye(y)),e!==n&&(s=bn())!==n&&(u=Re())!==n?r=e=[e,s,u]:(fe=r,r=n),r===n)){if(r=fe,t.substr(fe,9)===$?(e=$,fe+=9):(e=n,0===de&&ye(w)),e!==n)if((s=bn())!==n)if((u=ke())!==n){for(a=[],c=fe,(o=dn())!==n&&(i=ke())!==n?c=o=[o,i]:(fe=c,c=n);c!==n;)a.push(c),c=fe,(o=dn())!==n&&(i=ke())!==n?c=o=[o,i]:(fe=c,c=n);a!==n?r=e=[e,s,u,a]:(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n;else fe=r,r=n;r===n&&(r=fe,t.substr(fe,5)===E?(e=E,fe+=5):(e=n,0===de&&ye(S)),e!==n&&(s=bn())!==n?(u=function(){var t,r;t=fe,(r=hn())!==n&&(le=t,e=r,r=void((En.limit||(En.limit={})).rows={val:e}));var e;return t=r}(),u!==n?r=e=[e,s,u]:(fe=r,r=n)):(fe=r,r=n),r===n&&(r=fe,t.substr(fe,6)===z?(e=z,fe+=6):(e=n,0===de&&ye(Z)),e!==n&&(s=bn())!==n?(u=function(){var t,r;t=fe,(r=hn())!==n&&(le=t,e=r,r=void((En.limit||(En.limit={})).offset={val:e}));var e;return t=r}(),u!==n?r=e=[e,s,u]:(fe=r,r=n)):(fe=r,r=n),r===n&&(r=fe,t.substr(fe,8)===j?(e=j,fe+=8):(e=n,0===de&&ye(O)),e!==n&&(s=bn())!==n&&(u=Oe())!==n?r=e=[e,s,u]:(fe=r,r=n),r===n&&(r=fe,t.substr(fe,7)===B?(e=B,fe+=7):(e=n,0===de&&ye(R)),e!==n&&(s=bn())!==n?(u=function(){var t,r;t=fe,(r=cn())!==n&&(le=t,r=void(r&&(En.count=!0)));return t=r}(),u!==n?r=e=[e,s,u]:(fe=r,r=n)):(fe=r,r=n),r===n&&(r=fe,t.substr(fe,7)===F?(e=F,fe+=7):(e=n,0===de&&ye(T)),e!==n&&(s=bn())!==n&&(u=qe())!==n?r=e=[e,s,u]:(fe=r,r=n),r===n&&(r=function(){var r,e,s,u,a,c;r=fe,X.test(t.charAt(fe))?(e=t.charAt(fe),fe++):(e=n,0===de&&ye(Y));if(e!==n){for(s=[],tt.test(t.charAt(fe))?(u=t.charAt(fe),fe++):(u=n,0===de&&ye(rt));u!==n;)s.push(u),tt.test(t.charAt(fe))?(u=t.charAt(fe),fe++):(u=n,0===de&&ye(rt));if(s!==n)if(61===t.charCodeAt(fe)?(u="=",fe++):(u=n,0===de&&ye(g)),u!==n){for(a=[],et.test(t.charAt(fe))?(c=t.charAt(fe),fe++):(c=n,0===de&&ye(nt));c!==n;)a.push(c),et.test(t.charAt(fe))?(c=t.charAt(fe),fe++):(c=n,0===de&&ye(nt));a!==n?r=e=[e,s,u,a]:(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n}else fe=r,r=n;return r}()))))))}}return r}function Ze(){var r,e,s;return r=fe,42===t.charCodeAt(fe)?(e="*",fe++):(e=n,0===de&&ye(L)),e===n&&(e=De()),e!==n&&(le=r,s=e,En.columns=Array.isArray(En.columns)?En.columns:[],En.columns.find(Bn(s))||En.columns.push(s),e=s),r=e}function je(){var r,e,s,u,a,c,o,i,f,l,h;if(r=fe,e=fe,42===t.charCodeAt(fe)?(s="*",fe++):(s=n,0===de&&ye(L)),s===n&&(s=De()),s!==n&&(le=e,s=function(t){const r="*"===t?{}:t;return r.expand="*",Array.isArray(En.expand)||(En.expand=[]),En.expand.find(Bn(r))||En.expand.push(r),r}(s)),(e=s)!==n){if(s=fe,u=fe,(a=gn())!==n&&(le=u,wn.push(En),En=En.expand[En.expand.length-1],a=void(En.expand="*")),(u=a)!==n){for(a=fe,c=[],o=fe,(i=bn())!==n?(59===t.charCodeAt(fe)?(f=";",fe++):(f=n,0===de&&ye(N)),f===n&&(f=null),f!==n&&(l=bn())!==n&&(h=ze())!==n?o=i=[i,f,l,h]:(fe=o,o=n)):(fe=o,o=n);o!==n;)c.push(o),o=fe,(i=bn())!==n?(59===t.charCodeAt(fe)?(f=";",fe++):(f=n,0===de&&ye(N)),f===n&&(f=null),f!==n&&(l=bn())!==n&&(h=ze())!==n?o=i=[i,f,l,h]:(fe=o,o=n)):(fe=o,o=n);c!==n&&(le=a,c=function(t){if(En.columns){"*"===En.expand&&(En.expand=[]);for(const t of En.columns)En.expand.find(Bn(t))||En.expand.push(t);delete En.columns}else Array.isArray(En.expand)&&-1===En.expand.indexOf("*")&&En.expand.unshift("*")}()),(a=c)!==n?(c=fe,(o=vn())!==n&&(le=c,o=void(En=wn.pop())),(c=o)!==n?s=u=[u,a,c]:(fe=s,s=n)):(fe=s,s=n)}else fe=s,s=n;s===n&&(s=null),s!==n?(u=fe,(a=dn())!==n&&(c=je())!==n?u=a=[a,c]:(fe=u,u=n),u===n&&(u=null),u!==n?r=e=[e,s,u]:(fe=r,r=n)):(fe=r,r=n)}else fe=r,r=n;return r}function Oe(){var t,r,e;return t=fe,(r=Be())!==n&&(le=t,e=r,r=void(En.search=e)),t=r}function Be(){var r,e,s,u,a,c,o;if(r=fe,e=fe,(s=Ge())===n&&(s=null),s!==n&&(le=e,s=k(s)),(e=s)!==n)if(s=fe,(u=gn())!==n&&(a=Be())!==n&&(c=vn())!==n?(le=s,s=u=q(e,a)):(fe=s,s=n),s===n&&(s=fe,u=function(){var r,e,s,u,a;r=fe,34===t.charCodeAt(fe)?(e=Rr,fe++):(e=n,0===de&&ye(Fr));if(e!==n){for(s=fe,u=[],t.substr(fe,2)===Tr?(a=Tr,fe+=2):(a=n,0===de&&ye(Lr)),a===n&&(Nr.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(kr)));a!==n;)u.push(a),t.substr(fe,2)===Tr?(a=Tr,fe+=2):(a=n,0===de&&ye(Lr)),a===n&&(Nr.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(kr)));(s=u!==n?t.substring(s,fe):u)!==n?(34===t.charCodeAt(fe)?(u=Rr,fe++):(u=n,0===de&&ye(Fr)),u!==n?(le=r,r=e=s.replace(/\\\\/g,"\\").replace(/\\"/g,'"')):(fe=r,r=n)):(fe=r,r=n)}else fe=r,r=n;return r}(),u!==n&&(le=s,u=I(e,u)),(s=u)===n&&(s=fe,(u=on())!==n&&(le=s,u=I(e,u)),(s=u)===n&&(s=fe,(u=fn())!==n&&(le=s,u=I(e,u)),s=u))),s!==n){for(u=[],a=fe,(c=He())===n&&(c=Qe())===n&&(c=Ke()),c!==n&&(o=Be())!==n?(le=a,a=c=_(e,c,o)):(fe=a,a=n);a!==n;)u.push(a),a=fe,(c=He())===n&&(c=Qe())===n&&(c=Ke()),c!==n&&(o=Be())!==n?(le=a,a=c=_(e,c,o)):(fe=a,a=n);u!==n?(le=r,r=e=e):(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n;return r}function Re(){var t,r,e;return t=fe,(r=Fe())!==n&&(le=t,e=r,r=void(En.where=e)),t=r}function Fe(){var r,e,s,u,a,c,o,i;if(r=fe,e=fe,(s=Ge())===n&&(s=null),s!==n&&(le=e,s=k(s)),(e=s)!==n)if(s=fe,(u=gn())!==n&&(a=Fe())!==n&&(c=vn())!==n?(le=s,s=u=q(e,a)):(fe=s,s=n),s===n&&(s=fe,(u=Ie())!==n&&(le=s,i=u,u=void e.push(...i)),(s=u)===n&&(s=fe,(u=Te())!==n&&(le=s,u=function(t,r){t.push(...r)}(e,u)),(s=u)===n&&(s=fe,u=function(){var r,e,s,u;de++,r=fe,t.substr(fe,8)===Ot?(e=Ot,fe+=8):(e=n,0===de&&ye(Bt));e===n&&(t.substr(fe,8)===Rt?(e=Rt,fe+=8):(e=n,0===de&&ye(Ft)),e===n&&(t.substr(fe,10)===Tt?(e=Tt,fe+=10):(e=n,0===de&&ye(Lt))));e!==n&&gn()!==n&&(s=_e())!==n&&dn()!==n&&(u=_e())!==n&&vn()!==n?(le=r,r=e={func:e,args:[s,u]}):(fe=r,r=n);de--,r===n&&(e=n,0===de&&ye(jt));return r}(),u!==n&&(le=s,u=function(t,r){t.push(r)}(e,u)),(s=u)===n&&(s=fe,(u=cn())!==n&&(le=s,u=I(e,u)),s=u)))),s!==n){for(u=[],a=fe,(c=He())===n&&(c=Qe()),c!==n&&(o=Fe())!==n?(le=a,a=c=_(e,c,o)):(fe=a,a=n);a!==n;)u.push(a),a=fe,(c=He())===n&&(c=Qe()),c!==n&&(o=Fe())!==n?(le=a,a=c=_(e,c,o)):(fe=a,a=n);u!==n?(le=r,r=e=e):(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n;return r}function Te(){var r,e,s,u,o,i,f;if(r=fe,e=fe,(s=pn())!==n&&(le=e,s=[s]),(e=s)!==n)if(47===t.charCodeAt(fe)?(s=a,fe++):(s=n,0===de&&ye(c)),s!==n){for(u=[],o=fe,(i=pn())!==n?(47===t.charCodeAt(fe)?(f=a,fe++):(f=n,0===de&&ye(c)),f!==n?(le=o,o=i=D(e,i)):(fe=o,o=n)):(fe=o,o=n);o!==n;)u.push(o),o=fe,(i=pn())!==n?(47===t.charCodeAt(fe)?(f=a,fe++):(f=n,0===de&&ye(c)),f!==n?(le=o,o=i=D(e,i)):(fe=o,o=n)):(fe=o,o=n);u!==n?(o=fe,i=function(){var r,e,s;r=fe,t.substr(fe,3)===J?(e=J,fe+=3):(e=n,0===de&&ye(G));e!==n&&gn()!==n?((s=Ne())===n&&(s=null),s!==n&&vn()!==n?(le=r,r=e=s):(fe=r,r=n)):(fe=r,r=n);return r}(),i!==n&&(le=o,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 u=r[t];u.ref&&0===u.ref.length&&"="===r[t+1]?n[s++]={func:"contains",args:[{ref:e},r[t+=2]]}:n[s++]=u}return n.length<r.length?(e=t.pop(),["exists",{ref:[...t,{id:e,where:n}]}]):["exists",{ref:[...t,{id:e,where:r}]}]}(e,i)),(o=i)===n&&(o=fe,i=function(){var r,e,s;r=fe,t.substr(fe,3)===H?(e=H,fe+=3):(e=n,0===de&&ye(K));e!==n&&gn()!==n&&(s=Ne())!==n&&vn()!==n?(le=r,r=e=s):(fe=r,r=n);return r}(),i!==n&&(le=o,i=function(t,r){let e=t.pop();return["not","exists",{ref:[...t,{id:e,where:["not",{xpr:[...r]}]}]}]}(e,i)),o=i),o!==n?(le=r,r=e=o):(fe=r,r=n)):(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n;return r}function Le(){var t,r,e,s,u,a,c,o,i;if(t=fe,r=fe,(e=Ge())===n&&(e=null),e!==n&&(le=r,e=(o=e)?[o]:[]),(r=e)!==n)if(e=fe,(s=gn())!==n&&(u=Le())!==n&&(a=vn())!==n?(le=e,i=u,e=s=void r.push("(",...i,")")):(fe=e,e=n),e===n&&(e=fe,(s=Ie())!==n&&(le=e,s=function(t,r){t.push(...r)}(r,s)),(e=s)===n&&(e=fe,(s=Te())!==n&&(le=e,s=function(t,r){t.push(...r)}(r,s)),e=s)),e!==n){for(s=[],u=fe,(a=He())===n&&(a=Qe()),a!==n&&(c=Le())!==n?(le=u,u=a=U(r,a,c)):(fe=u,u=n);u!==n;)s.push(u),u=fe,(a=He())===n&&(a=Qe()),a!==n&&(c=Le())!==n?(le=u,u=a=U(r,a,c)):(fe=u,u=n);s!==n?(le=t,t=r=r):(fe=t,t=n)}else fe=t,t=n;else fe=t,t=n;return t}function Ne(){var r,e,s,u;return r=fe,(e=pn())!==n?(58===t.charCodeAt(fe)?(s=M,fe++):(s=n,0===de&&ye(P)),s!==n&&(u=Le())!==n?(le=r,r=e=function(t,r){for(const e of r)e.ref&&e.ref[0]===t&&e.ref.shift();return r}(e,u)):(fe=r,r=n)):(fe=r,r=n),r}function ke(){var r,e,s,u,a;return r=fe,(e=Je())===n&&(e=De()),e!==n?(s=fe,mn()!==n?(u=fe,"asc"===t.substr(fe,3)?(a="asc",fe+=3):(a=n,0===de&&ye(Q)),a===n&&(t.substr(fe,4)===V?(a=V,fe+=4):(a=n,0===de&&ye(W))),(u=a!==n?t.substring(u,fe):a)!==n?(le=s,s=u):(fe=s,s=n)):(fe=s,s=n),s===n&&(s=null),s!==n?(le=r,r=e=function(t,r){const e=Cn(t,r&&{sort:r});En.orderBy=En.orderBy?[...En.orderBy,e]:[e]}(e,s)):(fe=r,r=n)):(fe=r,r=n),r}function qe(){var r,e,s,u,o,i;if(r=fe,(e=Ve())!==n){for(s=[],u=fe,47===t.charCodeAt(fe)?(o=a,fe++):(o=n,0===de&&ye(c)),o!==n&&(i=Ve())!==n?u=o=[o,i]:(fe=u,u=n);u!==n;)s.push(u),u=fe,47===t.charCodeAt(fe)?(o=a,fe++):(o=n,0===de&&ye(c)),o!==n&&(i=Ve())!==n?u=o=[o,i]:(fe=u,u=n);s!==n?r=e=[e,s]:(fe=r,r=n)}else fe=r,r=n;return r}function Ie(){var r,e,s,u,a,c;return de++,r=fe,(e=_e())!==n&&mn()!==n?(s=fe,"eq"===t.substr(fe,2)?(u="eq",fe+=2):(u=n,0===de&&ye(ut)),u===n&&("ne"===t.substr(fe,2)?(u="ne",fe+=2):(u=n,0===de&&ye(at)),u===n&&("lt"===t.substr(fe,2)?(u="lt",fe+=2):(u=n,0===de&&ye(ct)),u===n&&("gt"===t.substr(fe,2)?(u="gt",fe+=2):(u=n,0===de&&ye(ot)),u===n&&("le"===t.substr(fe,2)?(u="le",fe+=2):(u=n,0===de&&ye(it)),u===n&&("ge"===t.substr(fe,2)?(u="ge",fe+=2):(u=n,0===de&&ye(ft))))))),(s=u!==n?t.substring(s,fe):u)!==n&&(u=mn())!==n&&(a=_e())!==n?(le=r,r=e=[e,{eq:"=",ne:"!=",lt:"<",gt:">",le:"<=",ge:">="}[c=s]||c,a]):(fe=r,r=n)):(fe=r,r=n),de--,r===n&&(e=n,0===de&&ye(st)),r}function _e(){var r;return de++,(r=Je())===n&&(r=De())===n&&(r=Ue())===n&&(r=Me())===n&&(r=Pe())===n&&(r=function(){var r,e,s,u,a;r=fe,91===t.charCodeAt(fe)?(e=mt,fe++):(e=n,0===de&&ye(xt));if(e!==n){for(s=fe,u=[],$t.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(wt));a!==n;)u.push(a),$t.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(wt));(s=u!==n?t.substring(s,fe):u)!==n?(93===t.charCodeAt(fe)?(u=Ct,fe++):(u=n,0===de&&ye(yt)),u!==n?(le=r,r=e={list:s.replace(/"/g,"").split(",").map((t=>({val:t})))}):(fe=r,r=n)):(fe=r,r=n)}else fe=r,r=n;return r}()),de--,r===n&&(n,0===de&&ye(lt)),r}function De(){var r,e,s,u,o,i,f,l;if(de++,r=fe,(e=pn())!==n){for(s=[],u=fe,47===t.charCodeAt(fe)?(o=a,fe++):(o=n,0===de&&ye(c)),o!==n&&(i=pn())!==n?(le=u,u=o=pt(0,i)):(fe=u,u=n);u!==n;)s.push(u),u=fe,47===t.charCodeAt(fe)?(o=a,fe++):(o=n,0===de&&ye(c)),o!==n&&(i=pn())!==n?(le=u,u=o=pt(0,i)):(fe=u,u=n);s!==n?(le=r,l=s,r=e="null"===(f=e)?{val:null}:{ref:[f,...l]}):(fe=r,r=n)}else fe=r,r=n;return de--,r===n&&(e=n,0===de&&ye(ht)),r}function Ue(){var r,e,s;return r=fe,(e=cn())===n&&(e=function(){var r,e,s,u,a,c,o,i,f,l,h,p,A,d,g,v,b,m,x,C,y,$,w,E;r=fe,e=fe,s=[],_r.test(t.charAt(fe))?(u=t.charAt(fe),fe++):(u=n,0===de&&ye(Dr));if(u!==n)for(;u!==n;)s.push(u),_r.test(t.charAt(fe))?(u=t.charAt(fe),fe++):(u=n,0===de&&ye(Dr));else s=n;if(s!==n)if(45===t.charCodeAt(fe)?(u=Ur,fe++):(u=n,0===de&&ye(Mr)),u!==n)if(_r.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(Dr)),a!==n)if(_r.test(t.charAt(fe))?(c=t.charAt(fe),fe++):(c=n,0===de&&ye(Dr)),c!==n)if(45===t.charCodeAt(fe)?(o=Ur,fe++):(o=n,0===de&&ye(Mr)),o!==n)if(_r.test(t.charAt(fe))?(i=t.charAt(fe),fe++):(i=n,0===de&&ye(Dr)),i!==n)if(_r.test(t.charAt(fe))?(f=t.charAt(fe),fe++):(f=n,0===de&&ye(Dr)),f!==n){if(l=fe,84===t.charCodeAt(fe)?(h="T",fe++):(h=n,0===de&&ye(Pr)),h!==n)if(_r.test(t.charAt(fe))?(p=t.charAt(fe),fe++):(p=n,0===de&&ye(Dr)),p!==n)if(_r.test(t.charAt(fe))?(A=t.charAt(fe),fe++):(A=n,0===de&&ye(Dr)),A!==n)if(58===t.charCodeAt(fe)?(d=M,fe++):(d=n,0===de&&ye(P)),d!==n)if(_r.test(t.charAt(fe))?(g=t.charAt(fe),fe++):(g=n,0===de&&ye(Dr)),g!==n)if(_r.test(t.charAt(fe))?(v=t.charAt(fe),fe++):(v=n,0===de&&ye(Dr)),v!==n){if(b=fe,58===t.charCodeAt(fe)?(m=M,fe++):(m=n,0===de&&ye(P)),m!==n)if(_r.test(t.charAt(fe))?(x=t.charAt(fe),fe++):(x=n,0===de&&ye(Dr)),x!==n)if(_r.test(t.charAt(fe))?(C=t.charAt(fe),fe++):(C=n,0===de&&ye(Dr)),C!==n){if(y=fe,46===t.charCodeAt(fe)?($=".",fe++):($=n,0===de&&ye(Jr)),$!==n){if(w=[],_r.test(t.charAt(fe))?(E=t.charAt(fe),fe++):(E=n,0===de&&ye(Dr)),E!==n)for(;E!==n;)w.push(E),_r.test(t.charAt(fe))?(E=t.charAt(fe),fe++):(E=n,0===de&&ye(Dr));else w=n;w!==n?y=$=[$,w]:(fe=y,y=n)}else fe=y,y=n;y===n&&(y=null),y!==n?b=m=[m,x,C,y]:(fe=b,b=n)}else fe=b,b=n;else fe=b,b=n;else fe=b,b=n;b===n&&(b=null),b!==n?(90===t.charCodeAt(fe)?(m="Z",fe++):(m=n,0===de&&ye(Gr)),m===n&&(m=fe,43===t.charCodeAt(fe)?(x="+",fe++):(x=n,0===de&&ye(Hr)),x===n&&(45===t.charCodeAt(fe)?(x=Ur,fe++):(x=n,0===de&&ye(Mr))),x!==n?(_r.test(t.charAt(fe))?(C=t.charAt(fe),fe++):(C=n,0===de&&ye(Dr)),C!==n?(_r.test(t.charAt(fe))?(y=t.charAt(fe),fe++):(y=n,0===de&&ye(Dr)),y!==n?(58===t.charCodeAt(fe)?($=M,fe++):($=n,0===de&&ye(P)),$!==n?(_r.test(t.charAt(fe))?(w=t.charAt(fe),fe++):(w=n,0===de&&ye(Dr)),w!==n?(_r.test(t.charAt(fe))?(E=t.charAt(fe),fe++):(E=n,0===de&&ye(Dr)),E!==n?m=x=[x,C,y,$,w,E]:(fe=m,m=n)):(fe=m,m=n)):(fe=m,m=n)):(fe=m,m=n)):(fe=m,m=n)):(fe=m,m=n)),m===n&&(m=null),m!==n?l=h=[h,p,A,d,g,v,b,m]:(fe=l,l=n)):(fe=l,l=n)}else fe=l,l=n;else fe=l,l=n;else fe=l,l=n;else fe=l,l=n;else fe=l,l=n;else fe=l,l=n;l===n&&(l=null),l!==n?e=s=[s,u,a,c,o,i,f,l]:(fe=e,e=n)}else fe=e,e=n;else fe=e,e=n;else fe=e,e=n;else fe=e,e=n;else fe=e,e=n;else fe=e,e=n;else fe=e,e=n;r=e!==n?t.substring(r,fe):e;return r}()),e!==n&&(le=r,e=At(e)),(r=e)===n&&(r=An())===n&&(r=fe,(e=ln())!==n&&(le=r,e="number"==typeof(s=e)?{val:s}:{val:s,literal:"number"}),(r=e)===n&&(r=fe,(e=on())!==n&&(le=r,e=At(e)),r=e)),r}function Me(){var r,e,s,u,a,c;if(r=fe,e=fe,s=fe,123===t.charCodeAt(fe)?(u="{",fe++):(u=n,0===de&&ye(dt)),u!==n){for(a=[],(c=Me())===n&&(gt.test(t.charAt(fe))?(c=t.charAt(fe),fe++):(c=n,0===de&&ye(vt)));c!==n;)a.push(c),(c=Me())===n&&(gt.test(t.charAt(fe))?(c=t.charAt(fe),fe++):(c=n,0===de&&ye(vt)));a!==n?(125===t.charCodeAt(fe)?(c="}",fe++):(c=n,0===de&&ye(bt)),c!==n?s=u=[u,a,c]:(fe=s,s=n)):(fe=s,s=n)}else fe=s,s=n;return(e=s!==n?t.substring(e,fe):s)!==n&&(le=r,e=At(e)),r=e}function Pe(){var r,e,s,u,a,c,o,i;if(r=fe,e=fe,s=fe,91===t.charCodeAt(fe)?(u=mt,fe++):(u=n,0===de&&ye(xt)),u!==n&&(a=bn())!==n?(93===t.charCodeAt(fe)?(c=Ct,fe++):(c=n,0===de&&ye(yt)),c!==n?s=u=[u,a,c]:(fe=s,s=n)):(fe=s,s=n),s===n)if(s=fe,91===t.charCodeAt(fe)?(u=mt,fe++):(u=n,0===de&&ye(xt)),u!==n)if((a=bn())!==n)if(123===t.charCodeAt(fe)?(c="{",fe++):(c=n,0===de&&ye(dt)),c!==n){for(o=[],(i=Pe())===n&&($t.test(t.charAt(fe))?(i=t.charAt(fe),fe++):(i=n,0===de&&ye(wt)));i!==n;)o.push(i),(i=Pe())===n&&($t.test(t.charAt(fe))?(i=t.charAt(fe),fe++):(i=n,0===de&&ye(wt)));o!==n?(93===t.charCodeAt(fe)?(i=Ct,fe++):(i=n,0===de&&ye(yt)),i!==n?s=u=[u,a,c,o,i]:(fe=s,s=n)):(fe=s,s=n)}else fe=s,s=n;else fe=s,s=n;else fe=s,s=n;return(e=s!==n?t.substring(e,fe):s)!==n&&(le=r,e=At(e)),r=e}function Je(){var r,e,s,u,a,c,o,i,f,l;if(de++,r=fe,e=fe,s=[],St.test(t.charAt(fe))?(u=t.charAt(fe),fe++):(u=n,0===de&&ye(zt)),u!==n)for(;u!==n;)s.push(u),St.test(t.charAt(fe))?(u=t.charAt(fe),fe++):(u=n,0===de&&ye(zt));else s=n;if((e=s!==n?t.substring(e,fe):s)!==n)if((s=gn())!==n)if((u=_e())!==n){for(a=[],c=fe,dn()!==n&&(o=_e())!==n?(le=c,c=Zt(0,0,o)):(fe=c,c=n);c!==n;)a.push(c),c=fe,dn()!==n&&(o=_e())!==n?(le=c,c=Zt(0,0,o)):(fe=c,c=n);a!==n&&(c=vn())!==n?(le=r,i=e,f=u,l=a,yn&&!(i in yn.functions)&&xn("'"+i+"' is an unknown function in OData URL spec (strict mode)"),r=e={func:i,args:[f,...l]}):(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n;else fe=r,r=n;return de--,r===n&&(e=n,0===de&&ye(Et)),r}function Ge(){var r,e;return r=fe,bn()!==n?("not"===t.substr(fe,3).toLowerCase()?(e=t.substr(fe,3),fe+=3):(e=n,0===de&&ye(Nt)),e!==n&&mn()!==n?(le=r,r="not"):(fe=r,r=n)):(fe=r,r=n),r}function He(){var r,e;return r=fe,mn()!==n?("and"===t.substr(fe,3).toLowerCase()?(e=t.substr(fe,3),fe+=3):(e=n,0===de&&ye(kt)),e!==n&&mn()!==n?(le=r,r="and"):(fe=r,r=n)):(fe=r,r=n),r}function Ke(){var t,r;return t=fe,(r=mn())!==n&&(le=t,r="and"),t=r}function Qe(){var r,e;return r=fe,mn()!==n?("or"===t.substr(fe,2).toLowerCase()?(e=t.substr(fe,2),fe+=2):(e=n,0===de&&ye(qt)),e!==n&&mn()!==n?(le=r,r="or"):(fe=r,r=n)):(fe=r,r=n),r}function Ve(){var r,e,s;return r=fe,t.substr(fe,9)===It?(e=It,fe+=9):(e=n,0===de&&ye(_t)),e!==n?(s=function(){var t,r,e,s,u,a,c,o,i,f;if(t=fe,(r=gn())!==n)if((e=bn())!==n)if((s=We())!==n){for(u=[],a=fe,(c=bn())!==n&&(o=dn())!==n&&(i=bn())!==n&&(f=We())!==n?a=c=[c,o,i,f]:(fe=a,a=n);a!==n;)u.push(a),a=fe,(c=bn())!==n&&(o=dn())!==n&&(i=bn())!==n&&(f=We())!==n?a=c=[c,o,i,f]:(fe=a,a=n);u!==n&&(a=bn())!==n&&(c=vn())!==n?t=r=[r,e,s,u,a,c]:(fe=t,t=n)}else fe=t,t=n;else fe=t,t=n;else fe=t,t=n;return t}(),s!==n?r=e=[e,s]:(fe=r,r=n)):(fe=r,r=n),r===n&&(r=fe,t.substr(fe,7)===Dt?(e=Dt,fe+=7):(e=n,0===de&&ye(Ut)),e!==n?(s=function(){var t,r,e,s,u,a,c,o,i,f,l;if(t=fe,(r=gn())!==n)if((e=bn())!==n){if(s=fe,(u=gn())!==n)if((a=en())!==n){for(c=[],o=fe,(i=dn())!==n&&(f=bn())!==n&&(l=en())!==n?o=i=[i,f,l]:(fe=o,o=n);o!==n;)c.push(o),o=fe,(i=dn())!==n&&(f=bn())!==n&&(l=en())!==n?o=i=[i,f,l]:(fe=o,o=n);c!==n&&(o=vn())!==n?s=u=[u,a,c,o]:(fe=s,s=n)}else fe=s,s=n;else fe=s,s=n;s!==n?(u=fe,(a=dn())!==n&&(c=bn())!==n&&(o=qe())!==n?u=a=[a,c,o]:(fe=u,u=n),u===n&&(u=null),u!==n&&(a=bn())!==n&&(c=vn())!==n?t=r=[r,e,s,u,a,c]:(fe=t,t=n)):(fe=t,t=n)}else fe=t,t=n;else fe=t,t=n;return t}(),s!==n?r=e=[e,s]:(fe=r,r=n)):(fe=r,r=n),r===n&&(r=fe,t.substr(fe,6)===Mt?(e=Mt,fe+=6):(e=n,0===de&&ye(Pt)),e!==n&&(s=nn())!==n?r=e=[e,s]:(fe=r,r=n),r===n&&(r=function(){var r,e,s,u;r=fe,t.substr(fe,8)===gr?(e=gr,fe+=8):(e=n,0===de&&ye(vr));e===n&&(t.substr(fe,11)===br?(e=br,fe+=11):(e=n,0===de&&ye(mr)));e!==n&&gn()!==n&&bn()!==n&&(s=ln())!==n&&bn()!==n&&dn()!==n&&bn()!==n&&(u=De())!==n&&bn()!==n&&vn()!==n?(le=r,r=e=function(t,r,e){const n={...e,sort:"topcount"===t?"desc":"asc"};En.orderBy=En.orderBy?[...En.orderBy,n]:[n],(En.limit||(En.limit={})).rows={val:r}}(e,s,u)):(fe=r,r=n);return r}(),r===n&&(r=fe,t.substr(fe,6)===Jt?(e=Jt,fe+=6):(e=n,0===de&&ye(Gt)),e!==n&&(s=sn())!==n?r=e=[e,s]:(fe=r,r=n),r===n&&(r=fe,t.substr(fe,6)===Ht?(e=Ht,fe+=6):(e=n,0===de&&ye(Kt)),e!==n?(s=function(){var t,r,e,s,u,a;t=fe,(r=gn())!==n&&(e=bn())!==n&&(s=Oe())!==n&&(u=bn())!==n&&(a=vn())!==n?t=r=[r,e,s,u,a]:(fe=t,t=n);return t}(),s!==n?r=e=[e,s]:(fe=r,r=n)):(fe=r,r=n),r===n&&(r=fe,t.substr(fe,6)===Qt?(e=Qt,fe+=6):(e=n,0===de&&ye(Vt)),e!==n?(s=function(){var t,r,e,s,u,a,c,o,i,f;if(t=fe,(r=gn())!==n)if((e=bn())!==n)if((s=qe())!==n){if(u=[],a=fe,(c=bn())!==n&&(o=dn())!==n&&(i=bn())!==n&&(f=qe())!==n?a=c=[c,o,i,f]:(fe=a,a=n),a!==n)for(;a!==n;)u.push(a),a=fe,(c=bn())!==n&&(o=dn())!==n&&(i=bn())!==n&&(f=qe())!==n?a=c=[c,o,i,f]:(fe=a,a=n);else u=n;u!==n&&(a=bn())!==n&&(c=vn())!==n?t=r=[r,e,s,u,a,c]:(fe=t,t=n)}else fe=t,t=n;else fe=t,t=n;else fe=t,t=n;return t}(),s!==n?r=e=[e,s]:(fe=r,r=n)):(fe=r,r=n),r===n&&(r=fe,t.substr(fe,7)===Wt?(e=Wt,fe+=7):(e=n,0===de&&ye(Xt)),e!==n?(s=function(){var t,r,e,s,u,a,c,o,i,f;if(t=fe,(r=gn())!==n)if((e=bn())!==n)if((s=un())!==n){for(u=[],a=fe,(c=bn())!==n&&(o=dn())!==n&&(i=bn())!==n&&(f=un())!==n?a=c=[c,o,i,f]:(fe=a,a=n);a!==n;)u.push(a),a=fe,(c=bn())!==n&&(o=dn())!==n&&(i=bn())!==n&&(f=un())!==n?a=c=[c,o,i,f]:(fe=a,a=n);u!==n&&(a=bn())!==n&&(c=vn())!==n?t=r=[r,e,s,u,a,c]:(fe=t,t=n)}else fe=t,t=n;else fe=t,t=n;else fe=t,t=n;return t}(),s!==n?r=e=[e,s]:(fe=r,r=n)):(fe=r,r=n),r===n&&(r=fe,t.substr(fe,13)===Yt?(e=Yt,fe+=13):(e=n,0===de&&ye(tr)),e!==n&&(s=an())!==n?r=e=[e,s]:(fe=r,r=n),r===n&&(r=fe,t.substr(fe,9)===rr?(e=rr,fe+=9):(e=n,0===de&&ye(er)),e!==n&&(s=an())!==n?r=e=[e,s]:(fe=r,r=n),r===n&&(r=fe,t.substr(fe,10)===nr?(e=nr,fe+=10):(e=n,0===de&&ye(sr)),e!==n&&(s=an())!==n?r=e=[e,s]:(fe=r,r=n),r===n&&(r=fe,t.substr(fe,6)===ur?(e=ur,fe+=6):(e=n,0===de&&ye(ar)),e!==n&&(s=an())!==n?r=e=[e,s]:(fe=r,r=n),r===n&&(r=function(){var r;t.substr(fe,8)===xr?(r=xr,fe+=8):(r=n,0===de&&ye(Cr));return r}())))))))))))),r}function We(){var r,e,s,u,a;return r=fe,e=fe,t.substr(fe,6)===f?(s=f,fe+=6):(s=n,0===de&&ye(l)),s!==n&&(u=rn())!==n?(le=e,e=s={func:"count",args:["*"],as:u}):(fe=e,e=n),e===n&&(e=Xe()),e!==n&&(le=r,a=e,En.columns=Array.isArray(En.columns)?En.columns:[],En.columns.find(Bn(a))||En.columns.push(a),e=a),r=e}function Xe(){var t,r,e,s,u;return t=fe,(r=De())!==n&&(e=Ye())!==n?((s=tn())===n&&(s=null),s!==n&&(u=rn())!==n?(le=t,t=r={func:e,args:[r],as:u}):(fe=t,t=n)):(fe=t,t=n),t===n&&(t=fe,(r=pn())!==n&&(e=gn())!==n&&(s=Xe())!==n&&(u=vn())!==n?t=r=[r,e,s,u]:(fe=t,t=n)),t}function Ye(){var r,e,s,u,a;if(r=fe,mn()!==n)if(t.substr(fe,4)===cr?(e=cr,fe+=4):(e=n,0===de&&ye(or)),e!==n)if(mn()!==n){if(s=fe,u=[],St.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(zt)),a!==n)for(;a!==n;)u.push(a),St.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(zt));else u=n;(s=u!==n?t.substring(s,fe):u)!==n?(le=r,r=s):(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n;else fe=r,r=n;return r}function tn(){var r,e,s,u,a,c,o;return r=fe,(e=mn())!==n?(t.substr(fe,4)===ir?(s=ir,fe+=4):(s=n,0===de&&ye(fr)),s!==n&&(u=mn())!==n&&(a=De())!==n&&(c=Ye())!==n?((o=tn())===n&&(o=null),o!==n?r=e=[e,s,u,a,c,o]:(fe=r,r=n)):(fe=r,r=n)):(fe=r,r=n),r}function rn(){var r,e,s;return r=fe,mn()!==n?("as"===t.substr(fe,2)?(e="as",fe+=2):(e=n,0===de&&ye(lr)),e!==n&&mn()!==n&&(s=pn())!==n?(le=r,r=s):(fe=r,r=n)):(fe=r,r=n),r}function en(){var r,e,s;return r=fe,e=function(){var r,e,s,u,a,c,o,i,f,l,h;r=fe,e=fe,t.substr(fe,6)===hr?(s=hr,fe+=6):(s=n,0===de&&ye(pr));if(s!==n)if((u=gn())!==n)if((a=bn())!==n)if(t.substr(fe,4)===Ar?(c=Ar,fe+=4):(c=n,0===de&&ye(dr)),c===n&&(c=De()),c!==n){if(o=[],i=fe,(f=bn())!==n&&(l=dn())!==n&&(h=De())!==n?i=f=[f,l,h]:(fe=i,i=n),i!==n)for(;i!==n;)o.push(i),i=fe,(f=bn())!==n&&(l=dn())!==n&&(h=De())!==n?i=f=[f,l,h]:(fe=i,i=n);else o=n;o!==n&&(i=bn())!==n&&(f=vn())!==n?e=s=[s,u,a,c,o,i,f]:(fe=e,e=n)}else fe=e,e=n;else fe=e,e=n;else fe=e,e=n;else fe=e,e=n;e!==n&&(le=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=De()),e!==n&&(le=r,s=e,e=void(En.groupBy||(En.groupBy=[])).push(s)),r=e}function nn(){var t,r,e,s,u,a;return t=fe,(r=gn())!==n&&(e=bn())!==n&&(s=Re())!==n&&(u=bn())!==n&&(a=vn())!==n?t=r=[r,e,s,u,a]:(fe=t,t=n),t}function sn(){var t,r,e,s,u,a,c,o,i,f,l,h,p,A;if(t=fe,(r=gn())!==n)if((e=bn())!==n)if((s=De())!==n)if((u=bn())!==n)if((a=dn())!==n)if((c=bn())!==n){if(o=fe,(i=sn())!==n){for(f=[],l=fe,(h=bn())!==n&&(p=dn())!==n&&(A=sn())!==n?l=h=[h,p,A]:(fe=l,l=n);l!==n;)f.push(l),l=fe,(h=bn())!==n&&(p=dn())!==n&&(A=sn())!==n?l=h=[h,p,A]:(fe=l,l=n);f!==n?o=i=[i,f]:(fe=o,o=n)}else fe=o,o=n;if(o===n)if(o=fe,(i=nn())!==n){for(f=[],l=fe,(h=bn())!==n&&(p=dn())!==n&&(A=sn())!==n?l=h=[h,p,A]:(fe=l,l=n);l!==n;)f.push(l),l=fe,(h=bn())!==n&&(p=dn())!==n&&(A=sn())!==n?l=h=[h,p,A]:(fe=l,l=n);f!==n?o=i=[i,f]:(fe=o,o=n)}else fe=o,o=n;o!==n&&(i=bn())!==n&&(f=vn())!==n?t=r=[r,e,s,u,a,c,o,i,f]:(fe=t,t=n)}else fe=t,t=n;else fe=t,t=n;else fe=t,t=n;else fe=t,t=n;else fe=t,t=n;else fe=t,t=n;return t}function un(){var t,r,e;return t=fe,(r=Fe())!==n&&(e=rn())!==n?t=r=[r,e]:(fe=t,t=n),t}function an(){var t,r,e,s,u,a,c,o,i,f;return t=fe,(r=gn())!==n&&(e=bn())!==n&&(s=_e())!==n&&(u=bn())!==n&&(a=dn())!==n&&(c=bn())!==n&&(o=_e())!==n&&(i=bn())!==n&&(f=vn())!==n?t=r=[r,e,s,u,a,c,o,i,f]:(fe=t,t=n),t}function cn(){var r,e;return r=fe,t.substr(fe,4)===yr?(e=yr,fe+=4):(e=n,0===de&&ye($r)),e===n&&(t.substr(fe,5)===wr?(e=wr,fe+=5):(e=n,0===de&&ye(Er))),e!==n&&(le=r,e="true"===e),r=e}function on(){var r,e,s,u,a;if(de++,r=fe,39===t.charCodeAt(fe)?(e="'",fe++):(e=n,0===de&&ye(zr)),e!==n){for(s=fe,u=[],t.substr(fe,2)===Zr?(a=Zr,fe+=2):(a=n,0===de&&ye(jr)),a===n&&(Or.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(Br)));a!==n;)u.push(a),t.substr(fe,2)===Zr?(a=Zr,fe+=2):(a=n,0===de&&ye(jr)),a===n&&(Or.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(Br)));(s=u!==n?t.substring(s,fe):u)!==n?(39===t.charCodeAt(fe)?(u="'",fe++):(u=n,0===de&&ye(zr)),u!==n?(le=r,r=e=s.replace(/''/g,"'")):(fe=r,r=n)):(fe=r,r=n)}else fe=r,r=n;return de--,r===n&&(e=n,0===de&&ye(Sr)),r}function fn(){var r,e,s;if(r=fe,e=[],qr.test(t.charAt(fe))?(s=t.charAt(fe),fe++):(s=n,0===de&&ye(Ir)),s!==n)for(;s!==n;)e.push(s),qr.test(t.charAt(fe))?(s=t.charAt(fe),fe++):(s=n,0===de&&ye(Ir));else e=n;return r=e!==n?t.substring(r,fe):e}function ln(){var r,e,s,u,a,c,o,i,f,l;if(r=fe,e=fe,s=fe,Kr.test(t.charAt(fe))?(u=t.charAt(fe),fe++):(u=n,0===de&&ye(Qr)),u===n&&(u=null),u!==n){if(a=[],_r.test(t.charAt(fe))?(c=t.charAt(fe),fe++):(c=n,0===de&&ye(Dr)),c!==n)for(;c!==n;)a.push(c),_r.test(t.charAt(fe))?(c=t.charAt(fe),fe++):(c=n,0===de&&ye(Dr));else a=n;if(a!==n){if(c=fe,46===t.charCodeAt(fe)?(o=".",fe++):(o=n,0===de&&ye(Jr)),o!==n){if(i=[],_r.test(t.charAt(fe))?(f=t.charAt(fe),fe++):(f=n,0===de&&ye(Dr)),f!==n)for(;f!==n;)i.push(f),_r.test(t.charAt(fe))?(f=t.charAt(fe),fe++):(f=n,0===de&&ye(Dr));else i=n;i!==n?c=o=[o,i]:(fe=c,c=n)}else fe=c,c=n;if(c===n&&(c=null),c!==n){if(o=fe,101===t.charCodeAt(fe)?(i="e",fe++):(i=n,0===de&&ye(Vr)),i!==n){if(f=[],_r.test(t.charAt(fe))?(l=t.charAt(fe),fe++):(l=n,0===de&&ye(Dr)),l!==n)for(;l!==n;)f.push(l),_r.test(t.charAt(fe))?(l=t.charAt(fe),fe++):(l=n,0===de&&ye(Dr));else f=n;f!==n?o=i=[i,f]:(fe=o,o=n)}else fe=o,o=n;o===n&&(o=null),o!==n?s=u=[u,a,c,o]:(fe=s,s=n)}else fe=s,s=n}else fe=s,s=n}else fe=s,s=n;return(e=s!==n?t.substring(e,fe):s)!==n&&(le=r,e=Zn(e)),r=e}function hn(){var r,e,s,u,a,c;if(r=fe,e=fe,s=fe,Kr.test(t.charAt(fe))?(u=t.charAt(fe),fe++):(u=n,0===de&&ye(Qr)),u===n&&(u=null),u!==n){if(a=[],_r.test(t.charAt(fe))?(c=t.charAt(fe),fe++):(c=n,0===de&&ye(Dr)),c!==n)for(;c!==n;)a.push(c),_r.test(t.charAt(fe))?(c=t.charAt(fe),fe++):(c=n,0===de&&ye(Dr));else a=n;a!==n?s=u=[u,a]:(fe=s,s=n)}else fe=s,s=n;return(e=s!==n?t.substring(e,fe):s)!==n&&(le=r,e=parseInt(e)),r=e}function pn(){var r,e,s,u,a,c,o,i;if(r=fe,e=fe,de++,s=cn(),de--,s===n?e=void 0:(fe=e,e=n),e!==n)if(s=fe,de++,u=An(),de--,u===n?s=void 0:(fe=s,s=n),s!==n){if(u=fe,a=fe,Wr.test(t.charAt(fe))?(c=t.charAt(fe),fe++):(c=n,0===de&&ye(Xr)),c!==n){for(o=[],Yr.test(t.charAt(fe))?(i=t.charAt(fe),fe++):(i=n,0===de&&ye(te));i!==n;)o.push(i),Yr.test(t.charAt(fe))?(i=t.charAt(fe),fe++):(i=n,0===de&&ye(te));o!==n?a=c=[c,o]:(fe=a,a=n)}else fe=a,a=n;(u=a!==n?t.substring(u,fe):a)!==n?(le=r,r=e=u):(fe=r,r=n)}else fe=r,r=n;else fe=r,r=n;return r}function An(){var r,e,s,u,a,c,o,i,f;if(r=fe,e=fe,s=fe,u=[],re.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(ee)),a!==n)for(;a!==n;)u.push(a),re.test(t.charAt(fe))?(a=t.charAt(fe),fe++):(a=n,0===de&&ye(ee));else u=n;if(u!==n)if(45===t.charCodeAt(fe)?(a=Ur,fe++):(a=n,0===de&&ye(Mr)),a!==n){if(c=[],o=fe,i=[],re.test(t.charAt(fe))?(f=t.charAt(fe),fe++):(f=n,0===de&&ye(ee)),f!==n)for(;f!==n;)i.push(f),re.test(t.charAt(fe))?(f=t.charAt(fe),fe++):(f=n,0===de&&ye(ee));else i=n;if(i!==n?(45===t.charCodeAt(fe)?(f=Ur,fe++):(f=n,0===de&&ye(Mr)),f===n&&(f=null),f!==n?o=i=[i,f]:(fe=o,o=n)):(fe=o,o=n),o!==n)for(;o!==n;){if(c.push(o),o=fe,i=[],re.test(t.charAt(fe))?(f=t.charAt(fe),fe++):(f=n,0===de&&ye(ee)),f!==n)for(;f!==n;)i.push(f),re.test(t.charAt(fe))?(f=t.charAt(fe),fe++):(f=n,0===de&&ye(ee));else i=n;i!==n?(45===t.charCodeAt(fe)?(f=Ur,fe++):(f=n,0===de&&ye(Mr)),f===n&&(f=null),f!==n?o=i=[i,f]:(fe=o,o=n)):(fe=o,o=n)}else c=n;c!==n?s=u=[u,a,c]:(fe=s,s=n)}else fe=s,s=n;else fe=s,s=n;return(e=s!==n?t.substring(e,fe):s)!==n&&(le=r,e=At(e)),r=e}function dn(){var r,e,s,u;return r=fe,(e=bn())!==n?(44===t.charCodeAt(fe)?(s=",",fe++):(s=n,0===de&&ye(ne)),s!==n&&(u=bn())!==n?r=e=[e,s,u]:(fe=r,r=n)):(fe=r,r=n),r}function gn(){var r,e,s,u;return r=fe,(e=bn())!==n?(40===t.charCodeAt(fe)?(s="(",fe++):(s=n,0===de&&ye(se)),s!==n&&(u=bn())!==n?r=e=[e,s,u]:(fe=r,r=n)):(fe=r,r=n),r}function vn(){var r,e,s;return r=fe,(e=bn())!==n?(41===t.charCodeAt(fe)?(s=")",fe++):(s=n,0===de&&ye(ue)),s!==n?r=e=[e,s]:(fe=r,r=n)):(fe=r,r=n),r}function bn(){var r,e,s;for(de++,r=fe,e=[],ce.test(t.charAt(fe))?(s=t.charAt(fe),fe++):(s=n,0===de&&ye(oe));s!==n;)e.push(s),ce.test(t.charAt(fe))?(s=t.charAt(fe),fe++):(s=n,0===de&&ye(oe));return r=e!==n?t.substring(r,fe):e,de--,r===n&&(e=n,0===de&&ye(ae)),r}function mn(){var r,e,s;if(de++,r=fe,e=[],ce.test(t.charAt(fe))?(s=t.charAt(fe),fe++):(s=n,0===de&&ye(oe)),s!==n)for(;s!==n;)e.push(s),ce.test(t.charAt(fe))?(s=t.charAt(fe),fe++):(s=n,0===de&&ye(oe));else e=n;return r=e!==n?t.substring(r,fe):e,de--,r===n&&(e=n,0===de&&ye(ie)),r}const xn=(t,r=400)=>{ge(JSON.stringify({code:r,message:t}))},Cn=Object.assign,{strict:yn,minimal:$n}=r,wn=[];let En,Sn;const zn=["$value"],Zn=r.safeNumber||function(t){const r=Number(t);return Number.isSafeInteger(r)?r:t},jn=(t,r)=>{const e=[...t];for(const t of e)t.xpr&&(t.xpr=jn(t.xpr,r)),t.args&&(t.args=jn(t.args,r)),t.ref&&r.includes(t.ref.join(""));return e},On=t=>{const r=t.groupBy,e=t.where,n=t.columns||[],s=n.filter((t=>t.as));let u=[],a=[];if(0!==s.length&&(u=n.filter((t=>!t.ref||s.includes(t.ref.join(""))))),r){const t=r.map((({ref:t})=>t&&t.join(""))),e=n.filter((r=>r.ref&&t.includes(r.ref.join(""))));a=0===e.length?[...r]:e}const c=0!==u.length||0!==a.length?[...a,...u]:t.columns;let o={...t};c&&(o.columns=c);if(e&&(r||0!==s.length)){const t=n.map((t=>t.ref&&t.ref.join("")||t.as));o={...o,where:jn(e,t)}}return o},Bn=t=>r=>t===r||t.as&&r.as&&t.as===r.as||t.ref&&r.ref&&t.ref.join("")===r.ref.join("");if((e=u())!==n&&fe===t.length)return e;throw e!==n&&fe<t.length&&ye({type:"end"}),$e(Ae,pe<t.length?t.charAt(pe):null,pe<t.length?Ce(pe,pe+1):Ce(pe,pe))}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?u(t.parts[r][0])+"-"+u(t.parts[r][1]):u(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 u(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,u=new Array(t.length);for(r=0;r<t.length;r++)u[r]=(s=t[r],e[s.type](s));if(u.sort(),u.length>0){for(r=1,n=1;r<u.length;r++)u[r-1]!==u[r]&&(u[n]=u[r],n++);u.length=n}switch(u.length){case 1:return u[0];case 2:return u[0]+" or "+u[1];default:return u.slice(0,-1).join(", ")+", or "+u[u.length-1]}}(t)+" but "+function(t){return t?'"'+s(t)+'"':"end of input"}(r)+" found."},module.exports={SyntaxError:peg$SyntaxError,parse:peg$parse};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const getSafeNumber = str => {
|
|
2
|
+
const n = Number(str)
|
|
3
|
+
return Number.isSafeInteger(n) || String(n) === str ? n : str
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
const V4UUIDREGEXP = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
|
7
|
+
const isV4UUID = val => V4UUIDREGEXP.test(val)
|
|
8
|
+
|
|
9
|
+
const _odataV2Val = (val, type) => {
|
|
10
|
+
switch (type) {
|
|
11
|
+
case 'cds.Binary':
|
|
12
|
+
case 'cds.LargeBinary':
|
|
13
|
+
return `binary'${val}'`
|
|
14
|
+
case 'cds.Date':
|
|
15
|
+
return `datetime'${val}T00:00:00'`
|
|
16
|
+
case 'cds.DateTime':
|
|
17
|
+
return `datetime'${val}'`
|
|
18
|
+
case 'cds.Time':
|
|
19
|
+
// eslint-disable-next-line no-case-declarations
|
|
20
|
+
const [hh, mm, ss] = val.split(':')
|
|
21
|
+
return `time'PT${hh}H${mm}M${ss}S'`
|
|
22
|
+
case 'cds.Timestamp':
|
|
23
|
+
return `datetimeoffset'${val}'`
|
|
24
|
+
case 'cds.UUID':
|
|
25
|
+
return `guid'${val}'`
|
|
26
|
+
default:
|
|
27
|
+
return `'${val}'`
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const _isTimestamp = val =>
|
|
32
|
+
/^\d+-\d\d-\d\d(T\d\d:\d\d(:\d\d(\.\d+)?)?(Z|([+-]{1}\d\d:\d\d))?)?$/.test(val) && !isNaN(Date.parse(val))
|
|
33
|
+
|
|
34
|
+
const _val = (val, type) => {
|
|
35
|
+
switch (type) {
|
|
36
|
+
case 'cds.Decimal':
|
|
37
|
+
case 'cds.Integer64':
|
|
38
|
+
return getSafeNumber(val)
|
|
39
|
+
case 'cds.Boolean':
|
|
40
|
+
case 'cds.DateTime':
|
|
41
|
+
case 'cds.Date':
|
|
42
|
+
case 'cds.Timestamp':
|
|
43
|
+
case 'cds.Time':
|
|
44
|
+
case 'cds.UUID':
|
|
45
|
+
return val
|
|
46
|
+
default:
|
|
47
|
+
return _isTimestamp(val) ? val : `'${val}'`
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const formatVal = (val, element, csnTarget, kind) => {
|
|
52
|
+
if (val === null || val === 'null') return 'null'
|
|
53
|
+
if (typeof val === 'boolean') return val
|
|
54
|
+
if (typeof val === 'number') return getSafeNumber(val)
|
|
55
|
+
if (!csnTarget && typeof val === 'string' && isV4UUID(val)) return kind === 'odata-v2' ? `guid'${val}'` : val
|
|
56
|
+
|
|
57
|
+
const csnElement = (csnTarget && csnTarget.elements && csnTarget.elements[element]) || { type: undefined }
|
|
58
|
+
return kind === 'odata-v2' ? _odataV2Val(val, csnElement.type) : _val(val, csnElement.type)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = {
|
|
62
|
+
getSafeNumber,
|
|
63
|
+
formatVal
|
|
64
|
+
}
|