@aws-cdk/aws-ivs-alpha
Version:
The CDK Construct Library for AWS::IVS
51 lines (50 loc) • 1.6 kB
JavaScript
const VALIDATORS = {};
function print(name, deprecationMessage) {
const deprecated = process.env.JSII_DEPRECATED;
const deprecationMode = ["warn", "fail", "quiet"].includes(deprecated) ? deprecated : "warn";
const message = `${name} is deprecated.\n ${deprecationMessage.trim()}\n This API will be removed in the next major release.`;
switch (deprecationMode) {
case "fail":
throw new DeprecationError(message);
case "warn":
console.warn("[WARNING]", message);
break;
}
}
function getPropertyDescriptor(obj, prop) {
const descriptor = Object.getOwnPropertyDescriptor(obj, prop);
if (descriptor) {
return descriptor;
}
const proto = Object.getPrototypeOf(obj);
const prototypeDescriptor = proto && getPropertyDescriptor(proto, prop);
if (prototypeDescriptor) {
return prototypeDescriptor;
}
return {};
}
const visitedObjects = new Set();
class DeprecationError extends Error {
constructor(...args) {
super(...args);
Object.defineProperty(this, "name", {
configurable: false,
enumerable: true,
value: "DeprecationError",
writable: false,
});
}
}
function nop() {
}
module.exports = new Proxy({}, {
get(target, prop, receiver) {
if (prop === "print")
return print;
if (prop === "getPropertyDescriptor")
return getPropertyDescriptor;
if (prop === "DeprecationError")
return DeprecationError;
return VALIDATORS[prop] ?? nop;
},
});