diff --git a/archiver/archiver-test.ts b/archiver/archiver-test.ts new file mode 100644 index 000000000..dcd71ca90 --- /dev/null +++ b/archiver/archiver-test.ts @@ -0,0 +1,14 @@ +/// +/// + +import Archiver = require('archiver'); +import FS = require('fs'); + +var archiver = Archiver.create('zip'); + +var writeStream = FS.createWriteStream('./archiver.d.ts'); +var readStream = FS.createReadStream('./archiver.d.ts'); + +archiver.pipe(writeStream); +archiver.append(readStream, {name: 'archiver.d.ts'}); +archiver.finalize(); \ No newline at end of file diff --git a/archiver/archiver.d.ts b/archiver/archiver.d.ts new file mode 100644 index 000000000..570e1424a --- /dev/null +++ b/archiver/archiver.d.ts @@ -0,0 +1,41 @@ +// Type definitions for archiver v0.15.0 +// Project: https://github.com/archiverjs/node-archiver +// Definitions by: Esri +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/* =================== USAGE =================== + + import Archiver = require('archiver); + var archiver = Archiver.create('zip'); + archiver.pipe(FS.createWriteStream('xxx')); + archiver.append(FS.createReadStream('xxx')); + archiver.finalize(); + + =============================================== */ + +/// +declare module "archiver" { + import * as FS from 'fs'; + + interface nameInterface { + name?: string; + } + + interface Archiver { + pipe(writeStream: FS.WriteStream): void; + append(readStream: FS.ReadStream, name: nameInterface): void; + finalize(): void; + } + + interface Options { + + } + + function archiver(format: string, options?: Options): Archiver; + + namespace archiver { + function create(format: string, options?: Options): Archiver; + } + + export = archiver; +} \ No newline at end of file diff --git a/cookie-parser/cookie-parser.d.ts b/cookie-parser/cookie-parser.d.ts index a4897c5e7..dd18bdc23 100644 --- a/cookie-parser/cookie-parser.d.ts +++ b/cookie-parser/cookie-parser.d.ts @@ -1,4 +1,4 @@ -// Type definitions for cookie-parser +// Type definitions for cookie-parser v1.3.4 // Project: https://github.com/expressjs/cookie-parser // Definitions by: Santi Albo // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -8,5 +8,6 @@ declare module "cookie-parser" { import express = require('express'); function e(secret?: string, options?: any): express.RequestHandler; + namespace e{} export = e; } \ No newline at end of file diff --git a/handlebars/handlebars-tests.ts b/handlebars/handlebars-tests.ts index 7ca58ff02..264d70103 100644 --- a/handlebars/handlebars-tests.ts +++ b/handlebars/handlebars-tests.ts @@ -80,3 +80,5 @@ Handlebars.registerHelper('fullName', (person: typeof context.author) => { }); var escapedExpression = Handlebars.Utils.escapeExpression(''); + +Handlebars.helpers !== undefined; diff --git a/handlebars/handlebars.d.ts b/handlebars/handlebars.d.ts index 652685724..9a0aa510a 100644 --- a/handlebars/handlebars.d.ts +++ b/handlebars/handlebars.d.ts @@ -18,6 +18,7 @@ declare module Handlebars { export var Utils: typeof hbs.Utils; export var logger: Logger; export var templates: HandlebarsTemplates; + export var helpers: any; export module AST { export var helpers: hbs.AST.helpers; diff --git a/lovefield/lovefield-tests.ts b/lovefield/lovefield-tests.ts index aa77f5b2c..26e7c8e24 100644 --- a/lovefield/lovefield-tests.ts +++ b/lovefield/lovefield-tests.ts @@ -43,6 +43,8 @@ function main(): void { }).then( function() { return todoDb.select(lf.fn.count()).from(itemSchema).exec(); + }).then(function() { + return todoDb.export(); }); } diff --git a/lovefield/lovefield.d.ts b/lovefield/lovefield.d.ts index b692a414f..02fdc5da0 100644 --- a/lovefield/lovefield.d.ts +++ b/lovefield/lovefield.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Lovefield v2.0.56 +// Type definitions for Lovefield v2.0.62 // Project: http://google.github.io/lovefield/ // Definitions by: freshp86 // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -18,6 +18,16 @@ declare module lf { STRING } + export enum ConstraintAction { + RESTRICT, + CASCADE + } + + export enum ConstraintTiming { + IMMEDIATE, + DEFERRABLE + } + export interface Binder { getIndex(): number } @@ -56,7 +66,9 @@ declare module lf { close(): void createTransaction(type?: TransactionType): Transaction delete(): query.Delete + export(): Promise getSchema(): schema.Database + import(data: Object): Promise insertOrReplace(): query.Insert insert(): query.Insert observe(query: query.Select, callback: Function): void @@ -174,9 +186,16 @@ declare module lf { order: Order } + type RawForeignKeySpec = { + local: string + ref: string + action: lf.ConstraintAction + timing: lf.ConstraintAction + } + export interface TableBuilder { addColumn(name: string, type: lf.Type): TableBuilder - addForeignKey(): TableBuilder + addForeignKey(name: string, spec: RawForeignKeySpec): TableBuilder addIndex( name: string, columns: Array|Array, unique?: boolean, order?: Order): TableBuilder diff --git a/node-jsfl-runner/node-jsfl-runner-tests.ts b/node-jsfl-runner/node-jsfl-runner-tests.ts index f92f4bfde..31202b9f7 100644 --- a/node-jsfl-runner/node-jsfl-runner-tests.ts +++ b/node-jsfl-runner/node-jsfl-runner-tests.ts @@ -8,11 +8,13 @@ let myJSFL: jsfl.JSFL = { } } +let flashLocation: string = ''; + jsfl.createJSFL(myJSFL, 'fileName.jsfl', ['Hello!'], (err: NodeJS.ErrnoException) => { }); -jsfl.runJSFL('fileName.jsfl', (err: NodeJS.ErrnoException) => { +jsfl.runJSFL(flashLocation, 'fileName.jsfl', (err: NodeJS.ErrnoException) => { }); diff --git a/node-jsfl-runner/node-jsfl-runner.d.ts b/node-jsfl-runner/node-jsfl-runner.d.ts index b3f0a8688..f1d11561a 100644 --- a/node-jsfl-runner/node-jsfl-runner.d.ts +++ b/node-jsfl-runner/node-jsfl-runner.d.ts @@ -1,4 +1,4 @@ -// Type definitions for node-jsfl-runner +// Type definitions for node-jsfl-runner v0.2.4 // Project: https://www.npmjs.com/package/node-jsfl-runner // Definitions by: Michael Randolph // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -28,8 +28,9 @@ declare module "node-jsfl-runner" { /** * Runs a JSFL file + * @param flashLocation Path to Flash executable * @param fileName Path to JSFL file to run * @param callback Callback */ - function runJSFL(fileName: string, callback: (err: NodeJS.ErrnoException) => void): void; + function runJSFL(flashLocation:string, fileName: string, callback: (err: NodeJS.ErrnoException) => void): void; } \ No newline at end of file diff --git a/node-mysql-wrapper/node-mysql-wrapper-tests.ts b/node-mysql-wrapper/node-mysql-wrapper-tests.ts index 869aa823e..3d26b6e8b 100644 --- a/node-mysql-wrapper/node-mysql-wrapper-tests.ts +++ b/node-mysql-wrapper/node-mysql-wrapper-tests.ts @@ -1,4 +1,7 @@ /// +/// +/// + var express = require('express'); var app = express(); var server = require('http').createServer(app); @@ -9,42 +12,37 @@ class User { //or interface userId: number; username: string; mail: string; + password:string; comments: Comment[]; + myComments: Comment[]; + info: UserInfo; } interface Comment { commentId: number; content: string; + likes: CommentLike[]; } +interface CommentLike { + commentLikeId: number; + userId: number; + commentId: number; +} + +interface UserInfo { + userInfoId: number; + userId: number; + hometown: string; +} db.ready(() => { var usersDb = db.table("users"); - usersDb.rules.orderBy("userId", true); - + + //or var usersDb = db.table("users"); if you don't want intel auto complete from your ide/editor - usersDb.findAll().then(users=> { - users.forEach(user=> { - console.log(user.userId); - }); - }); - - - //define new table rules: usersDb.rules.clear().orderBy....limit....groupBy... - - //define rules but keep unchanged (table's rules) in find method: - usersDb.find({ yearsOld: 22 }, (_users) => { - - console.log("-------------------------------------------------------"); - _users.forEach(_user=> { - console.log(_user.userId + " " + _user.username + " found with limit 3 but this doesnt..."); - - }); - - }).limit(3).execute(); - usersDb.findById(16, (_user) => { console.log("TEST1: \n"); @@ -56,20 +54,27 @@ db.ready(() => { }, (err) => { console.log("ERROR ON FETCHING FINDBY ID: " + err) }); */ - usersDb.find({ userId: 18, comments: { userId: '=' } }, _users=> { - - var _user = _users[0]; - - console.log("TEST2: \n"); - console.log(_user.username + " with "); - console.log(_user.comments.length + " comments "); - _user.comments.forEach(_comment=> { - console.log("--------------\n" + _comment.content); + usersDb.findSingle( + { + userId: 18, + myComments: { + userId: '=', + tableRules: { //NEW: SET rules to joined tables too! + table: "comments", //NEW SET table name inside any property u want! + limit: 50, + orderByDesc: "commentId" //give me the first 50 comments ordered by -commentId (DESC) from table 'comments' and put them at 'myComments' property inside the result object. + } + } + }).then(_user=> { // to get this promise use : .promise() + console.log("\n-------------TEST 2 ------------\n"); + console.log(_user.username + " with "); + console.log(_user.myComments.length + " comments "); + _user.myComments.forEach(_comment=> { + console.log("--------------\n" + _comment.content); + }); }); - }).execute(); - - usersDb.safeRemove(5620, answer=> { + usersDb.remove(5620, answer=> { console.log("TEST 3: \n"); console.log(answer.affectedRows + ' (1) has removed from table: ' + answer.table); @@ -86,8 +91,107 @@ db.ready(() => { }); + + usersDb.find( + { + yearsOld: 22, + comments: { + userId: "=", + tableRules: { + limit: 2 + } + } + + }, (_users) => { + + console.log("---------------TEST 6----------------------------------------"); + _users.forEach(_user=> { + console.log(_user.userId + " " + _user.username + " found with " + _user.comments.length + " comments"); + + }); + + }); + //if no rules setted to find method it's uses the table's rules ( if exists) + + + + let _criteriaFromBuilder = usersDb.criteria + .except("password") // or .exclude(...columns). the only column you cannot except/exclude is the primary key (because it is used at where clause), be careful. + .where("userId", 24) + .joinAs("info", "userInfos", "userId") + .at("info") + .limit(1) //because we make it limit 1 it will return this result as object not as array. + .parent() + .joinAs("myComments", "comments", "userId") + .at("myComments").limit(2) + .joinAs("likes", "commentLikes", "commentId") + .original().orderBy("userId", true).build(); + + /* console.dir(_criteriaFromBuilder); + prints this object: ( of course you can create your own in order to pass it on .find table methods ) + { + userId:23, + + myComments:{ + userId: '=', + + tableRules:{ + table: 'comments', + limit:2 + + }, + + likes:{ + commentId: '=', + + tableRules:{ + table: 'commentLikes' + } + + } + }, + + tableRules:{ + orderByDesc: 'userId', + except: ['password'] + } + + } + + + */ + + + + usersDb.find(_criteriaFromBuilder).then(_users=> { + console.log("\n----------------\nTEST ADVANCED 1\n-------------------\n "); + _users.forEach(_user=> { + console.log(_user.userId + " " + _user.username); + + if (_user.info !== undefined) { + console.log(' from ' + _user.info.hometown); + //console.dir(_user.userInfos); + } + + if (_user.myComments !== undefined) { + _user.myComments.forEach(_comment=> { + console.log(_comment.commentId + " " + _comment.content); + + if (_comment.likes !== undefined) { + console.log(' with ' + _comment.likes.length + ' likes!'); + } + }); + } + }); + + }); + + }); +server.on('uncaughtException', function(err:any) { + console.log(err); +}) var httpPort = 1193;//config.get('Server.port') || 1193; server.listen(httpPort, function() { diff --git a/node-mysql-wrapper/node-mysql-wrapper.d.ts b/node-mysql-wrapper/node-mysql-wrapper.d.ts index 095038faa..af100bbf4 100644 --- a/node-mysql-wrapper/node-mysql-wrapper.d.ts +++ b/node-mysql-wrapper/node-mysql-wrapper.d.ts @@ -1,5 +1,5 @@ // Type definitions for node-mysql-wrapper -// Project: https://github.com/kataras/node-mysql-wrapper +// Project: https://github.com/nodets/node-mysql-wrapper // Definitions by: Makis Maropoulos // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -12,11 +12,42 @@ declare module "node-mysql-wrapper" { import {EventEmitter} from 'events'; var EQUAL_TO_PROPERTY_SYMBOL: string; + var TABLE_RULES_PROPERTY: string; + + type DeleteAnswer = { + affectedRows: number; + table: string; + }; + + type RawRules = { + table: string, + begin: string, + orderBy: string, + orderByDesc: string, + groupBy: string, + limit: number, // limit = limitStart =0 and limitEnd = limit. + limitStart: number, + limitEnd: number, + end: string + + }; + + type TableToSearchPart = { tableName: string, propertyName: string }; interface Map { [index: string]: T; } + interface IQuery { + _table: Table; + execute(rawCriteria: any, callback?: (_results: any) => any): Promise; + } + + interface IQueryConstructor { + new (_table: Table): IQuery; + } + + class Helper { /** * Callback like forEach @@ -61,9 +92,7 @@ declare module "node-mysql-wrapper" { * @return {string} */ static toRowProperty(objectKey: string): string; - - /** * Iterate object's keys and return their values to the callback. * @param {Map} map the object. @@ -80,17 +109,38 @@ declare module "node-mysql-wrapper" { * @returnType {U} * @return {U} */ + static forEachKey(map: Map, callback: (key: string) => U): U; + + /** + * Checks if anything is a function. + * @param {functionToCheck} the object or function to pass + * @return boolean + */ + static isFunction(functionToCheck: any): boolean; + + /** + * Checks if an object has 'tableRules' property. + * @param {obj} the object to pass + * @return boolean + */ + static hasRules(obj: any): boolean; } - interface ICriteria { + + interface ICriteriaParts { rawCriteriaObject: any; - tables: string[]; + tables: TableToSearchPart[]; noDatabaseProperties: string[]; whereClause: string; + + selectFromClause(_table: Table): string; + } - class Criteria implements ICriteria { + + + class CriteriaParts implements ICriteriaParts { /** * The raw format of the criteria eg: {yearsOld:22}. @@ -100,7 +150,7 @@ declare module "node-mysql-wrapper" { /** * Which tables to search after the find method of the proto table finish. */ - tables: string[]; + tables: TableToSearchPart[]; /** * The properties of the criteria which don't belong to the database's table. @@ -112,10 +162,12 @@ declare module "node-mysql-wrapper" { */ whereClause: string; - constructor(rawCriteriaObject: any, tables: string[], noDatabaseProperties: string[], whereClause: string); + constructor(rawCriteriaObject: any, tables: TableToSearchPart[], noDatabaseProperties: string[], whereClause: string); + + selectFromClause(_table: Table): string; } - class CriteriaBuilder { + class CriteriaDivider { private _table; constructor(table: Table); @@ -125,70 +177,131 @@ declare module "node-mysql-wrapper" { * @returnType {Criteria} * @return {Criteria} */ - build(rawCriteriaObject: any): Criteria; + build(rawCriteriaObject: any): CriteriaParts; } class SelectQueryRules { - orderByClause: string; - groupByClause: string; - limitClause: string; - - + private lastPropertyClauseName: string; + manuallyEndClause: string; + manuallyBeginClause: string; + exceptColumns: string[]; + orderByColumn: string; + orderByDescColumn: string; + groupByColumn: string; + limitStart: number; + limitEnd: number; + public tableName: string; //auto den benei oute sto last, oute sto from. static build(): SelectQueryRules; - static build(parentRule?: SelectQueryRules): SelectQueryRules; + private last(propertyClauseName); + except(...columns: string[]): SelectQueryRules; + + /** + * Same as .except(...columns) + */ + exclude(...columns: string[]): SelectQueryRules; orderBy(columnKey: string, descending?: boolean): SelectQueryRules; - groupBy(columnKey: string): SelectQueryRules; - limit(limitRowsOrStart: number, limitEnd?: number): SelectQueryRules; - + appendToBegin(manualAfterWhereString: string): SelectQueryRules; + appendToEnd(manualAfterWhereString: string): SelectQueryRules; + append(appendToCurrent: string): SelectQueryRules; clearOrderBy(): SelectQueryRules; - clearGroupBy(): SelectQueryRules; - clearLimit(): SelectQueryRules; - + clearEndClause(): SelectQueryRules; + clearBeginClause(): SelectQueryRules; clear(): SelectQueryRules; - from(parentRule: SelectQueryRules): SelectQueryRules; - + isEmpty(): boolean; toString(): string; + toRawObject(): RawRules; + static toString(rules: SelectQueryRules): string; + static toRawObject(rules: SelectQueryRules): RawRules; + static fromRawObject(obj: RawRules): SelectQueryRules; } - class SelectQuery { + class CriteriaBuilder{ - private _rules: SelectQueryRules; - private _table: Table; - private _criteriaRawJsObject: any; - private _callback: (_results: T[]) => any; - private callback: (resolve?: (thenableOrResult?: T | Promise.Thenable) => void, reject?: (error?: any) => void) => void; + private rawCriteria: any; + private primaryTable: Table; + private parentBuilder: CriteriaBuilder; - constructor(table: Table, criteriaRawJsObject: any, callback?: (_results: T[]) => any); + constructor(primaryTable: Table); //to arxiko apo to Table.ts 9a benei + constructor(primaryTable: Table, tableName: string, parentBuilder: CriteriaBuilder);// auta 9a benoun apo to parent select query. + constructor(primaryTable: Table, tablePropertyName?: string, parentBuilder?: CriteriaBuilder); - orderBy(columnKey: string, descending?: boolean): SelectQuery; + except(...columns: string[]): CriteriaBuilder; + + /** + * Same as .except(...columns) + */ + exclude(...columns: string[]): CriteriaBuilder; - groupBy(columnKey: string): SelectQuery; + where(key: string, value: any): CriteriaBuilder; - limit(limitRowsOrStart: number, limitEnd?: number): SelectQuery; + private createRulesIfNotExists(): void; + + orderBy(column: string, desceding?: boolean): CriteriaBuilder; + + limit(start: number, end?: number): CriteriaBuilder; + + join(realTableName: string, foreignColumnName: string): CriteriaBuilder; + + joinAs(tableNameProperty: string, realTableName: string, foreignColumnName: string): CriteriaBuilder; + + at(tableNameProperty: string): CriteriaBuilder; + + parent(): CriteriaBuilder; + + original(): CriteriaBuilder; + + /** + * Auto kanei kuklous mexri na paei sto primary table kai ekei na epistrepsei to sunoliko raw criteria gia execute i kati allo. + */ + build(): any; + + static from(table: Table): CriteriaBuilder + + } + + class SelectQuery implements IQuery { // T for Table's result type. + + _table: Table + constructor(_table: Table); + + private parseQueryResult(result: any, criteria: ICriteriaParts): Promise; /** - * Executes the select and returns the Promise. - */ - promise(): Promise; - + * Executes the select and returns the Promise. + */ + promise(rawCriteria: any, callback?: (_results: T[]) => any): Promise; + /** * Exactly the same thing as promise(). * Executes the select and returns the Promise. - */ - execute(): Promise; - - then(onFulfill: (value: any[]) => any|Promise.Thenable): Promise; - then(onFulfill: (value: T[]) => U|Promise.Thenable, onReject: (error: any) => Promise.Thenable, onProgress?: (note: any) => any): Promise; - then(onFulfill: (value: T[]) => U|Promise.Thenable, onReject?: (error: any) => U, onProgress?: (note: any) => any): Promise; - + */ + execute(rawCriteria: any, callback?: (_results: T[]) => any): Promise; } + class SaveQuery implements IQuery { + + _table: Table + constructor(_table: Table); + + execute(criteriaRawJsObject: any, callback?: (_result: T | any) => any): Promise; + } + + class DeleteQuery implements IQuery{ + + _table: Table + constructor(_table: Table); + + execute(criteriaOrID: any | number | string, callback?: (_result: DeleteAnswer) => any): Promise; + } + + + class Connection extends EventEmitter { /** @@ -325,14 +438,17 @@ declare module "node-mysql-wrapper" { } class Table { - private _name; - private _connection; - private _columns; - private _primaryKey; - private _criteriaBuilder; - private _rules; + private _name: string; + private _connection: Connection; + private _columns: string[]; + private _primaryKey: string; + private _criteriaDivider: CriteriaDivider; + private _rules: SelectQueryRules; + private _selectQuery: SelectQuery + private _saveQuery: SaveQuery; + private _deleteQuery: DeleteQuery; constructor(tableName: string, connection: Connection); - + /** * An array of all columns' names inside this table. */ @@ -355,9 +471,23 @@ declare module "node-mysql-wrapper" { /** * Set of the query rules that will be applied after the 'where clause' on each select query executed by this table. + * @return {SelectQueryRules} */ rules: SelectQueryRules; + /** + * Returns this table's criteria divider class. + * @return {CriteriaDivider} + */ + criteriaDivider: CriteriaDivider; + + /** + * Returns new Criteria Builder each time. + * Helps you to make criteria raw js objects ready to use in find,remove and save methods. + * @return {CriteriaBuilder} + */ + criteria: CriteriaBuilder; + /** * Adds or turn on an event listener/watcher on a table for a 'database event'. * @param {string} evtType the event type you want to watch, one of these: ["INSERT", "UPDATE", "REMOVE", "SAVE"]. @@ -424,48 +554,31 @@ declare module "node-mysql-wrapper" { * @return {number | string} */ getPrimaryKeyValue(jsObject: any): number | string; - - parseQueryResult(result: any, criteria: ICriteria): Promise; /** * */ - find(criteriaRawJsObject: any): SelectQuery; // only criteria - find(criteriaRawJsObject: any, callback: ((_results: T[]) => any)): SelectQuery; // criteria and callback - find(criteriaRawJsObject: any, callback?: (_results: T[]) => any): SelectQuery; + find(criteriaRawJsObject: any): Promise; // only criteria + find(criteriaRawJsObject: any, callback: ((_results: T[]) => any)): Promise; // criteria and callback + find(criteriaRawJsObject: any, callback?: (_results: T[]) => any): Promise; + + findSingle(criteriaRawJsObject: any, callback?: (_result: T) => any): Promise; findById(id: number|string): Promise; // without callback findById(id: number | string, callback?: (result: T) => any): Promise; - findAll(): SelectQuery; // without callback - findAll(callback?: (_results: T[]) => any): SelectQuery; + findAll(): Promise; // only criteria and promise + findAll(tableRules: RawRules): Promise // only rules and promise + findAll(tableRules?: RawRules, callback?: (_results: T[]) => any): Promise; + save(criteriaRawJsObject: any): Promise; //without callback save(criteriaRawJsObject: any, callback?: (_result: any) => any): Promise; - safeRemove(id: number | string): Promise<{ - affectedRows: number; - table: string; - }>; //withoutcallback - safeRemove(id: number | string, callback?: (_result: { - affectedRows: number; - table: string; - }) => any): Promise<{ - affectedRows: number; - table: string; - }>; + remove(id: number | string): Promise; // ID without callback + remove(criteriaRawObject: any): Promise; // criteria obj without callback + remove(criteriaOrID: any | number | string, callback?: (_result: DeleteAnswer) => any): Promise; - remove(criteriaRawObject: any): Promise<{ - affectedRows: number; - table: string; - }>; // without callback - remove(criteriaRawJsObject: any, callback?: (_result: { - affectedRows: number; - table: string; - }) => any): Promise<{ - affectedRows: number; - table: string; - }>; } class Wrapper { diff --git a/observe-js/observe-js-test.ts b/observe-js/observe-js-test.ts new file mode 100644 index 000000000..37ad0216c --- /dev/null +++ b/observe-js/observe-js-test.ts @@ -0,0 +1,111 @@ +/// + +module observejs { + + function Test_PathObserver() { + var obj = { foo: { bar: 'baz' } }; + var defaultValue = 42; + var observer = new PathObserver(obj, 'foo.bar', defaultValue); + observer.open(function(newValue, oldValue) { + // respond to obj.foo.bar having changed value. + }); + } + + + function Test_ArrayObserver() { + var arr = [0, 1, 2, 4]; + var observer = new ArrayObserver(arr); + observer.open(function(splices) { + // respond to changes to the elements of arr. + splices.forEach(function(splice) { + splice.index; // the index position that the change occurred. + splice.removed; // an array of values representing the sequence of removed elements + splice.addedCount; // the number of elements which were inserted. + }); + }); + } + + function Test_ObejctObserver() { + var myObj = { id: 1, foo: 'bar' }; + var observer = new ObjectObserver(myObj); + observer.open(function(added, removed, changed, getOldValueFn) { + // respond to changes to the obj. + Object.keys(added).forEach(function(property) { + property; // a property which has been been added to obj + added[property]; // its value + }); + Object.keys(removed).forEach(function(property) { + property; // a property which has been been removed from obj + getOldValueFn(property); // its old value + }); + Object.keys(changed).forEach(function(property) { + property; // a property on obj which has changed value. + changed[property]; // its value + getOldValueFn(property); // its old value + }); + }); + } + + function Test_CompounObserver() { + var obj = { + a: 1, + b: 2, + }; + + var otherObj = { c: 3 }; + + var observer = new CompoundObserver(); + observer.addPath(obj, 'a'); + observer.addObserver(new PathObserver(obj, 'b')); + observer.addPath(otherObj, 'c'); + var logTemplate = 'The %sth value before & after:'; + observer.open(function(newValues, oldValues) { + // Use for-in to iterate which values have changed. + for (var i in oldValues) { + console.log(logTemplate, i, oldValues[i], newValues[i]); + } + }); + } + + function Test_ObserverTransform_1() { + var obj = { value: 10 }; + var observer = new PathObserver(obj, 'value'); + function getValue(value:any) { return value * 2 }; + function setValue(value:any) { return value / 2 }; + + var transform = new ObserverTransform(observer, getValue, setValue); + + // returns 20. + transform.open(function(newValue, oldValue) { + console.log('new: ' + newValue + ', old: ' + oldValue); + }); + + obj.value = 20; + transform.deliver(); // 'new: 40, old: 20' + transform.setValue(4); // obj.value === 2; + } + + function Test_ObserverTransform_2() { + var obj = { a: 1, b: 2, c: 3 }; + var observer = new CompoundObserver(); + observer.addPath(obj, 'a'); + observer.addPath(obj, 'b'); + observer.addPath(obj, 'c'); + var transform = new ObserverTransform(observer, function(values) { + var value = 0; + for (var i = 0; i < values.length; i++) + value += values[i] + return value; + }); + + // returns 6. + transform.open(function(newValue, oldValue) { + console.log('new: ' + newValue + ', old: ' + oldValue); + }); + + obj.a = 2; + obj.c = 10; + transform.deliver(); // 'new: 14, old: 6' + } + +} \ No newline at end of file diff --git a/observe-js/observe-js.d.ts b/observe-js/observe-js.d.ts new file mode 100644 index 000000000..abd2caa00 --- /dev/null +++ b/observe-js/observe-js.d.ts @@ -0,0 +1,250 @@ +// Type definitions for observe-js v0.5.5 +// Project: https://github.com/Polymer/observe-js +// Definitions by: Oliver Herrmann +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module observejs { + + /*---------------------- + Observable + ----------------------*/ + + interface Observable { + /** + * Begins observation. + * @param onChange the function that gets invoked if a change is detected + * @param the target of observation + */ + open(onChange:(newValue:any, oldValue:any)=>any, receiver?:any):void + + /** + * Report any changes now (does nothing if there are no changes to report). + */ + deliver(): void + + /** + * If there are changes to report, ignore them. Returns the current value of the observation. + */ + discardChanges():void + + /** + * Ends observation. Frees resources and drops references to observed objects. + */ + close():void + } + + + /*---------------------- + PathObserver + ----------------------*/ + + interface PathObserver_static { + /** + * Constructor + * @param receiver the target for observation + * @param path specifies the paht to observe. If path === '' the receiver itself gets observed. + * @param defaultValue the defaultValue + */ + new(receiver:any, path:string, defaultValue?:any): PathObserver_instance + } + + interface PathObserver_instance extends Observable { + /** + * sets the observed value without notifying about the change. + * @param value the value to set + */ + setValue(value:any): void + } + + /** + * Observes a "value-at-a-path" from a given object: + */ + var PathObserver: PathObserver_static + + + /*---------------------- + ArrayObserver + ----------------------*/ + + interface splice { + + /** + * the index position that the change occured + */ + index:number + + /** + * an array of values representing the sequence of removed elements + */ + removed: Array + + /** + * the number of element which were inserted + */ + addedCount:number + } + + interface ArrayObserver_static { + + /** + * Constructor + * @param receiver the target for observation + */ + new(receiver:Array): ArrayObserver_instance + + /** + * transforms a copy of an old state of an array into a copy of its current state. + * @param previous array of old state + * @param current array of current state + * @param splices splices to apply + */ + applySplices(previous:Array, current:Array, splices:Array):void + } + + interface ArrayObserver_instance extends Observable { + open(onChange:(splices:Array)=>any):void + } + + /** + * ArrayObserver observes the index-positions of an Array and reports changes as the minimal set of "splices" which would have had the same effect. + */ + var ArrayObserver: ArrayObserver_static + + + /*---------------------- + ObjectObserver + ----------------------*/ + + interface Properties { + [key:string]:any + } + + interface ObjectObserver_static { + + /** + * Constructor + * @param receiver the target for observation + */ + new(receiver:any): ObjectObserver_instance + } + + interface ObjectObserver_instance extends Observable { + open(onChange:(added:Properties, removed:Properties, changed:Properties, getOldValueFn:(property:string)=>any)=>any):void + } + + /** + * Observes the set of own-properties of an object and their values + */ + var ObjectObserver: ObjectObserver_static + + + /*---------------------- + CompounObserver + ----------------------*/ + + interface CompoundObserver_static { + + /** + * Constructor + */ + new(): CompoundObserver_instance + } + + interface CompoundObserver_instance extends Observable { + open(onChange:(newValues:Array, oldValue:Array)=>any):void + + /** + * Adds the receivers property at the specified path to the list of observables. + * @param receiver the target for observation + * @param path specifies the paht to observe. If path === '' the receiver itself gets observed. + */ + addPath(receiver:any, path:string):void + + /** + * Adds an Observer to the list of observables. + */ + addObserver(observer:Observable):void + + } + + /** + * CompoundObserver allows simultaneous observation of multiple paths and/or Observables. + */ + var CompoundObserver: CompoundObserver_static + + + + /*---------------------- + ObserverTransform + ----------------------*/ + + interface ObserverTransform_static { + + /** + * Constructor + * @param observer the observer to transform + * @param getValue function that proxys getting a value + * @param setValue function that proxys setting a value + */ + new(observer:Observable, getValue:(value:any)=>any, setValue:(value:any)=>any): ObserverTransform_instance + + /** + * Constructor + * @param observer the observer to transform + * @param valueFn function that gets invoked with all observed values. May return a single new value. + */ + new(observer:Observable, valueFn:(values:Array)=>any): ObserverTransform_instance + } + + interface ObserverTransform_instance extends Observable { + /** + * sets the observed value without notifying about the change. + * @param value the value to set + */ + setValue(value:any): void + } + + /** + * CompoundObserver allows simultaneous observation of multiple paths and/or Observables. + */ + var ObserverTransform: ObserverTransform_static + + + /*---------------------- + Path + ----------------------*/ + + interface Path { + + /** + * Returns the current value of the path from the provided object. If eval() is available, + * a compiled getter will be used for better performance. Like PathObserver above, undefined + * is returned unless you provide an overriding defaultValue. + */ + getValueFrom(object:any, defaultValue:any): any + + /** + * Attempts to set the value of the path from the provided object. Returns true IFF the path + * was reachable and set. + */ + getValueFrom(object:any, newValue:any): any + } +} + +declare module "observejs" { + var PathObserver: typeof observejs.PathObserver; + var ArrayObserver: typeof observejs.ArrayObserver; + var ObjectObserver: typeof observejs.ObjectObserver; + var CompoundObserver: typeof observejs.CompoundObserver; + var ObserverTransform: typeof observejs.ObserverTransform; + var Path: observejs.Path; + + export { + PathObserver, + ArrayObserver, + ObjectObserver, + CompoundObserver, + ObserverTransform, + Path + }; +} \ No newline at end of file diff --git a/serve-favicon/serve-favicon.d.ts b/serve-favicon/serve-favicon.d.ts index bb19c2f69..19bbb261e 100644 --- a/serve-favicon/serve-favicon.d.ts +++ b/serve-favicon/serve-favicon.d.ts @@ -1,4 +1,4 @@ -// Type definitions for serve-favicon 2.1.6 +// Type definitions for serve-favicon 2.2.0 // Project: https://github.com/expressjs/serve-favicon // Definitions by: Uros Smolnik // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -24,6 +24,8 @@ declare module "serve-favicon" { */ maxAge?: number; }): express.RequestHandler; + + namespace serveFavicon{} export = serveFavicon; } \ No newline at end of file diff --git a/slickgrid/SlickGrid.d.ts b/slickgrid/SlickGrid.d.ts index 60f0a24b6..850a9a117 100644 --- a/slickgrid/SlickGrid.d.ts +++ b/slickgrid/SlickGrid.d.ts @@ -507,11 +507,11 @@ declare module Slick { getEditor(column: Column): Editors.Editor; } - export interface FormatterFactory { + export interface FormatterFactory { getFormatter(column: Column): Formatter; } - export interface GridOptions { + export interface GridOptions { /** * Makes cell editors load asynchronously after a small delay. This greatly increases keyboard navigation speed. @@ -863,7 +863,7 @@ declare module Slick { * todo: no docs or comments available * @return **/ - public getSortColumns(): Column[]; + public getSortColumns(): { columnId: string; sortAsc: boolean }[]; /** * Updates an existing column definition and a corresponding header DOM element with the new title and tooltip. @@ -1106,39 +1106,39 @@ declare module Slick { // #region Events - public onScroll: Slick.Event; - public onSort: Slick.Event>; - public onHeaderMouseEnter: Slick.Event>; - public onHeaderMouseLeave: Slick.Event>; - public onHeaderContextMenu: Slick.Event>; - public onHeaderClick: Slick.Event>; - public onHeaderCellRendered: Slick.Event>; - public onBeforeHeaderCellDestroy: Slick.Event>; - public onHeaderRowCellRendered: Slick.Event>; - public onBeforeHeaderRowCellDestroy: Slick.Event>; - public onMouseEnter: Slick.Event; - public onMouseLeave: Slick.Event; - public onClick: Slick.Event; - public onDblClick: Slick.Event; - public onContextMenu: Slick.Event; - public onKeyDown: Slick.Event; - public onAddNewRow: Slick.Event>; - public onValidationError: Slick.Event>; - public onColumnsReordered: Slick.Event; - public onColumnsResized: Slick.Event; - public onCellChange: Slick.Event>; - public onBeforeEditCell: Slick.Event>; - public onBeforeCellEditorDestroy: Slick.Event>; - public onBeforeDestroy: Slick.Event; - public onActiveCellChanged: Slick.Event; - public onActiveCellPositionChanged: Slick.Event; - public onDragInit: Slick.Event; - public onDragStart: Slick.Event; - public onDrag: Slick.Event; - public onDragEnd: Slick.Event; - public onSelectedRowsChanged: Slick.Event; - public onCellCssStylesChanged: Slick.Event; - public onViewportChanged: Slick.Event; + public onScroll: Slick.Event>; + public onSort: Slick.Event>; + public onHeaderMouseEnter: Slick.Event>; + public onHeaderMouseLeave: Slick.Event>; + public onHeaderContextMenu: Slick.Event>; + public onHeaderClick: Slick.Event>; + public onHeaderCellRendered: Slick.Event>; + public onBeforeHeaderCellDestroy: Slick.Event>; + public onHeaderRowCellRendered: Slick.Event>; + public onBeforeHeaderRowCellDestroy: Slick.Event>; + public onMouseEnter: Slick.Event>; + public onMouseLeave: Slick.Event>; + public onClick: Slick.Event>; + public onDblClick: Slick.Event>; + public onContextMenu: Slick.Event>; + public onKeyDown: Slick.Event>; + public onAddNewRow: Slick.Event>; + public onValidationError: Slick.Event>; + public onColumnsReordered: Slick.Event>; + public onColumnsResized: Slick.Event>; + public onCellChange: Slick.Event>; + public onBeforeEditCell: Slick.Event>; + public onBeforeCellEditorDestroy: Slick.Event>; + public onBeforeDestroy: Slick.Event>; + public onActiveCellChanged: Slick.Event>; + public onActiveCellPositionChanged: Slick.Event>; + public onDragInit: Slick.Event>; + public onDragStart: Slick.Event>; + public onDrag: Slick.Event>; + public onDragEnd: Slick.Event>; + public onSelectedRowsChanged: Slick.Event>; + public onCellCssStylesChanged: Slick.Event>; + public onViewportChanged: Slick.Event>; // #endregion Events // #region Plugins @@ -1177,74 +1177,78 @@ declare module Slick { // #endregion Editors } - export interface OnCellCssStylesChangedEventData { + export interface GridEventArgs { + grid: Grid; + } + + export interface OnCellCssStylesChangedEventArgs extends GridEventArgs { key: string; hash: CellCssStylesHash; } - export interface OnSelectedRowsChangedEventData { + export interface OnSelectedRowsChangedEventArgs extends GridEventArgs { rows: number[]; } - export interface OnDragEndEventData { + export interface OnDragEndEventArgs extends GridEventArgs { // todo: need to understand $canvas drag event parameter's 'dd' object // the documentation is not enlightening } - export interface OnDragEventData { + export interface OnDragEventArgs extends GridEventArgs { // todo: need to understand $canvas drag event parameter's 'dd' object // the documentation is not enlightening } - export interface OnDragStartEventData { + export interface OnDragStartEventArgs extends GridEventArgs { // todo: need to understand $canvas drag event parameter's 'dd' object // the documentation is not enlightening } - export interface OnDragInitEventData { + export interface OnDragInitEventArgs extends GridEventArgs { // todo: need to understand $canvas drag event parameter's 'dd' object // the documentation is not enlightening } - export interface OnActiveCellPositionChangedEventData { + export interface OnActiveCellPositionChangedEventArgs extends GridEventArgs { } - export interface OnActiveCellChangedEventData { + export interface OnActiveCellChangedEventArgs extends GridEventArgs { row: number; cell: number; } - export interface OnBeforeDestroyEventData { + export interface OnBeforeDestroyEventArgs extends GridEventArgs { } - export interface OnBeforeCellEditorDestroyEventData { + export interface OnBeforeCellEditorDestroyEventArgs extends GridEventArgs { editor: Editors.Editor; } - export interface OnBeforeEditCellEventData { + export interface OnBeforeEditCellEventArgs extends GridEventArgs { row: number; cell: number; item: T; column: Column; } - export interface OnCellChangeEventData { + export interface OnCellChangeEventArgs extends GridEventArgs { row: number; cell: number; item: T; } - export interface OnColumnsResizedEventData { + export interface OnColumnsResizedEventArgs extends GridEventArgs { } - export interface OnColumnsReorderedEventData { + export interface OnColumnsReorderedEventArgs extends GridEventArgs { } - export interface OnValidationErrorEventData { + export interface OnValidationErrorEventArgs extends GridEventArgs { editor: Editors.Editor; cellNode: HTMLElement; validationResults: ValidateResults; @@ -1253,92 +1257,91 @@ declare module Slick { column: Column; } - export interface OnAddNewRowEventData { + export interface OnAddNewRowEventArgs extends GridEventArgs { item: T; column: Column; } - export interface OnKeyDownEventData { + export interface OnKeyDownEventArgs extends GridEventArgs { row: number; cell: number; } - export interface OnContextMenuEventData { + export interface OnContextMenuEventArgs extends GridEventArgs { } - export interface OnDblClickEventData { + export interface OnDblClickEventArgs extends GridEventArgs { row: number; cell: number; } - export interface OnClickEventData { + export interface OnClickEventArgs extends GridEventArgs { row: number; cell: number; } - export interface OnMouseLeaveEventData { + export interface OnMouseLeaveEventArgs extends GridEventArgs { } - export interface OnMouseEnterEventData { + export interface OnMouseEnterEventArgs extends GridEventArgs { } - export interface OnBeforeHeaderRowCellDestroyEventData { + export interface OnBeforeHeaderRowCellDestroyEventArgs extends GridEventArgs { node: HTMLElement; // todo: might be JQuery instance column: Column; } - export interface OnHeaderRowCellRenderedEventData { + export interface OnHeaderRowCellRenderedEventArgs extends GridEventArgs { node: HTMLElement; // todo: might be JQuery instance column: Column; } - export interface OnBeforeHeaderCellDestroyEventData { + export interface OnBeforeHeaderCellDestroyEventArgs extends GridEventArgs { node: HTMLElement; // todo: might be JQuery instance column: Column; } - export interface OnHeaderCellRenderedEventData { + export interface OnHeaderCellRenderedEventArgs extends GridEventArgs { node: HTMLElement; // todo: might be JQuery instance column: Column; } - export interface OnHeaderClickEventData { + export interface OnHeaderClickEventArgs extends GridEventArgs { column: Column; } - export interface OnHeaderContextMenuEventData { + export interface OnHeaderContextMenuEventArgs extends GridEventArgs { column: Column; } - export interface OnHeaderMouseEventData { + export interface OnHeaderMouseEventArgs extends GridEventArgs { column: Column; } - // todo: merge with existing column definition - export interface Column { - sortCol?: Column; - sortAsc?: boolean; - } - - export interface OnSortEventData { + export interface OnSortEventArgs extends GridEventArgs { multiColumnSort: boolean; - sortCol?: Column; - sortCols: Column[]; - sortAsc?: boolean; + sortCol?: SortColumn; + sortCols?: SortColumn[]; + sortAsc: boolean; } - export interface OnScrollEventData { + export interface OnScrollEventArgs extends GridEventArgs { scrollLeft: number; scrollTop: number; } - export interface OnViewportChangedEventData { + export interface OnViewportChangedEventArgs extends GridEventArgs { } + export interface SortColumn { + sortCol: Column; + sortAsc: boolean; + } + export interface Cell { row: number; cell: number; @@ -1449,7 +1452,7 @@ declare module Slick { } } - export interface Formatter { + export interface Formatter { (row: number, cell: number, value: any, columnDef: Column, dataContext: SlickData): string; } diff --git a/slickgrid/slick.headerbuttons.d.ts b/slickgrid/slick.headerbuttons.d.ts index 613203f43..df7e6bb25 100644 --- a/slickgrid/slick.headerbuttons.d.ts +++ b/slickgrid/slick.headerbuttons.d.ts @@ -24,7 +24,7 @@ declare module Slick { tooltip?: string; } - export interface OnCommandEventData { + export interface OnCommandEventArgs { grid: Grid; column: Column; command: string; @@ -35,7 +35,7 @@ declare module Slick { export class HeaderButtons extends Plugin { constructor(); - public onCommand: Event>; + public onCommand: Event>; } } }