-
Notifications
You must be signed in to change notification settings - Fork 1
/
method.d.ts
193 lines (176 loc) · 8.61 KB
/
method.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import { Meteor } from 'meteor/meteor';
import { Match } from 'meteor/check';
import type * as z from 'zod';
import SimpleSchema from 'simpl-schema';
export interface PipelineContext<T> {
originalInput: T,
type: 'method',
name: string | null;
onError: (err: any) => any;
onResult: (result: any) => void;
stop: () => void;
}
export interface CreateMethodPipeline<I, This = Meteor.MethodThisType> {
<R1>(fn1: (this: This, input: I, context: PipelineContext<I>) => R1): (...args: I extends undefined ? [] : [I]) => Promise<R1>;
<R1, R2>(fn1: (this: This, input: I, context: PipelineContext<I>) => R1, fn2: (this: This, input: Awaited<R1>, context: PipelineContext<I>) => R2,): (...args: I extends undefined ? [] : [I]) => Promise<R2>;
<R1, R2, R3>(fn1: (this: This, input: I, context: PipelineContext<I>) => R1, fn2: (this: This, input: Awaited<R1>, context: PipelineContext<I>) => R2, fn3: (this: This, input: Awaited<R2>, context: PipelineContext<I>) => R3): (...args: I extends undefined ? [] : [I]) => Promise<R3>;
<R1, R2, R3, R4>(fn1: (this: This, input: I, context: PipelineContext<I>) => R1, fn2: (this: This, input: Awaited<R1>, context: PipelineContext<I>) => R2, fn3: (this: This, input: Awaited<R2>, context: PipelineContext<I>) => R3, fn4: (this: This, input: Awaited<R3>, context: PipelineContext<I>) => R4): (...args: I extends undefined ? [] : [I]) => Promise<R4>;
<R1, R2, R3, R4, R5>(fn1: (this: This, input: I, context: PipelineContext<I>) => R1, fn2: (this: This, input: Awaited<R1>, context: PipelineContext<I>) => R2, fn3: (this: This, input: Awaited<R2>, context: PipelineContext<I>) => R3, fn4: (this: This, input: Awaited<R3>, context: PipelineContext<I>) => R4, fn5: (this: This, input: Awaited<R4>, context: PipelineContext<I>) => R5): (...args: I extends undefined ? [] : [I]) => Promise<R5>;
<R1, R2, R3, R4, R5, R6>(fn1: (this: This, input: I, context: PipelineContext<I>) => R1, fn2: (this: This, input: Awaited<R1>, context: PipelineContext<I>) => R2, fn3: (this: This, input: Awaited<R2>, context: PipelineContext<I>) => R3, fn4: (this: This, input: Awaited<R3>, context: PipelineContext<I>) => R4, fn5: (this: This, input: Awaited<R4>, context: PipelineContext<I>) => R5, fn6: (this: This, input: Awaited<R5>, context: PipelineContext<I>) => R6): (...args: I extends undefined ? [] : [I]) => Promise<R6>;
<R1, R2, R3, R4, R5, R6, R7>(fn1: (this: This, input: I, context: PipelineContext<I>) => R1, fn2: (this: This, input: Awaited<R1>, context: PipelineContext<I>) => R2, fn3: (this: This, input: Awaited<R2>, context: PipelineContext<I>) => R3, fn4: (this: This, input: Awaited<R3>, context: PipelineContext<I>) => R4, fn5: (this: This, input: Awaited<R4>, context: PipelineContext<I>) => R5, fn6: (this: This, input: Awaited<R5>, context: PipelineContext<I>) => R6, fn7: (this: This, input: Awaited<R1>, context: PipelineContext<I>) => R7): (...args: I extends undefined ? [] : [I]) => Promise<R7>;
<R1, R2, R3, R4, R5, R6, R7, R8>(fn1: (this: This, input: I, context: PipelineContext<I>) => R1, fn2: (this: This, input: Awaited<R1>, context: PipelineContext<I>) => R2, fn3: (this: This, input: Awaited<R2>, context: PipelineContext<I>) => R3, fn4: (this: This, input: Awaited<R3>, context: PipelineContext<I>) => R4, fn5: (this: This, input: Awaited<R4>, context: PipelineContext<I>) => R5, fn6: (this: This, input: Awaited<R5>, context: PipelineContext<I>) => R6, fn7: (this: This, input: Awaited<R1>, context: PipelineContext<I>) => R7, fn8: (this: This, input: Awaited<R7>, context: PipelineContext<I>) => R8): (...args: I extends undefined ? [] : [I]) => Promise<R8>;
}
export declare function validate<D, Z extends z.ZodTypeAny>(data: D): z.output<Z> | D;
/**
* Create a method with specified properties or given a function.
* @template {import('meteor/check').Match.Pattern | import('zod').ZodTypeAny | import('simpl-schema').SimpleSchema} S - The schema type (jam:easy-schema, check, Zod, or simple-schema)
* @template T - The return type
* @param {{
* name: string,
* schema?: S,
* validate?: Function,
* before?: Function | Array<Function>,
* after?: Function | Array<Function>,
* run?: (this: Meteor.MethodThisType, args?: z.output<S> | S) => T,
* rateLimit?: { limit: number, interval: number },
* open?: boolean,
* serverOnly?: boolean,
* options?: Object
* } | Function } config - Options for creating the method. Can be a function instead (see functional-style syntax in docs).
* @returns {(...args?: (z.input<S> | S)[]) => Promise<T> | { pipe: (...fns: Function[]) => (...args?: (z.input<S> | S)[]) => Promise<T> }} - The method function or an object with a `pipe` method
*/
export declare const createMethod: {
validate: typeof validate;
validate: {
only: typeof validate;
};
<S extends z.ZodTypeAny, T>(
config: {
name: string,
schema: S,
rateLimit?: { interval: number; limit: number },
validate?: Function,
before?: Function | Array<Function>,
after?: Function | Array<Function>,
open?: boolean,
serverOnly?: boolean,
options?: Object,
run: (this: Meteor.MethodThisType, args: z.output<S>) => T
}
): (...args: S extends z.ZodUndefined ? [] : [z.input<S>]) => Promise<T>;
<S extends Match.Pattern | SimpleSchema, T>(
config: {
name: string,
schema?: S,
validate?: Function,
rateLimit?: { interval: number; limit: number },
before?: Function | Array<Function>,
after?: Function | Array<Function>,
open?: boolean,
serverOnly?: boolean,
options?: Object,
run: (this: Meteor.MethodThisType, args?: any) => T
}
): (...args?: any) => Promise<T>;
<S extends z.ZodTypeAny>(
config: {
name: string,
schema: S,
rateLimit?: { interval: number; limit: number },
before?: Function | Array<Function>,
after?: Function | Array<Function>,
open?: boolean,
serverOnly?: boolean,
options?: Object,
}
): { pipe: CreateMethodPipeline<z.output<S>> };
<S extends Match.Pattern | SimpleSchema>(
config: {
name: string,
schema?: S,
validate?: Function,
rateLimit?: { interval: number; limit: number },
before?: Function | Array<Function>,
after?: Function | Array<Function>,
open?: boolean,
serverOnly?: boolean,
options?: Object,
}
): { pipe: CreateMethodPipeline<any> };
<T>(method: T): (...args?: any) => Promise<T>;
call<S, T>(
context: Meteor.MethodThisType,
...args: Array<S | z.input<S>>
): Promise<T>;
};
type Methods = {
config: {
before?: Function | Function[];
after?: Function | Function[];
serverOnly?: boolean;
options?: {
returnStubValue?: boolean;
throwStubExceptions?: boolean;
};
open?: boolean;
loggedOutError?: Error | Meteor.Error;
};
configure: (options: {
before?: Function | Function[];
after?: Function | Function[];
serverOnly?: boolean;
options?: {
returnStubValue?: boolean;
throwStubExceptions?: boolean;
};
open?: boolean;
loggedOutError?: Error | Meteor.Error;
}) => any;
create: typeof createMethod
};
export declare const Methods: Methods;
/**
* Creates a higher-order function with an attached schema value.
*
* @param schemaValue - The schema value to be attached to the function.
* @returns A higher-order function that has the provided schema value attached.
*/
export declare const schema: <T>(schemaValue: T) => (fn: Function) => Function;
/**
* Wraps a function to make it run on the server only.
*
* @param {function} fn - The function to be marked as server only.
* @returns {function} - The marked function that only executes on the server side. On the client, it returns a noop.
*/
export function server(fn: () => void): () => void;
/**
* Wraps a function to make it open - aka NOT require a logged-in user.
*
* @param {function} fn - The function to be marked as open.
* @returns {function} - The marked function.
*/
export declare function open(fn: Function): Function;
/**
* Wraps a function to make it closed - aka require a logged-in user.
*
* @param {function} fn - The function to be marked as closed.
* @returns {function} - The marked function.
*/
export declare function close(fn: Function): Function;
declare module 'meteor/mongo' {
module Mongo {
interface Collection {
attachMethods(
methods: { [methodName: string]: Function },
options?: {
before?: Function | Array<Function>;
after?: Function | Array<Function>;
rateLimit?: { limit: number; interval: number };
open?: boolean;
serverOnly?: boolean;
options?: object;
}
): void;
}
}
}