From dfb310d80e2562c1af2b717fa37da8230e300317 Mon Sep 17 00:00:00 2001 From: Dale Anderson Date: Wed, 13 Jan 2016 13:23:50 -0800 Subject: [PATCH] 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