Skip to content

Conversation

addaleax
Copy link
Collaborator

@addaleax addaleax commented Oct 5, 2020

For results from calls on collections, add metadata about the source of
the returned data (database name, collection name, method, arguments)
so that consumers of the shell can figure out from what source
the result was generated, e.g. in order to understand how to modify
that original data.

This also adds a fake Document type to the ShellResult reported
for e.g. findOne(), so that it is possible to tell those apart
from other plain JavaScript objects, e.g. in order to be able to
know whether the result is a modifiable object in the database or not.

@addaleax
Copy link
Collaborator Author

addaleax commented Oct 5, 2020

I’ve checked that this does make the necessary information available on the VSCode side

Also, the naming of some of the things in here could probably be improved, feel free to make suggestions :)

if (typeof result === 'object' && result !== null) {
const resultSourceInformation: ShellResultSourceInformation = {
dataSource: obj._dataSourceIdentifier(),
call: functionName,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just go with the source (db and collection) unless we already have a specific use for call and arguments. They shouldn't be necessary for this task (at least for what i've got).

Nothing major but there is a good chance we will have to leave around stuff nobody uses.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I’ve gone back and forth on this a bit myself … it feels like something that could be really useful, e.g. for figuring out how to get the data that this call resulted in a second time or displaying what call resulted in this output. I’d lean towards keeping it since it’s essentially free and data that is always going to be available anyway, but I’m also happy to remove it

* @returns {Cursor} The promise of the cursor.
*/
@returnsPromise
@returnType('Document')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice stuff!

@addaleax addaleax force-pushed the 376-dev branch 2 times, most recently from 4243e10 to 8cc2d2f Compare October 5, 2020 21:27
For results from calls on collections, add metadata about the source of
the returned data (database name, collection name, method, arguments)
so that consumers of the shell can figure out from what source
the result was generated, e.g. in order to understand how to modify
that original data.

This also adds a fake `Document` type to the `ShellResult` reported
for e.g. `findOne()`, so that it is possible to tell those apart
from other plain JavaScript objects, e.g. in order to be able to
know whether the result is a modifiable object in the database or not.
type: 'AggregationCursor',
value: this._mongo._serviceProvider.platform === ReplPlatform.JavaShell ? this : await this._asPrintable()
value: this._mongo._serviceProvider.platform === ReplPlatform.JavaShell ? this : await this._asPrintable(),
source: this[resultSource] ?? undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool, I've never seen '??' before.

@addaleax addaleax merged commit af6126a into master Oct 7, 2020
@addaleax addaleax deleted the 376-dev branch October 7, 2020 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants