-
Notifications
You must be signed in to change notification settings - Fork 265
draft: augment yaml definitions with test schema #1659
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
Draft
nirinchev
wants to merge
16
commits into
mongodb:v2.x
Choose a base branch
from
mongodb-js:ni/devtools-enhancements
base: v2.x
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
39224b6
WIP
addaleax 56a801b
add tests schema
nirinchev 7e64509
Revert "add tests schema"
nirinchev 07cd9fc
run yamlfix
nirinchev 7cb2274
Reformat after running the js generator
nirinchev cb2571c
generate schema for accumulators
nirinchev e28803d
add test schemas for expressions
nirinchev fd06dd6
add test schemas for query
nirinchev 64a44ad
add search schemas
nirinchev 6a34eda
schema for stages
nirinchev cc2c832
Update with some refs
nirinchev c027132
type tweaks
nirinchev 3602303
fix names to align with docs
nirinchev 7978e4f
regenerate test schemas
nirinchev b9b1d19
add searchHighlight as a type
nirinchev c2b1ee5
Add schema for first/last
nirinchev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
allow_duplicate_keys = false | ||
comments_min_spaces_from_content = 1 | ||
sequence_style = "block_style" | ||
indent_mapping = 4 | ||
indent_offset = 4 | ||
indent_sequence = 6 | ||
none_representation = "~" | ||
explicit_start = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,132 +1,149 @@ | ||
# $schema: ../schema.json | ||
name: $accumulator | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/' | ||
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/ | ||
type: | ||
- accumulator | ||
encode: object | ||
description: | | ||
Defines a custom accumulator function. | ||
New in MongoDB 4.4. | ||
arguments: | ||
- | ||
name: init | ||
type: | ||
- javascript | ||
description: | | ||
Function used to initialize the state. The init function receives its arguments from the initArgs array expression. You can specify the function definition as either BSON type Code or String. | ||
- | ||
name: initArgs | ||
type: | ||
- resolvesToArray | ||
optional: true | ||
description: | | ||
Arguments passed to the init function. | ||
- | ||
name: accumulate | ||
type: | ||
- javascript | ||
description: | | ||
Function used to accumulate documents. The accumulate function receives its arguments from the current state and accumulateArgs array expression. The result of the accumulate function becomes the new state. You can specify the function definition as either BSON type Code or String. | ||
- | ||
name: accumulateArgs | ||
type: | ||
- resolvesToArray | ||
description: | | ||
Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. | ||
- | ||
name: merge | ||
type: | ||
- javascript | ||
description: | | ||
Function used to merge two internal states. merge must be either a String or Code BSON type. merge returns the combined result of the two merged states. For information on when the merge function is called, see Merge Two States with $merge. | ||
- | ||
name: finalize | ||
type: | ||
- javascript | ||
optional: true | ||
description: | | ||
Function used to update the result of the accumulation. | ||
- | ||
name: lang | ||
type: | ||
- string | ||
description: | | ||
The language used in the $accumulator code. | ||
|
||
- name: init | ||
type: | ||
- javascript | ||
description: | | ||
Function used to initialize the state. The init function receives its arguments from the initArgs array expression. You can specify the function definition as either BSON type Code or String. | ||
- name: initArgs | ||
type: | ||
- resolvesToArray | ||
optional: true | ||
description: | | ||
Arguments passed to the init function. | ||
- name: accumulate | ||
type: | ||
- javascript | ||
description: | | ||
Function used to accumulate documents. The accumulate function receives its arguments from the current state and accumulateArgs array expression. The result of the accumulate function becomes the new state. You can specify the function definition as either BSON type Code or String. | ||
- name: accumulateArgs | ||
type: | ||
- resolvesToArray | ||
description: | | ||
Arguments passed to the accumulate function. You can use accumulateArgs to specify what field value(s) to pass to the accumulate function. | ||
- name: merge | ||
type: | ||
- javascript | ||
description: | | ||
Function used to merge two internal states. merge must be either a String or Code BSON type. merge returns the combined result of the two merged states. For information on when the merge function is called, see Merge Two States with $merge. | ||
- name: finalize | ||
type: | ||
- javascript | ||
optional: true | ||
description: | | ||
Function used to update the result of the accumulation. | ||
- name: lang | ||
type: | ||
- string | ||
description: | | ||
The language used in the $accumulator code. | ||
tests: | ||
- | ||
name: 'Use $accumulator to Implement the $avg Operator' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use--accumulator-to-implement-the--avg-operator' | ||
pipeline: | ||
- | ||
$group: | ||
_id: '$author' | ||
avgCopies: | ||
$accumulator: | ||
init: | ||
$code: |- | ||
function() { | ||
return { count: 0, sum: 0 } | ||
- name: Use $accumulator to Implement the $avg Operator | ||
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use--accumulator-to-implement-the--avg-operator | ||
pipeline: | ||
- $group: | ||
_id: $author | ||
avgCopies: | ||
$accumulator: | ||
init: | ||
$code: |- | ||
function() { | ||
return { count: 0, sum: 0 } | ||
} | ||
accumulate: | ||
$code: |- | ||
function(state, numCopies) { | ||
return { count: state.count + 1, sum: state.sum + numCopies } | ||
} | ||
accumulateArgs: | ||
- $copies | ||
merge: | ||
$code: |- | ||
function(state1, state2) { | ||
return { | ||
count: state1.count + state2.count, | ||
sum: state1.sum + state2.sum | ||
} | ||
accumulate: | ||
$code: |- | ||
function(state, numCopies) { | ||
return { count: state.count + 1, sum: state.sum + numCopies } | ||
} | ||
finalize: | ||
$code: |- | ||
function(state) { | ||
return (state.sum / state.count) | ||
} | ||
lang: js | ||
schema: | ||
books: | ||
_id: | ||
types: | ||
- bsonType: Number | ||
title: | ||
types: | ||
- bsonType: String | ||
author: | ||
types: | ||
- bsonType: String | ||
copies: | ||
types: | ||
- bsonType: Number | ||
- name: Use initArgs to Vary the Initial State by Group | ||
link: https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use-initargs-to-vary-the-initial-state-by-group | ||
pipeline: | ||
- $group: | ||
_id: | ||
city: $city | ||
restaurants: | ||
$accumulator: | ||
init: | ||
$code: |- | ||
function(city, userProfileCity) { | ||
return { max: city === userProfileCity ? 3 : 1, restaurants: [] } | ||
} | ||
initArgs: | ||
- $city | ||
- Bettles | ||
accumulate: | ||
$code: |- | ||
function(state, restaurantName) { | ||
if (state.restaurants.length < state.max) { | ||
state.restaurants.push(restaurantName); | ||
} | ||
accumulateArgs: [ "$copies" ] | ||
merge: | ||
$code: |- | ||
function(state1, state2) { | ||
return { | ||
count: state1.count + state2.count, | ||
sum: state1.sum + state2.sum | ||
} | ||
return state; | ||
} | ||
accumulateArgs: | ||
- $name | ||
merge: | ||
$code: |- | ||
function(state1, state2) { | ||
return { | ||
max: state1.max, | ||
restaurants: state1.restaurants.concat(state2.restaurants).slice(0, state1.max) | ||
} | ||
finalize: | ||
$code: |- | ||
function(state) { | ||
return (state.sum / state.count) | ||
} | ||
lang: 'js' | ||
|
||
- | ||
name: 'Use initArgs to Vary the Initial State by Group' | ||
link: 'https://www.mongodb.com/docs/manual/reference/operator/aggregation/accumulator/#use-initargs-to-vary-the-initial-state-by-group' | ||
pipeline: | ||
- | ||
$group: | ||
_id: | ||
city: '$city' | ||
restaurants: | ||
$accumulator: | ||
init: | ||
$code: |- | ||
function(city, userProfileCity) { | ||
return { max: city === userProfileCity ? 3 : 1, restaurants: [] } | ||
} | ||
initArgs: | ||
- '$city' | ||
- 'Bettles' | ||
accumulate: | ||
$code: |- | ||
function(state, restaurantName) { | ||
if (state.restaurants.length < state.max) { | ||
state.restaurants.push(restaurantName); | ||
} | ||
return state; | ||
} | ||
accumulateArgs: ['$name'] | ||
merge: | ||
$code: |- | ||
function(state1, state2) { | ||
return { | ||
max: state1.max, | ||
restaurants: state1.restaurants.concat(state2.restaurants).slice(0, state1.max) | ||
} | ||
} | ||
finalize: | ||
$code: |- | ||
function(state) { | ||
return state.restaurants | ||
} | ||
lang: 'js' | ||
} | ||
finalize: | ||
$code: |- | ||
function(state) { | ||
return state.restaurants | ||
} | ||
lang: js | ||
schema: | ||
restaurants: | ||
_id: | ||
types: | ||
- bsonType: Number | ||
name: | ||
types: | ||
- bsonType: String | ||
city: | ||
types: | ||
- bsonType: String | ||
cuisine: | ||
types: | ||
- bsonType: String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to keep quotes around strings? This style changes make the diff hard to read. Also, I use quotes by default around every string to prevent unexpected parsing rule from Yaml.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey, looks like the quotes usage is inconsistent in these files - I'd be inclined to define a prettier rule and reformat them in a separate PR to make this one less noisy if that'd make sense to you. The reason for these getting removed is that the way we're adding the schema information is parsing the yaml, fetching the schema from the docs, then writing it, which results in the file getting reformatted based on the tool conventions (we use https://www.npmjs.com/package/js-yaml here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, at least
prettier
supports YAML out of the box, so that feels like a great way to remove any formatting preference ambiguity