chore: Fixes issue related to flow types (#4724)
* Fixes issue related to flow types * Improves type inference on where clause, index * run parse-server start on liveQueryServer only on mongo, state leaks on postgres
This commit is contained in:
@@ -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 = [];
|
||||
@@ -611,6 +617,9 @@ const buildWhereClause = ({ schema, query, index }) => {
|
||||
}
|
||||
|
||||
export class PostgresStorageAdapter implements StorageAdapter {
|
||||
|
||||
canSortOnJoinTables: boolean;
|
||||
|
||||
// Private
|
||||
_collectionPrefix: string;
|
||||
_client: any;
|
||||
@@ -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() {
|
||||
@@ -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];
|
||||
@@ -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);
|
||||
@@ -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];
|
||||
@@ -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'`;
|
||||
}, '');
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user