Simplify TypeScript types package (#438)
This commit is contained in:
Родитель
0e832e715e
Коммит
db7b0e50e7
|
@ -39,6 +39,7 @@ azure-functions-language-worker-protobuf/*
|
|||
|
||||
dist
|
||||
pkg
|
||||
types/*.tgz
|
||||
|
||||
Azure.Functions.Cli
|
||||
Azure.Functions.Cli.zip
|
||||
|
@ -48,16 +49,3 @@ test/end-to-end/Azure.Functions.NodejsWorker.E2E/.vs
|
|||
test/end-to-end/Azure.Functions.NodejsWorker.E2E/Azure.Functions.NodejsWorker.E2E/bin
|
||||
test/end-to-end/Azure.Functions.NodejsWorker.E2E/Azure.Functions.NodejsWorker.E2E/obj
|
||||
**/*-test-results.xml
|
||||
|
||||
# Commit external interfaces
|
||||
types/*
|
||||
|
||||
!types/public
|
||||
types/public/*
|
||||
!types/public/Main.d.ts
|
||||
!types/public/Interfaces.d.ts
|
||||
!types/public/package.json
|
||||
!types/public/README.md
|
||||
!types/public/ts3.1
|
||||
types/public/ts3.1/*
|
||||
!types/public/ts3.1/Main.d.ts
|
|
@ -46,4 +46,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
|
|||
|
||||
### Contributing to TypeScript type definitions
|
||||
|
||||
`types/public/Interfaces.d.ts` is a generated file from `src/public/Interfaces.ts`. If you want to add a change to `Interfaces.d.ts`, please make the change first to `Interfaces.ts` and then `npm run build` to generate the appropriate type definitions. Any additional type definition tests should go in `test/InterfacesTest.ts`.
|
||||
The type definitions supplied by the `@azure/functions` [npm package](https://www.npmjs.com/package/@azure/functions) are located in the `types` folder. Any changes should be applied directly to `./types/index.d.ts`. Please make sure to update the tests in `./types/index.test.ts` as well.
|
|
@ -43,6 +43,8 @@
|
|||
"string-replace-webpack-plugin": "^0.1.3",
|
||||
"ts-node": "^3.3.0",
|
||||
"typescript": "^4.1.3",
|
||||
"typescript3": "npm:typescript@~3.7.0",
|
||||
"typescript4": "npm:typescript@~4.0.0",
|
||||
"uglify-js": "^3.7.7",
|
||||
"webpack": "^5.53.0",
|
||||
"webpack-cli": "^4.8.0"
|
||||
|
@ -4324,6 +4326,34 @@
|
|||
"node": ">=4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript3": {
|
||||
"name": "typescript",
|
||||
"version": "3.7.7",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.7.tgz",
|
||||
"integrity": "sha512-MmQdgo/XenfZPvVLtKZOq9jQQvzaUAUpcKW8Z43x9B2fOm4S5g//tPtMweZUIP+SoBqrVPEIm+dJeQ9dfO0QdA==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/typescript4": {
|
||||
"name": "typescript",
|
||||
"version": "4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.8.tgz",
|
||||
"integrity": "sha512-oz1765PN+imfz1MlZzSZPtC/tqcwsCyIYA8L47EkRnRW97ztRk83SzMiWLrnChC0vqoYxSU1fcFUDA5gV/ZiPg==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/uc.micro": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
|
||||
|
@ -7909,6 +7939,18 @@
|
|||
"integrity": "sha512-B3ZIOf1IKeH2ixgHhj6la6xdwR9QrLC5d1VKeCSY4tvkqhF2eqd9O7txNlS0PO3GrBAFIdr3L1ndNwteUbZLYg==",
|
||||
"dev": true
|
||||
},
|
||||
"typescript3": {
|
||||
"version": "npm:typescript@3.7.7",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.7.7.tgz",
|
||||
"integrity": "sha512-MmQdgo/XenfZPvVLtKZOq9jQQvzaUAUpcKW8Z43x9B2fOm4S5g//tPtMweZUIP+SoBqrVPEIm+dJeQ9dfO0QdA==",
|
||||
"dev": true
|
||||
},
|
||||
"typescript4": {
|
||||
"version": "npm:typescript@4.0.8",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.0.8.tgz",
|
||||
"integrity": "sha512-oz1765PN+imfz1MlZzSZPtC/tqcwsCyIYA8L47EkRnRW97ztRk83SzMiWLrnChC0vqoYxSU1fcFUDA5gV/ZiPg==",
|
||||
"dev": true
|
||||
},
|
||||
"uc.micro": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz",
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
"string-replace-webpack-plugin": "^0.1.3",
|
||||
"ts-node": "^3.3.0",
|
||||
"typescript": "^4.1.3",
|
||||
"typescript3": "npm:typescript@~3.7.0",
|
||||
"typescript4": "npm:typescript@~4.0.0",
|
||||
"uglify-js": "^3.7.7",
|
||||
"webpack": "^5.53.0",
|
||||
"webpack-cli": "^4.8.0"
|
||||
|
@ -53,13 +55,13 @@
|
|||
},
|
||||
"scripts": {
|
||||
"clean": "rimraf dist && rimraf azure-functions-language-worker-protobuf/src/rpc*",
|
||||
"build": "rimraf dist && npm run gen && shx mkdir -p dist/azure-functions-language-worker-protobuf/src && shx cp azure-functions-language-worker-protobuf/src/rpc.* dist/azure-functions-language-worker-protobuf/src/. && tsc",
|
||||
"build": "rimraf dist && npm run gen && shx mkdir -p dist/azure-functions-language-worker-protobuf/src && shx cp azure-functions-language-worker-protobuf/src/rpc.* dist/azure-functions-language-worker-protobuf/src/. && node ./node_modules/typescript/bin/tsc",
|
||||
"build-nomaps": "npm run build -- --sourceMap false",
|
||||
"gen": "node scripts/generateProtos.js",
|
||||
"test": "mocha -r ts-node/register ./test/**/*.ts --reporter mocha-multi-reporters --reporter-options configFile=test/mochaReporterOptions.json",
|
||||
"lint": "eslint src",
|
||||
"lint-fix": "eslint src --fix",
|
||||
"watch": "tsc --watch",
|
||||
"watch": "node ./node_modules/typescript/bin/tsc --watch",
|
||||
"prepare": "husky install"
|
||||
},
|
||||
"files": [
|
||||
|
|
|
@ -11,7 +11,7 @@ import {
|
|||
import { FunctionInfo } from './FunctionInfo';
|
||||
import { Request, RequestProperties } from './http/Request';
|
||||
import { Response } from './http/Response';
|
||||
import { BindingDefinition, Context, ExecutionContext, Logger, TraceContext } from './public/Interfaces';
|
||||
import { BindingDefinition, Context, ExecutionContext, Logger, TraceContext } from '@azure/functions';
|
||||
import LogLevel = rpc.RpcLog.Level;
|
||||
import LogCategory = rpc.RpcLog.RpcLogCategory;
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { Context } from '@azure/functions';
|
||||
import { format, isFunction } from 'util';
|
||||
import { AzureFunctionsRpcMessages as rpc } from '../azure-functions-language-worker-protobuf/src/rpc';
|
||||
import { CreateContextAndInputs, LogCallback, ResultCallback } from './Context';
|
||||
import { toTypedData } from './converters';
|
||||
import { IFunctionLoader } from './FunctionLoader';
|
||||
import { IEventStream } from './GrpcService';
|
||||
import { Context } from './public/Interfaces';
|
||||
import { InternalException } from './utils/InternalException';
|
||||
import { systemError } from './utils/Logger';
|
||||
import LogCategory = rpc.RpcLog.RpcLogCategory;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import { BindingDefinition } from '@azure/functions';
|
||||
import { AzureFunctionsRpcMessages as rpc } from '../../azure-functions-language-worker-protobuf/src/rpc';
|
||||
import { Dict } from '../Context';
|
||||
import { FunctionInfo } from '../FunctionInfo';
|
||||
import { BindingDefinition } from '../public/Interfaces';
|
||||
import { fromTypedData } from './RpcConverters';
|
||||
|
||||
type BindingDirection = 'in' | 'out' | 'inout' | undefined;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { TraceContext } from '@azure/functions';
|
||||
import { isLong } from 'long';
|
||||
import {
|
||||
AzureFunctionsRpcMessages as rpc,
|
||||
|
@ -6,7 +7,6 @@ import {
|
|||
INullableString,
|
||||
INullableTimestamp,
|
||||
} from '../../azure-functions-language-worker-protobuf/src/rpc';
|
||||
import { TraceContext } from '../public/Interfaces';
|
||||
import { InternalException } from '../utils/InternalException';
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { Cookie, HttpMethod } from '@azure/functions';
|
||||
import {
|
||||
AzureFunctionsRpcMessages as rpc,
|
||||
INullableString,
|
||||
} from '../../azure-functions-language-worker-protobuf/src/rpc';
|
||||
import { Dict } from '../Context';
|
||||
import { RequestProperties } from '../http/Request';
|
||||
import { Cookie, HttpMethod } from '../public/Interfaces';
|
||||
import {
|
||||
fromTypedData,
|
||||
toNullableBool,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
import { HttpMethod, HttpRequest } from '../public/Interfaces';
|
||||
import { HttpMethod, HttpRequest } from '@azure/functions';
|
||||
|
||||
export class RequestProperties implements HttpRequest {
|
||||
method: HttpMethod | null = null;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { Cookie } from '../public/Interfaces';
|
||||
import { Cookie } from '@azure/functions';
|
||||
|
||||
// Copyright (c) .NET Foundation. All rights thiserved.
|
||||
// Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
|
|
|
@ -1,300 +0,0 @@
|
|||
/**
|
||||
* Context bindings object. Provided to your function binding data, as defined in function.json.
|
||||
*/
|
||||
export interface ContextBindings {
|
||||
[name: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Context binding data. Provided to your function trigger metadata and function invocation data.
|
||||
*/
|
||||
export interface ContextBindingData {
|
||||
invocationId?: string | null;
|
||||
[name: string]: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* The context object can be used for writing logs, reading data from bindings, setting outputs and using
|
||||
* the context.done callback when your exported function is synchronous. A context object is passed
|
||||
* to your function from the Azure Functions runtime on function invocation.
|
||||
*/
|
||||
export interface Context {
|
||||
/**
|
||||
* A unique GUID per function invocation.
|
||||
*/
|
||||
invocationId: string;
|
||||
/**
|
||||
* Function execution metadata.
|
||||
*/
|
||||
executionContext: ExecutionContext;
|
||||
/**
|
||||
* Input and trigger binding data, as defined in function.json. Properties on this object are dynamically
|
||||
* generated and named based off of the "name" property in function.json.
|
||||
*/
|
||||
bindings: ContextBindings;
|
||||
/**
|
||||
* Trigger metadata and function invocation data.
|
||||
*/
|
||||
bindingData: ContextBindingData;
|
||||
/**
|
||||
* TraceContext information to enable distributed tracing scenarios.
|
||||
*/
|
||||
traceContext: TraceContext;
|
||||
/**
|
||||
* Bindings your function uses, as defined in function.json.
|
||||
*/
|
||||
bindingDefinitions: BindingDefinition[];
|
||||
/**
|
||||
* Allows you to write streaming function logs. Calling directly allows you to write streaming function logs
|
||||
* at the default trace level.
|
||||
*/
|
||||
log: Logger;
|
||||
/**
|
||||
* A callback function that signals to the runtime that your code has completed. If your function is synchronous,
|
||||
* you must call context.done at the end of execution. If your function is asynchronous, you should not use this
|
||||
* callback.
|
||||
*
|
||||
* @param err A user-defined error to pass back to the runtime. If present, your function execution will fail.
|
||||
* @param result An object containing output binding data. `result` will be passed to JSON.stringify unless it is
|
||||
* a string, Buffer, ArrayBufferView, or number.
|
||||
*/
|
||||
done(err?: Error | string | null, result?: any): void;
|
||||
/**
|
||||
* HTTP request object. Provided to your function when using HTTP Bindings.
|
||||
*/
|
||||
req?: HttpRequest;
|
||||
/**
|
||||
* HTTP response object. Provided to your function when using HTTP Bindings.
|
||||
*/
|
||||
res?: { [key: string]: any };
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP request headers.
|
||||
*/
|
||||
export interface HttpRequestHeaders {
|
||||
[name: string]: string | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Query string parameter keys and values from the URL.
|
||||
*/
|
||||
export interface HttpRequestQuery {
|
||||
[name: string]: string | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Route parameter keys and values.
|
||||
*/
|
||||
export interface HttpRequestParams {
|
||||
[name: string]: string | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP request object. Provided to your function when using HTTP Bindings.
|
||||
*/
|
||||
export interface HttpRequest {
|
||||
/**
|
||||
* HTTP request method used to invoke this function.
|
||||
*/
|
||||
method: HttpMethod | null;
|
||||
/**
|
||||
* Request URL.
|
||||
*/
|
||||
url: string;
|
||||
/**
|
||||
* HTTP request headers.
|
||||
*/
|
||||
headers: HttpRequestHeaders;
|
||||
/**
|
||||
* Query string parameter keys and values from the URL.
|
||||
*/
|
||||
query: HttpRequestQuery;
|
||||
/**
|
||||
* Route parameter keys and values.
|
||||
*/
|
||||
params: HttpRequestParams;
|
||||
/**
|
||||
* The HTTP request body.
|
||||
*/
|
||||
body?: any;
|
||||
/**
|
||||
* The HTTP request body as a UTF-8 string.
|
||||
*/
|
||||
rawBody?: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Possible values for an HTTP request method.
|
||||
*/
|
||||
export type HttpMethod = 'GET' | 'POST' | 'DELETE' | 'HEAD' | 'PATCH' | 'PUT' | 'OPTIONS' | 'TRACE' | 'CONNECT';
|
||||
|
||||
/**
|
||||
* Http response cookie object to "Set-Cookie"
|
||||
*/
|
||||
export interface Cookie {
|
||||
/** Cookie name */
|
||||
name: string;
|
||||
|
||||
/** Cookie value */
|
||||
value: string;
|
||||
|
||||
/** Specifies allowed hosts to receive the cookie */
|
||||
domain?: string;
|
||||
|
||||
/** Specifies URL path that must exist in the requested URL */
|
||||
path?: string;
|
||||
|
||||
/**
|
||||
* NOTE: It is generally recommended that you use maxAge over expires.
|
||||
* Sets the cookie to expire at a specific date instead of when the client closes.
|
||||
* This can be a Javascript Date or Unix time in milliseconds.
|
||||
*/
|
||||
expires?: Date | number;
|
||||
|
||||
/** Sets the cookie to only be sent with an encrypted request */
|
||||
secure?: boolean;
|
||||
|
||||
/** Sets the cookie to be inaccessible to JavaScript's Document.cookie API */
|
||||
httpOnly?: boolean;
|
||||
|
||||
/** Can restrict the cookie to not be sent with cross-site requests */
|
||||
sameSite?: 'Strict' | 'Lax' | 'None' | undefined;
|
||||
|
||||
/** Number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. */
|
||||
maxAge?: number;
|
||||
}
|
||||
|
||||
export interface ExecutionContext {
|
||||
/**
|
||||
* A unique GUID per function invocation.
|
||||
*/
|
||||
invocationId: string;
|
||||
/**
|
||||
* The name of the function that is being invoked. The name of your function is always the same as the
|
||||
* name of the corresponding function.json's parent directory.
|
||||
*/
|
||||
functionName: string;
|
||||
/**
|
||||
* The directory your function is in (this is the parent directory of this function's function.json).
|
||||
*/
|
||||
functionDirectory: string;
|
||||
/**
|
||||
* The retry context of the current funciton execution. The retry context of the current function execution. Equals null if retry policy is not defined or it's the first function execution.
|
||||
*/
|
||||
retryContext?: RetryContext;
|
||||
}
|
||||
|
||||
export interface RetryContext {
|
||||
/**
|
||||
* Current retry count of the function executions.
|
||||
*/
|
||||
retryCount: number;
|
||||
/**
|
||||
* Max retry count is the maximum number of times an execution is retried before eventual failure. A value of -1 means to retry indefinitely.
|
||||
*/
|
||||
maxRetryCount: number;
|
||||
/**
|
||||
* Exception that caused the retry
|
||||
*/
|
||||
exception?: Exception;
|
||||
}
|
||||
|
||||
export interface Exception {
|
||||
/** Exception source */
|
||||
source?: string | null;
|
||||
|
||||
/** Exception stackTrace */
|
||||
stackTrace?: string | null;
|
||||
|
||||
/** Exception message */
|
||||
message?: string | null;
|
||||
}
|
||||
|
||||
/**
|
||||
* TraceContext information to enable distributed tracing scenarios.
|
||||
*/
|
||||
export interface TraceContext {
|
||||
/** Describes the position of the incoming request in its trace graph in a portable, fixed-length format. */
|
||||
traceparent: string | null | undefined;
|
||||
|
||||
/** Extends traceparent with vendor-specific data. */
|
||||
tracestate: string | null | undefined;
|
||||
|
||||
/** Holds additional properties being sent as part of request telemetry. */
|
||||
attributes:
|
||||
| {
|
||||
[k: string]: string;
|
||||
}
|
||||
| null
|
||||
| undefined;
|
||||
}
|
||||
|
||||
export interface BindingDefinition {
|
||||
/**
|
||||
* The name of your binding, as defined in function.json.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The type of your binding, as defined in function.json.
|
||||
*/
|
||||
type: string;
|
||||
/**
|
||||
* The direction of your binding, as defined in function.json.
|
||||
*/
|
||||
direction: 'in' | 'out' | 'inout' | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows you to write streaming function logs.
|
||||
*/
|
||||
export interface Logger {
|
||||
/**
|
||||
* Writes streaming function logs at the default trace level.
|
||||
*/
|
||||
(...args: any[]): void;
|
||||
/**
|
||||
* Writes to error level logging or lower.
|
||||
*/
|
||||
error(...args: any[]): void;
|
||||
/**
|
||||
* Writes to warning level logging or lower.
|
||||
*/
|
||||
warn(...args: any[]): void;
|
||||
/**
|
||||
* Writes to info level logging or lower.
|
||||
*/
|
||||
info(...args: any[]): void;
|
||||
/**
|
||||
* Writes to verbose level logging.
|
||||
*/
|
||||
verbose(...args: any[]): void;
|
||||
}
|
||||
|
||||
export interface Timer {
|
||||
isPastDue: boolean;
|
||||
schedule: {
|
||||
/**
|
||||
* Describes whether the timer for daylight saving based on the timer's time zone
|
||||
*/
|
||||
adjustForDST: boolean;
|
||||
/**
|
||||
* Describes a timer schedule status
|
||||
*/
|
||||
/** Describes whether the timer schedules is past it's scheduled due time */
|
||||
};
|
||||
scheduleStatus: {
|
||||
/**
|
||||
* Describes the last recorded schedule occurence. Date ISO string.
|
||||
*/
|
||||
last: string;
|
||||
/**
|
||||
* Describes the expected next schedule occurrence
|
||||
*/
|
||||
next: string;
|
||||
/**
|
||||
* Describes the last time this record was updated. This is used to re-calculate `next` with the current schedule after a host restart. Date ISO string.
|
||||
*/
|
||||
lastUpdated: string;
|
||||
};
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
import { Context } from './Interfaces';
|
||||
export * from './Interfaces';
|
||||
|
||||
/**
|
||||
* Interface for your Azure Function code. This function must be exported (via module.exports or exports)
|
||||
* and will execute when triggered. It is recommended that you declare this function as async, which
|
||||
* implicitly returns a Promise.
|
||||
* @param context Context object passed to your function from the Azure Functions runtime.
|
||||
* @param {any[]} args Optional array of input and trigger binding data. These binding data are passed to the
|
||||
* function in the same order that they are defined in function.json. Valid input types are string, HttpRequest,
|
||||
* and Buffer.
|
||||
* @returns Output bindings (optional). If you are returning a result from a Promise (or an async function), this
|
||||
* result will be passed to JSON.stringify unless it is a string, Buffer, ArrayBufferView, or number.
|
||||
*/
|
||||
export type AzureFunction = (context: Context, ...args: any[]) => Promise<any> | void;
|
|
@ -1,18 +0,0 @@
|
|||
import { Context } from '../Interfaces';
|
||||
export * from '../Interfaces';
|
||||
|
||||
/**
|
||||
* Interface for your Azure Function code. This function must be exported (via module.exports or exports)
|
||||
* and will execute when triggered. It is recommended that you declare this function as async, which
|
||||
* implicitly returns a Promise.
|
||||
* @param context Context object passed to your function from the Azure Functions runtime.
|
||||
* @param {any[]} args Optional array of input and trigger binding data. These binding data are passed to the
|
||||
* function in the same order that they are defined in function.json. Valid input types are string, HttpRequest,
|
||||
* and Buffer.
|
||||
* @returns Output bindings (optional). If you are returning a result from a Promise (or an async function), this
|
||||
* result will be passed to JSON.stringify unless it is a string, Buffer, ArrayBufferView, or number.
|
||||
*/
|
||||
export declare type AzureFunction<TReturn = any, TArgs extends any[] = any[]> = (
|
||||
context: Context,
|
||||
...args: TArgs
|
||||
) => Promise<TReturn> | void;
|
|
@ -1,5 +1,5 @@
|
|||
import { CreateContextAndInputs, LogCallback, ResultCallback } from '../src/Context';
|
||||
import { Context } from "../src/public/Interfaces";
|
||||
import { Context } from "@azure/functions";
|
||||
import { FunctionInfo } from '../src/FunctionInfo';
|
||||
import { AzureFunctionsRpcMessages as rpc } from '../azure-functions-language-worker-protobuf/src/rpc';
|
||||
import * as sinon from 'sinon';
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { FunctionInfo } from '../src/FunctionInfo';
|
||||
import { Cookie } from "../types/public/Interfaces";
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import { AzureFunctionsRpcMessages as rpc } from '../azure-functions-language-worker-protobuf/src/rpc';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { toRpcHttpCookieList, toRpcHttp } from '../src/converters';
|
||||
import { Cookie } from "../types/public/Interfaces";
|
||||
import { Cookie } from "@azure/functions";
|
||||
import { expect } from 'chai';
|
||||
import * as sinon from 'sinon';
|
||||
import { AzureFunctionsRpcMessages as rpc } from '../azure-functions-language-worker-protobuf/src/rpc';
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import { expect } from 'chai';
|
||||
import * as cp from 'child_process';
|
||||
import 'mocha';
|
||||
import { ITestCallbackContext } from 'mocha';
|
||||
import * as path from 'path';
|
||||
|
||||
describe('Public TypeScript types', async () => {
|
||||
for (const tsVersion of ['3', '4']) {
|
||||
it(`builds with TypeScript v${tsVersion}`, async function (this: ITestCallbackContext) {
|
||||
this.timeout(10 * 1000);
|
||||
expect(await runTsBuild(tsVersion)).to.equal(0);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
async function runTsBuild(tsVersion: string): Promise<number> {
|
||||
const repoRoot = path.join(__dirname, '..');
|
||||
const tscPath = path.join(repoRoot, 'node_modules', `typescript${tsVersion}`, 'bin', 'tsc');
|
||||
const projectFile = path.join(repoRoot, 'types', 'tsconfig.json');
|
||||
return new Promise<number>((resolve, reject) => {
|
||||
const cmd = cp.spawn('node', [tscPath, '--project', projectFile]);
|
||||
cmd.stdout.on('data', function (data) {
|
||||
console.log(data.toString());
|
||||
});
|
||||
cmd.stderr.on('data', function (data) {
|
||||
console.error(data.toString());
|
||||
});
|
||||
cmd.on('error', reject);
|
||||
cmd.on('close', resolve);
|
||||
});
|
||||
}
|
|
@ -4,13 +4,13 @@
|
|||
"target": "es6",
|
||||
"noImplicitAny": false,
|
||||
"strict": true,
|
||||
"outDir": "dist/src",
|
||||
"outDir": "dist",
|
||||
"sourceMap": true,
|
||||
"declaration": true,
|
||||
"declarationDir": "types"
|
||||
},
|
||||
"include": [
|
||||
"src/**/*"
|
||||
],
|
||||
"compileOnSave": true
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
"@azure/functions": [
|
||||
"types"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
*.test.ts
|
||||
tsconfig.json
|
||||
dist
|
||||
*.tgz
|
|
@ -1,271 +1,286 @@
|
|||
/**
|
||||
* Context bindings object. Provided to your function binding data, as defined in function.json.
|
||||
*/
|
||||
export interface ContextBindings {
|
||||
[name: string]: any;
|
||||
}
|
||||
/**
|
||||
* Context binding data. Provided to your function trigger metadata and function invocation data.
|
||||
*/
|
||||
export interface ContextBindingData {
|
||||
invocationId?: string | null;
|
||||
[name: string]: any;
|
||||
}
|
||||
/**
|
||||
* The context object can be used for writing logs, reading data from bindings, setting outputs and using
|
||||
* the context.done callback when your exported function is synchronous. A context object is passed
|
||||
* to your function from the Azure Functions runtime on function invocation.
|
||||
*/
|
||||
export interface Context {
|
||||
declare module '@azure/functions' {
|
||||
/**
|
||||
* A unique GUID per function invocation.
|
||||
* Interface for your Azure Function code. This function must be exported (via module.exports or exports)
|
||||
* and will execute when triggered. It is recommended that you declare this function as async, which
|
||||
* implicitly returns a Promise.
|
||||
* @param context Context object passed to your function from the Azure Functions runtime.
|
||||
* @param {any[]} args Optional array of input and trigger binding data. These binding data are passed to the
|
||||
* function in the same order that they are defined in function.json. Valid input types are string, HttpRequest,
|
||||
* and Buffer.
|
||||
* @returns Output bindings (optional). If you are returning a result from a Promise (or an async function), this
|
||||
* result will be passed to JSON.stringify unless it is a string, Buffer, ArrayBufferView, or number.
|
||||
*/
|
||||
invocationId: string;
|
||||
export type AzureFunction = (context: Context, ...args: any[]) => Promise<any> | void;
|
||||
|
||||
/**
|
||||
* Function execution metadata.
|
||||
* Context bindings object. Provided to your function binding data, as defined in function.json.
|
||||
*/
|
||||
executionContext: ExecutionContext;
|
||||
export interface ContextBindings {
|
||||
[name: string]: any;
|
||||
}
|
||||
/**
|
||||
* Input and trigger binding data, as defined in function.json. Properties on this object are dynamically
|
||||
* generated and named based off of the "name" property in function.json.
|
||||
* Context binding data. Provided to your function trigger metadata and function invocation data.
|
||||
*/
|
||||
bindings: ContextBindings;
|
||||
export interface ContextBindingData {
|
||||
invocationId?: string | null;
|
||||
[name: string]: any;
|
||||
}
|
||||
/**
|
||||
* Trigger metadata and function invocation data.
|
||||
* The context object can be used for writing logs, reading data from bindings, setting outputs and using
|
||||
* the context.done callback when your exported function is synchronous. A context object is passed
|
||||
* to your function from the Azure Functions runtime on function invocation.
|
||||
*/
|
||||
bindingData: ContextBindingData;
|
||||
/**
|
||||
* TraceContext information to enable distributed tracing scenarios.
|
||||
*/
|
||||
traceContext: TraceContext;
|
||||
/**
|
||||
* Bindings your function uses, as defined in function.json.
|
||||
*/
|
||||
bindingDefinitions: BindingDefinition[];
|
||||
/**
|
||||
* Allows you to write streaming function logs. Calling directly allows you to write streaming function logs
|
||||
* at the default trace level.
|
||||
*/
|
||||
log: Logger;
|
||||
/**
|
||||
* A callback function that signals to the runtime that your code has completed. If your function is synchronous,
|
||||
* you must call context.done at the end of execution. If your function is asynchronous, you should not use this
|
||||
* callback.
|
||||
*
|
||||
* @param err A user-defined error to pass back to the runtime. If present, your function execution will fail.
|
||||
* @param result An object containing output binding data. `result` will be passed to JSON.stringify unless it is
|
||||
* a string, Buffer, ArrayBufferView, or number.
|
||||
*/
|
||||
done(err?: Error | string | null, result?: any): void;
|
||||
/**
|
||||
* HTTP request object. Provided to your function when using HTTP Bindings.
|
||||
*/
|
||||
req?: HttpRequest;
|
||||
/**
|
||||
* HTTP response object. Provided to your function when using HTTP Bindings.
|
||||
*/
|
||||
res?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* HTTP request headers.
|
||||
*/
|
||||
export interface HttpRequestHeaders {
|
||||
[name: string]: string | undefined;
|
||||
}
|
||||
/**
|
||||
* Query string parameter keys and values from the URL.
|
||||
*/
|
||||
export interface HttpRequestQuery {
|
||||
[name: string]: string | undefined;
|
||||
}
|
||||
/**
|
||||
* Route parameter keys and values.
|
||||
*/
|
||||
export interface HttpRequestParams {
|
||||
[name: string]: string | undefined;
|
||||
}
|
||||
/**
|
||||
* HTTP request object. Provided to your function when using HTTP Bindings.
|
||||
*/
|
||||
export interface HttpRequest {
|
||||
/**
|
||||
* HTTP request method used to invoke this function.
|
||||
*/
|
||||
method: HttpMethod | null;
|
||||
/**
|
||||
* Request URL.
|
||||
*/
|
||||
url: string;
|
||||
export interface Context {
|
||||
/**
|
||||
* A unique GUID per function invocation.
|
||||
*/
|
||||
invocationId: string;
|
||||
/**
|
||||
* Function execution metadata.
|
||||
*/
|
||||
executionContext: ExecutionContext;
|
||||
/**
|
||||
* Input and trigger binding data, as defined in function.json. Properties on this object are dynamically
|
||||
* generated and named based off of the "name" property in function.json.
|
||||
*/
|
||||
bindings: ContextBindings;
|
||||
/**
|
||||
* Trigger metadata and function invocation data.
|
||||
*/
|
||||
bindingData: ContextBindingData;
|
||||
/**
|
||||
* TraceContext information to enable distributed tracing scenarios.
|
||||
*/
|
||||
traceContext: TraceContext;
|
||||
/**
|
||||
* Bindings your function uses, as defined in function.json.
|
||||
*/
|
||||
bindingDefinitions: BindingDefinition[];
|
||||
/**
|
||||
* Allows you to write streaming function logs. Calling directly allows you to write streaming function logs
|
||||
* at the default trace level.
|
||||
*/
|
||||
log: Logger;
|
||||
/**
|
||||
* A callback function that signals to the runtime that your code has completed. If your function is synchronous,
|
||||
* you must call context.done at the end of execution. If your function is asynchronous, you should not use this
|
||||
* callback.
|
||||
*
|
||||
* @param err A user-defined error to pass back to the runtime. If present, your function execution will fail.
|
||||
* @param result An object containing output binding data. `result` will be passed to JSON.stringify unless it is
|
||||
* a string, Buffer, ArrayBufferView, or number.
|
||||
*/
|
||||
done(err?: Error | string | null, result?: any): void;
|
||||
/**
|
||||
* HTTP request object. Provided to your function when using HTTP Bindings.
|
||||
*/
|
||||
req?: HttpRequest;
|
||||
/**
|
||||
* HTTP response object. Provided to your function when using HTTP Bindings.
|
||||
*/
|
||||
res?: {
|
||||
[key: string]: any;
|
||||
};
|
||||
}
|
||||
/**
|
||||
* HTTP request headers.
|
||||
*/
|
||||
headers: HttpRequestHeaders;
|
||||
export interface HttpRequestHeaders {
|
||||
[name: string]: string | undefined;
|
||||
}
|
||||
/**
|
||||
* Query string parameter keys and values from the URL.
|
||||
*/
|
||||
query: HttpRequestQuery;
|
||||
export interface HttpRequestQuery {
|
||||
[name: string]: string | undefined;
|
||||
}
|
||||
/**
|
||||
* Route parameter keys and values.
|
||||
*/
|
||||
params: HttpRequestParams;
|
||||
export interface HttpRequestParams {
|
||||
[name: string]: string | undefined;
|
||||
}
|
||||
/**
|
||||
* The HTTP request body.
|
||||
* HTTP request object. Provided to your function when using HTTP Bindings.
|
||||
*/
|
||||
body?: any;
|
||||
/**
|
||||
* The HTTP request body as a UTF-8 string.
|
||||
*/
|
||||
rawBody?: any;
|
||||
}
|
||||
/**
|
||||
* Possible values for an HTTP request method.
|
||||
*/
|
||||
export declare type HttpMethod = 'GET' | 'POST' | 'DELETE' | 'HEAD' | 'PATCH' | 'PUT' | 'OPTIONS' | 'TRACE' | 'CONNECT';
|
||||
/**
|
||||
* Http response cookie object to "Set-Cookie"
|
||||
*/
|
||||
export interface Cookie {
|
||||
/** Cookie name */
|
||||
name: string;
|
||||
/** Cookie value */
|
||||
value: string;
|
||||
/** Specifies allowed hosts to receive the cookie */
|
||||
domain?: string;
|
||||
/** Specifies URL path that must exist in the requested URL */
|
||||
path?: string;
|
||||
/**
|
||||
* NOTE: It is generally recommended that you use maxAge over expires.
|
||||
* Sets the cookie to expire at a specific date instead of when the client closes.
|
||||
* This can be a Javascript Date or Unix time in milliseconds.
|
||||
*/
|
||||
expires?: Date | number;
|
||||
/** Sets the cookie to only be sent with an encrypted request */
|
||||
secure?: boolean;
|
||||
/** Sets the cookie to be inaccessible to JavaScript's Document.cookie API */
|
||||
httpOnly?: boolean;
|
||||
/** Can restrict the cookie to not be sent with cross-site requests */
|
||||
sameSite?: 'Strict' | 'Lax' | 'None' | undefined;
|
||||
/** Number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. */
|
||||
maxAge?: number;
|
||||
}
|
||||
export interface ExecutionContext {
|
||||
/**
|
||||
* A unique GUID per function invocation.
|
||||
*/
|
||||
invocationId: string;
|
||||
/**
|
||||
* The name of the function that is being invoked. The name of your function is always the same as the
|
||||
* name of the corresponding function.json's parent directory.
|
||||
*/
|
||||
functionName: string;
|
||||
/**
|
||||
* The directory your function is in (this is the parent directory of this function's function.json).
|
||||
*/
|
||||
functionDirectory: string;
|
||||
/**
|
||||
* The retry context of the current funciton execution. The retry context of the current function execution. Equals null if retry policy is not defined or it's the first function execution.
|
||||
*/
|
||||
retryContext?: RetryContext;
|
||||
}
|
||||
export interface RetryContext {
|
||||
/**
|
||||
* Current retry count of the function executions.
|
||||
*/
|
||||
retryCount: number;
|
||||
/**
|
||||
* Max retry count is the maximum number of times an execution is retried before eventual failure. A value of -1 means to retry indefinitely.
|
||||
*/
|
||||
maxRetryCount: number;
|
||||
/**
|
||||
* Exception that caused the retry
|
||||
*/
|
||||
exception?: Exception;
|
||||
}
|
||||
export interface Exception {
|
||||
/** Exception source */
|
||||
source?: string | null;
|
||||
/** Exception stackTrace */
|
||||
stackTrace?: string | null;
|
||||
/** Exception message */
|
||||
message?: string | null;
|
||||
}
|
||||
/**
|
||||
* TraceContext information to enable distributed tracing scenarios.
|
||||
*/
|
||||
export interface TraceContext {
|
||||
/** Describes the position of the incoming request in its trace graph in a portable, fixed-length format. */
|
||||
traceparent: string | null | undefined;
|
||||
/** Extends traceparent with vendor-specific data. */
|
||||
tracestate: string | null | undefined;
|
||||
/** Holds additional properties being sent as part of request telemetry. */
|
||||
attributes:
|
||||
| {
|
||||
[k: string]: string;
|
||||
}
|
||||
| null
|
||||
| undefined;
|
||||
}
|
||||
export interface BindingDefinition {
|
||||
/**
|
||||
* The name of your binding, as defined in function.json.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The type of your binding, as defined in function.json.
|
||||
*/
|
||||
type: string;
|
||||
/**
|
||||
* The direction of your binding, as defined in function.json.
|
||||
*/
|
||||
direction: 'in' | 'out' | 'inout' | undefined;
|
||||
}
|
||||
/**
|
||||
* Allows you to write streaming function logs.
|
||||
*/
|
||||
export interface Logger {
|
||||
/**
|
||||
* Writes streaming function logs at the default trace level.
|
||||
*/
|
||||
(...args: any[]): void;
|
||||
/**
|
||||
* Writes to error level logging or lower.
|
||||
*/
|
||||
error(...args: any[]): void;
|
||||
/**
|
||||
* Writes to warning level logging or lower.
|
||||
*/
|
||||
warn(...args: any[]): void;
|
||||
/**
|
||||
* Writes to info level logging or lower.
|
||||
*/
|
||||
info(...args: any[]): void;
|
||||
/**
|
||||
* Writes to verbose level logging.
|
||||
*/
|
||||
verbose(...args: any[]): void;
|
||||
}
|
||||
export interface Timer {
|
||||
isPastDue: boolean;
|
||||
schedule: {
|
||||
export interface HttpRequest {
|
||||
/**
|
||||
* Describes whether the timer for daylight saving based on the timer's time zone
|
||||
* HTTP request method used to invoke this function.
|
||||
*/
|
||||
adjustForDST: boolean;
|
||||
};
|
||||
scheduleStatus: {
|
||||
method: HttpMethod | null;
|
||||
/**
|
||||
* Describes the last recorded schedule occurence. Date ISO string.
|
||||
* Request URL.
|
||||
*/
|
||||
last: string;
|
||||
url: string;
|
||||
/**
|
||||
* Describes the expected next schedule occurrence
|
||||
* HTTP request headers.
|
||||
*/
|
||||
next: string;
|
||||
headers: HttpRequestHeaders;
|
||||
/**
|
||||
* Describes the last time this record was updated. This is used to re-calculate `next` with the current schedule after a host restart. Date ISO string.
|
||||
* Query string parameter keys and values from the URL.
|
||||
*/
|
||||
lastUpdated: string;
|
||||
};
|
||||
query: HttpRequestQuery;
|
||||
/**
|
||||
* Route parameter keys and values.
|
||||
*/
|
||||
params: HttpRequestParams;
|
||||
/**
|
||||
* The HTTP request body.
|
||||
*/
|
||||
body?: any;
|
||||
/**
|
||||
* The HTTP request body as a UTF-8 string.
|
||||
*/
|
||||
rawBody?: any;
|
||||
}
|
||||
/**
|
||||
* Possible values for an HTTP request method.
|
||||
*/
|
||||
export type HttpMethod = 'GET' | 'POST' | 'DELETE' | 'HEAD' | 'PATCH' | 'PUT' | 'OPTIONS' | 'TRACE' | 'CONNECT';
|
||||
/**
|
||||
* Http response cookie object to "Set-Cookie"
|
||||
*/
|
||||
export interface Cookie {
|
||||
/** Cookie name */
|
||||
name: string;
|
||||
/** Cookie value */
|
||||
value: string;
|
||||
/** Specifies allowed hosts to receive the cookie */
|
||||
domain?: string;
|
||||
/** Specifies URL path that must exist in the requested URL */
|
||||
path?: string;
|
||||
/**
|
||||
* NOTE: It is generally recommended that you use maxAge over expires.
|
||||
* Sets the cookie to expire at a specific date instead of when the client closes.
|
||||
* This can be a Javascript Date or Unix time in milliseconds.
|
||||
*/
|
||||
expires?: Date | number;
|
||||
/** Sets the cookie to only be sent with an encrypted request */
|
||||
secure?: boolean;
|
||||
/** Sets the cookie to be inaccessible to JavaScript's Document.cookie API */
|
||||
httpOnly?: boolean;
|
||||
/** Can restrict the cookie to not be sent with cross-site requests */
|
||||
sameSite?: 'Strict' | 'Lax' | 'None' | undefined;
|
||||
/** Number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. */
|
||||
maxAge?: number;
|
||||
}
|
||||
export interface ExecutionContext {
|
||||
/**
|
||||
* A unique GUID per function invocation.
|
||||
*/
|
||||
invocationId: string;
|
||||
/**
|
||||
* The name of the function that is being invoked. The name of your function is always the same as the
|
||||
* name of the corresponding function.json's parent directory.
|
||||
*/
|
||||
functionName: string;
|
||||
/**
|
||||
* The directory your function is in (this is the parent directory of this function's function.json).
|
||||
*/
|
||||
functionDirectory: string;
|
||||
/**
|
||||
* The retry context of the current funciton execution. The retry context of the current function execution. Equals null if retry policy is not defined or it's the first function execution.
|
||||
*/
|
||||
retryContext?: RetryContext;
|
||||
}
|
||||
export interface RetryContext {
|
||||
/**
|
||||
* Current retry count of the function executions.
|
||||
*/
|
||||
retryCount: number;
|
||||
/**
|
||||
* Max retry count is the maximum number of times an execution is retried before eventual failure. A value of -1 means to retry indefinitely.
|
||||
*/
|
||||
maxRetryCount: number;
|
||||
/**
|
||||
* Exception that caused the retry
|
||||
*/
|
||||
exception?: Exception;
|
||||
}
|
||||
export interface Exception {
|
||||
/** Exception source */
|
||||
source?: string | null;
|
||||
/** Exception stackTrace */
|
||||
stackTrace?: string | null;
|
||||
/** Exception message */
|
||||
message?: string | null;
|
||||
}
|
||||
/**
|
||||
* TraceContext information to enable distributed tracing scenarios.
|
||||
*/
|
||||
export interface TraceContext {
|
||||
/** Describes the position of the incoming request in its trace graph in a portable, fixed-length format. */
|
||||
traceparent: string | null | undefined;
|
||||
/** Extends traceparent with vendor-specific data. */
|
||||
tracestate: string | null | undefined;
|
||||
/** Holds additional properties being sent as part of request telemetry. */
|
||||
attributes:
|
||||
| {
|
||||
[k: string]: string;
|
||||
}
|
||||
| null
|
||||
| undefined;
|
||||
}
|
||||
export interface BindingDefinition {
|
||||
/**
|
||||
* The name of your binding, as defined in function.json.
|
||||
*/
|
||||
name: string;
|
||||
/**
|
||||
* The type of your binding, as defined in function.json.
|
||||
*/
|
||||
type: string;
|
||||
/**
|
||||
* The direction of your binding, as defined in function.json.
|
||||
*/
|
||||
direction: 'in' | 'out' | 'inout' | undefined;
|
||||
}
|
||||
/**
|
||||
* Allows you to write streaming function logs.
|
||||
*/
|
||||
export interface Logger {
|
||||
/**
|
||||
* Writes streaming function logs at the default trace level.
|
||||
*/
|
||||
(...args: any[]): void;
|
||||
/**
|
||||
* Writes to error level logging or lower.
|
||||
*/
|
||||
error(...args: any[]): void;
|
||||
/**
|
||||
* Writes to warning level logging or lower.
|
||||
*/
|
||||
warn(...args: any[]): void;
|
||||
/**
|
||||
* Writes to info level logging or lower.
|
||||
*/
|
||||
info(...args: any[]): void;
|
||||
/**
|
||||
* Writes to verbose level logging.
|
||||
*/
|
||||
verbose(...args: any[]): void;
|
||||
}
|
||||
export interface Timer {
|
||||
isPastDue: boolean;
|
||||
schedule: {
|
||||
/**
|
||||
* Describes whether the timer for daylight saving based on the timer's time zone
|
||||
*/
|
||||
adjustForDST: boolean;
|
||||
};
|
||||
scheduleStatus: {
|
||||
/**
|
||||
* Describes the last recorded schedule occurence. Date ISO string.
|
||||
*/
|
||||
last: string;
|
||||
/**
|
||||
* Describes the expected next schedule occurrence
|
||||
*/
|
||||
next: string;
|
||||
/**
|
||||
* Describes the last time this record was updated. This is used to re-calculate `next` with the current schedule after a host restart. Date ISO string.
|
||||
*/
|
||||
lastUpdated: string;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Test typescript interfaces for ts compliation errors
|
||||
import { Context, HttpRequest, HttpMethod, Cookie } from "../types/public/Interfaces";
|
||||
import { AzureFunction } from "../types/public/ts3.1/Main";
|
||||
// This file will be compiled by multiple versions of TypeScript as decribed in ./test/TypesTests.ts to verify there are no errors
|
||||
|
||||
import { AzureFunction, Context, HttpRequest, HttpMethod, Cookie } from "@azure/functions";
|
||||
const get: HttpMethod = "GET";
|
||||
|
||||
const runHttp: AzureFunction = async function (context: Context, req: HttpRequest) {
|
||||
|
@ -22,10 +22,10 @@ const runHttp: AzureFunction = async function (context: Context, req: HttpReques
|
|||
}
|
||||
}
|
||||
|
||||
const runServiceBus: AzureFunction = function (context: Context, myQueueItem: string) {
|
||||
context.log('Node.js ServiceBus queue trigger function processed message', myQueueItem);
|
||||
context.log.verbose('EnqueuedTimeUtc =', context.bindingData.enqueuedTimeUtc);
|
||||
context.log.verbose('DeliveryCount =', context.bindingData.deliveryCount);
|
||||
const runServiceBus: AzureFunction = function (context: Context, myQueueItem: string) {
|
||||
context.log('Node.js ServiceBus queue trigger function processed message', myQueueItem);
|
||||
context.log.verbose('EnqueuedTimeUtc =', context.bindingData.enqueuedTimeUtc);
|
||||
context.log.verbose('DeliveryCount =', context.bindingData.deliveryCount);
|
||||
context.log.verbose('MessageId =', context.bindingData.messageId);
|
||||
context.done();
|
||||
};
|
||||
|
@ -46,12 +46,12 @@ const runHttpReturn: AzureFunction = async function (context: Context, req: Http
|
|||
}
|
||||
}
|
||||
|
||||
const runFunction: AzureFunction = async function(context: Context) {
|
||||
const runFunction: AzureFunction = async function (context: Context) {
|
||||
context.log("Ran function");
|
||||
return "Ran function";
|
||||
}
|
||||
|
||||
const cookieFunction: AzureFunction = async function(context: Context) {
|
||||
const cookieFunction: AzureFunction = async function (context: Context) {
|
||||
let cookies: Cookie[] = [
|
||||
{
|
||||
name: "cookiename",
|
||||
|
@ -73,7 +73,7 @@ const runHttpWithQueue: AzureFunction = async function (context: Context, req: H
|
|||
|
||||
const returnWithContextDone: AzureFunction = function (context: Context, req: HttpRequest) {
|
||||
context.log.info("Writing to queue");
|
||||
context.done(null, { myOutput: { text: 'hello there, world', noNumber: true }});
|
||||
context.done(null, { myOutput: { text: 'hello there, world', noNumber: true } });
|
||||
}
|
||||
|
||||
export { runHttp, cookieFunction, runHttpReturn, runServiceBus, runFunction, runHttpWithQueue, returnWithContextDone };
|
||||
|
@ -82,19 +82,19 @@ export { runHttp, cookieFunction, runHttpReturn, runServiceBus, runFunction, run
|
|||
interface CustomOutput {
|
||||
value: string;
|
||||
}
|
||||
export const runTypedReturn: AzureFunction<CustomOutput> = async (context, request: HttpRequest) => {
|
||||
// return { // ts(2322) error
|
||||
// value1: "Test1"
|
||||
// };
|
||||
export const runTypedReturn: AzureFunction = async (context, request: HttpRequest): Promise<CustomOutput> => {
|
||||
// return { // ts(2322) error
|
||||
// value1: "Test1"
|
||||
// };
|
||||
return {
|
||||
value: "Test"
|
||||
};
|
||||
}
|
||||
|
||||
export const runTypedReturn1: AzureFunction<CustomOutput> = async (context, request ) => {
|
||||
// return { // ts(2322) error
|
||||
// value1: "Test1"
|
||||
// };
|
||||
export const runTypedReturn1: AzureFunction = async (context, request): Promise<CustomOutput> => {
|
||||
// return { // ts(2322) error
|
||||
// value1: "Test1"
|
||||
// };
|
||||
return {
|
||||
value: "Test"
|
||||
};
|
||||
|
|
|
@ -1,23 +1,16 @@
|
|||
{
|
||||
"name": "@azure/functions",
|
||||
"version": "2.1.2",
|
||||
"description": "Azure Functions types for Typescript",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Azure/azure-functions-nodejs-worker/tree/v3.x/types/public"
|
||||
},
|
||||
"keywords": [
|
||||
"azure-functions",
|
||||
"typescript"
|
||||
],
|
||||
"types": "./Main.d.ts",
|
||||
"typesVersions": {
|
||||
">=3.1": {
|
||||
"*": [
|
||||
"ts3.1/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"author": "Microsoft",
|
||||
"license": "MIT"
|
||||
"name": "@azure/functions",
|
||||
"version": "3.0.0-beta.0",
|
||||
"description": "Azure Functions types for Typescript",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Azure/azure-functions-nodejs-worker/tree/v3.x/types"
|
||||
},
|
||||
"keywords": [
|
||||
"azure-functions",
|
||||
"typescript"
|
||||
],
|
||||
"types": "./index.d.ts",
|
||||
"author": "Microsoft",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
import { Context } from './Interfaces';
|
||||
export * from './Interfaces';
|
||||
/**
|
||||
* Interface for your Azure Function code. This function must be exported (via module.exports or exports)
|
||||
* and will execute when triggered. It is recommended that you declare this function as async, which
|
||||
* implicitly returns a Promise.
|
||||
* @param context Context object passed to your function from the Azure Functions runtime.
|
||||
* @param {any[]} args Optional array of input and trigger binding data. These binding data are passed to the
|
||||
* function in the same order that they are defined in function.json. Valid input types are string, HttpRequest,
|
||||
* and Buffer.
|
||||
* @returns Output bindings (optional). If you are returning a result from a Promise (or an async function), this
|
||||
* result will be passed to JSON.stringify unless it is a string, Buffer, ArrayBufferView, or number.
|
||||
*/
|
||||
export declare type AzureFunction = (context: Context, ...args: any[]) => Promise<any> | void;
|
|
@ -1,17 +0,0 @@
|
|||
import { Context } from '../Interfaces';
|
||||
export * from '../Interfaces';
|
||||
/**
|
||||
* Interface for your Azure Function code. This function must be exported (via module.exports or exports)
|
||||
* and will execute when triggered. It is recommended that you declare this function as async, which
|
||||
* implicitly returns a Promise.
|
||||
* @param context Context object passed to your function from the Azure Functions runtime.
|
||||
* @param {any[]} args Optional array of input and trigger binding data. These binding data are passed to the
|
||||
* function in the same order that they are defined in function.json. Valid input types are string, HttpRequest,
|
||||
* and Buffer.
|
||||
* @returns Output bindings (optional). If you are returning a result from a Promise (or an async function), this
|
||||
* result will be passed to JSON.stringify unless it is a string, Buffer, ArrayBufferView, or number.
|
||||
*/
|
||||
export declare type AzureFunction<TReturn = any, TArgs extends any[] = any[]> = (
|
||||
context: Context,
|
||||
...args: TArgs
|
||||
) => Promise<TReturn> | void;
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"target": "es6",
|
||||
"strict": true,
|
||||
"outDir": "dist"
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче