matteobortolazzo / azure-cosmosdb-js-server-types

Typescript type definitions for Cosmos DB Javascript API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Azure CosmosDB JS Server Types

TypeScript type definitions for the Azure CosmosDB JS Server SDK.

Based on the official Azure CosmosDB JS Server Docs.

Example

Write the script in TypeScript:

interface User {
    name: string;
    age: number;
    addresses: Address[];    
}

interface Address {
    city: string;
}

function runQuery() {  
    const result = __.chain<User>()
        .filter(doc => doc.age > 30)
        .sortBy(user => user.age)
        .map(user => user.addresses)
        .flatten<Address>()
        .value(null, callback)
    if(!result.isAccepted)
    throw new Error("The call was not accepted");

    function callback(err: Error, items: Address[]) {
        if(err) throw err;

        // or getContext().getResponse().setBody({    
        __.response.setBody({
            result: items
        })
    }  
}

It will be compiled to JavaScript:

function runQuery() {
    var result = __.chain()
        .filter(function (doc) { return doc.age > 30; })
        .sortBy(function (user) { return user.age; })
        .map(function (user) { return user.addresses; })
        .flatten()
        .value(null, callback);
    if (!result.isAccepted)
        throw new Error("The call was not accepted");
    function callback(err, items) {
        if (err)
            throw err;
        // or getContext().getResponse().setBody({    
        __.response.setBody({
            result: items
        });
    }
}

About

Typescript type definitions for Cosmos DB Javascript API

License:MIT License