Socket
Socket
Sign inDemoInstall

@zeit/cosmosdb-query

Package Overview
Dependencies
Maintainers
55
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@zeit/cosmosdb-query - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

4

lib/helpers.d.ts

@@ -13,3 +13,3 @@ export declare const stripUndefined: (obj: any) => any;

[x: string]: any;
}[], ridPath: string[], ...orders: [string[], boolean][]) => {
}[], getRid: (a: any) => any, ...orders: [(a: any) => any, boolean][]) => {
[x: string]: any;

@@ -21,3 +21,3 @@ }[];

token: string;
}, ridPath?: string[], orderBy?: [string[], boolean]) => {
}, getRid?: (a: any) => any, orderBy?: [(a: any) => any, boolean]) => {
result: {

@@ -24,0 +24,0 @@ [x: string]: any;

@@ -35,3 +35,2 @@ "use strict";

};
const prop = (obj, path) => path.reduce((o, k) => (typeof o !== "undefined" ? o[k] : o), obj);
const comparator = (a, b) => {

@@ -170,11 +169,8 @@ if (a === b)

exports.concat = (a, b) => typeof a === "string" && typeof b === "string" ? a + b : undefined;
exports.sort = (collection, ridPath, ...orders) => {
if (orders.some(([o]) => !Array.isArray(o) || o.length < 2)) {
throw new Error("Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path.");
}
exports.sort = (collection, getRid, ...orders) => {
const sorted = collection.slice().sort((a, b) => {
for (let i = 0, l = orders.length; i < l; i += 1) {
const [path, desc] = orders[i];
const aValue = prop(a, path);
const bValue = prop(b, path);
const [getValue, desc] = orders[i];
const aValue = getValue(a);
const bValue = getValue(b);
const r = comparator(aValue, bValue);

@@ -185,4 +181,4 @@ if (r !== 0)

// sort by `_rid`
const rid1 = prop(a, ridPath);
const rid2 = prop(b, ridPath);
const rid1 = getRid(a);
const rid2 = getRid(b);
return comparator(rid1, rid2);

@@ -197,4 +193,4 @@ });

for (let j = 0, l = orders.length; j < l; j += 1) {
const [path] = orders[j];
const value = prop(doc, path);
const [getValue] = orders[j];
const value = getValue(doc);
const t = typeOf(value);

@@ -211,3 +207,3 @@ if (TYPE_ORDERS.has(t)) {

};
exports.paginate = (collection, maxItemCount, continuation, ridPath, orderBy) => {
exports.paginate = (collection, maxItemCount, continuation, getRid, orderBy) => {
let result = collection;

@@ -221,3 +217,3 @@ let token;

if (typeof token.RTD !== "undefined" && orderBy) {
const rtd = prop(d, orderBy[0]);
const rtd = orderBy[0](d);
const r = comparator(rtd, token.RTD) * (orderBy[1] ? -1 : 1);

@@ -229,3 +225,3 @@ if (r < 0)

}
const rid = prop(d, ridPath);
const rid = getRid(d);
if (!rid) {

@@ -251,3 +247,3 @@ throw new Error("The _rid field is required on items for the continuation option.");

const item = result[maxItemCount];
const RID = prop(item, ridPath);
const RID = getRid(item);
if (!RID) {

@@ -258,7 +254,7 @@ throw new Error("The _rid field is required on items for the maxItemCount option.");

const TRC = (token ? token.TRC : 0) + maxItemCount;
const RTD = orderBy ? prop(item, orderBy[0]) : undefined;
const RTD = orderBy ? orderBy[0](item) : undefined;
// calculate "SRC" which is the offset of items with the same `_rid`;
let j = offset + maxItemCount - 1;
for (; j >= 0; j -= 1) {
if (prop(collection[j], ridPath) !== RID)
if (getRid(collection[j]) !== RID)
break;

@@ -265,0 +261,0 @@ }

@@ -93,10 +93,27 @@ "use strict";

return {
type: "ArrayExpression",
elements: [
type: "ArrowFunctionExpression",
params: [
{
type: "StringLiteral",
value: ctx.document.properties[0].key.name
type: "Identifier",
name: "$"
}
],
body: {
type: "MemberExpression",
object: {
type: "MemberExpression",
object: {
type: "Identifier",
name: "$"
},
property: {
type: "Identifier",
name: ctx.document.properties[0].key.name
}
},
{ type: "StringLiteral", value: "_rid" }
]
property: {
type: "Identifier",
name: "_rid"
}
}
};

@@ -528,8 +545,37 @@ }

scalar_member_expression(ctx, { object, property, computed }) {
return {
const objectNode = transform(ctx, object);
const memberExpressionNode = {
type: "MemberExpression",
object: transform(ctx, object),
object: objectNode,
property: transform(ctx, property),
computed
};
return object.type === "scalar_member_expression"
? {
type: "ConditionalExpression",
test: {
type: "LogicalExpression",
left: {
type: "BinaryExpression",
left: {
type: "UnaryExpression",
operator: "typeof",
argument: objectNode
},
operator: "===",
right: {
type: "StringLiteral",
value: "object"
}
},
operator: "&&",
right: objectNode
},
consequent: memberExpressionNode,
alternate: {
type: "Identifier",
name: "undefined"
}
}
: memberExpressionNode;
},

@@ -776,20 +822,23 @@ scalar_object_expression(ctx, { properties }) {

sort_expression(ctx, { expression, order }) {
if (expression.type !== "scalar_member_expression") {
throw new Error("Unsupported ORDER BY clause. ORDER BY item expression could not be mapped to a document path.");
}
const node = transform(ctx, expression);
const elements = [];
if (node.type === "MemberExpression") {
traverse_1.default({ type: "Program", body: [node] }, {
MemberExpression(path) {
elements.unshift({
type: "StringLiteral",
value: path.node.property.name
});
if (path.node.object.type === "Identifier") {
elements.unshift({
type: "StringLiteral",
value: path.node.object.name
});
}
traverse_1.default({ type: "Program", body: [node] }, {
MemberExpression(path) {
if (path.node.object.type === "Identifier" &&
path.node.object.name !== "$") {
// eslint-disable-next-line no-param-reassign
path.node.object = {
type: "MemberExpression",
object: {
type: "Identifier",
name: "$"
},
property: path.node.object
};
path.skip();
}
});
}
}
});
return {

@@ -799,4 +848,10 @@ type: "ArrayExpression",

{
type: "ArrayExpression",
elements
type: "ArrowFunctionExpression",
params: [
{
type: "Identifier",
name: "$"
}
],
body: node
},

@@ -803,0 +858,0 @@ {

{
"name": "@zeit/cosmosdb-query",
"version": "0.3.0",
"version": "0.3.1",
"description": "A SQL parser and executer for Cosmos DB",

@@ -23,4 +23,4 @@ "license": "MIT",

"dependencies": {
"@babel/generator": "7.4.4",
"@babel/traverse": "7.4.5"
"@babel/generator": "7.5.5",
"@babel/traverse": "7.5.5"
},

@@ -30,17 +30,17 @@ "devDependencies": {

"@types/babel__traverse": "7.0.7",
"@types/node": "12.0.10",
"@typescript-eslint/eslint-plugin": "1.11.0",
"@typescript-eslint/parser": "1.11.0",
"@types/node": "12.7.3",
"@typescript-eslint/eslint-plugin": "2.0.0",
"@typescript-eslint/parser": "2.0.0",
"@zeit/best": "0.5.3",
"@zeit/git-hooks": "0.1.4",
"eslint": "6.0.1",
"eslint-config-airbnb": "17.1.0",
"eslint-config-prettier": "6.0.0",
"eslint-plugin-import": "2.18.0",
"eslint-plugin-jsx-a11y": "6.2.1",
"eslint-plugin-react": "7.14.2",
"eslint": "6.2.2",
"eslint-config-airbnb": "18.0.1",
"eslint-config-prettier": "6.1.0",
"eslint-plugin-import": "2.18.2",
"eslint-plugin-jsx-a11y": "6.2.3",
"eslint-plugin-react": "7.14.3",
"pegjs": "0.10.0",
"prettier": "1.18.2",
"ts-node": "8.3.0",
"typescript": "3.5.2"
"typescript": "3.6.2"
},

@@ -47,0 +47,0 @@ "eslintConfig": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc