Skip to content

Commit b5f1cb5

Browse files
authored
Introduces flow types for storage (parse-community#4349)
* 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
1 parent 794dac6 commit b5f1cb5

20 files changed

+1039
-869
lines changed

.flowconfig

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
[libs]
88

99
[options]
10+
suppress_comment= \\(.\\|\n\\)*\\@flow-disable-next

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"deep-diff": "0.3.8",
5757
"eslint": "^4.9.0",
5858
"eslint-plugin-flowtype": "^2.39.1",
59+
"flow-bin": "^0.59.0",
5960
"gaze": "1.1.2",
6061
"jasmine": "2.8.0",
6162
"jasmine-spec-reporter": "^4.1.0",
@@ -66,7 +67,7 @@
6667
},
6768
"scripts": {
6869
"dev": "npm run build && node bin/dev",
69-
"lint": "eslint --cache ./",
70+
"lint": "flow && eslint --cache ./",
7071
"build": "babel src/ -d lib/ --copy-files",
7172
"pretest": "npm run lint",
7273
"test": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 TESTING=1 jasmine",

spec/MongoStorageAdapter.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict';
22

3-
const MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
4-
const MongoClient = require('mongodb').MongoClient;
3+
import MongoStorageAdapter from '../src/Adapters/Storage/Mongo/MongoStorageAdapter';
4+
const { MongoClient } = require('mongodb');
55
const databaseURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
66

77
// These tests are specific to the mongo storage adapter + mongo storage format

spec/ParsePolygon.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const TestObject = Parse.Object.extend('TestObject');
2-
const MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
2+
import MongoStorageAdapter from '../src/Adapters/Storage/Mongo/MongoStorageAdapter';
33
const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
44
const rp = require('request-promise');
55
const defaultHeaders = {

spec/ParseQuery.FullTextSearch.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

3-
const MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
3+
import MongoStorageAdapter from '../src/Adapters/Storage/Mongo/MongoStorageAdapter';
44
const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
5-
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
5+
import PostgresStorageAdapter from '../src/Adapters/Storage/Postgres/PostgresStorageAdapter';
66
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
77
const Parse = require('parse/node');
88
const rp = require('request-promise');

spec/ParseServer.spec.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22
/* Tests for ParseServer.js */
33
const express = require('express');
4-
4+
import MongoStorageAdapter from '../src/Adapters/Storage/Mongo/MongoStorageAdapter';
5+
import PostgresStorageAdapter from '../src/Adapters/Storage/Postgres/PostgresStorageAdapter';
56
import ParseServer from '../src/ParseServer';
67

78
describe('Server Url Checks', () => {
@@ -35,8 +36,6 @@ describe('Server Url Checks', () => {
3536
});
3637

3738
it('handleShutdown, close connection', (done) => {
38-
var MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
39-
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
4039
const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';
4140
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
4241
let databaseAdapter;

spec/PostgresInitOptions.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const Parse = require('parse/node').Parse;
2-
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
2+
import PostgresStorageAdapter from '../src/Adapters/Storage/Postgres/PostgresStorageAdapter';
33
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
44
const ParseServer = require("../src/index");
55
const express = require('express');

spec/PostgresStorageAdapter.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
1+
import PostgresStorageAdapter from '../src/Adapters/Storage/Postgres/PostgresStorageAdapter';
22
const databaseURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
33

44
describe_only_db('postgres')('PostgresStorageAdapter', () => {

spec/helper.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ var cache = require('../src/cache').default;
2727
var ParseServer = require('../src/index').ParseServer;
2828
var path = require('path');
2929
var TestUtils = require('../src/TestUtils');
30-
var MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
3130
const GridStoreAdapter = require('../src/Adapters/Files/GridStoreAdapter').GridStoreAdapter;
3231
const FSAdapter = require('@parse/fs-files-adapter');
33-
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
32+
import PostgresStorageAdapter from '../src/Adapters/Storage/Postgres/PostgresStorageAdapter';
33+
import MongoStorageAdapter from '../src/Adapters/Storage/Mongo/MongoStorageAdapter';
3434
const RedisCacheAdapter = require('../src/Adapters/Cache/RedisCacheAdapter').default;
3535

3636
const mongoURI = 'mongodb://localhost:27017/parseServerMongoAdapterTestDatabase';

spec/index.spec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var ParseServer = require("../src/index");
66
var Config = require('../src/Config');
77
var express = require('express');
88

9-
const MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
9+
import MongoStorageAdapter from '../src/Adapters/Storage/Mongo/MongoStorageAdapter';
1010

1111
describe('server', () => {
1212
it('requires a master key and app id', done => {

src/Adapters/Files/GridStoreAdapter.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@flow weak
77
*/
88

9+
// @flow-disable-next
910
import { MongoClient, GridStore, Db} from 'mongodb';
1011
import { FilesAdapter } from './FilesAdapter';
1112
import defaults from '../../defaults';

src/Adapters/Storage/Mongo/MongoSchemaCollection.js

+12
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ class MongoSchemaCollection {
137137
return this._collection._mongoCollection.findAndRemove(_mongoSchemaQueryFromNameQuery(name), []);
138138
}
139139

140+
insertSchema(schema: any) {
141+
return this._collection.insertOne(schema)
142+
.then(result => mongoSchemaToParseSchema(result.ops[0]))
143+
.catch(error => {
144+
if (error.code === 11000) { //Mongo's duplicate key error
145+
throw new Parse.Error(Parse.Error.DUPLICATE_VALUE, 'Class already exists.');
146+
} else {
147+
throw error;
148+
}
149+
})
150+
}
151+
140152
updateSchema(name: string, update) {
141153
return this._collection.updateOne(_mongoSchemaQueryFromNameQuery(name), update);
142154
}

0 commit comments

Comments
 (0)