UNPKG

3.96 kBTypeScriptView Raw
1import { Key, Comparator } from "./utils";
2export interface Operation {
3 readonly success: boolean;
4 readonly done: boolean;
5 reset(): any;
6 next(item: any, key: Key, owner: any): any;
7}
8export declare type Tester = (item: any, key?: Key, owner?: any) => boolean;
9export declare type OperationCreator = (params: any, parentQuery: any, options: Options) => Operation;
10declare type BasicValueQuery<TValue> = {
11 $eq?: TValue;
12 $ne?: TValue;
13 $lt?: TValue;
14 $gt?: TValue;
15 $lte?: TValue;
16 $gte?: TValue;
17 $in?: TValue[];
18 $nin?: TValue[];
19 $mod?: [number, number];
20 $exists?: boolean;
21 $regex?: string;
22 $options?: "i" | "g" | "m" | "u";
23 $type?: Function;
24 $or?: Query<TValue>[];
25 $nor?: Query<TValue>[];
26};
27declare type ArrayValueQuery<TValue> = {
28 $elemMatch?: Query<TValue, true>;
29} & BasicValueQuery<TValue>;
30declare type Unpacked<T> = T extends (infer U)[] ? U : T;
31declare type ValueQuery<TValue> = TValue extends Array<any> ? ArrayValueQuery<Unpacked<TValue>> : BasicValueQuery<TValue>;
32declare type NotObject = string | number | Date | boolean | Array<any>;
33declare type ShapeQuery<TItemSchema> = TItemSchema extends NotObject ? {} : {
34 [k in keyof TItemSchema]?: TItemSchema[k] | ValueQuery<TItemSchema[k]>;
35};
36export declare type Query<TItemSchema, nested = false> = ValueQuery<TItemSchema> & ShapeQuery<TItemSchema>;
37export declare abstract class BaseOperation<TParams> implements Operation {
38 readonly params: TParams;
39 readonly owneryQuery: any;
40 readonly options: Options;
41 success: boolean;
42 done: boolean;
43 constructor(params: TParams, owneryQuery: any, options: Options);
44 protected init(): void;
45 reset(): void;
46 abstract next(item: any, key: Key, parent: any): any;
47}
48export declare abstract class GroupOperation extends BaseOperation<any> {
49 protected readonly _children: Operation[];
50 success: boolean;
51 done: boolean;
52 constructor(params: any, owneryQuery: any, options: Options, _children: Operation[]);
53 /**
54 */
55 reset(): void;
56 abstract next(item: any, key: Key, owner: any): any;
57 /**
58 */
59 protected childrenNext(item: any, key: Key, owner: any): void;
60}
61export declare class QueryOperation extends GroupOperation {
62 /**
63 */
64 next(item: any, key: Key, parent: any): void;
65}
66export declare class NestedOperation extends GroupOperation {
67 readonly keyPath: Key[];
68 constructor(keyPath: Key[], params: any, owneryQuery: any, options: Options, children: Operation[]);
69 /**
70 */
71 next(item: any, key: Key, parent: any): void;
72 /**
73 */
74 private _nextNestedValue;
75}
76export declare const createTester: (a: any, compare: Comparator) => any;
77export declare class EqualsOperation<TParam> extends BaseOperation<TParam> {
78 private _test;
79 init(): void;
80 next(item: any, key: Key, parent: any): void;
81}
82export declare const createEqualsOperation: (params: any, owneryQuery: any, options: Options) => EqualsOperation<any>;
83export declare class NopeOperation<TParam> extends BaseOperation<TParam> {
84 next(): void;
85}
86export declare const numericalOperationCreator: (createNumericalOperation: OperationCreator) => (params: any, owneryQuery: any, options: Options) => Operation | NopeOperation<any>;
87export declare const numericalOperation: (createTester: (any: any) => Tester) => (params: any, owneryQuery: any, options: Options) => Operation | NopeOperation<any>;
88export declare type Options = {
89 operations: {
90 [identifier: string]: OperationCreator;
91 };
92 compare: (a: any, b: any) => boolean;
93};
94export declare const containsOperation: (query: any) => boolean;
95export declare const createQueryOperation: (query: any, owneryQuery: any, options: Options) => any;
96export declare const createQueryTester: <TItem, TSchema = TItem>(query: Query<TSchema, false>, { compare, operations }?: Partial<Options>) => (item: TItem, key?: Key, owner?: any) => any;
97export {};