Options
All
  • Public
  • Public/Protected
  • All
Menu

Module core

SolidLabLib.js - Core

Build status Coverage Status npm version

A library of helper functions for developing Solid apps in TypeScript/JavaScript.

This package contains logic that is common to all SolidLabLib packages.

Requirements

Installation

$ npm install @solidlab/core

or

$ yarn add @solidlab/core

Usage

Solid Utility Context

The SolidUtilContext interface represents an object that can contain fields that can be used across different helper functions within SolidLabLib. This can contain fields such as an authenticated Solid session, and a query engine.

The easiest way to obtain such a context is as follows:

import { defaultSolidUtilContext } from '@solidlab/core';

const context = defaultSolidUtilContext();

If you already have parts of the context available (such as the session), you can fill in the other missing parts as follows:

const context = defaultSolidUtilContext({ session });

Alternatively, you can create your own context from scratch as long as it contains all the required fields:

const context = {
  session, // An authenticated Solid session.
  engine, // A query engine object that can be used for finding data.
  queryContext, // A context object for passing options to the query engine during query execution.
}

Helper functions

The following helper functions are available in this package:

  • getFirstBindings: Obtains the first bindings object in a bindings stream.
  • getTermValue: Obtain the value of the given RDF term, or throw an error if the term is undefined.

License

This code is copyrighted by Ghent University – imec and released under the MIT license.

Index

References

LinkedList

Re-exports LinkedList

Type aliases

IterableSource

IterableSource<T>: T[] | AsyncIterator<T> | EventEmitter | Iterator<T> | Iterable<T>

Type parameters

  • T

MapFunction

MapFunction<S, D>: (item: S) => D | null

Type parameters

  • S

  • D = S

Type declaration

    • (item: S): D | null
    • A synchronous mapping function from one element to another. A return value of null means that nothing should be emitted for a particular item.

      Parameters

      • item: S

      Returns D | null

PartialSolidUtilContext

PartialSolidUtilContext: Partial<SolidUtilContext>

A Solid utility context where all fields are optional.

QueryContext

QueryContext: RDF.QueryStringContext & RDF.QuerySourceContext<string>

QueryEngine

QueryEngine: RDF.StringSparqlQueryable<RDF.SparqlResultSupport, QueryContext>

Task

Task: () => void

Type declaration

    • (): void
    • Returns void

TaskScheduler

TaskScheduler: (task: Task) => void

Type declaration

    • (task: Task): void
    • Parameters

      Returns void

WithFunction

WithFunction<C, F>: C extends SolidUtilContext ? F & { with: any } : { with: any }

A function with a .with() function, which is used to expand the Solid utility context. The function is only callable if the scoped context contains all required fields.

Type parameters

Variables

Const CLOSED

CLOSED: number

ID of the CLOSED state. An iterator is closed if it no longer actively generates new items. Items might still be available.

Const CLOSING

CLOSING: number

ID of the CLOSING state. An iterator is closing if item generation is pending but will not be scheduled again.

Const DESTINATION

DESTINATION: unique symbol

Key indicating the current consumer of a source.

Const DESTROYED

DESTROYED: number

