MCPcopy Index your code
hub / github.com/atomicdata-dev/atomic-data-browser / getProperty

Method getProperty

lib/src/store.ts:194–228  ·  view source on GitHub ↗

Gets a property by URL.

(subject: string)

Source from the content-addressed store, hash-verified

192
193 /** Gets a property by URL. */
194 async getProperty(subject: string): Promise<Property> {
195 // This leads to multiple fetches!
196 const resource = await this.getResourceAsync(subject);
197 if (resource == undefined) {
198 throw Error(`Property ${subject} is not found`);
199 }
200 if (resource.error) {
201 throw Error(`Property ${subject} cannot be loaded: ${resource.error}`);
202 }
203 const prop = new Property();
204 const datatypeUrl = resource.get(urls.properties.datatype);
205 if (datatypeUrl == null) {
206 throw Error(
207 `Property ${subject} has no datatype: ${resource.getPropVals()}`,
208 );
209 }
210 const shortname = resource.get(urls.properties.shortname);
211 if (shortname == null) {
212 throw Error(
213 `Property ${subject} has no shortname: ${resource.getPropVals()}`,
214 );
215 }
216 const description = resource.get(urls.properties.description);
217 if (description == null) {
218 throw Error(
219 `Property ${subject} has no description: ${resource.getPropVals()}`,
220 );
221 }
222 const classTypeURL = resource.get(urls.properties.classType)?.toString();
223 prop.classType = classTypeURL;
224 prop.shortname = shortname.toString();
225 prop.description = description.toString();
226 prop.datatype = datatypeFromUrl(datatypeUrl.toString());
227 return prop;
228 }
229
230 /**
231 * This is called when Errors occur in some of the library functions. Set your

Callers 4

propertyLineFunction · 0.80
setMethod · 0.80
constructSubjectFunction · 0.80

Calls 4

getResourceAsyncMethod · 0.95
datatypeFromUrlFunction · 0.90
getMethod · 0.80
getPropValsMethod · 0.80

Tested by

no test coverage detected