Questions? Feedback? powered by Olark live chat software
Hopp over navigasjon

Announcing the release of Azure Mobile Apps Node SDK v3.0.0

Posted on 20 september, 2016

Sr. Program Manager, Azure App Service Mobile Apps

We are excited to announce the next iteration of the Azure Mobile Apps Node.js Server SDK.  This release includes a stack of new features, improvements and bug fixes.

Data Transforms, Filters and Hooks

One of the great features within the Server SDK was the ability to provide security filtering and record transformation at the server level, allowing the developer to refine the request-response pipeline for the server by writing JavaScript code.  With the v3.0 release, we've further refined the extensibility points to allow you to manipulate incoming queries and items, and trigger functionality after each data operation. You can, of course, create and distribute your own filters, transforms and hooks. However, we've packaged some common filters that reduce the amount of code you need to write.

Per-User Tables

Perhaps the most common filter request is to provide per-user data.  Per-user tables can be used with authentication to restrict data within the table to individual users.  To use this filter, add perUser = true to the table definition.  For example:

var table = require("azure-mobile-apps").table(); 
table.access = "authenticated";
table.perUser = true; 
module.exports = table;

Web Hooks

Web hooks can be used to call external HTTP endpoints (for example, Azure Functions) after each data operation completes:

var table = require("azure-mobile-apps").table();
table.webhook = { url: "https://function.azurewebsites.net/apo/HttpTriggerNodeJS1" };
module.exports = table;

For more information on this feature, including the structure that is posted to the HTTP endpoint, refer to the API Reference.

Record Expiry

Another commonly requested filter is the ability to prevent access to records older than a certain interval. For example, you may want to deny access to records older than 1 day:

var table = require("azure-mobile-apps").table();
tables.recordsExpire = { days: 1 };
module.exports = table;

For more information on specifying intervals, see the API reference.

Data Query Improvements

Azure Mobile Apps Servers sometimes have to refer to other tables to produce the right tables. We've made some improvements to the Query API to make specific common scenarios easier.

Including Soft Deleted Records

When you have soft-delete turned on, records are marked as deleted instead of being actually deleted from the SQL table. This information then flows down to other mobile devices so that they can update their offline cache. You can specify .includeDeleted() in the query to include deleted items:

table.insert((context) => {
    return context.tables('otherTable').includeDeleted().read()
        .then((results) => {
            context.item.count = results.length;
            return context.execute();
        });
});

Retrieving Records by ID

We've added a simple find function to make retrieving records by ID much simpler:

table.insert((context) => {
    return context.tables('otherTable').find(context.item.parentId)
        .then((parent) => {
            context.item.parentName = parent.name;
            return context.execute();
        });
});

Object Queries

Previously, you could use object based queries to query tables, but the same functionality was not available on update and delete operations. This functionality is now available and allows you to, for example, delete dependent records:

table.delete((context) => {
    return context.tables('childTable')
        .delete({ parentId: context.item.id })
        .then(context.execute);
});

Handling Callbacks in Table Functions

Prior SDK releases had no support for callbacks within table operation functions.  Such methods required you to re-factor the code to produce a Promise.  In v3.0.0, we directly support callbacks.  When the callback is completed, call context.next(err), passing in any error.  For example:

    var mongo = require('mongodb').MongoClient;

    table.insert(function (context) {
        context.execute().then(function () {
            mongo.connect('mongodb://localhost:27017/test', function(err, db) {
                db.collection('items').insertOne(context.item, function (err) {
                    // signal that the operation is complete, passing in any error that may have occurred
                    context.next(err);
                });
            });
        });
    });

Breaking Changes

When executing a query with both a skip() and take() clause against SQL Server, an additional column (ROW_NUMBER) was returned that was generated by the underlying query. This column is no longer returned. Because this change was implemented using T-SQL features available in SQL Server 2012 and above, versions of SQL Server prior to 2012 are no longer supported.

Installing the SDK

Whether you are creating a new Mobile App or upgrading an existing app, The Azure Mobile Apps Server SDK for Node is installed via npm:

npm install --save azure-mobile-apps@3.0

You can find full API documentation at our GitHub repository and a handy HOWTO document explaining how to build a mobile backend.