From 7ddd4ac29a85c7350c48caf50de3390d6809b1f1 Mon Sep 17 00:00:00 2001 From: Taylor Downs Date: Sat, 18 Dec 2021 14:37:38 +0000 Subject: [PATCH] add docs for attribute and update attrVal --- ast.json | 55 +++++++++++++++++++++++++++++++++++++++++++++++++- lib/Adaptor.js | 13 +++++++++++- src/Adaptor.js | 17 ++++++++++++---- 3 files changed, 79 insertions(+), 6 deletions(-) diff --git a/ast.json b/ast.json index aa9cffa..43128b0 100644 --- a/ast.json +++ b/ast.json @@ -856,7 +856,7 @@ }, { "title": "example", - "description": "valByName(tei.attributes, 'first name')" + "description": "attrVal(tei.attributes, 'first name')" }, { "title": "function", @@ -892,6 +892,59 @@ ] }, "valid": true + }, + { + "name": "attribute", + "params": [ + "attributeId", + "attributeValue" + ], + "docs": { + "description": "Converts an attribute ID and value into a DSHI2 attribute object", + "tags": [ + { + "title": "public", + "description": null, + "type": null + }, + { + "title": "example", + "description": "attribute('w75KJ2mc4zz', 'Elias')" + }, + { + "title": "function", + "description": null, + "name": null + }, + { + "title": "param", + "description": "A tracked entity instance (TEI) attribute ID.", + "type": { + "type": "NameExpression", + "name": "string" + }, + "name": "attributeId" + }, + { + "title": "param", + "description": "The value for that attribute.", + "type": { + "type": "NameExpression", + "name": "string" + }, + "name": "attributeValue" + }, + { + "title": "returns", + "description": null, + "type": { + "type": "NameExpression", + "name": "object" + } + } + ] + }, + "valid": true } ], "exports": [], diff --git a/lib/Adaptor.js b/lib/Adaptor.js index fb93c16..2a3bf5e 100644 --- a/lib/Adaptor.js +++ b/lib/Adaptor.js @@ -777,7 +777,7 @@ function del(resourceType, path, data, params, options, callback) { * Gets an attribute value by its case-insensitive display name * @public * @example - * valByName(tei.attributes, 'first name') + * attrVal(tei.attributes, 'first name') * @function * @param {Object} tei - A tracked entity instance (TEI) object * @param {string} attributeName - The 'displayName' to search for in the TEI's attributes @@ -790,6 +790,17 @@ function attrVal(tei, attributeName) { 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(a => (a === null || a === void 0 ? void 0 : a.displayName.toLowerCase()) == attributeName.toLowerCase())) === null || _tei$attributes$find === void 0 ? void 0 : _tei$attributes$find.value; } +/** + * Converts an attribute ID and value into a DSHI2 attribute object + * @public + * @example + * attribute('w75KJ2mc4zz', 'Elias') + * @function + * @param {string} attributeId - A tracked entity instance (TEI) attribute ID. + * @param {string} attributeValue - The value for that attribute. + * @returns {object} + */ + function attribute(attributeId, attributeValue) { return { diff --git a/src/Adaptor.js b/src/Adaptor.js index cd07b3e..3adc120 100644 --- a/src/Adaptor.js +++ b/src/Adaptor.js @@ -546,9 +546,8 @@ 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]; } @@ -770,7 +769,7 @@ export function del(resourceType, path, data, params, options, callback) { * Gets an attribute value by its case-insensitive display name * @public * @example - * valByName(tei.attributes, 'first name') + * attrVal(tei.attributes, 'first name') * @function * @param {Object} tei - A tracked entity instance (TEI) object * @param {string} attributeName - The 'displayName' to search for in the TEI's attributes @@ -782,6 +781,16 @@ export function attrVal(tei, attributeName) { )?.value; } +/** + * Converts an attribute ID and value into a DSHI2 attribute object + * @public + * @example + * attribute('w75KJ2mc4zz', 'Elias') + * @function + * @param {string} attributeId - A tracked entity instance (TEI) attribute ID. + * @param {string} attributeValue - The value for that attribute. + * @returns {object} + */ export function attribute(attributeId, attributeValue) { return { attribute: attributeId,