Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getResourceIriFromToken(token: YasguiYasqe.YasqeToken): Rdf.Iri | undefined {
const {prefixes} = token.state;
if (token.type === 'string-2') {
const [prefixKey, resource] = token.string.split(':');
if (resource) {
const prefix = prefixes[prefixKey];
if (prefix) {
return Rdf.iri(`${prefix}${resource}`);
}
try {
return resolveIris([token.string])[0];
} catch {
return undefined;
}
}
} else if (token.type === 'variable-3') {
const resourceIri = Rdf.fullIri(token.string);
if (!resourceIri.value.length) {
return undefined;
}
const prefixKey = findKey(prefixes, prefix => prefix === resourceIri.value);
return prefixKey ? undefined : resourceIri;
}
return undefined;
this.props.updateValue(v => {
const nonEmpty = FieldValue.isEmpty(v)
? FieldValue.fromLabeled({value: Rdf.iri('')}) : v;
const errors = FieldValue.getErrors(nonEmpty).push({
kind: ErrorKind.Loading,
message: `Failed to load value set`,
});
return FieldValue.setErrors(nonEmpty, errors);
});
}
}
if (!definition.maxOccurs || definition.maxOccurs === 'unbound') {
definition.maxOccurs = Infinity;
} else {
definition.maxOccurs = parseInt(definition.maxOccurs, 10);
}
if (!definition.order || definition.order === 'unbound') {
definition.order = 0;
} else {
definition.order = parseInt(definition.order, 10);
}
if (typeof definition.domain === 'string') {
definition.domain = [Rdf.iri(definition.domain)];
} else if (Array.isArray(definition.domain)) {
definition.domain = definition.domain.map(domain => {
if (typeof domain === 'string') {
return Rdf.iri(domain);
}
return domain;
});
}
if (typeof definition.range === 'string') {
definition.range = Rdf.iri(definition.range);
} else if (Array.isArray(definition.range)) {
definition.range = definition.range.map(range => {
if (typeof range === 'string') {
return Rdf.iri(range);
}
(id): Dictionary => ({'element': Rdf.iri(id)})
);
).flatMap(diagramIri => {
this.workspace.getModel().history.reset();
if (this.props.postSaving === 'navigate') {
const props = {...this.props.queryParams, diagram: diagramIri.value};
return navigateToResource(Rdf.iri(this.props.navigateTo), props);
}
this.setState({diagramIri: diagramIri.value});
return Kefir.constant(undefined);
}).map(results => {
trigger({
return ImageApi.queryImageBounds(iiifServerUrl, iiifImageId).flatMap(canvasSize =>
Kefir.constant({
baseIri: imageInfo.isRegion ? imageInfo.imageIRI : Rdf.iri(iri),
imageIri: imageInfo.imageIRI,
imageServiceUri,
canvasSize,
})
).flatMapErrors(() =>
throw 'Error while parsing annotation.html';
}
editor.trigger.editable.add(content);
this.setState({
target: annotation.target,
label: annotation.label,
editor: editor,
state: content,
});
});
} else {
const content = createEmptyState();
editor.trigger.editable.add(content);
this.setState({
target: props.annotationTarget ?
Rdf.iri(props.annotationTarget.replace(/<|>/g, '')) :
undefined,
editor: editor,
state: content,
});
}
}
if (typeof definition.range === 'string') {
definition.range = Rdf.iri(definition.range);
} else if (Array.isArray(definition.range)) {
definition.range = definition.range.map(range => {
if (typeof range === 'string') {
return Rdf.iri(range);
}
return range;
});
}
if (typeof definition.xsdDatatype === 'string') {
const datatype = XsdDataTypeValidation.parseXsdDatatype(definition.xsdDatatype);
definition.xsdDatatype = datatype
? datatype.iri : Rdf.iri(definition.xsdDatatype);
}
if (definition.xsdDatatype) {
definition.xsdDatatype = XsdDataTypeValidation.replaceDatatypeAliases(definition.xsdDatatype);
} else if (definition.range) {
definition.xsdDatatype = xsd.anyURI;
}
if (!definition.defaultValues) {
definition.defaultValues = [];
}
if (typeof definition.testSubject === 'string') {
definition.testSubject = Rdf.iri(definition.testSubject);
}
return ldpAssetsService.get(workflowData.definition).flatMap(graph => {
try {
const steps = Rdf.getValuesFromPropertyPath(
[VocabWorkflow.hasStep], Rdf.pg(workflowData.definition, graph)
);
const firstStep = steps.find(step => step.value === workflowData.firstStep.value);
if (!firstStep) {
throw new Error(`Unknown step ${workflowData.firstStep}, no equals with definition's steps`);
}
const subjectIri = this.generateSubjectByTemplate(
workflowData.newWorkflowIriTemplate);
const subject = Rdf.iri('');
const workflowStateIri = Rdf.iri(
`${VocabWorkflow.hasState.value}-${uuid.v4()}`
);
const workflowMetadataIri = Rdf.iri(
`${VocabWorkflow.metadata.value}-${uuid.v4()}`
);
const timeLiteral = Rdf.literal(moment().toISOString(), xsd.dateTime);
const triples: Array = [
Rdf.triple(subject, rdf.type, VocabWorkflow.WorkflowInstantiation),
Rdf.triple(subject, VocabWorkflow.subject, workflowData.subject),
Rdf.triple(subject, VocabWorkflow.hasState, workflowStateIri),
Rdf.triple(subject, VocabWorkflow.currentState, workflowStateIri),
Rdf.triple(workflowStateIri, rdf.type, VocabWorkflow.WorkflowState),
Rdf.triple(workflowStateIri, VocabWorkflow.step, firstStep),
Rdf.triple(workflowStateIri, VocabWorkflow.startTime, timeLiteral),
];
if (workflowData.assignee.value) {
match.excluded.forEach(excludedChild => {
triples.push(Rdf.triple(matchPointer, rso.PX_match_excludes, Rdf.iri(excludedChild)));
});
}