diaspora-orm/diaspora

View on GitHub
src/types/queryLanguage.ts

Summary

Maintainability
A
0 mins
Test Coverage
import * as ConstrainedTypes from './constrainedTypes';
import { EntityUid } from './entity';

/**
 * Namespace regrouping public interfaces exposed to users, related to query language
 */
export namespace QueryLanguage {
    /**
     * All properties are optional
     */
    export interface IQueryOptions {
        /**
         * Number of items to skip
         */
        skip?: ConstrainedTypes.AbsInt0;
        
        /**
         * Number of items to get
         */
        limit?: ConstrainedTypes.AbsIntInf0;
        
        /**
         * To use with {@link QueryOptions.limit `limit`} and without {@link QueryOptions.skip `skip`}. Skips `page` pages of `limit` elements
         */
        page?: ConstrainedTypes.AbsInt0;
        
        /**
         * Flag indicating if adapter input should be remapped or not. TODO Remapping doc
         */
        remapInput?: boolean;
        
        /**
         * Flag indicating if adapter output should be remapped or not. TODO Remapping doc
         */
        remapOutput?: boolean;
    }
    
    /**
     * By default, all conditions in a single SelectQueryCondition are combined with an `AND` operator.
     */
    export interface ISelectQueryCondition {
        /**
         * Alias for {@link SelectQueryCondition.$equals}
         */
        '==': any;
        
        /**
         * See {@link SelectQueryCondition.$equals}
         */
        $equals: any;
        
        /**
         * Alias for {@link SelectQueryCondition.$diff}
         */
        '!=': any;
        
        /**
         * See {@link SelectQueryCondition.$diff}
         */
        $diff: any;
        
        /**
         * Alias for {@link SelectQueryCondition.$exists}
         */
        '~': boolean;
        
        /**
         * See {@link SelectQueryCondition.$exists}
         */
        $exists: boolean;
        
        /**
         * Alias for {@link SelectQueryCondition.$less}
         */
        '<': number;
        
        /**
         * See {@link SelectQueryCondition.$less}
         */
        $less: number;
        
        /**
         * Alias for {@link SelectQueryCondition.$lessEqual}
         */
        '<=': number;
        
        /**
         * See {@link SelectQueryCondition.$lessEqual}
         */
        $lessEqual: number;
        
        /**
         * Alias for {@link SelectQueryCondition.$greater}
         */
        '>': number;
        
        /**
         * See {@link SelectQueryCondition.$greater}
         */
        $greater: number;
        
        /**
         * Alias for {@link SelectQueryCondition.$greaterEqual}
         */
        '>=': number;
        
        /**
         * See {@link SelectQueryCondition.$greaterEqual}
         */
        $greaterEqual: number;
        
        /**
         * Alias for {@link SelectQueryCondition.$or}
         */
        '||': SelectQueryOrCondition[];
        
        /**
         * See {@link SelectQueryCondition.$or}
         */
        $or: SelectQueryOrCondition[];
        
        /**
         * Alias for {@link SelectQueryCondition.$and}
         */
        '&&': SelectQueryOrCondition[];
        
        /**
         * See {@link SelectQueryCondition.$and}
         */
        $and: SelectQueryOrCondition[];
        
        /**
         * Alias for {@link SelectQueryCondition.$xor}
         */
        '^^': SelectQueryOrCondition[];
        
        /**
         * See {@link SelectQueryCondition.$xor}
         */
        $xor: SelectQueryOrCondition[];
        
        /**
         * Alias for {@link SelectQueryCondition.$not}
         */
        '!': SelectQueryOrCondition;
        
        /**
         * See {@link SelectQueryCondition.$not}
         */
        $not: SelectQueryOrCondition;
        
        /**
         * See {@link SelectQueryCondition.$contains}
         */
        $contains: SelectQueryOrCondition | string | any;
        
        /**
         * See {@link SelectQueryCondition.$in}
         */
        $in: any[];
    }
    
