UNPKG

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