From dfb310d80e2562c1af2b717fa37da8230e300317 Mon Sep 17 00:00:00 2001 From: Dale Anderson Date: Wed, 13 Jan 2016 13:23:50 -0800 Subject: [PATCH 1/5] Added azure-mobile-apps.d.ts and test --- azure-mobile-apps/azure-mobile-apps-tests.ts | 47 +++ azure-mobile-apps/azure-mobile-apps.d.ts | 284 +++++++++++++++++++ 2 files changed, 331 insertions(+) create mode 100644 azure-mobile-apps/azure-mobile-apps-tests.ts create mode 100644 azure-mobile-apps/azure-mobile-apps.d.ts diff --git a/azure-mobile-apps/azure-mobile-apps-tests.ts b/azure-mobile-apps/azure-mobile-apps-tests.ts new file mode 100644 index 000000000..f2a361d28 --- /dev/null +++ b/azure-mobile-apps/azure-mobile-apps-tests.ts @@ -0,0 +1,47 @@ +/// + +var app = require('express')(), + mobileApp = require('azure-mobile-apps')({ + debug: true, + data: { + provider: 'mssql', + server: '', + user: '', + database: '', + password: '' + } + }) + +mobileApp.tables.add('todoitem', { + authorize: true +}); + +mobileApp.api.add('customApi', { + authorize: true, + post: function (req, res, next) { + next(); + }, + patch: [function (req, res, next) {}, function (req, res, next) {}] +}) + +mobileApp.use(function (req, res, next) { + next(); +}); + +var table = mobileApp.table() +table.read(function (context) { + return context.execute().then(function (result) { + return result; + }); +}); + +table.use(function (req, res, next) { + next(new Error()); +}); + +var logger = require('azure-mobile-apps/src/logger'); +logger.silly('test', 'message'); +logger.error('Something happened', new Error()); + +var queries = require('azure-mobile-apps/src/query'); +queries.create('table').where({ x: 10 }).select('col1,col2'); \ No newline at end of file diff --git a/azure-mobile-apps/azure-mobile-apps.d.ts b/azure-mobile-apps/azure-mobile-apps.d.ts new file mode 100644 index 000000000..6e031049a --- /dev/null +++ b/azure-mobile-apps/azure-mobile-apps.d.ts @@ -0,0 +1,284 @@ +// Type definitions for azure-mobile-apps v2.0.0-beta3 +// Project: https://github.com/Azure/azure-mobile-apps-node/ +// Definitions by: Microsoft Azure +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module "azure-mobile-apps" { + function returnedFunction(configuration?: AzureMobileApps.Configuration): AzureMobileApps.ExpressMobileApp; + module returnedFunction { } + export = returnedFunction; +} + +declare module "azure-mobile-apps/src/express" { + function returnedFunction(configuration: AzureMobileApps.Configuration): AzureMobileApps.ExpressMobileApp; + module returnedFunction { } + export = returnedFunction; +} + +declare module "azure-mobile-apps/src/express/api" { + function returnedFunction(configuration: AzureMobileApps.Configuration): AzureMobileApps.ExpressApi; + module returnedFunction { } + export = returnedFunction; +} + +declare module "azure-mobile-apps/src/express/table" { + function returnedFunction(definition: AzureMobileApps.TableDefinition): AzureMobileApps.ExpressTable; + module returnedFunction { } + export = returnedFunction; +} + +declare module "azure-mobile-apps/src/express/tables" { + function returnedFunction(configuration: AzureMobileApps.Configuration): AzureMobileApps.ExpressTables; + module returnedFunction { } + export = returnedFunction; +} + +declare module "azure-mobile-apps/src/auth" { + function returnedFunction(configuration: AzureMobileApps.Configuration): AzureMobileApps.Auth; + module returnedFunction { } + export = returnedFunction; +} + +declare module "azure-mobile-apps/src/data" { + function returnedFunction(configuration: AzureMobileApps.Configuration): (table: AzureMobileApps.ExpressTable) => AzureMobileApps.Data; + module returnedFunction { } + export = returnedFunction; +} + +declare module "azure-mobile-apps/src/logger" { + var logger: AzureMobileApps.Logger; + export = logger; +} + +declare module "azure-mobile-apps/src/query" { + var query: AzureMobileApps.Query; + export = query; +} + +declare module AzureMobileApps { + // express + interface ExpressMobileApp { + configuration: Configuration; + tables: ExpressTables; + table(): ExpressTable; + api: ExpressApi; + use(middleware: Middleware | Middleware[]): void; + } + + interface ExpressApi { + add(name: string, definition: ApiDefinition): void; + import(fileOrFolder: string): void; + } + + interface ExpressTable { + authorize?: boolean; + autoIncrement?: boolean; + dynamicSchema?: boolean; + name: string; + columns?: any; + schema: string; + + use(middleware: Middleware | Middleware[]): void; + read(operationHandler: (context: Context) => void): void; + update(operationHandler: (context: Context) => void): void; + insert(operationHandler: (context: Context) => void): void; + delete(operationHandler: (context: Context) => void): void; + undelete(operationHandler: (context: Context) => void): void; + } + + interface ExpressTables { + configuration: Configuration; + add(name: string, definition: ExpressTable | TableDefinition): void; + import(fileOrFolder: string): void; + initialize(): Thenable; + } + + // data + interface Data { + read(query: QueryJs): Thenable; + update(item: any, query: QueryJs): Thenable; + insert(item: any): Thenable; + delete(query: QueryJs, version: string): Thenable; + undelete(query: QueryJs, version: string): Thenable; + truncate(): Thenable; + initialize(): Thenable; + schema(): Thenable; + } + + interface SchemaResult { + name: string; + type: string; + } + + // auth + interface User { + id: string; + claims: any[]; + token: string; + getIdentity(provider: string): Thenable; + } + + interface Auth { + validate(token: string): Thenable; + decode(token: string): User; + sign(payload: any): string; + } + + // configuration + interface Configuration { + platform?: string; + basePath?: string; + configFile?: string; + promiseConstructor?: (resolve: (result) => void, reject: (error) => void) => Thenable; + apiRootPath?: string; + tableRootPath?: string; + notificationRootPath?: string; + swaggerPath?: string; + authStubRoute?: string; + debug?: boolean; + version?: string; + apiVersion?: string; + homePage?: boolean; + swagger?: boolean; + maxTop?: number; + pageSize?: number; + logging?: LoggingConfiguration; + data?: MssqlDataConfiguration; + auth?: AuthConfiguration; + cors?: CorsConfiguration; + notifications?: NotificationsConfiguration; + } + + interface DataConfiguration { + provider?: string; + } + + interface MssqlDataConfiguration { + provider: string; + user: string; + password: string; + server: string; + port?: number; + database: string; + connectionTimeout?: string; + options?: { encrypt: boolean }; + schema?: string; + dynamicSchema?: boolean; + } + + interface AuthConfiguration { + secret: string; + validateTokens?: boolean; + } + + interface LoggingConfiguration { + level?: string; + transports?: LoggingTransport[]; + } + + interface LoggingTransport { } + + interface CorsConfiguration { + maxAge?: number; + origins: string[]; + } + + interface NotificationsConfiguration { + hubName: string; + connectionString?: string; + endpoint?: string; + sharedAccessKeyName?: string; + sharedAccessKeyValue?: string; + } + + // query + interface Query { + create(tableName: string): QueryJs; + fromRequest(req: Express.Request): QueryJs; + toOData(query: QueryJs): OData; + } + + interface QueryJs { + includeTotalCount?: boolean; + orderBy(properties: string): QueryJs; + orderByDescending(properties: string): QueryJs; + select(properties: string): QueryJs; + skip(count: number): QueryJs; + take(count: number): QueryJs; + where(filter: any): QueryJs; + } + + interface OData { + table: string; + filters?: string; + ordering?: string; + orderClauses?: string; + skip?: number; + take?: number; + selections?: string; + includeTotalCount?: boolean; + } + + // notifications + interface NotificationHubService { + + } + + // general + interface Context { + query: QueryJs; + id: string | number; + item: any; + req: Express.Request; + res: Express.Response; + data: (table: TableDefinition) => Data; + tables: (tableName: string) => Data; + user: User; + push: NotificationHubService; + logger: Logger; + execute(): Thenable; + } + + interface TableDefinition { + authorize?: boolean; + autoIncrement?: boolean; + dynamicSchema?: boolean; + name?: string; + columns?: any; + schema?: string; + } + + interface ApiDefinition { + authorize?: boolean; + get?: Middleware | Middleware[]; + post?: Middleware | Middleware[]; + patch?: Middleware | Middleware[]; + put?: Middleware | Middleware[]; + delete?: Middleware | Middleware[]; + } + + interface Thenable { + then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable; + then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Thenable; + } + + interface Logger { + log(level: string, ...message: any[]): void; + silly(...message: any[]): void; + debug(...message: any[]): void; + verbose(...message: any[]): void; + info(...message: any[]): void; + warn(...message: any[]): void; + error(...message: any[]): void; + } + + interface Middleware { + (req: Express.Request, res: Express.Response, next: NextMiddleware): void; + } + + interface NextMiddleware { + (error?: any): void; + } +} \ No newline at end of file From 54aae4b32628c7a20c4ec05312b515309826a637 Mon Sep 17 00:00:00 2001 From: Dale Anderson Date: Wed, 13 Jan 2016 13:29:06 -0800 Subject: [PATCH 2/5] Fixed implicit typings --- azure-mobile-apps/azure-mobile-apps-tests.ts | 10 +++++----- azure-mobile-apps/azure-mobile-apps.d.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/azure-mobile-apps/azure-mobile-apps-tests.ts b/azure-mobile-apps/azure-mobile-apps-tests.ts index f2a361d28..6ee440439 100644 --- a/azure-mobile-apps/azure-mobile-apps-tests.ts +++ b/azure-mobile-apps/azure-mobile-apps-tests.ts @@ -18,24 +18,24 @@ mobileApp.tables.add('todoitem', { mobileApp.api.add('customApi', { authorize: true, - post: function (req, res, next) { + post: function (req: any, res: any, next: any) { next(); }, - patch: [function (req, res, next) {}, function (req, res, next) {}] + patch: [function (req: any, res: any, next: any) {}, function (req: any, res: any, next: any) {}] }) -mobileApp.use(function (req, res, next) { +mobileApp.use(function (req: any, res: any, next: any) { next(); }); var table = mobileApp.table() table.read(function (context) { - return context.execute().then(function (result) { + return context.execute().then(function (result: any) { return result; }); }); -table.use(function (req, res, next) { +table.use(function (req: any, res: any, next: any) { next(new Error()); }); diff --git a/azure-mobile-apps/azure-mobile-apps.d.ts b/azure-mobile-apps/azure-mobile-apps.d.ts index 6e031049a..b6b7d49e7 100644 --- a/azure-mobile-apps/azure-mobile-apps.d.ts +++ b/azure-mobile-apps/azure-mobile-apps.d.ts @@ -131,7 +131,7 @@ declare module AzureMobileApps { platform?: string; basePath?: string; configFile?: string; - promiseConstructor?: (resolve: (result) => void, reject: (error) => void) => Thenable; + promiseConstructor?: (resolve: (result: any) => void, reject: (error: any) => void) => Thenable; apiRootPath?: string; tableRootPath?: string; notificationRootPath?: string; From 3bbc28476e65a6987990a3cd654fc048d200545d Mon Sep 17 00:00:00 2001 From: Dale Anderson Date: Wed, 13 Jan 2016 13:31:20 -0800 Subject: [PATCH 3/5] Fixed implicit typings --- azure-mobile-apps/azure-mobile-apps-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-mobile-apps/azure-mobile-apps-tests.ts b/azure-mobile-apps/azure-mobile-apps-tests.ts index 6ee440439..5e98e8074 100644 --- a/azure-mobile-apps/azure-mobile-apps-tests.ts +++ b/azure-mobile-apps/azure-mobile-apps-tests.ts @@ -29,7 +29,7 @@ mobileApp.use(function (req: any, res: any, next: any) { }); var table = mobileApp.table() -table.read(function (context) { +table.read(function (context: AzureMobileApps.Context) { return context.execute().then(function (result: any) { return result; }); From c78b43e26d12be1b448b3ad318f68fb2d85c4530 Mon Sep 17 00:00:00 2001 From: Dale Anderson Date: Thu, 14 Jan 2016 11:34:14 -0800 Subject: [PATCH 4/5] Added azure-sb and improved azure-mobile-apps --- azure-mobile-apps/azure-mobile-apps-tests.ts | 134 +++++---- azure-mobile-apps/azure-mobile-apps.d.ts | 275 +++++++++---------- azure-sb/azure-sb-tests.ts | 16 ++ azure-sb/azure-sb.d.ts | 168 +++++++++++ 4 files changed, 406 insertions(+), 187 deletions(-) create mode 100644 azure-sb/azure-sb-tests.ts create mode 100644 azure-sb/azure-sb.d.ts diff --git a/azure-mobile-apps/azure-mobile-apps-tests.ts b/azure-mobile-apps/azure-mobile-apps-tests.ts index 5e98e8074..093932c2f 100644 --- a/azure-mobile-apps/azure-mobile-apps-tests.ts +++ b/azure-mobile-apps/azure-mobile-apps-tests.ts @@ -1,47 +1,87 @@ -/// - -var app = require('express')(), - mobileApp = require('azure-mobile-apps')({ - debug: true, - data: { - provider: 'mssql', - server: '', - user: '', - database: '', - password: '' - } - }) - -mobileApp.tables.add('todoitem', { - authorize: true -}); - -mobileApp.api.add('customApi', { - authorize: true, - post: function (req: any, res: any, next: any) { - next(); - }, - patch: [function (req: any, res: any, next: any) {}, function (req: any, res: any, next: any) {}] -}) - -mobileApp.use(function (req: any, res: any, next: any) { - next(); -}); - -var table = mobileApp.table() -table.read(function (context: AzureMobileApps.Context) { - return context.execute().then(function (result: any) { - return result; - }); -}); - -table.use(function (req: any, res: any, next: any) { - next(new Error()); -}); - -var logger = require('azure-mobile-apps/src/logger'); -logger.silly('test', 'message'); -logger.error('Something happened', new Error()); - -var queries = require('azure-mobile-apps/src/query'); -queries.create('table').where({ x: 10 }).select('col1,col2'); \ No newline at end of file +/// + +import express = require('express'); +import mobileApps = require('azure-mobile-apps'); +import logger = require('azure-mobile-apps/src/logger'); +import queries = require('azure-mobile-apps/src/query'); + +var app = express(), + mobileApp = mobileApps(); + +// various configuration permutations +mobileApps({ + debug: true, + data: { + provider: 'mssql', + server: '', + user: '', + database: '', + password: '' + } +}); + +mobileApps({ + data: { + provider: 'memory' + } +}) + +// it would be nice to integrate with winston +mobileApps({ logging: { level: 'silly', transports: [{}] } }) + +// various custom middleware syntaxes +mobileApp.use(function (req: any, res: any, next: any) { next(); }); +mobileApp.use([function () {}, function () {}]); +mobileApp.use(function () {}, function () {}); +mobileApp.use(function () {}).use(function () {}); + +// basic syntax for tables and api +mobileApp.tables.add('todoitem'); +mobileApp.tables.add('todoitem', { authorize: true }); +mobileApp.tables.add('todoitem', mobileApps.table()); +mobileApp.tables.import('tables'); +mobileApp.api.add('api', { authorize: true, get: function () {}, delete: function () {} }); +mobileApp.api.import('api'); + +// Express.Table, instantiated from the mobile app +var table = mobileApp.table() +table.use(function (req: Express.Request, res: Express.Response, next: any) { + next(new Error()); +}); +table.use([function () {}, function () {}]); +table.read(function (context: Azure.MobileApps.Context) { + context.query.where({ p1: 'test' }); + return context.execute() + .then(function (result: any) { + return result; + }) + .catch(function (error: any) { }) + .then(function () {}); +}); +table.insert(function (context: Azure.MobileApps.Context) { + context.query.id = 'anotherId'; + context.query.single = true; + context.item.userId = context.user.id; + context.push.send('tag', {}, function (error, result) {}); + context.push.gcm.send('tag', {}, function (error, result) {}); + context.push.apns.send('tag', { payload: { } }, function (error, result) {}); + context.push.wns.sendToastText01('tag', '', { headers: { } }, function (error, result) {}); +}); +table.read.use(function () {}); +table.read.use([function () {}, function () {}]); +table.read.use(function () {}, function () {}); +table.use(function () {}).use(function () {}).read(function () {}).use(function () {}) + +// Express.Table, instantiated from the static require('azure-mobile-apps').table() +// This is going to be interesting if we ever support more than one provider +var table2 = mobileApps.table(); +table2.read(function (context: Azure.MobileApps.Context) {}) + +// Logger +logger.silly('test', 'message'); +logger.error('Something happened', new Error()); +mobileApps.logger.debug('a debug message') + +// Query +queries.create('table').where({ x: 10 }).select('col1,col2'); +mobileApps.query.create('table'); \ No newline at end of file diff --git a/azure-mobile-apps/azure-mobile-apps.d.ts b/azure-mobile-apps/azure-mobile-apps.d.ts index b6b7d49e7..5441515fe 100644 --- a/azure-mobile-apps/azure-mobile-apps.d.ts +++ b/azure-mobile-apps/azure-mobile-apps.d.ts @@ -4,112 +4,95 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// +/// declare module "azure-mobile-apps" { - function returnedFunction(configuration?: AzureMobileApps.Configuration): AzureMobileApps.ExpressMobileApp; - module returnedFunction { } - export = returnedFunction; -} + interface AzureMobileApps { + (configuration?: Azure.MobileApps.Configuration): Azure.MobileApps.Platforms.Express.MobileApp; + table(): Azure.MobileApps.Platforms.Express.Table; + logger: Azure.MobileApps.Logger; + query: Azure.MobileApps.Query; + } -declare module "azure-mobile-apps/src/express" { - function returnedFunction(configuration: AzureMobileApps.Configuration): AzureMobileApps.ExpressMobileApp; - module returnedFunction { } - export = returnedFunction; + var out: AzureMobileApps; + export = out; } - -declare module "azure-mobile-apps/src/express/api" { - function returnedFunction(configuration: AzureMobileApps.Configuration): AzureMobileApps.ExpressApi; - module returnedFunction { } - export = returnedFunction; -} - -declare module "azure-mobile-apps/src/express/table" { - function returnedFunction(definition: AzureMobileApps.TableDefinition): AzureMobileApps.ExpressTable; - module returnedFunction { } - export = returnedFunction; -} - -declare module "azure-mobile-apps/src/express/tables" { - function returnedFunction(configuration: AzureMobileApps.Configuration): AzureMobileApps.ExpressTables; - module returnedFunction { } - export = returnedFunction; -} - -declare module "azure-mobile-apps/src/auth" { - function returnedFunction(configuration: AzureMobileApps.Configuration): AzureMobileApps.Auth; - module returnedFunction { } - export = returnedFunction; -} - -declare module "azure-mobile-apps/src/data" { - function returnedFunction(configuration: AzureMobileApps.Configuration): (table: AzureMobileApps.ExpressTable) => AzureMobileApps.Data; - module returnedFunction { } - export = returnedFunction; -} - declare module "azure-mobile-apps/src/logger" { - var logger: AzureMobileApps.Logger; + var logger: Azure.MobileApps.Logger; export = logger; } declare module "azure-mobile-apps/src/query" { - var query: AzureMobileApps.Query; + var query: Azure.MobileApps.Query; export = query; } -declare module AzureMobileApps { - // express - interface ExpressMobileApp { - configuration: Configuration; - tables: ExpressTables; - table(): ExpressTable; - api: ExpressApi; - use(middleware: Middleware | Middleware[]): void; +declare module Azure.MobileApps { + // the additional Platforms namespace is required to avoid collisions with the main Express namespace + export module Platforms { + export module Express { + interface MobileApp { + configuration: Configuration; + tables: Tables; + table(): Table; + api: Api; + use(...middleware: Middleware[]): MobileApp; + use(middleware: Middleware[]): MobileApp; + } + + interface Api { + add(name: string, definition: ApiDefinition): void; + import(fileOrFolder: string): void; + } + + interface Table { + authorize?: boolean; + autoIncrement?: boolean; + dynamicSchema?: boolean; + name: string; + columns?: any; + schema: string; + + use(...middleware: Middleware[]): Table; + use(middleware: Middleware[]): Table; + read: TableOperation; + update: TableOperation; + insert: TableOperation; + delete: TableOperation; + undelete: TableOperation; + } + + interface TableOperation { + (operationHandler: (context: Context) => void): Table; + use(...middleware: Middleware[]): Table; + use(middleware: Middleware[]): Table; + } + + interface Tables { + configuration: Configuration; + add(name: string, definition?: Table | TableDefinition): void; + import(fileOrFolder: string): void; + initialize(): Thenable; + } + } } - interface ExpressApi { - add(name: string, definition: ApiDefinition): void; - import(fileOrFolder: string): void; - } + export module Data { + interface Table { + read(query: QueryJs): Thenable; + update(item: any, query: QueryJs): Thenable; + insert(item: any): Thenable; + delete(query: QueryJs, version: string): Thenable; + undelete(query: QueryJs, version: string): Thenable; + truncate(): Thenable; + initialize(): Thenable; + schema(): Thenable; + } - interface ExpressTable { - authorize?: boolean; - autoIncrement?: boolean; - dynamicSchema?: boolean; - name: string; - columns?: any; - schema: string; - - use(middleware: Middleware | Middleware[]): void; - read(operationHandler: (context: Context) => void): void; - update(operationHandler: (context: Context) => void): void; - insert(operationHandler: (context: Context) => void): void; - delete(operationHandler: (context: Context) => void): void; - undelete(operationHandler: (context: Context) => void): void; - } - - interface ExpressTables { - configuration: Configuration; - add(name: string, definition: ExpressTable | TableDefinition): void; - import(fileOrFolder: string): void; - initialize(): Thenable; - } - - // data - interface Data { - read(query: QueryJs): Thenable; - update(item: any, query: QueryJs): Thenable; - insert(item: any): Thenable; - delete(query: QueryJs, version: string): Thenable; - undelete(query: QueryJs, version: string): Thenable; - truncate(): Thenable; - initialize(): Thenable; - schema(): Thenable; - } - - interface SchemaResult { - name: string; - type: string; + interface Column { + name: string; + type: string; + } } // auth @@ -144,53 +127,53 @@ declare module AzureMobileApps { swagger?: boolean; maxTop?: number; pageSize?: number; - logging?: LoggingConfiguration; - data?: MssqlDataConfiguration; - auth?: AuthConfiguration; - cors?: CorsConfiguration; - notifications?: NotificationsConfiguration; + logging?: Configuration.Logging; + data?: Configuration.Data; + auth?: Configuration.Auth; + cors?: Configuration.Cors; + notifications?: Configuration.Notifications; } + + export module Configuration { + // it would be nice to have the config for various providers in separate interfaces, + // but this is the simplest solution to support variations of the current setup + interface Data { + provider: string; + user?: string; + password?: string; + server?: string; + port?: number; + database?: string; + connectionTimeout?: string; + options?: { encrypt: boolean }; + schema?: string; + dynamicSchema?: boolean; + } - interface DataConfiguration { - provider?: string; - } + interface Auth { + secret: string; + validateTokens?: boolean; + } - interface MssqlDataConfiguration { - provider: string; - user: string; - password: string; - server: string; - port?: number; - database: string; - connectionTimeout?: string; - options?: { encrypt: boolean }; - schema?: string; - dynamicSchema?: boolean; - } + interface Logging { + level?: string; + transports?: LoggingTransport[]; + } - interface AuthConfiguration { - secret: string; - validateTokens?: boolean; - } + interface LoggingTransport { } - interface LoggingConfiguration { - level?: string; - transports?: LoggingTransport[]; - } + interface Cors { + maxAge?: number; + origins: string[]; + } - interface LoggingTransport { } - - interface CorsConfiguration { - maxAge?: number; - origins: string[]; - } - - interface NotificationsConfiguration { - hubName: string; - connectionString?: string; - endpoint?: string; - sharedAccessKeyName?: string; - sharedAccessKeyValue?: string; + interface Notifications { + hubName: string; + connectionString?: string; + endpoint?: string; + sharedAccessKeyName?: string; + sharedAccessKeyValue?: string; + } } // query @@ -208,6 +191,9 @@ declare module AzureMobileApps { skip(count: number): QueryJs; take(count: number): QueryJs; where(filter: any): QueryJs; + // these are properties added by the SDK + id?: string | number; + single?: boolean; } interface OData { @@ -221,22 +207,18 @@ declare module AzureMobileApps { includeTotalCount?: boolean; } - // notifications - interface NotificationHubService { - - } - // general + var nh: Azure.ServiceBus.NotificationHubService; interface Context { query: QueryJs; id: string | number; item: any; req: Express.Request; res: Express.Response; - data: (table: TableDefinition) => Data; - tables: (tableName: string) => Data; + data: (table: TableDefinition) => Data.Table; + tables: (tableName: string) => Data.Table; user: User; - push: NotificationHubService; + push: typeof nh; logger: Logger; execute(): Thenable; } @@ -262,6 +244,8 @@ declare module AzureMobileApps { interface Thenable { then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => U | Thenable): Thenable; then(onFulfilled?: (value: R) => U | Thenable, onRejected?: (error: any) => void): Thenable; + catch(onRejected?: (error: any) => U | Thenable): Thenable; + catch(onRejected?: (error: any) => void): Thenable; } interface Logger { @@ -281,4 +265,15 @@ declare module AzureMobileApps { interface NextMiddleware { (error?: any): void; } +} + +// additions to the Express modules +declare module Express { + interface Request { + azureMobile: Azure.MobileApps.Context + } + + interface Response { + results?: any; + } } \ No newline at end of file diff --git a/azure-sb/azure-sb-tests.ts b/azure-sb/azure-sb-tests.ts new file mode 100644 index 000000000..508685181 --- /dev/null +++ b/azure-sb/azure-sb-tests.ts @@ -0,0 +1,16 @@ +/// + +var nh = new Azure.ServiceBus.NotificationHubService(); +nh.send('tag', '', function (error, result) {}); +nh.send('tag', '', { headers: {} }, function (error, result) {}); + +nh.apns.send('tag', { payload: { } }, function (error, result) {}); +nh.apns.send(['tag'], { payload: { } }, function (error, result) {}); +nh.gcm.send('tag', { }, function (error, result) {}); +nh.gcm.send(['tag'], { }, function (error, result) {}); +nh.wns.send('tag', '', 'wns/toast', function (error, result) {}); +nh.wns.send(['tag'], '', 'wns/toast', function (error, result) {}); +nh.wns.send('tag', '', 'wns/toast', { headers: {} }, function (error, result) {}); +nh.wns.sendToastText01('tag', '', function (error, result) {}); +nh.wns.sendToastText01(['tag'], '', function (error, result) {}); +nh.wns.sendToastText01('tag', '', { headers: {} }, function (error, result) {}); \ No newline at end of file diff --git a/azure-sb/azure-sb.d.ts b/azure-sb/azure-sb.d.ts new file mode 100644 index 000000000..3e9fdc974 --- /dev/null +++ b/azure-sb/azure-sb.d.ts @@ -0,0 +1,168 @@ +declare module Azure.ServiceBus { + interface Callback { + (error: any, response: any): void; + } + + interface NotificationHubRegistration { + RegistrationId: string; + ChannelUri?: string; + DeviceToken?: string; + gcmRegistrationId?: string; + Tags?: string; + BodyTemplate?: any; + WnsHeaders?: any; + MpnsHeaders?: any; + Expiry?: Date; + } + + export class NotificationHubService { + new(hubName: string, endpointOrConnectionString: string, sharedAccessKeyName?: string, sharedAccessKeyValue?: string): NotificationHubService; + hubName: string; + wns: Wns.Service; + apns: Apns.Service; + gcm: Gcm.Service; + mpns: Mpns.Service; + send(tags: string, payload: Object | string, optionsOrCallback?: { headers: Object } | Callback, callback?: Callback): void; + + createOrUpdateInstallation(installation: string, options: any, callback?: Callback): void; + patchInstallation(installationId: string, partialUpdateOperations: any[], options: any, callback?: Callback): void; + deleteInstallation(installationId: string, options: any, callback?: Callback): void; + getInstallation(installationId: string, options: any, callback?: Callback): void; + + /* + // old school? + createRegistrationId(callback?: Callback): void; + getRegistration(registrationId: string, options: any, callback?: Callback): void; + deleteRegistration(registrationId: string, options?: { etag: any }, callback?: Callback): void; + updateRegistration(registration: NotificationHubRegistration, options?: { etag: any }, callback?: Callback): void; + createOrUpdateRegistration(registration: NotificationHubRegistration, options?: { etag: any }, callback?: Callback): void; + listRegistrations(options?: { top: number, skip: number }, callback?: Callback): void; + listRegistrationsByTag(tag: string, options?: { top: number, skip: number }, callback?: Callback): void; + */ + } + + export module Apns { + interface Payload { + expiry?: Date; + aps?: Object; + badge?: number; + alert?: string; + sound?: string; + payload: Object; + } + + interface Service { + new(service: NotificationHubService): Service; + send(tags: string | string[], payload: Apns.Payload, callback?: Callback): void; + createNativeRegistration(token: string, tags: string | string[], optionsOrCallback?: Object | Callback, callback?: Callback): void; + createOrUpdateNativeRegistration(registrationId: string, token: string, tags: string | string[], optionsOrCallback?: Object | Callback, callback?: Callback): void; + createTemplateRegistration(token: string, tags: string | string[], template: Apns.Payload, optionsOrCallback?: Object | Callback, callback?: Callback): void; + createOrUpdateTemplateRegistration(registrationId: string, token: string, tags: string | string[], template: Apns.Payload, optionsOrCallback?: Object | Callback, callback?: Callback): void; + updateTemplateRegistration(registrationId: string, token: string, tags: string | string[], template: Apns.Payload, optionsOrCallback?: Object | Callback, callback?: Callback): void; + listRegistrationsByToken(token: string, optionsOrCallback?: { top: number, skip: number } | Callback, callback?: Callback): void; + } + } + export module Gcm { + interface Service { + new(service: NotificationHubService): Service; + send(tags: string | string[], payload: any, callback?: Callback): void; + createNativeRegistration(gcmRegistrationId: string, tags: string | string[], optionsOrCallback?: Object | Callback, callback?: Callback): void; + createOrUpdateNativeRegistration(registrationId: string, gcmRegistrationId: string, tags: string | string[], optionsOrCallback?: Object | Callback, callback?: Callback): void; + createTemplateRegistration(gcmRegistrationId: string, tags: string | string[], template: any, optionsOrCallback?: Object | Callback, callback?: Callback): void; + createOrUpdateTemplateRegistration(registrationId: string, gcmRegistrationId: string, tags: string | string[], template: any, optionsOrCallback?: Object | Callback, callback?: Callback): void; + updateTemplateRegistration(registrationId: string, gcmRegistrationId: string, tags: string | string[], template: any, optionsOrCallback?: Object | Callback, callback?: Callback): void; + listRegistrationsByGcmRegistrationId(gcmRegistrationId: string, optionsOrCallback?: { top: number, skip: number } | Callback, callback?: Callback): void; + } + } + + export module Mpns { interface Service { } } + + export module Wns { + interface Payload { + text1?: string; + text2?: string; + text3?: string; + text4?: string; + image1src?: string; + image1alt?: string; + image2src?: string; + image2alt?: string; + image3src?: string; + image3alt?: string; + image4src?: string; + image4alt?: string; + lang?: string; + type?: string; + } + + interface Options { + headers: Object; + } + + interface Service { + new(service: NotificationHubService): Service; + sendTileSquareBlock(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileSquareText01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileSquareText02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileSquareText03(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileSquareText04(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText03(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText04(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText05(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText06(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText07(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText08(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText09(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText10(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideText11(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileSquareImage(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileSquarePeekImageAndText01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileSquarePeekImageAndText02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileSquarePeekImageAndText03(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileSquarePeekImageAndText04(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideImage(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideImageCollection(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideImageAndText01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideImageAndText02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideBlockAndText01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideBlockAndText02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideSmallImageAndText01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideSmallImageAndText02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideSmallImageAndText03(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideSmallImageAndText04(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWideSmallImageAndText05(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImageCollection01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImageCollection02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImageCollection03(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImageCollection04(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImageCollection05(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImageCollection06(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImageAndText01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImageAndText02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImage01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImage02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImage03(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImage04(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImage05(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendTileWidePeekImage06(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendToastText01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendToastText02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendToastText03(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendToastText04(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendToastImageAndText01(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendToastImageAndText02(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendToastImageAndText03(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendToastImageAndText04(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + // badges = ['none','activity','alert','available','away','busy','newMessage','paused','playing','unavailable','error', 'attention'] + sendBadge(tags: string | string[], value: string | number, optionsOrCallback?: Options | Callback, callback?: Callback): void; + sendRaw(tags: string | string[], payload: any, optionsOrCallback?: Options | Callback, callback?: Callback): void; + // types = ['wns/toast', 'wns/badge', 'wns/tile', 'wns/raw'] + send(tags: string | string[], payload: string, type: string, optionsOrCallback?: Options | Callback, callback?: Callback): void; + createNativeRegistration(channel: string, tags: string | string[], optionsOrCallback?: Options | Callback, callback?: Callback): void; + createOrUpdateNativeRegistration(registrationId: string, channel: string, tags: string | string[], optionsOrCallback?: Options | Callback, callback?: Callback): void; + listRegistrationsByChannel(channel: string, optionsOrCallback?: { top: number, skip: number } | Callback, callback?: Callback): void; + } + } +} \ No newline at end of file From 9ce2ea8991020d1f10a049f1e9c9e111e996f02d Mon Sep 17 00:00:00 2001 From: Dale Anderson Date: Thu, 14 Jan 2016 11:40:11 -0800 Subject: [PATCH 5/5] Added header --- azure-sb/azure-sb.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/azure-sb/azure-sb.d.ts b/azure-sb/azure-sb.d.ts index 3e9fdc974..afa4074a9 100644 --- a/azure-sb/azure-sb.d.ts +++ b/azure-sb/azure-sb.d.ts @@ -1,3 +1,8 @@ +// Type definitions for azure-sb +// Project: https://github.com/Azure/azure-sdk-for-node/tree/master/lib/services/serviceBus +// Definitions by: Microsoft Azure +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + declare module Azure.ServiceBus { interface Callback { (error: any, response: any): void;