Skip to content

Commit d665503

Browse files
authored
NPM TypeScript type definitions (Azure#155)
* Adding README and package.json to public types * add title * modify versions bit, make it open to node worker and latest published type being out of sync * addressing cr readme comments
1 parent 3ba2d6a commit d665503

File tree

8 files changed

+82
-15
lines changed

8 files changed

+82
-15
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@ types/*
5353

5454
!types/public
5555
types/public/*
56-
!types/public/Interfaces.d.ts
56+
!types/public/Interfaces.d.ts
57+
!types/public/package.json
58+
!types/public/README.md

.vscode/launch.json

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@
1414
"${workspaceRoot}/dist/src/*.js"
1515
],
1616
"args": ["--host", "127.0.0.1", "--port", "50051", "--requestId", "100a", "--workerId", "worker1"]
17+
},
18+
{
19+
"type": "node",
20+
"request": "attach",
21+
"name": "Attach by Process ID",
22+
"processId": "${command:PickProcess}"
1723
}
1824
]
1925
}

Worker.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
33
<metadata>
44
<id>Microsoft.Azure.Functions.NodeJsWorker</id>
5-
<version>1.0.0-beta7$version$</version>
5+
<version>1.0.1$version$</version>
66
<authors>Microsoft</authors>
77
<owners>Microsoft</owners>
88
<requireLicenseAcceptance>false</requireLicenseAcceptance>

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "azure-functions-nodejs-worker",
33
"author": "Microsoft Corporation",
4-
"version": "1.0.0-beta7",
4+
"version": "1.0.1",
55
"description": "Microsoft Azure Functions NodeJS Worker",
66
"license": "(MIT OR Apache-2.0)",
77
"dependencies": {

test/InterfacesTest.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test typescript interfaces for ts compliation errors
2-
import * as azf from "../types/public/Interfaces";
2+
import { IFunction, IContext, IRequest} from "../types/public/Interfaces";
33

4-
let runHttp: azf.IFunction = async function (context: azf.IContext, req: azf.IRequest) {
4+
let runHttp: IFunction = async function (context: IContext, req: IRequest) {
55
context.log('JavaScript HTTP trigger function processed a request.');
66
if (req.query.name || (req.body && req.body.name)) {
77
context.res = {
@@ -16,8 +16,16 @@ let runHttp: azf.IFunction = async function (context: azf.IContext, req: azf.IRe
1616
}
1717
}
1818

19+
let runServiceBus: IFunction = function (context: IContext, myQueueItem: string) {
20+
context.log('Node.js ServiceBus queue trigger function processed message', myQueueItem);
21+
context.log.verbose('EnqueuedTimeUtc =', context.bindingData.enqueuedTimeUtc);
22+
context.log.verbose('DeliveryCount =', context.bindingData.deliveryCount);
23+
context.log.verbose('MessageId =', context.bindingData.messageId);
24+
context.done();
25+
};
26+
1927
// Assumes output binding is named '$return'
20-
let runHttpReturn: azf.IFunction = async function (context: azf.IContext, req: azf.IRequest) {
28+
let runHttpReturn: IFunction = async function (context: IContext, req: IRequest) {
2129
context.log('JavaScript HTTP trigger function processed a request.');
2230
if (req.query.name || (req.body && req.body.name)) {
2331
return {
@@ -32,12 +40,4 @@ let runHttpReturn: azf.IFunction = async function (context: azf.IContext, req: a
3240
}
3341
}
3442

35-
let runServiceBus: azf.IFunction = function (context: azf.IContext, myQueueItem: string) {
36-
context.log('Node.js ServiceBus queue trigger function processed message', myQueueItem);
37-
context.log.verbose('EnqueuedTimeUtc =', context.bindingData.enqueuedTimeUtc);
38-
context.log.verbose('DeliveryCount =', context.bindingData.deliveryCount);
39-
context.log.verbose('MessageId =', context.bindingData.messageId);
40-
context.done();
41-
};
42-
4343
export { runHttp, runHttpReturn, runServiceBus };

types/public/README.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Type definitions for Azure Functions
2+
This package contains type definitions for using TypeScript with Azure Functions.
3+
4+
These typings are for common objects that will be passed to your Azure Functions function code. Azure Functions supports TypeScript development, but does not support directly running TypeScript code without transpilation.
5+
6+
Read more on [configuring entry points](https://docs.microsoft.com/azure/azure-functions/functions-reference-node#configure-function-entry-point) in your Azure Functions function app.
7+
8+
# Install
9+
Because this package only contains TypeScript type definitions, it should be saved under `devDependencies`.
10+
11+
`npm install @azure/functions --save-dev`
12+
13+
# Usage
14+
```javascript
15+
import { IFunction, IContext, IRequest} from "@azure/functions";
16+
17+
const index: IFunction = async function (context: IContext, req: IRequest) {
18+
context.log('JavaScript HTTP trigger function processed a request.');
19+
if (req.query.name || (req.body && req.body.name)) {
20+
context.res = {
21+
status: "200",
22+
body: "Hello " + (req.query.name || req.body.name)
23+
};
24+
} else {
25+
context.res = {
26+
status: 400,
27+
body: "Please pass a name on the query string or in the request body"
28+
};
29+
}
30+
}
31+
32+
export { index };
33+
```
34+
35+
# Versions
36+
Versioning of @azure/functions is tied to the version of the [Azure Functions Node.js Worker](https://github.com/Azure/azure-functions-nodejs-worker/releases) the types were generated from. You can find the Azure Functions Node.js Worker version of a given Function Runtime Version [here](https://github.com/Azure/azure-functions-host/releases). It is recommended that you take the latest version available.
37+
38+
# Getting Started with Azure Functions
39+
If you are getting started with Azure Functions, you can follow this tutorial to [create and deploy your first JavaScript function](https://docs.microsoft.com/azure/azure-functions/functions-create-first-function-vs-code). We recommend that you use Visual Studio Code and the [Azure Functions extension](https://code.visualstudio.com/tutorials/functions-extension/getting-started).
40+
41+
The [Azure Functions developer guide](https://docs.microsoft.com/azure/azure-functions/functions-reference) and the [JavaScript-specific developer guide](https://docs.microsoft.com/azure/azure-functions/functions-reference-node) are good resources to gain an understanding of more Azure Functions concepts.
42+
43+

types/public/package.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "@azure/functions",
3+
"version": "1.0.1",
4+
"description": "Azure Functions types for Typescript",
5+
"main": "Interfaces.d.ts",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/Azure/azure-functions-nodejs-worker/tree/master/types/public"
9+
},
10+
"keywords": [
11+
"azure-functions",
12+
"typescript"
13+
],
14+
"author": "Microsoft",
15+
"license": "MIT"
16+
}

0 commit comments

Comments
 (0)