You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.6 KiB
49 lines
1.6 KiB
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.bindUnsafeByPropsQueries = void 0;
|
|
var _prettyFormat = _interopRequireDefault(require("pretty-format"));
|
|
var _errors = require("../helpers/errors");
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
const UNSAFE_getByProps = instance => function getByPropsFn(props) {
|
|
try {
|
|
return instance.findByProps(props);
|
|
} catch (error) {
|
|
throw new _errors.ErrorWithStack((0, _errors.prepareErrorMessage)(error), getByPropsFn);
|
|
}
|
|
};
|
|
const UNSAFE_getAllByProps = instance => function getAllByPropsFn(props) {
|
|
const results = instance.findAllByProps(props);
|
|
if (results.length === 0) {
|
|
throw new _errors.ErrorWithStack(`No instances found with props:\n${(0, _prettyFormat.default)(props)}`, getAllByPropsFn);
|
|
}
|
|
return results;
|
|
};
|
|
const UNSAFE_queryByProps = instance => function queryByPropsFn(props) {
|
|
try {
|
|
return UNSAFE_getByProps(instance)(props);
|
|
} catch (error) {
|
|
return (0, _errors.createQueryByError)(error, queryByPropsFn);
|
|
}
|
|
};
|
|
const UNSAFE_queryAllByProps = instance => props => {
|
|
try {
|
|
return UNSAFE_getAllByProps(instance)(props);
|
|
} catch (error) {
|
|
return [];
|
|
}
|
|
};
|
|
|
|
// Unsafe aliases
|
|
|
|
// TODO: migrate to makeQueries pattern
|
|
const bindUnsafeByPropsQueries = instance => ({
|
|
UNSAFE_getByProps: UNSAFE_getByProps(instance),
|
|
UNSAFE_getAllByProps: UNSAFE_getAllByProps(instance),
|
|
UNSAFE_queryByProps: UNSAFE_queryByProps(instance),
|
|
UNSAFE_queryAllByProps: UNSAFE_queryAllByProps(instance)
|
|
});
|
|
exports.bindUnsafeByPropsQueries = bindUnsafeByPropsQueries;
|
|
//# sourceMappingURL=unsafeProps.js.map
|