@azure/functions
Version:
Microsoft Azure Functions NodeJS Framework
1,028 lines (945 loc) • 130 kB
JavaScript
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/******/ var __webpack_modules__ = ({
/***/ "./src/InvocationContext.ts":
/*!**********************************!*\
!*** ./src/InvocationContext.ts ***!
\**********************************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _InvocationContext_userLogHandler, _InvocationContextExtraInputs_inputs, _InvocationContextExtraOutputs_outputs;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.InvocationContext = void 0;
const fallbackLogHandler_1 = __webpack_require__(/*! ./utils/fallbackLogHandler */ "./src/utils/fallbackLogHandler.ts");
class InvocationContext {
constructor(init) {
var _a, _b, _c, _d;
_InvocationContext_userLogHandler.set(this, void 0);
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: ((_a = init.options) === null || _a === void 0 ? void 0 : _a.trigger) || {
name: fallbackString,
type: fallbackString,
},
return: (_b = init.options) === null || _b === void 0 ? void 0 : _b.return,
extraInputs: ((_c = init.options) === null || _c === void 0 ? void 0 : _c.extraInputs) || [],
extraOutputs: ((_d = init.options) === null || _d === void 0 ? void 0 : _d.extraOutputs) || [],
};
__classPrivateFieldSet(this, _InvocationContext_userLogHandler, init.logHandler || fallbackLogHandler_1.fallbackLogHandler, "f");
}
log(...args) {
__classPrivateFieldGet(this, _InvocationContext_userLogHandler, "f").call(this, 'information', ...args);
}
trace(...args) {
__classPrivateFieldGet(this, _InvocationContext_userLogHandler, "f").call(this, 'trace', ...args);
}
debug(...args) {
__classPrivateFieldGet(this, _InvocationContext_userLogHandler, "f").call(this, 'debug', ...args);
}
info(...args) {
__classPrivateFieldGet(this, _InvocationContext_userLogHandler, "f").call(this, 'information', ...args);
}
warn(...args) {
__classPrivateFieldGet(this, _InvocationContext_userLogHandler, "f").call(this, 'warning', ...args);
}
error(...args) {
__classPrivateFieldGet(this, _InvocationContext_userLogHandler, "f").call(this, 'error', ...args);
}
}
exports.InvocationContext = InvocationContext;
_InvocationContext_userLogHandler = new WeakMap();
class InvocationContextExtraInputs {
constructor() {
_InvocationContextExtraInputs_inputs.set(this, {});
}
get(inputOrName) {
const name = typeof inputOrName === 'string' ? inputOrName : inputOrName.name;
return __classPrivateFieldGet(this, _InvocationContextExtraInputs_inputs, "f")[name];
}
set(inputOrName, value) {
const name = typeof inputOrName === 'string' ? inputOrName : inputOrName.name;
__classPrivateFieldGet(this, _InvocationContextExtraInputs_inputs, "f")[name] = value;
}
}
_InvocationContextExtraInputs_inputs = new WeakMap();
class InvocationContextExtraOutputs {
constructor() {
_InvocationContextExtraOutputs_outputs.set(this, {});
}
get(outputOrName) {
const name = typeof outputOrName === 'string' ? outputOrName : outputOrName.name;
return __classPrivateFieldGet(this, _InvocationContextExtraOutputs_outputs, "f")[name];
}
set(outputOrName, value) {
const name = typeof outputOrName === 'string' ? outputOrName : outputOrName.name;
__classPrivateFieldGet(this, _InvocationContextExtraOutputs_outputs, "f")[name] = value;
}
}
_InvocationContextExtraOutputs_outputs = new WeakMap();
/***/ }),
/***/ "./src/InvocationModel.ts":
/*!********************************!*\
!*** ./src/InvocationModel.ts ***!
\********************************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _InvocationModel_instances, _InvocationModel_isDone, _InvocationModel_coreCtx, _InvocationModel_functionName, _InvocationModel_bindings, _InvocationModel_triggerType, _InvocationModel_convertOutput, _InvocationModel_log, _InvocationModel_systemLog, _InvocationModel_userLog;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.InvocationModel = void 0;
const util_1 = __webpack_require__(/*! util */ "util");
const constants_1 = __webpack_require__(/*! ./constants */ "./src/constants.ts");
const fromRpcBindings_1 = __webpack_require__(/*! ./converters/fromRpcBindings */ "./src/converters/fromRpcBindings.ts");
const fromRpcContext_1 = __webpack_require__(/*! ./converters/fromRpcContext */ "./src/converters/fromRpcContext.ts");
const fromRpcTriggerMetadata_1 = __webpack_require__(/*! ./converters/fromRpcTriggerMetadata */ "./src/converters/fromRpcTriggerMetadata.ts");
const fromRpcTypedData_1 = __webpack_require__(/*! ./converters/fromRpcTypedData */ "./src/converters/fromRpcTypedData.ts");
const toCamelCase_1 = __webpack_require__(/*! ./converters/toCamelCase */ "./src/converters/toCamelCase.ts");
const toRpcHttp_1 = __webpack_require__(/*! ./converters/toRpcHttp */ "./src/converters/toRpcHttp.ts");
const toRpcTypedData_1 = __webpack_require__(/*! ./converters/toRpcTypedData */ "./src/converters/toRpcTypedData.ts");
const errors_1 = __webpack_require__(/*! ./errors */ "./src/errors.ts");
const httpProxy_1 = __webpack_require__(/*! ./http/httpProxy */ "./src/http/httpProxy.ts");
const HttpRequest_1 = __webpack_require__(/*! ./http/HttpRequest */ "./src/http/HttpRequest.ts");
const InvocationContext_1 = __webpack_require__(/*! ./InvocationContext */ "./src/InvocationContext.ts");
const setup_1 = __webpack_require__(/*! ./setup */ "./src/setup.ts");
const isTrigger_1 = __webpack_require__(/*! ./utils/isTrigger */ "./src/utils/isTrigger.ts");
const nonNull_1 = __webpack_require__(/*! ./utils/nonNull */ "./src/utils/nonNull.ts");
class InvocationModel {
constructor(coreCtx) {
_InvocationModel_instances.add(this);
_InvocationModel_isDone.set(this, false);
_InvocationModel_coreCtx.set(this, void 0);
_InvocationModel_functionName.set(this, void 0);
_InvocationModel_bindings.set(this, void 0);
_InvocationModel_triggerType.set(this, void 0);
__classPrivateFieldSet(this, _InvocationModel_coreCtx, coreCtx, "f");
__classPrivateFieldSet(this, _InvocationModel_functionName, (0, nonNull_1.nonNullProp)(coreCtx.metadata, 'name'), "f");
__classPrivateFieldSet(this, _InvocationModel_bindings, (0, nonNull_1.nonNullProp)(coreCtx.metadata, 'bindings'), "f");
const triggerBinding = (0, nonNull_1.nonNullValue)(Object.values(__classPrivateFieldGet(this, _InvocationModel_bindings, "f")).find((b) => (0, isTrigger_1.isTrigger)(b.type)), 'triggerBinding');
__classPrivateFieldSet(this, _InvocationModel_triggerType, (0, nonNull_1.nonNullProp)(triggerBinding, 'type'), "f");
}
// eslint-disable-next-line @typescript-eslint/require-await
getArguments() {
return __awaiter(this, void 0, void 0, function* () {
const req = __classPrivateFieldGet(this, _InvocationModel_coreCtx, "f").request;
const context = new InvocationContext_1.InvocationContext({
invocationId: (0, nonNull_1.nonNullProp)(__classPrivateFieldGet(this, _InvocationModel_coreCtx, "f"), 'invocationId'),
functionName: __classPrivateFieldGet(this, _InvocationModel_functionName, "f"),
logHandler: (level, ...args) => __classPrivateFieldGet(this, _InvocationModel_instances, "m", _InvocationModel_userLog).call(this, level, ...args),
retryContext: (0, fromRpcContext_1.fromRpcRetryContext)(req.retryContext),
traceContext: (0, fromRpcContext_1.fromRpcTraceContext)(req.traceContext),
triggerMetadata: (0, fromRpcTriggerMetadata_1.fromRpcTriggerMetadata)(req.triggerMetadata, __classPrivateFieldGet(this, _InvocationModel_triggerType, "f")),
options: (0, fromRpcBindings_1.fromRpcBindings)(__classPrivateFieldGet(this, _InvocationModel_bindings, "f")),
});
const inputs = [];
if (req.inputData) {
for (const binding of req.inputData) {
const bindingName = (0, nonNull_1.nonNullProp)(binding, 'name');
const rpcBinding = __classPrivateFieldGet(this, _InvocationModel_bindings, "f")[bindingName];
if (!rpcBinding) {
throw new errors_1.AzFuncSystemError(`Failed to find binding "${bindingName}" in bindings "${Object.keys(__classPrivateFieldGet(this, _InvocationModel_bindings, "f")).join(', ')}".`);
}
const bindingType = rpcBinding.type;
let input;
if ((0, isTrigger_1.isHttpTrigger)(bindingType) && setup_1.enableHttpStream) {
const proxyRequest = yield (0, httpProxy_1.waitForProxyRequest)(__classPrivateFieldGet(this, _InvocationModel_coreCtx, "f").invocationId);
input = (0, HttpRequest_1.createStreamRequest)(proxyRequest, (0, nonNull_1.nonNullProp)(req, 'triggerMetadata'));
}
else {
input = (0, fromRpcTypedData_1.fromRpcTypedData)(binding.data);
}
if ((0, isTrigger_1.isTimerTrigger)(bindingType)) {
input = (0, toCamelCase_1.toCamelCaseValue)(input);
}
if ((0, isTrigger_1.isTrigger)(bindingType)) {
inputs.push(input);
}
else {
context.extraInputs.set(bindingName, input);
}
}
}
return { context, inputs };
});
}
invokeFunction(context, inputs, handler) {
return __awaiter(this, void 0, void 0, function* () {
try {
return yield Promise.resolve(handler(...inputs, context));
}
finally {
__classPrivateFieldSet(this, _InvocationModel_isDone, true, "f");
}
});
}
getResponse(context, result) {
return __awaiter(this, void 0, void 0, function* () {
const response = { invocationId: __classPrivateFieldGet(this, _InvocationModel_coreCtx, "f").invocationId };
response.outputData = [];
let usedReturnValue = false;
for (const [name, binding] of Object.entries(__classPrivateFieldGet(this, _InvocationModel_bindings, "f"))) {
if (binding.direction === 'out') {
if (name === constants_1.returnBindingKey) {
response.returnValue = yield __classPrivateFieldGet(this, _InvocationModel_instances, "m", _InvocationModel_convertOutput).call(this, context.invocationId, binding, result);
usedReturnValue = true;
}
else {
const outputValue = yield __classPrivateFieldGet(this, _InvocationModel_instances, "m", _InvocationModel_convertOutput).call(this, context.invocationId, binding, context.extraOutputs.get(name));
if ((0, nonNull_1.isDefined)(outputValue)) {
response.outputData.push({ name, data: outputValue });
}
}
}
}
// This allows the return value of non-HTTP triggered functions to be passed back
// to the host, even if no explicit output binding is set. In most cases, this is ignored,
// but e.g., Durable uses this to pass orchestrator state back to the Durable extension, w/o
// an explicit output binding. See here for more details: https://github.com/Azure/azure-functions-nodejs-library/pull/25
if (!usedReturnValue && !(0, isTrigger_1.isHttpTrigger)(__classPrivateFieldGet(this, _InvocationModel_triggerType, "f"))) {
response.returnValue = (0, toRpcTypedData_1.toRpcTypedData)(result);
}
return response;
});
}
}
exports.InvocationModel = InvocationModel;
_InvocationModel_isDone = new WeakMap(), _InvocationModel_coreCtx = new WeakMap(), _InvocationModel_functionName = new WeakMap(), _InvocationModel_bindings = new WeakMap(), _InvocationModel_triggerType = new WeakMap(), _InvocationModel_instances = new WeakSet(), _InvocationModel_convertOutput = function _InvocationModel_convertOutput(invocationId, binding, value) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (((_a = binding.type) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'http') {
return (0, toRpcHttp_1.toRpcHttp)(invocationId, value);
}
else {
return (0, toRpcTypedData_1.toRpcTypedData)(value);
}
});
}, _InvocationModel_log = function _InvocationModel_log(level, logCategory, ...args) {
__classPrivateFieldGet(this, _InvocationModel_coreCtx, "f").log(level, logCategory, (0, util_1.format)(...args));
}, _InvocationModel_systemLog = function _InvocationModel_systemLog(level, ...args) {
__classPrivateFieldGet(this, _InvocationModel_instances, "m", _InvocationModel_log).call(this, level, 'system', ...args);
}, _InvocationModel_userLog = function _InvocationModel_userLog(level, ...args) {
if (__classPrivateFieldGet(this, _InvocationModel_isDone, "f") && __classPrivateFieldGet(this, _InvocationModel_coreCtx, "f").state !== 'postInvocationHooks') {
let badAsyncMsg = "Warning: Unexpected call to 'log' on the context object after function execution has completed. Please check for asynchronous calls that are not awaited. ";
badAsyncMsg += `Function name: ${__classPrivateFieldGet(this, _InvocationModel_functionName, "f")}. Invocation Id: ${__classPrivateFieldGet(this, _InvocationModel_coreCtx, "f").invocationId}.`;
__classPrivateFieldGet(this, _InvocationModel_instances, "m", _InvocationModel_systemLog).call(this, 'warning', badAsyncMsg);
}
__classPrivateFieldGet(this, _InvocationModel_instances, "m", _InvocationModel_log).call(this, level, 'user', ...args);
};
/***/ }),
/***/ "./src/ProgrammingModel.ts":
/*!*********************************!*\
!*** ./src/ProgrammingModel.ts ***!
\*********************************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.ProgrammingModel = void 0;
const constants_1 = __webpack_require__(/*! ./constants */ "./src/constants.ts");
const httpProxy_1 = __webpack_require__(/*! ./http/httpProxy */ "./src/http/httpProxy.ts");
const InvocationModel_1 = __webpack_require__(/*! ./InvocationModel */ "./src/InvocationModel.ts");
const setup_1 = __webpack_require__(/*! ./setup */ "./src/setup.ts");
class ProgrammingModel {
constructor() {
this.name = '@azure/functions';
this.version = constants_1.version;
}
getInvocationModel(coreCtx) {
return new InvocationModel_1.InvocationModel(coreCtx);
}
getCapabilities(workerCapabilities) {
return __awaiter(this, void 0, void 0, function* () {
(0, setup_1.lockSetup)();
if (setup_1.enableHttpStream) {
const httpUri = yield (0, httpProxy_1.setupHttpProxy)();
workerCapabilities.HttpUri = httpUri;
}
Object.assign(workerCapabilities, setup_1.capabilities);
return workerCapabilities;
});
}
}
exports.ProgrammingModel = ProgrammingModel;
/***/ }),
/***/ "./src/addBindingName.ts":
/*!*******************************!*\
!*** ./src/addBindingName.ts ***!
\*******************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.addBindingName = void 0;
const getRandomHexString_1 = __webpack_require__(/*! ./utils/getRandomHexString */ "./src/utils/getRandomHexString.ts");
/**
* If the host spawns multiple workers, it expects the metadata (including binding name) to be the same across workers.
* That means we need to generate binding names in a deterministic fashion, so we'll do that using a string hash of the binding data
* A few considerations:
* 1. We will include the binding type in the name to make it more readable
* 2. Users can manually specify the name themselves and we will respect that
* 3. The only time the hash should cause a conflict is if a single function has duplicate bindings. Not sure why someone would do that, but we will throw an error at function registration time
* More info here: https://github.com/Azure/azure-functions-nodejs-worker/issues/638
*/
function addBindingName(binding, suffix) {
if (!binding.name) {
let bindingType = binding.type;
if (!bindingType.toLowerCase().endsWith(suffix.toLowerCase())) {
bindingType += suffix;
}
binding.name = bindingType + (0, getRandomHexString_1.getStringHash)(JSON.stringify(binding));
}
return binding;
}
exports.addBindingName = addBindingName;
/***/ }),
/***/ "./src/app.ts":
/*!********************!*\
!*** ./src/app.ts ***!
\********************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.generic = exports.webPubSub = exports.mySql = exports.sql = exports.warmup = exports.cosmosDB = exports.eventGrid = exports.eventHub = exports.serviceBusTopic = exports.serviceBusQueue = exports.storageQueue = exports.storageBlob = exports.timer = exports.http = exports.deleteRequest = exports.patch = exports.post = exports.put = exports.get = exports.setup = exports.hook = void 0;
const toCoreFunctionMetadata_1 = __webpack_require__(/*! ./converters/toCoreFunctionMetadata */ "./src/converters/toCoreFunctionMetadata.ts");
const output = __webpack_require__(/*! ./output */ "./src/output.ts");
const ProgrammingModel_1 = __webpack_require__(/*! ./ProgrammingModel */ "./src/ProgrammingModel.ts");
const trigger = __webpack_require__(/*! ./trigger */ "./src/trigger.ts");
const tryGetCoreApiLazy_1 = __webpack_require__(/*! ./utils/tryGetCoreApiLazy */ "./src/utils/tryGetCoreApiLazy.ts");
exports.hook = __webpack_require__(/*! ./hooks/registerHook */ "./src/hooks/registerHook.ts");
var setup_1 = __webpack_require__(/*! ./setup */ "./src/setup.ts");
Object.defineProperty(exports, "setup", ({ enumerable: true, get: function () { return setup_1.setup; } }));
let hasSetModel = false;
function setProgrammingModel() {
const coreApi = (0, tryGetCoreApiLazy_1.tryGetCoreApiLazy)();
if (!coreApi) {
console.warn('WARNING: Failed to detect the Azure Functions runtime. Switching "@azure/functions" package to test mode - not all features are supported.');
}
else {
coreApi.setProgrammingModel(new ProgrammingModel_1.ProgrammingModel());
}
hasSetModel = true;
}
function convertToHttpOptions(optionsOrHandler, method) {
const options = typeof optionsOrHandler === 'function' ? { handler: optionsOrHandler } : optionsOrHandler;
options.methods = [method];
return options;
}
function convertToGenericOptions(options, triggerMethod) {
const { handler, return: ret, trigger, extraInputs, extraOutputs, retry } = options, triggerOptions = __rest(options, ["handler", "return", "trigger", "extraInputs", "extraOutputs", "retry"]);
return {
trigger: trigger !== null && trigger !== void 0 ? trigger : triggerMethod(triggerOptions),
return: ret,
retry,
extraInputs,
extraOutputs,
handler,
};
}
function get(name, optionsOrHandler) {
http(name, convertToHttpOptions(optionsOrHandler, 'GET'));
}
exports.get = get;
function put(name, optionsOrHandler) {
http(name, convertToHttpOptions(optionsOrHandler, 'PUT'));
}
exports.put = put;
function post(name, optionsOrHandler) {
http(name, convertToHttpOptions(optionsOrHandler, 'POST'));
}
exports.post = post;
function patch(name, optionsOrHandler) {
http(name, convertToHttpOptions(optionsOrHandler, 'PATCH'));
}
exports.patch = patch;
function deleteRequest(name, optionsOrHandler) {
http(name, convertToHttpOptions(optionsOrHandler, 'DELETE'));
}
exports.deleteRequest = deleteRequest;
function http(name, options) {
options.return || (options.return = output.http({}));
generic(name, convertToGenericOptions(options, trigger.http));
}
exports.http = http;
function timer(name, options) {
generic(name, convertToGenericOptions(options, trigger.timer));
}
exports.timer = timer;
function storageBlob(name, options) {
generic(name, convertToGenericOptions(options, trigger.storageBlob));
}
exports.storageBlob = storageBlob;
function storageQueue(name, options) {
generic(name, convertToGenericOptions(options, trigger.storageQueue));
}
exports.storageQueue = storageQueue;
function serviceBusQueue(name, options) {
generic(name, convertToGenericOptions(options, trigger.serviceBusQueue));
}
exports.serviceBusQueue = serviceBusQueue;
function serviceBusTopic(name, options) {
generic(name, convertToGenericOptions(options, trigger.serviceBusTopic));
}
exports.serviceBusTopic = serviceBusTopic;
function eventHub(name, options) {
generic(name, convertToGenericOptions(options, trigger.eventHub));
}
exports.eventHub = eventHub;
function eventGrid(name, options) {
generic(name, convertToGenericOptions(options, trigger.eventGrid));
}
exports.eventGrid = eventGrid;
function cosmosDB(name, options) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
generic(name, convertToGenericOptions(options, trigger.cosmosDB));
}
exports.cosmosDB = cosmosDB;
function warmup(name, options) {
generic(name, convertToGenericOptions(options, trigger.warmup));
}
exports.warmup = warmup;
function sql(name, options) {
generic(name, convertToGenericOptions(options, trigger.sql));
}
exports.sql = sql;
function mySql(name, options) {
generic(name, convertToGenericOptions(options, trigger.mySql));
}
exports.mySql = mySql;
function webPubSub(name, options) {
generic(name, convertToGenericOptions(options, trigger.webPubSub));
}
exports.webPubSub = webPubSub;
function generic(name, options) {
if (!hasSetModel) {
setProgrammingModel();
}
const coreApi = (0, tryGetCoreApiLazy_1.tryGetCoreApiLazy)();
if (!coreApi) {
console.warn(`WARNING: Skipping call to register function "${name}" because the "@azure/functions" package is in test mode.`);
}
else {
coreApi.registerFunction((0, toCoreFunctionMetadata_1.toCoreFunctionMetadata)(name, options), options.handler);
}
}
exports.generic = generic;
/***/ }),
/***/ "./src/constants.ts":
/*!**************************!*\
!*** ./src/constants.ts ***!
\**************************/
/***/ ((__unused_webpack_module, exports) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.returnBindingKey = exports.version = void 0;
exports.version = '4.7.0';
exports.returnBindingKey = '$return';
/***/ }),
/***/ "./src/converters/fromRpcBindings.ts":
/*!*******************************************!*\
!*** ./src/converters/fromRpcBindings.ts ***!
\*******************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.fromRpcBindings = void 0;
const constants_1 = __webpack_require__(/*! ../constants */ "./src/constants.ts");
const isTrigger_1 = __webpack_require__(/*! ../utils/isTrigger */ "./src/utils/isTrigger.ts");
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
function fromRpcBindings(bindings) {
let trigger;
let returnBinding;
const extraInputs = [];
const extraOutputs = [];
for (const [name, binding] of Object.entries((0, nonNull_1.nonNullValue)(bindings, 'bindings'))) {
if ((0, isTrigger_1.isTrigger)(binding.type)) {
trigger = fromRpcBinding(name, binding);
}
else if (name === constants_1.returnBindingKey) {
returnBinding = fromRpcBinding(name, binding);
}
else if (binding.direction === 'in') {
extraInputs.push(fromRpcBinding(name, binding));
}
else if (binding.direction === 'out') {
extraOutputs.push(fromRpcBinding(name, binding));
}
}
return {
trigger: (0, nonNull_1.nonNullValue)(trigger, 'trigger'),
return: returnBinding,
extraInputs,
extraOutputs,
};
}
exports.fromRpcBindings = fromRpcBindings;
function fromRpcBinding(name, binding) {
return Object.assign(Object.assign({}, binding), { type: (0, nonNull_1.nonNullProp)(binding, 'type'), name });
}
/***/ }),
/***/ "./src/converters/fromRpcContext.ts":
/*!******************************************!*\
!*** ./src/converters/fromRpcContext.ts ***!
\******************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.fromRpcTraceContext = exports.fromRpcRetryContext = void 0;
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
function fromRpcRetryContext(retryContext) {
if (!retryContext) {
return undefined;
}
else {
const result = {
retryCount: (0, nonNull_1.nonNullProp)(retryContext, 'retryCount'),
maxRetryCount: (0, nonNull_1.nonNullProp)(retryContext, 'maxRetryCount'),
};
if (retryContext.exception) {
result.exception = fromRpcException(retryContext.exception);
}
return result;
}
}
exports.fromRpcRetryContext = fromRpcRetryContext;
function fromRpcException(exception) {
const result = {};
(0, nonNull_1.copyPropIfDefined)(exception, result, 'message');
(0, nonNull_1.copyPropIfDefined)(exception, result, 'source');
(0, nonNull_1.copyPropIfDefined)(exception, result, 'stackTrace');
return result;
}
function fromRpcTraceContext(traceContext) {
if (!traceContext) {
return undefined;
}
else {
const result = {};
(0, nonNull_1.copyPropIfDefined)(traceContext, result, 'traceParent');
(0, nonNull_1.copyPropIfDefined)(traceContext, result, 'traceState');
if (traceContext.attributes) {
result.attributes = traceContext.attributes;
}
return result;
}
}
exports.fromRpcTraceContext = fromRpcTraceContext;
/***/ }),
/***/ "./src/converters/fromRpcNullable.ts":
/*!*******************************************!*\
!*** ./src/converters/fromRpcNullable.ts ***!
\*******************************************/
/***/ ((__unused_webpack_module, exports) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.fromNullableMapping = void 0;
function fromNullableMapping(nullableMapping, originalMapping) {
var _a;
let converted = {};
if (nullableMapping && Object.keys(nullableMapping).length > 0) {
for (const key in nullableMapping) {
converted[key] = ((_a = nullableMapping[key]) === null || _a === void 0 ? void 0 : _a.value) || '';
}
}
else if (originalMapping && Object.keys(originalMapping).length > 0) {
converted = originalMapping;
}
return converted;
}
exports.fromNullableMapping = fromNullableMapping;
/***/ }),
/***/ "./src/converters/fromRpcTriggerMetadata.ts":
/*!**************************************************!*\
!*** ./src/converters/fromRpcTriggerMetadata.ts ***!
\**************************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.fromRpcTriggerMetadata = void 0;
const isTrigger_1 = __webpack_require__(/*! ../utils/isTrigger */ "./src/utils/isTrigger.ts");
const fromRpcTypedData_1 = __webpack_require__(/*! ./fromRpcTypedData */ "./src/converters/fromRpcTypedData.ts");
const toCamelCase_1 = __webpack_require__(/*! ./toCamelCase */ "./src/converters/toCamelCase.ts");
function fromRpcTriggerMetadata(triggerMetadata, triggerType) {
// For http and timer triggers, we will avoid using `triggerMetadata` for a few reasons:
// 1. It uses `toCamelCase` methods, which can lead to weird casing bugs
// 2. It's generally a large medley of properties that is difficult for us to document/type
// 3. We can represent that information on the request & timer objects instead
if (!triggerMetadata || (0, isTrigger_1.isHttpTrigger)(triggerType) || (0, isTrigger_1.isTimerTrigger)(triggerType)) {
return undefined;
}
else {
const result = {};
for (const [key, value] of Object.entries(triggerMetadata)) {
result[(0, toCamelCase_1.toCamelCaseKey)(key)] = (0, toCamelCase_1.toCamelCaseValue)((0, fromRpcTypedData_1.fromRpcTypedData)(value));
}
return result;
}
}
exports.fromRpcTriggerMetadata = fromRpcTriggerMetadata;
/***/ }),
/***/ "./src/converters/fromRpcTypedData.ts":
/*!********************************************!*\
!*** ./src/converters/fromRpcTypedData.ts ***!
\********************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.fromRpcTypedData = void 0;
const HttpRequest_1 = __webpack_require__(/*! ../http/HttpRequest */ "./src/http/HttpRequest.ts");
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
function fromRpcTypedData(data) {
if (!data) {
return undefined;
}
else if ((0, nonNull_1.isDefined)(data.string)) {
return tryJsonParse(data.string);
}
else if ((0, nonNull_1.isDefined)(data.json)) {
return JSON.parse(data.json);
}
else if ((0, nonNull_1.isDefined)(data.bytes)) {
return Buffer.from(data.bytes);
}
else if ((0, nonNull_1.isDefined)(data.stream)) {
return Buffer.from(data.stream);
}
else if ((0, nonNull_1.isDefined)(data.http)) {
return new HttpRequest_1.HttpRequest(data.http);
}
else if ((0, nonNull_1.isDefined)(data.int)) {
return data.int;
}
else if ((0, nonNull_1.isDefined)(data.double)) {
return data.double;
}
else if (data.collectionBytes && (0, nonNull_1.isDefined)(data.collectionBytes.bytes)) {
return data.collectionBytes.bytes.map((d) => Buffer.from(d));
}
else if (data.collectionString && (0, nonNull_1.isDefined)(data.collectionString.string)) {
return data.collectionString.string.map(tryJsonParse);
}
else if (data.collectionDouble && (0, nonNull_1.isDefined)(data.collectionDouble.double)) {
return data.collectionDouble.double;
}
else if (data.collectionSint64 && (0, nonNull_1.isDefined)(data.collectionSint64.sint64)) {
return data.collectionSint64.sint64;
}
else {
return undefined;
}
}
exports.fromRpcTypedData = fromRpcTypedData;
function tryJsonParse(data) {
try {
return JSON.parse(data);
}
catch (_a) {
return data;
}
}
/***/ }),
/***/ "./src/converters/toCamelCase.ts":
/*!***************************************!*\
!*** ./src/converters/toCamelCase.ts ***!
\***************************************/
/***/ ((__unused_webpack_module, exports) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.toCamelCaseKey = exports.toCamelCaseValue = void 0;
function toCamelCaseValue(data) {
if (typeof data !== 'object' || data === null) {
return data;
}
else if (Array.isArray(data)) {
return data.map(toCamelCaseValue);
}
else {
const result = {};
for (const [key, value] of Object.entries(data)) {
result[toCamelCaseKey(key)] = toCamelCaseValue(value);
}
return result;
}
}
exports.toCamelCaseValue = toCamelCaseValue;
function toCamelCaseKey(key) {
return key.charAt(0).toLowerCase() + key.slice(1);
}
exports.toCamelCaseKey = toCamelCaseKey;
/***/ }),
/***/ "./src/converters/toCoreFunctionMetadata.ts":
/*!**************************************************!*\
!*** ./src/converters/toCoreFunctionMetadata.ts ***!
\**************************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.toCoreFunctionMetadata = void 0;
const constants_1 = __webpack_require__(/*! ../constants */ "./src/constants.ts");
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
const isTrigger_1 = __webpack_require__(/*! ../utils/isTrigger */ "./src/utils/isTrigger.ts");
const toRpcDuration_1 = __webpack_require__(/*! ./toRpcDuration */ "./src/converters/toRpcDuration.ts");
function toCoreFunctionMetadata(name, options) {
const bindings = {};
const bindingNames = [];
const trigger = options.trigger;
bindings[trigger.name] = Object.assign(Object.assign({}, trigger), { direction: 'in', type: (0, isTrigger_1.isTrigger)(trigger.type) ? trigger.type : trigger.type + 'Trigger' });
bindingNames.push(trigger.name);
if (options.extraInputs) {
for (const input of options.extraInputs) {
bindings[input.name] = Object.assign(Object.assign({}, input), { direction: 'in' });
bindingNames.push(input.name);
}
}
if (options.return) {
bindings[constants_1.returnBindingKey] = Object.assign(Object.assign({}, options.return), { direction: 'out' });
bindingNames.push(constants_1.returnBindingKey);
}
if (options.extraOutputs) {
for (const output of options.extraOutputs) {
bindings[output.name] = Object.assign(Object.assign({}, output), { direction: 'out' });
bindingNames.push(output.name);
}
}
const dupeBindings = bindingNames.filter((v, i) => bindingNames.indexOf(v) !== i);
if (dupeBindings.length > 0) {
throw new errors_1.AzFuncSystemError(`Duplicate bindings found for function "${name}". Remove a duplicate binding or manually specify the "name" property to make it unique.`);
}
let retryOptions;
if (options.retry) {
retryOptions = Object.assign(Object.assign({}, options.retry), { retryStrategy: options.retry.strategy, delayInterval: (0, toRpcDuration_1.toRpcDuration)(options.retry.delayInterval, 'retry.delayInterval'), maximumInterval: (0, toRpcDuration_1.toRpcDuration)(options.retry.maximumInterval, 'retry.maximumInterval'), minimumInterval: (0, toRpcDuration_1.toRpcDuration)(options.retry.minimumInterval, 'retry.minimumInterval') });
}
return { name, bindings, retryOptions };
}
exports.toCoreFunctionMetadata = toCoreFunctionMetadata;
/***/ }),
/***/ "./src/converters/toRpcDuration.ts":
/*!*****************************************!*\
!*** ./src/converters/toRpcDuration.ts ***!
\*****************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.toRpcDuration = void 0;
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
function toRpcDuration(dateTime, propertyName) {
if ((0, nonNull_1.isDefined)(dateTime)) {
try {
let timeInMilliseconds;
if (typeof dateTime === 'object') {
const minutes = (dateTime.minutes || 0) + (dateTime.hours || 0) * 60;
const seconds = (dateTime.seconds || 0) + minutes * 60;
timeInMilliseconds = (dateTime.milliseconds || 0) + seconds * 1000;
}
else if (typeof dateTime === 'number') {
timeInMilliseconds = dateTime;
}
if ((0, nonNull_1.isDefined)(timeInMilliseconds) && timeInMilliseconds >= 0) {
return {
seconds: Math.round(timeInMilliseconds / 1000),
};
}
}
catch (_a) {
// fall through
}
throw new errors_1.AzFuncSystemError(`A 'number' or 'Duration' object was expected instead of a '${typeof dateTime}'. Cannot parse value of '${propertyName}'.`);
}
return undefined;
}
exports.toRpcDuration = toRpcDuration;
/***/ }),
/***/ "./src/converters/toRpcHttp.ts":
/*!*************************************!*\
!*** ./src/converters/toRpcHttp.ts ***!
\*************************************/
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.toRpcHttp = void 0;
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
const httpProxy_1 = __webpack_require__(/*! ../http/httpProxy */ "./src/http/httpProxy.ts");
const HttpResponse_1 = __webpack_require__(/*! ../http/HttpResponse */ "./src/http/HttpResponse.ts");
const setup_1 = __webpack_require__(/*! ../setup */ "./src/setup.ts");
const toRpcHttpCookie_1 = __webpack_require__(/*! ./toRpcHttpCookie */ "./src/converters/toRpcHttpCookie.ts");
const toRpcTypedData_1 = __webpack_require__(/*! ./toRpcTypedData */ "./src/converters/toRpcTypedData.ts");
function toRpcHttp(invocationId, data) {
return __awaiter(this, void 0, void 0, function* () {
if (data === null || data === undefined) {
return data;
}
else if (typeof data !== 'object') {
throw new errors_1.AzFuncSystemError('The HTTP response must be an object with optional properties "body", "status", "headers", and "cookies".');
}
const response = data instanceof HttpResponse_1.HttpResponse ? data : new HttpResponse_1.HttpResponse(data);
if (setup_1.enableHttpStream) {
// send http data over http proxy instead of rpc
yield (0, httpProxy_1.sendProxyResponse)(invocationId, response);
return;
}
const rpcResponse = {};
rpcResponse.statusCode = response.status.toString();
rpcResponse.headers = {};
for (const [key, value] of response.headers.entries()) {
rpcResponse.headers[key] = value;
}
rpcResponse.cookies = [];
for (const cookie of response.cookies) {
rpcResponse.cookies.push((0, toRpcHttpCookie_1.toRpcHttpCookie)(cookie));
}
rpcResponse.enableContentNegotiation = response.enableContentNegotiation;
const bodyBytes = yield response.arrayBuffer();
rpcResponse.body = (0, toRpcTypedData_1.toRpcTypedData)(bodyBytes);
return { http: rpcResponse };
});
}
exports.toRpcHttp = toRpcHttp;
/***/ }),
/***/ "./src/converters/toRpcHttpCookie.ts":
/*!*******************************************!*\
!*** ./src/converters/toRpcHttpCookie.ts ***!
\*******************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.toRpcHttpCookie = void 0;
const toRpcNullable_1 = __webpack_require__(/*! ./toRpcNullable */ "./src/converters/toRpcNullable.ts");
/**
* From RFC specifications for 'Set-Cookie' response header: https://www.rfc-editor.org/rfc/rfc6265.txt
* @param inputCookie
*/
function toRpcHttpCookie(inputCookie) {
// Resolve RpcHttpCookie.SameSite enum, a one-off
let rpcSameSite = 'none';
if (inputCookie && inputCookie.sameSite) {
const sameSite = inputCookie.sameSite.toLocaleLowerCase();
if (sameSite === 'lax') {
rpcSameSite = 'lax';
}
else if (sameSite === 'strict') {
rpcSameSite = 'strict';
}
else if (sameSite === 'none') {
rpcSameSite = 'explicitNone';
}
}
const rpcCookie = {
name: inputCookie && (0, toRpcNullable_1.toRpcString)(inputCookie.name, 'cookie.name'),
value: inputCookie && (0, toRpcNullable_1.toRpcString)(inputCookie.value, 'cookie.value'),
domain: (0, toRpcNullable_1.toNullableString)(inputCookie && inputCookie.domain, 'cookie.domain'),
path: (0, toRpcNullable_1.toNullableString)(inputCookie && inputCookie.path, 'cookie.path'),
expires: (0, toRpcNullable_1.toNullableTimestamp)(inputCookie && inputCookie.expires, 'cookie.expires'),
secure: (0, toRpcNullable_1.toNullableBool)(inputCookie && inputCookie.secure, 'cookie.secure'),
httpOnly: (0, toRpcNullable_1.toNullableBool)(inputCookie && inputCookie.httpOnly, 'cookie.httpOnly'),
sameSite: rpcSameSite,
maxAge: (0, toRpcNullable_1.toNullableDouble)(inputCookie && inputCookie.maxAge, 'cookie.maxAge'),
};
return rpcCookie;
}
exports.toRpcHttpCookie = toRpcHttpCookie;
/***/ }),
/***/ "./src/converters/toRpcNullable.ts":
/*!*****************************************!*\
!*** ./src/converters/toRpcNullable.ts ***!
\*****************************************/
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.toNullableTimestamp = exports.toNullableString = exports.toRpcString = exports.toNullableDouble = exports.toNullableBool = void 0;
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
/**
* Converts boolean input to an 'INullableBool' to be sent through the RPC layer.
* Input that is not a boolean but is also not null or undefined logs a function app level warning.
* @param nullable Input to be converted to an INullableBool if it is a valid boolean
* @param propertyName The name of the property that the caller will assign the output to. Used for debugging.
*/
function toNullableBool(nullable, propertyName) {
if (typeof nullable === 'boolean') {
return {
value: nullable,
};
}
if ((0, nonNull_1.isDefined)(nullable)) {
throw new errors_1.AzFuncSystemError(`A 'boolean'