diff --git a/src/handler/query-plan-documents.ts b/src/handler/query-plan-documents.ts new file mode 100644 index 0000000..67ecde0 --- /dev/null +++ b/src/handler/query-plan-documents.ts @@ -0,0 +1,43 @@ +import * as http from "http"; +import Account from "../account"; + +export default async ( + account: Account, + req: http.IncomingMessage, + res: http.ServerResponse, + { + dbId, + collId + }: { + dbId: string; + collId: string; + } +) => { + console.log("returning random query plan") + + return { + "partitionedQueryExecutionInfoVersion": "2", + "queryInfo": { + "distinctType": "None", + "top": null, + "offset": null, + "limit": null, + "orderBy": [], + "orderByExpressions": [], + "groupByExpressions": [], + "groupByAliases": [], + "aggregates": [], + "groupByAliasToAggregateType": {}, + "rewrittenQuery": "", + "hasSelectValue": false, + "dCountInfo": null + }, + "queryRanges": [ + { + "min": "05C1A3C5D33F20083200", + "max": "05C1A3C5D33F20083200", + "isMinInclusive": true, + "isMaxInclusive": true + } + ] +} as any} diff --git a/src/router.ts b/src/router.ts index b7ed49c..103f0da 100644 --- a/src/router.ts +++ b/src/router.ts @@ -21,7 +21,11 @@ export default (rules: { [x: string]: { [y: string]: Function } }) => { } let { method } = req; - if ( + + if (req.method === "POST" && + trueHeader(req, "x-ms-cosmos-is-query-plan-request")){ + method += "_QUERYPLAN"; + } else if ( req.method === "POST" && (trueHeader(req, "x-ms-documentdb-isquery") || req.headers["content-type"] === "application/query+json") diff --git a/src/routes.ts b/src/routes.ts index ba5c2ee..5bbb126 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -10,6 +10,7 @@ import deleteUserDefinedFunction from "./handler/delete-user-defined-function"; import queryCollections from "./handler/query-collections"; import queryDatabases from "./handler/query-databases"; import queryDocuments from "./handler/query-documents"; +import queryPlanDocuments from "./handler/query-plan-documents" import queryUserDefinedFunctions from "./handler/query-user-defined-functions"; import readCollection from "./handler/read-collection"; import readCollections from "./handler/read-collections"; @@ -63,6 +64,9 @@ export default router({ "/dbs/:dbId/colls": queryCollections, "/dbs": queryDatabases }, + POST_QUERYPLAN: { + "/dbs/:dbId/colls/:collId/docs": queryPlanDocuments + }, POST_BATCH: { "/dbs/:dbId/colls/:collId/docs": batchDocuments },