Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: Add Expression Typings to Pipeline Stages #11370

Merged
merged 32 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2582959
initial
Uzlopak Feb 9, 2022
4b1e8e8
fix linting issues
Uzlopak Feb 9, 2022
d330145
fix linter error
Uzlopak Feb 9, 2022
f0ab5c8
Arithmetic Expression Operators
Uzlopak Feb 9, 2022
d0f466f
Text Expression Operators
Uzlopak Feb 9, 2022
fdada6b
+ Trigonometry Expression Operators
Uzlopak Feb 9, 2022
0291e9b
add comment
Uzlopak Feb 9, 2022
c667b50
add version info
Uzlopak Feb 9, 2022
519c314
only add and subtract can handle dates
Uzlopak Feb 9, 2022
742c951
add DateExpressionOperators
Uzlopak Feb 10, 2022
e2d1e6a
add boolean and comparison
Uzlopak Feb 10, 2022
29a8837
add ConditionalExpressionOperator
Uzlopak Feb 10, 2022
a8f26b4
add ArrayExpression
Uzlopak Feb 10, 2022
a17370e
some minor changes
Uzlopak Feb 10, 2022
ebcad04
add StringExpressionOperators
Uzlopak Feb 10, 2022
40acd28
Merge branch 'master' into types-expression
Uzlopak Feb 16, 2022
06f879e
Merge branch 'main' into types-expression
Uzlopak May 30, 2022
15dcd8e
remove duplicate Expression.test.ts
Uzlopak May 30, 2022
8f3f784
add more
Uzlopak May 30, 2022
be4a808
add Set Expression Operators
Uzlopak May 30, 2022
7cef3c5
add Window Expressions
Uzlopak May 30, 2022
e8e6842
add type expressions
Uzlopak May 31, 2022
08270f4
add DataSizeOperator
Uzlopak May 31, 2022
1ef01c0
add last operation set
Uzlopak May 31, 2022
238bb90
add some tests
Uzlopak May 31, 2022
f57e007
add tests, fix typings
Uzlopak May 31, 2022
510412f
add more tests, fix more
Uzlopak May 31, 2022
4635fcd
fix more
Uzlopak May 31, 2022
c94d2bb
fix linting
Uzlopak May 31, 2022
16deac9
auto format .eslintrc.json
Uzlopak Jun 2, 2022
365f39f
fix .eslint.json and linting errors
Uzlopak Jun 2, 2022
e3dca30
Merge branch 'master' into types-expression
Uzlopak Jun 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"docs",
"tools",
"dist",
"website.js",
"test/files/*",
"benchmarks"
],
Expand All @@ -22,6 +23,16 @@
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/triple-slash-reference": "off",
"spaced-comment": ["error", "always", {
"block": {
"markers": [
"!"
],
"balanced": true
},
"markers": ["/"]
}],
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/no-unused-vars": "off",
Expand Down
105 changes: 105 additions & 0 deletions test/types/Expression.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import type { Expression } from 'mongoose';
import { expectError, expectType } from 'tsd';

// ArithmeticExpressionOperators

const abs1: Expression = { $abs: '$date' };
const abs2: Expression = { $abs: { $add: ['$price', '$fee'] } };

const add1: Expression = { $add: ['$date', 3 * 24 * 60 * 60000] };
const add2: Expression = { $add: ['$price', '$fee'] };

const ceil: Expression = { $ceil: '$value' };

const divide: Expression = { $divide: ['$hours', 8] };

const exp: Expression = { $exp: '$rate' };

const floor: Expression = { $floor: '$value' };

const ln: Expression = { $ln: '$sales' };

const log: Expression = { $log: ['$positiveInt', 2] };

const log10: Expression = { $log10: '$H3O' };

const mod: Expression = { $mod: ['$hours', '$tasks'] };

const multiply1: Expression = { $multiply: ['$price', '$quantity'] };
const multiply2: Expression = { $multiply: ['$price', '$quantity', '$quantity'] };

const pow: Expression = { $pow: [{ $stdDevPop: '$scores.score' }, 2] };

const round1: Expression = { $round: ['$value'] };
const round2: Expression = { $round: ['$value', 1] };
const round3: Expression = { $round: ['$value', -1] };

const sqrt: Expression = {
$sqrt: {
$add: [
{ $pow: [{ $subtract: ['$p2.y', '$p1.y'] }, 2] },
{ $pow: [{ $subtract: ['$p2.x', '$p1.x'] }, 2] }
]
}
};

const subtract1: Expression = { $subtract: ['$date', 3 * 24 * 60 * 60000] };
const subtract2: Expression = { $subtract: ['$price', '$fee'] };

const trunc1: Expression = { $trunc: ['$value', 1] };
const trunc2: Expression = { $trunc: ['$value'] };

// TextExpressionOperators

const meta1: Expression = { $meta: 'textScore' };
const meta2: Expression = { $meta: 'indexKey' };

// TrigonometryExpressionOperators
const tanh1: Expression = { $tanh: { $degreesToRadians: '$angle' } };

const isoWeekYear: Expression = { $isoWeekYear: { date: new Date('2017-01-02T00:00:00Z'), timezone: '-0500' } };

const millisecond1: Expression = { $millisecond: new Date('2016-01-01') };
const millisecond2: Expression = { $millisecond: { date: new Date('Jan 7, 2003') } };
const millisecond3: Expression = { $millisecond: { date: new Date('August 14, 2011'), timezone: 'America/Chicago' } };
const millisecond4: Expression = { $millisecond: '$date' };

const dateTrunc: Expression = {
$dateTrunc: {
date: '$orderDate', unit: 'week', binSize: 2,
timezone: 'America/Los_Angeles', startOfWeek: 'Monday'
}
};


const yearMonthDayUTCDateToString: Expression = { $dateToString: { format: '%Y-%m-%d', date: '$date' } };
const timewithOffsetNYDateToString: Expression = { $dateToString: { format: '%H:%M:%S:%L%z', date: '$date', timezone: 'America/New_York' } };
const timewithOffset430DateToString: Expression = { $dateToString: { format: '%H:%M:%S:%L%z', date: '$date', timezone: '+04:30' } };
const minutesOffsetNYDateToString: Expression = { $dateToString: { format: '%Z', date: '$date', timezone: 'America/New_York' } };
const minutesOffset430DateToString: Expression = { $dateToString: { format: '%Z', date: '$date', timezone: '+04:30' } };

const dateSubtract1: Expression = {
$dateSubtract:
{
startDate: new Date('2021-03-31T12:10:05Z'),
unit: 'month',
amount: 1
}
};

const dateSubtract2: Expression = {
$dateSubtract:
{
startDate: '$logout',
unit: 'hour',
amount: 3,
timezone: 'Europe/Amsterdam'
}
};

const dateFromParts: Expression = {
$dateFromParts: {
year: 'asdf',
hour: 'asdf'
}
};