ID of the DESTROYED state. An iterator has been destroyed after calling {@link module:asynciterator.AsyncIterator#destroy}. The 'end' event has not been called, as pending elements were voided.

Const ENDED

ENDED: number

ID of the ENDED state. An iterator has ended if no further items will become available. The 'end' event is guaranteed to have been called when in this state.

Const INIT

INIT: number

ID of the INIT state. An iterator is initializing if it is preparing main item generation. It can already produce items.

Const OPEN

OPEN: number

ID of the OPEN state. An iterator is open if it can generate new items.

Const defaultQueryEngine

defaultQueryEngine: QueryEngine = ...

Const solidUtilContextFull

solidUtilContextFull: SolidUtilContext = ...

A Solid utility context with default values for all required fields. It uses @comunica/query-sparql-solid as default query engine.

Const solidUtilContextLight

solidUtilContextLight: Omit<SolidUtilContext, "engine"> = ...

A Solid utility context with default values for all requied fields, except for the query engine.

Functions

createTaskScheduler

  • Returns TaskScheduler

createWithContext

  • Internal utility function to create context-scoped helper functions.

    Type parameters

    Parameters

    • functionSupplier: (context: SolidUtilContext) => F

      A factory method that determines a context scope and returns a helper function.

    • Optional defaultContext: C

      An optional default context, which defaults to the light Solid utility context.

    Returns WithFunction<C, F>

    The helper function with a .with() function, which can be used to expand the context.

empty

  • Creates an empty iterator.

    Type parameters

    • T

    Returns AsyncIterator<T>

fromArray

  • Creates an iterator for the given array.

    Type parameters

    • T

    Parameters

    • items: Iterable<T>

      the items

    Returns AsyncIterator<T>

fromIterable

  • fromIterable<T>(source: Iterable<T> | Iterator<T>): AsyncIterator<T>
  • Creates an iterator for the given Iterable.

    Type parameters

    • T

    Parameters

    • source: Iterable<T> | Iterator<T>

      the iterable

    Returns AsyncIterator<T>

fromIterator

  • fromIterator<T>(source: Iterable<T> | Iterator<T>): AsyncIterator<T>
  • Creates an iterator for the given Iterator.

    Type parameters

    • T

    Parameters

    • source: Iterable<T> | Iterator<T>

      the iterator

    Returns AsyncIterator<T>

getFirstBindings

  • getFirstBindings(bindingsStream: RDF.ResultStream<RDF.Bindings>, errorMessage?: string): Promise<RDF.Bindings>
  • Obtains the first bindings object in a bindings stream.

    Parameters

    • bindingsStream: RDF.ResultStream<RDF.Bindings>

      A stream of query result bindings.

    • errorMessage: string = 'Could not find any results, while at least one was expected'

      The error message that will be thrown when the bindings stream has no results.

    Returns Promise<RDF.Bindings>

getTaskScheduler

  • Returns the asynchronous task scheduler.

    Returns TaskScheduler

getTermValue

  • getTermValue(term?: RDF.Term): string
  • Obtain the value of the given RDF term, or throw an error if the term is undefined.

    Parameters

    • Optional term: RDF.Term

      An optional RDF term.

    Returns string

identity

  • identity<S>(item: S): typeof item
  • Function that maps an element to itself.

    Type parameters

    • S

    Parameters

    • item: S

    Returns typeof item

isEventEmitter

  • isEventEmitter(object: any): object is EventEmitter
  • Parameters

    • object: any

    Returns object is EventEmitter

isFunction

  • isFunction(object: any): object is Function
  • Parameters

    • object: any

    Returns object is Function

isIterable

  • isIterable<T>(object: {}): object is Iterable<T>
  • Type parameters

    • T

    Parameters

    • object: {}
      • [key: string]: any

    Returns object is Iterable<T>

isIterator

  • isIterator<T>(object: {}): object is Iterator<T, any, undefined>
  • Type parameters

    • T

    Parameters

    • object: {}
      • [key: string]: any

    Returns object is Iterator<T, any, undefined>

isPromise

  • isPromise<T>(object: any): object is Promise<T>
  • Type parameters

    • T

    Parameters

    • object: any

    Returns object is Promise<T>

isSourceExpression

  • isSourceExpression<T>(object: any): object is SourceExpression<T>
  • Type parameters

    • T

    Parameters

    • object: any

    Returns object is SourceExpression<T>

isValidContext

range

  • Creates an iterator of integers for the given numeric range.

    Parameters

    • start: number
    • end: number
    • Optional step: number

    Returns IntegerIterator

scheduleTask

  • scheduleTask(task: Task): void
  • Schedules the given task for asynchronous execution.

    Parameters

    Returns void

setTaskScheduler

  • Sets the asynchronous task scheduler.

    Parameters

    Returns void

single

  • Creates an iterator with a single item.

    Type parameters

    • T

    Parameters

    • item: T

      the item

    Returns AsyncIterator<T>

union

  • Creates an iterator containing all items from the given iterators.

    Type parameters

    • T

    Parameters

    Returns UnionIterator<T>

wrap

  • Creates an iterator that wraps around a given iterator or readable stream. Use this to convert an iterator-like object into a full-featured AsyncIterator. After this operation, only read the returned iterator instead of the given one.

    function

    Type parameters

    • T

    Parameters

    Returns AsyncIterator<T>

    A new iterator with the items from the given iterator

Generated using TypeDoc