Merge pull request #3521 from fullflavedave/master

Definitions for Meteor 1.0.3.1 and TypeScript 1.4
This commit is contained in:
John Reilly
2015-01-23 07:30:52 +00:00
3 changed files with 535 additions and 463 deletions
+72 -41
View File
@@ -1,9 +1,11 @@
# Meteor Type Definitions
These are the definitions for version 0.9.1 of Meteor. Although these definitions can be downloaded separately for use, the recommended way to use these
These are the definitions for version 1.0.3.1 of Meteor.
Although these definitions can be downloaded separately for use, the recommended way to use these
definitions in a Meteor application is by installing the [typescript-libs](https://atmosphere.meteor.com/package/typescript-libs) Meteor smart package.
The smart package contains TypeScript definitions forMeteor, common third-party libraries (e.g. jquery, underscore, d3 etc.), and common smart packages
(e.g. iron-router).
(e.g. iron-router, etc).
From within any Meteor application that is version 0.9.0 or later, install this package in the standard manner:
@@ -11,28 +13,42 @@ From within any Meteor application that is version 0.9.0 or later, install this
## Usage Overview
For most applications, there are 4 specific steps you will have to take to write your Meteor application in TypeScript using this package:
## Usage
1. [Reference the definitions] (#usage-type-definition-references)
2. [Declare functions for Templates in a special way] (#usage-templates)
3. [Declare Collections in a special way] (#usage-collections)
4. [Create custom definitions for code you write] (#usage-creating-definitions)
5. [Transpile your .ts files into .js files] (#usage-transpilation)
1. Add a symbolic link to the definitions from within some directory within your project (e.g. ".typescript" or "lib"). The definitions can be found somewhere
deep within `<project_root_dir>/.meteor/...`. The following will probably work:
$ ln -s ../.meteor/local/build/programs/server/assets/packages/meteortypescript_typescript-libs/definitions package_defs
If the definitions can't be found within the .meteor directory, you will have to manually pull down the definitions from github and add them to your project:
<https://github.com/meteor-typescript/meteor-typescript-libs>
## Usage: Type Definition References
Within any TypeScript file, you can reference the Meteor definition file with this line:
2. Install the [Typescript compiler for Meteor](https://github.com/meteor-typescript/meteor-typescript-compiler) or an [IDE which can transpile TypeScript to JavaScript](#transpiling-typescript).
3. From the typescript files, add references. Reference the definition files with a single line:
///<reference path="/path/to/packages/typescript-libs/meteor.d.ts" />
/// <reference path=".typescript/package_defs/all-definitions.d.ts" /> (substitute path in your project)
Or you can reference definition files individually:
## Usage: Templates
When specifying template functions, you will need to use "bracket notation" instead of "dot notation":
/// <reference path=".typescript/package_defs/meteor.d.ts" /> (substitue path in your project)
/// <reference path=".typescript/package_defs/underscore.d.ts" />
/// <reference path=".typescript/package_defs/jquery.d.ts" />
Template['myTemplateName']['rendered'] = function ( ) { ... }
4. Be aware of differences in coding styles when using TypeScript (see below)
## TypeScript/Meteor coding style
### References
Try to stay away from referencing *file.ts*, rather generate a *file.d.ts* using `tsc --reference file.ts`, and reference it in your file. Compilation will
be much faster and code cleaner - it's always better to split definition from implemention.
### Templates
When specifying template *helpers*, *events*, and functions for *created*, *rendered*, and *destroyed*, you will need to use a "bracket notation" instead of the "dot notation":
Template['myTemplateName']['helpers']({
foo: function () {
@@ -40,21 +56,28 @@ When specifying template functions, you will need to use "bracket notation" inst
}
});
Template['myTemplateName']['foo'] = function () {
return Session.get("foo");
};
Template['myTemplateName']['rendered'] = function ( ) { ... }
This is because TypeScript enforces typing and it will throw an error saying "myTemplateName" does not exist when using the dot notation.
For "dot" notation, TypeScript requires properties be specified on a variable (but not for bracket notation), and it will throw an error saying "myTemplateName"
does not exist on Template.
### Accessing a Form field
Trying to read a form field value? use `(<HTMLInputElement>evt.target).value`.
### Global variables
## Usage: Collections
The majority of extra work required to use TypeScript with Meteor is creating and maintaining the collection interfaces. However, doing so also provides the
Preface any global variable declarations with a TypeScript "declare var" statement:
declare var NavbarHelpers;
NavbarHelpers = {};
NavbarHelpers.someMethod = function() {...}
### Collections
The majority of extra work required to use TypeScript with Meteor is creating and maintaining the collection interfaces. However, doing so also provides the
additional benefit of succinctly documenting collection schema definitions (that are actually enforced).
To define collections, you will need to create an interface representing the collection, and then declare a Collection type variable with that interface type (as a generic):
To define collections, you will need to create an interface representing the collection and then declare a Collection type variable with that interface type (as a generic):
interface JobDAO {
_id?: string;
@@ -63,39 +86,47 @@ To define collections, you will need to create an interface representing the col
queuedAt?: string;
}
declare var Jobs: Meteor.Collection<JobDAO>;
Jobs = new Meteor.Collection<JobDAO>('jobs');
declare var Jobs: Mongo.Collection<JobDAO>;
Jobs = new Mongo.Collection<JobDAO>('jobs');
Finally, any TypeScript file using collections will need to contain a reference at the top pointing to the collection definitions:
/// <reference path="../packages/typescript-libs/meteor.d.ts"/>
/// <reference path="../packages/typescript-libs/underscore.d.ts"/>
/// <reference path="models/models.ts"/>
/// <reference path=".typescript/package_defs/meteor.d.ts"/>
/// <reference path=".typescript/custom_defs/collections.ts"/>
### Creating definition files
If you choose to define collections (using the code above) in a separate file (e.g. collections/models/models.ts) and then create a separate file per collection
with the methods and permissions for that collection (e.g. collections/jobs.ts), the collection definitions should be one directory deeper than the collection
method/permission declarations so that Meteor can find the variable declarations before use. (e.g. collections/models/models.ts).
## Usage: Creating Definitions
Here is a guide to creating definitions: <http://www.typescriptlang.org/Handbook#writing-dts-files>
If you have lots of custom definitions for a project, you can:
- Create multiple definition files and include individual references to each definition file.
- Create one huge monolithic definition file so you only have to refer to that file.
- Create multiple definition files, and create a definition file with references to the other definitions files so that you only have to maintain one reference
for all of you custom definitions. e.g. contents of ".typescript/custom_defs/custom-definitions.d.ts":
## Usage: Transpilation
WebStorm is good TypeScript-aware editor. It can automatically transpile your TypeScript code into JavaScript every time you save a file. To enable this
/// <reference path='collections.ts' />
/// <reference path='paraview_helpers.d.ts'/>
/// <reference path='handsontable.d.ts'/>
/// <reference path='utility_helpers.ts'/>
## Transpiling TypeScript
### Meteor plugin
One solution for transpiling typescript is to install the following meteor package [https://github.com/meteor-typescript/meteor-typescript-compiler](https://github.com/meteor-typescript/meteor-typescript-compiler)
### IDE/Editor Transpilation
WebStorm is a good TypeScript-aware editor. It can automatically transpile your TypeScript code into JavaScript every time you save a file. To enable this
feature in WebStorm on OSX, first install the TypeScript transpiler on your system:
$ [sudo -H] npm install -g typescript
Then, within WebStorm, go to Preferences -> File Watchers -> "+" symbol and add TypeScript.
If you are not using a TypeScript-aware editor, you can transpile the files using the [Meteor Typescript Compiler](https://github.com/orefalo/meteor-typescript-compiler).
### Command line
Last option, is to compile code from the command line. With node and the typescript compiler installed:
## Example/Reference Projects
* [TypeScript demos](https://github.com/orefalo/meteor-typescript-demos)
$ tsc *.ts
+8 -9
View File
@@ -124,7 +124,7 @@ Meteor.methods({
var you_want_to_throw_an_error = true;
if (you_want_to_throw_an_error)
throw new Meteor.Error(404, "Can't find my pants");
throw new Meteor.Error("404", "Can't find my pants");
return "some return value";
},
@@ -376,7 +376,7 @@ Accounts.ui.config({
Accounts.validateNewUser(function (user) {
if (user.username && user.username.length >= 3)
return true;
throw new Meteor.Error(403, "Username must have at least 3 characters");
throw new Meteor.Error("403", "Username must have at least 3 characters");
});
// Validate username, without a specific error message.
Accounts.validateNewUser(function (user) {
@@ -530,13 +530,6 @@ Meteor.methods({
// Let other method calls from the same client start running,
// without waiting for the email sending to complete.
this.unblock();
Email.send({
to: to,
from: from,
subject: subject,
text: text
});
}
});
@@ -561,3 +554,9 @@ Blaze.toHTMLWithData(testTemplate, {test: 1});
Blaze.toHTMLWithData(testTemplate, function() {});
Blaze.toHTMLWithData(testView, {test: 1});
Blaze.toHTMLWithData(testView, function() {});
var reactiveVar1 = new ReactiveVar('test value');
var reactiveVar2 = new ReactiveVar('test value', function(oldVal) { return true; });
var varValue: string = reactiveVar1.get();
reactiveVar1.set('new value');
+455 -413
View File
@@ -1,19 +1,86 @@
// Type definitions for Meteor 0.9.1
// Type definitions for Meteor 1.0.3.1
// Project: http://www.meteor.com/
// Definitions by: Dave Allen <https://github.com/fullflavedave>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/**
* These are the modules and interfaces that can't be automatically generated from the Meteor api.js file
* These are the modules and interfaces that can't be automatically generated from the Meteor data.js file
*/
interface EJSON extends JSON {}
interface Template {
[templateName: string]: Meteor.Template;
}
declare module Match {
var Any;
var String;
var Integer;
var Boolean;
var undefined;
//function null(); // not allowed in TypeScript
var Object;
function Optional(pattern):boolean;
function ObjectIncluding(dico):boolean;
function OneOf(...patterns);
function Where(condition);
}
declare module Meteor {
interface EJSONObject extends Object {}
//interface EJSONObject extends Object {}
/** Start definitions for Template **/
// DA: "Template" needs to support these functions:
// Template.<your template name>.rendered
// Template.<your template name>.created
// Template.<your template name>.destroyed
// Template.<your template name>.helpers
// Template.<your template name>.events
// and
// Template.currentData
// Template.parentData, etc.
interface Event {
type:string;
target:HTMLElement;
currentTarget:HTMLElement;
which: number;
stopPropagation():void;
stopImmediatePropagation():void;
preventDefault():void;
isPropagationStopped():boolean;
isImmediatePropagationStopped():boolean;
isDefaultPrevented():boolean;
}
interface EventHandlerFunction extends Function {
(event?:Meteor.Event):any;
}
interface EventMap {
[id:string]:Meteor.EventHandlerFunction;
}
// Same definition as top-level Template Interface
interface TemplateBase {
[templateName: string]: Meteor.Template;
}
interface Template {
rendered: Function;
created: Function;
destroyed: Function;
events(eventMap:Meteor.EventMap): void;
helpers(helpers:{[id:string]: any}): void;
}
/** End definitions for Template **/
interface LoginWithExternalServiceOptions {
requestPermissions?: string[];
requestOfflineToken?: Boolean;
forceApprovalPrompt?: Boolean;
userEmail?: string;
loginStyle?: string;
}
function loginWithMeteorDeveloperAccount(options?: Meteor.LoginWithExternalServiceOptions, callback?: Function): void;
@@ -43,14 +110,6 @@ declare module Meteor {
ready(): boolean;
}
interface TemplateBase {
[templateName: string]: Meteor.Template;
}
interface RenderedTemplate extends Object {}
interface DataContext extends Object {}
interface Tinytest {
add(name:string, func:Function);
addAsync(name:string, func:Function);
@@ -81,31 +140,32 @@ declare module Meteor {
verifyEmail: Meteor.EmailFields;
}
interface AccountsBase {
EmailTemplates: {
from: string;
siteName: string;
resetPassword: Meteor.EmailFields;
enrollAccount: Meteor.EmailFields;
verifyEmail: Meteor.EmailFields;
}
loginServicesConfigured(): boolean;
interface Error {
error: number;
reason?: string;
details?: string;
}
interface MatchBase {
Any;
String;
Integer;
Boolean;
undefined;
null;
Object;
Optional(pattern):boolean;
ObjectIncluding(dico):boolean;
OneOf(...patterns);
Where(condition);
interface Connection {
id: string;
close: Function;
onClose: Function;
clientAddress: string;
httpHeaders: Object;
}
}
declare module Mongo {
interface Selector extends Object {}
interface Modifier {}
interface SortSpecifier {}
interface FieldSpecifier {
[id: string]: Number;
}
enum IdGenerationEnum {
STRING,
MONGO
}
interface AllowDenyOptions {
insert?: (userId:string, doc) => boolean;
update?: (userId, doc, fieldNames, modifier) => boolean;
@@ -113,95 +173,9 @@ declare module Meteor {
fetch?: string[];
transform?: Function;
}
interface Error {
error: number;
reason?: string;
details?: string;
}
}
declare module Mongo {
interface CollectionFieldSpecifier {
[id: string]: Number;
}
enum CollectionIdGenerationEnum {
STRING,
MONGO
}
// interface CollectionOptions {
// connection: Object;
// idGeneration: Mongo.CollectionIdGenerationEnum;
// transform?: (document)=>any;
// }
//
// function Collection<T>(name:string, options?: Mongo.CollectionOptions) : void;
}
declare module Tracker {
function Computation(): void;
interface Computation {
}
function Dependency(): void;
interface Dependency {
changed(): void;
depend(fromComputation: Tracker.Computation): boolean;
hasDependents(): boolean;
}
}
declare module Package {
function describe(metadata:PackageDescribeAPI);
function on_use(func:{(api:Api, where?:string[]):void});
function on_use(func:{(api:Api, where?:string):void});
function on_test(func:{(api:Api):void}) ;
function register_extension(extension:string, options:PackageRegisterExtensionOptions);
interface PackageRegisterExtensionOptions {(bundle:Bundle, source_path:string, serve_path:string, where?:string[]):void}
interface PackageDescribeAPI {
summary: string;
}
interface Api {
export(variable:string);
export(variables:string[]);
use(deps:string, where?:string[]);
use(deps:string, where?:string);
use(deps:string[], where?:string[]);
use(deps:string[], where?:string);
add_files(file:string, where?:string[]);
add_files(file:string, where?:string);
add_files(file:string[], where?:string[]);
add_files(file:string[], where?:string);
imply(package:string);
imply(packages:string[]);
}
interface BundleOptions {
type: string;
path: string;
data: any;
where: string[];
}
interface Bundle {
add_resource(options:BundleOptions);
error(diagnostics:string);
}
}
declare module Npm {
function require(module:string);
function depends(dependencies:{[id:string]:string});
}
declare module HTTP {
enum HTTPMethodEnum {
GET,
POST,
PUT,
DELETE
}
interface HTTPRequest {
content?:string;
data?:any;
@@ -259,6 +233,8 @@ declare module DDP {
}
declare module Random {
function id(numberOfChars?: number): string;
function secret(numberOfChars?: number): string;
function fraction():number;
function hexString(numberOfDigits:number):string; // @param numberOfDigits, @returns a random hex string of the given length
function choice(array:any[]):string; // @param array, @return a random element in array
@@ -292,339 +268,405 @@ declare module Blaze {
/**
* These modules and interfaces are automatically generated from the Meteor api.js file
*/
declare module Meteor {
var isClient: boolean;
var isServer: boolean;
var isCordova: boolean;
function startup(func: Function): void;
function wrapAsync(func: Function, context?: Object): any;
function absoluteUrl(path?: string, options?: {
secure?: Boolean;
replaceLocalhost?: Boolean;
rootUrl?: string;
}): string;
var settings: {[id:string]: any};
var release: string;
function publish(name: string, func: Function): void;
function subscribe(name, ...args): SubscriptionHandle;
function methods(methods: Object): void;
function Error(error, reason?, details?): void;
function call(name: string, ...params): void;
function apply(name: string, params, options?: {
wait?: Boolean;
onResultReceived?: Function;
}, asyncCallback?): void;
function status(): Meteor.StatusEnum;
function reconnect(): void;
function disconnect(): void;
function onConnection(callback: Function): void;
function user(): Meteor.User;
function userId(): string;
var users: Mongo.Collection<User>;
function loggingIn(): boolean;
function logout(callback?: Function): void;
function logoutOtherClients(callback?: Function): void;
function loginWithPassword(user: any, password: string, callback?: Function): void;
function loginWithExternalService(options?: {
requestPermissions?: string[];
requestOfflineToken?: Boolean;
forceApprovalPrompt?: Boolean;
userEmail?: string;
loginStyle?: string;
}, callback?: Function): void;
function setTimeout(func: Function, delay: number): number;
function setInterval(func: Function, delay: number): number;
function clearTimeout(id: number): void;
function clearInterval(id: number): void;
function EnvironmentVariable(): void;
function get(): string;
function withValue(value: any, func: Function): void;
function bindEnvironment(func: Function, onException: Function, _this: Object): Function;
declare module Accounts {
var ui: {
config(options: {
requestPermissions?: Object;
requestOfflineToken?: Object;
forceApprovalPrompt?: Object;
passwordSignupFields?: string;
}): void;
};
var emailTemplates: Meteor.EmailTemplates;
function config(options: {
sendVerificationEmail?: boolean;
forbidClientAccountCreation?: Boolean;
restrictCreationByEmailDomain?: string | Function;
loginExpirationInDays?: number;
oauthSecretKey?: string;
}): void;
function validateLoginAttempt(func: Function): {stop: Function};
function onLogin(func: Function): {stop: Function};
function onLoginFailure(func: Function): {stop: Function};
function onCreateUser(func: Function): void;
function validateNewUser(func: Function): void;
function onResetPasswordLink(callback: Function): void;
function onEmailVerificationLink(callback: Function): void;
function onEnrollmentLink(callback: Function): void;
function createUser(options: {
username?: string;
email?: string;
password?: string;
profile?: Object;
}, callback?: Function): string;
function changePassword(oldPassword: string, newPassword: string, callback?: Function): void;
function forgotPassword(options: {
email?: string;
}, callback?: Function): void;
function resetPassword(token: string, newPassword: string, callback?: Function): void;
function verifyEmail(token: string, callback?: Function): void;
function setPassword(userId: string, newPassword: string): void;
function sendResetPasswordEmail(userId: string, email?: string): void;
function sendEnrollmentEmail(userId: string, email?: string): void;
function sendVerificationEmail(userId: string, email?: string): void;
}
declare module Meteor {
interface EJSON {
parse(str: string): EJSON;
stringify(val: Meteor.EJSON, options?: {
indent?: any; // boolean, integer, or string
canonical?: Boolean;
}): string;
fromJSONValue(val: JSON): any;
toJSONValue(val: Meteor.EJSON): JSON;
equals(a: Meteor.EJSONObject, b: Meteor.EJSONObject, options?: {
keyOrderSensitive?: Boolean;
}): boolean;
clone<T>(v:T): T; /** TODO: add return value **/
newBinary(size: number): any;
isBinary(x): boolean;
addType(name: string, factory: Function): void;
declare module Blaze {
var currentView: Blaze.View;
function With(data: Object | Function, contentFunc: Function): Blaze.View;
function If(conditionFunc: Function, contentFunc: Function, elseFunc?: Function): Blaze.View;
function Unless(conditionFunc: Function, contentFunc: Function, elseFunc?: Function): Blaze.View;
function Each(argFunc: Function, contentFunc: Function, elseFunc?: Function): Blaze.View;
function isTemplate(value: any): boolean;
function render(templateOrView: Template | Blaze.View, parentNode: Node, nextNode?: Node, parentView?: Blaze.View): Blaze.View;
function renderWithData(templateOrView: Template | Blaze.View, data: Object | Function, parentNode: Node, nextNode?: Node, parentView?: Blaze.View): Blaze.View;
function remove(renderedView: Blaze.View): void;
function toHTML(templateOrView: Template | Blaze.View): string;
function toHTMLWithData(templateOrView: Template | Blaze.View, data: Object | Function): string;
function getData(elementOrView?: HTMLElement | Blaze.View): Object;
function getView(element?: HTMLElement): Blaze.View;
function Template(viewName?: string, renderFunction?: Function): void;
function TemplateInstance(view: Blaze.View): void;
interface TemplateInstance {
data(): Object;
view(): Object;
firstNode(): Object;
lastNode(): Object;
$(selector: string): Node[];
findAll(selector: string): HTMLElement[];
find(selector?: string): HTMLElement;
autorun(runFunc: Function): Object;
}
function View(name?: string, renderFunction?: Function): void;
}
declare module Match {
function test(value: any, pattern: any): boolean;
}
declare module DDP {
function connect(url: string): DDP.DDPStatic;
}
declare module EJSON {
var newBinary: any;
function addType(name: string, factory: Function): void;
function toJSONValue(val: EJSON): JSON;
function fromJSONValue(val: JSON): any;
function stringify(val: EJSON, options?: {
indent?: boolean | number | string;
canonical?: Boolean;
}): string;
function parse(str: string): EJSON;
function isBinary(x: Object): boolean;
function equals(a: EJSON, b: EJSON, options?: {
keyOrderSensitive?: boolean;
}): boolean;
function clone<T>(val:T): T;
function CustomType(): void;
interface CustomType {
typeName(): string;
toJSONValue(): JSON;
clone(): EJSON.CustomType;
equals(other: Object): boolean;
}
}
declare module Meteor {
var users: Mongo.Collection<User>;
var isClient: boolean;
var isServer: boolean;
var settings: {[id:string]: any};
var isCordova: boolean;
var release: string;
function userId(): string;
function loggingIn(): boolean;
function user(): Meteor.User;
function logout(callback?: Function): void;
function logoutOtherClients(callback?: Function): void;
function loginWith<ExternalService>(options?: {
requestPermissions?: string[];
requestOfflineToken?: boolean;
forceApprovalPrompt?: Boolean;
userEmail?: string;
loginStyle?: string;
}, callback?: Function): void;
function loginWithPassword(user: Object | string, password: string, callback?: Function): void;
function subscribe(name: string, ...args): SubscriptionHandle;
function call(name: string, ...args): void;
function apply(name: string, args: EJSON[], options?: {
wait?: boolean;
onResultReceived?: Function;
}, asyncCallback?: Function): void;
function status(): Meteor.StatusEnum;
function reconnect(): void;
function disconnect(): void;
function onConnection(callback: Function): void;
function publish(name: string, func: Function): void;
function methods(methods: Object): void;
function wrapAsync(func: Function, context?: Object): any;
function startup(func: Function): void;
function setTimeout(func: Function, delay: number): number;
function setInterval(func: Function, delay: number): number;
function clearInterval(id: number): void;
function clearTimeout(id: number): void;
function absoluteUrl(path?: string, options?: {
secure?: boolean;
replaceLocalhost?: Boolean;
rootUrl?: string;
}): string;
function Error(error: string, reason?: string, details?: string): void;
}
declare module Mongo {
function Collection<T>(name: string, options?: {
connection?: Object;
idGeneration?: Mongo.CollectionIdGenerationEnum;
transform?: (document)=>any;
}): void;
function ObjectID(hexString: string): void;
}
declare module Mongo {
connection?: Object;
idGeneration?: string;
transform?: Function;
}): void;
interface Collection<T> {
find(selector?: any, options?: {
sort?: any;
skip?: number;
limit?: number;
fields?: Mongo.CollectionFieldSpecifier;
reactive?: Boolean;
transform?: (document)=>any;
}): Mongo.Cursor<T>;
findOne(selector?: any, options?: {
sort?: any;
skip?: number;
fields?: Mongo.CollectionFieldSpecifier;
reactive?: Boolean;
transform?: (document)=>any;
}): Meteor.EJSONObject;
insert(doc: Object, callback?: Function): string;
update(selector: any, modifier: any, options?: {
multi?: Boolean;
upsert?: Boolean;
}, callback?: Function): number;
upsert(selector: any, modifier: any, options?: {
multi?: Boolean;
}, callback?: Function): {numberAffected?: number; insertedId?: string;};
remove(selector: any, callback?: Function): void;
allow(options: Meteor.AllowDenyOptions): boolean;
deny(options: Meteor.AllowDenyOptions): boolean;
insert(doc: Object, callback?: Function): string;
update(selector: Mongo.Selector, modifier: Mongo.Modifier, options?: {
multi?: boolean;
upsert?: Boolean;
}, callback?: Function): number;
find(selector?: Mongo.Selector, options?: {
sort?: Mongo.SortSpecifier;
skip?: number;
limit?: number;
fields?: Mongo.FieldSpecifier;
reactive?: boolean;
transform?: Function;
}): Mongo.Cursor<T>;
findOne(selector?: Mongo.Selector, options?: {
sort?: Mongo.SortSpecifier;
skip?: number;
fields?: Mongo.FieldSpecifier;
reactive?: boolean;
transform?: Function;
}): T;
remove(selector: Mongo.Selector, callback?: Function): void;
upsert(selector: Mongo.Selector, modifier: Mongo.Modifier, options?: {
multi?: boolean;
}, callback?: Function): {numberAffected?: number; insertedId?: string;};
allow(options: {
insert?: (userId:string, doc) => boolean;
update?: (userId, doc, fieldNames, modifier) => boolean;
remove?: (userId, doc) => boolean;
fetch?: string[];
transform?: Function;
}): boolean;
deny(options: {
insert?: (userId:string, doc) => boolean;
update?: (userId, doc, fieldNames, modifier) => boolean;
remove?: (userId, doc) => boolean;
fetch?: string[];
transform?: Function;
}): boolean;
}
}
declare module Mongo {
function ObjectID(hexString: string): void;
function Cursor<T>(): void;
interface Cursor<T> {
count(): number;
fetch(): any[];
forEach(callback: Function, thisArg?: any): void;
forEach(callback: Function, thisArg?: any): void;
map(callback: Function, thisArg?: any): void;
fetch(): Array<T>;
count(): number;
observe(callbacks: Object): Meteor.LiveQueryHandle;
observeChanges(callbacks: Object): Meteor.LiveQueryHandle;
}
}
declare module Random {
function id(): string;
}
declare module Tracker {
function autorun(runFunc: Function): Tracker.Computation;
function flush(): void;
function nonreactive(func: Function): void;
var active: boolean;
var currentComputation: Tracker.Computation;
function Computation(): void;
interface Computation {
stopped(): boolean;
invalidated(): boolean;
firstRun(): boolean;
onInvalidate(callback: Function): void;
invalidate(): void;
stop(): void;
}
function flush(): void;
function autorun(runFunc: Function): Tracker.Computation;
function nonreactive(func: Function): void;
function onInvalidate(callback: Function): void;
function afterFlush(callback: Function): void;
}
declare module Tracker {
interface Computation {
stop(): void;
invalidate(): void;
onInvalidate(callback: Function): void;
stopped: boolean;
invalidated: boolean;
firstRun: boolean;
}
}
declare module Tracker {
function Dependency(): void;
interface Dependency {
depend(fromComputation?: Tracker.Computation): boolean
changed(): void;
depend(fromComputation?: Tracker.Computation): boolean;
hasDependents(): boolean;
hasDependents(): boolean
}
}
declare module Meteor {
interface Accounts extends Meteor.AccountsBase {
config(options: {
sendVerificationEmail?: Boolean;
forbidClientAccountCreation?: Boolean;
restrictCreationByEmailDomain?: any; // string or Function
loginExpirationInDays?: number;
oauthSecretKey?: string;
}): void;
ui: {
config(options: {
requestPermissions?: Object;
requestOfflineToken?: Object;
forceApprovalPrompt?: Boolean;
passwordSignupFields?: string;
}); /** TODO: add return value **/
}
validateNewUser(func: Function): void;
onCreateUser(func: Function): void;
validateLoginAttempt(func: Function); /** TODO: add return value **/
onLogin(func: Function); /** TODO: add return value **/
onLoginFailure(func: Function); /** TODO: add return value **/
createUser(options: {
username?: string;
email?: string;
password?: string;
profile?: Object;
}, callback?: Function): string;
changePassword(oldPassword: string, newPassword: string, callback?: Function): void;
forgotPassword(options: {
email?: string;
}, callback?: Function): void;
resetPassword(token: string, newPassword: string, callback?: Function): void;
setPassword(userId: string, newPassword: string): void;
verifyEmail(token: string, callback?: Function): void;
sendResetPasswordEmail(userId: string, email?: string): void;
sendEnrollmentEmail(userId: string, email?: string): void;
sendVerificationEmail(userId: string, email?: string): void;
emailTemplates: Meteor.EmailTemplates;
}
}
declare module Meteor {
interface Match extends Meteor.MatchBase {
test(value: any, pattern: any): boolean;
}
}
declare module Meteor {
interface Session {
set(key: string, value: any): void;
setDefault(key: string, value: any): void;
get(key: string): any;
equals(key: string, value: any): boolean;
}
}
declare module HTTP {
function call(method: string, url, options?: {
content?: string;
data?: Object;
query?: string;
params?: Object;
auth?: string;
headers?: Object;
timeout?: number;
followRedirects?: Boolean;
}, asyncCallback?): HTTP.HTTPResponse;
function get(url, options?: {
}, asyncCallback?): HTTP.HTTPResponse;
function post(url, options?: {
}, asyncCallback?): HTTP.HTTPResponse;
function put(url, options?: {
}, asyncCallback?): HTTP.HTTPResponse;
function del(url, options?: {
}, asyncCallback?): HTTP.HTTPResponse;
}
declare module Meteor {
interface Template {
rendered: Function;
created: Function;
destroyed: Function;
events(eventMap: {[id:string]: Function}): void;
helpers(helpers: Object): void;
findAll(selector: string); /** TODO: add return value **/
$(selector: string); /** TODO: add return value **/
find(selector?: string); /** TODO: add return value **/
firstNode; /** TODO: add return value **/
lastNode; /** TODO: add return value **/
data; /** TODO: add return value **/
autorun(runFunc: Function); /** TODO: add return value **/
view; /** TODO: add return value **/
registerHelper(name: string, func: Function); /** TODO: add return value **/
body; /** TODO: add return value **/
currentData(); /** TODO: add return value **/
instance(); /** TODO: add return value **/
parentData(numLevels: number); /** TODO: add return value **/
}
}
declare module Blaze {
function render(templateOrView: any, parentNode: Node, nextNode?: Node, parentView?: Blaze.View): Blaze.View;
function renderWithData(templateOrView: any, data: any, parentNode: Node, nextNode?: Node, parentView?: Blaze.View): Blaze.View;
function remove(renderedView: Blaze.View): void;
function With(data: any, contentFunc: Function); /** TODO: add return value **/
function If(conditionFunc: Function, contentFunc: Function, elseFunc?: Function); /** TODO: add return value **/
function Unless(conditionFunc: Function, contentFunc: Function, elseFunc?: Function); /** TODO: add return value **/
function Each(argFunc: Function, contentFunc: Function, elseFunc?: Function); /** TODO: add return value **/
function getData(elementOrView?: any); /** TODO: add return value **/
var currentView; /** TODO: add return value **/
function getView(element?: HTMLElement); /** TODO: add return value **/
function toHTML(templateOrView: any): string;
function toHTMLWithData(templateOrView: any, data: any): string;
function View(name?: string, renderFunction?: Function): void;
function Template(viewName?: string, renderFunction?: Function): void;
function isTemplate(value: any): boolean;
}
declare module Meteor {
interface ReactiveVar {
get(); /** TODO: add return value **/
set(newValue: any); /** TODO: add return value **/
}
}
declare module Email {
function send(options: {
from?: string;
to?: any; // string or string[]
cc?: any; // string or string[]
bcc?: any; // string or string[]
replyTo?: any; // string or string[]
subject?: string;
text?: string;
html?: string;
headers?: Object;
}): void;
}
declare module Assets {
function getText(assetPath: string, asyncCallback?: Function): string;
function getBinary(assetPath: string, asyncCallback?: Function): Meteor.EJSON;
function getBinary(assetPath: string, asyncCallback?: Function): EJSON;
}
declare module Meteor {
interface Package {
describe(options: {
summary?: string;
version?: string;
name?: string;
git?: string;
}); /** TODO: add return value **/
onUse(f: Function); /** TODO: add return value **/
onTest(f: Function); /** TODO: add return value **/
describe(options: {
}); /** TODO: add return value **/
}
declare module App {
function info(options: {
id?: string;
version?: string;
name?: string;
description?: string;
author?: string;
email?: string;
website?: string;
}): void;
function setPreference(name: string, value: string): void;
function configurePlugin(pluginName: string, config: Object): void;
function icons(icons: Object): void;
function launchScreens(launchScreens: Object): void;
}
declare module Meteor {
interface Api {
use(packageNameAndVersion?: string, architecture?: string, options?: {
weak?: Boolean;
unordered?: Boolean;
}); /** TODO: add return value **/
versionsFrom(meteorversion: string); /** TODO: add return value **/
imply(packagespecOrpackagespecs: any); /** TODO: add return value **/
export(exportedObject: string, architecture?: string); /** TODO: add return value **/
addFiles(filenameOrfilenames: any); /** TODO: add return value **/
}
declare module Package {
function describe(options: {
summary?: string;
version?: string;
name?: string;
git?: string;
documentation?: string;
}): void;
function onUse(func: Function): void;
function onTest(func: Function): void;
function registerBuildPlugin(options?: {
name?: string;
use?: string | string[];
sources?: string[];
npmDependencies?: Object;
}): void;
}
declare module Npm {
function depends(dependencies:{[id:string]:string}): void;
function require(name: string): void;
}
declare module Cordova {
function depends(dependencies:{[id:string]:string}): void;
}
declare module Session {
function set(key: string, value: EJSON | any /** Undefined **/): void;
function setDefault(key: string, value: EJSON | any /** Undefined **/): void;
function get(key: string): any;
function equals(key: string, value: string | number | boolean | any /** Null **/ | any /** Undefined **/): boolean;
}
declare module HTTP {
function call(method: string, url: string, options?: {
content?: string;
data?: Object;
query?: string;
params?: Object;
auth?: string;
headers?: Object;
timeout?: number;
followRedirects?: boolean;
}, asyncCallback?: Function): HTTP.HTTPResponse;
function get(url: string, callOptions?: Object, asyncCallback?: Function): HTTP.HTTPResponse;
function post(url: string, callOptions?: Object, asyncCallback?: Function): HTTP.HTTPResponse;
function put(url: string, callOptions?: Object, asyncCallback?: Function): HTTP.HTTPResponse;
function del(url: string, callOptions?: Object, asyncCallback?: Function): HTTP.HTTPResponse;
}
declare module Email {
function send(options: {
from?: string;
to?: string | string[];
cc?: string | string[];
bcc?: string | string[];
replyTo?: string | string[];
subject?: string;
text?: string;
html?: string;
headers?: Object;
}): void;
}
declare function Subscription(): void;
declare module Subscription {
var connection: Meteor.Connection;
var userId: string;
function error(error: Error): void;
function stop(): void;
function onStop(func: Function): void;
function added(collection: string, id: string, fields: Object): void;
function changed(collection: string, id: string, fields: Object): void;
function removed(collection: string, id: string): void;
function ready(): void;
}
declare function ReactiveVar(initialValue: any, equalsFunc?: (oldVal:any, newVal:any)=>boolean): void;
declare module ReactiveVar {
function get(): any;
function set(newValue: any): void;
}
declare function Template(): void;
declare module Template {
var onCreated; /** TODO: add return value **/
var onRendered; /** TODO: add return value **/
var onDestroyed; /** TODO: add return value **/
var created: Function;
var rendered: Function;
var destroyed: Function;
var body: Meteor.TemplateBase;
function helpers(helpers:{[id:string]: any}): void;
function events(eventMap: {[actions: string]: Function}): void;
function instance(): Blaze.TemplateInstance;
function currentData(): {};
function parentData(numLevels?: number): {};
function registerHelper(name: string, helperFunction: Function): void;
}
declare function CompileStep(): void;
declare module CompileStep {
var inputSize; /** TODO: add return value **/
var inputPath; /** TODO: add return value **/
var fullInputPath; /** TODO: add return value **/
var pathForSourceMap; /** TODO: add return value **/
var packageName; /** TODO: add return value **/
var rootOutputPath; /** TODO: add return value **/
var arch; /** TODO: add return value **/
var fileOptions; /** TODO: add return value **/
var declaredExports; /** TODO: add return value **/
function read(n?: number); /** TODO: add return value **/
function addHtml(options: {
section?: string;
data?: string;
}); /** TODO: add return value **/
function addStylesheet(options: {
}, path: string, data: string, sourceMap: string); /** TODO: add return value **/
function addJavaScript(options: {
path?: string;
data?: string;
sourcePath?: string;
}); /** TODO: add return value **/
function addAsset(options: {
}, path: string, data: any /** Buffer **/ | string); /** TODO: add return value **/
function error(options: {
}, message: string, sourcePath?: string, line?: number, func?: string); /** TODO: add return value **/
}
declare function PackageAPI(): void;
declare module PackageAPI {
function use(packageNames: string | string[], architecture?: string, options?: {
weak?: boolean;
unordered?: Boolean;
}): void;
function imply(packageSpecs: string | string[]): void;
function addFiles(filename: string | string[], architecture?: string): void;
function versionsFrom(meteorRelease: string | string[]): void;
// function export(exportedObject: string, architecture?: string): void;
}
declare var Template: Meteor.TemplateBase;
declare var Session: Meteor.Session;
declare var Accounts: Meteor.Accounts;
declare var Match: Meteor.Match;
declare var EJSON: Meteor.EJSON;
declare var Tinytest: Meteor.Tinytest;