1 | import { Key, Comparator } from "./utils";
|
2 | export interface Operation {
|
3 | readonly success: boolean;
|
4 | readonly done: boolean;
|
5 | reset(): any;
|
6 | next(item: any, key: Key, owner: any): any;
|
7 | }
|
8 | export declare type Tester = (item: any, key?: Key, owner?: any) => boolean;
|
9 | export declare type OperationCreator = (params: any, parentQuery: any, options: Options) => Operation;
|
10 | declare 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 | };
|
27 | declare type ArrayValueQuery<TValue> = {
|
28 | $elemMatch?: Query<TValue, true>;
|
29 | } & BasicValueQuery<TValue>;
|
30 | declare type Unpacked<T> = T extends (infer U)[] ? U : T;
|
31 | declare type ValueQuery<TValue> = TValue extends Array<any> ? ArrayValueQuery<Unpacked<TValue>> : BasicValueQuery<TValue>;
|
32 | declare type NotObject = string | number | Date | boolean | Array<any>;
|
33 | declare type ShapeQuery<TItemSchema> = TItemSchema extends NotObject ? {} : {
|
34 | [k in keyof TItemSchema]?: TItemSchema[k] | ValueQuery<TItemSchema[k]>;
|
35 | };
|
36 | export declare type Query<TItemSchema, nested = false> = ValueQuery<TItemSchema> & ShapeQuery<TItemSchema>;
|
37 | export 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 | }
|
48 | export 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 | }
|
61 | export declare class QueryOperation extends GroupOperation {
|
62 | |
63 |
|
64 | next(item: any, key: Key, parent: any): void;
|
65 | }
|
66 | export 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 | }
|
76 | export declare const createTester: (a: any, compare: Comparator) => any;
|
77 | export declare class EqualsOperation<TParam> extends BaseOperation<TParam> {
|
78 | private _test;
|
79 | init(): void;
|
80 | next(item: any, key: Key, parent: any): void;
|
81 | }
|
82 | export declare const createEqualsOperation: (params: any, owneryQuery: any, options: Options) => EqualsOperation<any>;
|
83 | export declare class NopeOperation<TParam> extends BaseOperation<TParam> {
|
84 | next(): void;
|
85 | }
|
86 | export declare const numericalOperationCreator: (createNumericalOperation: OperationCreator) => (params: any, owneryQuery: any, options: Options) => Operation | NopeOperation<any>;
|
87 | export declare const numericalOperation: (createTester: (any: any) => Tester) => (params: any, owneryQuery: any, options: Options) => Operation | NopeOperation<any>;
|
88 | export declare type Options = {
|
89 | operations: {
|
90 | [identifier: string]: OperationCreator;
|
91 | };
|
92 | compare: (a: any, b: any) => boolean;
|
93 | };
|
94 | export declare const containsOperation: (query: any) => boolean;
|
95 | export declare const createQueryOperation: (query: any, owneryQuery: any, options: Options) => any;
|
96 | export declare const createQueryTester: <TItem, TSchema = TItem>(query: Query<TSchema, false>, { compare, operations }?: Partial<Options>) => (item: TItem, key?: Key, owner?: any) => any;
|
97 | export {};
|