From 4306205fa5e796dbfe7f00322a4a49b64779b67d Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sat, 30 Mar 2013 20:55:00 -0500 Subject: [PATCH 1/5] Basic commit for azure. --- azure/azure-tests.ts | 6 ++ azure/azure.d.ts | 193 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 199 insertions(+) create mode 100644 azure/azure-tests.ts create mode 100644 azure/azure.d.ts diff --git a/azure/azure-tests.ts b/azure/azure-tests.ts new file mode 100644 index 000000000..a0f701855 --- /dev/null +++ b/azure/azure-tests.ts @@ -0,0 +1,6 @@ +/// + + +import azure = module("azure"); + +var ts = new azure.TableService("asdf"); \ No newline at end of file diff --git a/azure/azure.d.ts b/azure/azure.d.ts new file mode 100644 index 000000000..cd23f0b81 --- /dev/null +++ b/azure/azure.d.ts @@ -0,0 +1,193 @@ +// Type definitions for Azure SDK for Node - v0.6.10 +// Project: https://github.com/WindowsAzure/azure-sdk-for-node +// Definitions by: Andrew Gaspar +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/** +* TODO +*/ +declare module "azure" { + //#region Services + export class TableService extends ServiceClient { + static incorrectTableNameErr: string; + static incorrectCallbackErr: string; + static incorrectTableQuery: string; + static incorrectPartitionErr: string; + + /** + * Creates a new TableService object. + * Uses the AZURE_STORAGE_ACCOUNT and AZURE_STORAGE_ACCESS_KEY environment variables. + * + * @constructor + * @extends {ServiceClient} + */ + constructor(); + /** + * Creates a new TableService object. + * Uses a connectionString to connect + * + * @constructor + * @extends {ServiceClient} + * @param {string} connectionString The connection string. + */ + constructor(connectionString: string); + /** + * Creates a new TableService object. + * Uses a storage account and an access key. + * + * @constructor + * @extends {ServiceClient} + * @param {string} storageAccount The storage account or the connection string. + * @param {string} storageAccessKey The storage access key. + * @param {string} host The host address. + * @param {object} authenticationProvider The authentication provider. + */ + constructor(storageAccount: string, storageAccessKey: string, host?: string, authenticationProvider?: string); + + public getServiceProperties(callback: (error, servicePropertiesResult, response) => void ): void; + public getServiceProperties(options, callback: (error, servicePropertiesResult, response) => void ): void; + } + + export class BlobService { + + } + + export class QueueService { + + } + + export class ServiceBusService { + + } + + export class SqlService { + + } + + export class ServiceManagementService { + + } + + export class SqlManagementService { + } + //#endregion + //#region Service Creators + export function createTableService(): TableService; + export function createTableService(connectionString: string): TableService; + export function createTableService(storageAccount: string, storageAccessKey: string, host?: string, authenticationProvider?: string): TableService; + + export function createBlobService(): BlobService; + export function createBlobService(connectionString: string): BlobService; + export function createBlobService(storageAccount: string, storageAccessKey: string, host?: string, authenticationProvider?: string): BlobService; + + export function createQueueService(): QueueService; + export function createQueueService(connectionString: string): QueueService; + export function createQueueService(storageAccount: string, storageAccessKey: string, host?: string, authenticationProvider?: string): QueueService; + + export function createServiceBusService(): ServiceBusService; + export function createServiceBusService(connectionString: string): ServiceBusService; + export function createServiceBusService(namespace: string, accessKey?: string, issuer?: string, acsNamespace?: string, host?: string, authenticationProvider?: string): ServiceBusService; + + export function createSqlService(serverName: string, administratorLogin: string, administratorLoginPassword: string, host?: string, acsHost?: string, authenticationProvider?: string): SqlService; + + export function createServiceManagementService(subscriptionId: string, authentication: string, hostOptions: string): ServiceManagementService; + + export function createSqlManagementService(subscriptionId: string, authentication: string, hostOptions: string): SqlManagementService; + //#endregion + + export module RoleEnvironment { + + } + + //#region Helpers + export class WebResource { + + } + + export class ServiceClient { + + } + + export class ServiceManagementClient { + + } + + export class TableQuery { + + } + + export class BatchServiceClient { + + } + + export module Constants { + + } + + export class LinearRetryPolicyFilter { + + } + + export class ExponentialRetryPolicyFilter { + + } + + export class SharedAccessSignature { + + } + + export class SharedKey { + + } + + export class SharedKeyLite { + + } + + export class SharedKeyTable { + + } + + export class SharedKeyLiteTable { + + } + + export module ISO8061Date { + + } + + export class Logger { + + } + + export class ConnectionStringParser { + + } + + export module ServiceSettings { + + } + + export class StorageServiceSettings { + + } + + export class ServiceBusSettings { + + } + + export class ServiceManagementSettinsg { + + } + + export module Validate { + + } + + export module date { + + } + //#endregion + + export function isEmulated(): bool; +} \ No newline at end of file From 9c35a4251404f2182b889fb029d8cd469a677e54 Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sun, 31 Mar 2013 02:08:09 -0500 Subject: [PATCH 2/5] Updated events module to include exported EventEmitter CLASS so it can be extended, like in the Azure library. --- azure/azure.d.ts | 68 +++++++++++++++++++++++++++++++++++++++++++++--- node/node.d.ts | 11 +++++++- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/azure/azure.d.ts b/azure/azure.d.ts index cd23f0b81..8d6c6ce8d 100644 --- a/azure/azure.d.ts +++ b/azure/azure.d.ts @@ -3,12 +3,16 @@ // Definitions by: Andrew Gaspar // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + +import events = module("events"); + /** * TODO */ declare module "azure" { //#region Services - export class TableService extends ServiceClient { + export class TableService extends BatchServiceClient { static incorrectTableNameErr: string; static incorrectCallbackErr: string; static incorrectTableQuery: string; @@ -99,13 +103,39 @@ declare module "azure" { } - //#region Helpers + //#region Export of internal classes export class WebResource { } - export class ServiceClient { + export class ServiceClient extends events.EventEmitter { + static EnvironmentVariables; + static DEVSTORE_STORAGE_ACCOUNT: string; + static DEVSTORE_STORAGE_ACCESS_KEY: string; + static DEVSTORE_BLOB_HOST: string; + static DEVSTORE_QUEUE_HOST: string; + static DEVSTORE_TABLE_HOST: string; + static CLOUD_BLOB_HOST: string; + static CLOUD_QUEUE_HOST: string; + static CLOUD_TABLE_HOST: string; + static CLOUD_SERVICEBUS_HOST: string; + static CLOUD_ACCESS_CONTROL_HOST: string; + static CLOUD_SERVICE_MANAGEMENT_HOST: string; + static CLOUD_DATABASE_HOST: string; + static DEFAULT_SERVICEBUS_ISSUER: string; + static DEFAULT_WRAP_NAMESPACE_SUFFIX: string; + static DEFAULT_PROTOCOL: string; + constructor(host: string, authenticationProvider); + + setHost(host: string): void; + performRequest(webResource: WebResource, outputData: string, options, callback: Function): void; + performRequestOutputStream(webResource: WebResource, outputStream, options, callback: Function): void; + performRequestInputStream(webResource: WebResource, outputData: string, inputStream, options, callback: Function): void; + withFilter(newFilter: { handle: (requestOptions, next: Function) => void; }): ServiceClient; + parseMetadataHeaders(headers): any; + isEmulated(): bool; + setProxy(proxyUrl: string, proxyPort: number): void; } export class ServiceManagementClient { @@ -116,8 +146,19 @@ declare module "azure" { } - export class BatchServiceClient { + export class BatchServiceClient extends StorageServiceClient { + operations: any[]; + constructor(storageAccount: string, storageAccessKey: string, host: string, usePathstyleUri: bool, authenticationProvider); + beginBatch(): void; + isInBatch(): bool; + rollback(): void; + hasOperations(): bool; + addOperation(webResource: WebResource, outputData): void; + commitBatch(callback: (error, operationResponses: any[], response) => void ): void; + commitBatch(options, callback: (error, operationResponses: any[], response) => void ): void; + processResponse(responseObject, requestOperations: any[]): any[]; + processOperation(webResource: WebResource, rawResponse: string): any; } export module Constants { @@ -189,5 +230,24 @@ declare module "azure" { } //#endregion + //#region Un-exported internal classes + class StorageServiceClient extends ServiceClient { + static incorrectStorageAccountErr: string; + static incorrectStorageAccessKeyErr: string; + static getStorageSettings(connectionString: string); + static getStorageSettings(storageAccount?: string, storageAccessKey?: string, host?: string): StorageServiceSettings; + private static _getStorageSettingsExplicitOrEnvironment(storageAccount?: string, storageAccessKey?: string, host?: string): StorageServiceSettings; + + apiVersion: string; + usePathStyleUri: string; + + constructor(storageAccount: string, storageAccessKey: string, host: string, usePathStyleUri: bool, authenticationProvider); + + private _buildRequestOptions(webResource: WebResource, options, callback: (error, requestOptions) => void ); + private _getPath(path: string): string; + private _setAccountCredentials(storageAccount: string, storageAccessKey: string): void; + } + //#endregion + export function isEmulated(): bool; } \ No newline at end of file diff --git a/node/node.d.ts b/node/node.d.ts index 10ba918c2..efee852cc 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -225,7 +225,16 @@ declare module "events" { emit(event: string, arg1?: any, arg2?: any): void; } - export var EventEmitter: NodeEventEmitter; + export class EventEmitter implements NodeEventEmitter { + addListener(event: string, listener: Function); + on(event: string, listener: Function): any; + once(event: string, listener: Function): void; + removeListener(event: string, listener: Function): void; + removeAllListener(event: string): void; + setMaxListeners(n: number): void; + listeners(event: string): { Function; }[]; + emit(event: string, arg1?: any, arg2?: any): void; + } } declare module "http" { From 4cf381e5b05ebb4ac9c7a21ebc64c9b3b09c76aa Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sun, 31 Mar 2013 05:21:04 -0500 Subject: [PATCH 3/5] Initial commit for azure node.js typescript definitions. --- azure/azure-tests.ts | 11 +++- azure/azure.d.ts | 129 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 129 insertions(+), 11 deletions(-) diff --git a/azure/azure-tests.ts b/azure/azure-tests.ts index a0f701855..6a3a7da74 100644 --- a/azure/azure-tests.ts +++ b/azure/azure-tests.ts @@ -1,6 +1,13 @@ /// -import azure = module("azure"); +import Azure = module("azure"); -var ts = new azure.TableService("asdf"); \ No newline at end of file +var ts = new Azure.TableService(); + +ts.createTable("babbsies", function (error, table) { + ts.insertEntity(table.TableName, { PartitionKey: "Midwest", RowKey: "1", Name: "Tommy", Color: "Blue" }, + function () { + ts.deleteEntity(table.TableName, { PartitionKey: "Midwest", RowKey: "1" }); + }); +}); \ No newline at end of file diff --git a/azure/azure.d.ts b/azure/azure.d.ts index 8d6c6ce8d..ec8296f51 100644 --- a/azure/azure.d.ts +++ b/azure/azure.d.ts @@ -5,12 +5,12 @@ /// -import events = module("events"); - /** * TODO */ declare module "azure" { + import events = module("events"); + //#region Services export class TableService extends BatchServiceClient { static incorrectTableNameErr: string; @@ -48,8 +48,49 @@ declare module "azure" { */ constructor(storageAccount: string, storageAccessKey: string, host?: string, authenticationProvider?: string); - public getServiceProperties(callback: (error, servicePropertiesResult, response) => void ): void; - public getServiceProperties(options, callback: (error, servicePropertiesResult, response) => void ): void; + getServiceProperties(callback?: (error, servicePropertiesResult, response) => void ): void; + getServiceProperties(options: TimeoutIntervalOptions, callback?: (error, servicePropertiesResult, response) => void ): void; + + setServiceProperties(serviceProperties: any, options: TimeoutIntervalOptions, callback?: Function): void; + + getTable(table: string, callback?: TableRequestCallback ): void; + getTable(table: string, options: TimeoutIntervalOptions, callback?: TableRequestCallback ): void; + + createTable(table: string, callback?: TableRequestCallback ): void; + createTable(table: string, options: TimeoutIntervalOptions, callback?: TableRequestCallback ): void; + + createTableIfNotExists(table: string, callback?: CreateTableIfNotExistsCallback ): void; + createTableIfNotExists(table: string, options: TimeoutIntervalOptions, callback?: CreateTableIfNotExistsCallback): void; + + deleteTable(table: string, callback?: DeleteTableCallback ): void; + deleteTable(table: string, options: TimeoutIntervalOptions, callback?: DeleteTableCallback ): void; + + queryTables(callback?: QueryTablesCallback ): void; + queryTables(options: QueryTablesOptions, callback?: QueryTablesCallback ): void; + + queryEntity(table: string, partitionKey: string, rowKey: string, callback?: QueryEntityCallback ): void; + queryEntity(table: string, partitionKey: string, rowKey: string, options: TimeoutIntervalOptions, callback?: QueryEntityCallback ): void; + + queryEntities(tableQuery: TableQuery, callback?: QueryEntitiesCallback): void; + queryEntities(tableQuery: TableQuery, options: TimeoutIntervalOptions, callback?: QueryEntitiesCallback): void; + + insertEntity(tableName: string, entityDescriptor: Entity, callback?: ModifyEntityCallback): void; + insertEntity(tableName: string, entityDescriptor: Entity, options: TimeoutIntervalOptions, callback?: ModifyEntityCallback): void; + + insertOrReplaceEntity(tableName: string, entityDescriptor: Entity, callback?: ModifyEntityCallback): void; + insertOrReplaceEntity(tableName: string, entityDescriptor: Entity, options: TimeoutIntervalOptions, callback?: ModifyEntityCallback): void; + + updateEntity(tableName: string, entityDescriptor: Entity, callback?: ModifyEntityCallback): void; + updateEntity(tableName: string, entityDescriptor: Entity, options: UpdateEntityOptions, callback?: ModifyEntityCallback): void; + + mergeEntity(tableName: string, entityDescriptor: Entity, callback?: ModifyEntityCallback): void; + mergeEntity(tableName: string, entityDescriptor: Entity, options: UpdateEntityOptions, callback?: ModifyEntityCallback): void; + + insertOrMergeEntity(tableName: string, entityDescriptor: Entity, callback?: ModifyEntityCallback): void; + insertOrMergeEntity(tableName: string, entityDescriptor: Entity, options: UpdateEntityOptions, callback?: ModifyEntityCallback): void; + + deleteEntity(tableName: string, entityDescriptor: Entity, callback?: DeleteEntityCallback): void; + deleteEntity(tableName: string, entityDescriptor: Entity, options: UpdateEntityOptions, callback?: DeleteEntityCallback): void; } export class BlobService { @@ -230,22 +271,92 @@ declare module "azure" { } //#endregion + //#region Non-explicit, undeclared interfaces + export interface WebResponse { + isSuccessful: bool; + statusCode: number; + body: { entry: { id: string; title; updated: string; author: { name; }; link; category; content; }; }; + headers; + md5; + } + + export interface TimeoutIntervalOptions { + timeoutIntervalInMs?: number; + } + + ///#region TableService Callbacks + export interface TableRequestCallback { + (error: Error, tableResult: { TableName: string; }, response: WebResponse): void; + } + + export interface CreateTableIfNotExistsCallback { + (error: Error, created: bool, response: WebResponse): void; + } + + export interface DeleteTableCallback { + (error: Error, successful: bool, response: WebResponse): void; + } + + export interface QueryTablesCallback { + (error: Error, queryTablesResult: TableResult[], resultsContinuation: QueryResultContinuation, response: WebResponse): void; + } + + export interface QueryResultContinuation { + tableService: TableService; + } + + export interface QueryTablesOptions extends TimeoutIntervalOptions { + nextTableName?: string; + } + + export interface TableResult { + TableName: string; + } + + export interface QueryEntityCallback { + (error: Error, entity: Entity, response: WebResponse): void; + } + + export interface QueryEntitiesCallback { + (error: Error, entities: Entity[], resultContinuation: QueryEntitiesResultContinuation, response: WebResponse): void; + } + + export interface QueryEntitiesResultContinuation extends QueryResultContinuation { + tableQuery: TableQuery; + } + + export interface ModifyEntityCallback { + (error: Error, entity: Entity, response: WebResponse): void; + } + + export interface DeleteEntityCallback { + (error: Error, successful: bool, response: WebResponse): void; + } + + export interface UpdateEntityOptions extends TimeoutIntervalOptions { + checkEtag?: bool; + } + + export interface Entity { + PartitionKey: string; + RowKey: string; + Timestamp?: Date; + etag?: string; + } + //#endregion + //#endregion + //#region Un-exported internal classes class StorageServiceClient extends ServiceClient { static incorrectStorageAccountErr: string; static incorrectStorageAccessKeyErr: string; static getStorageSettings(connectionString: string); static getStorageSettings(storageAccount?: string, storageAccessKey?: string, host?: string): StorageServiceSettings; - private static _getStorageSettingsExplicitOrEnvironment(storageAccount?: string, storageAccessKey?: string, host?: string): StorageServiceSettings; apiVersion: string; usePathStyleUri: string; constructor(storageAccount: string, storageAccessKey: string, host: string, usePathStyleUri: bool, authenticationProvider); - - private _buildRequestOptions(webResource: WebResource, options, callback: (error, requestOptions) => void ); - private _getPath(path: string): string; - private _setAccountCredentials(storageAccount: string, storageAccessKey: string): void; } //#endregion From a3506050025457740438b81726de2bbcebda3222 Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sun, 31 Mar 2013 05:26:08 -0500 Subject: [PATCH 4/5] Added test for EventEmitter class. --- node/node-tests.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/node/node-tests.ts b/node/node-tests.ts index 00e08b006..3e791405b 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -2,6 +2,7 @@ import assert = module("assert"); import fs = module("fs"); +import events = module("events"); assert(1 + 1 - 2 === 0, "The universe isn't how it should."); @@ -27,4 +28,12 @@ fs.writeFile("Harry Potter", { encoding: "ascii" }, - assert.ifError); \ No newline at end of file + assert.ifError); + +class Networker extends events.EventEmitter { + constructor() { + super(); + + this.emit("mingling"); + } +} \ No newline at end of file From 7466cd710e4bd7542e909a3b0fe0f8f2fc3cba0b Mon Sep 17 00:00:00 2001 From: Andrew Gaspar Date: Sun, 31 Mar 2013 13:31:24 -0500 Subject: [PATCH 5/5] Moved azure to azure-node. --- {azure => node-azure}/azure-tests.ts | 0 {azure => node-azure}/azure.d.ts | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {azure => node-azure}/azure-tests.ts (100%) rename {azure => node-azure}/azure.d.ts (100%) diff --git a/azure/azure-tests.ts b/node-azure/azure-tests.ts similarity index 100% rename from azure/azure-tests.ts rename to node-azure/azure-tests.ts diff --git a/azure/azure.d.ts b/node-azure/azure.d.ts similarity index 100% rename from azure/azure.d.ts rename to node-azure/azure.d.ts