Skip to content

Fixes issue related to flow types #4724

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

Merged
merged 3 commits into from
May 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 35 additions & 34 deletions spec/ParseLiveQueryServer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,46 +102,47 @@ describe('ParseLiveQueryServer', function() {
parseLiveQueryServer.server.close(done);
});

it('can be initialized through ParseServer without liveQueryServerOptions', function(done) {
const parseServer = ParseServer.start({
appId: 'hello',
masterKey: 'world',
port: 22345,
mountPath: '/1',
serverURL: 'http://localhost:12345/1',
liveQuery: {
classNames: ['Yolo']
},
startLiveQueryServer: true
describe_only_db('mongo')('initialization', () => {
it('can be initialized through ParseServer without liveQueryServerOptions', function(done) {
const parseServer = ParseServer.start({
appId: 'hello',
masterKey: 'world',
port: 22345,
mountPath: '/1',
serverURL: 'http://localhost:12345/1',
liveQuery: {
classNames: ['Yolo']
},
startLiveQueryServer: true
});

expect(parseServer.liveQueryServer).not.toBeUndefined();
expect(parseServer.liveQueryServer.server).toBe(parseServer.server);
parseServer.server.close(() => done());
});

expect(parseServer.liveQueryServer).not.toBeUndefined();
expect(parseServer.liveQueryServer.server).toBe(parseServer.server);
parseServer.server.close(() => done());
});
it('can be initialized through ParseServer with liveQueryServerOptions', function(done) {
const parseServer = ParseServer.start({
appId: 'hello',
masterKey: 'world',
port: 22346,
mountPath: '/1',
serverURL: 'http://localhost:12345/1',
liveQuery: {
classNames: ['Yolo']
},
liveQueryServerOptions: {
port: 22347,
}
});

it('can be initialized through ParseServer with liveQueryServerOptions', function(done) {
const parseServer = ParseServer.start({
appId: 'hello',
masterKey: 'world',
port: 22346,
mountPath: '/1',
serverURL: 'http://localhost:12345/1',
liveQuery: {
classNames: ['Yolo']
},
liveQueryServerOptions: {
port: 22347,
}
expect(parseServer.liveQueryServer).not.toBeUndefined();
expect(parseServer.liveQueryServer.server).not.toBe(parseServer.server);
parseServer.liveQueryServer.server.close();
parseServer.server.close(() => done());
});

expect(parseServer.liveQueryServer).not.toBeUndefined();
expect(parseServer.liveQueryServer.server).not.toBe(parseServer.server);
parseServer.liveQueryServer.server.close();
parseServer.server.close(() => done());
});


it('can handle connect command', function() {
const parseLiveQueryServer = new ParseLiveQueryServer(10, 10, {});
const parseWebSocket = {
Expand Down
2 changes: 1 addition & 1 deletion src/Adapters/Storage/Mongo/MongoStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export class MongoStorageAdapter implements StorageAdapter {
return this.connectionPromise;
}

handleError<T>(error: ?Error): Promise<T> {
handleError<T>(error: ?(Error | Parse.Error)): Promise<T> {
if (error && error.code === 13) { // Unauthorized error
delete this.client;
delete this.database;
Expand Down
26 changes: 18 additions & 8 deletions src/Adapters/Storage/Postgres/PostgresStorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,13 @@ const joinTablesForSchema = (schema) => {
return list;
}

const buildWhereClause = ({ schema, query, index }) => {
interface WhereClause {
pattern: string;
values: Array<any>;
sorts: Array<any>;
}

const buildWhereClause = ({ schema, query, index }): WhereClause => {
const patterns = [];
let values = [];
const sorts = [];
Expand Down Expand Up @@ -611,6 +617,9 @@ const buildWhereClause = ({ schema, query, index }) => {
}

export class PostgresStorageAdapter implements StorageAdapter {

canSortOnJoinTables: boolean;

// Private
_collectionPrefix: string;
_client: any;
Expand All @@ -625,6 +634,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
const { client, pgp } = createClient(uri, databaseOptions);
this._client = client;
this._pgp = pgp;
this.canSortOnJoinTables = false;
}

handleShutdown() {
Expand Down Expand Up @@ -862,7 +872,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
return this._client.task('delete-all-classes', function * (t) {
try {
const results = yield t.any('SELECT * FROM "_SCHEMA"');
const joins = results.reduce((list, schema) => {
const joins = results.reduce((list: Array<string>, schema: any) => {
return list.concat(joinTablesForSchema(schema.schema));
}, []);
const classes = ['_SCHEMA', '_PushStatus', '_JobStatus', '_JobSchedule', '_Hooks', '_GlobalConfig', '_Audience', ...results.map(result => result.className), ...joins];
Expand Down Expand Up @@ -895,7 +905,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
// Returns a Promise.
deleteFields(className: string, schema: SchemaType, fieldNames: string[]): Promise<void> {
debug('deleteFields', className, fieldNames);
fieldNames = fieldNames.reduce((list, fieldName) => {
fieldNames = fieldNames.reduce((list: Array<string>, fieldName: string) => {
const field = schema.fields[fieldName]
if (field.type !== 'Relation') {
list.push(fieldName);
Expand Down Expand Up @@ -1149,14 +1159,14 @@ export class PostgresStorageAdapter implements StorageAdapter {
} else if (fieldName == 'authData') {
// This recursively sets the json_object
// Only 1 level deep
const generate = (jsonb, key, value) => {
const generate = (jsonb: string, key: string, value: any) => {
return `json_object_set_key(COALESCE(${jsonb}, '{}'::jsonb), ${key}, ${value})::jsonb`;
}
const lastKey = `$${index}:name`;
const fieldNameIndex = index;
index += 1;
values.push(fieldName);
const update = Object.keys(fieldValue).reduce((lastKey, key) => {
const update = Object.keys(fieldValue).reduce((lastKey: string, key: string) => {
const str = generate(lastKey, `$${index}::text`, `$${index + 1}::jsonb`)
index += 2;
let value = fieldValue[key];
Expand Down Expand Up @@ -1259,13 +1269,13 @@ export class PostgresStorageAdapter implements StorageAdapter {
});
}

const keysToDelete = Object.keys(originalUpdate).filter(k => {
const keysToDelete: Array<string> = Object.keys(originalUpdate).filter(k => {
// choose top level fields that have a delete operation set.
const value = originalUpdate[k];
return value && value.__op === 'Delete' && k.split('.').length === 2 && k.split(".")[0] === fieldName;
}).map(k => k.split('.')[1]);

const deletePatterns = keysToDelete.reduce((p, c, i) => {
const deletePatterns = keysToDelete.reduce((p: string, c: string, i: number) => {
return p + ` - '$${index + 1 + i}:value'`;
}, '');

Expand Down Expand Up @@ -1556,7 +1566,7 @@ export class PostgresStorageAdapter implements StorageAdapter {
aggregate(className: string, schema: any, pipeline: any) {
debug('aggregate', className, pipeline);
const values = [className];
let index = 2;
let index: number = 2;
let columns: string[] = [];
let countField = null;
let groupValues = null;
Expand Down
2 changes: 2 additions & 0 deletions src/Adapters/Storage/StorageAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export type UpdateQueryOptions = {
export type FullQueryOptions = QueryOptions & UpdateQueryOptions;

export interface StorageAdapter {
canSortOnJoinTables: boolean;

classExists(className: string): Promise<boolean>;
setClassLevelPermissions(className: string, clps: any): Promise<void>;
createClass(className: string, schema: SchemaType): Promise<void>;
Expand Down