@azure/app-configuration
Version:
An isomorphic client library for the Azure App Configuration service.
111 lines (110 loc) • 4.17 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var restorePollerHelpers_exports = {};
__export(restorePollerHelpers_exports, {
restorePoller: () => restorePoller
});
module.exports = __toCommonJS(restorePollerHelpers_exports);
var import_operations = require("./api/operations.js");
var import_pollingHelpers = require("./static-helpers/pollingHelpers.js");
var import_core_lro = require("@azure/core-lro");
function restorePoller(client, serializedState, sourceOperation, options) {
const pollerConfig = (0, import_core_lro.deserializeState)(serializedState).config;
const { initialRequestUrl, requestMethod, metadata } = pollerConfig;
if (!initialRequestUrl || !requestMethod) {
throw new Error(
`Invalid serialized state: ${serializedState} for sourceOperation ${sourceOperation?.name}`
);
}
const resourceLocationConfig = metadata?.["resourceLocationConfig"];
const { deserializer, expectedStatuses = [] } = getDeserializationHelper(initialRequestUrl, requestMethod) ?? {};
const deserializeHelper = options?.processResponseBody ?? deserializer;
if (!deserializeHelper) {
throw new Error(
`Please ensure the operation is in this client! We can't find its deserializeHelper for ${sourceOperation?.name}.`
);
}
const apiVersion = getApiVersionFromUrl(initialRequestUrl);
return (0, import_pollingHelpers.getLongRunningPoller)(
client["_client"] ?? client,
deserializeHelper,
expectedStatuses,
{
updateIntervalInMs: options?.updateIntervalInMs,
abortSignal: options?.abortSignal,
resourceLocationConfig,
restoreFrom: serializedState,
initialRequestUrl,
apiVersion
}
);
}
const deserializeMap = {
"PUT /snapshots/{name}": {
deserializer: import_operations._createSnapshotDeserialize,
expectedStatuses: ["201", "200", "202"]
}
};
function getDeserializationHelper(urlStr, method) {
const path = new URL(urlStr).pathname;
const pathParts = path.split("/");
let matchedLen = -1, matchedValue;
for (const [key, value] of Object.entries(deserializeMap)) {
if (!key.startsWith(method)) {
continue;
}
const candidatePath = getPathFromMapKey(key);
const candidateParts = candidatePath.split("/");
let found = true;
for (let i = candidateParts.length - 1, j = pathParts.length - 1; i >= 1 && j >= 1; i--, j--) {
if (candidateParts[i]?.startsWith("{") && candidateParts[i]?.indexOf("}") !== -1) {
const start = candidateParts[i].indexOf("}") + 1, end = candidateParts[i]?.length;
const isMatched = new RegExp(`${candidateParts[i]?.slice(start, end)}`).test(
pathParts[j] || ""
);
if (!isMatched) {
found = false;
break;
}
continue;
}
if (candidateParts[i] !== pathParts[j]) {
found = false;
break;
}
}
if (found && candidatePath.length > matchedLen) {
matchedLen = candidatePath.length;
matchedValue = value;
}
}
return matchedValue;
}
function getPathFromMapKey(mapKey) {
const pathStart = mapKey.indexOf("/");
return mapKey.slice(pathStart);
}
function getApiVersionFromUrl(urlStr) {
const url = new URL(urlStr);
return url.searchParams.get("api-version") ?? void 0;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
restorePoller
});
//# sourceMappingURL=restorePollerHelpers.js.map