Skip to content

Commit 292c448

Browse files
committed
Adds flow types to SchemaCOntroller,
- runs flow on pre tests - fixes flow
1 parent c5d726f commit 292c448

File tree

8 files changed

+105
-69
lines changed

8 files changed

+105
-69
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
},
6868
"scripts": {
6969
"dev": "npm run build && node bin/dev",
70-
"lint": "eslint --cache ./",
70+
"lint": "flow && eslint --cache ./",
7171
"build": "babel src/ -d lib/ --copy-files",
7272
"pretest": "npm run lint",
7373
"test": "cross-env MONGODB_VERSION=${MONGODB_VERSION:=3.2.6} MONGODB_STORAGE_ENGINE=mmapv1 TESTING=1 $COVERAGE_OPTION jasmine",

src/Adapters/Files/GridStoreAdapter.js

Lines changed: 1 addition & 0 deletions
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/Postgres/PostgresStorageAdapter.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,8 @@ export class PostgresStorageAdapter implements StorageAdapter {
620620
});
621621
}
622622

623-
setIndexesWithSchemaFormat(className: string, submittedIndexes: any, existingIndexes: any = {}, fields: any, conn: any): Promise<void> {
624-
conn = conn || this._client;
623+
setIndexesWithSchemaFormat(className: string, submittedIndexes: any, existingIndexes: any = {}, fields: any, client: ?any): Promise<void> {
624+
const conn = client || this._client;
625625
if (submittedIndexes === undefined) {
626626
return Promise.resolve();
627627
}

src/Adapters/Storage/StorageAdapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface StorageAdapter {
3434

3535
// Indexing
3636
createIndexes(className: string, indexes: any, conn: ?any): Promise<void>;
37-
createIndexesIfNeeded(className: string, fieldName: string, type: any, conn: ?any): Promise<void>;
3837
getIndexes(className: string, connection: ?any): Promise<void>;
3938
updateSchemaWithIndexes(): Promise<void>;
39+
setIndexesWithSchemaFormat(className: string, submittedIndexes: any, existingIndexes: any, fields: any, conn: ?any): Promise<void>;
4040
}

src/Controllers/DatabaseController.js

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import intersect from 'intersect';
1111
// @flow-disable-next
1212
import deepcopy from 'deepcopy';
1313
import logger from '../logger';
14-
import * as SchemaController from './SchemaController';
14+
import * as SchemaController from './SchemaController';
1515
import { StorageAdapter } from '../Adapters/Storage/StorageAdapter';
1616
function addWriteACL(query, acl) {
1717
const newQuery = _.cloneDeep(query);
@@ -152,6 +152,14 @@ const filterSensitiveData = (isMaster, aclGroup, className, object) => {
152152
return object;
153153
};
154154

155+
type Options = {
156+
acl?: string[]
157+
}
158+
159+
type LoadSchemaOptions = {
160+
clearCache: boolean
161+
}
162+
155163
// Runs an update on the database.
156164
// Returns a promise for an object with the new values for field
157165
// modifications that don't know their results ahead of time, like
@@ -285,7 +293,7 @@ const relationSchema = { fields: { relatedId: { type: 'String' }, owningId: { ty
285293
class DatabaseController {
286294
adapter: StorageAdapter;
287295
schemaCache: any;
288-
schemaPromise: ?Promise<any>;
296+
schemaPromise: ?Promise<SchemaController.SchemaController>;
289297

290298
constructor(adapter: StorageAdapter, schemaCache: any) {
291299
this.adapter = adapter;
@@ -314,7 +322,7 @@ class DatabaseController {
314322
}
315323

316324
// Returns a promise for a schemaController.
317-
loadSchema(options : any = {clearCache: false}): Promise<any> {
325+
loadSchema(options: LoadSchemaOptions = {clearCache: false}): Promise<SchemaController.SchemaController> {
318326
if (this.schemaPromise != null) {
319327
return this.schemaPromise;
320328
}
@@ -327,25 +335,24 @@ class DatabaseController {
327335
// Returns a promise for the classname that is related to the given
328336
// classname through the key.
329337
// TODO: make this not in the DatabaseController interface
330-
redirectClassNameForKey(className: string, key: string): Promise<string> {
338+
redirectClassNameForKey(className: string, key: string): Promise<?string> {
331339
return this.loadSchema().then((schema) => {
332-
var t = schema.getExpectedType(className, key);
333-
if (t && t.type == 'Relation') {
340+
var t = schema.getExpectedType(className, key);
341+
if (t != null && typeof t !== 'string' && t.type === 'Relation') {
334342
return t.targetClass;
335-
} else {
336-
return className;
337343
}
344+
return className;
338345
});
339346
}
340347

341348
// Uses the schema to validate the object (REST API format).
342349
// Returns a promise that resolves to the new schema.
343350
// This does not update this.schema, because in a situation like a
344351
// batch request, that could confuse other users of the schema.
345-
validateObject(className: string, object: any, query: any, { acl }: any): Promise<boolean> {
352+
validateObject(className: string, object: any, query: any, { acl }: Options): Promise<boolean> {
346353
let schema;
347354
const isMaster = acl === undefined;
348-
var aclGroup = acl || [];
355+
var aclGroup: string[] = acl || [];
349356
return this.loadSchema().then(s => {
350357
schema = s;
351358
if (isMaster) {
@@ -537,7 +544,7 @@ class DatabaseController {
537544
// acl: a list of strings. If the object to be updated has an ACL,
538545
// one of the provided strings must provide the caller with
539546
// write permissions.
540-
destroy(className: string, query: any, { acl }: any = {}): Promise<any> {
547+
destroy(className: string, query: any, { acl }: Options = {}): Promise<any> {
541548
const isMaster = acl === undefined;
542549
const aclGroup = acl || [];
543550

@@ -579,7 +586,7 @@ class DatabaseController {
579586

580587
// Inserts an object into the database.
581588
// Returns a promise that resolves successfully iff the object saved.
582-
create(className: string, object: any, { acl }: any = {}): Promise<any> {
589+
create(className: string, object: any, { acl }: Options = {}): Promise<any> {
583590
// Make a copy of the object, so we don't mutate the incoming data.
584591
const originalObject = object;
585592
object = transformObjectACL(object);
@@ -610,7 +617,7 @@ class DatabaseController {
610617
})
611618
}
612619

613-
canAddField(schema: any, className: string, object: any, aclGroup: string[]): Promise<void> {
620+
canAddField(schema: SchemaController.SchemaController, className: string, object: any, aclGroup: string[]): Promise<void> {
614621
const classSchema = schema.data[className];
615622
if (!classSchema) {
616623
return Promise.resolve();
@@ -843,7 +850,7 @@ class DatabaseController {
843850
distinct,
844851
pipeline,
845852
readPreference
846-
}: any = {}): Promise<[any]> {
853+
}: any = {}): Promise<any> {
847854
const isMaster = acl === undefined;
848855
const aclGroup = acl || [];
849856
op = op || (typeof query.objectId == 'string' && Object.keys(query).length === 1 ? 'get' : 'find');
@@ -938,7 +945,7 @@ class DatabaseController {
938945
}
939946

940947
deleteSchema(className: string): Promise<void> {
941-
return this.loadSchema(true)
948+
return this.loadSchema({ clearCache: true })
942949
.then(schemaController => schemaController.getOneSchema(className, true))
943950
.catch(error => {
944951
if (error === undefined) {

src/Controllers/HooksController.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
/** @flow weak */
22

33
import * as triggers from "../triggers";
4+
// @flow-disable-next
45
import * as Parse from "parse/node";
6+
// @flow-disable-next
57
import * as request from "request";
68
import { logger } from '../logger';
79

@@ -28,15 +30,15 @@ export class HooksController {
2830
}
2931

3032
getFunction(functionName) {
31-
return this._getHooks({ functionName: functionName }, 1).then(results => results[0]);
33+
return this._getHooks({ functionName: functionName }).then(results => results[0]);
3234
}
3335

3436
getFunctions() {
3537
return this._getHooks({ functionName: { $exists: true } });
3638
}
3739

3840
getTrigger(className, triggerName) {
39-
return this._getHooks({ className: className, triggerName: triggerName }, 1).then(results => results[0]);
41+
return this._getHooks({ className: className, triggerName: triggerName }).then(results => results[0]);
4042
}
4143

4244
getTriggers() {

0 commit comments

Comments
 (0)