Introduces flow types for storage (#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 (#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
This commit is contained in:
53
src/Adapters/Storage/StorageAdapter.js
Normal file
53
src/Adapters/Storage/StorageAdapter.js
Normal file
@@ -0,0 +1,53 @@
|
||||
// @flow
|
||||
export type SchemaType = any;
|
||||
export type StorageClass = any;
|
||||
export type QueryType = any;
|
||||
|
||||
export type QueryOptions = {
|
||||
skip?: number,
|
||||
limit?: number,
|
||||
acl?: string[],
|
||||
sort?: {[string]: number},
|
||||
count?: boolean | number,
|
||||
keys?: string[],
|
||||
op?: string,
|
||||
distinct?: boolean,
|
||||
pipeline?: any,
|
||||
readPreference?: ?string,
|
||||
};
|
||||
|
||||
export type UpdateQueryOptions = {
|
||||
many?: boolean,
|
||||
upsert?: boolean
|
||||
}
|
||||
|
||||
export type FullQueryOptions = QueryOptions & UpdateQueryOptions;
|
||||
|
||||
export interface StorageAdapter {
|
||||
classExists(className: string): Promise<boolean>;
|
||||
setClassLevelPermissions(className: string, clps: any): Promise<void>;
|
||||
createClass(className: string, schema: SchemaType): Promise<void>;
|
||||
addFieldIfNotExists(className: string, fieldName: string, type: any): Promise<void>;
|
||||
deleteClass(className: string): Promise<void>;
|
||||
deleteAllClasses(): Promise<void>;
|
||||
deleteFields(className: string, schema: SchemaType, fieldNames: Array<string>): Promise<void>;
|
||||
getAllClasses(): Promise<StorageClass[]>;
|
||||
getClass(className: string): Promise<StorageClass>;
|
||||
createObject(className: string, schema: SchemaType, object: any): Promise<any>;
|
||||
deleteObjectsByQuery(className: string, schema: SchemaType, query: QueryType): Promise<void>;
|
||||
updateObjectsByQuery(className: string, schema: SchemaType, query: QueryType, update: any): Promise<[any]>;
|
||||
findOneAndUpdate(className: string, schema: SchemaType, query: QueryType, update: any): Promise<any>;
|
||||
upsertOneObject(className: string, schema: SchemaType, query: QueryType, update: any): Promise<any>;
|
||||
find(className: string, schema: SchemaType, query: QueryType, options: QueryOptions): Promise<[any]>;
|
||||
ensureUniqueness(className: string, schema: SchemaType, fieldNames: Array<string>): Promise<void>;
|
||||
count(className: string, schema: SchemaType, query: QueryType, readPreference: ?string): Promise<number>;
|
||||
distinct(className: string, schema: SchemaType, query: QueryType, fieldName: string): Promise<any>;
|
||||
aggregate(className: string, schema: any, pipeline: any, readPreference: ?string): Promise<any>;
|
||||
performInitialization(options: ?any): Promise<void>;
|
||||
|
||||
// Indexing
|
||||
createIndexes(className: string, indexes: any, conn: ?any): Promise<void>;
|
||||
getIndexes(className: string, connection: ?any): Promise<void>;
|
||||
updateSchemaWithIndexes(): Promise<void>;
|
||||
setIndexesWithSchemaFormat(className: string, submittedIndexes: any, existingIndexes: any, fields: any, conn: ?any): Promise<void>;
|
||||
}
|
||||
Reference in New Issue
Block a user