diff --git a/ast.json b/ast.json index 3a1d934..c3c4cc0 100644 --- a/ast.json +++ b/ast.json @@ -3082,10 +3082,10 @@ "valid": true }, { - "name": "valByName", + "name": "attrVal", "params": [ - "attr", - "name" + "tei", + "attributeName" ], "docs": { "description": "Gets an attribute value by its case-insensitive display name", @@ -3106,21 +3106,21 @@ }, { "title": "param", - "description": "An array of tracked entity attributes", + "description": "A tracked entity instance (TEI) object", "type": { "type": "NameExpression", "name": "Object" }, - "name": "attr" + "name": "tei" }, { "title": "param", - "description": "The display name to search for", + "description": "The 'displayName' to search for in the TEI's attributes", "type": { "type": "NameExpression", "name": "string" }, - "name": "name" + "name": "attributeName" }, { "title": "returns", diff --git a/lib/Adaptor.js b/lib/Adaptor.js index 2d3d7ba..7bb61d2 100644 --- a/lib/Adaptor.js +++ b/lib/Adaptor.js @@ -34,7 +34,7 @@ exports.update = update; exports.patch = patch; exports.del = del; exports.upsert = upsert; -exports.valByName = valByName; +exports.attrVal = attrVal; Object.defineProperty(exports, "field", { enumerable: true, get: function get() { @@ -1859,16 +1859,16 @@ function upsert(resourceType, uniqueAttribute, data, params, options, callback) * @example * valByName(tei.attributes, 'first name') * @function - * @param {Object} attr - An array of tracked entity attributes - * @param {string} name - The display name to search for + * @param {Object} tei - A tracked entity instance (TEI) object + * @param {string} attributeName - The 'displayName' to search for in the TEI's attributes * @returns {string} */ -function valByName(attr, name) { - var _attr$find; +function attrVal(tei, attributeName) { + var _tei$attributes, _tei$attributes$find; - return (_attr$find = attr.find(function (a) { - return a.displayName.toLowerCase() == name.toLowerCase(); - })) === null || _attr$find === void 0 ? void 0 : _attr$find.value; + return tei === null || tei === void 0 ? void 0 : (_tei$attributes = tei.attributes) === null || _tei$attributes === void 0 ? void 0 : (_tei$attributes$find = _tei$attributes.find(function (a) { + return (a === null || a === void 0 ? void 0 : a.displayName.toLowerCase()) == attributeName.toLowerCase(); + })) === null || _tei$attributes$find === void 0 ? void 0 : _tei$attributes$find.value; } \ No newline at end of file diff --git a/src/Adaptor.js b/src/Adaptor.js index 461e74c..4949052 100644 --- a/src/Adaptor.js +++ b/src/Adaptor.js @@ -899,8 +899,9 @@ export function discover(httpMethod, endpoint) { if (param.schema['$ref']) { let schemaRefIndex = param.schema['$ref'].lastIndexOf('/') + 1; - let schemaRef = - param.schema['$ref'].slice(schemaRefIndex); + let schemaRef = param.schema['$ref'].slice( + schemaRefIndex + ); param.schema = tempData.components.schemas[schemaRef]; } @@ -1933,13 +1934,14 @@ export function upsert( * @example * valByName(tei.attributes, 'first name') * @function - * @param {Object} attr - An array of tracked entity attributes - * @param {string} name - The display name to search for + * @param {Object} tei - A tracked entity instance (TEI) object + * @param {string} attributeName - The 'displayName' to search for in the TEI's attributes * @returns {string} */ -export function valByName(attr, name) { - return attr.find(a => a.displayName.toLowerCase() == name.toLowerCase()) - ?.value; +export function attrVal(tei, attributeName) { + return tei?.attributes?.find( + a => a?.displayName.toLowerCase() == attributeName.toLowerCase() + )?.value; } export { attribute } from './Utils';