Skip to content

Commit

Permalink
Merge pull request #424 from XiaoningLiu/module
Browse files Browse the repository at this point in the history
Module Support
  • Loading branch information
vinjiang committed Mar 6, 2018
2 parents 31a9878 + e4b1fa4 commit 78a09ef
Show file tree
Hide file tree
Showing 18 changed files with 311 additions and 293 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ blobservice_test.tmp

# Browserify bundle scripts
browser/bundle
browser/test
7 changes: 7 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Note: This is an Azure Storage only package. The all up Azure node sdk still has the old storage bits in there. In a future release, those storage bits will be removed and an npm dependency to this storage node sdk will
be taken. This is a GA release and the changes described below indicate the changes from the Azure node SDK 0.9.8 available here - https://github.com/Azure/azure-sdk-for-node.

2018.03 Version 2.8.1

ALL
* Updated request and validator package dependencies to reduce vulnerability.
* Fix a type assignment bug in tests for env variables.
* Improved documents.

2018.02 Version 2.8.0

ALL
Expand Down
166 changes: 92 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Microsoft Azure Storage SDK for Node.js
# Microsoft Azure Storage SDK for Node.js and JavaScript for Browsers

[![NPM version](https://badge.fury.io/js/azure-storage.svg)](http://badge.fury.io/js/azure-storage) [![Slack](https://azurestorageslack.azurewebsites.net/badge.svg)]( https://azurestorageslack.azurewebsites.net)

* Master [![Build Status](https://travis-ci.org/Azure/azure-storage-node.svg?branch=master)](https://travis-ci.org/Azure/azure-storage-node/branches) [![Coverage Status](https://coveralls.io/repos/Azure/azure-storage-node/badge.svg?branch=master&service=github)](https://coveralls.io/github/Azure/azure-storage-node?branch=master)
* Dev [![Build Status](https://travis-ci.org/Azure/azure-storage-node.svg?branch=dev)](https://travis-ci.org/Azure/azure-storage-node/branches) [![Coverage Status](https://coveralls.io/repos/Azure/azure-storage-node/badge.svg?branch=dev&service=github)](https://coveralls.io/github/Azure/azure-storage-node?branch=dev)

This project provides a Node.js package and a browser compatible [JavaScript Client Library](#azure-storage-javascript-client-library-for-browsers) that makes it easy to consume and manage Microsoft Azure Storage Services.
This project provides a Node.js package and a browser compatible [JavaScript Client Library](https://github.com/Azure/azure-storage-node#azure-storage-javascript-client-library-for-browsers) that makes it easy to consume and manage Microsoft Azure Storage Services.

> If you are looking for the Node.js SDK for other Azure services, visit [https://github.com/Azure/azure-sdk-for-node](https://github.com/Azure/azure-sdk-for-node).
# Features

- Tables
- Create/Delete Tables
- Query/Create/Read/Update/Delete Entities
- Blobs
- Create/Delete Containers
- Create/Read/Update/Delete Blobs
- Tables
- Create/Delete Tables
- Query/Create/Read/Update/Delete Entities
- Files
- Create/Delete Shares
- Create/Delete Directories
Expand Down Expand Up @@ -51,6 +51,75 @@ When using the Storage SDK, you must provide connection information for the stor

* Constructors - For example, `var tableSvc = azure.createTableService(accountName, accountKey);`

### Blob Storage

The **createContainerIfNotExists** method can be used to create a
container in which to store a blob:

```Javascript
var azure = require('azure-storage');
var blobService = azure.createBlobService();
blobService.createContainerIfNotExists('taskcontainer', {
publicAccessLevel: 'blob'
}, function(error, result, response) {
if (!error) {
// if result = true, container was created.
// if result = false, container already existed.
}
});
```

To upload a file (assuming it is called task1-upload.txt and it is placed in the same folder as the script below), the method **createBlockBlobFromLocalFile** can be used.

```Javascript
var azure = require('azure-storage');
var blobService = azure.createBlobService();

blobService.createBlockBlobFromLocalFile('mycontainer', 'taskblob', 'task1-upload.txt', function(error, result, response) {
if (!error) {
// file uploaded
}
});
```


For page blobs, use **createPageBlobFromLocalFile**. There are other methods for uploading blobs also, such as **createBlockBlobFromText** or **createPageBlobFromStream**.

There are also several ways to download block and page blobs. For example, **getBlobToStream** downloads the blob to a stream:

```Javascript
var blobService = azure.createBlobService();
var fs = require('fs');
blobService.getBlobToStream('mycontainer', 'taskblob', fs.createWriteStream('output.txt'), function(error, result, response) {
if (!error) {
// blob retrieved
}
});
```

To create a Shared Access Signature (SAS), use the **generateSharedAccessSignature** method. Additionally you can use the **date** helper functions to easily create a SAS that expires at some point relative to the current time.

```Javascript
var azure = require('azure-storage');
var blobService = azure.createBlobService();

var startDate = new Date();
var expiryDate = new Date(startDate);
expiryDate.setMinutes(startDate.getMinutes() + 100);
startDate.setMinutes(startDate.getMinutes() - 100);

var sharedAccessPolicy = {
AccessPolicy: {
Permissions: azure.BlobUtilities.SharedAccessPermissions.READ,
Start: startDate,
Expiry: expiryDate
}
};

var token = blobService.generateSharedAccessSignature(containerName, blobName, sharedAccessPolicy);
var sasUrl = blobService.getUrl(containerName, blobName, token);
```

### Table Storage

To ensure a table exists, call **createTableIfNotExists**:
Expand All @@ -64,7 +133,7 @@ tableService.createTableIfNotExists('mytable', function(error, result, response)
}
});
```
A new entity can be added by calling **insertEntity**:
A new entity can be added by calling **insertEntity** or **insertOrReplaceEntity**:

```Javascript
var azure = require('azure-storage');
Expand Down Expand Up @@ -112,91 +181,40 @@ tableService.retrieveEntity('mytable', 'part2', 'row1', function(error, result,
});
```

Use **TableQuery** to build complex queries:
The method **replaceEntity** or **insertOrReplaceEntity** can be called to update/edit an existing entry. In the following example we asssume that an entity `'part2', 'row1'` with a field `'taskDone'` set to `false` already exists.

```Javascript
var azure = require('azure-storage');
var tableService = azure.createTableService();
var query = new azure.TableQuery()
.top(5)
.where('PartitionKey eq ?', 'part2');

tableService.queryEntities('mytable', query, null, function(error, result, response) {
if (!error) {
// result.entries contains entities matching the query
}
});
```

### Blob Storage

The **createContainerIfNotExists** method can be used to create a
container in which to store a blob:
var entity = {
PartitionKey: entGen.String('part2'),
RowKey: entGen.String('row1'),
taskDone: entGen.Boolean(true),
};

```Javascript
var azure = require('azure-storage');
var blobService = azure.createBlobService();
blobService.createContainerIfNotExists('taskcontainer', {
publicAccessLevel: 'blob'
}, function(error, result, response) {
tableService.insertOrReplaceEntity('mytable', entity, function(error, result, response) {
if (!error) {
// if result = true, container was created.
// if result = false, container already existed.
// result contains the entity with field 'taskDone' set to `true`
}
});
```

To upload a file (assuming it is called task1-upload.txt and it is placed in the same folder as the script below), the method **createBlockBlobFromLocalFile** can be used.
Use **TableQuery** to build complex queries:

```Javascript
var azure = require('azure-storage');
var blobService = azure.createBlobService();

blobService.createBlockBlobFromLocalFile('mycontainer', 'taskblob', 'task1-upload.txt', function(error, result, response) {
if (!error) {
// file uploaded
}
});
```


For page blobs, use **createPageBlobFromLocalFile**. There are other methods for uploading blobs also, such as **createBlockBlobFromText** or **createPageBlobFromStream**.
var tableService = azure.createTableService();
var query = new azure.TableQuery()
.top(5)
.where('PartitionKey eq ?', 'part2');

There are also several ways to download block and page blobs. For example, **getBlobToStream** downloads the blob to a stream:

```Javascript
var blobService = azure.createBlobService();
var fs = require('fs');
blobService.getBlobToStream('mycontainer', 'taskblob', fs.createWriteStream('output.txt'), function(error, result, response) {
tableService.queryEntities('mytable', query, null, function(error, result, response) {
if (!error) {
// blob retrieved
// result.entries contains entities matching the query
}
});
```

To create a Shared Access Signature (SAS), use the **generateSharedAccessSignature** method. Additionally you can use the **date** helper functions to easily create a SAS that expires at some point relative to the current time.

```Javascript
var azure = require('azure-storage');
var blobService = azure.createBlobService();

var startDate = new Date();
var expiryDate = new Date(startDate);
expiryDate.setMinutes(startDate.getMinutes() + 100);
startDate.setMinutes(startDate.getMinutes() - 100);

var sharedAccessPolicy = {
AccessPolicy: {
Permissions: azure.BlobUtilities.SharedAccessPermissions.READ,
Start: startDate,
Expiry: expiryDate
}
};

var token = blobService.generateSharedAccessSignature(containerName, blobName, sharedAccessPolicy);
var sasUrl = blobService.getUrl(containerName, blobName, token);
```

### Queue Storage

The **createQueueIfNotExists** method can be used to ensure a queue exists:
Expand Down Expand Up @@ -497,15 +515,15 @@ On Linux, please use `export` other than `set` to set the variables.

Azure Storage Node.js Client Library is compatible with [Browserify](http://browserify.org/). This means you can bundle your Node.js application which depends on the Node.js Client Library using Browserify.

You can also choose to download the JavaScript Client Library provided by us, or generate the library by yourself. Please refer to the [README.md](browser/README.md) under `browser` folder for detailed usage guidelines.
You can also choose to download the JavaScript Client Library provided by us, or generate the library by yourself. Please refer to the [README.md](https://github.com/Azure/azure-storage-node/blob/master/browser/README.md) under `browser` folder for detailed usage guidelines.

## Downloading Azure Storage JavaScript Client Library

It's recommended to use the Azure Storage JavaScript Client Library provided by us. Please [download the latest library](https://aka.ms/downloadazurestoragejs).

## Generating Azure Storage JavaScript Client Library

We also provide browserify bundle scripts which generate Azure Storage JavaScript Client Library. The bundle script reduces the size of the Storage Client Library by splitting into smaller files, one per storage service and a common shared file. For more detailed information, refer to [README.md](browser/README.md) under `browser` folder.
We also provide browserify bundle scripts which generate Azure Storage JavaScript Client Library. The bundle script reduces the size of the Storage Client Library by splitting into smaller files, one per storage service. For more detailed information, refer to [README.md](https://github.com/Azure/azure-storage-node/blob/master/browser/README.md) under `browser` folder.

# JsDoc

Expand Down
6 changes: 6 additions & 0 deletions browser/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Note: This is the change log file for Azure Storage JavaScript Client Library.

2018.03 Version 0.2.8-preview.15

* Supported UMD module standard.
* Dropped `azure-storage.common.js`.
* Generated browser compatible JavaScript files based on Microsoft Azure Storage SDK for Node.js 2.8.1.

2018.02 Version 0.2.8-preview.14

* Generated browser compatible JavaScript files based on Microsoft Azure Storage SDK for Node.js 2.8.0.
Expand Down
67 changes: 28 additions & 39 deletions browser/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,33 @@

* Join the community discussion on Slack! [![Slack](https://azurestorageslack.azurewebsites.net/badge.svg)]( https://azurestorageslack.azurewebsites.net)

There are 5 generated JavaScript files for Azure Storage JavaScript Client Library:
- `azure-storage.common.js` contains the common part for other 4 JavaScript files.
- `azure-storage.table.js` contains the Azure Storage table service operation logic, which depends on azure-storage.common.js
- `azure-storage.blob.js` contains the Azure Storage blob service operation logic, which depends on azure-storage.common.js
- `azure-storage.queue.js` contains the Azure Storage queue service operation logic, which depends on azure-storage.common.js
- `azure-storage.file.js` contains the Azure Storage file service operation logic, which depends on azure-storage.common.js
There are 8 generated JavaScript files for Azure Storage JavaScript Client Library:
- `azure-storage.blob.js` and `azure-storage.blob.min.js` contain the Azure Storage blob service operation logic
- `azure-storage.table.js` and `azure-storage.table.min.js` contain the Azure Storage table service operation logic
- `azure-storage.queue.js` and `azure-storage.queue.min.js` contain the Azure Storage queue service operation logic
- `azure-storage.file.js` and `azure-storage.file.min.js` contain the Azure Storage file service operation logic

We also provide samples to guide you quickly start with the Azure Storage JavaScript Client Library. In the [JavaScript Client Library zip file](https://aka.ms/downloadazurestoragejs) or [azure-storage-node/browser/samples](samples), you will find 4 HTML samples:
- `sample-table.html` demonstrates how to operate with Azure Storage table service in the browser
- `sample-blob.html` demonstrates how to operate with Azure Storage blob service in the browser
- `sample-table.html` demonstrates how to operate with Azure Storage table service in the browser
- `sample-queue.html` demonstrates how to operate with Azure Storage queue service in the browser
- `sample-file.html` demonstrates how to operate with Azure Storage file service in the browser

After generating the JavaScript Client Library, you can try the samples in browsers such as Chrome/Edge/Firefox directly.

**Note**: An HTTP server should be set to host the samples for IE browser.

## Limitations
## Module Support

The Azure Storage JavaScript Client Library is currently in preview stage, there are some known issues or limitations as follows.
Above JavaScript files are all [UMD compatible](https://github.com/umdjs/umd). You can load them in a CommonJS or AMD environment by JavaScript module loaders. If no module system is found, following global variables will be set:
- `AzureStorage.Blob`
- `AzureStorage.Table`
- `AzureStorage.Queue`
- `AzureStorage.File`

### Compatibility
## Compatibility

Compatibility with mobile browsers have not been fully validated, please open issues when you get errors. Current validated browsers are as below:
Compatibility with mobile browsers have not been fully validated, please open issues when you get errors. Latest validated browser versions are as below:

| Chrome | Firefox | Internet Explorer | Microsoft Edge |
|------------|----------|--------------------|-----------------|
Expand All @@ -35,14 +38,17 @@ Compatibility with mobile browsers have not been fully validated, please open is

If you wish to customize the library and generate the Azure Storage JavaScript Client Library, you can follow the following steps.

We provide browserify bundle scripts which generate Azure Storage JavaScript Client Library. The bundle script reduces the size of the Storage Client Library by splitting into smaller files, one per storage service and a common shared file.
We provide browserify bundle scripts which generate Azure Storage JavaScript Client Library. The bundle script reduces the size of the Storage Client Library by splitting into smaller files, one per storage service.

The generated JavaScript Client Library includes 5 separated JavaScript files:
- `azure-storage.common.js`
- `azure-storage.table.js`
The generated JavaScript Client Library includes 8 separated JavaScript files:
- `azure-storage.blob.js`
- `azure-storage.table.js`
- `azure-storage.queue.js`
- `azure-storage.file.js`
- `azure-storage.blob.min.js`
- `azure-storage.table.min.js`
- `azure-storage.queue.min.js`
- `azure-storage.file.min.js`

Let's get started to generate the Azure Storage JavaScript Client Library!

Expand Down Expand Up @@ -73,34 +79,17 @@ npm install
We provide bundle scripts to help quickly generate the JavaScript Client Library. At the root directory of the cloned repo:

```Batchfile
npm run genjs
npm run genjs [VERSION_NUMBER]
```

### Step 4: Finding the Generated JavaScript Files

If everything goes well, the generated JavaScript files should be saved to `azure-storage-node/browser/bundle`. There will be 5 generated JavaScript files totally:
- `azure-storage.common.js`
- `azure-storage.table.js`
If everything goes well, the generated JavaScript files should be saved to `azure-storage-node/browser/bundle`. There will be 8 generated JavaScript files totally:
- `azure-storage.blob.js`
- `azure-storage.table.js`
- `azure-storage.queue.js`
- `azure-storage.file.js`

### Step 5: JavaScript Files Minify

You are able to minify the generated JavaScript files with your favorite minify tools. Here we show the minify process with Node.js minify tool [uglifyJS](https://github.com/mishoo/UglifyJS2).

Install uglifyJS:

```Batchfile
npm install -g uglify-js
```

Minify the JavaScript files:

```Batchfile
uglifyjs --compress --mangle -- azure-storage.common.js > azure-storage.common.min.js
uglifyjs --compress --mangle -- azure-storage.table.js > azure-storage.table.min.js
uglifyjs --compress --mangle -- azure-storage.blob.js > azure-storage.blob.min.js
uglifyjs --compress --mangle -- azure-storage.queue.js > azure-storage.queue.min.js
uglifyjs --compress --mangle -- azure-storage.file.js > azure-storage.file.min.js
```
- `azure-storage.blob.min.js`
- `azure-storage.table.min.js`
- `azure-storage.queue.min.js`
- `azure-storage.file.min.js`
Loading

0 comments on commit 78a09ef

Please sign in to comment.