Skip to content

Conversation

dplewis
Copy link
Member

@dplewis dplewis commented Aug 12, 2018

Fix for parse-community/Parse-SDK-JS#637

In JS SDK I can't pass an array into the payload. So I added a key to allow for this.

@dplewis dplewis requested a review from flovilmart August 12, 2018 17:44
@flovilmart
Copy link
Contributor

In JS SDK I can't pass an array into the payload

Why isn't this possible? The is redundant and having to support both in the future is kinda messy.

@dplewis
Copy link
Member Author

dplewis commented Aug 12, 2018

https://github.com/parse-community/Parse-SDK-JS/blob/master/src/RESTController.js#L163

This line here, currently I would need to pass in an array for data. As you can see that won't work.

Maybe I'm missing something.

@flovilmart
Copy link
Contributor

This is very annoying to realize that at this point in time... Because maintaining both implementation is quite a mess and not documented, I'm thinking about potential issues and explainting why the traces in JS don't match the traces in REST.

OR we make it a breaking change and we stop supporting without the PIPELINE operator .Which defeats the purpose of the aggregate router as we now have a differentiating key (pipeline).

The whole thing seems to be rushed out, and it isn't like the aggregation API hasn't been a source of issues in the past.

So my feeling at that point is that we should come back with a proper design for the aggregate API, discuss it before, and look at the impact in the current SDK's. As at this point, it's utterly broken.

@dplewis
Copy link
Member Author

dplewis commented Aug 12, 2018

This is very annoying to realize that at this point in time

I agree, the Aggregate API has had many unforeseen issues.

we make it a breaking change and we stop supporting without the PIPELINE operator. Which defeats the purpose of the aggregate router as we now have a differentiating key (pipeline).

I agree with making it a breaking change. Allowing for stages with the same name is what I'm going for right now so the PHP and JS SDK will need an update as well.

The aggregate router is there because we aren't returning Parse Objects. It also has a distinct operator as well.

pipeline = body.map((stage) => {
if (Array.isArray(data)) {
pipeline = data.map((stage) => {
const stageName = Object.keys(stage)[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it always the 1st key of the stage? What if the stage object has many keys? What is the shape of that object

Copy link
Member Author

Choose a reason for hiding this comment

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

The 1st key is always the operator like $group, $match, $project.


if (Array.isArray(body)) {
pipeline = body.map((stage) => {
if (Array.isArray(data)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

the names are very confusing here.

We extract pipeline from body, but then it's data, and it's mapped back as an array etc...

Also the this.transformStage(stageName, data) should only be called at one site.

My recommendation,

if it's an object map into an array
then transform that array into the proper pipeline option.

let pipeline = body.pipeline || body;

if (!Array.isArray(pipeline)) {
   pipeline = Object.keys(pipeline).map((key) => { [key]: pipeline[key] })
}

options.pipeline = pipeline.map((stage) => {
   const keys = Object.keys(state);
   if (keys.length != 1) { throw new Error(`Pipeline stages should only have one key found ${keys.join(' ')}`) }
   return this.transformStage(keys[0], stage);
});

handleFind(req) {
const body = Object.assign(req.body, ClassesRouter.JSONFromQuery(req.query));
const options = {};
const data = body.pipeline || body;
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a note here that originally the body could be passed as a single object, and now we support many options and please detail the options, and add a test for each possiblity.

Perhaps extract a single function that maps the request body to a pipeline like

getPipeline(body) {
   // 
}

transformStage(stage) {}

Consider making them static if needed as they don't need 'this'

@flovilmart
Copy link
Contributor

@dplewis so the new API should aloow only for:

{
   pipeline: [
    {
        stage0: {}
    },
    {
         stage1: {}
     }
   ]
}

??

@dplewis
Copy link
Member Author

dplewis commented Aug 12, 2018

Yes that is correct

@dplewis dplewis requested a review from flovilmart August 12, 2018 22:47
@codecov
Copy link

codecov bot commented Aug 12, 2018

Codecov Report

Merging #4959 into master will decrease coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4959      +/-   ##
==========================================
- Coverage   94.28%   94.26%   -0.02%     
==========================================
  Files         120      120              
  Lines        8744     8743       -1     
==========================================
- Hits         8244     8242       -2     
- Misses        500      501       +1
Impacted Files Coverage Δ
src/Routers/AggregateRouter.js 100% <100%> (ø) ⬆️
src/RestWrite.js 93.14% <0%> (-0.37%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 97.29% <0%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9e36a3c...417b43e. Read the comment docs.

@dplewis
Copy link
Member Author

dplewis commented Aug 13, 2018

How does this look?

@dplewis
Copy link
Member Author

dplewis commented Aug 13, 2018

Thanks for the help!

@dplewis dplewis merged commit 4802b1c into parse-community:master Aug 13, 2018
@dplewis dplewis deleted the pipeline-key branch September 10, 2018 17:27
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* Add pipeline key to Aggregate

* clean up

* unit tests
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.

2 participants