@sap/cds 5.5.3 → 5.6.1
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 +134 -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/index.js +1 -1
- package/lib/compile/to/sql.js +22 -2
- package/lib/connect/bindings.js +2 -1
- package/lib/connect/index.js +1 -1
- package/lib/core/infer.js +1 -1
- package/lib/core/reflect.js +3 -1
- package/lib/env/index.js +175 -41
- package/lib/env/requires.js +24 -3
- package/lib/i18n/localize.js +33 -5
- package/lib/index.js +7 -6
- package/lib/log/format/kibana.js +6 -2
- package/lib/ql/DELETE.js +1 -1
- package/lib/ql/INSERT.js +1 -1
- package/lib/ql/Query.js +13 -10
- package/lib/ql/SELECT.js +15 -8
- package/lib/ql/UPDATE.js +1 -1
- package/lib/ql/Whereable.js +5 -0
- package/lib/req/context.js +87 -37
- package/lib/req/{impl.js → request.js} +1 -1
- package/lib/req/{res.js → response.js} +0 -0
- package/lib/serve/Service-api.js +1 -1
- package/lib/serve/Service-dispatch.js +12 -2
- package/lib/serve/Service-handlers.js +21 -7
- package/lib/serve/Service-methods.js +1 -1
- package/lib/serve/Transaction.js +7 -6
- package/lib/serve/index.js +1 -1
- package/lib/utils/axios.js +7 -0
- package/lib/utils/data.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 +6 -0
- package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +37 -35
- package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +1 -1
- 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/metadata.js +1 -1
- 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/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 +48 -18
- 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/parse-url.js +9 -2
- 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/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/toggles/alpha.js +1 -1
- 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 +19 -9
- 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 +10 -24
- package/libx/_runtime/db/expand/rawToExpanded.js +2 -1
- 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 +10 -5
- 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 +2 -2
- 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/Service.js +5 -2
- package/libx/_runtime/hana/execute.js +1 -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/enterprise-messaging.js +1 -1
- package/libx/_runtime/messaging/message-queuing.js +18 -0
- package/libx/_runtime/remote/Service.js +14 -2
- 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 +4 -3
- package/libx/_runtime/sqlite/convertAssocToOneManaged.js +1 -3
- package/libx/_runtime/sqlite/execute.js +1 -1
- 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 +42 -29
- package/lib/req/cls.js +0 -39
- 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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
const cds = require('../_runtime/cds')
|
|
2
|
+
|
|
3
|
+
const express = require('express')
|
|
4
|
+
|
|
5
|
+
const auth = require('./middleware/auth')
|
|
6
|
+
const content = require('./middleware/content')
|
|
7
|
+
const parse = require('./middleware/parse')
|
|
8
|
+
|
|
9
|
+
const create = require('./middleware/create')
|
|
10
|
+
const read = require('./middleware/read')
|
|
11
|
+
const update = require('./middleware/update')
|
|
12
|
+
const deleet = require('./middleware/delete')
|
|
13
|
+
const operation = require('./middleware/operation')
|
|
14
|
+
|
|
15
|
+
const error = require('./middleware/error')
|
|
16
|
+
|
|
17
|
+
// REVISIT: _commit_attempted workaround to avoid double rollback leading to release error
|
|
18
|
+
const _commit_attempted = Symbol()
|
|
19
|
+
|
|
20
|
+
class RestAdapter extends express.Router {
|
|
21
|
+
constructor(srv) {
|
|
22
|
+
super()
|
|
23
|
+
|
|
24
|
+
this.use(express.json())
|
|
25
|
+
|
|
26
|
+
// pass srv-reated stuff to middlewares via req
|
|
27
|
+
this.use('/', (req, res, next) => {
|
|
28
|
+
req._srv = srv
|
|
29
|
+
next()
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// check @requires as soon as possible (DoS)
|
|
33
|
+
this.use('/', auth)
|
|
34
|
+
|
|
35
|
+
// content-type check
|
|
36
|
+
this.use('/', content)
|
|
37
|
+
|
|
38
|
+
// parse
|
|
39
|
+
this.use('/', parse)
|
|
40
|
+
|
|
41
|
+
// begin tx
|
|
42
|
+
this.use('/', (req, res, next) => {
|
|
43
|
+
// create tx and set as cds.context
|
|
44
|
+
// REVISIT: _model should not be necessary
|
|
45
|
+
req._tx = cds.context = srv.tx({ user: req.user, req, res, _model: req._srv.model })
|
|
46
|
+
next()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
// POST
|
|
50
|
+
this.post('/*', (req, res, next) => {
|
|
51
|
+
if (req._operation) operation(req, res, next)
|
|
52
|
+
else create(req, res, next)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// GET
|
|
56
|
+
this.get('/*', (req, res, next) => {
|
|
57
|
+
if (req._operation) operation(req, res, next)
|
|
58
|
+
else read(req, res, next)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
// PUT, PATCH, DELETE
|
|
62
|
+
this.put('/*', update)
|
|
63
|
+
this.patch('/*', update)
|
|
64
|
+
this.delete('/*', deleet)
|
|
65
|
+
|
|
66
|
+
// end tx (i.e., commit or rollback)
|
|
67
|
+
this.use('/', async (req, res, next) => {
|
|
68
|
+
const { result, status, location } = req._result
|
|
69
|
+
|
|
70
|
+
// unfortunately, express doesn't catch async errors -> try catch needed
|
|
71
|
+
try {
|
|
72
|
+
req._tx[_commit_attempted] = true
|
|
73
|
+
await req._tx.commit(result)
|
|
74
|
+
} catch (e) {
|
|
75
|
+
return next(e)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// TODO: cf. bufferToBase64() in old rest adapter
|
|
79
|
+
|
|
80
|
+
// only set status if not yet modified
|
|
81
|
+
if (status && res.statusCode === 200) res.status(status)
|
|
82
|
+
if (location) res.set('location', location)
|
|
83
|
+
res.send(result)
|
|
84
|
+
})
|
|
85
|
+
this.use('/', (err, req, res, next) => {
|
|
86
|
+
// request may fail during processing or during commit -> both caught here
|
|
87
|
+
|
|
88
|
+
// ignore rollback error, which should never happen
|
|
89
|
+
if (req._tx && !req._tx[_commit_attempted]) req._tx.rollback(err).catch(() => {})
|
|
90
|
+
|
|
91
|
+
next(err)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
/*
|
|
95
|
+
* error handling
|
|
96
|
+
*/
|
|
97
|
+
this.use(error)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
module.exports = RestAdapter
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const cds = require('../_runtime/cds')
|
|
2
|
+
|
|
3
|
+
class RestRequest extends cds.Request {
|
|
4
|
+
constructor(args) {
|
|
5
|
+
super(args)
|
|
6
|
+
|
|
7
|
+
// REVISIT: should not be necessary
|
|
8
|
+
/*
|
|
9
|
+
* propagate _ (i.e., req._ and, hence, req._.req/res)
|
|
10
|
+
* -> in the old adapters this is also set in OdataRequest/RestRequest
|
|
11
|
+
*/
|
|
12
|
+
Object.setPrototypeOf(this._, cds.context._)
|
|
13
|
+
|
|
14
|
+
/*
|
|
15
|
+
* new req.res api [work in progress -> not official]:
|
|
16
|
+
* - req.res.status(202)
|
|
17
|
+
* - req.res.set('location', '/Books/301')
|
|
18
|
+
* this way is $batch compatible, i.e., the status and headers can be set on "subresponse"
|
|
19
|
+
*/
|
|
20
|
+
this._status = null
|
|
21
|
+
this._headers = {}
|
|
22
|
+
const that = this
|
|
23
|
+
this.res = {
|
|
24
|
+
status: s => (that._status = s),
|
|
25
|
+
set: (k, v) => (that._headers[k] = v)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = RestRequest
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { UNAUTHORIZED, FORBIDDEN } = require('../../_runtime/common/utils/auth')
|
|
2
|
+
|
|
3
|
+
const { getRequiresAsArray } = require('../../_runtime/common/utils/auth')
|
|
4
|
+
|
|
5
|
+
module.exports = (req, res, next) => {
|
|
6
|
+
if (!req._srv._requires) req._srv._requires = getRequiresAsArray(req._srv.definition)
|
|
7
|
+
|
|
8
|
+
const { _requires: requires } = req._srv
|
|
9
|
+
|
|
10
|
+
if (req.path !== '/' && requires.length > 0 && !requires.some(r => req.user.is(r))) {
|
|
11
|
+
// > unauthorized or forbidden?
|
|
12
|
+
if (req.user._is_anonymous) {
|
|
13
|
+
if (req.user._challenges) res.set('WWW-Authenticate', req.user._challenges.join(';'))
|
|
14
|
+
// REVISIT: security log in else case?
|
|
15
|
+
throw UNAUTHORIZED
|
|
16
|
+
}
|
|
17
|
+
// REVISIT: security log?
|
|
18
|
+
throw FORBIDDEN
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
next()
|
|
22
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const PPP = { POST: 1, PUT: 1, PATCH: 1 }
|
|
2
|
+
const UPDATE = { PUT: 1, PATCH: 1 }
|
|
3
|
+
|
|
4
|
+
module.exports = (req, res, next) => {
|
|
5
|
+
if (PPP[req.method]) {
|
|
6
|
+
if (req.headers['content-type'] && req.headers['content-type'] !== 'application/json') {
|
|
7
|
+
throw { statusCode: 415, code: '415', message: 'INVALID_CONTENT_TYPE_ONLY_JSON' }
|
|
8
|
+
}
|
|
9
|
+
if (UPDATE[req.method] && Array.isArray(req.body)) {
|
|
10
|
+
throw { statusCode: 400, code: '400', message: `INVALID_${req.method}` }
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
next()
|
|
15
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const cds = require('../../_runtime/cds')
|
|
2
|
+
const { INSERT } = cds.ql
|
|
3
|
+
|
|
4
|
+
const RestRequest = require('../RestRequest')
|
|
5
|
+
|
|
6
|
+
const _error4 = rejected =>
|
|
7
|
+
rejected.length > 1 ? { message: 'MULTIPLE_ERRORS', details: rejected.map(r => r.reason) } : rejected[0].reason
|
|
8
|
+
|
|
9
|
+
module.exports = async (_req, _res, next) => {
|
|
10
|
+
const { _srv: srv, _query: query, _target, _data } = _req
|
|
11
|
+
|
|
12
|
+
let result, location
|
|
13
|
+
|
|
14
|
+
// unfortunately, express doesn't catch async errors -> try catch needed
|
|
15
|
+
try {
|
|
16
|
+
// add the data
|
|
17
|
+
query.entries(_data)
|
|
18
|
+
if (query.INSERT.entries.length > 1) {
|
|
19
|
+
// > batch insert
|
|
20
|
+
const reqs = query.INSERT.entries.map(
|
|
21
|
+
entry => new RestRequest({ query: INSERT.into(query.INSERT.into).entries(entry), _target })
|
|
22
|
+
)
|
|
23
|
+
const ress = await Promise.allSettled(reqs.map(req => srv.dispatch(req)))
|
|
24
|
+
const rejected = ress.filter(r => r.status === 'rejected')
|
|
25
|
+
if (rejected.length) throw _error4(rejected)
|
|
26
|
+
result = ress.map(r => r.value)
|
|
27
|
+
} else {
|
|
28
|
+
// > single insert
|
|
29
|
+
const req = new RestRequest({ query, _target })
|
|
30
|
+
result = await srv.dispatch(req)
|
|
31
|
+
location = `../${req.entity.replace(srv.name + '.', '')}`
|
|
32
|
+
for (const k in req.target.keys) location += `/${result[k]}`
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
return next(e)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
_req._result = { result, status: 201, location }
|
|
39
|
+
next()
|
|
40
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const RestRequest = require('../RestRequest')
|
|
2
|
+
|
|
3
|
+
module.exports = async (_req, _res, next) => {
|
|
4
|
+
const { _srv: srv, _query: query, _target, _params } = _req
|
|
5
|
+
|
|
6
|
+
// unfortunately, express doesn't catch async errors -> try catch needed
|
|
7
|
+
try {
|
|
8
|
+
const req = new RestRequest({ query, _target })
|
|
9
|
+
|
|
10
|
+
// req.data is filled with keys during read and delete
|
|
11
|
+
if (_params) req.data = _params[_params.length - 1]
|
|
12
|
+
|
|
13
|
+
await srv.dispatch(req)
|
|
14
|
+
} catch (e) {
|
|
15
|
+
return next(e)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
_req._result = { result: null, status: 204 }
|
|
19
|
+
next()
|
|
20
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const cds = require('../../_runtime/cds')
|
|
2
|
+
|
|
3
|
+
// requesting logger without module on purpose!
|
|
4
|
+
const LOG = cds.log()
|
|
5
|
+
|
|
6
|
+
let _i18n
|
|
7
|
+
const i18n = (...args) => {
|
|
8
|
+
if (!_i18n) _i18n = require('../../_runtime/common/i18n')
|
|
9
|
+
return _i18n(...args)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const { normalizeError, isClientError } = require('../../_runtime/common/error/frontend')
|
|
13
|
+
|
|
14
|
+
const _log = err => {
|
|
15
|
+
const level = isClientError(err) ? 'warn' : 'error'
|
|
16
|
+
if ((level === 'warn' && !LOG._warn) || (level === 'error' && !LOG._error)) return
|
|
17
|
+
|
|
18
|
+
// replace messages in toLog with developer texts (i.e., undefined locale)
|
|
19
|
+
const _message = err.message
|
|
20
|
+
const _details = err.details
|
|
21
|
+
err.message = i18n(err.message || err.code, undefined, err.args) || err.message
|
|
22
|
+
if (err.details) {
|
|
23
|
+
const details = []
|
|
24
|
+
for (const d of err.details) {
|
|
25
|
+
details.push(Object.assign({}, d, { message: i18n(d.message || d.code, undefined, d.args) || d.message }))
|
|
26
|
+
}
|
|
27
|
+
err.details = details
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// log it
|
|
31
|
+
LOG[level](err)
|
|
32
|
+
|
|
33
|
+
// restore
|
|
34
|
+
err.message = _message
|
|
35
|
+
if (_details) err.details = _details
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// eslint-disable-next-line no-unused-vars
|
|
39
|
+
module.exports = (err, req, res, next) => {
|
|
40
|
+
const { _srv: srv } = req
|
|
41
|
+
|
|
42
|
+
// invoke srv.on('error', function (err, req) { ... }) here in special situations
|
|
43
|
+
let ctx = cds.context
|
|
44
|
+
if (!ctx) {
|
|
45
|
+
// > error before req was dispatched
|
|
46
|
+
ctx = new cds.Request({ req, res: req.res, user: req.user || new cds.User.Anonymous() })
|
|
47
|
+
for (const each of srv._handlers._error) each.handler.call(srv, err, ctx)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// log the error (4xx -> warn)
|
|
51
|
+
_log(err)
|
|
52
|
+
|
|
53
|
+
const { error, statusCode } = normalizeError(err, req)
|
|
54
|
+
|
|
55
|
+
res.status(statusCode).send({ error })
|
|
56
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const { validateReturnType } = require('../../_runtime/cds-services/adapter/rest/utils/validation-checks')
|
|
2
|
+
|
|
3
|
+
const RestRequest = require('../RestRequest')
|
|
4
|
+
|
|
5
|
+
module.exports = async (_req, _res, next) => {
|
|
6
|
+
const { _srv: srv, _query: query, _operation: operation, _data: data } = _req
|
|
7
|
+
|
|
8
|
+
let result
|
|
9
|
+
|
|
10
|
+
// unfortunately, express doesn't catch async errors -> try catch needed
|
|
11
|
+
try {
|
|
12
|
+
const req = query
|
|
13
|
+
? new RestRequest({ query, event: operation.name, data })
|
|
14
|
+
: new RestRequest({ event: operation.name.replace(`${srv.name}.`, ''), data })
|
|
15
|
+
result = await srv.dispatch(req)
|
|
16
|
+
} catch (e) {
|
|
17
|
+
return next(e)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!operation.returns) {
|
|
21
|
+
_req._result = { status: 204 }
|
|
22
|
+
} else {
|
|
23
|
+
// unfortunately, express doesn't catch async errors -> try catch needed
|
|
24
|
+
try {
|
|
25
|
+
// REVISIT: do not use from old rest adapter
|
|
26
|
+
// REVISIT: new impl should return instead of throwing to avoid try catch
|
|
27
|
+
validateReturnType(operation, result)
|
|
28
|
+
} catch (e) {
|
|
29
|
+
return next(e)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// REVISIT: still needed?
|
|
33
|
+
if (!operation.returns.items && Array.isArray(result)) result = result[0]
|
|
34
|
+
|
|
35
|
+
_req._result = { result }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
next()
|
|
39
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const cds = require('../../_runtime/cds')
|
|
2
|
+
const { INSERT, SELECT, UPDATE, DELETE } = cds.ql
|
|
3
|
+
|
|
4
|
+
const { getDeepCopy } = require('../utils/data')
|
|
5
|
+
|
|
6
|
+
const { where2obj } = require('../../_runtime/common/utils/cqn')
|
|
7
|
+
|
|
8
|
+
module.exports = (req, res, next) => {
|
|
9
|
+
const { _srv: service } = req
|
|
10
|
+
const { model } = service
|
|
11
|
+
|
|
12
|
+
let query = cds.odata.parse(req.url, { service })
|
|
13
|
+
|
|
14
|
+
// parser always produces selects
|
|
15
|
+
const _target = (req._target = query.SELECT && query.SELECT.from)
|
|
16
|
+
if (!_target) return next()
|
|
17
|
+
|
|
18
|
+
// REVISIT: __target is the csn target definition
|
|
19
|
+
const {
|
|
20
|
+
__target: definition,
|
|
21
|
+
SELECT: { one }
|
|
22
|
+
} = query
|
|
23
|
+
delete query.__target
|
|
24
|
+
|
|
25
|
+
// REVISIT: hack for actions and functions
|
|
26
|
+
let operation, args
|
|
27
|
+
const last = _target.ref[_target.ref.length - 1]
|
|
28
|
+
if (last.operation) {
|
|
29
|
+
operation = last.operation
|
|
30
|
+
if (last.args) args = last.args
|
|
31
|
+
_target.ref.pop()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const unbound = _target.ref.length === 0
|
|
35
|
+
|
|
36
|
+
// query based on method
|
|
37
|
+
switch (req.method) {
|
|
38
|
+
case 'GET':
|
|
39
|
+
if (operation) {
|
|
40
|
+
// function
|
|
41
|
+
req._operation = operation = definition.kind === 'function' ? definition : definition.actions[operation]
|
|
42
|
+
if (!unbound) query = one ? SELECT.one(_target) : SELECT.from(_target)
|
|
43
|
+
else query = undefined
|
|
44
|
+
} else {
|
|
45
|
+
// read (nothing to do)
|
|
46
|
+
}
|
|
47
|
+
break
|
|
48
|
+
case 'POST':
|
|
49
|
+
if (operation) {
|
|
50
|
+
// action
|
|
51
|
+
req._operation = operation = definition.kind === 'action' ? definition : definition.actions[operation]
|
|
52
|
+
if (!unbound) query = one ? SELECT.one(_target) : SELECT.from(_target)
|
|
53
|
+
else query = undefined
|
|
54
|
+
} else {
|
|
55
|
+
// create
|
|
56
|
+
if (one) cds.error('POST not allowed on entity', { code: 400 })
|
|
57
|
+
query = INSERT.into(_target)
|
|
58
|
+
}
|
|
59
|
+
break
|
|
60
|
+
case 'PUT':
|
|
61
|
+
case 'PATCH':
|
|
62
|
+
if (!one) throw { statusCode: 400, code: '400', message: `INVALID_${req.method}` }
|
|
63
|
+
query = UPDATE(_target)
|
|
64
|
+
break
|
|
65
|
+
case 'DELETE':
|
|
66
|
+
if (!one) cds.error('DELETE not allowed on collection', { code: 400 })
|
|
67
|
+
query = DELETE.from(_target)
|
|
68
|
+
break
|
|
69
|
+
default:
|
|
70
|
+
// anything to do?
|
|
71
|
+
}
|
|
72
|
+
req._query = query
|
|
73
|
+
|
|
74
|
+
// REVISIT: query._data hack
|
|
75
|
+
// deep copy of body (incl. validations such as correct data type)
|
|
76
|
+
if ((query && (query.INSERT || query.UPDATE)) || (operation && operation.kind === 'action') || args) {
|
|
77
|
+
const [validations, copy] = getDeepCopy(args || req.body, operation || definition, model, req.method !== 'POST')
|
|
78
|
+
if (validations) throw validations
|
|
79
|
+
req._data = copy
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// REVISIT: req.params as documented
|
|
83
|
+
for (let i = 0; i < _target.ref.length; i++) {
|
|
84
|
+
req._params = req._params || []
|
|
85
|
+
if (_target.ref[i].where) req._params.push(where2obj(_target.ref[i].where))
|
|
86
|
+
else req._params.push({})
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
next()
|
|
90
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const RestRequest = require('../RestRequest')
|
|
2
|
+
|
|
3
|
+
module.exports = async (_req, _res, next) => {
|
|
4
|
+
const { _srv: srv, _query: query, _target, _params } = _req
|
|
5
|
+
|
|
6
|
+
let result,
|
|
7
|
+
status = 200
|
|
8
|
+
|
|
9
|
+
// unfortunately, express doesn't catch async errors -> try catch needed
|
|
10
|
+
try {
|
|
11
|
+
const req = new RestRequest({ query, _target })
|
|
12
|
+
|
|
13
|
+
// req.data is filled with keys during read and delete
|
|
14
|
+
if (_params) req.data = _params[_params.length - 1]
|
|
15
|
+
|
|
16
|
+
result = await srv.dispatch(req)
|
|
17
|
+
|
|
18
|
+
// 204 or 404?
|
|
19
|
+
if (result === null && query.SELECT.one) {
|
|
20
|
+
if (_target.ref.length > 1) status = 204
|
|
21
|
+
else throw { code: 404 }
|
|
22
|
+
}
|
|
23
|
+
} catch (e) {
|
|
24
|
+
return next(e)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_req._result = { result, status }
|
|
28
|
+
next()
|
|
29
|
+
}
|