@azure/functions
Version:
Microsoft Azure Functions NodeJS Framework
118 lines (105 loc) • 3.95 kB
text/typescript
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
import * as types from '@azure/functions';
import {
EffectiveFunctionOptions,
InvocationContextInit,
LogHandler,
RetryContext,
TraceContext,
TriggerMetadata,
} from '@azure/functions';
export class InvocationContext implements types.InvocationContext {
invocationId: string;
functionName: string;
extraInputs: InvocationContextExtraInputs;
extraOutputs: InvocationContextExtraOutputs;
retryContext?: RetryContext;
traceContext?: TraceContext;
triggerMetadata?: TriggerMetadata;
options: EffectiveFunctionOptions;
constructor(init?: InvocationContextInit) {
init = init || {};
const fallbackString = 'unknown';
this.invocationId = init.invocationId || fallbackString;
this.functionName = init.functionName || fallbackString;
this.extraInputs = new InvocationContextExtraInputs();
this.extraOutputs = new InvocationContextExtraOutputs();
this.retryContext = init.retryContext;
this.traceContext = init.traceContext;
this.triggerMetadata = init.triggerMetadata;
this.options = {
trigger: init.options?.trigger || {
name: fallbackString,
type: fallbackString,
},
return: init.options?.return,
extraInputs: init.options?.extraInputs || [],
extraOutputs: init.options?.extraOutputs || [],
};
this.
}
log(...args: unknown[]): void {
this.
}
trace(...args: unknown[]): void {
this.
}
debug(...args: unknown[]): void {
this.
}
info(...args: unknown[]): void {
this.
}
warn(...args: unknown[]): void {
this.
}
error(...args: unknown[]): void {
this.
}
}
class InvocationContextExtraInputs implements types.InvocationContextExtraInputs {
get(inputOrName: types.FunctionInput | string): any {
const name = typeof inputOrName === 'string' ? inputOrName : inputOrName.name;
return this.
}
set(inputOrName: types.FunctionInput | string, value: unknown): void {
const name = typeof inputOrName === 'string' ? inputOrName : inputOrName.name;
this.
}
}
class InvocationContextExtraOutputs implements types.InvocationContextExtraOutputs {
get(outputOrName: types.FunctionOutput | string): unknown {
const name = typeof outputOrName === 'string' ? outputOrName : outputOrName.name;
return this.
}
set(outputOrName: types.FunctionOutput | string, value: unknown): void {
const name = typeof outputOrName === 'string' ? outputOrName : outputOrName.name;
this.
}
}
function fallbackLogHandler(level: types.LogLevel, ...args: unknown[]): void {
switch (level) {
case 'trace':
console.trace(...args);
break;
case 'debug':
console.debug(...args);
break;
case 'information':
console.info(...args);
break;
case 'warning':
console.warn(...args);
break;
case 'critical':
case 'error':
console.error(...args);
break;
default:
console.log(...args);
}
}