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

Introduces flow types for storage #4349

Merged
merged 10 commits into from
Dec 31, 2017
Merged

Conversation

flovilmart
Copy link
Contributor

No description provided.

@@ -78,20 +87,20 @@ const mongoSchemaFromFieldsAndClassNameAndCLP = (fields, className, classLevelPe
}


export class MongoStorageAdapter {
export class MongoStorageAdapter implements StorageAdapter, IndexingStorageAdapter {
// Private
_uri: string;
_collectionPrefix: string;
_mongoOptions: Object;
// Public
connectionPromise;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to add a type here or not worthwhile?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably yes,

@codecov
Copy link

codecov bot commented Nov 14, 2017

Codecov Report

Merging #4349 into master will decrease coverage by 0.04%.
The diff coverage is 94.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4349      +/-   ##
==========================================
- Coverage   92.84%   92.79%   -0.05%     
==========================================
  Files         118      118              
  Lines        8381     8372       -9     
==========================================
- Hits         7781     7769      -12     
- Misses        600      603       +3
Impacted Files Coverage Δ
src/Adapters/Files/GridStoreAdapter.js 100% <ø> (ø) ⬆️
src/Push/PushWorker.js 93.1% <ø> (ø) ⬆️
src/Adapters/Storage/Mongo/MongoStorageAdapter.js 95.78% <100%> (+0.33%) ⬆️
src/Controllers/HooksController.js 96.15% <100%> (ø) ⬆️
...rc/Adapters/Storage/Mongo/MongoSchemaCollection.js 95.18% <80%> (-0.98%) ⬇️
src/Controllers/SchemaController.js 96.47% <86.36%> (-0.65%) ⬇️
...dapters/Storage/Postgres/PostgresStorageAdapter.js 96.87% <90%> (-0.2%) ⬇️
src/Controllers/DatabaseController.js 94.56% <95.61%> (-0.26%) ⬇️
src/Adapters/Auth/meetup.js 84.21% <0%> (-5.27%) ⬇️
... and 3 more

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 f0f1870...ef882d3. Read the comment docs.

@@ -1489,7 +1495,7 @@ export class PostgresStorageAdapter {
}
}

const qs = `SELECT ${columns} FROM $1:name ${wherePattern} ${sortPattern} ${limitPattern} ${skipPattern} ${groupPattern}`;
const qs = `SELECT ${columns.join(',')} FROM $1:name ${wherePattern} ${sortPattern} ${limitPattern} ${skipPattern} ${groupPattern}`;
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, how did the tests not catch this? Seems like this would have caused a noticeable problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah that's very very odd. @dplewis ?

Copy link
Member

@dplewis dplewis Nov 14, 2017

Choose a reason for hiding this comment

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

Good catch. There isn't a test for project with multiple fields, only a test with 1 field. This should fix that issue.

@@ -117,75 +122,6 @@ const validateQuery = query => {
});
}

function DatabaseController(adapter, schemaCache) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@flovilmart could you fill me on the rationale for the changes in this file? There's a lot that's been shifted around in the diff and I'm not entirely sure what the objective is here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make it a class, and also make it conform to a particular interface, so it’s easier to know what’s consumed and how in the future (like the indexing) this also rationalizes to a certain extent also the interfaces for every calls to the adapters.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, now I see! Thanks for clarifying.

@flovilmart
Copy link
Contributor Author

@montymxb I could go further, formalize Schema and SchemaController as it's quite tough to follow there what's what. What do you think?

@montymxb
Copy link
Contributor

montymxb commented Nov 15, 2017

@flovilmart I think we could go further, but for now I think this is good for the PR 👍 . Any other improvements to structure are always good though.

Just to note I recently took some time to go back through the source again for parse-server. Last time I really went through it all was when this was all first open sourced with fosco. A ton has changed since then, figured I needed to go back over it all.

Looking at it all it's been really cool to see everything that's been built into this, but it's been a lot of growth. I think it could use some trimming/restructuring now to standardize and clean things up. In the process of doing that it would be nice to roadmap the layout that is parse server, in a general sense kind of like this for the php sdk but not necessarily in graphical form. Just something that we can add to the docs that can help someone grasp things like:

  • What Parse Server is
  • How to use it
  • How it works (generally)
  • How it works (under the hood)

That's a lot of work to put together docs for stuff like that, but if we organize it so we do it with a general code cleanup/restructures we could do it piece by piece. Whenever we have time. Once the cleanup is done the documented portions of that code would be done as well (hopefully).

Just some thoughts, we could open up a project for this to itemize what would need to be done. May not even need to actually do a code restructure either, maybe just cleanup some TODOs and such. Either way, it would be an excuse to make the project a bit more transparent and easy to understand.

@@ -1627,7 +1633,7 @@ function literalizeRegexPart(s) {

// process regex that has a beginning specified for the literal text
const matcher2 = /\\Q((?!\\E).*)$/
const result2 = s.match(matcher2);
const result2: any = s.match(matcher2);
if(result2 && result2.length > 1 && result2.index > -1){
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the linter catch spaces in if statements. if () {

@flovilmart flovilmart added this to the 2.7.0 milestone Nov 25, 2017
@flovilmart flovilmart force-pushed the flow-type-storage-adapter branch 2 times, most recently from 3f333b3 to 0c8180f Compare November 25, 2017 21:36
@montymxb
Copy link
Contributor

montymxb commented Dec 8, 2017

@flovilmart are we still pushing for this?

@flovilmart
Copy link
Contributor Author

Needs some rework

acinader
acinader previously approved these changes Dec 8, 2017
@@ -1,6 +1,6 @@
'use strict';

const MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
const MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter').MongoStorageAdapter;
Copy link
Contributor

Choose a reason for hiding this comment

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

the newer airbnb wants:

const {MongoStorageAdapter} = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');

all the cool kids are doing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lol :) most definitely :)

@dplewis
Copy link
Member

dplewis commented Dec 29, 2017

@flovilmart Do you know why find succeeds when query is within maxTimeMS keeps failing?

@montymxb
Copy link
Contributor

Wanted to note that I've been keeping a small log of the arbitrary errors we see in CI. That one in particular is the most common from what I've observed.

vitaly-t and others added 3 commits December 30, 2017 14:22
Fixing invalid database code in method `setIndexesWithSchemaFormat`:

* It must be a transaction, not a task, as it executes multiple database changes
* It should contain the initial queries inside the transaction, providing the context, not outside it;
* Replaced the code with the ES6 Generator notation
* Removing the use of batch, as the value of the result promise is irrelevant, only success/failure that matters
@flovilmart
Copy link
Contributor Author

@montymxb @dplewis can we get a look at this one? With the refactoring in PG, it becomes costly to maintain this :)

@dplewis
Copy link
Member

dplewis commented Dec 30, 2017

LGTM! Good work flo on getting flow types working. Let’s get this in before it gets stale.

@flovilmart flovilmart merged commit 1063137 into master Dec 31, 2017
@flovilmart flovilmart deleted the flow-type-storage-adapter branch December 31, 2017 01:44
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* Introduces flow types for storage

* Better typing of QueryOptions

* Adds flow types to SchemaCOntroller,

- runs flow on pre tests
- fixes flow

* Adds ClassLevelPermissions type

* Moves Controller types into a single file

* Changes import styles

* Changes import styles

* fixing method setIndexesWithSchemaFormat (parse-community#4454)

Fixing invalid database code in method `setIndexesWithSchemaFormat`:

* It must be a transaction, not a task, as it executes multiple database changes
* It should contain the initial queries inside the transaction, providing the context, not outside it;
* Replaced the code with the ES6 Generator notation
* Removing the use of batch, as the value of the result promise is irrelevant, only success/failure that matters

* nits

* Fixes tests, improves flow typing
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.

6 participants