    export interface ISelectQuery {
        /**
         * Fields to search. If not providing an object, find items with a property value that equals this value
         */
        [key: string]: any | ISelectQueryCondition;
    }
    
    export type SelectQueryOrCondition = ISelectQuery | ISelectQueryCondition;
    export type SearchQuery = SelectQueryOrCondition | EntityUid;
}

/**
 * Namespace regrouping private & internal interfaces used by Diaspora, related to query language. Its public counterpart is [[QueryLanguage]]
 * @internal
 */
export namespace _QueryLanguage {
    /**
     * Generated by Diaspora
     */
    export interface IQueryOptions {
        /**
         * Number of items to skip
         */
        skip: ConstrainedTypes.AbsInt0;
        
        /**
         * Number of items to get
         */
        limit: ConstrainedTypes.AbsIntInf0;
        
        /**
         * Flag indicating if adapter input should be remapped or not. TODO Remapping doc
         */
        remapInput: boolean;
        
        /**
         * Flag indicating if adapter output should be remapped or not. TODO Remapping doc
         */
        remapOutput: boolean;
    }
    
    /**
     * By default, all conditions in a single SelectQueryCondition are combined with an `AND` operator.
     */
    export interface ISelectQueryCondition {
        /**
         * Match if item value is equal to this. Objects and array are compared deeply. Canonical form of {@link Raw.SelectQueryCondition['==']}
         */
        $equals: any;
        
        /**
         * Match if item value is different to this. Objects and array are compared deeply. Canonical form of {@link Raw.SelectQueryCondition['!=']}
         */
        $diff: any;
        
        /**
         * If `true`, match items where this prop is defined. If `false`, match when prop is null or not set. Canonical form of {@link Raw.SelectQueryCondition['~']}
         */
        $exists: boolean;
        
        /**
         * Match if item value is less than this. Canonical form of {@link Raw.SelectQueryCondition['<']}
         */
        $less: number;
        
        /**
         * Match if item value is less than this or equals to this. Canonical form of {@link Raw.SelectQueryCondition['<=']}
         */
        $lessEqual: number;
        
        /**
         * Match if item value is greater than this. Canonical form of {@link Raw.SelectQueryCondition['>']}
         */
        $greater: number;
        
        /**
         * Match if item value is greater than this or equals to this. Canonical form of {@link Raw.SelectQueryCondition['>=']}
         */
        $greaterEqual: number;
        
        /**
         * Match if *one of* the conditions in the array is true. Canonical form of {@link Raw.SelectQueryCondition['||']} **NOT IMPLEMENTED YET**
         */
        $or: SelectQueryOrCondition[];
        
        /**
         * Match if *all* the conditions in the array are true. Optional, because several conditions in a single SelectQueryCondition are combined with an `AND` operator. Canonical form of {@link Raw.SelectQueryCondition['&&']} **NOT IMPLEMENTED YET**
         */
        $and: SelectQueryOrCondition[];
        
        /**
         * Match if *a single* of the conditions in the array is true. Canonical form of {@link Raw.SelectQueryCondition['^^']} **NOT IMPLEMENTED YET**
         */
        $xor: SelectQueryOrCondition[];
        
        /**
         * Invert the condition Canonical form of {@link Raw.SelectQueryCondition['!']} **NOT IMPLEMENTED YET**
         */
        $not: SelectQueryOrCondition;
        
        /**
         * On *array*, it will check if item contains the query. On *string*, it will check if query is included in item using GLOB. **NOT IMPLEMENTED YET**
         */
        $contains: SelectQueryOrCondition | string | any;
        
        /**
         * Check if item value is contained (using deep comparaison) in query. **NOT IMPLEMENTED YET**
         */
        $in: any[];
    }
    
    export interface ISelectQuery {
        /**
         * Fields to search. If not providing an object, find items with a property value that equals this value
         */
        [key: string]: any | ISelectQueryCondition;
    }
    
    export type SelectQueryOrCondition = ISelectQuery | ISelectQueryCondition;
}