@azure/functions
Version:
Microsoft Azure Functions NodeJS Framework
2,846 lines • 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' type was expected instead of a '${typeof nullable}' type. Cannot parse value of '${propertyName}'.`);
}
return undefined;
}
exports.toNullableBool = toNullableBool;
/**
* Converts number or string that parses to a number to an 'INullableDouble' to be sent through the RPC layer.
* Input that is not a valid number but is also not null or undefined logs a function app level warning.
* @param nullable Input to be converted to an INullableDouble if it is a valid number
* @param propertyName The name of the property that the caller will assign the output to. Used for debugging.
*/
function toNullableDouble(nullable, propertyName) {
if (typeof nullable === 'number') {
return {
value: nullable,
};
}
else if (typeof nullable === 'string') {
if (!isNaN(Number(nullable))) {
const parsedNumber = parseFloat(nullable);
return {
value: parsedNumber,
};
}
}
if ((0, nonNull_1.isDefined)(nullable)) {
throw new errors_1.AzFuncSystemError(`A 'number' type was expected instead of a '${typeof nullable}' type. Cannot parse value of '${propertyName}'.`);
}
return undefined;
}
exports.toNullableDouble = toNullableDouble;
/**
* Converts string input to an 'INullableString' to be sent through the RPC layer.
* Input that is not a string but is also not null or undefined logs a function app level warning.
* @param nullable Input to be converted to an INullableString if it is a valid string
* @param propertyName The name of the property that the caller will assign the output to. Used for debugging.
*/
function toRpcString(nullable, propertyName) {
if (typeof nullable === 'string') {
return nullable;
}
if ((0, nonNull_1.isDefined)(nullable)) {
throw new errors_1.AzFuncSystemError(`A 'string' type was expected instead of a '${typeof nullable}' type. Cannot parse value of '${propertyName}'.`);
}
return '';
}
exports.toRpcString = toRpcString;
/**
* Converts string input to an 'INullableString' to be sent through the RPC layer.
* Input that is not a string but is also not null or undefined logs a function app level warning.
* @param nullable Input to be converted to an INullableString if it is a valid string
* @param propertyName The name of the property that the caller will assign the output to. Used for debugging.
*/
function toNullableString(nullable, propertyName) {
if (typeof nullable === 'string') {
return {
value: nullable,
};
}
if ((0, nonNull_1.isDefined)(nullable)) {
throw new errors_1.AzFuncSystemError(`A 'string' type was expected instead of a '${typeof nullable}' type. Cannot parse value of '${propertyName}'.`);
}
return undefined;
}
exports.toNullableString = toNullableString;
/**
* Converts Date or number input to an 'INullableTimestamp' to be sent through the RPC layer.
* Input that is not a Date or number but is also not null or undefined logs a function app level warning.
* @param nullable Input to be converted to an INullableTimestamp if it is valid input
* @param propertyName The name of the property that the caller will assign the output to. Used for debugging.
*/
function toNullableTimestamp(dateTime, propertyName) {
if ((0, nonNull_1.isDefined)(dateTime)) {
try {
const timeInMilliseconds = typeof dateTime === 'number' ? dateTime : dateTime.getTime();
if (timeInMilliseconds && timeInMilliseconds >= 0) {
return {
value: {
seconds: Math.round(timeInMilliseconds / 1000),
},
};
}
}
catch (_a) {
throw new errors_1.AzFuncSystemError(`A 'number' or 'Date' input was expected instead of a '${typeof dateTime}'. Cannot parse value of '${propertyName}'.`);
}
}
return undefined;
}
exports.toNullableTimestamp = toNullableTimestamp;
/***/ }),
/***/ "./src/converters/toRpcTypedData.ts":
/*!******************************************!*\
!*** ./src/converters/toRpcTypedData.ts ***!
\******************************************/
/***/ ((__unused_webpack_module, exports) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.toRpcTypedData = void 0;
function toRpcTypedData(data) {
if (data === null || data === undefined) {
return data;
}
else if (typeof data === 'string') {
return { string: data };
}
else if (Buffer.isBuffer(data)) {
return { bytes: data };
}
else if (ArrayBuffer.isView(data)) {
const bytes = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
return { bytes: bytes };
}
else if (data instanceof ArrayBuffer) {
const bytes = new Uint8Array(data);
return { bytes: bytes };
}
else if (typeof data === 'number') {
if (Number.isInteger(data)) {
return { int: data };
}
else {
return { double: data };
}
}
else {
return { json: JSON.stringify(data) };
}
}
exports.toRpcTypedData = toRpcTypedData;
/***/ }),
/***/ "./src/errors.ts":
/*!***********************!*\
!*** ./src/errors.ts ***!
\***********************/
/***/ ((__unused_webpack_module, exports) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isError = exports.trySetErrorMessage = exports.ensureErrorType = exports.ReadOnlyError = exports.AzFuncRangeError = exports.AzFuncTypeError = exports.AzFuncSystemError = void 0;
class AzFuncSystemError extends Error {
constructor() {
super(...arguments);
this.isAzureFunctionsSystemError = true;
}
}
exports.AzFuncSystemError = AzFuncSystemError;
class AzFuncTypeError extends TypeError {
constructor() {
super(...arguments);
this.isAzureFunctionsSystemError = true;
}
}
exports.AzFuncTypeError = AzFuncTypeError;
class AzFuncRangeError extends RangeError {
constructor() {
super(...arguments);
this.isAzureFunctionsSystemError = true;
}
}
exports.AzFuncRangeError = AzFuncRangeError;
class ReadOnlyError extends AzFuncTypeError {
constructor(propertyName) {
super(`Cannot assign to read only property '${propertyName}'`);
}
}
exports.ReadOnlyError = ReadOnlyError;
function ensureErrorType(err) {
if (err instanceof Error) {
return err;
}
else {
let message;
if (err === undefined || err === null) {
message = 'Unknown error';
}
else if (typeof err === 'string') {
message = err;
}
else if (typeof err === 'object') {
message = JSON.stringify(err);
}
else {
message = String(err);
}
return new Error(message);
}
}
exports.ensureErrorType = ensureErrorType;
function trySetErrorMessage(err, message) {
try {
err.message = message;
}
catch (_a) {
// If we can't set the message, we'll keep the error as is
}
}
exports.trySetErrorMessage = trySetErrorMessage;
/**
* This is mostly for callbacks where `null` or `undefined` indicates there is no error
* By contrast, anything thrown/caught is assumed to be an error regardless of what it is
*/
function isError(err) {
return err !== null && err !== undefined;
}
exports.isError = isError;
/***/ }),
/***/ "./src/hooks/AppStartContext.ts":
/*!**************************************!*\
!*** ./src/hooks/AppStartContext.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.AppStartContext = void 0;
const HookContext_1 = __webpack_require__(/*! ./HookContext */ "./src/hooks/HookContext.ts");
class AppStartContext extends HookContext_1.HookContext {
}
exports.AppStartContext = AppStartContext;
/***/ }),
/***/ "./src/hooks/AppTerminateContext.ts":
/*!******************************************!*\
!*** ./src/hooks/AppTerminateContext.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.AppTerminateContext = void 0;
const HookContext_1 = __webpack_require__(/*! ./HookContext */ "./src/hooks/HookContext.ts");
class AppTerminateContext extends HookContext_1.HookContext {
}
exports.AppTerminateContext = AppTerminateContext;
/***/ }),
/***/ "./src/hooks/HookContext.ts":
/*!**********************************!*\
!*** ./src/hooks/HookContext.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 _HookContext_init;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.HookContext = void 0;
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
class HookContext {
constructor(init) {
var _a;
var _b;
_HookContext_init.set(this, void 0);
__classPrivateFieldSet(this, _HookContext_init, init !== null && init !== void 0 ? init : {}, "f");
(_a = (_b = __classPrivateFieldGet(this, _HookContext_init, "f")).hookData) !== null && _a !== void 0 ? _a : (_b.hookData = {});
}
get hookData() {
return (0, nonNull_1.nonNullProp)(__classPrivateFieldGet(this, _HookContext_init, "f"), 'hookData');
}
set hookData(_value) {
throw new errors_1.ReadOnlyError('hookData');
}
}
exports.HookContext = HookContext;
_HookContext_init = new WeakMap();
/***/ }),
/***/ "./src/hooks/InvocationHookContext.ts":
/*!********************************************!*\
!*** ./src/hooks/InvocationHookContext.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 _InvocationHookContext_init;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.InvocationHookContext = void 0;
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
const InvocationContext_1 = __webpack_require__(/*! ../InvocationContext */ "./src/InvocationContext.ts");
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
const HookContext_1 = __webpack_require__(/*! ./HookContext */ "./src/hooks/HookContext.ts");
class InvocationHookContext extends HookContext_1.HookContext {
constructor(init) {
var _a, _b;
var _c, _d;
super(init);
_InvocationHookContext_init.set(this, void 0);
__classPrivateFieldSet(this, _InvocationHookContext_init, init !== null && init !== void 0 ? init : {}, "f");
(_a = (_c = __classPrivateFieldGet(this, _InvocationHookContext_init, "f")).inputs) !== null && _a !== void 0 ? _a : (_c.inputs = []);
(_b = (_d = __classPrivateFieldGet(this, _InvocationHookContext_init, "f")).invocationContext) !== null && _b !== void 0 ? _b : (_d.invocationContext = new InvocationContext_1.InvocationContext());
}
get invocationContext() {
return (0, nonNull_1.nonNullProp)(__classPrivateFieldGet(this, _InvocationHookContext_init, "f"), 'invocationContext');
}
set invocationContext(_value) {
throw new errors_1.ReadOnlyError('invocationContext');
}
get inputs() {
return (0, nonNull_1.nonNullProp)(__classPrivateFieldGet(this, _InvocationHookContext_init, "f"), 'inputs');
}
set inputs(value) {
__classPrivateFieldGet(this, _InvocationHookContext_init, "f").inputs = value;
}
}
exports.InvocationHookContext = InvocationHookContext;
_InvocationHookContext_init = new WeakMap();
/***/ }),
/***/ "./src/hooks/LogHookContext.ts":
/*!*************************************!*\
!*** ./src/hooks/LogHookContext.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 _LogHookContext_init;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.LogHookContext = void 0;
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
const HookContext_1 = __webpack_require__(/*! ./HookContext */ "./src/hooks/HookContext.ts");
class LogHookContext extends HookContext_1.HookContext {
constructor(init) {
var _a, _b, _c;
var _d, _e, _f;
super(init);
_LogHookContext_init.set(this, void 0);
__classPrivateFieldSet(this, _LogHookContext_init, init !== null && init !== void 0 ? init : {}, "f");
(_a = (_d = __classPrivateFieldGet(this, _LogHookContext_init, "f")).level) !== null && _a !== void 0 ? _a : (_d.level = 'information');
(_b = (_e = __classPrivateFieldGet(this, _LogHookContext_init, "f")).message) !== null && _b !== void 0 ? _b : (_e.message = 'unknown');
(_c = (_f = __classPrivateFieldGet(this, _LogHookContext_init, "f")).category) !== null && _c !== void 0 ? _c : (_f.category = 'user');
}
get level() {
return (0, nonNull_1.nonNullProp)(__classPrivateFieldGet(this, _LogHookContext_init, "f"), 'level');
}
set level(value) {
__classPrivateFieldGet(this, _LogHookContext_init, "f").level = value;
}
get message() {
return (0, nonNull_1.nonNullProp)(__classPrivateFieldGet(this, _LogHookContext_init, "f"), 'message');
}
set message(value) {
__classPrivateFieldGet(this, _LogHookContext_init, "f").message = value;
}
get category() {
return (0, nonNull_1.nonNullProp)(__classPrivateFieldGet(this, _LogHookContext_init, "f"), 'category');
}
set category(_value) {
throw new errors_1.ReadOnlyError('category');
}
get invocationContext() {
return __classPrivateFieldGet(this, _LogHookContext_init, "f").invocationContext;
}
set invocationContext(_value) {
throw new errors_1.ReadOnlyError('invocationContext');
}
}
exports.LogHookContext = LogHookContext;
_LogHookContext_init = new WeakMap();
/***/ }),
/***/ "./src/hooks/PostInvocationContext.ts":
/*!********************************************!*\
!*** ./src/hooks/PostInvocationContext.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 _PostInvocationContext_init;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.PostInvocationContext = void 0;
const InvocationHookContext_1 = __webpack_require__(/*! ./InvocationHookContext */ "./src/hooks/InvocationHookContext.ts");
class PostInvocationContext extends InvocationHookContext_1.InvocationHookContext {
constructor(init) {
super(init);
_PostInvocationContext_init.set(this, void 0);
__classPrivateFieldSet(this, _PostInvocationContext_init, init !== null && init !== void 0 ? init : {}, "f");
}
get result() {
return __classPrivateFieldGet(this, _PostInvocationContext_init, "f").result;
}
set result(value) {
__classPrivateFieldGet(this, _PostInvocationContext_init, "f").result = value;
}
get error() {
return __classPrivateFieldGet(this, _PostInvocationContext_init, "f").error;
}
set error(value) {
__classPrivateFieldGet(this, _PostInvocationContext_init, "f").error = value;
}
}
exports.PostInvocationContext = PostInvocationContext;
_PostInvocationContext_init = new WeakMap();
/***/ }),
/***/ "./src/hooks/PreInvocationContext.ts":
/*!*******************************************!*\
!*** ./src/hooks/PreInvocationContext.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 _PreInvocationContext_init;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.PreInvocationContext = void 0;
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
const InvocationHookContext_1 = __webpack_require__(/*! ./InvocationHookContext */ "./src/hooks/InvocationHookContext.ts");
class PreInvocationContext extends InvocationHookContext_1.InvocationHookContext {
constructor(init) {
var _a;
var _b;
super(init);
_PreInvocationContext_init.set(this, void 0);
__classPrivateFieldSet(this, _PreInvocationContext_init, init !== null && init !== void 0 ? init : {}, "f");
(_a = (_b = __classPrivateFieldGet(this, _PreInvocationContext_init, "f")).functionCallback) !== null && _a !== void 0 ? _a : (_b.functionCallback = () => { });
}
get functionHandler() {
return (0, nonNull_1.nonNullProp)(__classPrivateFieldGet(this, _PreInvocationContext_init, "f"), 'functionCallback');
}
set functionHandler(value) {
__classPrivateFieldGet(this, _PreInvocationContext_init, "f").functionCallback = value;
}
}
exports.PreInvocationContext = PreInvocationContext;
_PreInvocationContext_init = new WeakMap();
/***/ }),
/***/ "./src/hooks/registerHook.ts":
/*!***********************************!*\
!*** ./src/hooks/registerHook.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.log = exports.postInvocation = exports.preInvocation = exports.appTerminate = exports.appStart = void 0;
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
const Disposable_1 = __webpack_require__(/*! ../utils/Disposable */ "./src/utils/Disposable.ts");
const tryGetCoreApiLazy_1 = __webpack_require__(/*! ../utils/tryGetCoreApiLazy */ "./src/utils/tryGetCoreApiLazy.ts");
const AppStartContext_1 = __webpack_require__(/*! ./AppStartContext */ "./src/hooks/AppStartContext.ts");
const AppTerminateContext_1 = __webpack_require__(/*! ./AppTerminateContext */ "./src/hooks/AppTerminateContext.ts");
const LogHookContext_1 = __webpack_require__(/*! ./LogHookContext */ "./src/hooks/LogHookContext.ts");
const PostInvocationContext_1 = __webpack_require__(/*! ./PostInvocationContext */ "./src/hooks/PostInvocationContext.ts");
const PreInvocationContext_1 = __webpack_require__(/*! ./PreInvocationContext */ "./src/hooks/PreInvocationContext.ts");
function registerHook(hookName, callback) {
const coreApi = (0, tryGetCoreApiLazy_1.tryGetCoreApiLazy)();
if (!coreApi) {
console.warn(`WARNING: Skipping call to register ${hookName} hook because the "@azure/functions" package is in test mode.`);
return new Disposable_1.Disposable(() => {
console.warn(`WARNING: Skipping call to dispose ${hookName} hook because the "@azure/functions" package is in test mode.`);
});
}
else {
return coreApi.registerHook(hookName, callback);
}
}
function appStart(handler) {
return registerHook('appStart', (coreContext) => {
return handler(new AppStartContext_1.AppStartContext(coreContext));
});
}
exports.appStart = appStart;
function appTerminate(handler) {
return registerHook('appTerminate', (coreContext) => {
return handler(new AppTerminateContext_1.AppTerminateContext(coreContext));
});
}
exports.appTerminate = appTerminate;
function preInvocation(handler) {
return registerHook('preInvocation', (coreContext) => {
return handler(new PreInvocationContext_1.PreInvocationContext(coreContext));
});
}
exports.preInvocation = preInvocation;
function postInvocation(handler) {
return registerHook('postInvocation', (coreContext) => {
return handler(new PostInvocationContext_1.PostInvocationContext(coreContext));
});
}
exports.postInvocation = postInvocation;
function log(handler) {
try {
return registerHook('log', (coreContext) => {
return handler(new LogHookContext_1.LogHookContext(coreContext));
});
}
catch (err) {
const error = (0, errors_1.ensureErrorType)(err);
if (error.name === 'RangeError' && error.isAzureFunctionsSystemError) {
throw new errors_1.AzFuncSystemError(`Log hooks require Azure Functions Host v4.34 or higher.`);
}
else {
throw err;
}
}
}
exports.log = log;
/***/ }),
/***/ "./src/http/HttpRequest.ts":
/*!*********************************!*\
!*** ./src/http/HttpRequest.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 __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;
};
var _HttpRequest_cachedUser, _HttpRequest_uReq, _HttpRequest_init;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.createStreamRequest = exports.HttpRequest = void 0;
const undici_1 = __webpack_require__(/*! undici */ "undici");
const url_1 = __webpack_require__(/*! url */ "url");
const fromRpcNullable_1 = __webpack_require__(/*! ../converters/fromRpcNullable */ "./src/converters/fromRpcNullable.ts");
const fromRpcTypedData_1 = __webpack_require__(/*! ../converters/fromRpcTypedData */ "./src/converters/fromRpcTypedData.ts");
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
const extractHttpUserFromHeaders_1 = __webpack_require__(/*! ./extractHttpUserFromHeaders */ "./src/http/extractHttpUserFromHeaders.ts");
class HttpRequest {
constructor(init) {
var _a, _b, _c;
_HttpRequest_cachedUser.set(this, void 0);
_HttpRequest_uReq.set(this, void 0);
_HttpRequest_init.set(this, void 0);
__classPrivateFieldSet(this, _HttpRequest_init, init, "f");
let uReq = init.undiciRequest;
if (!uReq) {
const url = (0, nonNull_1.nonNullProp)(init, 'url');
let body;
if ((_a = init.body) === null || _a === void 0 ? void 0 : _a.bytes) {
body = Buffer.from((_b = init.body) === null || _b === void 0 ? void 0 : _b.bytes);
}
else if ((_c = init.body) === null || _c === void 0 ? void 0 : _c.string) {
body = init.body.string;
}
uReq = new undici_1.Request(url, {
body,
method: (0, nonNull_1.nonNullProp)(init, 'method'),
headers: (0, fromRpcNullable_1.fromNullableMapping)(init.nullableHeaders, init.headers),
});
}
__classPrivateFieldSet(this, _HttpRequest_uReq, uReq, "f");
if (init.nullableQuery || init.query) {
this.query = new url_1.URLSearchParams((0, fromRpcNullable_1.fromNullableMapping)(init.nullableQuery, init.query));
}
else {
this.query = new URL(__classPrivateFieldGet(this, _HttpRequest_uReq, "f").url).searchParams;
}
this.params = (0, fromRpcNullable_1.fromNullableMapping)(init.nullableParams, init.params);
}
get url() {
return __classPrivateFieldGet(this, _HttpRequest_uReq, "f").url;
}
get method() {
return __classPrivateFieldGet(this, _HttpRequest_uReq, "f").method;
}
get headers() {
return __classPrivateFieldGet(this, _HttpRequest_uReq, "f").headers;
}
get user() {
if (__classPrivateFieldGet(this, _HttpRequest_cachedUser, "f") === undefined) {
__classPrivateFieldSet(this, _HttpRequest_cachedUser, (0, extractHttpUserFromHeaders_1.extractHttpUserFromHeaders)(this.headers), "f");
}
return __classPrivateFieldGet(this, _HttpRequest_cachedUser, "f");
}
get body() {
return __classPrivateFieldGet(this, _HttpRequest_uReq, "f").body;
}
get bodyUsed() {
return __classPrivateFieldGet(this, _HttpRequest_uReq, "f").bodyUsed;
}
arrayBuffer() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _HttpRequest_uReq, "f").arrayBuffer();
});
}
blob() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _HttpRequest_uReq, "f").blob();
});
}
formData() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _HttpRequest_uReq, "f").formData();
});
}
json() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _HttpRequest_uReq, "f").json();
});
}
text() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _HttpRequest_uReq, "f").text();
});
}
clone() {
const newInit = structuredClone(__classPrivateFieldGet(this, _HttpRequest_init, "f"));
newInit.undiciRequest = __classPrivateFieldGet(this, _HttpRequest_uReq, "f").clone();
return new HttpRequest(newInit);
}
}
exports.HttpRequest = HttpRequest;
_HttpRequest_cachedUser = new WeakMap(), _HttpRequest_uReq = new WeakMap(), _HttpRequest_init = new WeakMap();
function createStreamRequest(proxyReq, triggerMetadata) {
var _a;
const hostHeaderName = 'x-forwarded-host';
const protoHeaderName = 'x-forwarded-proto';
const host = proxyReq.headers[hostHeaderName];
const proto = proxyReq.headers[protoHeaderName];
if (typeof host !== 'string' || typeof proto !== 'string') {
throw new errors_1.AzFuncSystemError(`Expected headers "${hostHeaderName}" and "${protoHeaderName}" to be set.`);
}
const url = `${proto}://${host}${(0, nonNull_1.nonNullProp)(proxyReq, 'url')}`;
let body;
const lowerMethod = (_a = proxyReq.method) === null || _a === void 0 ? void 0 : _a.toLowerCase();
if (lowerMethod !== 'get' && lowerMethod !== 'head') {
body = proxyReq;
}
// Get headers and params from trigger metadata
// See here for more info: https://github.com/Azure/azure-functions-host/issues/9840
// NOTE: We ignore query info because it has this bug: https://github.com/Azure/azure-functions-nodejs-library/issues/168
const { Query: rpcQueryIgnored, Headers: rpcHeaders } = triggerMetadata, rpcParams = __rest(triggerMetadata, ["Query", "Headers"]);
let headers;
const headersData = (0, fromRpcTypedData_1.fromRpcTypedData)(rpcHeaders);
if (typeof headersData === 'object' && (0, nonNull_1.isDefined)(headersData)) {
headers = headersData;
}
const uReq = new undici_1.Request(url, {
body,
duplex: 'half',
method: (0, nonNull_1.nonNullProp)(proxyReq, 'method'),
headers,
});
const params = {};
for (const [key, rpcValue] of Object.entries(rpcParams)) {
if ((0, nonNull_1.isDefined)(rpcValue.string)) {
params[key] = rpcValue.string;
}
}
return new HttpRequest({
undiciRequest: uReq,
params,
});
}
exports.createStreamRequest = createStreamRequest;
/***/ }),
/***/ "./src/http/HttpResponse.ts":
/*!**********************************!*\
!*** ./src/http/HttpResponse.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 _HttpResponse_uRes, _HttpResponse_init;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.HttpResponse = void 0;
const undici_1 = __webpack_require__(/*! undici */ "undici");
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
class HttpResponse {
constructor(init) {
var _a;
_HttpResponse_uRes.set(this, void 0);
_HttpResponse_init.set(this, void 0);
init !== null && init !== void 0 ? init : (init = {});
__classPrivateFieldSet(this, _HttpResponse_init, init, "f");
if (init.undiciResponse) {
__classPrivateFieldSet(this, _HttpResponse_uRes, init.undiciResponse, "f");
}
else {
const uResInit = { status: init.status, headers: init.headers };
if ((0, nonNull_1.isDefined)(init.jsonBody)) {
__classPrivateFieldSet(this, _HttpResponse_uRes, undici_1.Response.json(init.jsonBody, uResInit), "f");
}
else {
__classPrivateFieldSet(this, _HttpResponse_uRes, new undici_1.Response(init.body, uResInit), "f");
}
}
this.cookies = (_a = init.cookies) !== null && _a !== void 0 ? _a : [];
this.enableContentNegotiation = !!init.enableContentNegotiation;
}
get status() {
return __classPrivateFieldGet(this, _HttpResponse_uRes, "f").status;
}
get headers() {
return __classPrivateFieldGet(this, _HttpResponse_uRes, "f").headers;
}
get body() {
return __classPrivateFieldGet(this, _HttpResponse_uRes, "f").body;
}
get bodyUsed() {
return __classPrivateFieldGet(this, _HttpResponse_uRes, "f").bodyUsed;
}
arrayBuffer() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _HttpResponse_uRes, "f").arrayBuffer();
});
}
blob() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _HttpResponse_uRes, "f").blob();
});
}
formData() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _HttpResponse_uRes, "f").formData();
});
}
json() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _HttpResponse_uRes, "f").json();
});
}
text() {
return __awaiter(this, void 0, void 0, function* () {
return __classPrivateFieldGet(this, _HttpResponse_uRes, "f").text();
});
}
clone() {
const newInit = structuredClone(__classPrivateFieldGet(this, _HttpResponse_init, "f"));
newInit.undiciResponse = __classPrivateFieldGet(this, _HttpResponse_uRes, "f").clone();
return new HttpResponse(newInit);
}
}
exports.HttpResponse = HttpResponse;
_HttpResponse_uRes = new WeakMap(), _HttpResponse_init = new WeakMap();
/***/ }),
/***/ "./src/http/extractHttpUserFromHeaders.ts":
/*!************************************************!*\
!*** ./src/http/extractHttpUserFromHeaders.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.extractHttpUserFromHeaders = void 0;
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
/* grandfathered in. Should fix when possible */
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access */
function extractHttpUserFromHeaders(headers) {
let user = null;
const clientPrincipal = headers.get('x-ms-client-principal');
if (clientPrincipal) {
const claimsPrincipalData = JSON.parse(Buffer.from(clientPrincipal, 'base64').toString('utf-8'));
if (claimsPrincipalData['identityProvider']) {
user = {
type: 'StaticWebApps',
id: claimsPrincipalData['userId'],
username: claimsPrincipalData['userDetails'],
identityProvider: claimsPrincipalData['identityProvider'],
claimsPrincipalData,
};
}
else {
user = {
type: 'AppService',
id: (0, nonNull_1.nonNullValue)(headers.get('x-ms-client-principal-id'), 'user-id'),
username: (0, nonNull_1.nonNullValue)(headers.get('x-ms-client-principal-name'), 'user-name'),
identityProvider: (0, nonNull_1.nonNullValue)(headers.get('x-ms-client-principal-idp'), 'user-idp'),
claimsPrincipalData,
};
}
}
return user;
}
exports.extractHttpUserFromHeaders = extractHttpUserFromHeaders;
/***/ }),
/***/ "./src/http/httpProxy.ts":
/*!*******************************!*\
!*** ./src/http/httpProxy.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 __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.setupHttpProxy = exports.sendProxyResponse = exports.waitForProxyRequest = void 0;
const cookie_1 = __webpack_require__(/*! cookie */ "cookie");
const events_1 = __webpack_require__(/*! events */ "events");
const http = __webpack_require__(/*! http */ "http");
const net = __webpack_require__(/*! net */ "net");
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
const nonNull_1 = __webpack_require__(/*! ../utils/nonNull */ "./src/utils/nonNull.ts");
const workerSystemLog_1 = __webpack_require__(/*! ../utils/workerSystemLog */ "./src/utils/workerSystemLog.ts");
const requests = {};
const responses = {};
const minPort = 55000;
const maxPort = 55025;
const invocRequestEmitter = new events_1.EventEmitter();
function waitForProxyRequest(invocationId) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, _reject) => {
const req = requests[invocationId];
if (req) {
resolve(req);
delete requests[invocationId];
}
else {
invocRequestEmitter.once(invocationId, () => {
const req = requests[invocationId];
if (req) {
resolve(req);
delete requests[invocationId];
}
});
}
});
});
}
exports.waitForProxyRequest = waitForProxyRequest;
const invocationIdHeader = 'x-ms-invocation-id';
function sendProxyResponse(invocationId, userRes) {
var e_1, _a;
return __awaiter(this, void 0, void 0, function* () {
const proxyRes = (0, nonNull_1.nonNullProp)(responses, invocationId);
delete responses[invocationId];
for (const [key, val] of userRes.headers.entries()) {
proxyRes.setHeader(key, val);
}
proxyRes.setHeader(invocationIdHeader, invocationId);
proxyRes.statusCode = userRes.status;
if (userRes.cookies.length > 0) {
setCookies(userRes, proxyRes);
}
if (userRes.body) {
try {
for (var _b = __asyncValues(userRes.body.values()), _c; _c = yield _b.next(), !_c.done;) {
const chunk = _c.value;
proxyRes.write(chunk);
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) yield _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
}
proxyRes.end();
});
}
exports.sendProxyResponse = sendProxyResponse;
function setCookies(userRes, proxyRes) {
const serializedCookies = userRes.cookies.map((c) => {
let sameSite;
switch (c.sameSite) {
case 'Lax':
sameSite = 'lax';
break;
case 'None':
sameSite = 'none';
break;
case 'Strict':
sameSite = 'strict';
break;
default:
sameSite = c.sameSite;
}
return (0, cookie_1.serialize)(c.name, c.value, {
domain: c.domain,
path: c.path,
expires: typeof c.expires === 'number' ? new Date(c.expires) : c.expires,
secure: c.secure,
httpOnly: c.httpOnly,
sameSite: sameSite,
maxAge: c.maxAge,
});
});
proxyRes.setHeader('Set-Cookie', serializedCookies);
}
function setupHttpProxy() {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
const server = http.createServer();
server.on('request', (req, res) => {
const invocationId = req.headers[invocationIdHeader];
if (typeof invocationId === 'string') {
requests[invocationId] = req;
responses[invocationId] = res;
invocRequestEmitter.emit(invocationId);
}
else {
(0, workerSystemLog_1.workerSystemLog)('error', `Http proxy request missing header ${invocationIdHeader}`);
}
});
server.on('error', (err) => {
err = (0, errors_1.ensureErrorType)(err);
(0, workerSystemLog_1.workerSystemLog)('error', `Http proxy error: ${err.stack || err.message}`);
});
server.listen(() => {
const address = server.address();
// Valid address has been created
if (address !== null && typeof address === 'object') {
if (address.port === 0) {
// Auto-assigned port is 0, find and bind to an open port
(0, workerSystemLog_1.workerSystemLog)('debug', `Port 0 assigned. Finding open port.`);
findOpenPort((openPort) => {
// Close the server and re-listen on the found open port
server.close();
server.listen(openPort, () => {
(0, workerSystemLog_1.workerSystemLog)('debug', `Server is now listening on found open port: ${openPort}`);
});
resolve(`http://localhost:${openPort}/`);
});
}
else {
// Auto-assigned port is not 0
(0, workerSystemLog_1.workerSystemLog)('debug', `Auto-assigned port is valid. Port: ${address.port}`);
resolve(`http://localhost:${address.port}/`);
}
}
else {
reject(new errors_1.AzFuncSystemError('Unexpected server address during http proxy setup'));
}
});
server.on('close', () => {
(0, workerSystemLog_1.workerSystemLog)('information', 'Http proxy closing');
});
});
});
}
exports.setupHttpProxy = setupHttpProxy;
// Function to find an open port starting from a specified port
function findOpenPort(callback) {
const server = net.createServer();
function tryPort(port) {
if (port > maxPort) {
// If we've reached the maximum port, throw an error
throw new errors_1.AzFuncSystemError(`No available ports found between ${minPort} and ${maxPort}. To enable HTTP streaming, please open a port in this range.`);
}
server.once('error', () => {
// If the port is unavailable, increment and try the next one
tryPort(port + 1);
});
// If the port is available, return it
server.once('listening', () => {
const address = server.address();
if (address !== null && typeof address === 'object') {
port = address.port;
server.close();
callback(port);
}
});
// Try binding to the given port
server.listen(port);
}
// Start trying from the specified starting port
tryPort(minPort);
}
/***/ }),
/***/ "./src/index.ts":
/*!**********************!*\
!*** ./src/index.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.MySqlChangeOperation = exports.SqlChangeOperation = exports.Disposable = exports.trigger = exports.output = exports.InvocationContext = exports.input = exports.HttpResponse = exports.HttpRequest = exports.PreInvocationContext = exports.PostInvocationContext = exports.LogHookContext = exports.InvocationHookContext = exports.HookContext = exports.AppTerminateContext = exports.AppStartContext = exports.app = void 0;
exports.app = __webpack_require__(/*! ./app */ "./src/app.ts");
var AppStartContext_1 = __webpack_require__(/*! ./hooks/AppStartContext */ "./src/hooks/AppStartContext.ts");
Object.defineProperty(exports, "AppStartContext", ({ enumerable: true, get: function () { return AppStartContext_1.AppStartContext; } }));
var AppTerminateContext_1 = __webpack_require__(/*! ./hooks/AppTerminateContext */ "./src/hooks/AppTerminateContext.ts");
Object.defineProperty(exports, "AppTerminateContext", ({ enumerable: true, get: function () { return AppTerminateContext_1.AppTerminateContext; } }));
var HookContext_1 = __webpack_require__(/*! ./hooks/HookContext */ "./src/hooks/HookContext.ts");
Object.defineProperty(exports, "HookContext", ({ enumerable: true, get: function () { return HookContext_1.HookContext; } }));
var InvocationHookContext_1 = __webpack_require__(/*! ./hooks/InvocationHookContext */ "./src/hooks/InvocationHookContext.ts");
Object.defineProperty(exports, "InvocationHookContext", ({ enumerable: true, get: function () { return InvocationHookContext_1.InvocationHookContext; } }));
var LogHookContext_1 = __webpack_require__(/*! ./hooks/LogHookContext */ "./src/hooks/LogHookContext.ts");
Object.defineProperty(exports, "LogHookContext", ({ enumerable: true, get: function () { return LogHookContext_1.LogHookContext; } }));
var PostInvocationContext_1 = __webpack_require__(/*! ./hooks/PostInvocationContext */ "./src/hooks/PostInvocationContext.ts");
Object.defineProperty(exports, "PostInvocationContext", ({ enumerable: true, get: function () { return PostInvocationContext_1.PostInvocationContext; } }));
var PreInvocationContext_1 = __webpack_require__(/*! ./hooks/PreInvocationContext */ "./src/hooks/PreInvocationContext.ts");
Object.defineProperty(exports, "PreInvocationContext", ({ enumerable: true, get: function () { return PreInvocationContext_1.PreInvocationContext; } }));
var HttpRequest_1 = __webpack_require__(/*! ./http/HttpRequest */ "./src/http/HttpRequest.ts");
Object.defineProperty(exports, "HttpRequest", ({ enumerable: true, get: function () { return HttpRequest_1.HttpRequest; } }));
var HttpResponse_1 = __webpack_require__(/*! ./http/HttpResponse */ "./src/http/HttpResponse.ts");
Object.defineProperty(exports, "HttpResponse", ({ enumerable: true, get: function () { return HttpResponse_1.HttpResponse; } }));
exports.input = __webpack_require__(/*! ./input */ "./src/input.ts");
var InvocationContext_1 = __webpack_require__(/*! ./InvocationContext */ "./src/InvocationContext.ts");
Object.defineProperty(exports, "InvocationContext", ({ enumerable: true, get: function () { return InvocationContext_1.InvocationContext; } }));
exports.output = __webpack_require__(/*! ./output */ "./src/output.ts");
exports.trigger = __webpack_require__(/*! ./trigger */ "./src/trigger.ts");
var Disposable_1 = __webpack_require__(/*! ./utils/Disposable */ "./src/utils/Disposable.ts");
Object.defineProperty(exports, "Disposable", ({ enumerable: true, get: function () { return Disposable_1.Disposable; } }));
var SqlChangeOperation;
(function (SqlChangeOperation) {
SqlChangeOperation[SqlChangeOperation["Insert"] = 0] = "Insert";
SqlChangeOperation[SqlChangeOperation["Update"] = 1] = "Update";
SqlChangeOperation[SqlChangeOperation["Delete"] = 2] = "Delete";
})(SqlChangeOperation = exports.SqlChangeOperation || (exports.SqlChangeOperation = {}));
var MySqlChangeOperation;
(function (MySqlChangeOperation) {
MySqlChangeOperation[MySqlChangeOperation["Update"] = 0] = "Update";
})(MySqlChangeOperation = exports.MySqlChangeOperation || (exports.MySqlChangeOperation = {}));
/***/ }),
/***/ "./src/input.ts":
/*!**********************!*\
!*** ./src/input.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.generic = exports.webPubSubContext = exports.webPubSubConnection = exports.mySql = exports.sql = exports.cosmosDB = exports.table = exports.storageBlob = void 0;
const addBindingName_1 = __webpack_require__(/*! ./addBindingName */ "./src/addBindingName.ts");
function storageBlob(options) {
return addInputBindingName(Object.assign(Object.assign({}, options), { type: 'blob' }));
}
exports.storageBlob = storageBlob;
function table(options) {
return addInputBindingName(Object.assign(Object.assign({}, options), { type: 'table' }));
}
exports.table = table;
function cosmosDB(options) {
return addInputBindingName(Object.assign(Object.assign({}, options), { type: 'cosmosDB' }));
}
exports.cosmosDB = cosmosDB;
function sql(options) {
return addInputBindingName(Object.assign(Object.assign({}, options), { type: 'sql' }));
}
exports.sql = sql;
function mySql(options) {
return addInputBindingName(Object.assign(Object.assign({}, options), { type: 'mysql' }));
}
exports.mySql = mySql;
function webPubSubConnection(options) {
return addInputBindingName(Object.assign(Object.assign({}, options), { type: 'webPubSubConnection' }));
}
exports.webPubSubConnection = webPubSubConnection;
function webPubSubContext(options) {
return addInputBindingName(Object.assign(Object.assign({}, options), { type: 'webPubSubContext' }));
}
exports.webPubSubContext = webPubSubContext;
function generic(options) {
return addInputBindingName(options);
}
exports.generic = generic;
function addInputBindingName(binding) {
return (0, addBindingName_1.addBindingName)(binding, 'Input');
}
/***/ }),
/***/ "./src/output.ts":
/*!***********************!*\
!*** ./src/output.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.generic = exports.webPubSub = exports.mySql = exports.sql = exports.cosmosDB = exports.eventGrid = exports.eventHub = exports.serviceBusTopic = exports.serviceBusQueue = exports.storageQueue = exports.table = exports.storageBlob = exports.http = void 0;
const addBindingName_1 = __webpack_require__(/*! ./addBindingName */ "./src/addBindingName.ts");
function http(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'http' }));
}
exports.http = http;
function storageBlob(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'blob' }));
}
exports.storageBlob = storageBlob;
function table(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'table' }));
}
exports.table = table;
function storageQueue(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'queue' }));
}
exports.storageQueue = storageQueue;
function serviceBusQueue(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'serviceBus' }));
}
exports.serviceBusQueue = serviceBusQueue;
function serviceBusTopic(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'serviceBus' }));
}
exports.serviceBusTopic = serviceBusTopic;
function eventHub(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'eventHub' }));
}
exports.eventHub = eventHub;
function eventGrid(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'eventGrid' }));
}
exports.eventGrid = eventGrid;
function cosmosDB(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'cosmosDB' }));
}
exports.cosmosDB = cosmosDB;
function sql(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'sql' }));
}
exports.sql = sql;
function mySql(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'mysql' }));
}
exports.mySql = mySql;
function webPubSub(options) {
return addOutputBindingName(Object.assign(Object.assign({}, options), { type: 'webPubSub' }));
}
exports.webPubSub = webPubSub;
function generic(options) {
return addOutputBindingName(options);
}
exports.generic = generic;
function addOutputBindingName(binding) {
return (0, addBindingName_1.addBindingName)(binding, 'Output');
}
/***/ }),
/***/ "./src/setup.ts":
/*!**********************!*\
!*** ./src/setup.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.setup = exports.capabilities = exports.enableHttpStream = exports.lockSetup = void 0;
const errors_1 = __webpack_require__(/*! ./errors */ "./src/errors.ts");
const nonNull_1 = __webpack_require__(/*! ./utils/nonNull */ "./src/utils/nonNull.ts");
const tryGetCoreApiLazy_1 = __webpack_require__(/*! ./utils/tryGetCoreApiLazy */ "./src/utils/tryGetCoreApiLazy.ts");
const workerSystemLog_1 = __webpack_require__(/*! ./utils/workerSystemLog */ "./src/utils/workerSystemLog.ts");
let setupLocked = false;
function lockSetup() {
setupLocked = true;
}
exports.lockSetup = lockSetup;
exports.enableHttpStream = false;
exports.capabilities = {};
function setup(opts) {
if (setupLocked) {
throw new errors_1.AzFuncSystemError("Setup options can't be changed after app startup has finished.");
}
if (opts.enableHttpStream) {
// NOTE: coreApi.log was coincidentally added the same time as http streaming,
// so we can use that to validate the host version instead of messing with semver parsing
const coreApi = (0, tryGetCoreApiLazy_1.tryGetCoreApiLazy)();
if (coreApi && !coreApi.log) {
throw new errors_1.AzFuncSystemError(`HTTP streaming requires Azure Functions Host v4.28 or higher.`);
}
}
if ((0, nonNull_1.isDefined)(opts.enableHttpStream)) {
exports.enableHttpStream = opts.enableHttpStream;
}
if (opts.capabilities) {
for (let [key, val] of Object.entries(opts.capabilities)) {
if ((0, nonNull_1.isDefined)(val)) {
val = String(val);
(0, workerSystemLog_1.workerSystemLog)('debug', `Capability ${key} set to ${val}.`);
exports.capabilities[key] = val;
}
}
}
if (exports.enableHttpStream) {
(0, workerSystemLog_1.workerSystemLog)('debug', `HTTP streaming enabled.`);
}
}
exports.setup = setup;
/***/ }),
/***/ "./src/trigger.ts":
/*!************************!*\
!*** ./src/trigger.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.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 = void 0;
const addBindingName_1 = __webpack_require__(/*! ./addBindingName */ "./src/addBindingName.ts");
function http(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { authLevel: options.authLevel || 'anonymous', methods: options.methods || ['GET', 'POST'], type: 'httpTrigger' }));
}
exports.http = http;
function timer(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'timerTrigger' }));
}
exports.timer = timer;
function storageBlob(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'blobTrigger' }));
}
exports.storageBlob = storageBlob;
function storageQueue(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'queueTrigger' }));
}
exports.storageQueue = storageQueue;
function serviceBusQueue(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'serviceBusTrigger' }));
}
exports.serviceBusQueue = serviceBusQueue;
function serviceBusTopic(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'serviceBusTrigger' }));
}
exports.serviceBusTopic = serviceBusTopic;
function eventHub(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'eventHubTrigger' }));
}
exports.eventHub = eventHub;
function eventGrid(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'eventGridTrigger' }));
}
exports.eventGrid = eventGrid;
function cosmosDB(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'cosmosDBTrigger' }));
}
exports.cosmosDB = cosmosDB;
function warmup(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'warmupTrigger' }));
}
exports.warmup = warmup;
function sql(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'sqlTrigger' }));
}
exports.sql = sql;
function mySql(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'mysqlTrigger' }));
}
exports.mySql = mySql;
function webPubSub(options) {
return addTriggerBindingName(Object.assign(Object.assign({}, options), { type: 'webPubSubTrigger' }));
}
exports.webPubSub = webPubSub;
function generic(options) {
return addTriggerBindingName(options);
}
exports.generic = generic;
function addTriggerBindingName(binding) {
return (0, addBindingName_1.addBindingName)(binding, 'Trigger');
}
/***/ }),
/***/ "./src/utils/Disposable.ts":
/*!*********************************!*\
!*** ./src/utils/Disposable.ts ***!
\*********************************/
/***/ (function(__unused_webpack_module, exports) {
// 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 _Disposable_callOnDispose;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Disposable = void 0;
/**
* Based off of VS Code
* https://github.com/microsoft/vscode/blob/7bed4ce3e9f5059b5fc638c348f064edabcce5d2/src/vs/workbench/api/common/extHostTypes.ts#L65
*/
class Disposable {
constructor(callOnDispose) {
_Disposable_callOnDispose.set(this, void 0);
__classPrivateFieldSet(this, _Disposable_callOnDispose, callOnDispose, "f");
}
static from(...inDisposables) {
let disposables = inDisposables;
return new Disposable(function () {
if (disposables) {
for (const disposable of disposables) {
if (disposable && typeof disposable.dispose === 'function') {
disposable.dispose();
}
}
disposables = undefined;
}
});
}
dispose() {
if (typeof __classPrivateFieldGet(this, _Disposable_callOnDispose, "f") === 'function') {
__classPrivateFieldGet(this, _Disposable_callOnDispose, "f").call(this);
__classPrivateFieldSet(this, _Disposable_callOnDispose, undefined, "f");
}
}
}
exports.Disposable = Disposable;
_Disposable_callOnDispose = new WeakMap();
/***/ }),
/***/ "./src/utils/fallbackLogHandler.ts":
/*!*****************************************!*\
!*** ./src/utils/fallbackLogHandler.ts ***!
\*****************************************/
/***/ ((__unused_webpack_module, exports) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.fallbackLogHandler = void 0;
function fallbackLogHandler(level, ...args) {
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);
}
}
exports.fallbackLogHandler = fallbackLogHandler;
/***/ }),
/***/ "./src/utils/getRandomHexString.ts":
/*!*****************************************!*\
!*** ./src/utils/getRandomHexString.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.getStringHash = exports.getRandomHexString = void 0;
const crypto = __webpack_require__(/*! crypto */ "crypto");
function getRandomHexString(length = 10) {
const buffer = crypto.randomBytes(Math.ceil(length / 2));
return buffer.toString('hex').slice(0, length);
}
exports.getRandomHexString = getRandomHexString;
function getStringHash(data, length = 10) {
return crypto.createHash('sha256').update(data).digest('hex').slice(0, length);
}
exports.getStringHash = getStringHash;
/***/ }),
/***/ "./src/utils/isTrigger.ts":
/*!********************************!*\
!*** ./src/utils/isTrigger.ts ***!
\********************************/
/***/ ((__unused_webpack_module, exports) => {
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.isTimerTrigger = exports.isHttpTrigger = exports.isTrigger = void 0;
function isTrigger(typeName) {
return !!typeName && /trigger$/i.test(typeName);
}
exports.isTrigger = isTrigger;
function isHttpTrigger(typeName) {
return (typeName === null || typeName === void 0 ? void 0 : typeName.toLowerCase()) === 'httptrigger';
}
exports.isHttpTrigger = isHttpTrigger;
function isTimerTrigger(typeName) {
return (typeName === null || typeName === void 0 ? void 0 : typeName.toLowerCase()) === 'timertrigger';
}
exports.isTimerTrigger = isTimerTrigger;
/***/ }),
/***/ "./src/utils/nonNull.ts":
/*!******************************!*\
!*** ./src/utils/nonNull.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.isDefined = exports.copyPropIfDefined = exports.nonNullValue = exports.nonNullProp = void 0;
const errors_1 = __webpack_require__(/*! ../errors */ "./src/errors.ts");
/**
* Retrieves a property by name from an object and checks that it's not null and not undefined. It is strongly typed
* for the property and will give a compile error if the given name is not a property of the source.
*/
function nonNullProp(source, name) {
const value = source[name];
return nonNullValue(value, name);
}
exports.nonNullProp = nonNullProp;
/**
* Validates that a given value is not null and not undefined.
*/
function nonNullValue(value, propertyNameOrMessage) {
if (value === null || value === undefined) {
throw new errors_1.AzFuncSystemError('Internal error: Expected value to be neither null nor undefined' +
(propertyNameOrMessage ? `: ${propertyNameOrMessage}` : ''));
}
return value;
}
exports.nonNullValue = nonNullValue;
function copyPropIfDefined(source, destination, key) {
if (source[key] !== null && source[key] !== undefined) {
destination[key] = source[key];
}
}
exports.copyPropIfDefined = copyPropIfDefined;
function isDefined(data) {
return data !== null && data !== undefined;
}
exports.isDefined = isDefined;
/***/ }),
/***/ "./src/utils/tryGetCoreApiLazy.ts":
/*!****************************************!*\
!*** ./src/utils/tryGetCoreApiLazy.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.tryGetCoreApiLazy = void 0;
let coreApi;
function tryGetCoreApiLazy() {
if (coreApi === undefined) {
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
coreApi = __webpack_require__(/*! @azure/functions-core */ "@azure/functions-core");
}
catch (_a) {
coreApi = null;
}
}
return coreApi;
}
exports.tryGetCoreApiLazy = tryGetCoreApiLazy;
/***/ }),
/***/ "./src/utils/workerSystemLog.ts":
/*!**************************************!*\
!*** ./src/utils/workerSystemLog.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.workerSystemLog = void 0;
const util_1 = __webpack_require__(/*! util */ "util");
const fallbackLogHandler_1 = __webpack_require__(/*! ./fallbackLogHandler */ "./src/utils/fallbackLogHandler.ts");
const tryGetCoreApiLazy_1 = __webpack_require__(/*! ./tryGetCoreApiLazy */ "./src/utils/tryGetCoreApiLazy.ts");
function workerSystemLog(level, ...args) {
const coreApi = (0, tryGetCoreApiLazy_1.tryGetCoreApiLazy)();
// NOTE: coreApi.log doesn't exist on older versions of the worker
if (coreApi && coreApi.log) {
coreApi.log(level, 'system', (0, util_1.format)(...args));
}
else {
(0, fallbackLogHandler_1.fallbackLogHandler)(level, ...args);
}
}
exports.workerSystemLog = workerSystemLog;
/***/ }),
/***/ "@azure/functions-core":
/*!****************************************!*\
!*** external "@azure/functions-core" ***!
\****************************************/
/***/ ((module) => {
module.exports = require("@azure/functions-core");
/***/ }),
/***/ "cookie":
/*!*************************!*\
!*** external "cookie" ***!
\*************************/
/***/ ((module) => {
module.exports = require("cookie");
/***/ }),
/***/ "crypto":
/*!*************************!*\
!*** external "crypto" ***!
\*************************/
/***/ ((module) => {
module.exports = require("crypto");
/***/ }),
/***/ "events":
/*!*************************!*\
!*** external "events" ***!
\*************************/
/***/ ((module) => {
module.exports = require("events");
/***/ }),
/***/ "http":
/*!***********************!*\
!*** external "http" ***!
\***********************/
/***/ ((module) => {
module.exports = require("http");
/***/ }),
/***/ "net":
/*!**********************!*\
!*** external "net" ***!
\**********************/
/***/ ((module) => {
module.exports = require("net");
/***/ }),
/***/ "undici":
/*!*************************!*\
!*** external "undici" ***!
\*************************/
/***/ ((module) => {
module.exports = require("undici");
/***/ }),
/***/ "url":
/*!**********************!*\
!*** external "url" ***!
\**********************/
/***/ ((module) => {
module.exports = require("url");
/***/ }),
/***/ "util":
/*!***********************!*\
!*** external "util" ***!
\***********************/
/***/ ((module) => {
module.exports = require("util");
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __webpack_require__("./src/index.ts");
/******/ module.exports = __webpack_exports__;
/******/
/******/ })()
;
//# sourceMappingURL=azure-functions.js.map