Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new PromiseProxyIterator(async () => {
let output: IActorRdfResolveQuadPatternOutput;
if (this.isSourceEmpty(source, pattern)) {
output = { data: new EmptyIterator(), metadata: () => Promise.resolve({ totalItems: 0 }) };
} else {
output = await this.mediatorResolveQuadPattern.mediate({ pattern, context });
}
if (output.metadata) {
output.metadata().then((subMetadata: {[id: string]: any}) => {
if ((!subMetadata.totalItems && subMetadata.totalItems !== 0) || !isFinite(subMetadata.totalItems)) {
metadata.totalItems = Infinity;
remainingSources = 0; // We're already at infinite, so ignore any later metadata
checkEmitMetadata(Infinity, source, pattern, subMetadata);
} else {
metadata.totalItems += subMetadata.totalItems;
remainingSources--;
checkEmitMetadata(subMetadata.totalItems, source, pattern, subMetadata);
}
});
} else {
public getIterator(iteratorOptions: IConnectionsIteratorOptions): AsyncIterator {
const { backward } = iteratorOptions;
let { lowerBoundDate, upperBoundDate } = iteratorOptions;
if (this.hasFinishedPrimary && this.store.length === 0) {
return new EmptyIterator();
}
const firstConnection = this.store[0];
const firstDepartureTime = firstConnection && firstConnection.departureTime;
const lastConnection = this.store[this.store.length - 1];
const lastDepartureTime = lastConnection && lastConnection.departureTime;
if (lowerBoundDate && lowerBoundDate < firstDepartureTime) {
throw new Error("Must supply a lowerBoundDate after the first prefetched connection");
}
if (backward) {
if (!upperBoundDate) {
throw new Error("Must supply upperBoundDate when iterating backward");
exitLocation,
exitConnection.travelMode,
{ average: duration },
departureTime,
arrivalTime,
undefined,
enterConnection.id,
exitConnection.id,
);
path.addStep(step);
currentStopId = enterConnection.departureStop;
}
if (!path.steps.length) {
return new EmptyIterator();
}
path.reverse();
return new SingletonIterator(path);
}