Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
## Installation

`typings install github:meteor-typings/validated-method#5244da37df5e49812ca5afe6520642f875921665 --global`
Place typings in some directory, e.g. `/@types/validated-methods/index.d.ts`.

Update `tsconfig.json` to specify directory of the typings. See [@types, –typeRoots and –types](https://www.typescriptlang.org/docs/handbook/tsconfig-json.html#types-typeroots-and-types) for more details.

```json
{
"compilerOptions": {
// ...,
"typeRoots": [
"node_modules/@types",
"./@types"
],
// ...
}
}
```

## Usage

```typescript
import { ValidatedMethod } from 'meteor/mdg:validated-method';

export const create = new ValidatedMethod({
name: 'todos.create',
validate: null,
run({ id, ...rest }) {
return Todos.insert({
id,
...rest
});
}
});

```
44 changes: 44 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
declare module 'meteor/mdg:validated-method' {
export class ValidatedMethod<T, U> {
constructor(options: {
/**
* DDP method name
*/
name: string;
/**
* Method extensions
*/
mixins?: Function[];
/**
* Argument validation. Use null if method does not need argument validation or it does not take any arguments
*/
validate: null | ((args: any) => boolean); // returned from SimpleSchemaInstance.validator() method;
/**
* Use this to pass options into Meteor.apply every time this method is called. This can be used, for instance, to
* ask meteor not to retry this method if it fails.
*/
applyOptions?: {
noRetry: boolean;
returnStubValue: boolean;
throwStubExceptions: boolean;
onResultReceived: (result: any) => void;
[key: string]: any };
/**
* This is the body of the method. Use ES2015 object destructuring to get the keyword arguments.
*/
run: (args: T) => U;
})

call(args: T, cb?: (error: any, result: any) => void ): U;

/**
* Run method.
*/
run(args: T): U;

/**
* Call this from your test code to simulate calling a method on behalf of a particular user.
*/
_execute(context: { [key: string]: any; }, args: { [key: string]: any; }): void;
}
}
30 changes: 0 additions & 30 deletions main.d.ts

This file was deleted.

10 changes: 0 additions & 10 deletions package.json

This file was deleted.

7 changes: 0 additions & 7 deletions typings.json

This file was deleted.