mirror of
https://github.com/JonasunderscoreJones/jonas_jones-api.git
synced 2025-10-23 17:19:18 +02:00
some progress
This commit is contained in:
parent
aea93a5527
commit
e3c15bd288
1388 changed files with 306946 additions and 68323 deletions
20
node_modules/sift/MIT-LICENSE.txt
generated
vendored
Normal file
20
node_modules/sift/MIT-LICENSE.txt
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
Copyright (c) 2015 Craig Condon
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
465
node_modules/sift/README.md
generated
vendored
Executable file
465
node_modules/sift/README.md
generated
vendored
Executable file
|
@ -0,0 +1,465 @@
|
|||
**Installation**: `npm install sift`, or `yarn add sift`
|
||||
|
||||
## Sift is a tiny library for using MongoDB queries in Javascript
|
||||
|
||||
[](https://secure.travis-ci.org/crcn/sift.js)
|
||||
|
||||
<!-- [](https://coveralls.io/r/crcn/sift.js) -->
|
||||
<!-- [](https://gitter.im/crcn/sift.js?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -->
|
||||
|
||||
**For extended documentation, checkout http://docs.mongodb.org/manual/reference/operator/query/**
|
||||
|
||||
## Features:
|
||||
|
||||
- Supported operators: [\$in](#in), [\$nin](#nin), [\$exists](#exists), [\$gte](#gte), [\$gt](#gt), [\$lte](#lte), [\$lt](#lt), [\$eq](#eq), [\$ne](#ne), [\$mod](#mod), [\$all](#all), [\$and](#and), [\$or](#or), [\$nor](#nor), [\$not](#not), [\$size](#size), [\$type](#type), [\$regex](#regex), [\$where](#where), [\$elemMatch](#elemmatch)
|
||||
- Regexp searches
|
||||
- Supports node.js, and web
|
||||
- Custom Operations
|
||||
- Tree-shaking (omitting functionality from web app bundles)
|
||||
|
||||
## Examples
|
||||
|
||||
```javascript
|
||||
import sift from "sift";
|
||||
|
||||
//intersecting arrays
|
||||
const result1 = ["hello", "sifted", "array!"].filter(
|
||||
sift({ $in: ["hello", "world"] })
|
||||
); //['hello']
|
||||
|
||||
//regexp filter
|
||||
const result2 = ["craig", "john", "jake"].filter(sift(/^j/)); //['john','jake']
|
||||
|
||||
// function filter
|
||||
const testFilter = sift({
|
||||
//you can also filter against functions
|
||||
name: function(value) {
|
||||
return value.length == 5;
|
||||
}
|
||||
});
|
||||
|
||||
const result3 = [
|
||||
{
|
||||
name: "craig"
|
||||
},
|
||||
{
|
||||
name: "john"
|
||||
},
|
||||
{
|
||||
name: "jake"
|
||||
}
|
||||
].filter(testFilter); // filtered: [{ name: 'craig' }]
|
||||
|
||||
//you can test *single values* against your custom sifter
|
||||
testFilter({ name: "sarah" }); //true
|
||||
testFilter({ name: "tim" }); //false
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### sift(query: MongoQuery, options?: Options): Function
|
||||
|
||||
Creates a filter with all of the built-in MongoDB query operations.
|
||||
|
||||
- `query` - the filter to use against the target array
|
||||
- `options`
|
||||
- `operations` - [custom operations](#custom-operations)
|
||||
- `compare` - compares difference between two values
|
||||
|
||||
Example:
|
||||
|
||||
```javascript
|
||||
import sift from "sift";
|
||||
|
||||
const test = sift({ $gt: 5 }));
|
||||
|
||||
console.log(test(6)); // true
|
||||
console.log(test(4)); // false
|
||||
|
||||
[3, 4, 5, 6, 7].filter(sift({ $exists: true })); // [6, 7]
|
||||
```
|
||||
|
||||
### createQueryTester(query: Query, options?: Options): Function
|
||||
|
||||
Creates a filter function **without** built-in MongoDB query operations. This is useful
|
||||
if you're looking to omit certain operations from application bundles. See [Omitting built-in operations](#omitting-built-in-operations) for more info.
|
||||
|
||||
```javascript
|
||||
import { createQueryTester, $eq, $in } from "sift";
|
||||
const filter = createQueryTester({ $eq: 5 }, { operations: { $eq, $in } });
|
||||
```
|
||||
|
||||
### createEqualsOperation(params: any, ownerQuery: Query, options: Options): Operation
|
||||
|
||||
Used for [custom operations](#custom-operations).
|
||||
|
||||
```javascript
|
||||
import { createQueryTester, createEqualsOperation, $eq, $in } from "sift";
|
||||
const filter = createQueryTester(
|
||||
{ $mod: 5 },
|
||||
{
|
||||
operations: {
|
||||
$something(mod, ownerQuery, options) {
|
||||
return createEqualsOperation(
|
||||
value => value % mod === 0,
|
||||
ownerQuery,
|
||||
options
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
filter(10); // true
|
||||
filter(11); // false
|
||||
```
|
||||
|
||||
## Supported Operators
|
||||
|
||||
See MongoDB's [advanced queries](http://www.mongodb.org/display/DOCS/Advanced+Queries) for more info.
|
||||
|
||||
### \$in
|
||||
|
||||
array value must be _\$in_ the given query:
|
||||
|
||||
Intersecting two arrays:
|
||||
|
||||
```javascript
|
||||
//filtered: ['Brazil']
|
||||
["Brazil", "Haiti", "Peru", "Chile"].filter(
|
||||
sift({ $in: ["Costa Rica", "Brazil"] })
|
||||
);
|
||||
```
|
||||
|
||||
Here's another example. This acts more like the \$or operator:
|
||||
|
||||
```javascript
|
||||
[{ name: "Craig", location: "Brazil" }].filter(
|
||||
sift({ location: { $in: ["Costa Rica", "Brazil"] } })
|
||||
);
|
||||
```
|
||||
|
||||
### \$nin
|
||||
|
||||
Opposite of \$in:
|
||||
|
||||
```javascript
|
||||
//filtered: ['Haiti','Peru','Chile']
|
||||
["Brazil", "Haiti", "Peru", "Chile"].filter(
|
||||
sift({ $nin: ["Costa Rica", "Brazil"] })
|
||||
);
|
||||
```
|
||||
|
||||
### \$exists
|
||||
|
||||
Checks if whether a value exists:
|
||||
|
||||
```javascript
|
||||
//filtered: ['Craig','Tim']
|
||||
sift({ $exists: true })(["Craig", null, "Tim"]);
|
||||
```
|
||||
|
||||
You can also filter out values that don't exist
|
||||
|
||||
```javascript
|
||||
//filtered: [{ name: "Tim" }]
|
||||
[{ name: "Craig", city: "Minneapolis" }, { name: "Tim" }].filter(
|
||||
sift({ city: { $exists: false } })
|
||||
);
|
||||
```
|
||||
|
||||
### \$gte
|
||||
|
||||
Checks if a number is >= value:
|
||||
|
||||
```javascript
|
||||
//filtered: [2, 3]
|
||||
[0, 1, 2, 3].filter(sift({ $gte: 2 }));
|
||||
```
|
||||
|
||||
### \$gt
|
||||
|
||||
Checks if a number is > value:
|
||||
|
||||
```javascript
|
||||
//filtered: [3]
|
||||
[0, 1, 2, 3].filter(sift({ $gt: 2 }));
|
||||
```
|
||||
|
||||
### \$lte
|
||||
|
||||
Checks if a number is <= value.
|
||||
|
||||
```javascript
|
||||
//filtered: [0, 1, 2]
|
||||
[0, 1, 2, 3].filter(sift({ $lte: 2 }));
|
||||
```
|
||||
|
||||
### \$lt
|
||||
|
||||
Checks if number is < value.
|
||||
|
||||
```javascript
|
||||
//filtered: [0, 1]
|
||||
[0, 1, 2, 3].filter(sift({ $lt: 2 }));
|
||||
```
|
||||
|
||||
### \$eq
|
||||
|
||||
Checks if `query === value`. Note that **\$eq can be omitted**. For **\$eq**, and **\$ne**
|
||||
|
||||
```javascript
|
||||
//filtered: [{ state: 'MN' }]
|
||||
[{ state: "MN" }, { state: "CA" }, { state: "WI" }].filter(
|
||||
sift({ state: { $eq: "MN" } })
|
||||
);
|
||||
```
|
||||
|
||||
Or:
|
||||
|
||||
```javascript
|
||||
//filtered: [{ state: 'MN' }]
|
||||
[{ state: "MN" }, { state: "CA" }, { state: "WI" }].filter(
|
||||
sift({ state: "MN" })
|
||||
);
|
||||
```
|
||||
|
||||
### \$ne
|
||||
|
||||
Checks if `query !== value`.
|
||||
|
||||
```javascript
|
||||
//filtered: [{ state: 'CA' }, { state: 'WI'}]
|
||||
[{ state: "MN" }, { state: "CA" }, { state: "WI" }].filter(
|
||||
sift({ state: { $ne: "MN" } })
|
||||
);
|
||||
```
|
||||
|
||||
### \$mod
|
||||
|
||||
Modulus:
|
||||
|
||||
```javascript
|
||||
//filtered: [300, 600]
|
||||
[100, 200, 300, 400, 500, 600].filter(sift({ $mod: [3, 0] }));
|
||||
```
|
||||
|
||||
### \$all
|
||||
|
||||
values must match **everything** in array:
|
||||
|
||||
```javascript
|
||||
//filtered: [ { tags: ['books','programming','travel' ]} ]
|
||||
[
|
||||
{ tags: ["books", "programming", "travel"] },
|
||||
{ tags: ["travel", "cooking"] }
|
||||
].filter(sift({ tags: { $all: ["books", "programming"] } }));
|
||||
```
|
||||
|
||||
### \$and
|
||||
|
||||
ability to use an array of expressions. All expressions must test true.
|
||||
|
||||
```javascript
|
||||
//filtered: [ { name: 'Craig', state: 'MN' }]
|
||||
|
||||
[
|
||||
{ name: "Craig", state: "MN" },
|
||||
{ name: "Tim", state: "MN" },
|
||||
{ name: "Joe", state: "CA" }
|
||||
].filter(sift({ $and: [{ name: "Craig" }, { state: "MN" }] }));
|
||||
```
|
||||
|
||||
### \$or
|
||||
|
||||
OR array of expressions.
|
||||
|
||||
```javascript
|
||||
//filtered: [ { name: 'Craig', state: 'MN' }, { name: 'Tim', state: 'MN' }]
|
||||
[
|
||||
{ name: "Craig", state: "MN" },
|
||||
{ name: "Tim", state: "MN" },
|
||||
{ name: "Joe", state: "CA" }
|
||||
].filter(sift({ $or: [{ name: "Craig" }, { state: "MN" }] }));
|
||||
```
|
||||
|
||||
### \$nor
|
||||
|
||||
opposite of or:
|
||||
|
||||
```javascript
|
||||
//filtered: [{ name: 'Joe', state: 'CA' }]
|
||||
[
|
||||
{ name: "Craig", state: "MN" },
|
||||
{ name: "Tim", state: "MN" },
|
||||
{ name: "Joe", state: "CA" }
|
||||
].filter(sift({ $nor: [{ name: "Craig" }, { state: "MN" }] }));
|
||||
```
|
||||
|
||||
### \$size
|
||||
|
||||
Matches an array - must match given size:
|
||||
|
||||
```javascript
|
||||
//filtered: ['food','cooking']
|
||||
[{ tags: ["food", "cooking"] }, { tags: ["traveling"] }].filter(
|
||||
sift({ tags: { $size: 2 } })
|
||||
);
|
||||
```
|
||||
|
||||
### \$type
|
||||
|
||||
Matches a values based on the type
|
||||
|
||||
```javascript
|
||||
[new Date(), 4342, "hello world"].filter(sift({ $type: Date })); //returns single date
|
||||
[new Date(), 4342, "hello world"].filter(sift({ $type: String })); //returns ['hello world']
|
||||
```
|
||||
|
||||
### \$regex
|
||||
|
||||
Matches values based on the given regular expression
|
||||
|
||||
```javascript
|
||||
["frank", "fred", "sam", "frost"].filter(
|
||||
sift({ $regex: /^f/i, $nin: ["frank"] })
|
||||
); // ["fred", "frost"]
|
||||
["frank", "fred", "sam", "frost"].filter(
|
||||
sift({ $regex: "^f", $options: "i", $nin: ["frank"] })
|
||||
); // ["fred", "frost"]
|
||||
```
|
||||
|
||||
### \$where
|
||||
|
||||
Matches based on some javascript comparison
|
||||
|
||||
```javascript
|
||||
[{ name: "frank" }, { name: "joe" }].filter(
|
||||
sift({ $where: "this.name === 'frank'" })
|
||||
); // ["frank"]
|
||||
[{ name: "frank" }, { name: "joe" }].filter(
|
||||
sift({
|
||||
$where: function() {
|
||||
return this.name === "frank";
|
||||
}
|
||||
})
|
||||
); // ["frank"]
|
||||
```
|
||||
|
||||
### \$elemMatch
|
||||
|
||||
Matches elements of array
|
||||
|
||||
```javascript
|
||||
var bills = [
|
||||
{
|
||||
month: "july",
|
||||
casts: [
|
||||
{
|
||||
id: 1,
|
||||
value: 200
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
value: 1000
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
month: "august",
|
||||
casts: [
|
||||
{
|
||||
id: 3,
|
||||
value: 1000
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
value: 4000
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
var result = bills.filter(
|
||||
sift({
|
||||
casts: {
|
||||
$elemMatch: {
|
||||
value: { $gt: 1000 }
|
||||
}
|
||||
}
|
||||
})
|
||||
); // {month:'august', casts:[{id:3, value: 1000},{id: 4, value: 4000}]}
|
||||
```
|
||||
|
||||
### \$not
|
||||
|
||||
Not expression:
|
||||
|
||||
```javascript
|
||||
["craig", "tim", "jake"].filter(sift({ $not: { $in: ["craig", "tim"] } })); //['jake']
|
||||
["craig", "tim", "jake"].filter(sift({ $not: { $size: 5 } })); //['tim','jake']
|
||||
```
|
||||
|
||||
### Date comparison
|
||||
|
||||
Mongodb allows you to do date comparisons like so:
|
||||
|
||||
```javascript
|
||||
db.collection.find({ createdAt: { $gte: "2018-03-22T06:00:00Z" } });
|
||||
```
|
||||
|
||||
In Sift, you'll need to specify a Date object:
|
||||
|
||||
```javascript
|
||||
collection.find(
|
||||
sift({ createdAt: { $gte: new Date("2018-03-22T06:00:00Z") } })
|
||||
);
|
||||
```
|
||||
|
||||
## Custom behavior
|
||||
|
||||
Sift works like MongoDB out of the box, but you're also able to modify the behavior to suite your needs.
|
||||
|
||||
#### Custom operations
|
||||
|
||||
You can register your own custom operations. Here's an example:
|
||||
|
||||
```javascript
|
||||
import sift, { createEqualsOperation } from "sift";
|
||||
|
||||
var filter = sift(
|
||||
{
|
||||
$customMod: 2
|
||||
},
|
||||
{
|
||||
operations: {
|
||||
$customMod(params, ownerQuery, options) {
|
||||
return createEqualsOperation(
|
||||
value => value % params !== 0,
|
||||
ownerQuery,
|
||||
options
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
[1, 2, 3, 4, 5].filter(filter); // 1, 3, 5
|
||||
```
|
||||
|
||||
#### Omitting built-in operations
|
||||
|
||||
You can create a filter function that omits the built-in operations like so:
|
||||
|
||||
```javascript
|
||||
import { createQueryTester, $in, $all, $nin, $lt } from "sift";
|
||||
const test = createQueryTester(
|
||||
{
|
||||
$eq: 10
|
||||
},
|
||||
{ operations: { $in, $all, $nin, $lt } }
|
||||
);
|
||||
|
||||
[1, 2, 3, 4, 10].filter(test);
|
||||
```
|
||||
|
||||
For bundlers like `Webpack` and `Rollup`, operations that aren't used are omitted from application bundles via tree-shaking.
|
626
node_modules/sift/es/index.js
generated
vendored
Normal file
626
node_modules/sift/es/index.js
generated
vendored
Normal file
|
@ -0,0 +1,626 @@
|
|||
const typeChecker = (type) => {
|
||||
const typeString = "[object " + type + "]";
|
||||
return function (value) {
|
||||
return getClassName(value) === typeString;
|
||||
};
|
||||
};
|
||||
const getClassName = value => Object.prototype.toString.call(value);
|
||||
const comparable = (value) => {
|
||||
if (value instanceof Date) {
|
||||
return value.getTime();
|
||||
}
|
||||
else if (isArray(value)) {
|
||||
return value.map(comparable);
|
||||
}
|
||||
else if (value && typeof value.toJSON === "function") {
|
||||
return value.toJSON();
|
||||
}
|
||||
return value;
|
||||
};
|
||||
const isArray = typeChecker("Array");
|
||||
const isObject = typeChecker("Object");
|
||||
const isFunction = typeChecker("Function");
|
||||
const isVanillaObject = value => {
|
||||
return (value &&
|
||||
(value.constructor === Object ||
|
||||
value.constructor === Array ||
|
||||
value.constructor.toString() === "function Object() { [native code] }" ||
|
||||
value.constructor.toString() === "function Array() { [native code] }") &&
|
||||
!value.toJSON);
|
||||
};
|
||||
const equals = (a, b) => {
|
||||
if (a == null && a == b) {
|
||||
return true;
|
||||
}
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
|
||||
return false;
|
||||
}
|
||||
if (isArray(a)) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0, { length } = a; i < length; i++) {
|
||||
if (!equals(a[i], b[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (isObject(a)) {
|
||||
if (Object.keys(a).length !== Object.keys(b).length) {
|
||||
return false;
|
||||
}
|
||||
for (const key in a) {
|
||||
if (!equals(a[key], b[key]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walks through each value given the context - used for nested operations. E.g:
|
||||
* { "person.address": { $eq: "blarg" }}
|
||||
*/
|
||||
const walkKeyPathValues = (item, keyPath, next, depth, key, owner) => {
|
||||
const currentKey = keyPath[depth];
|
||||
// if array, then try matching. Might fall through for cases like:
|
||||
// { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
|
||||
if (isArray(item) && isNaN(Number(currentKey))) {
|
||||
for (let i = 0, { length } = item; i < length; i++) {
|
||||
// if FALSE is returned, then terminate walker. For operations, this simply
|
||||
// means that the search critera was met.
|
||||
if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (depth === keyPath.length || item == null) {
|
||||
return next(item, key, owner, depth === 0);
|
||||
}
|
||||
return walkKeyPathValues(item[currentKey], keyPath, next, depth + 1, currentKey, item);
|
||||
};
|
||||
class BaseOperation {
|
||||
constructor(params, owneryQuery, options, name) {
|
||||
this.params = params;
|
||||
this.owneryQuery = owneryQuery;
|
||||
this.options = options;
|
||||
this.name = name;
|
||||
this.init();
|
||||
}
|
||||
init() { }
|
||||
reset() {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
class GroupOperation extends BaseOperation {
|
||||
constructor(params, owneryQuery, options, children) {
|
||||
super(params, owneryQuery, options);
|
||||
this.children = children;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
reset() {
|
||||
this.keep = false;
|
||||
this.done = false;
|
||||
for (let i = 0, { length } = this.children; i < length; i++) {
|
||||
this.children[i].reset();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
childrenNext(item, key, owner, root) {
|
||||
let done = true;
|
||||
let keep = true;
|
||||
for (let i = 0, { length } = this.children; i < length; i++) {
|
||||
const childOperation = this.children[i];
|
||||
if (!childOperation.done) {
|
||||
childOperation.next(item, key, owner, root);
|
||||
}
|
||||
if (!childOperation.keep) {
|
||||
keep = false;
|
||||
}
|
||||
if (childOperation.done) {
|
||||
if (!childOperation.keep) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
this.done = done;
|
||||
this.keep = keep;
|
||||
}
|
||||
}
|
||||
class NamedGroupOperation extends GroupOperation {
|
||||
constructor(params, owneryQuery, options, children, name) {
|
||||
super(params, owneryQuery, options, children);
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
class QueryOperation extends GroupOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
next(item, key, parent, root) {
|
||||
this.childrenNext(item, key, parent, root);
|
||||
}
|
||||
}
|
||||
class NestedOperation extends GroupOperation {
|
||||
constructor(keyPath, params, owneryQuery, options, children) {
|
||||
super(params, owneryQuery, options, children);
|
||||
this.keyPath = keyPath;
|
||||
this.propop = true;
|
||||
/**
|
||||
*/
|
||||
this._nextNestedValue = (value, key, owner, root) => {
|
||||
this.childrenNext(value, key, owner, root);
|
||||
return !this.done;
|
||||
};
|
||||
}
|
||||
/**
|
||||
*/
|
||||
next(item, key, parent) {
|
||||
walkKeyPathValues(item, this.keyPath, this._nextNestedValue, 0, key, parent);
|
||||
}
|
||||
}
|
||||
const createTester = (a, compare) => {
|
||||
if (a instanceof Function) {
|
||||
return a;
|
||||
}
|
||||
if (a instanceof RegExp) {
|
||||
return b => {
|
||||
const result = typeof b === "string" && a.test(b);
|
||||
a.lastIndex = 0;
|
||||
return result;
|
||||
};
|
||||
}
|
||||
const comparableA = comparable(a);
|
||||
return b => compare(comparableA, comparable(b));
|
||||
};
|
||||
class EqualsOperation extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() {
|
||||
this._test = createTester(this.params, this.options.compare);
|
||||
}
|
||||
next(item, key, parent) {
|
||||
if (!Array.isArray(parent) || parent.hasOwnProperty(key)) {
|
||||
if (this._test(item, key, parent)) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const createEqualsOperation = (params, owneryQuery, options) => new EqualsOperation(params, owneryQuery, options);
|
||||
class NopeOperation extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
next() {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
const numericalOperationCreator = (createNumericalOperation) => (params, owneryQuery, options, name) => {
|
||||
if (params == null) {
|
||||
return new NopeOperation(params, owneryQuery, options, name);
|
||||
}
|
||||
return createNumericalOperation(params, owneryQuery, options, name);
|
||||
};
|
||||
const numericalOperation = (createTester) => numericalOperationCreator((params, owneryQuery, options, name) => {
|
||||
const typeofParams = typeof comparable(params);
|
||||
const test = createTester(params);
|
||||
return new EqualsOperation(b => {
|
||||
return typeof comparable(b) === typeofParams && test(b);
|
||||
}, owneryQuery, options, name);
|
||||
});
|
||||
const createNamedOperation = (name, params, parentQuery, options) => {
|
||||
const operationCreator = options.operations[name];
|
||||
if (!operationCreator) {
|
||||
throwUnsupportedOperation(name);
|
||||
}
|
||||
return operationCreator(params, parentQuery, options, name);
|
||||
};
|
||||
const throwUnsupportedOperation = (name) => {
|
||||
throw new Error(`Unsupported operation: ${name}`);
|
||||
};
|
||||
const containsOperation = (query, options) => {
|
||||
for (const key in query) {
|
||||
if (options.operations.hasOwnProperty(key) || key.charAt(0) === "$")
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const createNestedOperation = (keyPath, nestedQuery, parentKey, owneryQuery, options) => {
|
||||
if (containsOperation(nestedQuery, options)) {
|
||||
const [selfOperations, nestedOperations] = createQueryOperations(nestedQuery, parentKey, options);
|
||||
if (nestedOperations.length) {
|
||||
throw new Error(`Property queries must contain only operations, or exact objects.`);
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, selfOperations);
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
|
||||
new EqualsOperation(nestedQuery, owneryQuery, options)
|
||||
]);
|
||||
};
|
||||
const createQueryOperation = (query, owneryQuery = null, { compare, operations } = {}) => {
|
||||
const options = {
|
||||
compare: compare || equals,
|
||||
operations: Object.assign({}, operations || {})
|
||||
};
|
||||
const [selfOperations, nestedOperations] = createQueryOperations(query, null, options);
|
||||
const ops = [];
|
||||
if (selfOperations.length) {
|
||||
ops.push(new NestedOperation([], query, owneryQuery, options, selfOperations));
|
||||
}
|
||||
ops.push(...nestedOperations);
|
||||
if (ops.length === 1) {
|
||||
return ops[0];
|
||||
}
|
||||
return new QueryOperation(query, owneryQuery, options, ops);
|
||||
};
|
||||
const createQueryOperations = (query, parentKey, options) => {
|
||||
const selfOperations = [];
|
||||
const nestedOperations = [];
|
||||
if (!isVanillaObject(query)) {
|
||||
selfOperations.push(new EqualsOperation(query, query, options));
|
||||
return [selfOperations, nestedOperations];
|
||||
}
|
||||
for (const key in query) {
|
||||
if (options.operations.hasOwnProperty(key)) {
|
||||
const op = createNamedOperation(key, query[key], query, options);
|
||||
if (op) {
|
||||
if (!op.propop && parentKey && !options.operations[parentKey]) {
|
||||
throw new Error(`Malformed query. ${key} cannot be matched against property.`);
|
||||
}
|
||||
}
|
||||
// probably just a flag for another operation (like $options)
|
||||
if (op != null) {
|
||||
selfOperations.push(op);
|
||||
}
|
||||
}
|
||||
else if (key.charAt(0) === "$") {
|
||||
throwUnsupportedOperation(key);
|
||||
}
|
||||
else {
|
||||
nestedOperations.push(createNestedOperation(key.split("."), query[key], key, query, options));
|
||||
}
|
||||
}
|
||||
return [selfOperations, nestedOperations];
|
||||
};
|
||||
const createOperationTester = (operation) => (item, key, owner) => {
|
||||
operation.reset();
|
||||
operation.next(item, key, owner);
|
||||
return operation.keep;
|
||||
};
|
||||
const createQueryTester = (query, options = {}) => {
|
||||
return createOperationTester(createQueryOperation(query, null, options));
|
||||
};
|
||||
|
||||
class $Ne extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() {
|
||||
this._test = createTester(this.params, this.options.compare);
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this.keep = true;
|
||||
}
|
||||
next(item) {
|
||||
if (this._test(item)) {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
|
||||
class $ElemMatch extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() {
|
||||
if (!this.params || typeof this.params !== "object") {
|
||||
throw new Error(`Malformed query. $elemMatch must by an object.`);
|
||||
}
|
||||
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._queryOperation.reset();
|
||||
}
|
||||
next(item) {
|
||||
if (isArray(item)) {
|
||||
for (let i = 0, { length } = item; i < length; i++) {
|
||||
// reset query operation since item being tested needs to pass _all_ query
|
||||
// operations for it to be a success
|
||||
this._queryOperation.reset();
|
||||
const child = item[i];
|
||||
this._queryOperation.next(child, i, item, false);
|
||||
this.keep = this.keep || this._queryOperation.keep;
|
||||
}
|
||||
this.done = true;
|
||||
}
|
||||
else {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
class $Not extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() {
|
||||
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._queryOperation.reset();
|
||||
}
|
||||
next(item, key, owner, root) {
|
||||
this._queryOperation.next(item, key, owner, root);
|
||||
this.done = this._queryOperation.done;
|
||||
this.keep = !this._queryOperation.keep;
|
||||
}
|
||||
}
|
||||
class $Size extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() { }
|
||||
next(item) {
|
||||
if (isArray(item) && item.length === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
// if (parent && parent.length === this.params) {
|
||||
// this.done = true;
|
||||
// this.keep = true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
const assertGroupNotEmpty = (values) => {
|
||||
if (values.length === 0) {
|
||||
throw new Error(`$and/$or/$nor must be a nonempty array`);
|
||||
}
|
||||
};
|
||||
class $Or extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = false;
|
||||
}
|
||||
init() {
|
||||
assertGroupNotEmpty(this.params);
|
||||
this._ops = this.params.map(op => createQueryOperation(op, null, this.options));
|
||||
}
|
||||
reset() {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
for (let i = 0, { length } = this._ops; i < length; i++) {
|
||||
this._ops[i].reset();
|
||||
}
|
||||
}
|
||||
next(item, key, owner) {
|
||||
let done = false;
|
||||
let success = false;
|
||||
for (let i = 0, { length } = this._ops; i < length; i++) {
|
||||
const op = this._ops[i];
|
||||
op.next(item, key, owner);
|
||||
if (op.keep) {
|
||||
done = true;
|
||||
success = op.keep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
}
|
||||
}
|
||||
class $Nor extends $Or {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = false;
|
||||
}
|
||||
next(item, key, owner) {
|
||||
super.next(item, key, owner);
|
||||
this.keep = !this.keep;
|
||||
}
|
||||
}
|
||||
class $In extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() {
|
||||
this._testers = this.params.map(value => {
|
||||
if (containsOperation(value, this.options)) {
|
||||
throw new Error(`cannot nest $ under ${this.name.toLowerCase()}`);
|
||||
}
|
||||
return createTester(value, this.options.compare);
|
||||
});
|
||||
}
|
||||
next(item, key, owner) {
|
||||
let done = false;
|
||||
let success = false;
|
||||
for (let i = 0, { length } = this._testers; i < length; i++) {
|
||||
const test = this._testers[i];
|
||||
if (test(item)) {
|
||||
done = true;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
}
|
||||
}
|
||||
class $Nin extends BaseOperation {
|
||||
constructor(params, ownerQuery, options, name) {
|
||||
super(params, ownerQuery, options, name);
|
||||
this.propop = true;
|
||||
this._in = new $In(params, ownerQuery, options, name);
|
||||
}
|
||||
next(item, key, owner, root) {
|
||||
this._in.next(item, key, owner);
|
||||
if (isArray(owner) && !root) {
|
||||
if (this._in.keep) {
|
||||
this.keep = false;
|
||||
this.done = true;
|
||||
}
|
||||
else if (key == owner.length - 1) {
|
||||
this.keep = true;
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.keep = !this._in.keep;
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._in.reset();
|
||||
}
|
||||
}
|
||||
class $Exists extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
next(item, key, owner) {
|
||||
if (owner.hasOwnProperty(key) === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
class $And extends NamedGroupOperation {
|
||||
constructor(params, owneryQuery, options, name) {
|
||||
super(params, owneryQuery, options, params.map(query => createQueryOperation(query, owneryQuery, options)), name);
|
||||
this.propop = false;
|
||||
assertGroupNotEmpty(params);
|
||||
}
|
||||
next(item, key, owner, root) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
}
|
||||
}
|
||||
class $All extends NamedGroupOperation {
|
||||
constructor(params, owneryQuery, options, name) {
|
||||
super(params, owneryQuery, options, params.map(query => createQueryOperation(query, owneryQuery, options)), name);
|
||||
this.propop = true;
|
||||
}
|
||||
next(item, key, owner, root) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
}
|
||||
}
|
||||
const $eq = (params, owneryQuery, options) => new EqualsOperation(params, owneryQuery, options);
|
||||
const $ne = (params, owneryQuery, options, name) => new $Ne(params, owneryQuery, options, name);
|
||||
const $or = (params, owneryQuery, options, name) => new $Or(params, owneryQuery, options, name);
|
||||
const $nor = (params, owneryQuery, options, name) => new $Nor(params, owneryQuery, options, name);
|
||||
const $elemMatch = (params, owneryQuery, options, name) => new $ElemMatch(params, owneryQuery, options, name);
|
||||
const $nin = (params, owneryQuery, options, name) => new $Nin(params, owneryQuery, options, name);
|
||||
const $in = (params, owneryQuery, options, name) => {
|
||||
return new $In(params, owneryQuery, options, name);
|
||||
};
|
||||
const $lt = numericalOperation(params => b => b < params);
|
||||
const $lte = numericalOperation(params => b => b <= params);
|
||||
const $gt = numericalOperation(params => b => b > params);
|
||||
const $gte = numericalOperation(params => b => b >= params);
|
||||
const $mod = ([mod, equalsValue], owneryQuery, options) => new EqualsOperation(b => comparable(b) % mod === equalsValue, owneryQuery, options);
|
||||
const $exists = (params, owneryQuery, options, name) => new $Exists(params, owneryQuery, options, name);
|
||||
const $regex = (pattern, owneryQuery, options) => new EqualsOperation(new RegExp(pattern, owneryQuery.$options), owneryQuery, options);
|
||||
const $not = (params, owneryQuery, options, name) => new $Not(params, owneryQuery, options, name);
|
||||
const typeAliases = {
|
||||
number: v => typeof v === "number",
|
||||
string: v => typeof v === "string",
|
||||
bool: v => typeof v === "boolean",
|
||||
array: v => Array.isArray(v),
|
||||
null: v => v === null,
|
||||
timestamp: v => v instanceof Date
|
||||
};
|
||||
const $type = (clazz, owneryQuery, options) => new EqualsOperation(b => {
|
||||
if (typeof clazz === "string") {
|
||||
if (!typeAliases[clazz]) {
|
||||
throw new Error(`Type alias does not exist`);
|
||||
}
|
||||
return typeAliases[clazz](b);
|
||||
}
|
||||
return b != null ? b instanceof clazz || b.constructor === clazz : false;
|
||||
}, owneryQuery, options);
|
||||
const $and = (params, ownerQuery, options, name) => new $And(params, ownerQuery, options, name);
|
||||
const $all = (params, ownerQuery, options, name) => new $All(params, ownerQuery, options, name);
|
||||
const $size = (params, ownerQuery, options) => new $Size(params, ownerQuery, options, "$size");
|
||||
const $options = () => null;
|
||||
const $where = (params, ownerQuery, options) => {
|
||||
let test;
|
||||
if (isFunction(params)) {
|
||||
test = params;
|
||||
}
|
||||
else if (!process.env.CSP_ENABLED) {
|
||||
test = new Function("obj", "return " + params);
|
||||
}
|
||||
else {
|
||||
throw new Error(`In CSP mode, sift does not support strings in "$where" condition`);
|
||||
}
|
||||
return new EqualsOperation(b => test.bind(b)(b), ownerQuery, options);
|
||||
};
|
||||
|
||||
var defaultOperations = /*#__PURE__*/Object.freeze({
|
||||
__proto__: null,
|
||||
$Size: $Size,
|
||||
$eq: $eq,
|
||||
$ne: $ne,
|
||||
$or: $or,
|
||||
$nor: $nor,
|
||||
$elemMatch: $elemMatch,
|
||||
$nin: $nin,
|
||||
$in: $in,
|
||||
$lt: $lt,
|
||||
$lte: $lte,
|
||||
$gt: $gt,
|
||||
$gte: $gte,
|
||||
$mod: $mod,
|
||||
$exists: $exists,
|
||||
$regex: $regex,
|
||||
$not: $not,
|
||||
$type: $type,
|
||||
$and: $and,
|
||||
$all: $all,
|
||||
$size: $size,
|
||||
$options: $options,
|
||||
$where: $where
|
||||
});
|
||||
|
||||
const createDefaultQueryOperation = (query, ownerQuery, { compare, operations } = {}) => {
|
||||
return createQueryOperation(query, ownerQuery, {
|
||||
compare,
|
||||
operations: Object.assign({}, defaultOperations, operations || {})
|
||||
});
|
||||
};
|
||||
const createDefaultQueryTester = (query, options = {}) => {
|
||||
const op = createDefaultQueryOperation(query, null, options);
|
||||
return createOperationTester(op);
|
||||
};
|
||||
|
||||
export default createDefaultQueryTester;
|
||||
export { $Size, $all, $and, $elemMatch, $eq, $exists, $gt, $gte, $in, $lt, $lte, $mod, $ne, $nin, $nor, $not, $options, $or, $regex, $size, $type, $where, EqualsOperation, createDefaultQueryOperation, createEqualsOperation, createOperationTester, createQueryOperation, createQueryTester };
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/sift/es/index.js.map
generated
vendored
Normal file
1
node_modules/sift/es/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
729
node_modules/sift/es5m/index.js
generated
vendored
Normal file
729
node_modules/sift/es5m/index.js
generated
vendored
Normal file
|
@ -0,0 +1,729 @@
|
|||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
***************************************************************************** */
|
||||
/* global Reflect, Promise */
|
||||
|
||||
var extendStatics = function(d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
|
||||
function __extends(d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
}
|
||||
|
||||
var typeChecker = function (type) {
|
||||
var typeString = "[object " + type + "]";
|
||||
return function (value) {
|
||||
return getClassName(value) === typeString;
|
||||
};
|
||||
};
|
||||
var getClassName = function (value) { return Object.prototype.toString.call(value); };
|
||||
var comparable = function (value) {
|
||||
if (value instanceof Date) {
|
||||
return value.getTime();
|
||||
}
|
||||
else if (isArray(value)) {
|
||||
return value.map(comparable);
|
||||
}
|
||||
else if (value && typeof value.toJSON === "function") {
|
||||
return value.toJSON();
|
||||
}
|
||||
return value;
|
||||
};
|
||||
var isArray = typeChecker("Array");
|
||||
var isObject = typeChecker("Object");
|
||||
var isFunction = typeChecker("Function");
|
||||
var isVanillaObject = function (value) {
|
||||
return (value &&
|
||||
(value.constructor === Object ||
|
||||
value.constructor === Array ||
|
||||
value.constructor.toString() === "function Object() { [native code] }" ||
|
||||
value.constructor.toString() === "function Array() { [native code] }") &&
|
||||
!value.toJSON);
|
||||
};
|
||||
var equals = function (a, b) {
|
||||
if (a == null && a == b) {
|
||||
return true;
|
||||
}
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
|
||||
return false;
|
||||
}
|
||||
if (isArray(a)) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0, length_1 = a.length; i < length_1; i++) {
|
||||
if (!equals(a[i], b[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (isObject(a)) {
|
||||
if (Object.keys(a).length !== Object.keys(b).length) {
|
||||
return false;
|
||||
}
|
||||
for (var key in a) {
|
||||
if (!equals(a[key], b[key]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walks through each value given the context - used for nested operations. E.g:
|
||||
* { "person.address": { $eq: "blarg" }}
|
||||
*/
|
||||
var walkKeyPathValues = function (item, keyPath, next, depth, key, owner) {
|
||||
var currentKey = keyPath[depth];
|
||||
// if array, then try matching. Might fall through for cases like:
|
||||
// { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
|
||||
if (isArray(item) && isNaN(Number(currentKey))) {
|
||||
for (var i = 0, length_1 = item.length; i < length_1; i++) {
|
||||
// if FALSE is returned, then terminate walker. For operations, this simply
|
||||
// means that the search critera was met.
|
||||
if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (depth === keyPath.length || item == null) {
|
||||
return next(item, key, owner, depth === 0);
|
||||
}
|
||||
return walkKeyPathValues(item[currentKey], keyPath, next, depth + 1, currentKey, item);
|
||||
};
|
||||
var BaseOperation = /** @class */ (function () {
|
||||
function BaseOperation(params, owneryQuery, options, name) {
|
||||
this.params = params;
|
||||
this.owneryQuery = owneryQuery;
|
||||
this.options = options;
|
||||
this.name = name;
|
||||
this.init();
|
||||
}
|
||||
BaseOperation.prototype.init = function () { };
|
||||
BaseOperation.prototype.reset = function () {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
};
|
||||
return BaseOperation;
|
||||
}());
|
||||
var GroupOperation = /** @class */ (function (_super) {
|
||||
__extends(GroupOperation, _super);
|
||||
function GroupOperation(params, owneryQuery, options, children) {
|
||||
var _this = _super.call(this, params, owneryQuery, options) || this;
|
||||
_this.children = children;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
GroupOperation.prototype.reset = function () {
|
||||
this.keep = false;
|
||||
this.done = false;
|
||||
for (var i = 0, length_2 = this.children.length; i < length_2; i++) {
|
||||
this.children[i].reset();
|
||||
}
|
||||
};
|
||||
/**
|
||||
*/
|
||||
GroupOperation.prototype.childrenNext = function (item, key, owner, root) {
|
||||
var done = true;
|
||||
var keep = true;
|
||||
for (var i = 0, length_3 = this.children.length; i < length_3; i++) {
|
||||
var childOperation = this.children[i];
|
||||
if (!childOperation.done) {
|
||||
childOperation.next(item, key, owner, root);
|
||||
}
|
||||
if (!childOperation.keep) {
|
||||
keep = false;
|
||||
}
|
||||
if (childOperation.done) {
|
||||
if (!childOperation.keep) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
this.done = done;
|
||||
this.keep = keep;
|
||||
};
|
||||
return GroupOperation;
|
||||
}(BaseOperation));
|
||||
var NamedGroupOperation = /** @class */ (function (_super) {
|
||||
__extends(NamedGroupOperation, _super);
|
||||
function NamedGroupOperation(params, owneryQuery, options, children, name) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, children) || this;
|
||||
_this.name = name;
|
||||
return _this;
|
||||
}
|
||||
return NamedGroupOperation;
|
||||
}(GroupOperation));
|
||||
var QueryOperation = /** @class */ (function (_super) {
|
||||
__extends(QueryOperation, _super);
|
||||
function QueryOperation() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
QueryOperation.prototype.next = function (item, key, parent, root) {
|
||||
this.childrenNext(item, key, parent, root);
|
||||
};
|
||||
return QueryOperation;
|
||||
}(GroupOperation));
|
||||
var NestedOperation = /** @class */ (function (_super) {
|
||||
__extends(NestedOperation, _super);
|
||||
function NestedOperation(keyPath, params, owneryQuery, options, children) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, children) || this;
|
||||
_this.keyPath = keyPath;
|
||||
_this.propop = true;
|
||||
/**
|
||||
*/
|
||||
_this._nextNestedValue = function (value, key, owner, root) {
|
||||
_this.childrenNext(value, key, owner, root);
|
||||
return !_this.done;
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
NestedOperation.prototype.next = function (item, key, parent) {
|
||||
walkKeyPathValues(item, this.keyPath, this._nextNestedValue, 0, key, parent);
|
||||
};
|
||||
return NestedOperation;
|
||||
}(GroupOperation));
|
||||
var createTester = function (a, compare) {
|
||||
if (a instanceof Function) {
|
||||
return a;
|
||||
}
|
||||
if (a instanceof RegExp) {
|
||||
return function (b) {
|
||||
var result = typeof b === "string" && a.test(b);
|
||||
a.lastIndex = 0;
|
||||
return result;
|
||||
};
|
||||
}
|
||||
var comparableA = comparable(a);
|
||||
return function (b) { return compare(comparableA, comparable(b)); };
|
||||
};
|
||||
var EqualsOperation = /** @class */ (function (_super) {
|
||||
__extends(EqualsOperation, _super);
|
||||
function EqualsOperation() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
EqualsOperation.prototype.init = function () {
|
||||
this._test = createTester(this.params, this.options.compare);
|
||||
};
|
||||
EqualsOperation.prototype.next = function (item, key, parent) {
|
||||
if (!Array.isArray(parent) || parent.hasOwnProperty(key)) {
|
||||
if (this._test(item, key, parent)) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
return EqualsOperation;
|
||||
}(BaseOperation));
|
||||
var createEqualsOperation = function (params, owneryQuery, options) { return new EqualsOperation(params, owneryQuery, options); };
|
||||
var NopeOperation = /** @class */ (function (_super) {
|
||||
__extends(NopeOperation, _super);
|
||||
function NopeOperation() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
NopeOperation.prototype.next = function () {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
};
|
||||
return NopeOperation;
|
||||
}(BaseOperation));
|
||||
var numericalOperationCreator = function (createNumericalOperation) { return function (params, owneryQuery, options, name) {
|
||||
if (params == null) {
|
||||
return new NopeOperation(params, owneryQuery, options, name);
|
||||
}
|
||||
return createNumericalOperation(params, owneryQuery, options, name);
|
||||
}; };
|
||||
var numericalOperation = function (createTester) {
|
||||
return numericalOperationCreator(function (params, owneryQuery, options, name) {
|
||||
var typeofParams = typeof comparable(params);
|
||||
var test = createTester(params);
|
||||
return new EqualsOperation(function (b) {
|
||||
return typeof comparable(b) === typeofParams && test(b);
|
||||
}, owneryQuery, options, name);
|
||||
});
|
||||
};
|
||||
var createNamedOperation = function (name, params, parentQuery, options) {
|
||||
var operationCreator = options.operations[name];
|
||||
if (!operationCreator) {
|
||||
throwUnsupportedOperation(name);
|
||||
}
|
||||
return operationCreator(params, parentQuery, options, name);
|
||||
};
|
||||
var throwUnsupportedOperation = function (name) {
|
||||
throw new Error("Unsupported operation: " + name);
|
||||
};
|
||||
var containsOperation = function (query, options) {
|
||||
for (var key in query) {
|
||||
if (options.operations.hasOwnProperty(key) || key.charAt(0) === "$")
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
var createNestedOperation = function (keyPath, nestedQuery, parentKey, owneryQuery, options) {
|
||||
if (containsOperation(nestedQuery, options)) {
|
||||
var _a = createQueryOperations(nestedQuery, parentKey, options), selfOperations = _a[0], nestedOperations = _a[1];
|
||||
if (nestedOperations.length) {
|
||||
throw new Error("Property queries must contain only operations, or exact objects.");
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, selfOperations);
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
|
||||
new EqualsOperation(nestedQuery, owneryQuery, options)
|
||||
]);
|
||||
};
|
||||
var createQueryOperation = function (query, owneryQuery, _a) {
|
||||
if (owneryQuery === void 0) { owneryQuery = null; }
|
||||
var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
|
||||
var options = {
|
||||
compare: compare || equals,
|
||||
operations: Object.assign({}, operations || {})
|
||||
};
|
||||
var _c = createQueryOperations(query, null, options), selfOperations = _c[0], nestedOperations = _c[1];
|
||||
var ops = [];
|
||||
if (selfOperations.length) {
|
||||
ops.push(new NestedOperation([], query, owneryQuery, options, selfOperations));
|
||||
}
|
||||
ops.push.apply(ops, nestedOperations);
|
||||
if (ops.length === 1) {
|
||||
return ops[0];
|
||||
}
|
||||
return new QueryOperation(query, owneryQuery, options, ops);
|
||||
};
|
||||
var createQueryOperations = function (query, parentKey, options) {
|
||||
var selfOperations = [];
|
||||
var nestedOperations = [];
|
||||
if (!isVanillaObject(query)) {
|
||||
selfOperations.push(new EqualsOperation(query, query, options));
|
||||
return [selfOperations, nestedOperations];
|
||||
}
|
||||
for (var key in query) {
|
||||
if (options.operations.hasOwnProperty(key)) {
|
||||
var op = createNamedOperation(key, query[key], query, options);
|
||||
if (op) {
|
||||
if (!op.propop && parentKey && !options.operations[parentKey]) {
|
||||
throw new Error("Malformed query. " + key + " cannot be matched against property.");
|
||||
}
|
||||
}
|
||||
// probably just a flag for another operation (like $options)
|
||||
if (op != null) {
|
||||
selfOperations.push(op);
|
||||
}
|
||||
}
|
||||
else if (key.charAt(0) === "$") {
|
||||
throwUnsupportedOperation(key);
|
||||
}
|
||||
else {
|
||||
nestedOperations.push(createNestedOperation(key.split("."), query[key], key, query, options));
|
||||
}
|
||||
}
|
||||
return [selfOperations, nestedOperations];
|
||||
};
|
||||
var createOperationTester = function (operation) { return function (item, key, owner) {
|
||||
operation.reset();
|
||||
operation.next(item, key, owner);
|
||||
return operation.keep;
|
||||
}; };
|
||||
var createQueryTester = function (query, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return createOperationTester(createQueryOperation(query, null, options));
|
||||
};
|
||||
|
||||
var $Ne = /** @class */ (function (_super) {
|
||||
__extends($Ne, _super);
|
||||
function $Ne() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Ne.prototype.init = function () {
|
||||
this._test = createTester(this.params, this.options.compare);
|
||||
};
|
||||
$Ne.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this.keep = true;
|
||||
};
|
||||
$Ne.prototype.next = function (item) {
|
||||
if (this._test(item)) {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
}
|
||||
};
|
||||
return $Ne;
|
||||
}(BaseOperation));
|
||||
// https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
|
||||
var $ElemMatch = /** @class */ (function (_super) {
|
||||
__extends($ElemMatch, _super);
|
||||
function $ElemMatch() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$ElemMatch.prototype.init = function () {
|
||||
if (!this.params || typeof this.params !== "object") {
|
||||
throw new Error("Malformed query. $elemMatch must by an object.");
|
||||
}
|
||||
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
|
||||
};
|
||||
$ElemMatch.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this._queryOperation.reset();
|
||||
};
|
||||
$ElemMatch.prototype.next = function (item) {
|
||||
if (isArray(item)) {
|
||||
for (var i = 0, length_1 = item.length; i < length_1; i++) {
|
||||
// reset query operation since item being tested needs to pass _all_ query
|
||||
// operations for it to be a success
|
||||
this._queryOperation.reset();
|
||||
var child = item[i];
|
||||
this._queryOperation.next(child, i, item, false);
|
||||
this.keep = this.keep || this._queryOperation.keep;
|
||||
}
|
||||
this.done = true;
|
||||
}
|
||||
else {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
}
|
||||
};
|
||||
return $ElemMatch;
|
||||
}(BaseOperation));
|
||||
var $Not = /** @class */ (function (_super) {
|
||||
__extends($Not, _super);
|
||||
function $Not() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Not.prototype.init = function () {
|
||||
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
|
||||
};
|
||||
$Not.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this._queryOperation.reset();
|
||||
};
|
||||
$Not.prototype.next = function (item, key, owner, root) {
|
||||
this._queryOperation.next(item, key, owner, root);
|
||||
this.done = this._queryOperation.done;
|
||||
this.keep = !this._queryOperation.keep;
|
||||
};
|
||||
return $Not;
|
||||
}(BaseOperation));
|
||||
var $Size = /** @class */ (function (_super) {
|
||||
__extends($Size, _super);
|
||||
function $Size() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Size.prototype.init = function () { };
|
||||
$Size.prototype.next = function (item) {
|
||||
if (isArray(item) && item.length === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
// if (parent && parent.length === this.params) {
|
||||
// this.done = true;
|
||||
// this.keep = true;
|
||||
// }
|
||||
};
|
||||
return $Size;
|
||||
}(BaseOperation));
|
||||
var assertGroupNotEmpty = function (values) {
|
||||
if (values.length === 0) {
|
||||
throw new Error("$and/$or/$nor must be a nonempty array");
|
||||
}
|
||||
};
|
||||
var $Or = /** @class */ (function (_super) {
|
||||
__extends($Or, _super);
|
||||
function $Or() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = false;
|
||||
return _this;
|
||||
}
|
||||
$Or.prototype.init = function () {
|
||||
var _this = this;
|
||||
assertGroupNotEmpty(this.params);
|
||||
this._ops = this.params.map(function (op) {
|
||||
return createQueryOperation(op, null, _this.options);
|
||||
});
|
||||
};
|
||||
$Or.prototype.reset = function () {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
for (var i = 0, length_2 = this._ops.length; i < length_2; i++) {
|
||||
this._ops[i].reset();
|
||||
}
|
||||
};
|
||||
$Or.prototype.next = function (item, key, owner) {
|
||||
var done = false;
|
||||
var success = false;
|
||||
for (var i = 0, length_3 = this._ops.length; i < length_3; i++) {
|
||||
var op = this._ops[i];
|
||||
op.next(item, key, owner);
|
||||
if (op.keep) {
|
||||
done = true;
|
||||
success = op.keep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
};
|
||||
return $Or;
|
||||
}(BaseOperation));
|
||||
var $Nor = /** @class */ (function (_super) {
|
||||
__extends($Nor, _super);
|
||||
function $Nor() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = false;
|
||||
return _this;
|
||||
}
|
||||
$Nor.prototype.next = function (item, key, owner) {
|
||||
_super.prototype.next.call(this, item, key, owner);
|
||||
this.keep = !this.keep;
|
||||
};
|
||||
return $Nor;
|
||||
}($Or));
|
||||
var $In = /** @class */ (function (_super) {
|
||||
__extends($In, _super);
|
||||
function $In() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$In.prototype.init = function () {
|
||||
var _this = this;
|
||||
this._testers = this.params.map(function (value) {
|
||||
if (containsOperation(value, _this.options)) {
|
||||
throw new Error("cannot nest $ under " + _this.name.toLowerCase());
|
||||
}
|
||||
return createTester(value, _this.options.compare);
|
||||
});
|
||||
};
|
||||
$In.prototype.next = function (item, key, owner) {
|
||||
var done = false;
|
||||
var success = false;
|
||||
for (var i = 0, length_4 = this._testers.length; i < length_4; i++) {
|
||||
var test = this._testers[i];
|
||||
if (test(item)) {
|
||||
done = true;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
};
|
||||
return $In;
|
||||
}(BaseOperation));
|
||||
var $Nin = /** @class */ (function (_super) {
|
||||
__extends($Nin, _super);
|
||||
function $Nin(params, ownerQuery, options, name) {
|
||||
var _this = _super.call(this, params, ownerQuery, options, name) || this;
|
||||
_this.propop = true;
|
||||
_this._in = new $In(params, ownerQuery, options, name);
|
||||
return _this;
|
||||
}
|
||||
$Nin.prototype.next = function (item, key, owner, root) {
|
||||
this._in.next(item, key, owner);
|
||||
if (isArray(owner) && !root) {
|
||||
if (this._in.keep) {
|
||||
this.keep = false;
|
||||
this.done = true;
|
||||
}
|
||||
else if (key == owner.length - 1) {
|
||||
this.keep = true;
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.keep = !this._in.keep;
|
||||
this.done = true;
|
||||
}
|
||||
};
|
||||
$Nin.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this._in.reset();
|
||||
};
|
||||
return $Nin;
|
||||
}(BaseOperation));
|
||||
var $Exists = /** @class */ (function (_super) {
|
||||
__extends($Exists, _super);
|
||||
function $Exists() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Exists.prototype.next = function (item, key, owner) {
|
||||
if (owner.hasOwnProperty(key) === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
};
|
||||
return $Exists;
|
||||
}(BaseOperation));
|
||||
var $And = /** @class */ (function (_super) {
|
||||
__extends($And, _super);
|
||||
function $And(params, owneryQuery, options, name) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, params.map(function (query) { return createQueryOperation(query, owneryQuery, options); }), name) || this;
|
||||
_this.propop = false;
|
||||
assertGroupNotEmpty(params);
|
||||
return _this;
|
||||
}
|
||||
$And.prototype.next = function (item, key, owner, root) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
};
|
||||
return $And;
|
||||
}(NamedGroupOperation));
|
||||
var $All = /** @class */ (function (_super) {
|
||||
__extends($All, _super);
|
||||
function $All(params, owneryQuery, options, name) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, params.map(function (query) { return createQueryOperation(query, owneryQuery, options); }), name) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$All.prototype.next = function (item, key, owner, root) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
};
|
||||
return $All;
|
||||
}(NamedGroupOperation));
|
||||
var $eq = function (params, owneryQuery, options) {
|
||||
return new EqualsOperation(params, owneryQuery, options);
|
||||
};
|
||||
var $ne = function (params, owneryQuery, options, name) { return new $Ne(params, owneryQuery, options, name); };
|
||||
var $or = function (params, owneryQuery, options, name) { return new $Or(params, owneryQuery, options, name); };
|
||||
var $nor = function (params, owneryQuery, options, name) { return new $Nor(params, owneryQuery, options, name); };
|
||||
var $elemMatch = function (params, owneryQuery, options, name) { return new $ElemMatch(params, owneryQuery, options, name); };
|
||||
var $nin = function (params, owneryQuery, options, name) { return new $Nin(params, owneryQuery, options, name); };
|
||||
var $in = function (params, owneryQuery, options, name) {
|
||||
return new $In(params, owneryQuery, options, name);
|
||||
};
|
||||
var $lt = numericalOperation(function (params) { return function (b) { return b < params; }; });
|
||||
var $lte = numericalOperation(function (params) { return function (b) { return b <= params; }; });
|
||||
var $gt = numericalOperation(function (params) { return function (b) { return b > params; }; });
|
||||
var $gte = numericalOperation(function (params) { return function (b) { return b >= params; }; });
|
||||
var $mod = function (_a, owneryQuery, options) {
|
||||
var mod = _a[0], equalsValue = _a[1];
|
||||
return new EqualsOperation(function (b) { return comparable(b) % mod === equalsValue; }, owneryQuery, options);
|
||||
};
|
||||
var $exists = function (params, owneryQuery, options, name) { return new $Exists(params, owneryQuery, options, name); };
|
||||
var $regex = function (pattern, owneryQuery, options) {
|
||||
return new EqualsOperation(new RegExp(pattern, owneryQuery.$options), owneryQuery, options);
|
||||
};
|
||||
var $not = function (params, owneryQuery, options, name) { return new $Not(params, owneryQuery, options, name); };
|
||||
var typeAliases = {
|
||||
number: function (v) { return typeof v === "number"; },
|
||||
string: function (v) { return typeof v === "string"; },
|
||||
bool: function (v) { return typeof v === "boolean"; },
|
||||
array: function (v) { return Array.isArray(v); },
|
||||
null: function (v) { return v === null; },
|
||||
timestamp: function (v) { return v instanceof Date; }
|
||||
};
|
||||
var $type = function (clazz, owneryQuery, options) {
|
||||
return new EqualsOperation(function (b) {
|
||||
if (typeof clazz === "string") {
|
||||
if (!typeAliases[clazz]) {
|
||||
throw new Error("Type alias does not exist");
|
||||
}
|
||||
return typeAliases[clazz](b);
|
||||
}
|
||||
return b != null ? b instanceof clazz || b.constructor === clazz : false;
|
||||
}, owneryQuery, options);
|
||||
};
|
||||
var $and = function (params, ownerQuery, options, name) { return new $And(params, ownerQuery, options, name); };
|
||||
var $all = function (params, ownerQuery, options, name) { return new $All(params, ownerQuery, options, name); };
|
||||
var $size = function (params, ownerQuery, options) { return new $Size(params, ownerQuery, options, "$size"); };
|
||||
var $options = function () { return null; };
|
||||
var $where = function (params, ownerQuery, options) {
|
||||
var test;
|
||||
if (isFunction(params)) {
|
||||
test = params;
|
||||
}
|
||||
else if (!process.env.CSP_ENABLED) {
|
||||
test = new Function("obj", "return " + params);
|
||||
}
|
||||
else {
|
||||
throw new Error("In CSP mode, sift does not support strings in \"$where\" condition");
|
||||
}
|
||||
return new EqualsOperation(function (b) { return test.bind(b)(b); }, ownerQuery, options);
|
||||
};
|
||||
|
||||
var defaultOperations = /*#__PURE__*/Object.freeze({
|
||||
__proto__: null,
|
||||
$Size: $Size,
|
||||
$eq: $eq,
|
||||
$ne: $ne,
|
||||
$or: $or,
|
||||
$nor: $nor,
|
||||
$elemMatch: $elemMatch,
|
||||
$nin: $nin,
|
||||
$in: $in,
|
||||
$lt: $lt,
|
||||
$lte: $lte,
|
||||
$gt: $gt,
|
||||
$gte: $gte,
|
||||
$mod: $mod,
|
||||
$exists: $exists,
|
||||
$regex: $regex,
|
||||
$not: $not,
|
||||
$type: $type,
|
||||
$and: $and,
|
||||
$all: $all,
|
||||
$size: $size,
|
||||
$options: $options,
|
||||
$where: $where
|
||||
});
|
||||
|
||||
var createDefaultQueryOperation = function (query, ownerQuery, _a) {
|
||||
var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
|
||||
return createQueryOperation(query, ownerQuery, {
|
||||
compare: compare,
|
||||
operations: Object.assign({}, defaultOperations, operations || {})
|
||||
});
|
||||
};
|
||||
var createDefaultQueryTester = function (query, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var op = createDefaultQueryOperation(query, null, options);
|
||||
return createOperationTester(op);
|
||||
};
|
||||
|
||||
export default createDefaultQueryTester;
|
||||
export { $Size, $all, $and, $elemMatch, $eq, $exists, $gt, $gte, $in, $lt, $lte, $mod, $ne, $nin, $nor, $not, $options, $or, $regex, $size, $type, $where, EqualsOperation, createDefaultQueryOperation, createEqualsOperation, createOperationTester, createQueryOperation, createQueryTester };
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/sift/es5m/index.js.map
generated
vendored
Normal file
1
node_modules/sift/es5m/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
4
node_modules/sift/index.d.ts
generated
vendored
Normal file
4
node_modules/sift/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
import sift from "./lib";
|
||||
|
||||
export default sift;
|
||||
export * from "./lib";
|
4
node_modules/sift/index.js
generated
vendored
Normal file
4
node_modules/sift/index.js
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
const lib = require("./lib");
|
||||
|
||||
module.exports = lib.default;
|
||||
Object.assign(module.exports, lib);
|
120
node_modules/sift/lib/core.d.ts
generated
vendored
Normal file
120
node_modules/sift/lib/core.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,120 @@
|
|||
import { Key, Comparator } from "./utils";
|
||||
export interface Operation<TItem> {
|
||||
readonly keep: boolean;
|
||||
readonly done: boolean;
|
||||
propop: boolean;
|
||||
reset(): any;
|
||||
next(item: TItem, key?: Key, owner?: any, root?: boolean): any;
|
||||
}
|
||||
export declare type Tester = (item: any, key?: Key, owner?: any, root?: boolean) => boolean;
|
||||
export interface NamedOperation {
|
||||
name: string;
|
||||
}
|
||||
export declare type OperationCreator<TItem> = (params: any, parentQuery: any, options: Options, name: string) => Operation<TItem>;
|
||||
export declare type BasicValueQuery<TValue> = {
|
||||
$eq?: TValue;
|
||||
$ne?: TValue;
|
||||
$lt?: TValue;
|
||||
$gt?: TValue;
|
||||
$lte?: TValue;
|
||||
$gte?: TValue;
|
||||
$in?: TValue[];
|
||||
$nin?: TValue[];
|
||||
$all?: TValue[];
|
||||
$mod?: [number, number];
|
||||
$exists?: boolean;
|
||||
$regex?: string | RegExp;
|
||||
$size?: number;
|
||||
$where?: ((this: TValue, obj: TValue) => boolean) | string;
|
||||
$options?: "i" | "g" | "m" | "u";
|
||||
$type?: Function;
|
||||
$not?: NestedQuery<TValue>;
|
||||
$or?: NestedQuery<TValue>[];
|
||||
$nor?: NestedQuery<TValue>[];
|
||||
$and?: NestedQuery<TValue>[];
|
||||
};
|
||||
export declare type ArrayValueQuery<TValue> = {
|
||||
$elemMatch?: Query<TValue>;
|
||||
} & BasicValueQuery<TValue>;
|
||||
declare type Unpacked<T> = T extends (infer U)[] ? U : T;
|
||||
export declare type ValueQuery<TValue> = TValue extends Array<any> ? ArrayValueQuery<Unpacked<TValue>> : BasicValueQuery<TValue>;
|
||||
declare type NotObject = string | number | Date | boolean | Array<any>;
|
||||
export declare type ShapeQuery<TItemSchema> = TItemSchema extends NotObject ? {} : {
|
||||
[k in keyof TItemSchema]?: TItemSchema[k] | ValueQuery<TItemSchema[k]>;
|
||||
};
|
||||
export declare type NestedQuery<TItemSchema> = ValueQuery<TItemSchema> & ShapeQuery<TItemSchema>;
|
||||
export declare type Query<TItemSchema> = TItemSchema | RegExp | NestedQuery<TItemSchema>;
|
||||
export declare type QueryOperators<TValue = any> = keyof ValueQuery<TValue>;
|
||||
export declare abstract class BaseOperation<TParams, TItem = any> implements Operation<TItem> {
|
||||
readonly params: TParams;
|
||||
readonly owneryQuery: any;
|
||||
readonly options: Options;
|
||||
readonly name?: string;
|
||||
keep: boolean;
|
||||
done: boolean;
|
||||
abstract propop: boolean;
|
||||
constructor(params: TParams, owneryQuery: any, options: Options, name?: string);
|
||||
protected init(): void;
|
||||
reset(): void;
|
||||
abstract next(item: any, key: Key, parent: any, root: boolean): any;
|
||||
}
|
||||
declare abstract class GroupOperation extends BaseOperation<any> {
|
||||
readonly children: Operation<any>[];
|
||||
keep: boolean;
|
||||
done: boolean;
|
||||
constructor(params: any, owneryQuery: any, options: Options, children: Operation<any>[]);
|
||||
/**
|
||||
*/
|
||||
reset(): void;
|
||||
abstract next(item: any, key: Key, owner: any, root: boolean): any;
|
||||
/**
|
||||
*/
|
||||
protected childrenNext(item: any, key: Key, owner: any, root: boolean): void;
|
||||
}
|
||||
export declare abstract class NamedGroupOperation extends GroupOperation implements NamedOperation {
|
||||
readonly name: string;
|
||||
abstract propop: boolean;
|
||||
constructor(params: any, owneryQuery: any, options: Options, children: Operation<any>[], name: string);
|
||||
}
|
||||
export declare class QueryOperation<TItem> extends GroupOperation {
|
||||
readonly propop = true;
|
||||
/**
|
||||
*/
|
||||
next(item: TItem, key: Key, parent: any, root: boolean): void;
|
||||
}
|
||||
export declare class NestedOperation extends GroupOperation {
|
||||
readonly keyPath: Key[];
|
||||
readonly propop = true;
|
||||
constructor(keyPath: Key[], params: any, owneryQuery: any, options: Options, children: Operation<any>[]);
|
||||
/**
|
||||
*/
|
||||
next(item: any, key: Key, parent: any): void;
|
||||
/**
|
||||
*/
|
||||
private _nextNestedValue;
|
||||
}
|
||||
export declare const createTester: (a: any, compare: Comparator) => any;
|
||||
export declare class EqualsOperation<TParam> extends BaseOperation<TParam> {
|
||||
readonly propop = true;
|
||||
private _test;
|
||||
init(): void;
|
||||
next(item: any, key: Key, parent: any): void;
|
||||
}
|
||||
export declare const createEqualsOperation: (params: any, owneryQuery: any, options: Options) => EqualsOperation<any>;
|
||||
export declare class NopeOperation<TParam> extends BaseOperation<TParam> {
|
||||
readonly propop = true;
|
||||
next(): void;
|
||||
}
|
||||
export declare const numericalOperationCreator: (createNumericalOperation: OperationCreator<any>) => (params: any, owneryQuery: any, options: Options, name: string) => Operation<any>;
|
||||
export declare const numericalOperation: (createTester: (any: any) => Tester) => (params: any, owneryQuery: any, options: Options, name: string) => Operation<any>;
|
||||
export declare type Options = {
|
||||
operations: {
|
||||
[identifier: string]: OperationCreator<any>;
|
||||
};
|
||||
compare: (a: any, b: any) => boolean;
|
||||
};
|
||||
export declare const containsOperation: (query: any, options: Options) => boolean;
|
||||
export declare const createQueryOperation: <TItem, TSchema = TItem>(query: Query<TSchema>, owneryQuery?: any, { compare, operations }?: Partial<Options>) => QueryOperation<TItem>;
|
||||
export declare const createOperationTester: <TItem>(operation: Operation<TItem>) => (item: TItem, key?: Key, owner?: any) => boolean;
|
||||
export declare const createQueryTester: <TItem, TSchema = TItem>(query: Query<TSchema>, options?: Partial<Options>) => (item: TItem, key?: Key, owner?: any) => boolean;
|
||||
export {};
|
6
node_modules/sift/lib/index.d.ts
generated
vendored
Normal file
6
node_modules/sift/lib/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { Query, QueryOperators, BasicValueQuery, ArrayValueQuery, ValueQuery, NestedQuery, ShapeQuery, Options, createQueryTester, EqualsOperation, createQueryOperation, createEqualsOperation, createOperationTester } from "./core";
|
||||
declare const createDefaultQueryOperation: <TItem, TSchema extends TItem = TItem>(query: Query<TSchema>, ownerQuery: any, { compare, operations }?: Partial<Options>) => import("./core").QueryOperation<unknown>;
|
||||
declare const createDefaultQueryTester: <TItem, TSchema extends TItem = TItem>(query: Query<TSchema>, options?: Partial<Options>) => (item: unknown, key?: import("./utils").Key, owner?: any) => boolean;
|
||||
export { Query, QueryOperators, BasicValueQuery, ArrayValueQuery, ValueQuery, NestedQuery, ShapeQuery, EqualsOperation, createQueryTester, createOperationTester, createDefaultQueryOperation, createEqualsOperation, createQueryOperation };
|
||||
export * from "./operations";
|
||||
export default createDefaultQueryTester;
|
766
node_modules/sift/lib/index.js
generated
vendored
Normal file
766
node_modules/sift/lib/index.js
generated
vendored
Normal file
|
@ -0,0 +1,766 @@
|
|||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(global = global || self, factory(global.sift = {}));
|
||||
}(this, (function (exports) { 'use strict';
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
***************************************************************************** */
|
||||
/* global Reflect, Promise */
|
||||
|
||||
var extendStatics = function(d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
|
||||
function __extends(d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
}
|
||||
|
||||
var typeChecker = function (type) {
|
||||
var typeString = "[object " + type + "]";
|
||||
return function (value) {
|
||||
return getClassName(value) === typeString;
|
||||
};
|
||||
};
|
||||
var getClassName = function (value) { return Object.prototype.toString.call(value); };
|
||||
var comparable = function (value) {
|
||||
if (value instanceof Date) {
|
||||
return value.getTime();
|
||||
}
|
||||
else if (isArray(value)) {
|
||||
return value.map(comparable);
|
||||
}
|
||||
else if (value && typeof value.toJSON === "function") {
|
||||
return value.toJSON();
|
||||
}
|
||||
return value;
|
||||
};
|
||||
var isArray = typeChecker("Array");
|
||||
var isObject = typeChecker("Object");
|
||||
var isFunction = typeChecker("Function");
|
||||
var isVanillaObject = function (value) {
|
||||
return (value &&
|
||||
(value.constructor === Object ||
|
||||
value.constructor === Array ||
|
||||
value.constructor.toString() === "function Object() { [native code] }" ||
|
||||
value.constructor.toString() === "function Array() { [native code] }") &&
|
||||
!value.toJSON);
|
||||
};
|
||||
var equals = function (a, b) {
|
||||
if (a == null && a == b) {
|
||||
return true;
|
||||
}
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
|
||||
return false;
|
||||
}
|
||||
if (isArray(a)) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0, length_1 = a.length; i < length_1; i++) {
|
||||
if (!equals(a[i], b[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (isObject(a)) {
|
||||
if (Object.keys(a).length !== Object.keys(b).length) {
|
||||
return false;
|
||||
}
|
||||
for (var key in a) {
|
||||
if (!equals(a[key], b[key]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walks through each value given the context - used for nested operations. E.g:
|
||||
* { "person.address": { $eq: "blarg" }}
|
||||
*/
|
||||
var walkKeyPathValues = function (item, keyPath, next, depth, key, owner) {
|
||||
var currentKey = keyPath[depth];
|
||||
// if array, then try matching. Might fall through for cases like:
|
||||
// { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
|
||||
if (isArray(item) && isNaN(Number(currentKey))) {
|
||||
for (var i = 0, length_1 = item.length; i < length_1; i++) {
|
||||
// if FALSE is returned, then terminate walker. For operations, this simply
|
||||
// means that the search critera was met.
|
||||
if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (depth === keyPath.length || item == null) {
|
||||
return next(item, key, owner, depth === 0);
|
||||
}
|
||||
return walkKeyPathValues(item[currentKey], keyPath, next, depth + 1, currentKey, item);
|
||||
};
|
||||
var BaseOperation = /** @class */ (function () {
|
||||
function BaseOperation(params, owneryQuery, options, name) {
|
||||
this.params = params;
|
||||
this.owneryQuery = owneryQuery;
|
||||
this.options = options;
|
||||
this.name = name;
|
||||
this.init();
|
||||
}
|
||||
BaseOperation.prototype.init = function () { };
|
||||
BaseOperation.prototype.reset = function () {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
};
|
||||
return BaseOperation;
|
||||
}());
|
||||
var GroupOperation = /** @class */ (function (_super) {
|
||||
__extends(GroupOperation, _super);
|
||||
function GroupOperation(params, owneryQuery, options, children) {
|
||||
var _this = _super.call(this, params, owneryQuery, options) || this;
|
||||
_this.children = children;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
GroupOperation.prototype.reset = function () {
|
||||
this.keep = false;
|
||||
this.done = false;
|
||||
for (var i = 0, length_2 = this.children.length; i < length_2; i++) {
|
||||
this.children[i].reset();
|
||||
}
|
||||
};
|
||||
/**
|
||||
*/
|
||||
GroupOperation.prototype.childrenNext = function (item, key, owner, root) {
|
||||
var done = true;
|
||||
var keep = true;
|
||||
for (var i = 0, length_3 = this.children.length; i < length_3; i++) {
|
||||
var childOperation = this.children[i];
|
||||
if (!childOperation.done) {
|
||||
childOperation.next(item, key, owner, root);
|
||||
}
|
||||
if (!childOperation.keep) {
|
||||
keep = false;
|
||||
}
|
||||
if (childOperation.done) {
|
||||
if (!childOperation.keep) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
this.done = done;
|
||||
this.keep = keep;
|
||||
};
|
||||
return GroupOperation;
|
||||
}(BaseOperation));
|
||||
var NamedGroupOperation = /** @class */ (function (_super) {
|
||||
__extends(NamedGroupOperation, _super);
|
||||
function NamedGroupOperation(params, owneryQuery, options, children, name) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, children) || this;
|
||||
_this.name = name;
|
||||
return _this;
|
||||
}
|
||||
return NamedGroupOperation;
|
||||
}(GroupOperation));
|
||||
var QueryOperation = /** @class */ (function (_super) {
|
||||
__extends(QueryOperation, _super);
|
||||
function QueryOperation() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
QueryOperation.prototype.next = function (item, key, parent, root) {
|
||||
this.childrenNext(item, key, parent, root);
|
||||
};
|
||||
return QueryOperation;
|
||||
}(GroupOperation));
|
||||
var NestedOperation = /** @class */ (function (_super) {
|
||||
__extends(NestedOperation, _super);
|
||||
function NestedOperation(keyPath, params, owneryQuery, options, children) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, children) || this;
|
||||
_this.keyPath = keyPath;
|
||||
_this.propop = true;
|
||||
/**
|
||||
*/
|
||||
_this._nextNestedValue = function (value, key, owner, root) {
|
||||
_this.childrenNext(value, key, owner, root);
|
||||
return !_this.done;
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
NestedOperation.prototype.next = function (item, key, parent) {
|
||||
walkKeyPathValues(item, this.keyPath, this._nextNestedValue, 0, key, parent);
|
||||
};
|
||||
return NestedOperation;
|
||||
}(GroupOperation));
|
||||
var createTester = function (a, compare) {
|
||||
if (a instanceof Function) {
|
||||
return a;
|
||||
}
|
||||
if (a instanceof RegExp) {
|
||||
return function (b) {
|
||||
var result = typeof b === "string" && a.test(b);
|
||||
a.lastIndex = 0;
|
||||
return result;
|
||||
};
|
||||
}
|
||||
var comparableA = comparable(a);
|
||||
return function (b) { return compare(comparableA, comparable(b)); };
|
||||
};
|
||||
var EqualsOperation = /** @class */ (function (_super) {
|
||||
__extends(EqualsOperation, _super);
|
||||
function EqualsOperation() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
EqualsOperation.prototype.init = function () {
|
||||
this._test = createTester(this.params, this.options.compare);
|
||||
};
|
||||
EqualsOperation.prototype.next = function (item, key, parent) {
|
||||
if (!Array.isArray(parent) || parent.hasOwnProperty(key)) {
|
||||
if (this._test(item, key, parent)) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
return EqualsOperation;
|
||||
}(BaseOperation));
|
||||
var createEqualsOperation = function (params, owneryQuery, options) { return new EqualsOperation(params, owneryQuery, options); };
|
||||
var NopeOperation = /** @class */ (function (_super) {
|
||||
__extends(NopeOperation, _super);
|
||||
function NopeOperation() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
NopeOperation.prototype.next = function () {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
};
|
||||
return NopeOperation;
|
||||
}(BaseOperation));
|
||||
var numericalOperationCreator = function (createNumericalOperation) { return function (params, owneryQuery, options, name) {
|
||||
if (params == null) {
|
||||
return new NopeOperation(params, owneryQuery, options, name);
|
||||
}
|
||||
return createNumericalOperation(params, owneryQuery, options, name);
|
||||
}; };
|
||||
var numericalOperation = function (createTester) {
|
||||
return numericalOperationCreator(function (params, owneryQuery, options, name) {
|
||||
var typeofParams = typeof comparable(params);
|
||||
var test = createTester(params);
|
||||
return new EqualsOperation(function (b) {
|
||||
return typeof comparable(b) === typeofParams && test(b);
|
||||
}, owneryQuery, options, name);
|
||||
});
|
||||
};
|
||||
var createNamedOperation = function (name, params, parentQuery, options) {
|
||||
var operationCreator = options.operations[name];
|
||||
if (!operationCreator) {
|
||||
throwUnsupportedOperation(name);
|
||||
}
|
||||
return operationCreator(params, parentQuery, options, name);
|
||||
};
|
||||
var throwUnsupportedOperation = function (name) {
|
||||
throw new Error("Unsupported operation: " + name);
|
||||
};
|
||||
var containsOperation = function (query, options) {
|
||||
for (var key in query) {
|
||||
if (options.operations.hasOwnProperty(key) || key.charAt(0) === "$")
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
var createNestedOperation = function (keyPath, nestedQuery, parentKey, owneryQuery, options) {
|
||||
if (containsOperation(nestedQuery, options)) {
|
||||
var _a = createQueryOperations(nestedQuery, parentKey, options), selfOperations = _a[0], nestedOperations = _a[1];
|
||||
if (nestedOperations.length) {
|
||||
throw new Error("Property queries must contain only operations, or exact objects.");
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, selfOperations);
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
|
||||
new EqualsOperation(nestedQuery, owneryQuery, options)
|
||||
]);
|
||||
};
|
||||
var createQueryOperation = function (query, owneryQuery, _a) {
|
||||
if (owneryQuery === void 0) { owneryQuery = null; }
|
||||
var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
|
||||
var options = {
|
||||
compare: compare || equals,
|
||||
operations: Object.assign({}, operations || {})
|
||||
};
|
||||
var _c = createQueryOperations(query, null, options), selfOperations = _c[0], nestedOperations = _c[1];
|
||||
var ops = [];
|
||||
if (selfOperations.length) {
|
||||
ops.push(new NestedOperation([], query, owneryQuery, options, selfOperations));
|
||||
}
|
||||
ops.push.apply(ops, nestedOperations);
|
||||
if (ops.length === 1) {
|
||||
return ops[0];
|
||||
}
|
||||
return new QueryOperation(query, owneryQuery, options, ops);
|
||||
};
|
||||
var createQueryOperations = function (query, parentKey, options) {
|
||||
var selfOperations = [];
|
||||
var nestedOperations = [];
|
||||
if (!isVanillaObject(query)) {
|
||||
selfOperations.push(new EqualsOperation(query, query, options));
|
||||
return [selfOperations, nestedOperations];
|
||||
}
|
||||
for (var key in query) {
|
||||
if (options.operations.hasOwnProperty(key)) {
|
||||
var op = createNamedOperation(key, query[key], query, options);
|
||||
if (op) {
|
||||
if (!op.propop && parentKey && !options.operations[parentKey]) {
|
||||
throw new Error("Malformed query. " + key + " cannot be matched against property.");
|
||||
}
|
||||
}
|
||||
// probably just a flag for another operation (like $options)
|
||||
if (op != null) {
|
||||
selfOperations.push(op);
|
||||
}
|
||||
}
|
||||
else if (key.charAt(0) === "$") {
|
||||
throwUnsupportedOperation(key);
|
||||
}
|
||||
else {
|
||||
nestedOperations.push(createNestedOperation(key.split("."), query[key], key, query, options));
|
||||
}
|
||||
}
|
||||
return [selfOperations, nestedOperations];
|
||||
};
|
||||
var createOperationTester = function (operation) { return function (item, key, owner) {
|
||||
operation.reset();
|
||||
operation.next(item, key, owner);
|
||||
return operation.keep;
|
||||
}; };
|
||||
var createQueryTester = function (query, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return createOperationTester(createQueryOperation(query, null, options));
|
||||
};
|
||||
|
||||
var $Ne = /** @class */ (function (_super) {
|
||||
__extends($Ne, _super);
|
||||
function $Ne() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Ne.prototype.init = function () {
|
||||
this._test = createTester(this.params, this.options.compare);
|
||||
};
|
||||
$Ne.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this.keep = true;
|
||||
};
|
||||
$Ne.prototype.next = function (item) {
|
||||
if (this._test(item)) {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
}
|
||||
};
|
||||
return $Ne;
|
||||
}(BaseOperation));
|
||||
// https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
|
||||
var $ElemMatch = /** @class */ (function (_super) {
|
||||
__extends($ElemMatch, _super);
|
||||
function $ElemMatch() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$ElemMatch.prototype.init = function () {
|
||||
if (!this.params || typeof this.params !== "object") {
|
||||
throw new Error("Malformed query. $elemMatch must by an object.");
|
||||
}
|
||||
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
|
||||
};
|
||||
$ElemMatch.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this._queryOperation.reset();
|
||||
};
|
||||
$ElemMatch.prototype.next = function (item) {
|
||||
if (isArray(item)) {
|
||||
for (var i = 0, length_1 = item.length; i < length_1; i++) {
|
||||
// reset query operation since item being tested needs to pass _all_ query
|
||||
// operations for it to be a success
|
||||
this._queryOperation.reset();
|
||||
var child = item[i];
|
||||
this._queryOperation.next(child, i, item, false);
|
||||
this.keep = this.keep || this._queryOperation.keep;
|
||||
}
|
||||
this.done = true;
|
||||
}
|
||||
else {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
}
|
||||
};
|
||||
return $ElemMatch;
|
||||
}(BaseOperation));
|
||||
var $Not = /** @class */ (function (_super) {
|
||||
__extends($Not, _super);
|
||||
function $Not() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Not.prototype.init = function () {
|
||||
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
|
||||
};
|
||||
$Not.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this._queryOperation.reset();
|
||||
};
|
||||
$Not.prototype.next = function (item, key, owner, root) {
|
||||
this._queryOperation.next(item, key, owner, root);
|
||||
this.done = this._queryOperation.done;
|
||||
this.keep = !this._queryOperation.keep;
|
||||
};
|
||||
return $Not;
|
||||
}(BaseOperation));
|
||||
var $Size = /** @class */ (function (_super) {
|
||||
__extends($Size, _super);
|
||||
function $Size() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Size.prototype.init = function () { };
|
||||
$Size.prototype.next = function (item) {
|
||||
if (isArray(item) && item.length === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
// if (parent && parent.length === this.params) {
|
||||
// this.done = true;
|
||||
// this.keep = true;
|
||||
// }
|
||||
};
|
||||
return $Size;
|
||||
}(BaseOperation));
|
||||
var assertGroupNotEmpty = function (values) {
|
||||
if (values.length === 0) {
|
||||
throw new Error("$and/$or/$nor must be a nonempty array");
|
||||
}
|
||||
};
|
||||
var $Or = /** @class */ (function (_super) {
|
||||
__extends($Or, _super);
|
||||
function $Or() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = false;
|
||||
return _this;
|
||||
}
|
||||
$Or.prototype.init = function () {
|
||||
var _this = this;
|
||||
assertGroupNotEmpty(this.params);
|
||||
this._ops = this.params.map(function (op) {
|
||||
return createQueryOperation(op, null, _this.options);
|
||||
});
|
||||
};
|
||||
$Or.prototype.reset = function () {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
for (var i = 0, length_2 = this._ops.length; i < length_2; i++) {
|
||||
this._ops[i].reset();
|
||||
}
|
||||
};
|
||||
$Or.prototype.next = function (item, key, owner) {
|
||||
var done = false;
|
||||
var success = false;
|
||||
for (var i = 0, length_3 = this._ops.length; i < length_3; i++) {
|
||||
var op = this._ops[i];
|
||||
op.next(item, key, owner);
|
||||
if (op.keep) {
|
||||
done = true;
|
||||
success = op.keep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
};
|
||||
return $Or;
|
||||
}(BaseOperation));
|
||||
var $Nor = /** @class */ (function (_super) {
|
||||
__extends($Nor, _super);
|
||||
function $Nor() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = false;
|
||||
return _this;
|
||||
}
|
||||
$Nor.prototype.next = function (item, key, owner) {
|
||||
_super.prototype.next.call(this, item, key, owner);
|
||||
this.keep = !this.keep;
|
||||
};
|
||||
return $Nor;
|
||||
}($Or));
|
||||
var $In = /** @class */ (function (_super) {
|
||||
__extends($In, _super);
|
||||
function $In() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$In.prototype.init = function () {
|
||||
var _this = this;
|
||||
this._testers = this.params.map(function (value) {
|
||||
if (containsOperation(value, _this.options)) {
|
||||
throw new Error("cannot nest $ under " + _this.name.toLowerCase());
|
||||
}
|
||||
return createTester(value, _this.options.compare);
|
||||
});
|
||||
};
|
||||
$In.prototype.next = function (item, key, owner) {
|
||||
var done = false;
|
||||
var success = false;
|
||||
for (var i = 0, length_4 = this._testers.length; i < length_4; i++) {
|
||||
var test = this._testers[i];
|
||||
if (test(item)) {
|
||||
done = true;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
};
|
||||
return $In;
|
||||
}(BaseOperation));
|
||||
var $Nin = /** @class */ (function (_super) {
|
||||
__extends($Nin, _super);
|
||||
function $Nin(params, ownerQuery, options, name) {
|
||||
var _this = _super.call(this, params, ownerQuery, options, name) || this;
|
||||
_this.propop = true;
|
||||
_this._in = new $In(params, ownerQuery, options, name);
|
||||
return _this;
|
||||
}
|
||||
$Nin.prototype.next = function (item, key, owner, root) {
|
||||
this._in.next(item, key, owner);
|
||||
if (isArray(owner) && !root) {
|
||||
if (this._in.keep) {
|
||||
this.keep = false;
|
||||
this.done = true;
|
||||
}
|
||||
else if (key == owner.length - 1) {
|
||||
this.keep = true;
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.keep = !this._in.keep;
|
||||
this.done = true;
|
||||
}
|
||||
};
|
||||
$Nin.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this._in.reset();
|
||||
};
|
||||
return $Nin;
|
||||
}(BaseOperation));
|
||||
var $Exists = /** @class */ (function (_super) {
|
||||
__extends($Exists, _super);
|
||||
function $Exists() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Exists.prototype.next = function (item, key, owner) {
|
||||
if (owner.hasOwnProperty(key) === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
};
|
||||
return $Exists;
|
||||
}(BaseOperation));
|
||||
var $And = /** @class */ (function (_super) {
|
||||
__extends($And, _super);
|
||||
function $And(params, owneryQuery, options, name) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, params.map(function (query) { return createQueryOperation(query, owneryQuery, options); }), name) || this;
|
||||
_this.propop = false;
|
||||
assertGroupNotEmpty(params);
|
||||
return _this;
|
||||
}
|
||||
$And.prototype.next = function (item, key, owner, root) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
};
|
||||
return $And;
|
||||
}(NamedGroupOperation));
|
||||
var $All = /** @class */ (function (_super) {
|
||||
__extends($All, _super);
|
||||
function $All(params, owneryQuery, options, name) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, params.map(function (query) { return createQueryOperation(query, owneryQuery, options); }), name) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$All.prototype.next = function (item, key, owner, root) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
};
|
||||
return $All;
|
||||
}(NamedGroupOperation));
|
||||
var $eq = function (params, owneryQuery, options) {
|
||||
return new EqualsOperation(params, owneryQuery, options);
|
||||
};
|
||||
var $ne = function (params, owneryQuery, options, name) { return new $Ne(params, owneryQuery, options, name); };
|
||||
var $or = function (params, owneryQuery, options, name) { return new $Or(params, owneryQuery, options, name); };
|
||||
var $nor = function (params, owneryQuery, options, name) { return new $Nor(params, owneryQuery, options, name); };
|
||||
var $elemMatch = function (params, owneryQuery, options, name) { return new $ElemMatch(params, owneryQuery, options, name); };
|
||||
var $nin = function (params, owneryQuery, options, name) { return new $Nin(params, owneryQuery, options, name); };
|
||||
var $in = function (params, owneryQuery, options, name) {
|
||||
return new $In(params, owneryQuery, options, name);
|
||||
};
|
||||
var $lt = numericalOperation(function (params) { return function (b) { return b < params; }; });
|
||||
var $lte = numericalOperation(function (params) { return function (b) { return b <= params; }; });
|
||||
var $gt = numericalOperation(function (params) { return function (b) { return b > params; }; });
|
||||
var $gte = numericalOperation(function (params) { return function (b) { return b >= params; }; });
|
||||
var $mod = function (_a, owneryQuery, options) {
|
||||
var mod = _a[0], equalsValue = _a[1];
|
||||
return new EqualsOperation(function (b) { return comparable(b) % mod === equalsValue; }, owneryQuery, options);
|
||||
};
|
||||
var $exists = function (params, owneryQuery, options, name) { return new $Exists(params, owneryQuery, options, name); };
|
||||
var $regex = function (pattern, owneryQuery, options) {
|
||||
return new EqualsOperation(new RegExp(pattern, owneryQuery.$options), owneryQuery, options);
|
||||
};
|
||||
var $not = function (params, owneryQuery, options, name) { return new $Not(params, owneryQuery, options, name); };
|
||||
var typeAliases = {
|
||||
number: function (v) { return typeof v === "number"; },
|
||||
string: function (v) { return typeof v === "string"; },
|
||||
bool: function (v) { return typeof v === "boolean"; },
|
||||
array: function (v) { return Array.isArray(v); },
|
||||
null: function (v) { return v === null; },
|
||||
timestamp: function (v) { return v instanceof Date; }
|
||||
};
|
||||
var $type = function (clazz, owneryQuery, options) {
|
||||
return new EqualsOperation(function (b) {
|
||||
if (typeof clazz === "string") {
|
||||
if (!typeAliases[clazz]) {
|
||||
throw new Error("Type alias does not exist");
|
||||
}
|
||||
return typeAliases[clazz](b);
|
||||
}
|
||||
return b != null ? b instanceof clazz || b.constructor === clazz : false;
|
||||
}, owneryQuery, options);
|
||||
};
|
||||
var $and = function (params, ownerQuery, options, name) { return new $And(params, ownerQuery, options, name); };
|
||||
var $all = function (params, ownerQuery, options, name) { return new $All(params, ownerQuery, options, name); };
|
||||
var $size = function (params, ownerQuery, options) { return new $Size(params, ownerQuery, options, "$size"); };
|
||||
var $options = function () { return null; };
|
||||
var $where = function (params, ownerQuery, options) {
|
||||
var test;
|
||||
if (isFunction(params)) {
|
||||
test = params;
|
||||
}
|
||||
else if (!process.env.CSP_ENABLED) {
|
||||
test = new Function("obj", "return " + params);
|
||||
}
|
||||
else {
|
||||
throw new Error("In CSP mode, sift does not support strings in \"$where\" condition");
|
||||
}
|
||||
return new EqualsOperation(function (b) { return test.bind(b)(b); }, ownerQuery, options);
|
||||
};
|
||||
|
||||
var defaultOperations = /*#__PURE__*/Object.freeze({
|
||||
__proto__: null,
|
||||
$Size: $Size,
|
||||
$eq: $eq,
|
||||
$ne: $ne,
|
||||
$or: $or,
|
||||
$nor: $nor,
|
||||
$elemMatch: $elemMatch,
|
||||
$nin: $nin,
|
||||
$in: $in,
|
||||
$lt: $lt,
|
||||
$lte: $lte,
|
||||
$gt: $gt,
|
||||
$gte: $gte,
|
||||
$mod: $mod,
|
||||
$exists: $exists,
|
||||
$regex: $regex,
|
||||
$not: $not,
|
||||
$type: $type,
|
||||
$and: $and,
|
||||
$all: $all,
|
||||
$size: $size,
|
||||
$options: $options,
|
||||
$where: $where
|
||||
});
|
||||
|
||||
var createDefaultQueryOperation = function (query, ownerQuery, _a) {
|
||||
var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
|
||||
return createQueryOperation(query, ownerQuery, {
|
||||
compare: compare,
|
||||
operations: Object.assign({}, defaultOperations, operations || {})
|
||||
});
|
||||
};
|
||||
var createDefaultQueryTester = function (query, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var op = createDefaultQueryOperation(query, null, options);
|
||||
return createOperationTester(op);
|
||||
};
|
||||
|
||||
exports.$Size = $Size;
|
||||
exports.$all = $all;
|
||||
exports.$and = $and;
|
||||
exports.$elemMatch = $elemMatch;
|
||||
exports.$eq = $eq;
|
||||
exports.$exists = $exists;
|
||||
exports.$gt = $gt;
|
||||
exports.$gte = $gte;
|
||||
exports.$in = $in;
|
||||
exports.$lt = $lt;
|
||||
exports.$lte = $lte;
|
||||
exports.$mod = $mod;
|
||||
exports.$ne = $ne;
|
||||
exports.$nin = $nin;
|
||||
exports.$nor = $nor;
|
||||
exports.$not = $not;
|
||||
exports.$options = $options;
|
||||
exports.$or = $or;
|
||||
exports.$regex = $regex;
|
||||
exports.$size = $size;
|
||||
exports.$type = $type;
|
||||
exports.$where = $where;
|
||||
exports.EqualsOperation = EqualsOperation;
|
||||
exports.createDefaultQueryOperation = createDefaultQueryOperation;
|
||||
exports.createEqualsOperation = createEqualsOperation;
|
||||
exports.createOperationTester = createOperationTester;
|
||||
exports.createQueryOperation = createQueryOperation;
|
||||
exports.createQueryTester = createQueryTester;
|
||||
exports.default = createDefaultQueryTester;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
})));
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/sift/lib/index.js.map
generated
vendored
Normal file
1
node_modules/sift/lib/index.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
88
node_modules/sift/lib/operations.d.ts
generated
vendored
Normal file
88
node_modules/sift/lib/operations.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
import { BaseOperation, EqualsOperation, Options, Operation, Query, NamedGroupOperation } from "./core";
|
||||
import { Key } from "./utils";
|
||||
declare class $Ne extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
private _test;
|
||||
init(): void;
|
||||
reset(): void;
|
||||
next(item: any): void;
|
||||
}
|
||||
declare class $ElemMatch extends BaseOperation<Query<any>> {
|
||||
readonly propop = true;
|
||||
private _queryOperation;
|
||||
init(): void;
|
||||
reset(): void;
|
||||
next(item: any): void;
|
||||
}
|
||||
declare class $Not extends BaseOperation<Query<any>> {
|
||||
readonly propop = true;
|
||||
private _queryOperation;
|
||||
init(): void;
|
||||
reset(): void;
|
||||
next(item: any, key: Key, owner: any, root: boolean): void;
|
||||
}
|
||||
export declare class $Size extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
init(): void;
|
||||
next(item: any): void;
|
||||
}
|
||||
declare class $Or extends BaseOperation<any> {
|
||||
readonly propop = false;
|
||||
private _ops;
|
||||
init(): void;
|
||||
reset(): void;
|
||||
next(item: any, key: Key, owner: any): void;
|
||||
}
|
||||
declare class $Nor extends $Or {
|
||||
readonly propop = false;
|
||||
next(item: any, key: Key, owner: any): void;
|
||||
}
|
||||
declare class $In extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
private _testers;
|
||||
init(): void;
|
||||
next(item: any, key: Key, owner: any): void;
|
||||
}
|
||||
declare class $Nin extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
private _in;
|
||||
constructor(params: any, ownerQuery: any, options: Options, name: string);
|
||||
next(item: any, key: Key, owner: any, root: boolean): void;
|
||||
reset(): void;
|
||||
}
|
||||
declare class $Exists extends BaseOperation<boolean> {
|
||||
readonly propop = true;
|
||||
next(item: any, key: Key, owner: any): void;
|
||||
}
|
||||
declare class $And extends NamedGroupOperation {
|
||||
readonly propop = false;
|
||||
constructor(params: Query<any>[], owneryQuery: Query<any>, options: Options, name: string);
|
||||
next(item: any, key: Key, owner: any, root: boolean): void;
|
||||
}
|
||||
declare class $All extends NamedGroupOperation {
|
||||
readonly propop = true;
|
||||
constructor(params: Query<any>[], owneryQuery: Query<any>, options: Options, name: string);
|
||||
next(item: any, key: Key, owner: any, root: boolean): void;
|
||||
}
|
||||
export declare const $eq: (params: any, owneryQuery: Query<any>, options: Options) => EqualsOperation<any>;
|
||||
export declare const $ne: (params: any, owneryQuery: Query<any>, options: Options, name: string) => $Ne;
|
||||
export declare const $or: (params: Query<any>[], owneryQuery: Query<any>, options: Options, name: string) => $Or;
|
||||
export declare const $nor: (params: Query<any>[], owneryQuery: Query<any>, options: Options, name: string) => $Nor;
|
||||
export declare const $elemMatch: (params: any, owneryQuery: Query<any>, options: Options, name: string) => $ElemMatch;
|
||||
export declare const $nin: (params: any, owneryQuery: Query<any>, options: Options, name: string) => $Nin;
|
||||
export declare const $in: (params: any, owneryQuery: Query<any>, options: Options, name: string) => $In;
|
||||
export declare const $lt: (params: any, owneryQuery: any, options: Options, name: string) => Operation<any>;
|
||||
export declare const $lte: (params: any, owneryQuery: any, options: Options, name: string) => Operation<any>;
|
||||
export declare const $gt: (params: any, owneryQuery: any, options: Options, name: string) => Operation<any>;
|
||||
export declare const $gte: (params: any, owneryQuery: any, options: Options, name: string) => Operation<any>;
|
||||
export declare const $mod: ([mod, equalsValue]: number[], owneryQuery: Query<any>, options: Options) => EqualsOperation<(b: any) => boolean>;
|
||||
export declare const $exists: (params: boolean, owneryQuery: Query<any>, options: Options, name: string) => $Exists;
|
||||
export declare const $regex: (pattern: string, owneryQuery: Query<any>, options: Options) => EqualsOperation<RegExp>;
|
||||
export declare const $not: (params: any, owneryQuery: Query<any>, options: Options, name: string) => $Not;
|
||||
export declare const $type: (clazz: Function | string, owneryQuery: Query<any>, options: Options) => EqualsOperation<(b: any) => any>;
|
||||
export declare const $and: (params: Query<any>[], ownerQuery: Query<any>, options: Options, name: string) => $And;
|
||||
export declare const $all: (params: Query<any>[], ownerQuery: Query<any>, options: Options, name: string) => $All;
|
||||
export declare const $size: (params: number, ownerQuery: Query<any>, options: Options) => $Size;
|
||||
export declare const $options: () => any;
|
||||
export declare const $where: (params: string | Function, ownerQuery: Query<any>, options: Options) => EqualsOperation<(b: any) => any>;
|
||||
export {};
|
9
node_modules/sift/lib/utils.d.ts
generated
vendored
Normal file
9
node_modules/sift/lib/utils.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
export declare type Key = string | number;
|
||||
export declare type Comparator = (a: any, b: any) => boolean;
|
||||
export declare const typeChecker: <TType>(type: any) => (value: any) => value is TType;
|
||||
export declare const comparable: (value: any) => any;
|
||||
export declare const isArray: (value: any) => value is any[];
|
||||
export declare const isObject: (value: any) => value is Object;
|
||||
export declare const isFunction: (value: any) => value is Function;
|
||||
export declare const isVanillaObject: (value: any) => boolean;
|
||||
export declare const equals: (a: any, b: any) => boolean;
|
62
node_modules/sift/package.json
generated
vendored
Normal file
62
node_modules/sift/package.json
generated
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
{
|
||||
"name": "sift",
|
||||
"description": "MongoDB query filtering in JavaScript",
|
||||
"version": "16.0.1",
|
||||
"repository": "crcn/sift.js",
|
||||
"sideEffects": false,
|
||||
"author": {
|
||||
"name": "Craig Condon",
|
||||
"email": "craig.j.condon@gmail.com"
|
||||
},
|
||||
"license": "MIT",
|
||||
"engines": {},
|
||||
"typings": "./index.d.ts",
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "pretty-quick --staged"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-replace": "^2.3.2",
|
||||
"@rollup/plugin-typescript": "8.2.1",
|
||||
"@types/node": "^13.7.0",
|
||||
"bson": "^4.0.3",
|
||||
"eval": "^0.1.4",
|
||||
"husky": "^1.2.1",
|
||||
"immutable": "^3.7.6",
|
||||
"mocha": "8.3.2",
|
||||
"mongodb": "^3.6.6",
|
||||
"prettier": "1.15.3",
|
||||
"pretty-quick": "^1.11.1",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "^2.7.2",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"tslib": "2.2.0",
|
||||
"typescript": "4.2.4"
|
||||
},
|
||||
"main": "./index.js",
|
||||
"module": "./es5m/index.js",
|
||||
"es2015": "./es/index.js",
|
||||
"scripts": {
|
||||
"clean": "rimraf lib es5m es",
|
||||
"prebuild": "npm run clean && npm run build:types",
|
||||
"build": "rollup -c",
|
||||
"build:types": "tsc -p tsconfig.json --emitDeclarationOnly --outDir lib",
|
||||
"test": "npm run test:spec && npm run test:types",
|
||||
"test:spec": "mocha ./test -R spec",
|
||||
"test:types": "cd test && tsc types.ts --noEmit",
|
||||
"prepublishOnly": "npm run build && npm run test"
|
||||
},
|
||||
"files": [
|
||||
"es",
|
||||
"es5m",
|
||||
"lib",
|
||||
"src",
|
||||
"*.d.ts",
|
||||
"*.js.map",
|
||||
"index.js",
|
||||
"sift.csp.min.js",
|
||||
"sift.min.js",
|
||||
"MIT-LICENSE.txt"
|
||||
]
|
||||
}
|
763
node_modules/sift/sift.csp.min.js
generated
vendored
Normal file
763
node_modules/sift/sift.csp.min.js
generated
vendored
Normal file
|
@ -0,0 +1,763 @@
|
|||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
||||
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
||||
(global = global || self, factory(global.sift = {}));
|
||||
}(this, (function (exports) { 'use strict';
|
||||
|
||||
/*! *****************************************************************************
|
||||
Copyright (c) Microsoft Corporation.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
PERFORMANCE OF THIS SOFTWARE.
|
||||
***************************************************************************** */
|
||||
/* global Reflect, Promise */
|
||||
|
||||
var extendStatics = function(d, b) {
|
||||
extendStatics = Object.setPrototypeOf ||
|
||||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
||||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
||||
return extendStatics(d, b);
|
||||
};
|
||||
|
||||
function __extends(d, b) {
|
||||
if (typeof b !== "function" && b !== null)
|
||||
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
||||
extendStatics(d, b);
|
||||
function __() { this.constructor = d; }
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
}
|
||||
|
||||
var typeChecker = function (type) {
|
||||
var typeString = "[object " + type + "]";
|
||||
return function (value) {
|
||||
return getClassName(value) === typeString;
|
||||
};
|
||||
};
|
||||
var getClassName = function (value) { return Object.prototype.toString.call(value); };
|
||||
var comparable = function (value) {
|
||||
if (value instanceof Date) {
|
||||
return value.getTime();
|
||||
}
|
||||
else if (isArray(value)) {
|
||||
return value.map(comparable);
|
||||
}
|
||||
else if (value && typeof value.toJSON === "function") {
|
||||
return value.toJSON();
|
||||
}
|
||||
return value;
|
||||
};
|
||||
var isArray = typeChecker("Array");
|
||||
var isObject = typeChecker("Object");
|
||||
var isFunction = typeChecker("Function");
|
||||
var isVanillaObject = function (value) {
|
||||
return (value &&
|
||||
(value.constructor === Object ||
|
||||
value.constructor === Array ||
|
||||
value.constructor.toString() === "function Object() { [native code] }" ||
|
||||
value.constructor.toString() === "function Array() { [native code] }") &&
|
||||
!value.toJSON);
|
||||
};
|
||||
var equals = function (a, b) {
|
||||
if (a == null && a == b) {
|
||||
return true;
|
||||
}
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
|
||||
return false;
|
||||
}
|
||||
if (isArray(a)) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (var i = 0, length_1 = a.length; i < length_1; i++) {
|
||||
if (!equals(a[i], b[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (isObject(a)) {
|
||||
if (Object.keys(a).length !== Object.keys(b).length) {
|
||||
return false;
|
||||
}
|
||||
for (var key in a) {
|
||||
if (!equals(a[key], b[key]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* Walks through each value given the context - used for nested operations. E.g:
|
||||
* { "person.address": { $eq: "blarg" }}
|
||||
*/
|
||||
var walkKeyPathValues = function (item, keyPath, next, depth, key, owner) {
|
||||
var currentKey = keyPath[depth];
|
||||
// if array, then try matching. Might fall through for cases like:
|
||||
// { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
|
||||
if (isArray(item) && isNaN(Number(currentKey))) {
|
||||
for (var i = 0, length_1 = item.length; i < length_1; i++) {
|
||||
// if FALSE is returned, then terminate walker. For operations, this simply
|
||||
// means that the search critera was met.
|
||||
if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (depth === keyPath.length || item == null) {
|
||||
return next(item, key, owner, depth === 0);
|
||||
}
|
||||
return walkKeyPathValues(item[currentKey], keyPath, next, depth + 1, currentKey, item);
|
||||
};
|
||||
var BaseOperation = /** @class */ (function () {
|
||||
function BaseOperation(params, owneryQuery, options, name) {
|
||||
this.params = params;
|
||||
this.owneryQuery = owneryQuery;
|
||||
this.options = options;
|
||||
this.name = name;
|
||||
this.init();
|
||||
}
|
||||
BaseOperation.prototype.init = function () { };
|
||||
BaseOperation.prototype.reset = function () {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
};
|
||||
return BaseOperation;
|
||||
}());
|
||||
var GroupOperation = /** @class */ (function (_super) {
|
||||
__extends(GroupOperation, _super);
|
||||
function GroupOperation(params, owneryQuery, options, children) {
|
||||
var _this = _super.call(this, params, owneryQuery, options) || this;
|
||||
_this.children = children;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
GroupOperation.prototype.reset = function () {
|
||||
this.keep = false;
|
||||
this.done = false;
|
||||
for (var i = 0, length_2 = this.children.length; i < length_2; i++) {
|
||||
this.children[i].reset();
|
||||
}
|
||||
};
|
||||
/**
|
||||
*/
|
||||
GroupOperation.prototype.childrenNext = function (item, key, owner, root) {
|
||||
var done = true;
|
||||
var keep = true;
|
||||
for (var i = 0, length_3 = this.children.length; i < length_3; i++) {
|
||||
var childOperation = this.children[i];
|
||||
if (!childOperation.done) {
|
||||
childOperation.next(item, key, owner, root);
|
||||
}
|
||||
if (!childOperation.keep) {
|
||||
keep = false;
|
||||
}
|
||||
if (childOperation.done) {
|
||||
if (!childOperation.keep) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
this.done = done;
|
||||
this.keep = keep;
|
||||
};
|
||||
return GroupOperation;
|
||||
}(BaseOperation));
|
||||
var NamedGroupOperation = /** @class */ (function (_super) {
|
||||
__extends(NamedGroupOperation, _super);
|
||||
function NamedGroupOperation(params, owneryQuery, options, children, name) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, children) || this;
|
||||
_this.name = name;
|
||||
return _this;
|
||||
}
|
||||
return NamedGroupOperation;
|
||||
}(GroupOperation));
|
||||
var QueryOperation = /** @class */ (function (_super) {
|
||||
__extends(QueryOperation, _super);
|
||||
function QueryOperation() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
QueryOperation.prototype.next = function (item, key, parent, root) {
|
||||
this.childrenNext(item, key, parent, root);
|
||||
};
|
||||
return QueryOperation;
|
||||
}(GroupOperation));
|
||||
var NestedOperation = /** @class */ (function (_super) {
|
||||
__extends(NestedOperation, _super);
|
||||
function NestedOperation(keyPath, params, owneryQuery, options, children) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, children) || this;
|
||||
_this.keyPath = keyPath;
|
||||
_this.propop = true;
|
||||
/**
|
||||
*/
|
||||
_this._nextNestedValue = function (value, key, owner, root) {
|
||||
_this.childrenNext(value, key, owner, root);
|
||||
return !_this.done;
|
||||
};
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
NestedOperation.prototype.next = function (item, key, parent) {
|
||||
walkKeyPathValues(item, this.keyPath, this._nextNestedValue, 0, key, parent);
|
||||
};
|
||||
return NestedOperation;
|
||||
}(GroupOperation));
|
||||
var createTester = function (a, compare) {
|
||||
if (a instanceof Function) {
|
||||
return a;
|
||||
}
|
||||
if (a instanceof RegExp) {
|
||||
return function (b) {
|
||||
var result = typeof b === "string" && a.test(b);
|
||||
a.lastIndex = 0;
|
||||
return result;
|
||||
};
|
||||
}
|
||||
var comparableA = comparable(a);
|
||||
return function (b) { return compare(comparableA, comparable(b)); };
|
||||
};
|
||||
var EqualsOperation = /** @class */ (function (_super) {
|
||||
__extends(EqualsOperation, _super);
|
||||
function EqualsOperation() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
EqualsOperation.prototype.init = function () {
|
||||
this._test = createTester(this.params, this.options.compare);
|
||||
};
|
||||
EqualsOperation.prototype.next = function (item, key, parent) {
|
||||
if (!Array.isArray(parent) || parent.hasOwnProperty(key)) {
|
||||
if (this._test(item, key, parent)) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
return EqualsOperation;
|
||||
}(BaseOperation));
|
||||
var createEqualsOperation = function (params, owneryQuery, options) { return new EqualsOperation(params, owneryQuery, options); };
|
||||
var NopeOperation = /** @class */ (function (_super) {
|
||||
__extends(NopeOperation, _super);
|
||||
function NopeOperation() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
NopeOperation.prototype.next = function () {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
};
|
||||
return NopeOperation;
|
||||
}(BaseOperation));
|
||||
var numericalOperationCreator = function (createNumericalOperation) { return function (params, owneryQuery, options, name) {
|
||||
if (params == null) {
|
||||
return new NopeOperation(params, owneryQuery, options, name);
|
||||
}
|
||||
return createNumericalOperation(params, owneryQuery, options, name);
|
||||
}; };
|
||||
var numericalOperation = function (createTester) {
|
||||
return numericalOperationCreator(function (params, owneryQuery, options, name) {
|
||||
var typeofParams = typeof comparable(params);
|
||||
var test = createTester(params);
|
||||
return new EqualsOperation(function (b) {
|
||||
return typeof comparable(b) === typeofParams && test(b);
|
||||
}, owneryQuery, options, name);
|
||||
});
|
||||
};
|
||||
var createNamedOperation = function (name, params, parentQuery, options) {
|
||||
var operationCreator = options.operations[name];
|
||||
if (!operationCreator) {
|
||||
throwUnsupportedOperation(name);
|
||||
}
|
||||
return operationCreator(params, parentQuery, options, name);
|
||||
};
|
||||
var throwUnsupportedOperation = function (name) {
|
||||
throw new Error("Unsupported operation: " + name);
|
||||
};
|
||||
var containsOperation = function (query, options) {
|
||||
for (var key in query) {
|
||||
if (options.operations.hasOwnProperty(key) || key.charAt(0) === "$")
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
var createNestedOperation = function (keyPath, nestedQuery, parentKey, owneryQuery, options) {
|
||||
if (containsOperation(nestedQuery, options)) {
|
||||
var _a = createQueryOperations(nestedQuery, parentKey, options), selfOperations = _a[0], nestedOperations = _a[1];
|
||||
if (nestedOperations.length) {
|
||||
throw new Error("Property queries must contain only operations, or exact objects.");
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, selfOperations);
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
|
||||
new EqualsOperation(nestedQuery, owneryQuery, options)
|
||||
]);
|
||||
};
|
||||
var createQueryOperation = function (query, owneryQuery, _a) {
|
||||
if (owneryQuery === void 0) { owneryQuery = null; }
|
||||
var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
|
||||
var options = {
|
||||
compare: compare || equals,
|
||||
operations: Object.assign({}, operations || {})
|
||||
};
|
||||
var _c = createQueryOperations(query, null, options), selfOperations = _c[0], nestedOperations = _c[1];
|
||||
var ops = [];
|
||||
if (selfOperations.length) {
|
||||
ops.push(new NestedOperation([], query, owneryQuery, options, selfOperations));
|
||||
}
|
||||
ops.push.apply(ops, nestedOperations);
|
||||
if (ops.length === 1) {
|
||||
return ops[0];
|
||||
}
|
||||
return new QueryOperation(query, owneryQuery, options, ops);
|
||||
};
|
||||
var createQueryOperations = function (query, parentKey, options) {
|
||||
var selfOperations = [];
|
||||
var nestedOperations = [];
|
||||
if (!isVanillaObject(query)) {
|
||||
selfOperations.push(new EqualsOperation(query, query, options));
|
||||
return [selfOperations, nestedOperations];
|
||||
}
|
||||
for (var key in query) {
|
||||
if (options.operations.hasOwnProperty(key)) {
|
||||
var op = createNamedOperation(key, query[key], query, options);
|
||||
if (op) {
|
||||
if (!op.propop && parentKey && !options.operations[parentKey]) {
|
||||
throw new Error("Malformed query. " + key + " cannot be matched against property.");
|
||||
}
|
||||
}
|
||||
// probably just a flag for another operation (like $options)
|
||||
if (op != null) {
|
||||
selfOperations.push(op);
|
||||
}
|
||||
}
|
||||
else if (key.charAt(0) === "$") {
|
||||
throwUnsupportedOperation(key);
|
||||
}
|
||||
else {
|
||||
nestedOperations.push(createNestedOperation(key.split("."), query[key], key, query, options));
|
||||
}
|
||||
}
|
||||
return [selfOperations, nestedOperations];
|
||||
};
|
||||
var createOperationTester = function (operation) { return function (item, key, owner) {
|
||||
operation.reset();
|
||||
operation.next(item, key, owner);
|
||||
return operation.keep;
|
||||
}; };
|
||||
var createQueryTester = function (query, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
return createOperationTester(createQueryOperation(query, null, options));
|
||||
};
|
||||
|
||||
var $Ne = /** @class */ (function (_super) {
|
||||
__extends($Ne, _super);
|
||||
function $Ne() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Ne.prototype.init = function () {
|
||||
this._test = createTester(this.params, this.options.compare);
|
||||
};
|
||||
$Ne.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this.keep = true;
|
||||
};
|
||||
$Ne.prototype.next = function (item) {
|
||||
if (this._test(item)) {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
}
|
||||
};
|
||||
return $Ne;
|
||||
}(BaseOperation));
|
||||
// https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
|
||||
var $ElemMatch = /** @class */ (function (_super) {
|
||||
__extends($ElemMatch, _super);
|
||||
function $ElemMatch() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$ElemMatch.prototype.init = function () {
|
||||
if (!this.params || typeof this.params !== "object") {
|
||||
throw new Error("Malformed query. $elemMatch must by an object.");
|
||||
}
|
||||
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
|
||||
};
|
||||
$ElemMatch.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this._queryOperation.reset();
|
||||
};
|
||||
$ElemMatch.prototype.next = function (item) {
|
||||
if (isArray(item)) {
|
||||
for (var i = 0, length_1 = item.length; i < length_1; i++) {
|
||||
// reset query operation since item being tested needs to pass _all_ query
|
||||
// operations for it to be a success
|
||||
this._queryOperation.reset();
|
||||
var child = item[i];
|
||||
this._queryOperation.next(child, i, item, false);
|
||||
this.keep = this.keep || this._queryOperation.keep;
|
||||
}
|
||||
this.done = true;
|
||||
}
|
||||
else {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
}
|
||||
};
|
||||
return $ElemMatch;
|
||||
}(BaseOperation));
|
||||
var $Not = /** @class */ (function (_super) {
|
||||
__extends($Not, _super);
|
||||
function $Not() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Not.prototype.init = function () {
|
||||
this._queryOperation = createQueryOperation(this.params, this.owneryQuery, this.options);
|
||||
};
|
||||
$Not.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this._queryOperation.reset();
|
||||
};
|
||||
$Not.prototype.next = function (item, key, owner, root) {
|
||||
this._queryOperation.next(item, key, owner, root);
|
||||
this.done = this._queryOperation.done;
|
||||
this.keep = !this._queryOperation.keep;
|
||||
};
|
||||
return $Not;
|
||||
}(BaseOperation));
|
||||
var $Size = /** @class */ (function (_super) {
|
||||
__extends($Size, _super);
|
||||
function $Size() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Size.prototype.init = function () { };
|
||||
$Size.prototype.next = function (item) {
|
||||
if (isArray(item) && item.length === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
// if (parent && parent.length === this.params) {
|
||||
// this.done = true;
|
||||
// this.keep = true;
|
||||
// }
|
||||
};
|
||||
return $Size;
|
||||
}(BaseOperation));
|
||||
var assertGroupNotEmpty = function (values) {
|
||||
if (values.length === 0) {
|
||||
throw new Error("$and/$or/$nor must be a nonempty array");
|
||||
}
|
||||
};
|
||||
var $Or = /** @class */ (function (_super) {
|
||||
__extends($Or, _super);
|
||||
function $Or() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = false;
|
||||
return _this;
|
||||
}
|
||||
$Or.prototype.init = function () {
|
||||
var _this = this;
|
||||
assertGroupNotEmpty(this.params);
|
||||
this._ops = this.params.map(function (op) {
|
||||
return createQueryOperation(op, null, _this.options);
|
||||
});
|
||||
};
|
||||
$Or.prototype.reset = function () {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
for (var i = 0, length_2 = this._ops.length; i < length_2; i++) {
|
||||
this._ops[i].reset();
|
||||
}
|
||||
};
|
||||
$Or.prototype.next = function (item, key, owner) {
|
||||
var done = false;
|
||||
var success = false;
|
||||
for (var i = 0, length_3 = this._ops.length; i < length_3; i++) {
|
||||
var op = this._ops[i];
|
||||
op.next(item, key, owner);
|
||||
if (op.keep) {
|
||||
done = true;
|
||||
success = op.keep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
};
|
||||
return $Or;
|
||||
}(BaseOperation));
|
||||
var $Nor = /** @class */ (function (_super) {
|
||||
__extends($Nor, _super);
|
||||
function $Nor() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = false;
|
||||
return _this;
|
||||
}
|
||||
$Nor.prototype.next = function (item, key, owner) {
|
||||
_super.prototype.next.call(this, item, key, owner);
|
||||
this.keep = !this.keep;
|
||||
};
|
||||
return $Nor;
|
||||
}($Or));
|
||||
var $In = /** @class */ (function (_super) {
|
||||
__extends($In, _super);
|
||||
function $In() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$In.prototype.init = function () {
|
||||
var _this = this;
|
||||
this._testers = this.params.map(function (value) {
|
||||
if (containsOperation(value, _this.options)) {
|
||||
throw new Error("cannot nest $ under " + _this.name.toLowerCase());
|
||||
}
|
||||
return createTester(value, _this.options.compare);
|
||||
});
|
||||
};
|
||||
$In.prototype.next = function (item, key, owner) {
|
||||
var done = false;
|
||||
var success = false;
|
||||
for (var i = 0, length_4 = this._testers.length; i < length_4; i++) {
|
||||
var test = this._testers[i];
|
||||
if (test(item)) {
|
||||
done = true;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
};
|
||||
return $In;
|
||||
}(BaseOperation));
|
||||
var $Nin = /** @class */ (function (_super) {
|
||||
__extends($Nin, _super);
|
||||
function $Nin(params, ownerQuery, options, name) {
|
||||
var _this = _super.call(this, params, ownerQuery, options, name) || this;
|
||||
_this.propop = true;
|
||||
_this._in = new $In(params, ownerQuery, options, name);
|
||||
return _this;
|
||||
}
|
||||
$Nin.prototype.next = function (item, key, owner, root) {
|
||||
this._in.next(item, key, owner);
|
||||
if (isArray(owner) && !root) {
|
||||
if (this._in.keep) {
|
||||
this.keep = false;
|
||||
this.done = true;
|
||||
}
|
||||
else if (key == owner.length - 1) {
|
||||
this.keep = true;
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.keep = !this._in.keep;
|
||||
this.done = true;
|
||||
}
|
||||
};
|
||||
$Nin.prototype.reset = function () {
|
||||
_super.prototype.reset.call(this);
|
||||
this._in.reset();
|
||||
};
|
||||
return $Nin;
|
||||
}(BaseOperation));
|
||||
var $Exists = /** @class */ (function (_super) {
|
||||
__extends($Exists, _super);
|
||||
function $Exists() {
|
||||
var _this = _super !== null && _super.apply(this, arguments) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$Exists.prototype.next = function (item, key, owner) {
|
||||
if (owner.hasOwnProperty(key) === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
};
|
||||
return $Exists;
|
||||
}(BaseOperation));
|
||||
var $And = /** @class */ (function (_super) {
|
||||
__extends($And, _super);
|
||||
function $And(params, owneryQuery, options, name) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, params.map(function (query) { return createQueryOperation(query, owneryQuery, options); }), name) || this;
|
||||
_this.propop = false;
|
||||
assertGroupNotEmpty(params);
|
||||
return _this;
|
||||
}
|
||||
$And.prototype.next = function (item, key, owner, root) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
};
|
||||
return $And;
|
||||
}(NamedGroupOperation));
|
||||
var $All = /** @class */ (function (_super) {
|
||||
__extends($All, _super);
|
||||
function $All(params, owneryQuery, options, name) {
|
||||
var _this = _super.call(this, params, owneryQuery, options, params.map(function (query) { return createQueryOperation(query, owneryQuery, options); }), name) || this;
|
||||
_this.propop = true;
|
||||
return _this;
|
||||
}
|
||||
$All.prototype.next = function (item, key, owner, root) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
};
|
||||
return $All;
|
||||
}(NamedGroupOperation));
|
||||
var $eq = function (params, owneryQuery, options) {
|
||||
return new EqualsOperation(params, owneryQuery, options);
|
||||
};
|
||||
var $ne = function (params, owneryQuery, options, name) { return new $Ne(params, owneryQuery, options, name); };
|
||||
var $or = function (params, owneryQuery, options, name) { return new $Or(params, owneryQuery, options, name); };
|
||||
var $nor = function (params, owneryQuery, options, name) { return new $Nor(params, owneryQuery, options, name); };
|
||||
var $elemMatch = function (params, owneryQuery, options, name) { return new $ElemMatch(params, owneryQuery, options, name); };
|
||||
var $nin = function (params, owneryQuery, options, name) { return new $Nin(params, owneryQuery, options, name); };
|
||||
var $in = function (params, owneryQuery, options, name) {
|
||||
return new $In(params, owneryQuery, options, name);
|
||||
};
|
||||
var $lt = numericalOperation(function (params) { return function (b) { return b < params; }; });
|
||||
var $lte = numericalOperation(function (params) { return function (b) { return b <= params; }; });
|
||||
var $gt = numericalOperation(function (params) { return function (b) { return b > params; }; });
|
||||
var $gte = numericalOperation(function (params) { return function (b) { return b >= params; }; });
|
||||
var $mod = function (_a, owneryQuery, options) {
|
||||
var mod = _a[0], equalsValue = _a[1];
|
||||
return new EqualsOperation(function (b) { return comparable(b) % mod === equalsValue; }, owneryQuery, options);
|
||||
};
|
||||
var $exists = function (params, owneryQuery, options, name) { return new $Exists(params, owneryQuery, options, name); };
|
||||
var $regex = function (pattern, owneryQuery, options) {
|
||||
return new EqualsOperation(new RegExp(pattern, owneryQuery.$options), owneryQuery, options);
|
||||
};
|
||||
var $not = function (params, owneryQuery, options, name) { return new $Not(params, owneryQuery, options, name); };
|
||||
var typeAliases = {
|
||||
number: function (v) { return typeof v === "number"; },
|
||||
string: function (v) { return typeof v === "string"; },
|
||||
bool: function (v) { return typeof v === "boolean"; },
|
||||
array: function (v) { return Array.isArray(v); },
|
||||
null: function (v) { return v === null; },
|
||||
timestamp: function (v) { return v instanceof Date; }
|
||||
};
|
||||
var $type = function (clazz, owneryQuery, options) {
|
||||
return new EqualsOperation(function (b) {
|
||||
if (typeof clazz === "string") {
|
||||
if (!typeAliases[clazz]) {
|
||||
throw new Error("Type alias does not exist");
|
||||
}
|
||||
return typeAliases[clazz](b);
|
||||
}
|
||||
return b != null ? b instanceof clazz || b.constructor === clazz : false;
|
||||
}, owneryQuery, options);
|
||||
};
|
||||
var $and = function (params, ownerQuery, options, name) { return new $And(params, ownerQuery, options, name); };
|
||||
var $all = function (params, ownerQuery, options, name) { return new $All(params, ownerQuery, options, name); };
|
||||
var $size = function (params, ownerQuery, options) { return new $Size(params, ownerQuery, options, "$size"); };
|
||||
var $options = function () { return null; };
|
||||
var $where = function (params, ownerQuery, options) {
|
||||
var test;
|
||||
if (isFunction(params)) {
|
||||
test = params;
|
||||
}
|
||||
else {
|
||||
throw new Error("In CSP mode, sift does not support strings in \"$where\" condition");
|
||||
}
|
||||
return new EqualsOperation(function (b) { return test.bind(b)(b); }, ownerQuery, options);
|
||||
};
|
||||
|
||||
var defaultOperations = /*#__PURE__*/Object.freeze({
|
||||
__proto__: null,
|
||||
$Size: $Size,
|
||||
$eq: $eq,
|
||||
$ne: $ne,
|
||||
$or: $or,
|
||||
$nor: $nor,
|
||||
$elemMatch: $elemMatch,
|
||||
$nin: $nin,
|
||||
$in: $in,
|
||||
$lt: $lt,
|
||||
$lte: $lte,
|
||||
$gt: $gt,
|
||||
$gte: $gte,
|
||||
$mod: $mod,
|
||||
$exists: $exists,
|
||||
$regex: $regex,
|
||||
$not: $not,
|
||||
$type: $type,
|
||||
$and: $and,
|
||||
$all: $all,
|
||||
$size: $size,
|
||||
$options: $options,
|
||||
$where: $where
|
||||
});
|
||||
|
||||
var createDefaultQueryOperation = function (query, ownerQuery, _a) {
|
||||
var _b = _a === void 0 ? {} : _a, compare = _b.compare, operations = _b.operations;
|
||||
return createQueryOperation(query, ownerQuery, {
|
||||
compare: compare,
|
||||
operations: Object.assign({}, defaultOperations, operations || {})
|
||||
});
|
||||
};
|
||||
var createDefaultQueryTester = function (query, options) {
|
||||
if (options === void 0) { options = {}; }
|
||||
var op = createDefaultQueryOperation(query, null, options);
|
||||
return createOperationTester(op);
|
||||
};
|
||||
|
||||
exports.$Size = $Size;
|
||||
exports.$all = $all;
|
||||
exports.$and = $and;
|
||||
exports.$elemMatch = $elemMatch;
|
||||
exports.$eq = $eq;
|
||||
exports.$exists = $exists;
|
||||
exports.$gt = $gt;
|
||||
exports.$gte = $gte;
|
||||
exports.$in = $in;
|
||||
exports.$lt = $lt;
|
||||
exports.$lte = $lte;
|
||||
exports.$mod = $mod;
|
||||
exports.$ne = $ne;
|
||||
exports.$nin = $nin;
|
||||
exports.$nor = $nor;
|
||||
exports.$not = $not;
|
||||
exports.$options = $options;
|
||||
exports.$or = $or;
|
||||
exports.$regex = $regex;
|
||||
exports.$size = $size;
|
||||
exports.$type = $type;
|
||||
exports.$where = $where;
|
||||
exports.EqualsOperation = EqualsOperation;
|
||||
exports.createDefaultQueryOperation = createDefaultQueryOperation;
|
||||
exports.createEqualsOperation = createEqualsOperation;
|
||||
exports.createOperationTester = createOperationTester;
|
||||
exports.createQueryOperation = createQueryOperation;
|
||||
exports.createQueryTester = createQueryTester;
|
||||
exports.default = createDefaultQueryTester;
|
||||
|
||||
Object.defineProperty(exports, '__esModule', { value: true });
|
||||
|
||||
})));
|
||||
//# sourceMappingURL=sift.csp.min.js.map
|
1
node_modules/sift/sift.csp.min.js.map
generated
vendored
Normal file
1
node_modules/sift/sift.csp.min.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
16
node_modules/sift/sift.min.js
generated
vendored
Normal file
16
node_modules/sift/sift.min.js
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
1
node_modules/sift/sift.min.js.map
generated
vendored
Normal file
1
node_modules/sift/sift.min.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
120
node_modules/sift/src/core.d.ts
generated
vendored
Normal file
120
node_modules/sift/src/core.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,120 @@
|
|||
import { Key, Comparator } from "./utils";
|
||||
export interface Operation<TItem> {
|
||||
readonly keep: boolean;
|
||||
readonly done: boolean;
|
||||
propop: boolean;
|
||||
reset(): any;
|
||||
next(item: TItem, key?: Key, owner?: any, root?: boolean): any;
|
||||
}
|
||||
export declare type Tester = (item: any, key?: Key, owner?: any, root?: boolean) => boolean;
|
||||
export interface NamedOperation {
|
||||
name: string;
|
||||
}
|
||||
export declare type OperationCreator<TItem> = (params: any, parentQuery: any, options: Options, name: string) => Operation<TItem>;
|
||||
export declare type BasicValueQuery<TValue> = {
|
||||
$eq?: TValue;
|
||||
$ne?: TValue;
|
||||
$lt?: TValue;
|
||||
$gt?: TValue;
|
||||
$lte?: TValue;
|
||||
$gte?: TValue;
|
||||
$in?: TValue[];
|
||||
$nin?: TValue[];
|
||||
$all?: TValue[];
|
||||
$mod?: [number, number];
|
||||
$exists?: boolean;
|
||||
$regex?: string | RegExp;
|
||||
$size?: number;
|
||||
$where?: ((this: TValue, obj: TValue) => boolean) | string;
|
||||
$options?: "i" | "g" | "m" | "u";
|
||||
$type?: Function;
|
||||
$not?: NestedQuery<TValue>;
|
||||
$or?: NestedQuery<TValue>[];
|
||||
$nor?: NestedQuery<TValue>[];
|
||||
$and?: NestedQuery<TValue>[];
|
||||
};
|
||||
export declare type ArrayValueQuery<TValue> = {
|
||||
$elemMatch?: Query<TValue>;
|
||||
} & BasicValueQuery<TValue>;
|
||||
declare type Unpacked<T> = T extends (infer U)[] ? U : T;
|
||||
export declare type ValueQuery<TValue> = TValue extends Array<any> ? ArrayValueQuery<Unpacked<TValue>> : BasicValueQuery<TValue>;
|
||||
declare type NotObject = string | number | Date | boolean | Array<any>;
|
||||
export declare type ShapeQuery<TItemSchema> = TItemSchema extends NotObject ? {} : {
|
||||
[k in keyof TItemSchema]?: TItemSchema[k] | ValueQuery<TItemSchema[k]>;
|
||||
};
|
||||
export declare type NestedQuery<TItemSchema> = ValueQuery<TItemSchema> & ShapeQuery<TItemSchema>;
|
||||
export declare type Query<TItemSchema> = TItemSchema | RegExp | NestedQuery<TItemSchema>;
|
||||
export declare type QueryOperators<TValue = any> = keyof ValueQuery<TValue>;
|
||||
export declare abstract class BaseOperation<TParams, TItem = any> implements Operation<TItem> {
|
||||
readonly params: TParams;
|
||||
readonly owneryQuery: any;
|
||||
readonly options: Options;
|
||||
readonly name?: string;
|
||||
keep: boolean;
|
||||
done: boolean;
|
||||
abstract propop: boolean;
|
||||
constructor(params: TParams, owneryQuery: any, options: Options, name?: string);
|
||||
protected init(): void;
|
||||
reset(): void;
|
||||
abstract next(item: any, key: Key, parent: any, root: boolean): any;
|
||||
}
|
||||
declare abstract class GroupOperation extends BaseOperation<any> {
|
||||
readonly children: Operation<any>[];
|
||||
keep: boolean;
|
||||
done: boolean;
|
||||
constructor(params: any, owneryQuery: any, options: Options, children: Operation<any>[]);
|
||||
/**
|
||||
*/
|
||||
reset(): void;
|
||||
abstract next(item: any, key: Key, owner: any, root: boolean): any;
|
||||
/**
|
||||
*/
|
||||
protected childrenNext(item: any, key: Key, owner: any, root: boolean): void;
|
||||
}
|
||||
export declare abstract class NamedGroupOperation extends GroupOperation implements NamedOperation {
|
||||
readonly name: string;
|
||||
abstract propop: boolean;
|
||||
constructor(params: any, owneryQuery: any, options: Options, children: Operation<any>[], name: string);
|
||||
}
|
||||
export declare class QueryOperation<TItem> extends GroupOperation {
|
||||
readonly propop = true;
|
||||
/**
|
||||
*/
|
||||
next(item: TItem, key: Key, parent: any, root: boolean): void;
|
||||
}
|
||||
export declare class NestedOperation extends GroupOperation {
|
||||
readonly keyPath: Key[];
|
||||
readonly propop = true;
|
||||
constructor(keyPath: Key[], params: any, owneryQuery: any, options: Options, children: Operation<any>[]);
|
||||
/**
|
||||
*/
|
||||
next(item: any, key: Key, parent: any): void;
|
||||
/**
|
||||
*/
|
||||
private _nextNestedValue;
|
||||
}
|
||||
export declare const createTester: (a: any, compare: Comparator) => any;
|
||||
export declare class EqualsOperation<TParam> extends BaseOperation<TParam> {
|
||||
readonly propop = true;
|
||||
private _test;
|
||||
init(): void;
|
||||
next(item: any, key: Key, parent: any): void;
|
||||
}
|
||||
export declare const createEqualsOperation: (params: any, owneryQuery: any, options: Options) => EqualsOperation<any>;
|
||||
export declare class NopeOperation<TParam> extends BaseOperation<TParam> {
|
||||
readonly propop = true;
|
||||
next(): void;
|
||||
}
|
||||
export declare const numericalOperationCreator: (createNumericalOperation: OperationCreator<any>) => (params: any, owneryQuery: any, options: Options, name: string) => Operation<any> | NopeOperation<any>;
|
||||
export declare const numericalOperation: (createTester: (any: any) => Tester) => (params: any, owneryQuery: any, options: Options, name: string) => Operation<any> | NopeOperation<any>;
|
||||
export declare type Options = {
|
||||
operations: {
|
||||
[identifier: string]: OperationCreator<any>;
|
||||
};
|
||||
compare: (a: any, b: any) => boolean;
|
||||
};
|
||||
export declare const containsOperation: (query: any, options: Options) => boolean;
|
||||
export declare const createQueryOperation: <TItem, TSchema = TItem>(query: Query<TSchema>, owneryQuery?: any, { compare, operations }?: Partial<Options>) => QueryOperation<TItem>;
|
||||
export declare const createOperationTester: <TItem>(operation: Operation<TItem>) => (item: TItem, key?: Key, owner?: any) => boolean;
|
||||
export declare const createQueryTester: <TItem, TSchema = TItem>(query: Query<TSchema>, options?: Partial<Options>) => (item: TItem, key?: Key, owner?: any) => boolean;
|
||||
export {};
|
267
node_modules/sift/src/core.js
generated
vendored
Normal file
267
node_modules/sift/src/core.js
generated
vendored
Normal file
|
@ -0,0 +1,267 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createQueryTester = exports.createOperationTester = exports.createQueryOperation = exports.containsOperation = exports.numericalOperation = exports.numericalOperationCreator = exports.NopeOperation = exports.createEqualsOperation = exports.EqualsOperation = exports.createTester = exports.NestedOperation = exports.QueryOperation = exports.NamedGroupOperation = exports.BaseOperation = void 0;
|
||||
const utils_1 = require("./utils");
|
||||
/**
|
||||
* Walks through each value given the context - used for nested operations. E.g:
|
||||
* { "person.address": { $eq: "blarg" }}
|
||||
*/
|
||||
const walkKeyPathValues = (item, keyPath, next, depth, key, owner) => {
|
||||
const currentKey = keyPath[depth];
|
||||
// if array, then try matching. Might fall through for cases like:
|
||||
// { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
|
||||
if ((0, utils_1.isArray)(item) && isNaN(Number(currentKey))) {
|
||||
for (let i = 0, { length } = item; i < length; i++) {
|
||||
// if FALSE is returned, then terminate walker. For operations, this simply
|
||||
// means that the search critera was met.
|
||||
if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (depth === keyPath.length || item == null) {
|
||||
return next(item, key, owner, depth === 0);
|
||||
}
|
||||
return walkKeyPathValues(item[currentKey], keyPath, next, depth + 1, currentKey, item);
|
||||
};
|
||||
class BaseOperation {
|
||||
constructor(params, owneryQuery, options, name) {
|
||||
this.params = params;
|
||||
this.owneryQuery = owneryQuery;
|
||||
this.options = options;
|
||||
this.name = name;
|
||||
this.init();
|
||||
}
|
||||
init() { }
|
||||
reset() {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
exports.BaseOperation = BaseOperation;
|
||||
class GroupOperation extends BaseOperation {
|
||||
constructor(params, owneryQuery, options, children) {
|
||||
super(params, owneryQuery, options);
|
||||
this.children = children;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
reset() {
|
||||
this.keep = false;
|
||||
this.done = false;
|
||||
for (let i = 0, { length } = this.children; i < length; i++) {
|
||||
this.children[i].reset();
|
||||
}
|
||||
}
|
||||
/**
|
||||
*/
|
||||
childrenNext(item, key, owner, root) {
|
||||
let done = true;
|
||||
let keep = true;
|
||||
for (let i = 0, { length } = this.children; i < length; i++) {
|
||||
const childOperation = this.children[i];
|
||||
if (!childOperation.done) {
|
||||
childOperation.next(item, key, owner, root);
|
||||
}
|
||||
if (!childOperation.keep) {
|
||||
keep = false;
|
||||
}
|
||||
if (childOperation.done) {
|
||||
if (!childOperation.keep) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
this.done = done;
|
||||
this.keep = keep;
|
||||
}
|
||||
}
|
||||
class NamedGroupOperation extends GroupOperation {
|
||||
constructor(params, owneryQuery, options, children, name) {
|
||||
super(params, owneryQuery, options, children);
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
exports.NamedGroupOperation = NamedGroupOperation;
|
||||
class QueryOperation extends GroupOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
/**
|
||||
*/
|
||||
next(item, key, parent, root) {
|
||||
this.childrenNext(item, key, parent, root);
|
||||
}
|
||||
}
|
||||
exports.QueryOperation = QueryOperation;
|
||||
class NestedOperation extends GroupOperation {
|
||||
constructor(keyPath, params, owneryQuery, options, children) {
|
||||
super(params, owneryQuery, options, children);
|
||||
this.keyPath = keyPath;
|
||||
this.propop = true;
|
||||
/**
|
||||
*/
|
||||
this._nextNestedValue = (value, key, owner, root) => {
|
||||
this.childrenNext(value, key, owner, root);
|
||||
return !this.done;
|
||||
};
|
||||
}
|
||||
/**
|
||||
*/
|
||||
next(item, key, parent) {
|
||||
walkKeyPathValues(item, this.keyPath, this._nextNestedValue, 0, key, parent);
|
||||
}
|
||||
}
|
||||
exports.NestedOperation = NestedOperation;
|
||||
const createTester = (a, compare) => {
|
||||
if (a instanceof Function) {
|
||||
return a;
|
||||
}
|
||||
if (a instanceof RegExp) {
|
||||
return b => {
|
||||
const result = typeof b === "string" && a.test(b);
|
||||
a.lastIndex = 0;
|
||||
return result;
|
||||
};
|
||||
}
|
||||
const comparableA = (0, utils_1.comparable)(a);
|
||||
return b => compare(comparableA, (0, utils_1.comparable)(b));
|
||||
};
|
||||
exports.createTester = createTester;
|
||||
class EqualsOperation extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() {
|
||||
this._test = (0, exports.createTester)(this.params, this.options.compare);
|
||||
}
|
||||
next(item, key, parent) {
|
||||
if (!Array.isArray(parent) || parent.hasOwnProperty(key)) {
|
||||
if (this._test(item, key, parent)) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.EqualsOperation = EqualsOperation;
|
||||
const createEqualsOperation = (params, owneryQuery, options) => new EqualsOperation(params, owneryQuery, options);
|
||||
exports.createEqualsOperation = createEqualsOperation;
|
||||
class NopeOperation extends BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
next() {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
exports.NopeOperation = NopeOperation;
|
||||
const numericalOperationCreator = (createNumericalOperation) => (params, owneryQuery, options, name) => {
|
||||
if (params == null) {
|
||||
return new NopeOperation(params, owneryQuery, options, name);
|
||||
}
|
||||
return createNumericalOperation(params, owneryQuery, options, name);
|
||||
};
|
||||
exports.numericalOperationCreator = numericalOperationCreator;
|
||||
const numericalOperation = (createTester) => (0, exports.numericalOperationCreator)((params, owneryQuery, options, name) => {
|
||||
const typeofParams = typeof (0, utils_1.comparable)(params);
|
||||
const test = createTester(params);
|
||||
return new EqualsOperation(b => {
|
||||
return typeof (0, utils_1.comparable)(b) === typeofParams && test(b);
|
||||
}, owneryQuery, options, name);
|
||||
});
|
||||
exports.numericalOperation = numericalOperation;
|
||||
const createNamedOperation = (name, params, parentQuery, options) => {
|
||||
const operationCreator = options.operations[name];
|
||||
if (!operationCreator) {
|
||||
throwUnsupportedOperation(name);
|
||||
}
|
||||
return operationCreator(params, parentQuery, options, name);
|
||||
};
|
||||
const throwUnsupportedOperation = (name) => {
|
||||
throw new Error(`Unsupported operation: ${name}`);
|
||||
};
|
||||
const containsOperation = (query, options) => {
|
||||
for (const key in query) {
|
||||
if (options.operations.hasOwnProperty(key) || key.charAt(0) === "$")
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
exports.containsOperation = containsOperation;
|
||||
const createNestedOperation = (keyPath, nestedQuery, parentKey, owneryQuery, options) => {
|
||||
if ((0, exports.containsOperation)(nestedQuery, options)) {
|
||||
const [selfOperations, nestedOperations] = createQueryOperations(nestedQuery, parentKey, options);
|
||||
if (nestedOperations.length) {
|
||||
throw new Error(`Property queries must contain only operations, or exact objects.`);
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, selfOperations);
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
|
||||
new EqualsOperation(nestedQuery, owneryQuery, options)
|
||||
]);
|
||||
};
|
||||
const createQueryOperation = (query, owneryQuery = null, { compare, operations } = {}) => {
|
||||
const options = {
|
||||
compare: compare || utils_1.equals,
|
||||
operations: Object.assign({}, operations || {})
|
||||
};
|
||||
const [selfOperations, nestedOperations] = createQueryOperations(query, null, options);
|
||||
const ops = [];
|
||||
if (selfOperations.length) {
|
||||
ops.push(new NestedOperation([], query, owneryQuery, options, selfOperations));
|
||||
}
|
||||
ops.push(...nestedOperations);
|
||||
if (ops.length === 1) {
|
||||
return ops[0];
|
||||
}
|
||||
return new QueryOperation(query, owneryQuery, options, ops);
|
||||
};
|
||||
exports.createQueryOperation = createQueryOperation;
|
||||
const createQueryOperations = (query, parentKey, options) => {
|
||||
const selfOperations = [];
|
||||
const nestedOperations = [];
|
||||
if (!(0, utils_1.isVanillaObject)(query)) {
|
||||
selfOperations.push(new EqualsOperation(query, query, options));
|
||||
return [selfOperations, nestedOperations];
|
||||
}
|
||||
for (const key in query) {
|
||||
if (options.operations.hasOwnProperty(key)) {
|
||||
const op = createNamedOperation(key, query[key], query, options);
|
||||
if (op) {
|
||||
if (!op.propop && parentKey && !options.operations[parentKey]) {
|
||||
throw new Error(`Malformed query. ${key} cannot be matched against property.`);
|
||||
}
|
||||
}
|
||||
// probably just a flag for another operation (like $options)
|
||||
if (op != null) {
|
||||
selfOperations.push(op);
|
||||
}
|
||||
}
|
||||
else if (key.charAt(0) === "$") {
|
||||
throwUnsupportedOperation(key);
|
||||
}
|
||||
else {
|
||||
nestedOperations.push(createNestedOperation(key.split("."), query[key], key, query, options));
|
||||
}
|
||||
}
|
||||
return [selfOperations, nestedOperations];
|
||||
};
|
||||
const createOperationTester = (operation) => (item, key, owner) => {
|
||||
operation.reset();
|
||||
operation.next(item, key, owner);
|
||||
return operation.keep;
|
||||
};
|
||||
exports.createOperationTester = createOperationTester;
|
||||
const createQueryTester = (query, options = {}) => {
|
||||
return (0, exports.createOperationTester)((0, exports.createQueryOperation)(query, null, options));
|
||||
};
|
||||
exports.createQueryTester = createQueryTester;
|
||||
//# sourceMappingURL=core.js.map
|
1
node_modules/sift/src/core.js.map
generated
vendored
Normal file
1
node_modules/sift/src/core.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
481
node_modules/sift/src/core.ts
generated
vendored
Normal file
481
node_modules/sift/src/core.ts
generated
vendored
Normal file
|
@ -0,0 +1,481 @@
|
|||
import {
|
||||
isArray,
|
||||
Key,
|
||||
Comparator,
|
||||
isVanillaObject,
|
||||
comparable,
|
||||
equals
|
||||
} from "./utils";
|
||||
|
||||
export interface Operation<TItem> {
|
||||
readonly keep: boolean;
|
||||
readonly done: boolean;
|
||||
propop: boolean;
|
||||
reset();
|
||||
next(item: TItem, key?: Key, owner?: any, root?: boolean);
|
||||
}
|
||||
|
||||
export type Tester = (
|
||||
item: any,
|
||||
key?: Key,
|
||||
owner?: any,
|
||||
root?: boolean
|
||||
) => boolean;
|
||||
|
||||
export interface NamedOperation {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type OperationCreator<TItem> = (
|
||||
params: any,
|
||||
parentQuery: any,
|
||||
options: Options,
|
||||
name: string
|
||||
) => Operation<TItem>;
|
||||
|
||||
export type BasicValueQuery<TValue> = {
|
||||
$eq?: TValue;
|
||||
$ne?: TValue;
|
||||
$lt?: TValue;
|
||||
$gt?: TValue;
|
||||
$lte?: TValue;
|
||||
$gte?: TValue;
|
||||
$in?: TValue[];
|
||||
$nin?: TValue[];
|
||||
$all?: TValue[];
|
||||
$mod?: [number, number];
|
||||
$exists?: boolean;
|
||||
$regex?: string | RegExp;
|
||||
$size?: number;
|
||||
$where?: ((this: TValue, obj: TValue) => boolean) | string;
|
||||
$options?: "i" | "g" | "m" | "u";
|
||||
$type?: Function;
|
||||
$not?: NestedQuery<TValue>;
|
||||
$or?: NestedQuery<TValue>[];
|
||||
$nor?: NestedQuery<TValue>[];
|
||||
$and?: NestedQuery<TValue>[];
|
||||
};
|
||||
|
||||
export type ArrayValueQuery<TValue> = {
|
||||
$elemMatch?: Query<TValue>;
|
||||
} & BasicValueQuery<TValue>;
|
||||
type Unpacked<T> = T extends (infer U)[] ? U : T;
|
||||
|
||||
export type ValueQuery<TValue> = TValue extends Array<any>
|
||||
? ArrayValueQuery<Unpacked<TValue>>
|
||||
: BasicValueQuery<TValue>;
|
||||
|
||||
type NotObject = string | number | Date | boolean | Array<any>;
|
||||
export type ShapeQuery<TItemSchema> = TItemSchema extends NotObject
|
||||
? {}
|
||||
: { [k in keyof TItemSchema]?: TItemSchema[k] | ValueQuery<TItemSchema[k]> };
|
||||
|
||||
export type NestedQuery<TItemSchema> = ValueQuery<TItemSchema> &
|
||||
ShapeQuery<TItemSchema>;
|
||||
export type Query<TItemSchema> =
|
||||
| TItemSchema
|
||||
| RegExp
|
||||
| NestedQuery<TItemSchema>;
|
||||
|
||||
export type QueryOperators<TValue = any> = keyof ValueQuery<TValue>;
|
||||
|
||||
/**
|
||||
* Walks through each value given the context - used for nested operations. E.g:
|
||||
* { "person.address": { $eq: "blarg" }}
|
||||
*/
|
||||
|
||||
const walkKeyPathValues = (
|
||||
item: any,
|
||||
keyPath: Key[],
|
||||
next: Tester,
|
||||
depth: number,
|
||||
key: Key,
|
||||
owner: any
|
||||
) => {
|
||||
const currentKey = keyPath[depth];
|
||||
|
||||
// if array, then try matching. Might fall through for cases like:
|
||||
// { $eq: [1, 2, 3] }, [ 1, 2, 3 ].
|
||||
if (isArray(item) && isNaN(Number(currentKey))) {
|
||||
for (let i = 0, { length } = item; i < length; i++) {
|
||||
// if FALSE is returned, then terminate walker. For operations, this simply
|
||||
// means that the search critera was met.
|
||||
if (!walkKeyPathValues(item[i], keyPath, next, depth, i, item)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (depth === keyPath.length || item == null) {
|
||||
return next(item, key, owner, depth === 0);
|
||||
}
|
||||
|
||||
return walkKeyPathValues(
|
||||
item[currentKey],
|
||||
keyPath,
|
||||
next,
|
||||
depth + 1,
|
||||
currentKey,
|
||||
item
|
||||
);
|
||||
};
|
||||
|
||||
export abstract class BaseOperation<TParams, TItem = any>
|
||||
implements Operation<TItem> {
|
||||
keep: boolean;
|
||||
done: boolean;
|
||||
abstract propop: boolean;
|
||||
constructor(
|
||||
readonly params: TParams,
|
||||
readonly owneryQuery: any,
|
||||
readonly options: Options,
|
||||
readonly name?: string
|
||||
) {
|
||||
this.init();
|
||||
}
|
||||
protected init() {}
|
||||
reset() {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
}
|
||||
abstract next(item: any, key: Key, parent: any, root: boolean);
|
||||
}
|
||||
|
||||
abstract class GroupOperation extends BaseOperation<any> {
|
||||
keep: boolean;
|
||||
done: boolean;
|
||||
|
||||
constructor(
|
||||
params: any,
|
||||
owneryQuery: any,
|
||||
options: Options,
|
||||
public readonly children: Operation<any>[]
|
||||
) {
|
||||
super(params, owneryQuery, options);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
reset() {
|
||||
this.keep = false;
|
||||
this.done = false;
|
||||
for (let i = 0, { length } = this.children; i < length; i++) {
|
||||
this.children[i].reset();
|
||||
}
|
||||
}
|
||||
|
||||
abstract next(item: any, key: Key, owner: any, root: boolean);
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
protected childrenNext(item: any, key: Key, owner: any, root: boolean) {
|
||||
let done = true;
|
||||
let keep = true;
|
||||
for (let i = 0, { length } = this.children; i < length; i++) {
|
||||
const childOperation = this.children[i];
|
||||
if (!childOperation.done) {
|
||||
childOperation.next(item, key, owner, root);
|
||||
}
|
||||
if (!childOperation.keep) {
|
||||
keep = false;
|
||||
}
|
||||
if (childOperation.done) {
|
||||
if (!childOperation.keep) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
this.done = done;
|
||||
this.keep = keep;
|
||||
}
|
||||
}
|
||||
|
||||
export abstract class NamedGroupOperation extends GroupOperation
|
||||
implements NamedOperation {
|
||||
abstract propop: boolean;
|
||||
constructor(
|
||||
params: any,
|
||||
owneryQuery: any,
|
||||
options: Options,
|
||||
children: Operation<any>[],
|
||||
readonly name: string
|
||||
) {
|
||||
super(params, owneryQuery, options, children);
|
||||
}
|
||||
}
|
||||
|
||||
export class QueryOperation<TItem> extends GroupOperation {
|
||||
readonly propop = true;
|
||||
/**
|
||||
*/
|
||||
|
||||
next(item: TItem, key: Key, parent: any, root: boolean) {
|
||||
this.childrenNext(item, key, parent, root);
|
||||
}
|
||||
}
|
||||
|
||||
export class NestedOperation extends GroupOperation {
|
||||
readonly propop = true;
|
||||
constructor(
|
||||
readonly keyPath: Key[],
|
||||
params: any,
|
||||
owneryQuery: any,
|
||||
options: Options,
|
||||
children: Operation<any>[]
|
||||
) {
|
||||
super(params, owneryQuery, options, children);
|
||||
}
|
||||
/**
|
||||
*/
|
||||
|
||||
next(item: any, key: Key, parent: any) {
|
||||
walkKeyPathValues(
|
||||
item,
|
||||
this.keyPath,
|
||||
this._nextNestedValue,
|
||||
0,
|
||||
key,
|
||||
parent
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
|
||||
private _nextNestedValue = (
|
||||
value: any,
|
||||
key: Key,
|
||||
owner: any,
|
||||
root: boolean
|
||||
) => {
|
||||
this.childrenNext(value, key, owner, root);
|
||||
return !this.done;
|
||||
};
|
||||
}
|
||||
|
||||
export const createTester = (a, compare: Comparator) => {
|
||||
if (a instanceof Function) {
|
||||
return a;
|
||||
}
|
||||
if (a instanceof RegExp) {
|
||||
return b => {
|
||||
const result = typeof b === "string" && a.test(b);
|
||||
a.lastIndex = 0;
|
||||
return result;
|
||||
};
|
||||
}
|
||||
const comparableA = comparable(a);
|
||||
return b => compare(comparableA, comparable(b));
|
||||
};
|
||||
|
||||
export class EqualsOperation<TParam> extends BaseOperation<TParam> {
|
||||
readonly propop = true;
|
||||
private _test: Tester;
|
||||
init() {
|
||||
this._test = createTester(this.params, this.options.compare);
|
||||
}
|
||||
next(item, key: Key, parent: any) {
|
||||
if (!Array.isArray(parent) || parent.hasOwnProperty(key)) {
|
||||
if (this._test(item, key, parent)) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const createEqualsOperation = (
|
||||
params: any,
|
||||
owneryQuery: any,
|
||||
options: Options
|
||||
) => new EqualsOperation(params, owneryQuery, options);
|
||||
|
||||
export class NopeOperation<TParam> extends BaseOperation<TParam> {
|
||||
readonly propop = true;
|
||||
next() {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
|
||||
export const numericalOperationCreator = (
|
||||
createNumericalOperation: OperationCreator<any>
|
||||
) => (params: any, owneryQuery: any, options: Options, name: string) => {
|
||||
if (params == null) {
|
||||
return new NopeOperation(params, owneryQuery, options, name);
|
||||
}
|
||||
|
||||
return createNumericalOperation(params, owneryQuery, options, name);
|
||||
};
|
||||
|
||||
export const numericalOperation = (createTester: (any) => Tester) =>
|
||||
numericalOperationCreator(
|
||||
(params: any, owneryQuery: Query<any>, options: Options, name: string) => {
|
||||
const typeofParams = typeof comparable(params);
|
||||
const test = createTester(params);
|
||||
return new EqualsOperation(
|
||||
b => {
|
||||
return typeof comparable(b) === typeofParams && test(b);
|
||||
},
|
||||
owneryQuery,
|
||||
options,
|
||||
name
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
export type Options = {
|
||||
operations: {
|
||||
[identifier: string]: OperationCreator<any>;
|
||||
};
|
||||
compare: (a, b) => boolean;
|
||||
};
|
||||
|
||||
const createNamedOperation = (
|
||||
name: string,
|
||||
params: any,
|
||||
parentQuery: any,
|
||||
options: Options
|
||||
) => {
|
||||
const operationCreator = options.operations[name];
|
||||
if (!operationCreator) {
|
||||
throwUnsupportedOperation(name);
|
||||
}
|
||||
return operationCreator(params, parentQuery, options, name);
|
||||
};
|
||||
|
||||
const throwUnsupportedOperation = (name: string) => {
|
||||
throw new Error(`Unsupported operation: ${name}`);
|
||||
};
|
||||
|
||||
export const containsOperation = (query: any, options: Options) => {
|
||||
for (const key in query) {
|
||||
if (options.operations.hasOwnProperty(key) || key.charAt(0) === "$")
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
const createNestedOperation = (
|
||||
keyPath: Key[],
|
||||
nestedQuery: any,
|
||||
parentKey: string,
|
||||
owneryQuery: any,
|
||||
options: Options
|
||||
) => {
|
||||
if (containsOperation(nestedQuery, options)) {
|
||||
const [selfOperations, nestedOperations] = createQueryOperations(
|
||||
nestedQuery,
|
||||
parentKey,
|
||||
options
|
||||
);
|
||||
if (nestedOperations.length) {
|
||||
throw new Error(
|
||||
`Property queries must contain only operations, or exact objects.`
|
||||
);
|
||||
}
|
||||
return new NestedOperation(
|
||||
keyPath,
|
||||
nestedQuery,
|
||||
owneryQuery,
|
||||
options,
|
||||
selfOperations
|
||||
);
|
||||
}
|
||||
return new NestedOperation(keyPath, nestedQuery, owneryQuery, options, [
|
||||
new EqualsOperation(nestedQuery, owneryQuery, options)
|
||||
]);
|
||||
};
|
||||
|
||||
export const createQueryOperation = <TItem, TSchema = TItem>(
|
||||
query: Query<TSchema>,
|
||||
owneryQuery: any = null,
|
||||
{ compare, operations }: Partial<Options> = {}
|
||||
): QueryOperation<TItem> => {
|
||||
const options = {
|
||||
compare: compare || equals,
|
||||
operations: Object.assign({}, operations || {})
|
||||
};
|
||||
|
||||
const [selfOperations, nestedOperations] = createQueryOperations(
|
||||
query,
|
||||
null,
|
||||
options
|
||||
);
|
||||
|
||||
const ops = [];
|
||||
|
||||
if (selfOperations.length) {
|
||||
ops.push(
|
||||
new NestedOperation([], query, owneryQuery, options, selfOperations)
|
||||
);
|
||||
}
|
||||
|
||||
ops.push(...nestedOperations);
|
||||
|
||||
if (ops.length === 1) {
|
||||
return ops[0];
|
||||
}
|
||||
return new QueryOperation(query, owneryQuery, options, ops);
|
||||
};
|
||||
|
||||
const createQueryOperations = (
|
||||
query: any,
|
||||
parentKey: string,
|
||||
options: Options
|
||||
) => {
|
||||
const selfOperations = [];
|
||||
const nestedOperations = [];
|
||||
if (!isVanillaObject(query)) {
|
||||
selfOperations.push(new EqualsOperation(query, query, options));
|
||||
return [selfOperations, nestedOperations];
|
||||
}
|
||||
for (const key in query) {
|
||||
if (options.operations.hasOwnProperty(key)) {
|
||||
const op = createNamedOperation(key, query[key], query, options);
|
||||
|
||||
if (op) {
|
||||
if (!op.propop && parentKey && !options.operations[parentKey]) {
|
||||
throw new Error(
|
||||
`Malformed query. ${key} cannot be matched against property.`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// probably just a flag for another operation (like $options)
|
||||
if (op != null) {
|
||||
selfOperations.push(op);
|
||||
}
|
||||
} else if (key.charAt(0) === "$") {
|
||||
throwUnsupportedOperation(key);
|
||||
} else {
|
||||
nestedOperations.push(
|
||||
createNestedOperation(key.split("."), query[key], key, query, options)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return [selfOperations, nestedOperations];
|
||||
};
|
||||
|
||||
export const createOperationTester = <TItem>(operation: Operation<TItem>) => (
|
||||
item: TItem,
|
||||
key?: Key,
|
||||
owner?: any
|
||||
) => {
|
||||
operation.reset();
|
||||
operation.next(item, key, owner);
|
||||
return operation.keep;
|
||||
};
|
||||
|
||||
export const createQueryTester = <TItem, TSchema = TItem>(
|
||||
query: Query<TSchema>,
|
||||
options: Partial<Options> = {}
|
||||
) => {
|
||||
return createOperationTester(
|
||||
createQueryOperation<TItem, TSchema>(query, null, options)
|
||||
);
|
||||
};
|
6
node_modules/sift/src/index.d.ts
generated
vendored
Normal file
6
node_modules/sift/src/index.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
import { Query, QueryOperators, BasicValueQuery, ArrayValueQuery, ValueQuery, NestedQuery, ShapeQuery, Options, createQueryTester, EqualsOperation, createQueryOperation, createEqualsOperation, createOperationTester } from "./core";
|
||||
declare const createDefaultQueryOperation: <TItem, TSchema extends TItem = TItem>(query: Query<TSchema>, ownerQuery: any, { compare, operations }?: Partial<Options>) => import("./core").QueryOperation<unknown>;
|
||||
declare const createDefaultQueryTester: <TItem, TSchema extends TItem = TItem>(query: Query<TSchema>, options?: Partial<Options>) => (item: unknown, key?: import("./utils").Key, owner?: any) => boolean;
|
||||
export { Query, QueryOperators, BasicValueQuery, ArrayValueQuery, ValueQuery, NestedQuery, ShapeQuery, EqualsOperation, createQueryTester, createOperationTester, createDefaultQueryOperation, createEqualsOperation, createQueryOperation };
|
||||
export * from "./operations";
|
||||
export default createDefaultQueryTester;
|
38
node_modules/sift/src/index.js
generated
vendored
Normal file
38
node_modules/sift/src/index.js
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.createQueryOperation = exports.createEqualsOperation = exports.createDefaultQueryOperation = exports.createOperationTester = exports.createQueryTester = exports.EqualsOperation = void 0;
|
||||
const defaultOperations = require("./operations");
|
||||
const core_1 = require("./core");
|
||||
Object.defineProperty(exports, "createQueryTester", { enumerable: true, get: function () { return core_1.createQueryTester; } });
|
||||
Object.defineProperty(exports, "EqualsOperation", { enumerable: true, get: function () { return core_1.EqualsOperation; } });
|
||||
Object.defineProperty(exports, "createQueryOperation", { enumerable: true, get: function () { return core_1.createQueryOperation; } });
|
||||
Object.defineProperty(exports, "createEqualsOperation", { enumerable: true, get: function () { return core_1.createEqualsOperation; } });
|
||||
Object.defineProperty(exports, "createOperationTester", { enumerable: true, get: function () { return core_1.createOperationTester; } });
|
||||
const createDefaultQueryOperation = (query, ownerQuery, { compare, operations } = {}) => {
|
||||
return (0, core_1.createQueryOperation)(query, ownerQuery, {
|
||||
compare,
|
||||
operations: Object.assign({}, defaultOperations, operations || {})
|
||||
});
|
||||
};
|
||||
exports.createDefaultQueryOperation = createDefaultQueryOperation;
|
||||
const createDefaultQueryTester = (query, options = {}) => {
|
||||
const op = createDefaultQueryOperation(query, null, options);
|
||||
return (0, core_1.createOperationTester)(op);
|
||||
};
|
||||
__exportStar(require("./operations"), exports);
|
||||
exports.default = createDefaultQueryTester;
|
||||
//# sourceMappingURL=index.js.map
|
1
node_modules/sift/src/index.js.map
generated
vendored
Normal file
1
node_modules/sift/src/index.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,kDAAkD;AAClD,iCAcgB;AA8Bd,kGAnCA,wBAAiB,OAmCA;AADjB,gGAjCA,sBAAe,OAiCA;AAKf,qGArCA,2BAAoB,OAqCA;AADpB,sGAnCA,4BAAqB,OAmCA;AAFrB,sGAhCA,4BAAqB,OAgCA;AA7BvB,MAAM,2BAA2B,GAAG,CAClC,KAAqB,EACrB,UAAe,EACf,EAAE,OAAO,EAAE,UAAU,KAAuB,EAAE,EAC9C,EAAE;IACF,OAAO,IAAA,2BAAoB,EAAC,KAAK,EAAE,UAAU,EAAE;QAC7C,OAAO;QACP,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,iBAAiB,EAAE,UAAU,IAAI,EAAE,CAAC;KACnE,CAAC,CAAC;AACL,CAAC,CAAC;AAqBA,kEAA2B;AAnB7B,MAAM,wBAAwB,GAAG,CAC/B,KAAqB,EACrB,UAA4B,EAAE,EAC9B,EAAE;IACF,MAAM,EAAE,GAAG,2BAA2B,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IAC7D,OAAO,IAAA,4BAAqB,EAAC,EAAE,CAAC,CAAC;AACnC,CAAC,CAAC;AAiBF,+CAA6B;AAE7B,kBAAe,wBAAwB,CAAC"}
|
54
node_modules/sift/src/index.ts
generated
vendored
Normal file
54
node_modules/sift/src/index.ts
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
import * as defaultOperations from "./operations";
|
||||
import {
|
||||
Query,
|
||||
QueryOperators,
|
||||
BasicValueQuery,
|
||||
ArrayValueQuery,
|
||||
ValueQuery,
|
||||
NestedQuery,
|
||||
ShapeQuery,
|
||||
Options,
|
||||
createQueryTester,
|
||||
EqualsOperation,
|
||||
createQueryOperation,
|
||||
createEqualsOperation,
|
||||
createOperationTester
|
||||
} from "./core";
|
||||
|
||||
const createDefaultQueryOperation = <TItem, TSchema extends TItem = TItem>(
|
||||
query: Query<TSchema>,
|
||||
ownerQuery: any,
|
||||
{ compare, operations }: Partial<Options> = {}
|
||||
) => {
|
||||
return createQueryOperation(query, ownerQuery, {
|
||||
compare,
|
||||
operations: Object.assign({}, defaultOperations, operations || {})
|
||||
});
|
||||
};
|
||||
|
||||
const createDefaultQueryTester = <TItem, TSchema extends TItem = TItem>(
|
||||
query: Query<TSchema>,
|
||||
options: Partial<Options> = {}
|
||||
) => {
|
||||
const op = createDefaultQueryOperation(query, null, options);
|
||||
return createOperationTester(op);
|
||||
};
|
||||
|
||||
export {
|
||||
Query,
|
||||
QueryOperators,
|
||||
BasicValueQuery,
|
||||
ArrayValueQuery,
|
||||
ValueQuery,
|
||||
NestedQuery,
|
||||
ShapeQuery,
|
||||
EqualsOperation,
|
||||
createQueryTester,
|
||||
createOperationTester,
|
||||
createDefaultQueryOperation,
|
||||
createEqualsOperation,
|
||||
createQueryOperation
|
||||
};
|
||||
export * from "./operations";
|
||||
|
||||
export default createDefaultQueryTester;
|
88
node_modules/sift/src/operations.d.ts
generated
vendored
Normal file
88
node_modules/sift/src/operations.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,88 @@
|
|||
import { BaseOperation, EqualsOperation, Options, Operation, Query, NamedGroupOperation } from "./core";
|
||||
import { Key } from "./utils";
|
||||
declare class $Ne extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
private _test;
|
||||
init(): void;
|
||||
reset(): void;
|
||||
next(item: any): void;
|
||||
}
|
||||
declare class $ElemMatch extends BaseOperation<Query<any>> {
|
||||
readonly propop = true;
|
||||
private _queryOperation;
|
||||
init(): void;
|
||||
reset(): void;
|
||||
next(item: any): void;
|
||||
}
|
||||
declare class $Not extends BaseOperation<Query<any>> {
|
||||
readonly propop = true;
|
||||
private _queryOperation;
|
||||
init(): void;
|
||||
reset(): void;
|
||||
next(item: any, key: Key, owner: any, root: boolean): void;
|
||||
}
|
||||
export declare class $Size extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
init(): void;
|
||||
next(item: any): void;
|
||||
}
|
||||
declare class $Or extends BaseOperation<any> {
|
||||
readonly propop = false;
|
||||
private _ops;
|
||||
init(): void;
|
||||
reset(): void;
|
||||
next(item: any, key: Key, owner: any): void;
|
||||
}
|
||||
declare class $Nor extends $Or {
|
||||
readonly propop = false;
|
||||
next(item: any, key: Key, owner: any): void;
|
||||
}
|
||||
declare class $In extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
private _testers;
|
||||
init(): void;
|
||||
next(item: any, key: Key, owner: any): void;
|
||||
}
|
||||
declare class $Nin extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
private _in;
|
||||
constructor(params: any, ownerQuery: any, options: Options, name: string);
|
||||
next(item: any, key: Key, owner: any, root: boolean): void;
|
||||
reset(): void;
|
||||
}
|
||||
declare class $Exists extends BaseOperation<boolean> {
|
||||
readonly propop = true;
|
||||
next(item: any, key: Key, owner: any): void;
|
||||
}
|
||||
declare class $And extends NamedGroupOperation {
|
||||
readonly propop = false;
|
||||
constructor(params: Query<any>[], owneryQuery: Query<any>, options: Options, name: string);
|
||||
next(item: any, key: Key, owner: any, root: boolean): void;
|
||||
}
|
||||
declare class $All extends NamedGroupOperation {
|
||||
readonly propop = true;
|
||||
constructor(params: Query<any>[], owneryQuery: Query<any>, options: Options, name: string);
|
||||
next(item: any, key: Key, owner: any, root: boolean): void;
|
||||
}
|
||||
export declare const $eq: (params: any, owneryQuery: Query<any>, options: Options) => EqualsOperation<any>;
|
||||
export declare const $ne: (params: any, owneryQuery: Query<any>, options: Options, name: string) => $Ne;
|
||||
export declare const $or: (params: Query<any>[], owneryQuery: Query<any>, options: Options, name: string) => $Or;
|
||||
export declare const $nor: (params: Query<any>[], owneryQuery: Query<any>, options: Options, name: string) => $Nor;
|
||||
export declare const $elemMatch: (params: any, owneryQuery: Query<any>, options: Options, name: string) => $ElemMatch;
|
||||
export declare const $nin: (params: any, owneryQuery: Query<any>, options: Options, name: string) => $Nin;
|
||||
export declare const $in: (params: any, owneryQuery: Query<any>, options: Options, name: string) => $In;
|
||||
export declare const $lt: (params: any, owneryQuery: any, options: Options, name: string) => Operation<any> | import("./core").NopeOperation<any>;
|
||||
export declare const $lte: (params: any, owneryQuery: any, options: Options, name: string) => Operation<any> | import("./core").NopeOperation<any>;
|
||||
export declare const $gt: (params: any, owneryQuery: any, options: Options, name: string) => Operation<any> | import("./core").NopeOperation<any>;
|
||||
export declare const $gte: (params: any, owneryQuery: any, options: Options, name: string) => Operation<any> | import("./core").NopeOperation<any>;
|
||||
export declare const $mod: ([mod, equalsValue]: number[], owneryQuery: Query<any>, options: Options) => EqualsOperation<(b: any) => boolean>;
|
||||
export declare const $exists: (params: boolean, owneryQuery: Query<any>, options: Options, name: string) => $Exists;
|
||||
export declare const $regex: (pattern: string, owneryQuery: Query<any>, options: Options) => EqualsOperation<RegExp>;
|
||||
export declare const $not: (params: any, owneryQuery: Query<any>, options: Options, name: string) => $Not;
|
||||
export declare const $type: (clazz: Function | string, owneryQuery: Query<any>, options: Options) => EqualsOperation<(b: any) => any>;
|
||||
export declare const $and: (params: Query<any>[], ownerQuery: Query<any>, options: Options, name: string) => $And;
|
||||
export declare const $all: (params: Query<any>[], ownerQuery: Query<any>, options: Options, name: string) => $All;
|
||||
export declare const $size: (params: number, ownerQuery: Query<any>, options: Options) => $Size;
|
||||
export declare const $options: () => any;
|
||||
export declare const $where: (params: string | Function, ownerQuery: Query<any>, options: Options) => EqualsOperation<(b: any) => any>;
|
||||
export {};
|
297
node_modules/sift/src/operations.js
generated
vendored
Normal file
297
node_modules/sift/src/operations.js
generated
vendored
Normal file
|
@ -0,0 +1,297 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.$where = exports.$options = exports.$size = exports.$all = exports.$and = exports.$type = exports.$not = exports.$regex = exports.$exists = exports.$mod = exports.$gte = exports.$gt = exports.$lte = exports.$lt = exports.$in = exports.$nin = exports.$elemMatch = exports.$nor = exports.$or = exports.$ne = exports.$eq = exports.$Size = void 0;
|
||||
const core_1 = require("./core");
|
||||
const utils_1 = require("./utils");
|
||||
class $Ne extends core_1.BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() {
|
||||
this._test = (0, core_1.createTester)(this.params, this.options.compare);
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this.keep = true;
|
||||
}
|
||||
next(item) {
|
||||
if (this._test(item)) {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
|
||||
class $ElemMatch extends core_1.BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() {
|
||||
if (!this.params || typeof this.params !== "object") {
|
||||
throw new Error(`Malformed query. $elemMatch must by an object.`);
|
||||
}
|
||||
this._queryOperation = (0, core_1.createQueryOperation)(this.params, this.owneryQuery, this.options);
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._queryOperation.reset();
|
||||
}
|
||||
next(item) {
|
||||
if ((0, utils_1.isArray)(item)) {
|
||||
for (let i = 0, { length } = item; i < length; i++) {
|
||||
// reset query operation since item being tested needs to pass _all_ query
|
||||
// operations for it to be a success
|
||||
this._queryOperation.reset();
|
||||
const child = item[i];
|
||||
this._queryOperation.next(child, i, item, false);
|
||||
this.keep = this.keep || this._queryOperation.keep;
|
||||
}
|
||||
this.done = true;
|
||||
}
|
||||
else {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
class $Not extends core_1.BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() {
|
||||
this._queryOperation = (0, core_1.createQueryOperation)(this.params, this.owneryQuery, this.options);
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._queryOperation.reset();
|
||||
}
|
||||
next(item, key, owner, root) {
|
||||
this._queryOperation.next(item, key, owner, root);
|
||||
this.done = this._queryOperation.done;
|
||||
this.keep = !this._queryOperation.keep;
|
||||
}
|
||||
}
|
||||
class $Size extends core_1.BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() { }
|
||||
next(item) {
|
||||
if ((0, utils_1.isArray)(item) && item.length === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
// if (parent && parent.length === this.params) {
|
||||
// this.done = true;
|
||||
// this.keep = true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
exports.$Size = $Size;
|
||||
const assertGroupNotEmpty = (values) => {
|
||||
if (values.length === 0) {
|
||||
throw new Error(`$and/$or/$nor must be a nonempty array`);
|
||||
}
|
||||
};
|
||||
class $Or extends core_1.BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = false;
|
||||
}
|
||||
init() {
|
||||
assertGroupNotEmpty(this.params);
|
||||
this._ops = this.params.map(op => (0, core_1.createQueryOperation)(op, null, this.options));
|
||||
}
|
||||
reset() {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
for (let i = 0, { length } = this._ops; i < length; i++) {
|
||||
this._ops[i].reset();
|
||||
}
|
||||
}
|
||||
next(item, key, owner) {
|
||||
let done = false;
|
||||
let success = false;
|
||||
for (let i = 0, { length } = this._ops; i < length; i++) {
|
||||
const op = this._ops[i];
|
||||
op.next(item, key, owner);
|
||||
if (op.keep) {
|
||||
done = true;
|
||||
success = op.keep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
}
|
||||
}
|
||||
class $Nor extends $Or {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = false;
|
||||
}
|
||||
next(item, key, owner) {
|
||||
super.next(item, key, owner);
|
||||
this.keep = !this.keep;
|
||||
}
|
||||
}
|
||||
class $In extends core_1.BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
init() {
|
||||
this._testers = this.params.map(value => {
|
||||
if ((0, core_1.containsOperation)(value, this.options)) {
|
||||
throw new Error(`cannot nest $ under ${this.name.toLowerCase()}`);
|
||||
}
|
||||
return (0, core_1.createTester)(value, this.options.compare);
|
||||
});
|
||||
}
|
||||
next(item, key, owner) {
|
||||
let done = false;
|
||||
let success = false;
|
||||
for (let i = 0, { length } = this._testers; i < length; i++) {
|
||||
const test = this._testers[i];
|
||||
if (test(item)) {
|
||||
done = true;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
}
|
||||
}
|
||||
class $Nin extends core_1.BaseOperation {
|
||||
constructor(params, ownerQuery, options, name) {
|
||||
super(params, ownerQuery, options, name);
|
||||
this.propop = true;
|
||||
this._in = new $In(params, ownerQuery, options, name);
|
||||
}
|
||||
next(item, key, owner, root) {
|
||||
this._in.next(item, key, owner);
|
||||
if ((0, utils_1.isArray)(owner) && !root) {
|
||||
if (this._in.keep) {
|
||||
this.keep = false;
|
||||
this.done = true;
|
||||
}
|
||||
else if (key == owner.length - 1) {
|
||||
this.keep = true;
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.keep = !this._in.keep;
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._in.reset();
|
||||
}
|
||||
}
|
||||
class $Exists extends core_1.BaseOperation {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
this.propop = true;
|
||||
}
|
||||
next(item, key, owner) {
|
||||
if (owner.hasOwnProperty(key) === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
class $And extends core_1.NamedGroupOperation {
|
||||
constructor(params, owneryQuery, options, name) {
|
||||
super(params, owneryQuery, options, params.map(query => (0, core_1.createQueryOperation)(query, owneryQuery, options)), name);
|
||||
this.propop = false;
|
||||
assertGroupNotEmpty(params);
|
||||
}
|
||||
next(item, key, owner, root) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
}
|
||||
}
|
||||
class $All extends core_1.NamedGroupOperation {
|
||||
constructor(params, owneryQuery, options, name) {
|
||||
super(params, owneryQuery, options, params.map(query => (0, core_1.createQueryOperation)(query, owneryQuery, options)), name);
|
||||
this.propop = true;
|
||||
}
|
||||
next(item, key, owner, root) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
}
|
||||
}
|
||||
const $eq = (params, owneryQuery, options) => new core_1.EqualsOperation(params, owneryQuery, options);
|
||||
exports.$eq = $eq;
|
||||
const $ne = (params, owneryQuery, options, name) => new $Ne(params, owneryQuery, options, name);
|
||||
exports.$ne = $ne;
|
||||
const $or = (params, owneryQuery, options, name) => new $Or(params, owneryQuery, options, name);
|
||||
exports.$or = $or;
|
||||
const $nor = (params, owneryQuery, options, name) => new $Nor(params, owneryQuery, options, name);
|
||||
exports.$nor = $nor;
|
||||
const $elemMatch = (params, owneryQuery, options, name) => new $ElemMatch(params, owneryQuery, options, name);
|
||||
exports.$elemMatch = $elemMatch;
|
||||
const $nin = (params, owneryQuery, options, name) => new $Nin(params, owneryQuery, options, name);
|
||||
exports.$nin = $nin;
|
||||
const $in = (params, owneryQuery, options, name) => {
|
||||
return new $In(params, owneryQuery, options, name);
|
||||
};
|
||||
exports.$in = $in;
|
||||
exports.$lt = (0, core_1.numericalOperation)(params => b => b < params);
|
||||
exports.$lte = (0, core_1.numericalOperation)(params => b => b <= params);
|
||||
exports.$gt = (0, core_1.numericalOperation)(params => b => b > params);
|
||||
exports.$gte = (0, core_1.numericalOperation)(params => b => b >= params);
|
||||
const $mod = ([mod, equalsValue], owneryQuery, options) => new core_1.EqualsOperation(b => (0, utils_1.comparable)(b) % mod === equalsValue, owneryQuery, options);
|
||||
exports.$mod = $mod;
|
||||
const $exists = (params, owneryQuery, options, name) => new $Exists(params, owneryQuery, options, name);
|
||||
exports.$exists = $exists;
|
||||
const $regex = (pattern, owneryQuery, options) => new core_1.EqualsOperation(new RegExp(pattern, owneryQuery.$options), owneryQuery, options);
|
||||
exports.$regex = $regex;
|
||||
const $not = (params, owneryQuery, options, name) => new $Not(params, owneryQuery, options, name);
|
||||
exports.$not = $not;
|
||||
const typeAliases = {
|
||||
number: v => typeof v === "number",
|
||||
string: v => typeof v === "string",
|
||||
bool: v => typeof v === "boolean",
|
||||
array: v => Array.isArray(v),
|
||||
null: v => v === null,
|
||||
timestamp: v => v instanceof Date
|
||||
};
|
||||
const $type = (clazz, owneryQuery, options) => new core_1.EqualsOperation(b => {
|
||||
if (typeof clazz === "string") {
|
||||
if (!typeAliases[clazz]) {
|
||||
throw new Error(`Type alias does not exist`);
|
||||
}
|
||||
return typeAliases[clazz](b);
|
||||
}
|
||||
return b != null ? b instanceof clazz || b.constructor === clazz : false;
|
||||
}, owneryQuery, options);
|
||||
exports.$type = $type;
|
||||
const $and = (params, ownerQuery, options, name) => new $And(params, ownerQuery, options, name);
|
||||
exports.$and = $and;
|
||||
const $all = (params, ownerQuery, options, name) => new $All(params, ownerQuery, options, name);
|
||||
exports.$all = $all;
|
||||
const $size = (params, ownerQuery, options) => new $Size(params, ownerQuery, options, "$size");
|
||||
exports.$size = $size;
|
||||
const $options = () => null;
|
||||
exports.$options = $options;
|
||||
const $where = (params, ownerQuery, options) => {
|
||||
let test;
|
||||
if ((0, utils_1.isFunction)(params)) {
|
||||
test = params;
|
||||
}
|
||||
else if (!process.env.CSP_ENABLED) {
|
||||
test = new Function("obj", "return " + params);
|
||||
}
|
||||
else {
|
||||
throw new Error(`In CSP mode, sift does not support strings in "$where" condition`);
|
||||
}
|
||||
return new core_1.EqualsOperation(b => test.bind(b)(b), ownerQuery, options);
|
||||
};
|
||||
exports.$where = $where;
|
||||
//# sourceMappingURL=operations.js.map
|
1
node_modules/sift/src/operations.js.map
generated
vendored
Normal file
1
node_modules/sift/src/operations.js.map
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
411
node_modules/sift/src/operations.ts
generated
vendored
Normal file
411
node_modules/sift/src/operations.ts
generated
vendored
Normal file
|
@ -0,0 +1,411 @@
|
|||
import {
|
||||
BaseOperation,
|
||||
EqualsOperation,
|
||||
Options,
|
||||
createTester,
|
||||
Tester,
|
||||
createQueryOperation,
|
||||
QueryOperation,
|
||||
Operation,
|
||||
Query,
|
||||
NamedGroupOperation,
|
||||
numericalOperation,
|
||||
containsOperation,
|
||||
NamedOperation
|
||||
} from "./core";
|
||||
import { Key, comparable, isFunction, isArray } from "./utils";
|
||||
|
||||
class $Ne extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
private _test: Tester;
|
||||
init() {
|
||||
this._test = createTester(this.params, this.options.compare);
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this.keep = true;
|
||||
}
|
||||
next(item: any) {
|
||||
if (this._test(item)) {
|
||||
this.done = true;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// https://docs.mongodb.com/manual/reference/operator/query/elemMatch/
|
||||
class $ElemMatch extends BaseOperation<Query<any>> {
|
||||
readonly propop = true;
|
||||
private _queryOperation: QueryOperation<any>;
|
||||
init() {
|
||||
if (!this.params || typeof this.params !== "object") {
|
||||
throw new Error(`Malformed query. $elemMatch must by an object.`);
|
||||
}
|
||||
this._queryOperation = createQueryOperation(
|
||||
this.params,
|
||||
this.owneryQuery,
|
||||
this.options
|
||||
);
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._queryOperation.reset();
|
||||
}
|
||||
next(item: any) {
|
||||
if (isArray(item)) {
|
||||
for (let i = 0, { length } = item; i < length; i++) {
|
||||
// reset query operation since item being tested needs to pass _all_ query
|
||||
// operations for it to be a success
|
||||
this._queryOperation.reset();
|
||||
|
||||
const child = item[i];
|
||||
this._queryOperation.next(child, i, item, false);
|
||||
this.keep = this.keep || this._queryOperation.keep;
|
||||
}
|
||||
this.done = true;
|
||||
} else {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class $Not extends BaseOperation<Query<any>> {
|
||||
readonly propop = true;
|
||||
private _queryOperation: QueryOperation<any>;
|
||||
init() {
|
||||
this._queryOperation = createQueryOperation(
|
||||
this.params,
|
||||
this.owneryQuery,
|
||||
this.options
|
||||
);
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._queryOperation.reset();
|
||||
}
|
||||
next(item: any, key: Key, owner: any, root: boolean) {
|
||||
this._queryOperation.next(item, key, owner, root);
|
||||
this.done = this._queryOperation.done;
|
||||
this.keep = !this._queryOperation.keep;
|
||||
}
|
||||
}
|
||||
|
||||
export class $Size extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
init() {}
|
||||
next(item) {
|
||||
if (isArray(item) && item.length === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
// if (parent && parent.length === this.params) {
|
||||
// this.done = true;
|
||||
// this.keep = true;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
const assertGroupNotEmpty = (values: any[]) => {
|
||||
if (values.length === 0) {
|
||||
throw new Error(`$and/$or/$nor must be a nonempty array`);
|
||||
}
|
||||
};
|
||||
|
||||
class $Or extends BaseOperation<any> {
|
||||
readonly propop = false;
|
||||
private _ops: Operation<any>[];
|
||||
init() {
|
||||
assertGroupNotEmpty(this.params);
|
||||
this._ops = this.params.map(op =>
|
||||
createQueryOperation(op, null, this.options)
|
||||
);
|
||||
}
|
||||
reset() {
|
||||
this.done = false;
|
||||
this.keep = false;
|
||||
for (let i = 0, { length } = this._ops; i < length; i++) {
|
||||
this._ops[i].reset();
|
||||
}
|
||||
}
|
||||
next(item: any, key: Key, owner: any) {
|
||||
let done = false;
|
||||
let success = false;
|
||||
for (let i = 0, { length } = this._ops; i < length; i++) {
|
||||
const op = this._ops[i];
|
||||
op.next(item, key, owner);
|
||||
if (op.keep) {
|
||||
done = true;
|
||||
success = op.keep;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
}
|
||||
}
|
||||
|
||||
class $Nor extends $Or {
|
||||
readonly propop = false;
|
||||
next(item: any, key: Key, owner: any) {
|
||||
super.next(item, key, owner);
|
||||
this.keep = !this.keep;
|
||||
}
|
||||
}
|
||||
|
||||
class $In extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
private _testers: Tester[];
|
||||
init() {
|
||||
this._testers = this.params.map(value => {
|
||||
if (containsOperation(value, this.options)) {
|
||||
throw new Error(`cannot nest $ under ${this.name.toLowerCase()}`);
|
||||
}
|
||||
return createTester(value, this.options.compare);
|
||||
});
|
||||
}
|
||||
next(item: any, key: Key, owner: any) {
|
||||
let done = false;
|
||||
let success = false;
|
||||
for (let i = 0, { length } = this._testers; i < length; i++) {
|
||||
const test = this._testers[i];
|
||||
if (test(item)) {
|
||||
done = true;
|
||||
success = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this.keep = success;
|
||||
this.done = done;
|
||||
}
|
||||
}
|
||||
|
||||
class $Nin extends BaseOperation<any> {
|
||||
readonly propop = true;
|
||||
private _in: $In;
|
||||
constructor(params: any, ownerQuery: any, options: Options, name: string) {
|
||||
super(params, ownerQuery, options, name);
|
||||
this._in = new $In(params, ownerQuery, options, name);
|
||||
}
|
||||
next(item: any, key: Key, owner: any, root: boolean) {
|
||||
this._in.next(item, key, owner);
|
||||
|
||||
if (isArray(owner) && !root) {
|
||||
if (this._in.keep) {
|
||||
this.keep = false;
|
||||
this.done = true;
|
||||
} else if (key == owner.length - 1) {
|
||||
this.keep = true;
|
||||
this.done = true;
|
||||
}
|
||||
} else {
|
||||
this.keep = !this._in.keep;
|
||||
this.done = true;
|
||||
}
|
||||
}
|
||||
reset() {
|
||||
super.reset();
|
||||
this._in.reset();
|
||||
}
|
||||
}
|
||||
|
||||
class $Exists extends BaseOperation<boolean> {
|
||||
readonly propop = true;
|
||||
next(item: any, key: Key, owner: any) {
|
||||
if (owner.hasOwnProperty(key) === this.params) {
|
||||
this.done = true;
|
||||
this.keep = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class $And extends NamedGroupOperation {
|
||||
readonly propop = false;
|
||||
constructor(
|
||||
params: Query<any>[],
|
||||
owneryQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) {
|
||||
super(
|
||||
params,
|
||||
owneryQuery,
|
||||
options,
|
||||
params.map(query => createQueryOperation(query, owneryQuery, options)),
|
||||
name
|
||||
);
|
||||
|
||||
assertGroupNotEmpty(params);
|
||||
}
|
||||
next(item: any, key: Key, owner: any, root: boolean) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
}
|
||||
}
|
||||
|
||||
class $All extends NamedGroupOperation {
|
||||
readonly propop = true;
|
||||
constructor(
|
||||
params: Query<any>[],
|
||||
owneryQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) {
|
||||
super(
|
||||
params,
|
||||
owneryQuery,
|
||||
options,
|
||||
params.map(query => createQueryOperation(query, owneryQuery, options)),
|
||||
name
|
||||
);
|
||||
}
|
||||
next(item: any, key: Key, owner: any, root: boolean) {
|
||||
this.childrenNext(item, key, owner, root);
|
||||
}
|
||||
}
|
||||
|
||||
export const $eq = (params: any, owneryQuery: Query<any>, options: Options) =>
|
||||
new EqualsOperation(params, owneryQuery, options);
|
||||
export const $ne = (
|
||||
params: any,
|
||||
owneryQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) => new $Ne(params, owneryQuery, options, name);
|
||||
export const $or = (
|
||||
params: Query<any>[],
|
||||
owneryQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) => new $Or(params, owneryQuery, options, name);
|
||||
export const $nor = (
|
||||
params: Query<any>[],
|
||||
owneryQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) => new $Nor(params, owneryQuery, options, name);
|
||||
export const $elemMatch = (
|
||||
params: any,
|
||||
owneryQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) => new $ElemMatch(params, owneryQuery, options, name);
|
||||
export const $nin = (
|
||||
params: any,
|
||||
owneryQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) => new $Nin(params, owneryQuery, options, name);
|
||||
export const $in = (
|
||||
params: any,
|
||||
owneryQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) => {
|
||||
return new $In(params, owneryQuery, options, name);
|
||||
};
|
||||
|
||||
export const $lt = numericalOperation(params => b => b < params);
|
||||
export const $lte = numericalOperation(params => b => b <= params);
|
||||
export const $gt = numericalOperation(params => b => b > params);
|
||||
export const $gte = numericalOperation(params => b => b >= params);
|
||||
export const $mod = (
|
||||
[mod, equalsValue]: number[],
|
||||
owneryQuery: Query<any>,
|
||||
options: Options
|
||||
) =>
|
||||
new EqualsOperation(
|
||||
b => comparable(b) % mod === equalsValue,
|
||||
owneryQuery,
|
||||
options
|
||||
);
|
||||
export const $exists = (
|
||||
params: boolean,
|
||||
owneryQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) => new $Exists(params, owneryQuery, options, name);
|
||||
export const $regex = (
|
||||
pattern: string,
|
||||
owneryQuery: Query<any>,
|
||||
options: Options
|
||||
) =>
|
||||
new EqualsOperation(
|
||||
new RegExp(pattern, owneryQuery.$options),
|
||||
owneryQuery,
|
||||
options
|
||||
);
|
||||
export const $not = (
|
||||
params: any,
|
||||
owneryQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) => new $Not(params, owneryQuery, options, name);
|
||||
|
||||
const typeAliases = {
|
||||
number: v => typeof v === "number",
|
||||
string: v => typeof v === "string",
|
||||
bool: v => typeof v === "boolean",
|
||||
array: v => Array.isArray(v),
|
||||
null: v => v === null,
|
||||
timestamp: v => v instanceof Date
|
||||
};
|
||||
|
||||
export const $type = (
|
||||
clazz: Function | string,
|
||||
owneryQuery: Query<any>,
|
||||
options: Options
|
||||
) =>
|
||||
new EqualsOperation(
|
||||
b => {
|
||||
if (typeof clazz === "string") {
|
||||
if (!typeAliases[clazz]) {
|
||||
throw new Error(`Type alias does not exist`);
|
||||
}
|
||||
|
||||
return typeAliases[clazz](b);
|
||||
}
|
||||
|
||||
return b != null ? b instanceof clazz || b.constructor === clazz : false;
|
||||
},
|
||||
owneryQuery,
|
||||
options
|
||||
);
|
||||
export const $and = (
|
||||
params: Query<any>[],
|
||||
ownerQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) => new $And(params, ownerQuery, options, name);
|
||||
|
||||
export const $all = (
|
||||
params: Query<any>[],
|
||||
ownerQuery: Query<any>,
|
||||
options: Options,
|
||||
name: string
|
||||
) => new $All(params, ownerQuery, options, name);
|
||||
export const $size = (
|
||||
params: number,
|
||||
ownerQuery: Query<any>,
|
||||
options: Options
|
||||
) => new $Size(params, ownerQuery, options, "$size");
|
||||
export const $options = () => null;
|
||||
export const $where = (
|
||||
params: string | Function,
|
||||
ownerQuery: Query<any>,
|
||||
options: Options
|
||||
) => {
|
||||
let test;
|
||||
|
||||
if (isFunction(params)) {
|
||||
test = params;
|
||||
} else if (!process.env.CSP_ENABLED) {
|
||||
test = new Function("obj", "return " + params);
|
||||
} else {
|
||||
throw new Error(
|
||||
`In CSP mode, sift does not support strings in "$where" condition`
|
||||
);
|
||||
}
|
||||
|
||||
return new EqualsOperation(b => test.bind(b)(b), ownerQuery, options);
|
||||
};
|
9
node_modules/sift/src/utils.d.ts
generated
vendored
Normal file
9
node_modules/sift/src/utils.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
export declare type Key = string | number;
|
||||
export declare type Comparator = (a: any, b: any) => boolean;
|
||||
export declare const typeChecker: <TType>(type: any) => (value: any) => value is TType;
|
||||
export declare const comparable: (value: any) => any;
|
||||
export declare const isArray: (value: any) => value is any[];
|
||||
export declare const isObject: (value: any) => value is Object;
|
||||
export declare const isFunction: (value: any) => value is Function;
|
||||
export declare const isVanillaObject: (value: any) => boolean;
|
||||
export declare const equals: (a: any, b: any) => boolean;
|
70
node_modules/sift/src/utils.js
generated
vendored
Normal file
70
node_modules/sift/src/utils.js
generated
vendored
Normal file
|
@ -0,0 +1,70 @@
|
|||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.equals = exports.isVanillaObject = exports.isFunction = exports.isObject = exports.isArray = exports.comparable = exports.typeChecker = void 0;
|
||||
const typeChecker = (type) => {
|
||||
const typeString = "[object " + type + "]";
|
||||
return function (value) {
|
||||
return getClassName(value) === typeString;
|
||||
};
|
||||
};
|
||||
exports.typeChecker = typeChecker;
|
||||
const getClassName = value => Object.prototype.toString.call(value);
|
||||
const comparable = (value) => {
|
||||
if (value instanceof Date) {
|
||||
return value.getTime();
|
||||
}
|
||||
else if ((0, exports.isArray)(value)) {
|
||||
return value.map(exports.comparable);
|
||||
}
|
||||
else if (value && typeof value.toJSON === "function") {
|
||||
return value.toJSON();
|
||||
}
|
||||
return value;
|
||||
};
|
||||
exports.comparable = comparable;
|
||||
exports.isArray = (0, exports.typeChecker)("Array");
|
||||
exports.isObject = (0, exports.typeChecker)("Object");
|
||||
exports.isFunction = (0, exports.typeChecker)("Function");
|
||||
const isVanillaObject = value => {
|
||||
return (value &&
|
||||
(value.constructor === Object ||
|
||||
value.constructor === Array ||
|
||||
value.constructor.toString() === "function Object() { [native code] }" ||
|
||||
value.constructor.toString() === "function Array() { [native code] }") &&
|
||||
!value.toJSON);
|
||||
};
|
||||
exports.isVanillaObject = isVanillaObject;
|
||||
const equals = (a, b) => {
|
||||
if (a == null && a == b) {
|
||||
return true;
|
||||
}
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
|
||||
return false;
|
||||
}
|
||||
if ((0, exports.isArray)(a)) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0, { length } = a; i < length; i++) {
|
||||
if (!(0, exports.equals)(a[i], b[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if ((0, exports.isObject)(a)) {
|
||||
if (Object.keys(a).length !== Object.keys(b).length) {
|
||||
return false;
|
||||
}
|
||||
for (const key in a) {
|
||||
if (!(0, exports.equals)(a[key], b[key]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
exports.equals = equals;
|
||||
//# sourceMappingURL=utils.js.map
|
1
node_modules/sift/src/utils.js.map
generated
vendored
Normal file
1
node_modules/sift/src/utils.js.map
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{"version":3,"file":"utils.js","sourceRoot":"","sources":["utils.ts"],"names":[],"mappings":";;;AAEO,MAAM,WAAW,GAAG,CAAQ,IAAI,EAAE,EAAE;IACzC,MAAM,UAAU,GAAG,UAAU,GAAG,IAAI,GAAG,GAAG,CAAC;IAC3C,OAAO,UAAS,KAAK;QACnB,OAAO,YAAY,CAAC,KAAK,CAAC,KAAK,UAAU,CAAC;IAC5C,CAAC,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,WAAW,eAKtB;AAEF,MAAM,YAAY,GAAG,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAE7D,MAAM,UAAU,GAAG,CAAC,KAAU,EAAE,EAAE;IACvC,IAAI,KAAK,YAAY,IAAI,EAAE;QACzB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;KACxB;SAAM,IAAI,IAAA,eAAO,EAAC,KAAK,CAAC,EAAE;QACzB,OAAO,KAAK,CAAC,GAAG,CAAC,kBAAU,CAAC,CAAC;KAC9B;SAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,MAAM,KAAK,UAAU,EAAE;QACtD,OAAO,KAAK,CAAC,MAAM,EAAE,CAAC;KACvB;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAVW,QAAA,UAAU,cAUrB;AAEW,QAAA,OAAO,GAAG,IAAA,mBAAW,EAAa,OAAO,CAAC,CAAC;AAC3C,QAAA,QAAQ,GAAG,IAAA,mBAAW,EAAS,QAAQ,CAAC,CAAC;AACzC,QAAA,UAAU,GAAG,IAAA,mBAAW,EAAW,UAAU,CAAC,CAAC;AACrD,MAAM,eAAe,GAAG,KAAK,CAAC,EAAE;IACrC,OAAO,CACL,KAAK;QACL,CAAC,KAAK,CAAC,WAAW,KAAK,MAAM;YAC3B,KAAK,CAAC,WAAW,KAAK,KAAK;YAC3B,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,qCAAqC;YACtE,KAAK,CAAC,WAAW,CAAC,QAAQ,EAAE,KAAK,oCAAoC,CAAC;QACxE,CAAC,KAAK,CAAC,MAAM,CACd,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,eAAe,mBAS1B;AAEK,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;IAC7B,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE;QACvB,OAAO,IAAI,CAAC;KACb;IACD,IAAI,CAAC,KAAK,CAAC,EAAE;QACX,OAAO,IAAI,CAAC;KACb;IAED,IAAI,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE;QAC3E,OAAO,KAAK,CAAC;KACd;IAED,IAAI,IAAA,eAAO,EAAC,CAAC,CAAC,EAAE;QACd,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,EAAE;YACzB,OAAO,KAAK,CAAC;SACd;QACD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE;YAC/C,IAAI,CAAC,IAAA,cAAM,EAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;SACvC;QACD,OAAO,IAAI,CAAC;KACb;SAAM,IAAI,IAAA,gBAAQ,EAAC,CAAC,CAAC,EAAE;QACtB,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE;YACnD,OAAO,KAAK,CAAC;SACd;QACD,KAAK,MAAM,GAAG,IAAI,CAAC,EAAE;YACnB,IAAI,CAAC,IAAA,cAAM,EAAC,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;SAC3C;QACD,OAAO,IAAI,CAAC;KACb;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AA9BW,QAAA,MAAM,UA8BjB"}
|
68
node_modules/sift/src/utils.ts
generated
vendored
Normal file
68
node_modules/sift/src/utils.ts
generated
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
export type Key = string | number;
|
||||
export type Comparator = (a, b) => boolean;
|
||||
export const typeChecker = <TType>(type) => {
|
||||
const typeString = "[object " + type + "]";
|
||||
return function(value): value is TType {
|
||||
return getClassName(value) === typeString;
|
||||
};
|
||||
};
|
||||
|
||||
const getClassName = value => Object.prototype.toString.call(value);
|
||||
|
||||
export const comparable = (value: any) => {
|
||||
if (value instanceof Date) {
|
||||
return value.getTime();
|
||||
} else if (isArray(value)) {
|
||||
return value.map(comparable);
|
||||
} else if (value && typeof value.toJSON === "function") {
|
||||
return value.toJSON();
|
||||
}
|
||||
|
||||
return value;
|
||||
};
|
||||
|
||||
export const isArray = typeChecker<Array<any>>("Array");
|
||||
export const isObject = typeChecker<Object>("Object");
|
||||
export const isFunction = typeChecker<Function>("Function");
|
||||
export const isVanillaObject = value => {
|
||||
return (
|
||||
value &&
|
||||
(value.constructor === Object ||
|
||||
value.constructor === Array ||
|
||||
value.constructor.toString() === "function Object() { [native code] }" ||
|
||||
value.constructor.toString() === "function Array() { [native code] }") &&
|
||||
!value.toJSON
|
||||
);
|
||||
};
|
||||
|
||||
export const equals = (a, b) => {
|
||||
if (a == null && a == b) {
|
||||
return true;
|
||||
}
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (Object.prototype.toString.call(a) !== Object.prototype.toString.call(b)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isArray(a)) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0, { length } = a; i < length; i++) {
|
||||
if (!equals(a[i], b[i])) return false;
|
||||
}
|
||||
return true;
|
||||
} else if (isObject(a)) {
|
||||
if (Object.keys(a).length !== Object.keys(b).length) {
|
||||
return false;
|
||||
}
|
||||
for (const key in a) {
|
||||
if (!equals(a[key], b[key])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue