From 5bf40c59d1cc2c29a79dbfa9e09892d43d2f21d7 Mon Sep 17 00:00:00 2001 From: Nick Lee Date: Sat, 16 May 2015 15:25:33 -0400 Subject: [PATCH 001/122] Added an interface for the object returned during synchronous validations. --- joi/joi.d.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/joi/joi.d.ts b/joi/joi.d.ts index 951fc4045..ad9eb174d 100644 --- a/joi/joi.d.ts +++ b/joi/joi.d.ts @@ -61,6 +61,11 @@ declare module 'joi' { options?: ValidationOptions; } + export interface ValidationResult { + error: ValidationError; + value: T; + } + export interface SchemaMap { [key: string]: Schema; } @@ -461,8 +466,7 @@ declare module 'joi' { */ export function validate(value: T, schema: Schema, callback: (err: ValidationError, value: T) => void): void; export function validate(value: T, schema: Object, callback: (err: ValidationError, value: T) => void): void; - export function validate(value: T, schema: Schema, options?: ValidationOptions, callback?: (err: ValidationError, value: T) => void): void; - export function validate(value: T, schema: Object, options?: ValidationOptions, callback?: (err: ValidationError, value: T) => void): void; + export function validate(value: T, schema: Object, options?: ValidationOptions, callback?: (err: ValidationError, value: T) => void): ValidationResult; /** * Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object). From 2f1df1f63590f9b97134414eab0ea53eea206c94 Mon Sep 17 00:00:00 2001 From: Nick Lee Date: Tue, 2 Jun 2015 12:21:16 -0400 Subject: [PATCH 002/122] Added IP and Hostname validators to Joi.d.ts --- joi/joi.d.ts | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/joi/joi.d.ts b/joi/joi.d.ts index 5e4bfc37b..3df8ada9e 100644 --- a/joi/joi.d.ts +++ b/joi/joi.d.ts @@ -47,11 +47,16 @@ declare module 'joi' { contextPrefix?: string; } + export interface IPOptions { + version?: Array; + cidr?: string + } + export interface ValidationError { message: string; details: ValidationErrorItem[]; - simple (): string; - annotated (): string; + simple(): string; + annotated(): string; } export interface ValidationErrorItem { @@ -82,19 +87,19 @@ declare module 'joi' { /** * Whitelists a value */ - allow(value: any, ...values : any[]): T; + allow(value: any, ...values: any[]): T; allow(values: any[]): T; /** * Adds the provided values into the allowed whitelist and marks them as the only valid values allowed. */ - valid(value: any, ...values : any[]): T; + valid(value: any, ...values: any[]): T; valid(values: any[]): T; /** * Blacklists a value */ - invalid(value: any, ...values : any[]): T; + invalid(value: any, ...values: any[]): T; invalid(values: any[]): T; /** @@ -257,6 +262,16 @@ declare module 'joi' { * Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed. */ trim(): StringSchema; + + /** + * Requires the string value be a valid hostname. + */ + hostname(): StringSchema; + + /** + * Requires the string value to be a valid IP address. + */ + ip(options: IPOptions): StringSchema; /** * Requires the string value to be a valid uri with the passed scheme. @@ -364,7 +379,7 @@ declare module 'joi' { /** * Overrides the handling of unknown keys for the scope of the current object only (does not apply to children). */ - unknown(allow?:boolean): ObjectSchema; + unknown(allow?: boolean): ObjectSchema; } export interface BinarySchema extends AnySchema { @@ -486,5 +501,5 @@ declare module 'joi' { /** * Generates a reference to the value of the named key. */ - export function ref(key:string, options?: ReferenceOptions): Reference; + export function ref(key: string, options?: ReferenceOptions): Reference; } From cde81f5458364ef1dc43a85e1be6a9e132c94e11 Mon Sep 17 00:00:00 2001 From: Nick Lee Date: Wed, 3 Jun 2015 11:18:34 -0400 Subject: [PATCH 003/122] exported BoomError interface on Boom.d.ts --- boom/boom.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/boom/boom.d.ts b/boom/boom.d.ts index d0f05065c..e1539d21b 100644 --- a/boom/boom.d.ts +++ b/boom/boom.d.ts @@ -6,7 +6,8 @@ /// declare module Boom { - interface BoomError { + + export interface BoomError { data: any; reformat: () => void; isBoom: boolean; From 8dd3b27579a67c878e5605b8819718a17c34cf0b Mon Sep 17 00:00:00 2001 From: Laurence Dougal Myers Date: Mon, 22 Jun 2015 17:29:18 +1000 Subject: [PATCH 004/122] Joi: update definitions to v6.5.0 --- joi/joi-tests.ts | 248 ++++++++++++++++++++++++++++++++++++---- joi/joi.d.ts | 292 ++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 491 insertions(+), 49 deletions(-) diff --git a/joi/joi-tests.ts b/joi/joi-tests.ts index 26048a9dc..fc1f8ef25 100644 --- a/joi/joi-tests.ts +++ b/joi/joi-tests.ts @@ -56,6 +56,7 @@ validOpts = {allowUnknown: bool}; validOpts = {skipFunctions: bool}; validOpts = {stripUnknown: bool}; validOpts = {language: bool}; +validOpts = {presence: str}; validOpts = {context: obj}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -65,6 +66,34 @@ var renOpts: Joi.RenameOptions = null; renOpts = {alias: bool}; renOpts = {multiple: bool}; renOpts = {override: bool}; +renOpts = {ignoreUndefined: bool}; + +// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- + +var emailOpts: Joi.EmailOptions = null; + +emailOpts = {errorLevel: num}; +emailOpts = {errorLevel: bool}; +emailOpts = {tldWhitelist: strArr}; +emailOpts = {tldWhitelist: obj}; +emailOpts = {minDomainAtoms: num}; + +// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- + +var ipOpts: Joi.IpOptions = null; + +ipOpts = {version: str}; +ipOpts = {version: strArr}; +ipOpts = {cidr: str}; + +// --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- + +var uriOpts: Joi.UriOptions = null; + +uriOpts = {scheme: str}; +uriOpts = {scheme: exp}; +uriOpts = {scheme: strArr}; +uriOpts = {scheme: expArr}; // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- @@ -144,15 +173,30 @@ module common { anySchema = anySchema.valid(x); anySchema = anySchema.valid(x, x); anySchema = anySchema.valid([x, x, x]); + anySchema = anySchema.only(x); + anySchema = anySchema.only(x, x); + anySchema = anySchema.only([x, x, x]); + anySchema = anySchema.equal(x); + anySchema = anySchema.equal(x, x); + anySchema = anySchema.equal([x, x, x]); anySchema = anySchema.invalid(x); anySchema = anySchema.invalid(x, x); anySchema = anySchema.invalid([x, x, x]); + anySchema = anySchema.disallow(x); + anySchema = anySchema.disallow(x, x); + anySchema = anySchema.disallow([x, x, x]); + anySchema = anySchema.not(x); + anySchema = anySchema.not(x, x); + anySchema = anySchema.not([x, x, x]); + anySchema = anySchema.default(); anySchema = anySchema.default(x); + anySchema = anySchema.default(x, str); anySchema = anySchema.required(); anySchema = anySchema.optional(); anySchema = anySchema.forbidden(); + anySchema = anySchema.strip(); anySchema = anySchema.description(str); anySchema = anySchema.notes(str); @@ -166,43 +210,65 @@ module common { anySchema = anySchema.options(validOpts); anySchema = anySchema.strict(); + anySchema = anySchema.strict(bool); anySchema = anySchema.concat(x); altSchema = anySchema.when(str, whenOpts); altSchema = anySchema.when(ref, whenOpts); + + anySchema = anySchema.label(str); + anySchema = anySchema.raw(); + anySchema = anySchema.raw(bool); + anySchema = anySchema.empty(); + anySchema = anySchema.empty(str); + anySchema = anySchema.empty(anySchema); } // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- arrSchema = Joi.array(); +arrSchema = arrSchema.sparse(); +arrSchema = arrSchema.sparse(bool); +arrSchema = arrSchema.single(); +arrSchema = arrSchema.single(bool); arrSchema = arrSchema.min(num); arrSchema = arrSchema.max(num); arrSchema = arrSchema.length(num); +arrSchema = arrSchema.unique(); -arrSchema = arrSchema.includes(numSchema); -arrSchema = arrSchema.includes(numSchema, strSchema); -arrSchema = arrSchema.includes([numSchema, strSchema]); +arrSchema = arrSchema.items(numSchema); +arrSchema = arrSchema.items(numSchema, strSchema); +arrSchema = arrSchema.items([numSchema, strSchema]); -arrSchema = arrSchema.excludes(numSchema); -arrSchema = arrSchema.excludes(numSchema, strSchema); -arrSchema = arrSchema.excludes([numSchema, strSchema]); // - - - - - - - - module common_copy_paste { // use search & replace from any - anySchema = anySchema.allow(x); - anySchema = anySchema.allow(x, x); - anySchema = anySchema.allow([x, x, x]); - anySchema = anySchema.valid(x); - anySchema = anySchema.valid(x, x); - anySchema = anySchema.valid([x, x, x]); - anySchema = anySchema.invalid(x); - anySchema = anySchema.invalid(x, x); - anySchema = anySchema.invalid([x, x, x]); - - anySchema = anySchema.default(x); + arrSchema = arrSchema.allow(x); + arrSchema = arrSchema.allow(x, x); + arrSchema = arrSchema.allow([x, x, x]); + arrSchema = arrSchema.valid(x); + arrSchema = arrSchema.valid(x, x); + arrSchema = arrSchema.valid([x, x, x]); + arrSchema = arrSchema.only(x); + arrSchema = arrSchema.only(x, x); + arrSchema = arrSchema.only([x, x, x]); + arrSchema = arrSchema.equal(x); + arrSchema = arrSchema.equal(x, x); + arrSchema = arrSchema.equal([x, x, x]); + arrSchema = arrSchema.invalid(x); + arrSchema = arrSchema.invalid(x, x); + arrSchema = arrSchema.invalid([x, x, x]); + arrSchema = arrSchema.disallow(x); + arrSchema = arrSchema.disallow(x, x); + arrSchema = arrSchema.disallow([x, x, x]); + arrSchema = arrSchema.not(x); + arrSchema = arrSchema.not(x, x); + arrSchema = arrSchema.not([x, x, x]); + + arrSchema = arrSchema.default(x); arrSchema = arrSchema.required(); arrSchema = arrSchema.optional(); @@ -238,10 +304,22 @@ module common_copy_paste { boolSchema = boolSchema.valid(x); boolSchema = boolSchema.valid(x, x); boolSchema = boolSchema.valid([x, x, x]); + boolSchema = boolSchema.only(x); + boolSchema = boolSchema.only(x, x); + boolSchema = boolSchema.only([x, x, x]); + boolSchema = boolSchema.equal(x); + boolSchema = boolSchema.equal(x, x); + boolSchema = boolSchema.equal([x, x, x]); boolSchema = boolSchema.invalid(x); boolSchema = boolSchema.invalid(x, x); boolSchema = boolSchema.invalid([x, x, x]); - + boolSchema = boolSchema.disallow(x); + boolSchema = boolSchema.disallow(x, x); + boolSchema = boolSchema.disallow([x, x, x]); + boolSchema = boolSchema.not(x); + boolSchema = boolSchema.not(x, x); + boolSchema = boolSchema.not([x, x, x]); + boolSchema = boolSchema.default(x); boolSchema = boolSchema.required(); @@ -270,6 +348,7 @@ module common_copy_paste { binSchema = Joi.binary(); +binSchema = binSchema.encoding(str); binSchema = binSchema.min(num); binSchema = binSchema.max(num); binSchema = binSchema.length(num); @@ -281,10 +360,22 @@ module common { binSchema = binSchema.valid(x); binSchema = binSchema.valid(x, x); binSchema = binSchema.valid([x, x, x]); + binSchema = binSchema.only(x); + binSchema = binSchema.only(x, x); + binSchema = binSchema.only([x, x, x]); + binSchema = binSchema.equal(x); + binSchema = binSchema.equal(x, x); + binSchema = binSchema.equal([x, x, x]); binSchema = binSchema.invalid(x); binSchema = binSchema.invalid(x, x); binSchema = binSchema.invalid([x, x, x]); - + binSchema = binSchema.disallow(x); + binSchema = binSchema.disallow(x, x); + binSchema = binSchema.disallow([x, x, x]); + binSchema = binSchema.not(x); + binSchema = binSchema.not(x, x); + binSchema = binSchema.not([x, x, x]); + binSchema = binSchema.default(x); binSchema = binSchema.required(); @@ -322,6 +413,14 @@ dateSchema = dateSchema.max(str); dateSchema = dateSchema.min(num); dateSchema = dateSchema.max(num); +dateSchema = dateSchema.min(ref); +dateSchema = dateSchema.max(ref); + +dateSchema = dateSchema.format(str); +dateSchema = dateSchema.format(strArr); + +dateSchema = dateSchema.iso(); + module common { dateSchema = dateSchema.allow(x); dateSchema = dateSchema.allow(x, x); @@ -329,10 +428,22 @@ module common { dateSchema = dateSchema.valid(x); dateSchema = dateSchema.valid(x, x); dateSchema = dateSchema.valid([x, x, x]); + dateSchema = dateSchema.only(x); + dateSchema = dateSchema.only(x, x); + dateSchema = dateSchema.only([x, x, x]); + dateSchema = dateSchema.equal(x); + dateSchema = dateSchema.equal(x, x); + dateSchema = dateSchema.equal([x, x, x]); dateSchema = dateSchema.invalid(x); dateSchema = dateSchema.invalid(x, x); dateSchema = dateSchema.invalid([x, x, x]); - + dateSchema = dateSchema.disallow(x); + dateSchema = dateSchema.disallow(x, x); + dateSchema = dateSchema.disallow([x, x, x]); + dateSchema = dateSchema.not(x); + dateSchema = dateSchema.not(x, x); + dateSchema = dateSchema.not([x, x, x]); + dateSchema = dateSchema.default(x); dateSchema = dateSchema.required(); @@ -366,8 +477,18 @@ funcSchema = Joi.func(); numSchema = Joi.number(); numSchema = numSchema.min(num); +numSchema = numSchema.min(ref); numSchema = numSchema.max(num); +numSchema = numSchema.max(ref); +numSchema = numSchema.greater(num); +numSchema = numSchema.greater(ref); +numSchema = numSchema.less(num); +numSchema = numSchema.less(ref); numSchema = numSchema.integer(); +numSchema = numSchema.precision(num); +numSchema = numSchema.multiple(num); +numSchema = numSchema.positive(); +numSchema = numSchema.negative(); module common { numSchema = numSchema.allow(x); @@ -376,10 +497,22 @@ module common { numSchema = numSchema.valid(x); numSchema = numSchema.valid(x, x); numSchema = numSchema.valid([x, x, x]); + numSchema = numSchema.only(x); + numSchema = numSchema.only(x, x); + numSchema = numSchema.only([x, x, x]); + numSchema = numSchema.equal(x); + numSchema = numSchema.equal(x, x); + numSchema = numSchema.equal([x, x, x]); numSchema = numSchema.invalid(x); numSchema = numSchema.invalid(x, x); numSchema = numSchema.invalid([x, x, x]); - + numSchema = numSchema.disallow(x); + numSchema = numSchema.disallow(x, x); + numSchema = numSchema.disallow([x, x, x]); + numSchema = numSchema.not(x); + numSchema = numSchema.not(x, x); + numSchema = numSchema.not([x, x, x]); + numSchema = numSchema.default(x); numSchema = numSchema.required(); @@ -418,12 +551,23 @@ objSchema = objSchema.length(num); objSchema = objSchema.pattern(exp, schema); +objSchema = objSchema.and(str); +objSchema = objSchema.and(str, str); objSchema = objSchema.and(str, str, str); objSchema = objSchema.and(strArr); +objSchema = objSchema.nand(str); +objSchema = objSchema.nand(str, str); +objSchema = objSchema.nand(str, str, str); +objSchema = objSchema.nand(strArr); + +objSchema = objSchema.or(str); +objSchema = objSchema.or(str, str); objSchema = objSchema.or(str, str, str); objSchema = objSchema.or(strArr); +objSchema = objSchema.xor(str); +objSchema = objSchema.xor(str, str); objSchema = objSchema.xor(str, str, str); objSchema = objSchema.xor(strArr); @@ -442,6 +586,17 @@ objSchema = objSchema.assert(ref, schema, str); objSchema = objSchema.unknown(); objSchema = objSchema.unknown(bool); +objSchema = objSchema.type(func); +objSchema = objSchema.type(func, str); + +objSchema = objSchema.requiredKeys(str); +objSchema = objSchema.requiredKeys(str, str); +objSchema = objSchema.requiredKeys(strArr); + +objSchema = objSchema.optionalKeys(str); +objSchema = objSchema.optionalKeys(str, str); +objSchema = objSchema.optionalKeys(strArr); + module common { objSchema = objSchema.allow(x); objSchema = objSchema.allow(x, x); @@ -449,10 +604,22 @@ module common { objSchema = objSchema.valid(x); objSchema = objSchema.valid(x, x); objSchema = objSchema.valid([x, x, x]); + objSchema = objSchema.only(x); + objSchema = objSchema.only(x, x); + objSchema = objSchema.only([x, x, x]); + objSchema = objSchema.equal(x); + objSchema = objSchema.equal(x, x); + objSchema = objSchema.equal([x, x, x]); objSchema = objSchema.invalid(x); objSchema = objSchema.invalid(x, x); objSchema = objSchema.invalid([x, x, x]); - + objSchema = objSchema.disallow(x); + objSchema = objSchema.disallow(x, x); + objSchema = objSchema.disallow([x, x, x]); + objSchema = objSchema.not(x); + objSchema = objSchema.not(x, x); + objSchema = objSchema.not([x, x, x]); + objSchema = objSchema.default(x); objSchema = objSchema.required(); @@ -483,13 +650,33 @@ strSchema = Joi.string(); strSchema = strSchema.insensitive(); strSchema = strSchema.min(num); +strSchema = strSchema.min(num, str); +strSchema = strSchema.min(ref); +strSchema = strSchema.min(ref, str); strSchema = strSchema.max(num); +strSchema = strSchema.max(num, str); +strSchema = strSchema.max(ref); +strSchema = strSchema.max(ref, str); +strSchema = strSchema.creditCard(); strSchema = strSchema.length(num); +strSchema = strSchema.length(num, str); +strSchema = strSchema.length(ref); +strSchema = strSchema.length(ref, str); strSchema = strSchema.regex(exp); +strSchema = strSchema.regex(exp, str); +strSchema = strSchema.replace(exp, str); +strSchema = strSchema.replace(str, str); strSchema = strSchema.alphanum(); strSchema = strSchema.token(); strSchema = strSchema.email(); +strSchema = strSchema.email(emailOpts); +strSchema = strSchema.ip(); +strSchema = strSchema.ip(ipOpts); +strSchema = strSchema.uri(); +strSchema = strSchema.uri(uriOpts); strSchema = strSchema.guid(); +strSchema = strSchema.hex(); +strSchema = strSchema.hostname(); strSchema = strSchema.isoDate(); strSchema = strSchema.lowercase(); strSchema = strSchema.uppercase(); @@ -502,10 +689,22 @@ module common { strSchema = strSchema.valid(x); strSchema = strSchema.valid(x, x); strSchema = strSchema.valid([x, x, x]); + strSchema = strSchema.only(x); + strSchema = strSchema.only(x, x); + strSchema = strSchema.only([x, x, x]); + strSchema = strSchema.equal(x); + strSchema = strSchema.equal(x, x); + strSchema = strSchema.equal([x, x, x]); strSchema = strSchema.invalid(x); strSchema = strSchema.invalid(x, x); strSchema = strSchema.invalid([x, x, x]); - + strSchema = strSchema.disallow(x); + strSchema = strSchema.disallow(x, x); + strSchema = strSchema.disallow([x, x, x]); + strSchema = strSchema.not(x); + strSchema = strSchema.not(x, x); + strSchema = strSchema.not([x, x, x]); + strSchema = strSchema.default(x); strSchema = strSchema.required(); @@ -537,6 +736,7 @@ schema = Joi.alternatives(schema, anySchema, boolSchema); // --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- +Joi.validate(value, obj); Joi.validate(value, schema); Joi.validate(value, schema, validOpts); Joi.validate(value, schema, validOpts, (err, value) => { @@ -566,6 +766,8 @@ Joi.validate(value, {}); schema = Joi.compile(obj); Joi.assert(obj, schema); +Joi.assert(obj, schema, str); +Joi.assert(obj, schema, err); ref = Joi.ref(str, refOpts); ref = Joi.ref(str); diff --git a/joi/joi.d.ts b/joi/joi.d.ts index 5e4bfc37b..20ef52a66 100644 --- a/joi/joi.d.ts +++ b/joi/joi.d.ts @@ -1,6 +1,6 @@ // Type definitions for joi v4.6.0 // Project: https://github.com/spumko/joi -// Definitions by: Bart van der Schoor +// Definitions by: Bart van der Schoor , Laurence Dougal Myers // Definitions: https://github.com/borisyankov/DefinitelyTyped // TODO express type of Schema in a type-parameter (.default, .valid, .example etc) @@ -19,7 +19,9 @@ declare module 'joi' { // when true, unknown keys are deleted (only when value is an object). Defaults to false. stripUnknown?: boolean; // overrides individual error messages. Defaults to no override ({}). - language?: Object + language?: Object; + // sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'. Defaults to 'optional'. + presence?: string; // provides an external data set to be used in references context?: Object; } @@ -33,6 +35,28 @@ declare module 'joi' { override?: boolean; } + export interface EmailOptions { + // Numerical threshold at which an email address is considered invalid + errorLevel?: number | boolean; + // Specifies a list of acceptable TLDs. + tldWhitelist?: string[] | Object; + // Number of atoms required for the domain. Be careful since some domains, such as io, directly allow email. + minDomainAtoms?: number; + } + + export interface IpOptions { + // One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture + version ?: string | string[]; + // Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden + cidr?: string; + } + + export interface UriOptions { + // Specifies one or more acceptable Schemes, should only include the scheme name. + // Can be an Array or String (strings are automatically escaped for use in a Regular Expression). + scheme ?: string | RegExp | Array; + } + export interface WhenOptions { // the required condition joi type. is: Schema; @@ -90,12 +114,20 @@ declare module 'joi' { */ valid(value: any, ...values : any[]): T; valid(values: any[]): T; + only(value: any, ...values : any[]): T; + only(values: any[]): T; + equal(value: any, ...values : any[]): T; + equal(values: any[]): T; /** * Blacklists a value */ invalid(value: any, ...values : any[]): T; invalid(values: any[]): T; + disallow(value: any, ...values : any[]): T; + disallow(values: any[]): T; + not(value: any, ...values : any[]): T; + not(values: any[]): T; /** * Marks a key as required which will not allow undefined as value. All keys are optional by default. @@ -112,6 +144,11 @@ declare module 'joi' { */ forbidden(): T; + /** + * Marks a key to be removed from a resulting object or array after validation. Used to sanitize output. + */ + strip(): T; + /** * Annotates the key */ @@ -152,12 +189,28 @@ declare module 'joi' { /** * Sets the options.convert options to false which prevent type casting for the current key and any child keys. */ - strict(): T; + strict(isStrict?: boolean): T; /** * Sets a default value if the original value is undefined. + * @param value - the value. + * value supports references. + * value may also be a function which returns the default value. + * If value is specified as a function that accepts a single parameter, that parameter will be a context + * object that can be used to derive the resulting value. This clones the object however, which incurs some + * overhead so if you don't need access to the context define your method so that it does not accept any + * parameters. + * Without any value, default has no effect, except for object that will then create nested defaults + * (applying inner defaults of that object). + * + * Note that if value is an object, any changes to the object after default() is called will change the + * reference and any future assignment. + * + * Additionally, when specifying a method you must either have a description property on your method or the + * second parameter is required. */ - default(value: any): T; + default(value: any, description?: string): T; + default(): T; /** * Returns a new type that is the result of adding the rules of one type to another. @@ -169,6 +222,22 @@ declare module 'joi' { */ when(ref: string, options: WhenOptions): AlternativesSchema; when(ref: Reference, options: WhenOptions): AlternativesSchema; + + /** + * Overrides the key name in error messages. + */ + label(name: string): T; + + /** + * Outputs the original untouched value instead of the casted value. + */ + raw(isRaw?: boolean): T; + + /** + * Considers anything that matches the schema to be empty (undefined). + * @param schema - any object or joi schema to match. An undefined schema unsets that rule. + */ + empty(schema?: any) : T; } export interface BooleanSchema extends AnySchema { @@ -178,18 +247,57 @@ declare module 'joi' { export interface NumberSchema extends AnySchema { /** * Specifies the minimum value. + * It can also be a reference to another field. */ min(limit: number): NumberSchema; + min(limit: Reference): NumberSchema; /** * Specifies the maximum value. + * It can also be a reference to another field. */ max(limit: number): NumberSchema; + max(limit: Reference): NumberSchema; + + /** + * Specifies that the value must be greater than limit. + * It can also be a reference to another field. + */ + greater(limit: number): NumberSchema; + greater(limit: Reference): NumberSchema; + + /** + * Specifies that the value must be less than limit. + * It can also be a reference to another field. + */ + less(limit: number): NumberSchema; + less(limit: Reference): NumberSchema; /** * Requires the number to be an integer (no floating point). */ integer(): NumberSchema; + + /** + * Specifies the maximum number of decimal places where: + * limit - the maximum number of decimal places allowed. + */ + precision(limit: number): NumberSchema; + + /** + * Specifies that the value must be a multiple of base. + */ + multiple(base: number): NumberSchema; + + /** + * Requires the number to be positive. + */ + positive(): NumberSchema; + + /** + * Requires the number to be negative. + */ + negative(): NumberSchema; } export interface StringSchema extends AnySchema { @@ -200,23 +308,47 @@ declare module 'joi' { /** * Specifies the minimum number string characters. + * @param limit - the minimum number of string characters required. It can also be a reference to another field. + * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. */ - min(limit: number): StringSchema; + min(limit: number, encoding?: string): StringSchema; + min(limit: Reference, encoding?: string): StringSchema; /** * Specifies the maximum number of string characters. + * @param limit - the maximum number of string characters allowed. It can also be a reference to another field. + * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. */ - max(limit: number): StringSchema; + max(limit: number, encoding?: string): StringSchema; + max(limit: Reference, encoding?: string): StringSchema; + + /** + * Requires the number to be a credit card number (Using Lunh Algorithm). + */ + creditCard(): StringSchema; /** * Specifies the exact string length required + * @param limit - the required string length. It can also be a reference to another field. + * @param encoding - if specified, the string length is calculated in bytes using the provided encoding. */ - length(limit: number): StringSchema; + length(limit: number, encoding?: string): StringSchema; + length(limit: Reference, encoding?: string): StringSchema; /** * Defines a regular expression rule. + * @param pattern - a regular expression object the string value must match against. + * @param name - optional name for patterns (useful with multiple patterns). Defaults to 'required'. */ - regex(pattern: RegExp): StringSchema; + regex(pattern: RegExp, name?: string): StringSchema; + + /** + * Replace characters matching the given pattern with the specified replacement string where: + * @param pattern - a regular expression object to match against, or a string of which all occurrences will be replaced. + * @param replacement - the string that will replace the pattern. + */ + replace(pattern: RegExp, replacement: string): StringSchema; + replace(pattern: string, replacement: string): StringSchema; /** * Requires the string value to only contain a-z, A-Z, and 0-9. @@ -231,13 +363,33 @@ declare module 'joi' { /** * Requires the string value to be a valid email address. */ - email(): StringSchema; + email(options?: EmailOptions): StringSchema; + + /** + * Requires the string value to be a valid ip address. + */ + ip(options?: IpOptions): StringSchema; + + /** + * Requires the string value to be a valid RFC 3986 URI. + */ + uri(options?: UriOptions): StringSchema; /** * Requires the string value to be a valid GUID. */ guid(): StringSchema; + /** + * Requires the string value to be a valid hexadecimal string. + */ + hex(): StringSchema; + + /** + * Requires the string value to be a valid hostname as per RFC1123. + */ + hostname(): StringSchema; + /** * Requires the string value to be in valid ISO 8601 date format. */ @@ -257,25 +409,35 @@ declare module 'joi' { * Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed. */ trim(): StringSchema; - - /** - * Requires the string value to be a valid uri with the passed scheme. - */ - uri(options?: { scheme?: string }): StringSchema; } export interface ArraySchema extends AnySchema { - /** - * List the types allowed for the array value - */ - includes(type: Schema, ...types: Schema[]): ArraySchema; - includes(types: Schema[]): ArraySchema; /** - * List the types forbidden for the array values. + * Allow this array to be sparse. + * enabled can be used with a falsy value to go back to the default behavior. */ - excludes(type: Schema, ...types: Schema[]): ArraySchema; - excludes(types: Schema[]): ArraySchema; + sparse(enabled?: any): ArraySchema; + + /** + * Allow single values to be checked against rules as if it were provided as an array. + * enabled can be used with a falsy value to go back to the default behavior. + */ + single(enabled?: any): ArraySchema; + + /** + * List the types allowed for the array values. + * type can be an array of values, or multiple values can be passed as individual arguments. + * If a given type is .required() then there must be a matching item in the array. + * If a type is .forbidden() then it cannot appear in the array. + * Required items can be added multiple times to signify that multiple items must be found. + * Errors will contain the number of items that didn't match. + * Any unmatched item having a label will be mentioned explicitly. + * + * @param type - a joi schema object to validate each array item against. + */ + items(type: Schema, ...types: Schema[]): ArraySchema; + items(types: Schema[]): ArraySchema; /** * Specifies the minimum number of items in the array. @@ -292,6 +454,12 @@ declare module 'joi' { */ length(limit: number): ArraySchema; + /** + * Requires the array values to be unique. + * Be aware that a deep equality is performed on elements of the array having a type of object, + * a performance penalty is to be expected for this kind of operation. + */ + unique(): ArraySchema; } export interface ObjectSchema extends AnySchema { @@ -322,20 +490,30 @@ declare module 'joi' { /** * Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as well. + * @param peers - the key names of which if one present, all are required. peers can be a single string value, + * an array of string values, or each peer provided as an argument. */ - and(peer1: string, peer2: string, ...peers: string[]): ObjectSchema; + and(peer1: string, ...peers: string[]): ObjectSchema; and(peers: string[]): ObjectSchema; + /** + * Defines a relationship between keys where not all peers can be present at the same time. + * @param peers - the key names of which if one present, the others may not all be present. + * peers can be a single string value, an array of string values, or each peer provided as an argument. + */ + nand(peer1: string, ...peers: string[]): ObjectSchema; + nand(peers: string[]): ObjectSchema; + /** * Defines a relationship between keys where one of the peers is required (and more than one is allowed). */ - or(peer1: string, peer2: string, ...peers: string[]): ObjectSchema; + or(peer1: string, ...peers: string[]): ObjectSchema; or(peers: string[]): ObjectSchema; /** * Defines an exclusive relationship between a set of keys. one of them is required but not at the same time where: */ - xor(peer1: string, peer2: string, ...peers: string[]): ObjectSchema; + xor(peer1: string, ...peers: string[]): ObjectSchema; xor(peers: string[]): ObjectSchema; /** @@ -365,9 +543,47 @@ declare module 'joi' { * Overrides the handling of unknown keys for the scope of the current object only (does not apply to children). */ unknown(allow?:boolean): ObjectSchema; + + /** + * Requires the object to be an instance of a given constructor. + * + * @param constructor - the constructor function that the object must be an instance of. + * @param name - an alternate name to use in validation errors. This is useful when the constructor function does not have a name. + */ + type(constructor: Function, name?: string): ObjectSchema; + + /** + * Sets the specified children to required. + * + * @param children - can be a single string value, an array of string values, or each child provided as an argument. + * + * var schema = Joi.object().keys({ a: { b: Joi.number() }, c: { d: Joi.string() } }); + * var requiredSchema = schema.requiredKeys('', 'a.b', 'c', 'c.d'); + * + * Note that in this example '' means the current object, a is not required but b is, as well as c and d. + */ + requiredKeys(children: string): ObjectSchema; + requiredKeys(children: string[]): ObjectSchema; + requiredKeys(child:string, ...children: string[]): ObjectSchema; + + /** + * Sets the specified children to optional. + * + * @param children - can be a single string value, an array of string values, or each child provided as an argument. + * + * The behavior is exactly the same as requiredKeys. + */ + optionalKeys(children: string): ObjectSchema; + optionalKeys(children: string[]): ObjectSchema; + optionalKeys(child:string, ...children: string[]): ObjectSchema; } export interface BinarySchema extends AnySchema { + /** + * Sets the string encoding format if a string input is converted to a buffer. + */ + encoding(encoding: string): BinarySchema; + /** * Specifies the minimum length of the buffer. */ @@ -388,17 +604,37 @@ declare module 'joi' { /** * Specifies the oldest date allowed. + * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, + * allowing to explicitly ensure a date is either in the past or in the future. + * It can also be a reference to another field. */ min(date: Date): DateSchema; min(date: number): DateSchema; min(date: string): DateSchema; + min(date: Reference): DateSchema; /** * Specifies the latest date allowed. + * Notes: 'now' can be passed in lieu of date so as to always compare relatively to the current date, + * allowing to explicitly ensure a date is either in the past or in the future. + * It can also be a reference to another field. */ max(date: Date): DateSchema; max(date: number): DateSchema; max(date: string): DateSchema; + max(date: Reference): DateSchema; + + /** + * Specifies the allowed date format: + * @param format - string or array of strings that follow the moment.js format. + */ + format(format: string): DateSchema; + format(format: string[]): DateSchema; + + /** + * Requires the string value to be in valid ISO 8601 date format. + */ + iso(): DateSchema; } export interface FunctionSchema extends AnySchema { @@ -480,8 +716,12 @@ declare module 'joi' { /** * Validates a value against a schema and throws if validation fails. + * + * @param value - the value to validate. + * @param schema - the schema object. + * @param message - optional message string prefix added in front of the error message. may also be an Error object. */ - export function assert(value: any, schema: Schema): void; + export function assert(value: any, schema: Schema, message?: string | Error): void; /** * Generates a reference to the value of the named key. From f02d001d3d809136f507048113369660ee9876ef Mon Sep 17 00:00:00 2001 From: Daisuke Aoki Date: Tue, 21 Jul 2015 18:37:43 +0900 Subject: [PATCH 005/122] Enable data types to specify options * Add call signatures to definition of Sequelize data types * ex. `INTEGER(20)`, `ARRAY(Sequelize.INTEGER)` --- sequelize/sequelize-tests.ts | 213 ++++++++++++++++++++++++++++++++++- sequelize/sequelize.d.ts | 82 ++++++++++++-- 2 files changed, 284 insertions(+), 11 deletions(-) diff --git a/sequelize/sequelize-tests.ts b/sequelize/sequelize-tests.ts index 8766745b8..58d85086d 100644 --- a/sequelize/sequelize-tests.ts +++ b/sequelize/sequelize-tests.ts @@ -213,4 +213,215 @@ promiseMe = myModelInst.increment({}); promiseMe = myModelInst.decrement({}, incrOpts); isBool = myModelInst.equal(myModelInst); isBool = myModelInst.equalsOneOf([myModelInst]); -myModelPojo = myModelInst.toJSON(); \ No newline at end of file +myModelPojo = myModelInst.toJSON(); + + +// data types test +var types:any = Sequelize.STRING; +types = Sequelize.STRING(12); +types = Sequelize.STRING(12, true); +types = Sequelize.STRING.BINARY; +types = Sequelize.STRING(12).BINARY; +types = Sequelize.STRING.BINARY(12); +types = Sequelize.STRING({length:12, binary:true}); +types = Sequelize.STRING({length:12}).BINARY; + +types = Sequelize.CHAR; +types = Sequelize.CHAR(12); +types = Sequelize.CHAR(12, true); +types = Sequelize.CHAR.BINARY; +types = Sequelize.CHAR(12).BINARY; +types = Sequelize.CHAR.BINARY(12); +types = Sequelize.CHAR({length:12, binary:true}); +types = Sequelize.CHAR({length:12}).BINARY; + +types = Sequelize.TEXT; +types = Sequelize.TEXT('tiny'); +types = Sequelize.TEXT({length:'tiny'}); + +types = Sequelize.NUMBER; +var numberOptions = {length:12, zerofill:true, decimals:1, precision:1, scale:1, unsigned:true}; +types = Sequelize.NUMBER(numberOptions); + +types = Sequelize.INTEGER; +types = Sequelize.INTEGER.ZEROFILL; +types = Sequelize.INTEGER.UNSIGNED; +types = Sequelize.INTEGER.ZEROFILL.UNSIGNED; +types = Sequelize.INTEGER.UNSIGNED.ZEROFILL; +types = Sequelize.INTEGER(12); +types = Sequelize.INTEGER(12).ZEROFILL; +types = Sequelize.INTEGER(12).UNSIGNED; +types = Sequelize.INTEGER(12).ZEROFILL.UNSIGNED; +types = Sequelize.INTEGER(12).UNSIGNED.ZEROFILL; +types = Sequelize.INTEGER(numberOptions); +types = Sequelize.INTEGER(numberOptions).ZEROFILL; +types = Sequelize.INTEGER(numberOptions).UNSIGNED; +types = Sequelize.INTEGER(numberOptions).ZEROFILL.UNSIGNED; +types = Sequelize.INTEGER(numberOptions).UNSIGNED.ZEROFILL; + +types = Sequelize.BIGINT; +types = Sequelize.BIGINT.ZEROFILL; +types = Sequelize.BIGINT.UNSIGNED; +types = Sequelize.BIGINT.ZEROFILL.UNSIGNED; +types = Sequelize.BIGINT.UNSIGNED.ZEROFILL; +types = Sequelize.BIGINT(12); +types = Sequelize.BIGINT(12).ZEROFILL; +types = Sequelize.BIGINT(12).UNSIGNED; +types = Sequelize.BIGINT(12).ZEROFILL.UNSIGNED; +types = Sequelize.BIGINT(12).UNSIGNED.ZEROFILL; +types = Sequelize.BIGINT(numberOptions); +types = Sequelize.BIGINT(numberOptions).ZEROFILL; +types = Sequelize.BIGINT(numberOptions).UNSIGNED; +types = Sequelize.BIGINT(numberOptions).ZEROFILL.UNSIGNED; +types = Sequelize.BIGINT(numberOptions).UNSIGNED.ZEROFILL; + +types = Sequelize.FLOAT; +types = Sequelize.FLOAT.ZEROFILL; +types = Sequelize.FLOAT.UNSIGNED; +types = Sequelize.FLOAT.ZEROFILL.UNSIGNED; +types = Sequelize.FLOAT.UNSIGNED.ZEROFILL; +types = Sequelize.FLOAT(12); +types = Sequelize.FLOAT(12).ZEROFILL; +types = Sequelize.FLOAT(12).UNSIGNED; +types = Sequelize.FLOAT(12).ZEROFILL.UNSIGNED; +types = Sequelize.FLOAT(12).UNSIGNED.ZEROFILL; +types = Sequelize.FLOAT(12,12); +types = Sequelize.FLOAT(12,12).ZEROFILL; +types = Sequelize.FLOAT(12,12).UNSIGNED; +types = Sequelize.FLOAT(12,12).ZEROFILL.UNSIGNED; +types = Sequelize.FLOAT(12,12).UNSIGNED.ZEROFILL; +types = Sequelize.FLOAT(numberOptions); +types = Sequelize.FLOAT(numberOptions).ZEROFILL; +types = Sequelize.FLOAT(numberOptions).UNSIGNED; +types = Sequelize.FLOAT(numberOptions).ZEROFILL.UNSIGNED; +types = Sequelize.FLOAT(numberOptions).UNSIGNED.ZEROFILL; + +types = Sequelize.DOUBLE; +types = Sequelize.DOUBLE.ZEROFILL; +types = Sequelize.DOUBLE.UNSIGNED; +types = Sequelize.DOUBLE.ZEROFILL.UNSIGNED; +types = Sequelize.DOUBLE.UNSIGNED.ZEROFILL; +types = Sequelize.DOUBLE(12); +types = Sequelize.DOUBLE(12).ZEROFILL; +types = Sequelize.DOUBLE(12).UNSIGNED; +types = Sequelize.DOUBLE(12).ZEROFILL.UNSIGNED; +types = Sequelize.DOUBLE(12).UNSIGNED.ZEROFILL; +types = Sequelize.DOUBLE(12,12); +types = Sequelize.DOUBLE(12,12).ZEROFILL; +types = Sequelize.DOUBLE(12,12).UNSIGNED; +types = Sequelize.DOUBLE(12,12).ZEROFILL.UNSIGNED; +types = Sequelize.DOUBLE(12,12).UNSIGNED.ZEROFILL; +types = Sequelize.DOUBLE(numberOptions); +types = Sequelize.DOUBLE(numberOptions).ZEROFILL; +types = Sequelize.DOUBLE(numberOptions).UNSIGNED; +types = Sequelize.DOUBLE(numberOptions).ZEROFILL.UNSIGNED; +types = Sequelize.DOUBLE(numberOptions).UNSIGNED.ZEROFILL; + +types = Sequelize.TIME; +types = Sequelize.DATE; +types = Sequelize.DATEONLY; +types = Sequelize.BOOLEAN; +types = Sequelize.NOW; + +types = Sequelize.BLOB; +types = Sequelize.BLOB('tiny'); +types = Sequelize.BLOB({length:'tiny'}); + +types = Sequelize.DECIMAL; +types = Sequelize.DECIMAL.ZEROFILL; +types = Sequelize.DECIMAL.UNSIGNED; +types = Sequelize.DECIMAL.ZEROFILL.UNSIGNED; +types = Sequelize.DECIMAL.UNSIGNED.ZEROFILL; +types = Sequelize.DECIMAL(12,12); +types = Sequelize.DECIMAL(12,12).ZEROFILL; +types = Sequelize.DECIMAL(12,12).UNSIGNED; +types = Sequelize.DECIMAL(12,12).ZEROFILL.UNSIGNED; +types = Sequelize.DECIMAL(12,12).UNSIGNED.ZEROFILL; +types = Sequelize.DECIMAL(numberOptions); +types = Sequelize.DECIMAL(numberOptions).ZEROFILL; +types = Sequelize.DECIMAL(numberOptions).UNSIGNED; +types = Sequelize.DECIMAL(numberOptions).ZEROFILL.UNSIGNED; +types = Sequelize.DECIMAL(numberOptions).UNSIGNED.ZEROFILL; + +types = Sequelize.NUMERIC; +types = Sequelize.NUMERIC.ZEROFILL; +types = Sequelize.NUMERIC.UNSIGNED; +types = Sequelize.NUMERIC.ZEROFILL.UNSIGNED; +types = Sequelize.NUMERIC.UNSIGNED.ZEROFILL; +types = Sequelize.NUMERIC(12,12); +types = Sequelize.NUMERIC(12,12).ZEROFILL; +types = Sequelize.NUMERIC(12,12).UNSIGNED; +types = Sequelize.NUMERIC(12,12).ZEROFILL.UNSIGNED; +types = Sequelize.NUMERIC(12,12).UNSIGNED.ZEROFILL; +types = Sequelize.NUMERIC(numberOptions); +types = Sequelize.NUMERIC(numberOptions).ZEROFILL; +types = Sequelize.NUMERIC(numberOptions).UNSIGNED; +types = Sequelize.NUMERIC(numberOptions).ZEROFILL.UNSIGNED; +types = Sequelize.NUMERIC(numberOptions).UNSIGNED.ZEROFILL; + +types = Sequelize.UUID; +types = Sequelize.UUIDV1; +types = Sequelize.UUIDV4; +types = Sequelize.HSTORE; +types = Sequelize.JSON; +types = Sequelize.JSONB; +types = Sequelize.VIRTUAL; + +types = Sequelize.ARRAY(Sequelize.INTEGER(12)); +types = Sequelize.ARRAY({type: Sequelize.BLOB}); +var obj = {}; +var isbool:boolean = types.is(obj, obj); + +types = Sequelize.NONE; +types = Sequelize.ENUM("one", "two", 'three'); + +types = Sequelize.RANGE(Sequelize.INTEGER(12)); +types = Sequelize.RANGE({subtype: Sequelize.BLOB}); + +types = Sequelize.REAL; +types = Sequelize.REAL.ZEROFILL; +types = Sequelize.REAL.UNSIGNED; +types = Sequelize.REAL.ZEROFILL.UNSIGNED; +types = Sequelize.REAL.UNSIGNED.ZEROFILL; +types = Sequelize.REAL(12,12); +types = Sequelize.REAL(12,12).ZEROFILL; +types = Sequelize.REAL(12,12).UNSIGNED; +types = Sequelize.REAL(12,12).ZEROFILL.UNSIGNED; +types = Sequelize.REAL(12,12).UNSIGNED.ZEROFILL; +types = Sequelize.REAL(numberOptions); +types = Sequelize.REAL(numberOptions).ZEROFILL; +types = Sequelize.REAL(numberOptions).UNSIGNED; +types = Sequelize.REAL(numberOptions).ZEROFILL.UNSIGNED; +types = Sequelize.REAL(numberOptions).UNSIGNED.ZEROFILL; + +types = Sequelize.DOUBLE; +types = Sequelize.DOUBLE.ZEROFILL; +types = Sequelize.DOUBLE.UNSIGNED; +types = Sequelize.DOUBLE.ZEROFILL.UNSIGNED; +types = Sequelize.DOUBLE.UNSIGNED.ZEROFILL; +types = Sequelize.DOUBLE(12,12); +types = Sequelize.DOUBLE(12,12).ZEROFILL; +types = Sequelize.DOUBLE(12,12).UNSIGNED; +types = Sequelize.DOUBLE(12,12).ZEROFILL.UNSIGNED; +types = Sequelize.DOUBLE(12,12).UNSIGNED.ZEROFILL; +types = Sequelize.DOUBLE(numberOptions); +types = Sequelize.DOUBLE(numberOptions).ZEROFILL; +types = Sequelize.DOUBLE(numberOptions).UNSIGNED; +types = Sequelize.DOUBLE(numberOptions).ZEROFILL.UNSIGNED; +types = Sequelize.DOUBLE(numberOptions).UNSIGNED.ZEROFILL; + +types = Sequelize["DOUBLE PRECISION"]; +types = Sequelize["DOUBLE PRECISION"].ZEROFILL; +types = Sequelize["DOUBLE PRECISION"].UNSIGNED; +types = Sequelize["DOUBLE PRECISION"].ZEROFILL.UNSIGNED; +types = Sequelize["DOUBLE PRECISION"].UNSIGNED.ZEROFILL; +types = Sequelize["DOUBLE PRECISION"](12,12); +types = Sequelize["DOUBLE PRECISION"](12,12).ZEROFILL; +types = Sequelize["DOUBLE PRECISION"](12,12).UNSIGNED; +types = Sequelize["DOUBLE PRECISION"](12,12).ZEROFILL.UNSIGNED; +types = Sequelize["DOUBLE PRECISION"](12,12).UNSIGNED.ZEROFILL; +types = Sequelize["DOUBLE PRECISION"](numberOptions); +types = Sequelize["DOUBLE PRECISION"](numberOptions).ZEROFILL; +types = Sequelize["DOUBLE PRECISION"](numberOptions).UNSIGNED; +types = Sequelize["DOUBLE PRECISION"](numberOptions).ZEROFILL.UNSIGNED; +types = Sequelize["DOUBLE PRECISION"](numberOptions).UNSIGNED.ZEROFILL; \ No newline at end of file diff --git a/sequelize/sequelize.d.ts b/sequelize/sequelize.d.ts index 1bb6be593..eb5b0296f 100644 --- a/sequelize/sequelize.d.ts +++ b/sequelize/sequelize.d.ts @@ -2725,59 +2725,121 @@ declare module "sequelize" interface DataTypeStringBase { BINARY: DataTypeString; + (length:number, binary?:boolean):DataTypeString; + (options:{length?:number; binary?:boolean;}):DataTypeString; } + + interface DataTypeNumberOptions { + length?:number; + zerofill?:boolean; + decimals?:number; + precision?:number; + scale?:number; + unsigned?:boolean; + } + interface DataTypeNumberBase { - UNSIGNED: boolean; - ZEROFILL: boolean; + UNSIGNED: DataTypeNumberBase; + ZEROFILL: DataTypeNumberBase; + (options: DataTypeNumberOptions): DataTypeNumberBase; } interface DataTypeString extends DataTypeStringBase { } interface DataTypeChar extends DataTypeStringBase { } + + interface DataTypeText { + (length:string): DataTypeText; + (options:{length:string}): DataTypeText; + } + interface DataTypeInteger extends DataTypeNumberBase { + (length:number):DataTypeInteger; + (options:DataTypeNumberOptions):DataTypeInteger; } + interface DataTypeBigInt extends DataTypeNumberBase { + (length:number):DataTypeBigInt; + (options:DataTypeNumberOptions):DataTypeBigInt; } + interface DataTypeFloat extends DataTypeNumberBase { + (length:number, decimals?:number):DataTypeFloat; + (options:DataTypeNumberOptions):DataTypeFloat; } + + interface DataTypeReal extends DataTypeNumberBase { + (length:number, decimals?:number):DataTypeReal; + (options:DataTypeNumberOptions):DataTypeReal; + } + + interface DataTypeDouble extends DataTypeNumberBase { + (length:number, decimals?:number):DataTypeDouble; + (options:DataTypeNumberOptions):DataTypeDouble; + } + interface DataTypeBlob { + (length:string):DataTypeBlob; + (options:{length:string}):DataTypeBlob; } - interface DataTypeDecimal { - PRECISION: number; - SCALE: number; + + interface DataTypeDecimal extends DataTypeNumberBase { + (precision:number, scale:number):DataTypeDecimal; + (options:DataTypeNumberOptions):DataTypeDecimal; + } + + interface DataTypeRange { + (subtype?:any):DataTypeRange; + (options:{subtype:any}):DataTypeRange; } interface DataTypeVirtual { } + interface DataTypeEnum { (...values: Array): DataTypeEnum; } interface DataTypeArray { + (type?:any):DataTypeArray; + (options:{type:any}):DataTypeArray; + is(obj:any, type:any):boolean; } + interface DataTypeHstore { } interface DataTypes { + ABSTRACT: string; STRING: DataTypeString; CHAR: DataTypeChar; - TEXT: string; + TEXT: DataTypeText; + NUMBER: DataTypeNumberBase; INTEGER: DataTypeInteger; BIGINT: DataTypeBigInt; - DATE: string; - BOOLEAN: string; FLOAT: DataTypeFloat; + TIME:string; + DATE: string; + DATEONLY:string; + BOOLEAN: string; NOW: string; BLOB: DataTypeBlob; DECIMAL: DataTypeDecimal; + NUMERIC: DataTypeDecimal; UUID: string; UUIDV1: string; UUIDV4: string; + HSTORE: DataTypeHstore; + JSON: string; + JSONB: string; VIRTUAL: DataTypeVirtual; + ARRAY: DataTypeArray; NONE: DataTypeVirtual; ENUM: DataTypeEnum; - ARRAY: DataTypeArray; - HSTORE: DataTypeHstore; + RANGE:DataTypeRange; + REAL: DataTypeReal; + DOUBLE: DataTypeDouble; + "DOUBLE PRECISION": DataTypeDouble; } } From 4bfe4cfc5821a779e8ad1393765ffd0d269c5120 Mon Sep 17 00:00:00 2001 From: Roman Quiring Date: Fri, 24 Jul 2015 23:07:41 +0200 Subject: [PATCH 006/122] initial commit --- vexflow/vexflow.d.ts | 1325 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1325 insertions(+) create mode 100644 vexflow/vexflow.d.ts diff --git a/vexflow/vexflow.d.ts b/vexflow/vexflow.d.ts new file mode 100644 index 000000000..7316987c9 --- /dev/null +++ b/vexflow/vexflow.d.ts @@ -0,0 +1,1325 @@ +// Type definitions for VexFlow v1.2.27 +// Project: http://vexflow.com +// Definitions by: Roman Quiring +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +//inconsistent namespace: this is a helper funtion from tables.js and should not pollute the global namespace! +declare function sanitizeDuration(duration : string) : string; + +declare module Vex { + + function L(block : string, args : any[]) : void; + function Merge(destination : T, source : Object) : T; + function Min(a : number, b : number) : number; + function Max(a : number, b : number) : number; + function RoundN(x : number, n : number) : number; + function MidLine(a : number, b : number) : number; + function SortAndUnique(arr : T, cmp : Function, eq : Function) : T; + function Contains(a : any[], obj : any) : boolean; + function getCanvasContext(canvas_sel : string) : CanvasRenderingContext2D; + function drawDot(ctx : IRenderContext, x : number, y : number, color? : string) : void; + function BM(s : number, f : Function) : void; + function Inherit(child : T, parent : Object, object : Object) : T; + + class RuntimeError { + constructor(code : string, message : string); + } + + class RERR { + constructor(code : string, message : string); + } + + /** + * Helper interface for handling the different rendering contexts (i.e. CanvasContext, RaphaelContext, SVGContext). Not part of VexFlow! + */ + interface IRenderContext { + clear() : void; + setFont(family : string, size : number, weight? : number) : IRenderContext; + setRawFont(font : string) : IRenderContext; + setFillStyle(style : string) : IRenderContext; + setBackgroundFillStyle(style : string) : IRenderContext; + setStrokeStyle(style : string) : IRenderContext; + setShadowColor(color : string) : IRenderContext; + setShadowBlur(blur : string) : IRenderContext; + setLineWidth(width : number) : IRenderContext; + setLineCap(cap_type : string) : IRenderContext; + setLineDash(dash : string) : IRenderContext; + scale(x : number, y : number) : IRenderContext; + resize(width : number, height : number) : IRenderContext; + fillRect(x : number, y : number, width : number, height : number) : IRenderContext; + clearRect(x : number, y : number, width : number, height : number) : IRenderContext; + beginPath() : IRenderContext; + moveTo(x : number, y : number) : IRenderContext; + lineTo(x : number, y : number) : IRenderContext; + bezierCurveToTo(x1 : number, y1 : number, x2 : number, y2 : number, x : number, y : number) : IRenderContext; + quadraticCurveToTo(x1 : number, y1 : number, x2 : number, y2 : number) : void; + arc(x : number, y : number, radius : number, startAngle : number, endAngle : number, antiClockwise : boolean) : IRenderContext; + glow() : IRenderContext; + fill() : IRenderContext; + stroke() : IRenderContext; + closePath() : IRenderContext; + fillText(text : string, x : number, y : number) : IRenderContext; + save() : IRenderContext; + restore() : IRenderContext; + + /** + * canvas returns TextMetrics, SVG returns SVGRect, Raphael returns {width : number, height : number}. Only width is used throughout VexFlow. + */ + measureText(text : string) : {width : number}; + } + + /** + * Helper interface for handling the Vex.Flow.Font object in Vex.Flow.Glyph. Not part of VexFlow! + */ + interface IFont { + glyphs : {x_min : number, x_max : number, ha : number, o : string[]}[]; + cssFontWeight : string; + ascender : number; + underlinePosition : number; + cssFontStyle : string; + boundingBox : {yMin : number, xMin : number, yMax : number, xMax : number}; + resolution : number; + descender : number; + familyName : string; + lineHeight : number; + underlineThickness : number; + + /** + * This property is missing in vexflow_font.js, but present in gonville_original.js and gonville_all.js. + */ + original_font_information? : {postscript_name : string, version_string : string, vendor_url : string, full_font_name : string, font_family_name : string, copyright : string, description : string, trademark : string, designer : string, designer_url : string, unique_font_identifier : string, license_url : string, license_description : string, manufacturer_name : string, font_sub_family_name : string}; + } + + module Flow { + + var RESOLUTION : number; + + // from tables.js: + var STEM_WIDTH : number; + var STEM_HEIGHT : number; + var STAVE_LINE_THICKNESS : number; + var TIME4_4 : {num_beats : number, beat_value : number, resolution : number}; + var unicode : {[name : string] : string}; //inconsistent API: this should be private and have a wrapper function like the other tables + function clefProperties(clef : string) : {line_shift : number}; + function keyProperties(key : string, clef : string, params : {octave_shift? : number}) : {key : string, octave : number, line : number, int_value : number, accidental : string, code : number, stroke : number, shift_right : number, displaced : boolean}; + function integerToNote(integer : number) : string; + function tabToGlyph(fret : string) : {text : string, code : number, width : number, shift_y : number}; + function textWidth(text : string) : number; + function articulationCodes(artic : string) : {code : string, width : number, shift_right : number, shift_up : number, shift_down : number, between_lines : boolean}; + function accidentalCodes(acc : string) : {code : string, width : number, gracenote_width : number, shift_right : number, shift_down : number}; + function ornamentCodes(acc : string) : {code : string, shift_right : number, shift_up : number, shift_down : number, width : number}; + function keySignature(spec : string) : {type: string, line: number}[]; + function parseNoteDurationString(durationString : string) : {duration : string, dots : number, type : string}; + function parseNoteData(noteData : {duration : string, dots : number, type : string}) : {duration : string, type : string, dots : number, ticks : number}; + function durationToFraction(duration : string) : Fraction; + function durationToNumber(duration : string) : number; + function durationToTicks(duration : string) : number; + function durationToGlyph(duration : string, type : string) : {head_width : number, stem : boolean, stem_offset : number, flag : boolean, stem_up_extension : number, stem_down_extension : number, gracenote_stem_up_extension : number, gracenote_stem_down_extension : number, tabnote_stem_up_extension : number, tabnote_stem_down_extension : number, dot_shiftY : number, line_above : number, line_below : number, code_head? : string, rest? : boolean, position? : string}; + + // from glyph.js: + function renderGlyph(ctx : IRenderContext, x_pos : number, y_pos : number, point : number, val : string, nocache : boolean) : void; + + class Accidental extends Modifier { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes + setNote(note : Note) : Modifier; + + constructor(type : string); + static CATEGORY : string; + static DEBUG : boolean; + static format(accidentals : Accidental[], state : {left_shift : number, right_shift : number, text_line : number}) : void; + setNote(note : StaveNote) : void; + setAsCautionary() : Accidental; + draw() : void; + static applyAccidentals(voices : Voice[], keySignature? : string) : void; + } + + export module Annotation { + enum Justify {LEFT, CENTER, RIGHT, CENTER_STEM} + enum VerticalJustify {TOP, CENTER, BOTTOM, CENTER_STEM} + } + + class Annotation extends Modifier { + constructor(text : string); + static CATEGORY : string; + static DEBUG : boolean; + static format(annotations : Annotation[], state : {left_shift : number, right_shift : number, text_line : number}) : boolean; + setTextLine(line : number) : Annotation; + setFont(family : string, size : number, weight : string) : Annotation; + setVerticalJustification(just : Annotation.VerticalJustify) : Annotation; + getJustification() : Annotation.Justify; + setJustification(justification : Annotation.Justify) : Annotation; + draw() : void; + } + + class Articulation extends Modifier { + constructor(type : string); + static CATEGORY : string; + static DEBUG : boolean; + static format(articulations : Articulation[], state : {left_shift : number, right_shift : number, text_line : number}) : boolean; + draw() : void; + } + + class BarNote extends Note { + static DEBUG : boolean; + getType() : Barline.type; + setType(type : Barline.type) : BarNote; + getBoundingBox() : BoundingBox; + addToModifierContext() : BarNote; + preFormat() : BarNote; + draw() : void; + } + + export module Barline { + enum type {SINGLE, DOUBLE, END, REPEAT_BEGIN, REPEAT_END, REPEAT_BOTH, NONE} + } + + class Barline extends StaveModifier { + constructor(type : Barline.type, x : number); + getCategory() : string; + setX(x : number) : Barline; + draw(stave : Stave, x_shift? : number) : void; + drawVerticalBar(stave : Stave, x : number, double_bar? : boolean) : void; + drawVerticalEndBar(stave : Stave, x : number) : void; + drawRepeatBar(stave : Stave, x : number, begin : boolean) : void; + } + + class Beam { + constructor(notes : StemmableNote[], auto_stem? : boolean); + setContext(context : IRenderContext) : Beam; + getNotes() : StemmableNote[]; + getBeamCount() : number; + breakSecondaryAt(indices : number[]) : Beam; + getSlopeY() : number; + calculateSlope() : void; + applyStemExtensions() : void; + getBeamLines(duration : string) : {start : number, end : number}[]; + drawStems() : void; + drawBeamLines() : void; + preFormat() : Beam; + postFormat() : Beam; + draw() : boolean; + calculateStemDirection(notes : Note) : number; + static getDefaultBeamGroups(time_sig : string) : Fraction[]; + static applyAndGetBeams(voice : Voice, stem_direction : number, groups : Fraction[]) : Beam[]; + static generateBeams(notes : StemmableNote[], config? : {groups? : Fraction[], stem_direction? : number, beam_rests? : boolean, beam_middle_only? : boolean, show_stemlets? : boolean, maintain_stem_directions? : boolean}) : Beam[]; + } + + class Bend { + constructor(text : string, release? : boolean, phrase? : {type : number, text : string, width : number}[]); + static CATEGORY : string; + static UP : number; + static DOWN : number; + static format(bends : Bend[], state : {left_shift : number, right_shift : number, text_line : number}) : boolean; + setXShift(value : number) : void; + setFont(font : string) : Bend; + getText() : string; + updateWidth() : Bend; + draw() : void; + } + + class BoundingBox { + constructor(x : number, y : number, w : number, h : number); + static copy(that : BoundingBox) : BoundingBox; + getX() : number; + getY() : number; + getW() : number; + getH() : number; + setX(x : number) : BoundingBox; + setY(y : number) : BoundingBox; + setW(w : number) : BoundingBox; + setH(h : number) : BoundingBox; + move(x : number, y : number) : void; + clone() : BoundingBox; + mergeWith(boundingBox : BoundingBox, ctx? : IRenderContext) : BoundingBox; + draw(ctx : IRenderContext, x : number, y : number) : void; + } + + class CanvasContext implements IRenderContext { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes or type inconsistencies mentioned below are fixed + setLineDash(dash : string) : CanvasContext; + scale(x : number, y : number) : CanvasContext; + resize(width : number, height : number) : CanvasContext; + fillRect(x : number, y : number, width : number, height : number) : CanvasContext; + clearRect(x : number, y : number, width : number, height : number) : CanvasContext; + beginPath() : CanvasContext; + moveTo(x : number, y : number) : CanvasContext; + lineTo(x : number, y : number) : CanvasContext; + bezierCurveToTo(x1 : number, y1 : number, x2 : number, y2 : number, x : number, y : number) : CanvasContext; + quadraticCurveToTo(x1 : number, y1 : number, x2 : number, y2 : number) : CanvasContext; + arc(x : number, y : number, radius : number, startAngle : number, endAngle : number, antiClockwise : boolean) : CanvasContext; + glow() : CanvasContext; + fill() : CanvasContext; + stroke() : CanvasContext; + closePath() : CanvasContext; + fillText(text : string, x : number, y : number) : CanvasContext; + save() : CanvasContext; + restore() : CanvasContext; + + constructor(context : CanvasRenderingContext2D); + static WIDTH : number; + static HEIGHT : number; + clear() : void; + setFont(family : string, size : number, weight? : number) : CanvasContext; + setRawFont(font : string) : CanvasContext; + setFillStyle(style : string) : CanvasContext; + setBackgroundFillStyle(style : string) : CanvasContext; + setStrokeStyle(style : string) : CanvasContext; + setShadowColor(style : string) : CanvasContext; //inconsistent name: style -> color + setShadowBlur(blur : string) : CanvasContext; + setLineWidth(width : number) : CanvasContext; + setLineCap(cap_type : string) : CanvasContext; + + //inconsistent type: void -> CanvasContext + setLineDash(dash : string) : void; + scale(x : number, y : number) : void; + resize(width : number, height : number) : void; + fillRect(x : number, y : number, width : number, height : number) : void; + clearRect(x : number, y : number, width : number, height : number) : void; + beginPath() : void; + moveTo(x : number, y : number) : void; + lineTo(x : number, y : number) : void; + bezierCurveToTo(x1 : number, y1 : number, x2 : number, y2 : number, x : number, y : number) : void; + quadraticCurveToTo(x1 : number, y1 : number, x : number, y : number) : void; //inconsistent name: x -> x2, y -> y2 + arc(x : number, y : number, radius : number, startAngle : number, endAngle : number, antiClockwise : boolean) : void; + glow() : void; + fill() : void; + stroke() : void; + closePath() : void; + measureText(text : string) : TextMetrics; + fillText(text : string, x : number, y : number) : void; + save() : void; + restore() : void; + } + + class Clef extends StaveModifier { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes + addModifier() : void; + addEndModifier() : void; + + constructor(clef : string, size? : string, annotation? : string); + static DEBUG : boolean; + addModifier(stave : Stave) : void; + addEndModifier(stave : Stave) : void; + } + + class ClefNote extends Note { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes + setStave(stave : Stave) : Note; + + constructor(clef : string, size? : string, annotation? : string); + setClef(clef : string, size? : string, annotation? : string) : ClefNote; + getClef() : string; + setStave(stave : Stave) : void; + getBoundingBox() : BoundingBox; + addToModifierContext() : ClefNote; + getCategory() : string; + preFormat() : ClefNote; + draw() : void; + } + + class Crescendo extends Note { + constructor(note_struct : {duration : number, line? : number}); + static DEBUG : boolean; + setLine(line : number) : Crescendo; + setHeight(height : number) : Crescendo; + setDecrescendo(decresc : boolean) : Crescendo; + preFormat() : Crescendo; + draw() : void; + } + + export module Curve { + enum Position {NEAR_HEAD, NEAR_TOP} + } + + class Curve { + constructor(from : Note, to : Note, options? : {spacing? : number, thickness? : number, x_shift? : number, y_shift : number, position : Curve.Position, invert : boolean, cps? : {x : number, y : number}[]}); + static DEBUG : boolean; + setContext(context : IRenderContext) : Curve; + setNotes(from : Note, to : Note) : Curve; + isPartial() : boolean; + renderCurve(params : {first_x : number, first_y : number, last_x : number, last_y : number, direction : number}) : void; + draw() : boolean; + } + + class Dot extends Modifier { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes or type inconsistencies mentioned below are fixed + setNote(note : Note) : Dot; + + static CATEGORY : string; + static format(dots : number, state : {left_shift : number, right_shift : number, text_line : number}) : void; + setNote(note : Note) : void; //inconsistent type: void -> Dot + setDotShiftY(y : number) : Dot; + draw() : void; + } + + var Font : { + glyphs : {x_min : number, x_max : number, ha : number, o : string[]}[]; + cssFontWeight : string; + ascender : number; + underlinePosition : number; + cssFontStyle : string; + boundingBox : {yMin : number, xMin : number, yMax : number, xMax : number}; + resolution : number; + descender : number; + familyName : string; + lineHeight : number; + underlineThickness : number; + + //inconsistent member : this is missing in vexflow_font.js, but present in gonville_original.js and gonville_all.js + original_font_information : {postscript_name : string, version_string : string, vendor_url : string, full_font_name : string, font_family_name : string, copyright : string, description : string, trademark : string, designer : string, designer_url : string, unique_font_identifier : string, license_url : string, license_description : string, manufacturer_name : string, font_sub_family_name : string}; + } + + class Formatter { + static DEBUG : boolean; + static FormatAndDraw(ctx : IRenderContext, stave : Stave, notes : StaveNote[], params : {auto_beam : boolean, align_rests : boolean}) : BoundingBox; + static FormatAndDraw(ctx : IRenderContext, stave : Stave, notes : StaveNote[], params : boolean) : BoundingBox; + static FormatAndDrawTab(ctx : IRenderContext, tabstave : TabStave, stave : Stave, tabnotes : TabNote[], notes : StaveNote[], autobeam : boolean, params : {auto_beam : boolean, align_rests : boolean}) : void; + static FormatAndDrawTab(ctx : IRenderContext, tabstave : TabStave, stave : Stave, tabnotes : TabNote[], notes : StaveNote[], autobeam : boolean, params : boolean) : void; + static AlignRestsToNotes(notes : Note[], align_all_notes? : boolean, align_tuplets? : boolean) : Formatter; + alignRests(voices : Voice[], align_all_notes : boolean) : void; + preCalculateMinTotalWidth(voices : Voice[]) : number; + getMinTotalWidth() : number; + createModifierContexts(voices : Voice[]) : ModifierContext[]; + createTickContexts(voices : Voice[]) : TickContext[]; + preFormat(justifyWidth? : number, rendering_context? : IRenderContext, voices? : Voice[], stave? : Stave) : void; + postFormat() : Formatter; + joinVoices(voices : Voice[]) : Formatter; + format(voices : Voice[], justifyWidth : number, options? : {align_rests? : boolean, context : IRenderContext}) : Formatter; + formatToStave(voices : Voice[], stave : Stave, options? : {align_rests? : boolean, context : IRenderContext}) : Formatter; + } + + class Fraction { + constructor(numerator : number, denominator : number); + static GCD(a : number, b : number) : number; + static LCM(a : number, b : number) : number; + static LCMM(a : number, b : number) : number; + set(numerator : number, denominator : number) : Fraction; + value() : number; + simplify() : Fraction; + add(param1 : Fraction, param2 : Fraction) : Fraction; + add(param1 : number, param2 : number) : Fraction; + subtract(param1 : Fraction, param2 : Fraction) : Fraction; + subtract(param1 : number, param2 : number) : Fraction; + multiply(param1 : Fraction, param2 : Fraction) : Fraction; + multiply(param1 : number, param2 : number) : Fraction; + divide(param1 : Fraction, param2 : Fraction) : Fraction; + divide(param1 : number, param2 : number) : Fraction; + equals(compare : Fraction) : boolean; + greaterThan(compare : Fraction) : boolean; + greaterThanEquals(compare : Fraction) : boolean; + lessThan(compare : Fraction) : boolean; + lessThanEquals(compare : Fraction) : boolean; + clone() : Fraction; + copy(copy : Fraction) : Fraction; + quotient() : number; + fraction() : number; + abs() : Fraction; + toString() : string; + toSimplifiedString() : string; + toMixedString() : string; + parse(str : string) : Fraction; + } + + class FretHandFinger extends Modifier { + constructor(number : number); + static CATEGORY : string; + static format(nums : FretHandFinger[], state : {left_shift : number, right_shift : number, text_line : number}) : void; + getNote() : Note; + setNote(note : Note) : FretHandFinger; + getIndex() : number; + setIndex(index : number) : FretHandFinger; + getPosition() : Modifier.Position; + setPosition(position : Modifier.Position) : FretHandFinger; + setFretHandFinger(number : number) : FretHandFinger; + setOffsetX(x : number) : FretHandFinger; + setOffsetY(y : number) : FretHandFinger; + draw() : void; + } + + class GhostNote extends StemmableNote { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes or type inconsistencies mentioned below are fixed + setStave(stave : Stave) : Note; + + constructor(duration : string); + constructor(note_struct : {type? : string, dots? : number, duration : string}); //inconsistent name : init struct is called 'duration', should be 'params'/'options' (may be string or Object) + isRest() : boolean; + setStave(stave : Stave) : void; //inconsistent type: void -> GhostNote + addToModifierContext() : GhostNote; + preFormat() : GhostNote; + draw() : void; + } + + class Glyph { + constructor(code : string, point : number, options? : {cache? : boolean, font? : IFont}); + setOptions(options? : {cache? : boolean, font? : IFont}) : void; + setStave(stave : Stave) : Glyph; + setXShift(x_shift : number) : Glyph; + setYShift(y_shift : number) : Glyph; + setContext(context : IRenderContext) : Glyph; + getContext() : IRenderContext; + reset() : void; + setWidth(width : number) : Glyph; + getMetrics() : {x_min : number, x_max : number, width : number, height : number}; + render(ctx : IRenderContext, x_pos : number, y_pos : number) : void; + renderToStave(x : number) : void; + static loadMetrics(font : IFont, code : string, cache : boolean) : {x_min : number, x_max : number, ha : number, outline : number[]}; + static renderOutline(ctx : IRenderContext, outline : number[], scale : number, x_pos : number, y_pos : number) : void; + } + + class GraceNote extends StaveNote { + getStemExtension() : number; + getCategory() : string; + draw() : void; + } + + class GraceNoteGroup { + constructor(grace_notes : GraceNote[], show_slur? : boolean); //inconsistent name: 'show_slur' is called 'config', suggesting object (is boolean) + static CATEGORY : string; + static DEBUG : boolean; + static format(gracenote_groups : GraceNoteGroup[], state : {left_shift : number, right_shift : number, text_line : number}) : boolean; + preFormat() : void; + beamNotes() : GraceNoteGroup; + setNote(note : Note) : void; + setWidth(width : number) : void; + getWidth() : number; + setXShift(x_shift : number) : void; + draw() : void; + } + + class KeyManager { + constructor(key : string); + setKey(key : string) : KeyManager; + getKey() : string; + reset() : KeyManager; + getAccidental(key : string) : {note : string, accidental : string}; + selectNote(note : string) : {note : string, accidental : string, change : boolean}; + } + + class KeySignature extends StaveModifier { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes + addModifier() : void; + + constructor(key_spec : string); + addAccToStave(stave : Stave, acc : {type : string, line : number}, next? : {type : string, line : number}) : void; + cancelKey(spec : string) : KeySignature; + addModifier(stave : Stave) : KeySignature; + addToStave(stave : Stave, firstGlyph? : boolean) : KeySignature; + convertAccLines(clef : string, type : string) : void; + } + + export module Modifier { + enum Position {LEFT, RIGHT, ABOVE, BELOW} + } + + class Modifier { + static CATEGORY : string; + static DEBUG : boolean; + getCategory() : string; + getWidth() : number; + setWidth(width : number) : Modifier; + getNote() : Note; + setNote(note : Note) : Modifier; + getIndex() : number; + setIndex(index : number) : Modifier; + getContext() : IRenderContext; + setContext(context : IRenderContext) : Modifier; + getModifierContext() : ModifierContext; + setModifierContext(c : ModifierContext) : Modifier; + getPosition() : Modifier.Position; + setPosition(position : Modifier.Position) : Modifier; + setTextLine(line : number) : Modifier; + setYShift(y : number) : Modifier; + setXShift(x : number) : void; //inconsistent type: void -> Modifier + draw() : void; + } + + class ModifierContext { + static DEBUG : boolean; + addModifier(modifier : Modifier) : ModifierContext; + getModifiers(type : string) : Modifier[]; + getWidth() : number; + getExtraLeftPx() : number; + getExtraRightPx() : number; + getState() : {left_shift : number, right_shift : number, text_line : number}; + getMetrics() : {width : number, spacing : number, extra_left_px : number, extra_right_px : number}; + preFormat() : void; + postFormat() : void; + } + + class Music { + static NUM_TONES : number; + isValidNoteValue(note : number) : boolean; + isValidIntervalValue(interval : number) : boolean; + getNoteParts(noteString : string) : {root : string, accidental : string}; + getKeyParts(noteString : string) : {root : string, accidental : string, type : string}; + getNoteValue(noteString : string) : number; + getIntervalValue(intervalString : string) : number; + getCanonicalNoteName(noteValue : number) : string; + getCanonicalIntervalName(intervalValue : number) : string; + getRelativeNoteValue(noteValue : number, intervalValue : number, direction? : number) : number; + getRelativeNoteName(root : string, noteValue : number) : string; + getScaleTones(key : string, intervals : number[]) : number; + getIntervalBetween(note1 : number, note2 : number, direction? : number) : number; + createScaleMap(keySignature : string) : {[rootName : string] : string}; + } + + class Note extends Tickable { + constructor(note_struct : {type? : string, dots? : number, duration : string}); + static CATEGORY : string; + getPlayNote() : any; + setPlayNote(note : any) : Note; + isRest() : boolean; + addStroke(index : number, stroke : Stroke) : Note; + getStave() : Stave; + setStave(stave : Stave) : Note; + getCategory() : string; + setContext(context : IRenderContext) : Note; + getExtraLeftPx() : number; + getExtraRightPx() : number; + setExtraLeftPx(x : number) : Note; + setExtraRightPx(x : number) : Note; + shouldIgnoreTicks() : boolean; + getLineNumber() : number; + getLineForRest() : number; + getGlyph() : Glyph; + setYs(ys : number[]) : Note; + getYs() : number[]; + getYForTopText(text_line : number) : number; + getBoundingBox() : BoundingBox; + getVoice() : Voice; + setVoice(voice : Voice) : Note; + getTickContext() : TickContext; + setTickContext(tc : TickContext) : Note; + getDuration() : string; + isDotted() : boolean; + hasStem() : boolean; + getDots() : number; + getNoteType() : string; + setBeam() : Note; + setModifierContext(mc : ModifierContext) : Note; + addModifier(modifier : Modifier, index? : number) : Note; + getModifierStartXY() : {x : number, y : number}; + getMetrics() : {width : number, noteWidth : number, left_shift : number, modLeftPx : number, modRightPx : number, extraLeftPx : number, extraRightPx : number}; + setWidth(width : number) : void; + getWidth() : number; + setXShift(x : number) : Note; + getX() : number; + getAbsoluteX() : number; + setPreFormatted(value : boolean) : void; + } + + class NoteHead extends Note { + constructor(head_options : {x? : number, y? : number, note_type? : string, duration : string, displaced? : boolean, stem_direction? : number, x_shift : number, style : string, slashed : boolean, glyph_font_scale? : number}); + static DEBUG : boolean; + getCategory() : string; + setContext(context : IRenderContext) : NoteHead; + getWidth() : number; + isDisplaced() : boolean; + getStyle() : {shadowColor? : string, shadowBlur? : string, fillStyle? : string, strokeStyle? : string}; + setStyle(style : {shadowColor? : string, shadowBlur? : string, fillStyle? : string, strokeStyle? : string}) : NoteHead; + getGlyph() : Glyph; + setX(x : number) : NoteHead; + getY() : number; + setY(y : number) : NoteHead; + getLine() : number; + setLine(line : number) : NoteHead; + getAbsoluteX() : number; + getBoundingBox() : BoundingBox; + applyStyle(context : IRenderContext) : NoteHead; + setStave(stave : Stave) : NoteHead; + preFormat() : NoteHead; + draw() : void; + } + + class Ornament extends Modifier { + constructor(type : string); + static CATEGORY : string; + static DEBUG : boolean; + static format(ornaments : Ornament[], state : {left_shift : number, right_shift : number, text_line : number}) : boolean; + setDelayed(delayed : boolean) : Ornament; + setUpperAccidental(acc : string) : Ornament; + setLowerAccidental(acc : string) : Ornament; + draw() : void; + } + + export module PedalMarking { + enum Styles {TEXT, BRACKET, MIXED} + } + + class PedalMarking { + constructor(notes : Note[]); //inconsistent name: 'notes' is called 'type', suggesting string (is Note[]) + static DEBUG : boolean; + static createSustain(notes : Note[]) : PedalMarking; + static createSostenuto(notes : Note[]) : PedalMarking; + static createUnaCorda(notes : Note[]) : PedalMarking; + setCustomText(depress? : string, release? : string) : PedalMarking; + setStyle(style : PedalMarking.Styles) : PedalMarking; + setLine(line : number) : PedalMarking; + setContext(context : IRenderContext) : PedalMarking; + drawBracketed() : void; + drawText() : void; + draw() : void; + } + + class RaphaelContext implements IRenderContext { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes or type inconsistencies mentioned below are fixed + setLineWidth(width : number) : RaphaelContext; + glow() : RaphaelContext; + + constructor(element : HTMLElement); + setFont(family : string, size : number, weight? : number) : RaphaelContext; + setRawFont(font : string) : RaphaelContext; + setFillStyle(style : string) : RaphaelContext; + setBackgroundFillStyle(style : string) : RaphaelContext; + setStrokeStyle(style : string) : RaphaelContext; + setShadowColor(style : string) : RaphaelContext; //inconsistent name: style -> color + setShadowBlur(blur : string) : RaphaelContext; + setLineWidth(width : number) : void; //inconsistent type: void -> RaphaelContext + setLineDash(dash : string) : RaphaelContext; + setLineCap(cap_type : string) : RaphaelContext; + scale(x : number, y : number) : RaphaelContext; + clear() : void; + resize(width : number, height : number) : RaphaelContext; + setViewBox(viewBox : string) : void; + rect(x : number, y : number, width : number, height : number) : void; + fillRect(x : number, y : number, width : number, height : number) : RaphaelContext; + clearRect(x : number, y : number, width : number, height : number) : RaphaelContext; + beginPath() : RaphaelContext; + moveTo(x : number, y : number) : RaphaelContext; + lineTo(x : number, y : number) : RaphaelContext; + bezierCurveToTo(x1 : number, y1 : number, x2 : number, y2 : number, x : number, y : number) : RaphaelContext; + quadraticCurveToTo(x1 : number, y1 : number, x : number, y : number) : RaphaelContext; //inconsistent name: x, y -> x2, y2 + arc(x : number, y : number, radius : number, startAngle : number, endAngle : number, antiClockwise : boolean) : RaphaelContext; + glow() : {width : number, fill : boolean, opacity : number, offsetx : number, offsety : number, color : string}; //inconsistent type : Object -> RaphaelContext + fill() : RaphaelContext; + stroke() : RaphaelContext; + closePath() : RaphaelContext; + measureText(text : string) : {width : number, height : number}; + fillText(text : string, x : number, y : number) : RaphaelContext; + save() : RaphaelContext; + restore() : RaphaelContext; + } + + export module Renderer { + enum Backends {CANVAS, RAPHAEL, SVG, VML} + enum LineEndType {NONE, UP, DOWN} + } + + class Renderer { + constructor(sel : HTMLElement, backend : Renderer.Backends) + static USE_CANVAS_PROXY : boolean; + static buildContext(sel : HTMLElement, backend : Renderer.Backends, width? : number, height? : number, background? : string) : IRenderContext; + static getCanvasContext(sel : HTMLElement, backend : Renderer.Backends, width? : number, height? : number, background? : string) : CanvasContext; + static getRaphaelContext(sel : HTMLElement, backend : Renderer.Backends, width? : number, height? : number, background? : string) : RaphaelContext; + static getSVGContext(sel : HTMLElement, backend : Renderer.Backends, width? : number, height? : number, background? : string) : SVGContext; + static bolsterCanvasContext(ctx : CanvasRenderingContext2D) : CanvasContext; + static drawDashedLine(context : IRenderContext, fromX : number, fromY : number, toX : number, toY : number, dashPattern : number[]) : void; + resize(width : number, height : number) : Renderer; + getContext() : IRenderContext; + } + + export module Repetition { + enum type {NONE, CODA_LEFT, CODA_RIGHT, SEGNO_LEFT, SEGNO_RIGHT, DC, DC_AL_CODA, DC_AL_FINE, DS, DS_AL_CODA, DS_AL_FINE, FINE} + } + + class Repetition extends StaveModifier { + constructor(type : Repetition.type, x : number, y_shift : number); + getCategory() : string; + setShiftX(x : number) : Repetition; + setShiftY(y : number) : Repetition; + draw(stave : Stave, x : number) : Repetition; + drawCodaFixed(stave : Stave, x : number) : Repetition; + drawSignoFixed(stave : Stave, x : number) : Repetition; //inconsistent name: drawSignoFixed -> drawSegnoFixed + drawSymbolText(stave : Stave, x : number, text : string, draw_coda : boolean) : Repetition; + } + + class Stave { + constructor(x : number, y : number, width : number, options? : {vertical_bar_width? : number, glyph_spacing_px? : number, num_lines? : number, fill_style? : string, spacing_between_lines_px? : number, space_above_staff_ln? : number, space_below_staff_ln? : number, top_text_position? : number}); + static THICKNESS : number; + resetLines() : void; + setNoteStartX(x : number) : Stave; + getNoteStartX() : number; + getNoteEndX() : number; + getTieStartX() : number; + getTieEndX() : number; + setContext(context : IRenderContext) : Stave; + getContext() : IRenderContext; + getX() : number; + getNumLines() : number; + setY(y : number) : Stave; + setWidth(width : number) : Stave; + getWidth() : number; + setMeasure(measure : number) : Stave; + setBegBarType(type : Barline.type) : Stave; + setEndBarType(type : Barline.type) : Stave; + getModifierXShift(index : number) : number; + setRepetitionTypeLeft(type : Repetition.type, y : number) : Stave; + setRepetitionTypeRight(type : Repetition.type, y : number) : Stave; + setVoltaType(type : Volta.type, number_t : number, y : number) : Stave; + setSection(section : string, y : number) : Stave; + setTempo(tempo : {name? : string, duration : string, dots : number, bpm : number}, y : number) : Stave; + setText(text : string, position : Modifier.Position, options? : {shift_x? : number, shift_y? : number, justification? : TextNote.Justification}) : Stave; + getHeight() : number; + getSpacingBetweenLines() : number; + getBoundingBix() : BoundingBox; + getBottomY() : number; + getBottomLineY() : number; + getYForLine(line : number) : number; + getYForTopText(line? : number) : number; + getYForBottomText(line? : number) : number; + getYForNote(line? : number) : number; + getYForGlyphs() : number; + addGlyph(glypg : Glyph) : Stave; + addEndGlyph(glypg : Glyph) : Stave; + addModifier(modifier : StaveModifier) : Stave; + addEndModifier(modifier : StaveModifier) : Stave; + addKeySignature(keySpec : string) : Stave; + addClef(clef : string, size? : string, annotation? : string) : Stave; + addEndClef(clef : string, size? : string, annotation? : string) : Stave; + addTimeSignature(timeSpec : string, customPadding? : number) : void; //inconsistent type: void -> Stave + addTrebleGlyph() : Stave; + draw() : void; + drawVertical(x : number, isDouble : boolean) : void; + drawVerticalFixed(x : number, isDouble : boolean) : void; + drawVerticalBar(x : number) : void; + drawVerticalBarFixed(x : number) : void; + getConfigForLines() : {visible : boolean}[]; + setConfigForLine(line_number : number, line_config : {visible : boolean}) : Stave; + setConfigForLines(lines_configuration : {visible : boolean}[]) : Stave; + } + + export module StaveConnector { + enum type {SINGLE_RIGHT, SINGLE_LEFT, SINGLE, DOUBLE, BRACE, BRACKET, BOLD_DOUBLE_LEFT, BOLD_DOUBLE_RIGHT, THIN_DOUBLE} + } + + class StaveConnector { + constructor(top_stave : Stave, bottom_stave : Stave); + setContext(ctx : IRenderContext) : StaveConnector; + setType(type : StaveConnector.type) : StaveConnector; + setText(text : string, text_options? : {shift_x? : number, shift_y? : number}) : StaveConnector; + setFont(font : {family? : string, size? : number, weight? : string}) : StaveConnector; + setXShift(x_shift : number) : StaveConnector; + draw() : void; + drawBoldDoubleLine(ctx : Object, type : StaveConnector.type, topX : number, topY : number, botY : number) : void; + } + + export module StaveHairpin { + enum type {CRESC, DECRESC} + } + + class StaveHairpin { + constructor(notes : {first_note : Note, last_note : Note}, type : StaveHairpin.type); + static FormatByTicksAndDraw(ctx : IRenderContext, formatter : Formatter, notes : Note[], type : StaveHairpin.type, position : Modifier.Position, options? : {height? : number, y_shift : number, left_shift_px : number, right_shift_px : number}) : void; + setContext(context : IRenderContext) : StaveHairpin; + setPosition(position : Modifier.Position) : StaveHairpin; + setRenderOptions(options : {height? : number, y_shift : number, left_shift_px : number, right_shift_px : number}) : StaveHairpin; + setNotes(notes : {first_note : Note, last_note : Note}) : StaveHairpin; + draw() : boolean; + } + + export module StaveLine { + enum TextVerticalPosition {TOP, BOTTOM} + enum TextJustification {LEFT, CENTER, RIGHT} + } + + class StaveLine { + constructor(notes : {first_note: Note, last_note: Note, first_indices : number[], last_indices : number[]}); + setContext(context : Object) : StaveLine; + setFont(font : {family : string, size : number, weight : string}) : StaveLine; + setText(text : string) : StaveLine; + setNotes(notes : {first_note: Note, last_note: Note, first_indices? : number[], last_indices? : number[]}) : StaveLine; + applyLineStyle() : void; + applyFontStyle() : void; + draw() : StaveLine; + + //inconsistent API: this should be set via an options object in the constructor + render_options : {padding_left : number, padding_right : number, line_width : number, line_dash : number[], rounded_end : boolean, color : string, draw_start_arrow : boolean, draw_end_arrow : boolean, arrowhead_length : number, arrowhead_angle : number, text_position_vertical : StaveLine.TextVerticalPosition, text_justification : StaveLine.TextJustification}; + } + + class StaveModifier { + getCategory() : string; + makeSpacer(padding : number) : {getContext: Function, setStave: Function, renderToStave: Function, getMetrics: Function}; + placeGlyphOnLine(glyph : Glyph, stave : Stave, line : number) : void; + setPadding(padding : number) : void; + addToStave(stave : Stave, firstGlyph : boolean) : StaveModifier; + addToStaveEnd(stave : Stave, firstGlyph : boolean) : StaveModifier; + addModifier() : void; + addEndModifier() : void; + } + + class StaveNote extends StemmableNote { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes and/or inconsistencies mentioned below are fixed + buildStem() : StemmableNote; + setStave(stave : Stave) : Note; + addModifier(modifier : Modifier, index? : number) : Note; + getModifierStartXY() : {x : number, y : number}; + getDots() : number; + + constructor(note_struct : {type : string, dots? : number, duration : string, clef : string, keys : string[], octave_shift? : number}); + static CATEGORY : string; + static DEBUG : boolean; + static STEM_UP : number; + static STEM_DOWN : number; + static format(notes : StaveNote[] , state : {left_shift : number, right_shift : number, text_line : number}) : boolean; + static formatByY(notes : StaveNote[] , state : {left_shift : number, right_shift : number, text_line : number}) : void; + static postFormat(notes : StaveNote[]) : boolean; + buildStem() : void; //inconsistent type: void -> StaveNote + buildNoteHeads() : void; + autoStem() : void; + calculateKeyProps() : void; + getBoundingBox() : BoundingBox; + getLineNumber() : number; + isRest() : boolean; + isChord() : boolean; + hasStem() : boolean; + getYForTopText(text_line : number) : number; + getYForBottomText(text_line : number) : number; + setStave(stave : Stave) : StaveNote; + getKeys() : string[]; + getKeyProps() : {key : string, octave : number, line : number, int_value : number, accidental : string, code : number, stroke : number, shift_right : number, displaced : boolean}[]; + isDisplaced() : boolean; + setNoteDisplaced(displaced : boolean) : StaveNote; + getTieRightX() : number; + getTieLeftX() : number; + getLineForRest() : number; + getModifierStartXY(position : Modifier.Position, index : number) : {x : number, y : number}; + setStyle(style : {shadowColor? : string, shadowBlur? : string, fillStyle? : string, strokeStyle? : string}) : void; // inconsistent type: void -> StaveNote + setKeyStyle(index : number, style : string) : StaveNote; + setKeyLine(index : number, line : number) : StaveNote; + getKeyLine(index : number) : number; + addToModifierContext(mContext : ModifierContext) : StaveNote; + addModifier(index : number, modifier : Modifier) : StaveNote; + addAccidental(index : number, accidental : Accidental) : StaveNote; + addArticulation(index : number, articulation : Articulation) : StaveNote; + addAnnotation(index : number, annotation : Annotation) : StaveNote; + addDot(index : number) : StaveNote; + addDotToAll() : StaveNote; + getAccidentals() : Accidental[]; + getDots() : Dot[]; + getVoiceShiftWidth() : number; + calcExtraPx() : void; + preFormat() : void; + getNoteHeadBounds() : {y_top: number, y_bottom: number, highest_line: number, lowest_line: number}; + getNoteHeadBeginX() : number; + getNoteHeadEndX() : number; + drawLedgerLines() : void; + drawModifiers() : void; + drawFlag() : void; + drawNoteHeads() : void; + drawStem(struct : {x_begin? : number, x_end? : number, y_top? : number, y_bottom? : number, y_extend? : number, stem_extension? : number, stem_direction? : number}) : void; + draw() : void; + } + + class StaveSection extends Modifier { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes + draw() : void; + + constructor(section : string, x : number, shift_y : number); + getCategory() : string; + setStaveSection(section : string) : StaveSection; + setShiftX(x : number) : StaveSection; + setShiftY(y : number) : StaveSection; + draw(stave : Stave, shift_x : number) : StaveSection; + } + + class StaveTempo extends StaveModifier { + constructor(tempo : {name? : string, duration : string, dots : number, bpm : number}, x : number, shift_y : number); + getCategory() : string; + setTempo(tempo : {name : string, duration : string, dots : number, bpm : number}) : StaveTempo; + setShiftX(x : number) : StaveTempo; + setShiftY(y : number) : StaveTempo; + draw(stave : Stave, shift_x : number) : StaveTempo; + } + + class StaveText extends Modifier { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes + draw() : void; + + constructor(text : string, position : Modifier.Position, options? : {shift_x? : number, shift_y? : number, justification? : TextNote.Justification}); + getCategory() : string; + setStaveText(text : string) : StaveText; + setShiftX(x : number) : StaveText; + setShiftY(y : number) : StaveText; + setFont(font : {family? : string, size? : number, weight? : number}) : void; + setText(text : string) : void; + draw(stave : Stave) : StaveText; + } + + class StaveTie { + constructor(notes : {first_note: Note, last_note: Note, first_indices : number[], last_indices : number[]}, text : string); + setContext(context : IRenderContext) : StaveTie; + setFont(font : {family : string, size : number, weight : string}) : StaveTie; + setNotes(notes : {first_note: Note, last_note: Note, first_indices : number[], last_indices : number[]}) : StaveTie; + isPartial() : boolean; + renderTie(params : {first_ys : number[], last_ys : number[], last_x_px : number, first_x_px : number, direction : number}) : void; + renderText(first_x_px : number, last_x_px : number) : void; + draw() : boolean; + } + + class Stem { + constructor(options : {x_begin? : number, x_end? : number, y_top? : number, y_bottom? : number, y_extend? : number, stem_extension? : number, stem_direction? : number}); + static DEBUG : boolean; + static UP : number; + static DOWN : number; + static WIDTH : number; + static HEIGHT : number; + setNoteHeadXBounds(x_begin : number, x_end : number) : Stem; + setDirection(direction : number) : void; + setExtension(extension : number) : void; + setYBounds(y_top : number, y_bottom : number) : void; + getCategory() : string; + setContext(context : IRenderContext) : Stem; + getHeight() : number; + getBoundingBox() : BoundingBox; + getExtents() : {topY : number, baseY : number}; + setStyle(style : {shadowColor? : string, shadowBlur? : string, fillStyle? : string, strokeStyle? : string}) : void; + getStyle() : {shadowColor? : string, shadowBlur? : string, fillStyle? : string, strokeStyle? : string}; + applyStyle(context : IRenderContext) : Stem; + draw() : void; + } + + class StemmableNote extends Note { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes + setBeam() : Note; + + constructor(note_struct : {type? : string, dots? : number, duration : string}); + static DEBUG : boolean; + getStem() : Stem; + setStem(stem : Stem) : StemmableNote; + buildStem() : StemmableNote; + getStemLength() : number; + getBeamCount() : number; + getStemMinumumLength() : number; //inconsistent name: getStemMinumumLength -> getStemMinimumLength + getStemDirection() : number; + setStemDirection(direction : number) : StemmableNote; + getStemX() : number; + getCenterGlyphX() : number; + getStemExtension() : number; + setStemLength() : number; + getStemExtents() : {topY : number, baseY : number}; + setBeam(beam : Beam) : StemmableNote; + getYForTopText(text_line : number) : number; + getYForBottomText(text_line : number) : number; + postFormat() : StemmableNote; + drawStem(stem_struct : {x_begin? : number, x_end? : number, y_top? : number, y_bottom? : number, y_extend? : number, stem_extension? : number, stem_direction? : number}) : void; + } + + class StringNumber extends Modifier { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes + setNote(note : Note) : StringNumber; + + constructor(number : number); + static CATEGORY : string; + static format(nums : StringNumber[], state : {left_shift : number, right_shift : number, text_line : number}) : boolean; + getNote() : Note; + setNote(note : StaveNote) : StringNumber; + getIndex() : number; + setIndex(index : number) : StringNumber; + setLineEndType(leg : Renderer.LineEndType) : StringNumber; + getPosition() : Modifier.Position; + setPosition(position : Modifier.Position) : StringNumber; + setStringNumber(number : number) : StringNumber; + setOffsetX(x : number) : StringNumber; + setOffsetY(y : number) : StringNumber; + setLastNote(note : StaveNote) : StringNumber; + setDashed(dashed : boolean) : StringNumber; + draw() : void; + } + + export module Stroke { + enum Type {BRUSH_DOWN, BRUSH_UP, ROLL_DOWN, ROLL_UP, RASQUEDO_DOWN, RASQUEDO_UP} + } + + class Stroke extends Modifier { + constructor(type : Stroke.Type, options : {all_voices? : boolean}); + static CATEGORY : string; + static format(strokes : Stroke[], state : {left_shift : number, right_shift : number, text_line : number}) : boolean; + getPosition() : Modifier.Position; + addEndNote(note : Note) : Stroke; + draw() : void; + } + + class SVGContext implements IRenderContext { + constructor(element : HTMLElement); + iePolyfill() : boolean; + setFont(family : string, size : number, weight? : number) : SVGContext; + setRawFont(font : string) : SVGContext; + setFillStyle(style : string) : SVGContext; + setBackgroundFillStyle(style : string) : SVGContext; + setStrokeStyle(style : string) : SVGContext; + setShadowColor(style : string) : SVGContext; //inconsistent name: style -> color + setShadowBlur(blur : string) : SVGContext; + setLineWidth(width : number) : SVGContext; + setLineDash(dash : string) : SVGContext; + setLineCap(cap_type : string) : SVGContext; + resize(width : number, height : number) : SVGContext; + scale(x : number, y : number) : SVGContext; + setViewBox(xMin : number, yMin : number, width : number, height : number) : void; + clear() : void; + rect(x : number, y : number, width : number, height : number) : SVGContext; + fillRect(x : number, y : number, width : number, height : number) : SVGContext; + clearRect(x : number, y : number, width : number, height : number) : SVGContext; + beginPath() : SVGContext; + moveTo(x : number, y : number) : SVGContext; + lineTo(x : number, y : number) : SVGContext; + bezierCurveToTo(x1 : number, y1 : number, x2 : number, y2 : number, x : number, y : number) : SVGContext; + quadraticCurveToTo(x1 : number, y1 : number, x : number, y : number) : SVGContext; //inconsistent: x, y -> x2, y2 + arc(x : number, y : number, radius : number, startAngle : number, endAngle : number, antiClockwise : boolean) : SVGContext; + closePath() : SVGContext; + glow() : SVGContext; + fill() : SVGContext; + stroke() : SVGContext; + measureText(text : string) : SVGRect; + ieMeasureTextFix(bbox : SVGRect, text : string) : {x : number, y : number, width : number, height : number}; + fillText(text : string, x : number, y : number) : SVGContext; + save() : SVGContext; + restore() : SVGContext; + } + + class TabNote extends StemmableNote { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes + setStave(stave : Stave) : Note; + getModifierStartXY() : {x : number, y : number}; + + constructor(tab_struct : {positions : {str : number, fret : number}[], type : string, dots? : number, duration : string}, draw_stem : boolean); + getCategory() : string; + setGhost(ghost : boolean) : TabNote; + hasStem() : boolean; + getStemExtension() : number; + addDot() : TabNote; + updateWidth() : void; + setStave(stave : Stave) : TabNote; + getPositions() : {str : number, fret : number}[]; + addToModifierContext(mc : ModifierContext) : TabNote; + getTieRightX() : number; + getTieLeftX() : number; + getModifierStartXY(position : Modifier.Position, index : number) : {x : number, y : number}; + getLineForRest() : number; + preFormat() : void; + getStemX() : number; + getStemY() : number; + getStemExtents() : {topY : number, baseY : number}; + drawFlag() : void; + drawModifiers() : void; + drawStemThrough() : void; + draw() : void; + } + + class TabSlide extends TabTie { + constructor(notes : {first_note: Note, last_note: Note, first_indices : number[], last_indices : number[]}, direction : number); + static SLIDE_UP : number; + static SLIDE_DOWN : number; + static createSlideUp(notes : {first_note: Note, last_note: Note, first_indices : number[], last_indices : number[]}) : TabSlide; + static createSlideDown(notes : {first_note: Note, last_note: Note, first_indices : number[], last_indices : number[]}) : TabSlide; + renderTie(params : {first_ys : number[], last_ys : number[], last_x_px : number, first_x_px : number, direction : number}) : void; + } + + class TabStave extends Stave { + constructor(x : number, y : number, width : number, options : {vertical_bar_width? : number, glyph_spacing_px? : number, num_lines? : number, fill_style? : string, spacing_between_lines_px? : number, space_above_staff_ln? : number, space_below_staff_ln? : number, top_text_position? : number}); + getYForGlyphs() : number; + addTabGlyph() : TabStave; + } + + class TabTie extends StaveTie { + constructor(notes : {first_note: Note, last_note: Note, first_indices : number[], last_indices : number[]}, text : string); + createHammeron(notes : {first_note: Note, last_note: Note, first_indices : number[], last_indices : number[]}) : TabTie; + createPulloff(notes : {first_note: Note, last_note: Note, first_indices : number[], last_indices : number[]}) : TabTie; + draw() : boolean; + } + + export module TextBracket { + enum Position {TOP, BOTTOM} + } + + class TextBracket { + constructor(bracket_data : {start : Note, stop : Note, text? : string, superscript? : string, position : TextBracket.Position}); + static DEBUG : boolean; + applyStyle(context : IRenderContext) : TextBracket; + setDashed(dashed : boolean, dash? : number[]) : TextBracket; + setFont(family : string, size : number, weight? : number) : TextBracket; + setContext(context : IRenderContext) : TextBracket; + setLine(line : number) : TextBracket; + draw() : void; + } + + class TextDynamics extends Note { + constructor(text_struct : {duration : string, text : string, line? : number}); + static DEBUG : boolean; + setLine(line : number) : TextDynamics; + preFormat() : TextDynamics; + draw() : void; + } + + export module TextNote { + enum Justification {LEFT, CENTER, RIGHT} + } + + class TextNote extends Note { + constructor(text_struct : {duration : string, text : string, superscript : boolean, subscript : boolean, glyph : string, font? : {family : string, size : number, weight : string}, line? : number, smooth? : boolean, ignore_ticks? : boolean}); + setJustification(just : TextNote.Justification) : TextNote; + setLine(line : number) : TextNote; + preFormat() : void; + draw() : void; + } + + class Tickable { + setContext(context : IRenderContext) : void; + getBoundingBox() : BoundingBox; + getTicks() : Fraction; + shouldIgnoreTicks() : boolean; + getWidth() : number; + setXShift(x : number) : Tickable; + getCenterXShift() : number; + isCenterAligned() : boolean; + setCenterAlignment(align_center : boolean) : Tickable; + getVoice() : Voice; + setVoice(voice : Voice) : void; + getTuplet() : Tuplet; + setTuplet(tuplet : Tuplet) : Tickable; + addToModifierContext(mc : ModifierContext) : void; + addModifier(mod : Modifier) : Tickable; + setTickContext(tc : TickContext) : void; + preFormat() : void; + postFormat() : Tickable; + getIntrinsicTicks() : Fraction; + setIntrinsicTicks(intrinsicTicks : Fraction) : void; + getTickMultiplier() : Fraction; + applyTickMultiplier(numerator : number, denominator : number) : void; + setDuration(duration : Fraction) : void; + } + + class TickContext { + setContext(context : IRenderContext) : void; + getContext() : IRenderContext; + shouldIgnoreTicks() : boolean; + getWidth() : number; + getX() : number; + setX(x : number) : TickContext; + getPixelsUsed() : number; + setPixelsUsed(pixelsUsed : number) : TickContext; + setPadding(padding : number) : TickContext; + getMaxTicks() : number; + getMinTicks() : number; + getTickables() : Tickable[]; + getCenterAlignedTickables() : Tickable[]; + getMetrics() : {width : number, notePx : number, extraLeftPx : number, extraRightPx : number}; + getCurrentTick() : Fraction; + setCurrentTick(tick : Fraction) : void; + getExtraPx() : {left: number, right: number, extraLeft : number, extraRight : number}; + addTickable(tickable : Tickable) : TickContext; + preFormat() : TickContext; + postFormat() : TickContext; + static getNextContext(tContext : TickContext) : TickContext; + } + + class TimeSignature extends StaveModifier { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes + addModifier() : void; + addEndModifier() : void; + + constructor(timeSpec : string, customPadding? : number); + parseTimeSpec(timeSpec : string) : {num : number, glyph : Glyph}; + makeTimeSignatureGlyph(topNums : number[], botNums : number[]) : Glyph; + getTimeSig() : {num : number, glyph : Glyph}; + addModifier(stave : Stave) : void; + addEndModifier(stave : Stave) : void; + } + + class TimeSigNote extends Note { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes or type inconsistencies mentioned below are fixed + setStave(stave : Stave) : Note; + + constructor(timeSpec : string, customPadding : number); + setStave(stave : Stave) : void; //inconsistent type: void -> TimeSignote + getBoundingBox() : BoundingBox; + addToModifierContext() : TimeSigNote; + preFormat() : TimeSigNote; + draw() : void; + } + + class Tremolo extends Modifier { + constructor(num : number); + getCategory() : string; + draw() : void; + } + + class Tuning { + constructor(tuningString? : string); + noteToInteger(noteString : string) : number; + setTuning(tuningString : string) : void; + getValueForString(stringNum : string) : number; + getValueForFret(fretNum : string, stringNum : string) : number; + getNoteForFret(fretNum : string, stringNum : string) : string; + } + + class Tuplet { + constructor(notes : StaveNote[], options : {num_notes? : number, beats_occupied? : number}); + static LOCATION_TOP : number; + static LOCATION_BOTTOM : number; + attach() : void; + detach() : void; + setContext(context : IRenderContext) : Tuplet; + setBracketed(bracketed : boolean) : Tuplet; + setRatioed(ratioed : boolean) : Tuplet; + setTupletLocation(location : number) : Tuplet; + getNotes() : StaveNote[]; + getNoteCount() : number; + getBeatsOccupied() : number; + setBeatsOccupied(beats : number) : void; + resolveGlyphs() : void; + draw() : void; + } + + class Vibrato extends Modifier { + static CATEGORY : string; + static format(vibratos : Vibrato[], state : {left_shift : number, right_shift : number, text_line : number}, context : ModifierContext) : boolean; + setHarsh(harsh : boolean) : Vibrato; + setVibratoWidth(width : number) : Vibrato; + draw() : void; + } + + export module Voice { + enum Mode {STRICT, SOFT, FULL} + } + + class Voice { + constructor(time : {num_beats : number, beat_value : number, resolution : number}); + getTotalTicks() : Fraction; + getTicksUsed() : Fraction; + getLargestTickWidth() : number; + getSmallestTickCount() : Fraction; + getTickables() : Tickable[]; + getMode() : number; + setMode(mode : number) : Voice; + getResolutionMultiplier() : number; + getActualResolution() : number; + setStave(stave : Stave) : Voice; + getBoundingBox() : BoundingBox; + getVoiceGroup() : VoiceGroup; + setVoiceGroup(g : VoiceGroup) : Voice; + setStrict(strict : boolean) : Voice; + isComplete() : boolean; + addTickable(tickable : Tickable) : Voice; + addTickables(tickables : Tickable[]) : Voice; + preFormat() : Voice; + draw(context : IRenderContext, stave? : Stave) : void; + } + + class VoiceGroup { + getVoices() : Voice[]; + getModifierContexts() : ModifierContext[]; + addVoice(voice : Voice) : void; + } + + export module Volta { + enum type {NONE, BEGIN, MID, END, BEGIN_END} + } + + class Volta extends StaveModifier { + constructor(type : Volta.type, number : number, x : number, y_shift : number); + getCategory() : string; + setShiftY(y : number) : Volta; + draw(stave : Stave, x : number) : Volta; + } + } +} \ No newline at end of file From b1dc72bc6e2e247ee96589d433535f6c9cf4efdf Mon Sep 17 00:00:00 2001 From: Roman Quiring Date: Sat, 25 Jul 2015 14:15:54 +0200 Subject: [PATCH 007/122] corrected definition for Vex.Flow.StaveNote --- vexflow/vexflow.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vexflow/vexflow.d.ts b/vexflow/vexflow.d.ts index 7316987c9..259babf3f 100644 --- a/vexflow/vexflow.d.ts +++ b/vexflow/vexflow.d.ts @@ -855,7 +855,7 @@ declare module Vex { getModifierStartXY() : {x : number, y : number}; getDots() : number; - constructor(note_struct : {type : string, dots? : number, duration : string, clef : string, keys : string[], octave_shift? : number}); + constructor(note_struct : {type? : string, dots? : number, duration : string, clef : string, keys : string[], octave_shift? : number}); static CATEGORY : string; static DEBUG : boolean; static STEM_UP : number; @@ -884,7 +884,7 @@ declare module Vex { getLineForRest() : number; getModifierStartXY(position : Modifier.Position, index : number) : {x : number, y : number}; setStyle(style : {shadowColor? : string, shadowBlur? : string, fillStyle? : string, strokeStyle? : string}) : void; // inconsistent type: void -> StaveNote - setKeyStyle(index : number, style : string) : StaveNote; + setKeyStyle(index : number, style : {shadowColor? : string, shadowBlur? : string, fillStyle? : string, strokeStyle? : string}) : StaveNote; setKeyLine(index : number, line : number) : StaveNote; getKeyLine(index : number) : number; addToModifierContext(mContext : ModifierContext) : StaveNote; From d2e5432873c2b59db55903430bd2cbe45d41875c Mon Sep 17 00:00:00 2001 From: Roman Quiring Date: Sat, 25 Jul 2015 14:28:46 +0200 Subject: [PATCH 008/122] changed constants in Vex.Flow from var to const --- vexflow/vexflow.d.ts | 47 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/vexflow/vexflow.d.ts b/vexflow/vexflow.d.ts index 259babf3f..afdc5f25a 100644 --- a/vexflow/vexflow.d.ts +++ b/vexflow/vexflow.d.ts @@ -92,14 +92,14 @@ declare module Vex { module Flow { - var RESOLUTION : number; + const RESOLUTION : number; // from tables.js: - var STEM_WIDTH : number; - var STEM_HEIGHT : number; - var STAVE_LINE_THICKNESS : number; - var TIME4_4 : {num_beats : number, beat_value : number, resolution : number}; - var unicode : {[name : string] : string}; //inconsistent API: this should be private and have a wrapper function like the other tables + const STEM_WIDTH : number; + const STEM_HEIGHT : number; + const STAVE_LINE_THICKNESS : number; + const TIME4_4 : {num_beats : number, beat_value : number, resolution : number}; + const unicode : {[name : string] : string}; //inconsistent API: this should be private and have a wrapper function like the other tables function clefProperties(clef : string) : {line_shift : number}; function keyProperties(key : string, clef : string, params : {octave_shift? : number}) : {key : string, octave : number, line : number, int_value : number, accidental : string, code : number, stroke : number, shift_right : number, displaced : boolean}; function integerToNote(integer : number) : string; @@ -119,6 +119,24 @@ declare module Vex { // from glyph.js: function renderGlyph(ctx : IRenderContext, x_pos : number, y_pos : number, point : number, val : string, nocache : boolean) : void; + // from vexflow_font.js / gonville_original.js / gonville_all.js + var Font : { + glyphs : {x_min : number, x_max : number, ha : number, o : string[]}[]; + cssFontWeight : string; + ascender : number; + underlinePosition : number; + cssFontStyle : string; + boundingBox : {yMin : number, xMin : number, yMax : number, xMax : number}; + resolution : number; + descender : number; + familyName : string; + lineHeight : number; + underlineThickness : number; + + //inconsistent member : this is missing in vexflow_font.js, but present in gonville_original.js and gonville_all.js + original_font_information : {postscript_name : string, version_string : string, vendor_url : string, full_font_name : string, font_family_name : string, copyright : string, description : string, trademark : string, designer : string, designer_url : string, unique_font_identifier : string, license_url : string, license_description : string, manufacturer_name : string, font_sub_family_name : string}; + } + class Accidental extends Modifier { //TODO remove the following lines once TypeScript allows subclass overrides with type changes setNote(note : Note) : Modifier; @@ -352,23 +370,6 @@ declare module Vex { draw() : void; } - var Font : { - glyphs : {x_min : number, x_max : number, ha : number, o : string[]}[]; - cssFontWeight : string; - ascender : number; - underlinePosition : number; - cssFontStyle : string; - boundingBox : {yMin : number, xMin : number, yMax : number, xMax : number}; - resolution : number; - descender : number; - familyName : string; - lineHeight : number; - underlineThickness : number; - - //inconsistent member : this is missing in vexflow_font.js, but present in gonville_original.js and gonville_all.js - original_font_information : {postscript_name : string, version_string : string, vendor_url : string, full_font_name : string, font_family_name : string, copyright : string, description : string, trademark : string, designer : string, designer_url : string, unique_font_identifier : string, license_url : string, license_description : string, manufacturer_name : string, font_sub_family_name : string}; - } - class Formatter { static DEBUG : boolean; static FormatAndDraw(ctx : IRenderContext, stave : Stave, notes : StaveNote[], params : {auto_beam : boolean, align_rests : boolean}) : BoundingBox; From 8c18f7d318940a780470c703d2bd06efd3977839 Mon Sep 17 00:00:00 2001 From: benishouga Date: Thu, 30 Jul 2015 01:03:33 +0900 Subject: [PATCH 009/122] add svg attribute width and height for react element. --- react/react.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/react/react.d.ts b/react/react.d.ts index 5fbad0d22..c27d523f0 100644 --- a/react/react.d.ts +++ b/react/react.d.ts @@ -540,6 +540,7 @@ declare module __React { fy?: number | string; gradientTransform?: string; gradientUnits?: string; + height?: number | string; markerEnd?: string; markerMid?: string; markerStart?: string; @@ -564,6 +565,7 @@ declare module __React { transform?: string; version?: string; viewBox?: string; + width?: number | string; x1?: number | string; x2?: number | string; x?: number | string; From c12257bc528680aae57dbeb6e56420ec51e9a883 Mon Sep 17 00:00:00 2001 From: Salehen Shovon Rahman Date: Fri, 31 Jul 2015 09:07:55 -0700 Subject: [PATCH 010/122] Added an override for support for jQuery Gridster's `add_widget` ultimately passes on the first parameter to jQuery, and jQuery accepts either a string, a DOM element, or a jQuery object. `add_widget`'s first parameter should reflect what jQuer supports. --- jquery.gridster/gridster.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jquery.gridster/gridster.d.ts b/jquery.gridster/gridster.d.ts index 53f26704e..0459b2f70 100644 --- a/jquery.gridster/gridster.d.ts +++ b/jquery.gridster/gridster.d.ts @@ -184,6 +184,11 @@ interface Gridster { **/ add_widget(html: HTMLElement, size_x?: number, size_y?: number, col?: number, row?: number): JQuery; + /** + * @see add_widget + **/ + add_widget(html: JQuery, size_x?: number, size_y?: number, col?: number, row?: number): JQuery; + /** * Change the size of a widget. * @param $widget The jQuery wrapped HTMLElement that represents the widget is going to be resized. From a586fa0f3688e8db70b3a2ed1970172b6e0e0d5d Mon Sep 17 00:00:00 2001 From: Salehen Shovon Rahman Date: Fri, 31 Jul 2015 11:40:23 -0700 Subject: [PATCH 011/122] Added remove_widget as well. --- jquery.gridster/gridster.d.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jquery.gridster/gridster.d.ts b/jquery.gridster/gridster.d.ts index 0459b2f70..e003f0ebc 100644 --- a/jquery.gridster/gridster.d.ts +++ b/jquery.gridster/gridster.d.ts @@ -213,6 +213,16 @@ interface Gridster { **/ remove_widget(el: HTMLElement, callback: (el: HTMLElement) => void): Gridster; + /** + * @see remove_widget + **/ + remove_widget(el: JQuery, silent?: boolean, callback?: (el: HTMLElement) => void): Gridster; + + /** + * @see remove_widget + **/ + remove_widget(el: JQuery, callback: (el: HTMLElement) => void): Gridster; + /** * Returns a serialized array of the widgets in the grid. * @param $widgets The collection of jQuery wrap ed HTMLElements you want to serialize. If no argument is passed a l widgets will be serialized. From c48ecfcb12a0519094e285ce99dd564ba711809d Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Sun, 2 Aug 2015 23:45:43 +0100 Subject: [PATCH 012/122] Postal.js v1.0.6 --- postal/postal-0.8.9.d.ts | 71 ++++++++++++++++++++++++++++ postal/postal.d.ts | 99 +++++++++++++++++++++++++++------------- 2 files changed, 138 insertions(+), 32 deletions(-) create mode 100644 postal/postal-0.8.9.d.ts diff --git a/postal/postal-0.8.9.d.ts b/postal/postal-0.8.9.d.ts new file mode 100644 index 000000000..0ef40c5d5 --- /dev/null +++ b/postal/postal-0.8.9.d.ts @@ -0,0 +1,71 @@ +// Type definitions for Postal v0.8.9 +// Project: https://github.com/postaljs/postal.js +// Definitions by: Lokesh Peta +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +interface IConfiguration{ + SYSTEM_CHANNEL: string; + DEFAULT_CHANNEL: string; + resolver: any; +} + +interface ISubscriptionDefinition{ + unsubscribe(): void; + subscribe(callback: (data: any, envelope: IEnvelope)=> void): void; + defer():ISubscriptionDefinition; + disposeAfter(maxCalls: number): ISubscriptionDefinition; + distinctUntilChanged(): ISubscriptionDefinition; + once(): ISubscriptionDefinition; + withConstraint(predicate: Function): ISubscriptionDefinition; + withConstraints(predicates: Array): ISubscriptionDefinition; + + withContext(context: any): ISubscriptionDefinition; + withDebounce(milliseconds: number, immediate: boolean ): ISubscriptionDefinition; + withDelay(milliseconds: number): ISubscriptionDefinition; + withThrottle(milliseconds: number): ISubscriptionDefinition; +} + +interface IEnvelope{ + topic: string; + data?: any; + + /*Uses DEFAULT_CHANNEL if no channel is provided*/ + channel?: string; + + timeStamp?: string; +} + + +interface IChannelDefinition { + subscribe(topic: string): ISubscriptionDefinition; + subscribe(topic: string, callback: (data: any, envelope: IEnvelope)=> void): ISubscriptionDefinition; + + publish(topic: string, data?: any): void; + publish(envelope: IEnvelope): void; + + channel: string; +} + +interface IPostalUtils{ + getSubscribersFor(channel: string, tpc: any): any; + reset(): void; +} + +interface IPostal { + channel(name?:string): IChannelDefinition; + + linkChannels(sources: IEnvelope | IEnvelope[], destinations: IEnvelope | IEnvelope[]): ISubscriptionDefinition[]; + + utils: IPostalUtils; + + configuration: IConfiguration; +} + +declare var postal: IPostal; + +declare module "postal" { + var postal: IPostal; + export = postal; +} \ No newline at end of file diff --git a/postal/postal.d.ts b/postal/postal.d.ts index 0ef40c5d5..e1bad48cc 100644 --- a/postal/postal.d.ts +++ b/postal/postal.d.ts @@ -1,33 +1,48 @@ -// Type definitions for Postal v0.8.9 +// Type definitions for Postal v1.0.6 // Project: https://github.com/postaljs/postal.js -// Definitions by: Lokesh Peta +// Definitions by: Lokesh Peta , Paul Jolly // Definitions: https://github.com/borisyankov/DefinitelyTyped -/// - -interface IConfiguration{ +interface IConfiguration { SYSTEM_CHANNEL: string; DEFAULT_CHANNEL: string; - resolver: any; + resolver: IResolver; } -interface ISubscriptionDefinition{ - unsubscribe(): void; - subscribe(callback: (data: any, envelope: IEnvelope)=> void): void; - defer():ISubscriptionDefinition; +interface IResolver { + compare(binding: string, topic: string, headerOptions: {}): boolean; + reset(): void; + purge(options?: {topic?: string, binding?: string, compact?: boolean}): void; +} + +interface ICallback { + (data: any, envelope: IEnvelope): void +} + +interface ISubscriptionDefinition { + channel: string; + topic: string; + callback: ICallback; + + // after and before lack documentation + + constraint(predicateFn: (data: any, envelope: IEnvelope) => boolean): ISubscriptionDefinition; + constraints(predicateFns: ((data: any, envelope: IEnvelope) => boolean)[]): ISubscriptionDefinition; + context(theContext: any): ISubscriptionDefinition; + debounce(interval: number): ISubscriptionDefinition; + defer(): ISubscriptionDefinition; + delay(waitTime: number): ISubscriptionDefinition; disposeAfter(maxCalls: number): ISubscriptionDefinition; + distinct(): ISubscriptionDefinition; distinctUntilChanged(): ISubscriptionDefinition; + logError(): ISubscriptionDefinition; once(): ISubscriptionDefinition; - withConstraint(predicate: Function): ISubscriptionDefinition; - withConstraints(predicates: Array): ISubscriptionDefinition; - - withContext(context: any): ISubscriptionDefinition; - withDebounce(milliseconds: number, immediate: boolean ): ISubscriptionDefinition; - withDelay(milliseconds: number): ISubscriptionDefinition; - withThrottle(milliseconds: number): ISubscriptionDefinition; + throttle(interval: number): ISubscriptionDefinition; + subscribe(callback: ICallback): ISubscriptionDefinition; + unsubscribe(): void; } -interface IEnvelope{ +interface IEnvelope { topic: string; data?: any; @@ -39,26 +54,45 @@ interface IEnvelope{ interface IChannelDefinition { - subscribe(topic: string): ISubscriptionDefinition; - subscribe(topic: string, callback: (data: any, envelope: IEnvelope)=> void): ISubscriptionDefinition; + subscribe(topic: string, callback: ICallback): ISubscriptionDefinition; publish(topic: string, data?: any): void; - publish(envelope: IEnvelope): void; channel: string; } -interface IPostalUtils{ - getSubscribersFor(channel: string, tpc: any): any; - reset(): void; +interface ISourceArg { + topic: string; + channel?: string; +} + +interface IDestinationArg { + topic: string | ((topic: string) => string); + channel?: string; } interface IPostal { - channel(name?:string): IChannelDefinition; - - linkChannels(sources: IEnvelope | IEnvelope[], destinations: IEnvelope | IEnvelope[]): ISubscriptionDefinition[]; - - utils: IPostalUtils; + subscriptions: {}; + wiretaps: ICallback[]; + + addWireTap(callback: ICallback): () => void; + + channel(name?: string): IChannelDefinition; + + getSubscribersFor(): ISubscriptionDefinition[]; + getSubscribersFor(options: {channel?: string, topic?: string, context?: any}): ISubscriptionDefinition[]; + getSubscribersFor(predicateFn: (sub: ISubscriptionDefinition) => boolean): ISubscriptionDefinition[]; + + linkChannels(source: ISourceArg | ISourceArg[], destination: IDestinationArg | IDestinationArg[]): void; + + publish(envelope: IEnvelope): void; + + reset(): void; + + subscribe(options: {channel?: string, topic: string, callback: ICallback}): ISubscriptionDefinition; + unsubscribe(sub: ISubscriptionDefinition): void; + unsubscribeFor(): void; + unsubscribeFor(options: {channel?: string, topic?: string, context?: any}): void; configuration: IConfiguration; } @@ -66,6 +100,7 @@ interface IPostal { declare var postal: IPostal; declare module "postal" { - var postal: IPostal; - export = postal; -} \ No newline at end of file + var postal: IPostal; + export = postal; +} + From 62bb9fd8073c969c84bf27347ff7d51e6199b7cb Mon Sep 17 00:00:00 2001 From: benishouga Date: Tue, 4 Aug 2015 00:01:32 +0900 Subject: [PATCH 013/122] SVGAttributes inherit HTMLAttributes. fixed react-addons.d.ts and react-global.d.ts. --- react/react-addons.d.ts | 5 +---- react/react-global.d.ts | 4 +--- react/react.d.ts | 6 +----- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/react/react-addons.d.ts b/react/react-addons.d.ts index 37cde636d..9479cc722 100644 --- a/react/react-addons.d.ts +++ b/react/react-addons.d.ts @@ -518,9 +518,7 @@ declare module "react/addons" { unselectable?: boolean; } - interface SVGAttributes extends DOMAttributes { - ref?: string | ((component: SVGComponent) => void); - + interface SVGAttributes extends HTMLAttributes { cx?: number | string; cy?: number | string; d?: string; @@ -1048,4 +1046,3 @@ declare module "react/addons" { identifiedTouch(identifier: number): Touch; } } - diff --git a/react/react-global.d.ts b/react/react-global.d.ts index 3c1a69e43..ea032100c 100644 --- a/react/react-global.d.ts +++ b/react/react-global.d.ts @@ -524,9 +524,7 @@ declare module React { preserveAspectRatio?: string; } - interface SVGAttributes extends DOMAttributes { - ref?: string | ((component: SVGComponent) => void); - + interface SVGAttributes extends HTMLAttributes { cx?: number | string; cy?: number | string; d?: string; diff --git a/react/react.d.ts b/react/react.d.ts index c27d523f0..74d6eab4f 100644 --- a/react/react.d.ts +++ b/react/react.d.ts @@ -524,9 +524,7 @@ declare module __React { preserveAspectRatio?: string; } - interface SVGAttributes extends DOMAttributes { - ref?: string | ((component: SVGComponent) => void); - + interface SVGAttributes extends HTMLAttributes { cx?: number | string; cy?: number | string; d?: string; @@ -540,7 +538,6 @@ declare module __React { fy?: number | string; gradientTransform?: string; gradientUnits?: string; - height?: number | string; markerEnd?: string; markerMid?: string; markerStart?: string; @@ -565,7 +562,6 @@ declare module __React { transform?: string; version?: string; viewBox?: string; - width?: number | string; x1?: number | string; x2?: number | string; x?: number | string; From 44c3a8bf0498f80bae5414494b884571389abd0f Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 3 Aug 2015 09:36:59 -0700 Subject: [PATCH 014/122] username -> user for 'ftp' --- ftp/ftp-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ftp/ftp-tests.ts b/ftp/ftp-tests.ts index 2e37e53f9..57b706182 100644 --- a/ftp/ftp-tests.ts +++ b/ftp/ftp-tests.ts @@ -19,8 +19,8 @@ c.connect(); c.connect({ host: "127.0.0.1", - port: 21, - username: "Boo", + port: 21, + user: "Boo", password: "secret" }); From 3f6ae4eabec3e6cddd71d0730127603131de2bbb Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 3 Aug 2015 09:44:45 -0700 Subject: [PATCH 015/122] Added 'base' for 'gulp-watch' tests. --- gulp/gulp.d.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gulp/gulp.d.ts b/gulp/gulp.d.ts index d7a0dba57..13c12a811 100644 --- a/gulp/gulp.d.ts +++ b/gulp/gulp.d.ts @@ -28,6 +28,13 @@ declare module gulp { */ buffer?: boolean; + /** + * The base path of a glob. + * + * Default is everything before a glob starts. + */ + base?: string; + /** * The current working directory in which to search. * Defaults to process.cwd(). From 01ca8013b4e15de9531fe5ba58e5a08e6f7a1529 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 3 Aug 2015 09:49:41 -0700 Subject: [PATCH 016/122] summary -> description for 'microsoft-live-connect' --- microsoft-live-connect/microsoft-live-connect-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/microsoft-live-connect/microsoft-live-connect-tests.ts b/microsoft-live-connect/microsoft-live-connect-tests.ts index e6c1e2ad0..00f2208f0 100644 --- a/microsoft-live-connect/microsoft-live-connect-tests.ts +++ b/microsoft-live-connect/microsoft-live-connect-tests.ts @@ -467,7 +467,7 @@ var calendarCollection: Microsoft.Live.IObjectCollection Date: Tue, 4 Aug 2015 03:12:43 +0200 Subject: [PATCH 017/122] fixed definition of Vex.Flow.Bend --- vexflow/vexflow.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vexflow/vexflow.d.ts b/vexflow/vexflow.d.ts index afdc5f25a..2d3cae966 100644 --- a/vexflow/vexflow.d.ts +++ b/vexflow/vexflow.d.ts @@ -222,7 +222,7 @@ declare module Vex { static generateBeams(notes : StemmableNote[], config? : {groups? : Fraction[], stem_direction? : number, beam_rests? : boolean, beam_middle_only? : boolean, show_stemlets? : boolean, maintain_stem_directions? : boolean}) : Beam[]; } - class Bend { + class Bend extends Modifier { constructor(text : string, release? : boolean, phrase? : {type : number, text : string, width : number}[]); static CATEGORY : string; static UP : number; From d64b972ee9095b53fc8f6078680068b72c00ddae Mon Sep 17 00:00:00 2001 From: Roman Quiring Date: Tue, 4 Aug 2015 03:21:29 +0200 Subject: [PATCH 018/122] fixed definition of Vex.Flow.GraceNote --- vexflow/vexflow.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/vexflow/vexflow.d.ts b/vexflow/vexflow.d.ts index 2d3cae966..ab995f3f1 100644 --- a/vexflow/vexflow.d.ts +++ b/vexflow/vexflow.d.ts @@ -468,6 +468,7 @@ declare module Vex { } class GraceNote extends StaveNote { + constructor(note_struct : {slash? : boolean, type? : string, dots? : number, duration : string, clef? : string, keys : string[], octave_shift? : number, auto_stem? : boolean, stem_direction? : number}); getStemExtension() : number; getCategory() : string; draw() : void; From b2d719a615fe0766ef0f21db4c3e8897114ee593 Mon Sep 17 00:00:00 2001 From: Roman Quiring Date: Tue, 4 Aug 2015 03:36:32 +0200 Subject: [PATCH 019/122] fixed definition of Vex.Flow.GraceNoteGroup --- vexflow/vexflow.d.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/vexflow/vexflow.d.ts b/vexflow/vexflow.d.ts index ab995f3f1..2ffc1e648 100644 --- a/vexflow/vexflow.d.ts +++ b/vexflow/vexflow.d.ts @@ -474,15 +474,19 @@ declare module Vex { draw() : void; } - class GraceNoteGroup { + class GraceNoteGroup extends Modifier { + //TODO remove the following lines once TypeScript allows subclass overrides with type changes or type inconsistencies mentioned below are fixed + setWidth(width : number) : Modifier; + setNote(note : StaveNote) : Modifier; + constructor(grace_notes : GraceNote[], show_slur? : boolean); //inconsistent name: 'show_slur' is called 'config', suggesting object (is boolean) static CATEGORY : string; static DEBUG : boolean; static format(gracenote_groups : GraceNoteGroup[], state : {left_shift : number, right_shift : number, text_line : number}) : boolean; preFormat() : void; beamNotes() : GraceNoteGroup; - setNote(note : Note) : void; - setWidth(width : number) : void; + setNote(note : Note) : void; //inconsistent type: void -> GraceNoteGroup + setWidth(width : number) : void; //inconsistent type: void -> GraceNoteGroup getWidth() : number; setXShift(x_shift : number) : void; draw() : void; From 25288cd386bf1168eb621a00be3665e7ef073cf3 Mon Sep 17 00:00:00 2001 From: Roman Quiring Date: Tue, 4 Aug 2015 04:10:16 +0200 Subject: [PATCH 020/122] changed difinition of Vex.Flow.Music - changed NUM_TONES from static to const - added definitions of helper tables --- vexflow/vexflow.d.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/vexflow/vexflow.d.ts b/vexflow/vexflow.d.ts index 2ffc1e648..75908add3 100644 --- a/vexflow/vexflow.d.ts +++ b/vexflow/vexflow.d.ts @@ -552,8 +552,21 @@ declare module Vex { postFormat() : void; } + module Music { + const NUM_TONES : number; + const roots : string[]; + const root_values : number[]; + const root_indices : {[root : string] : number}; + const canonical_notes : string[]; + const diatonic_intervals : string[]; + const diatonic_accidentals : {[diatonic_interval : string] : {note : number, accidental : number}}; + const intervals : {[interval : string] : number}; + const scales : {[scale : string] : number[]}; + const accidentals : string[]; + const noteValues : {[value : string] : {root_index : number, int_val : number}}; + } + class Music { - static NUM_TONES : number; isValidNoteValue(note : number) : boolean; isValidIntervalValue(interval : number) : boolean; getNoteParts(noteString : string) : {root : string, accidental : string}; From 1c40165c8d3651db1aedf7c186ce065f2fedb96a Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Mon, 3 Aug 2015 22:57:10 -0700 Subject: [PATCH 021/122] Use result of 'template' instead of 'settings' parameter. --- underscore/underscore-tests.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/underscore/underscore-tests.ts b/underscore/underscore-tests.ts index d530a4334..f469d3bea 100644 --- a/underscore/underscore-tests.ts +++ b/underscore/underscore-tests.ts @@ -291,17 +291,18 @@ _.result(object, 'stuff'); var compiled = _.template("hello: <%= name %>"); compiled({ name: 'moe' }); var list2 = "<% _.each(people, function(name) { %>
  • <%= name %>
  • <% }); %>"; -_.template(list2, { people: ['moe', 'curly', 'larry'] }); +_.template(list2)({ people: ['moe', 'curly', 'larry'] }); var template = _.template("<%- value %>"); template({ value: '