Class ROCrate

Class for building, navigating, testing and rendering ROCrates

Todo

import validation and rendering from Calcyte

Hierarchy

  • ROCrate

Constructors

  • Create a new ROCrate object using a default template or from a valid jsonld object.

    Parameters

    • json: any = {}

      a valid jsonld object

    • Optional config: {
          array: boolean;
          defaultType: string;
          duplicate: boolean;
          link: boolean;
          merge: boolean;
          replace: boolean;
      }
      • array: boolean

        Always return property of an Entity as an array (eg when using getEntity() method)

      • defaultType: string

        The default value for @type to be used when adding a new entity and the property is not specified. Default to 'Thing'

      • duplicate: boolean

        Allow duplicate values in a property that has multiple values

      • link: boolean

        Resolve linked node as nested object

      • merge: boolean

        When replacing or updating an entity, merge the values and the properties instead of full replace

      • replace: boolean

        When importing from json, a subsequent duplicate entity always replaces the existing one

    Returns ROCrate

Properties

__context: Set<any> = ...

Internal representation of the context

__contextDefinitionIndex: Map<any, any> = ...
__contextTermIndex: Map<any, any> = ...

Index of all context contents or terms

__handler: Handler

Lookup table to index nodes by their properties

__handlerReverse: {
    get(target, prop) => any;
}

Type declaration

  • get:function
    • Parameters

      • target: any
      • prop: any

      Returns any

__nodeById: Map<string, Node> = ...

Lookup table to get a reference to existing and non-existing nodes. This is needed to avoid searching for the whole graph for every "@reverse" lookup as an entity referenced by other entities may not exist yet in the graph.

config: {}

Type declaration

    defaults: {
        ROCrate_Specification_Identifier: string;
        back_back_links: Set<any>;
        back_links: {};
        context: (string | {
            @vocab: string;
        })[];
        datasetTemplate: {
            @id: string;
            @type: string;
        };
        metadataFileDescriptorTemplate: {
            @id: string;
            @type: string;
            about: {
                @id: string;
            };
            identifier: string;
        };
        pageSize: number;
        render_script: string;
        roCrateMetadataID: string;
        roCrateMetadataIDs: string[];
        roCratePreviewFileName: string;
        ro_crate_name: string;
    } = defaults

    Type declaration

    • ROCrate_Specification_Identifier: string
    • back_back_links: Set<any>
    • back_links: {}
      • context: (string | {
            @vocab: string;
        })[]
      • datasetTemplate: {
            @id: string;
            @type: string;
        }
        • @id: string
        • @type: string
      • metadataFileDescriptorTemplate: {
            @id: string;
            @type: string;
            about: {
                @id: string;
            };
            identifier: string;
        }
        • @id: string
        • @type: string
        • about: {
              @id: string;
          }
          • @id: string
        • identifier: string
      • pageSize: number
      • render_script: string
      • roCrateMetadataID: string
      • roCrateMetadataIDs: string[]
      • roCratePreviewFileName: string
      • ro_crate_name: string
      utils: typeof Utils = Utils

      Deprecated

      Import Utils class directly

      defaults: {
          ROCrate_Specification_Identifier: string;
          back_back_links: Set<any>;
          back_links: {};
          context: (string | {
              @vocab: string;
          })[];
          datasetTemplate: {
              @id: string;
              @type: string;
          };
          metadataFileDescriptorTemplate: {
              @id: string;
              @type: string;
              about: {
                  @id: string;
              };
              identifier: string;
          };
          pageSize: number;
          render_script: string;
          roCrateMetadataID: string;
          roCrateMetadataIDs: string[];
          roCratePreviewFileName: string;
          ro_crate_name: string;
      } = defaults

      Type declaration

      • ROCrate_Specification_Identifier: string
      • back_back_links: Set<any>
      • back_links: {}
        • context: (string | {
              @vocab: string;
          })[]
        • datasetTemplate: {
              @id: string;
              @type: string;
          }
          • @id: string
          • @type: string
        • metadataFileDescriptorTemplate: {
              @id: string;
              @type: string;
              about: {
                  @id: string;
              };
              identifier: string;
          }
          • @id: string
          • @type: string
          • about: {
                @id: string;
            }
            • @id: string
          • identifier: string
        • pageSize: number
        • render_script: string
        • roCrateMetadataID: string
        • roCrateMetadataIDs: string[]
        • roCratePreviewFileName: string
        • ro_crate_name: string

        Accessors

        • get context(): any
        • The context part of the crate. An alias for '@context'. This returns the original context information.

          Returns any

        • get graph(): any[]
        • An array of all nodes in the graph. An alias for '@graph'

          Returns any[]

        • get rootId(): string
        • The root identifier of the RO Crate

          Returns string

        • set rootId(newId): void
        • Parameters

          • newId: string

          Returns void

        Methods

        • Parameters

          • ref: any
          • prop: any
          • oldValues_: any
          • values: any
          • __namedParameters: Object

          Returns any

        • Create a new node or return an existing node with the given data

          Parameters

          • id: string

            Identifier of the node (@id)

          • Optional ref: NodeRef

            An immutable and unique reference to node that contains id and reverse information only

          Returns Node

          a newly created or existing node that matches the id

        • Return a proxy that wraps a node as an entity object supporting linked objects capability.

          Parameters

          • n: Node

          Returns any

        • Parameters

          • entity: Node
          • prop: string
          • values: any
          • opt: {
                duplicate: boolean;
                merge: boolean;
                recurse: boolean;
                replace: boolean;
                seen: WeakSet<any>;
            }
            • duplicate: boolean
            • merge: boolean
            • recurse: boolean
            • replace: boolean
            • seen: WeakSet<any>

          Returns boolean

        • Parameters

          • idOrEntity: any

          Returns Node

        • Init a new node or update existing one

          Parameters

          • node: Node
          • data: any

            Update the node with the given data

          • opt: {
                add: boolean;
                merge: boolean;
                recurse: boolean;
                replace: boolean;
                seen: WeakSet<any>;
            }
            • add: boolean

              If true, create an entity even if the data is empty

            • merge: boolean

              If false and if node already exists, remove all existing properties not in the specified data

            • recurse: boolean

              Process nested objects recursively

            • replace: boolean

              If false and if node already exists, do nothing to the node

            • seen: WeakSet<any>

              A set to keep track of cyclic reference in the input

          Returns boolean

          Return true if node is changed

        • Returns void

          Deprecated

          Not required anymore. Calling this method will do nothing.

        • Append the specified string or object directly as an entry into the RO-Crate JSON-LD Context array. It does not check for duplicates or overlapping content if the context is an object.

          Parameters

          • context: any

            A URL or an Object that contains the context mapping

          Returns void

        • Add an entity to the crate.

          Parameters

          • data: any

            A valid RO-Crate entity described in plain object.

          • opt: {
                recurse: boolean;
                replace: boolean;
            } = {}
            • recurse: boolean

              If true, nested entities will be added as well.

            • replace: boolean

              If true, replace existing entity with the same id.

          Returns boolean

          true if the entity is successfully added.

        • Add a new identifier as a PropertyValue to the root DataSet. identifier and name are required parameters

          Parameters

          • options: {
                description: string;
                identifier: string;
                name: string;
            }
            • description: string
            • identifier: string
            • name: string

          Returns string

          The added identifier or undefined

        • This silently fails if the item has no

          Parameters

          • item: any

          Returns boolean

          Id

          or already exists - this is probably sub-optimal

          Deprecated

          Use addEntity

        • Add a Profile URI to the crate

          Parameters

          • uri: string

            A valid Profile URI

          Returns void

        • Parameters

          • prov: any

          Returns void

        • Add the term and its definition to the first context definition (a map) found from the @context entries. If no existing context definition found, a new one will be created.

          Parameters

          • term: string
          • definition: any

          Returns void

        • Add one or more value to a property of an entity. If the specified property does not exists, a new one will be set. If the property already exists, the new value will be added to the property array.

          Parameters

          • idOrEntity: any

            The id or the entity to add the property to

          • prop: string

            The name of the property

          • values: any

            The value of the property

          • opt: {
                duplicate: boolean;
            } = {}
            • duplicate: boolean

              If true, allow a property to have duplicate values in the array

          Returns boolean

        • Parameters

          • subgraphs: any

          Returns any[]

          Deprecated

          Use union, eg: union([sg1, sg2])

        • Delete an entity from the graph

          Parameters

          • id_or_entity: string | Entity

            Entity Identifier or the entity object itself

          • opt: {
                references: boolean;
            } = {}
            • references: boolean

              Set true to delete all references to the deleted entity

          Returns boolean

          True if any existing entity was deleted

        • Delete a property of an Entity

          Parameters

          • idOrEntity: any

            The id of the entity to add the property to

          • prop: string

            The name of the property

          Returns boolean

          • True, if the property has been deleted
        • Delete one or more values from a property.

          Parameters

          • idOrEntity: string | Entity
          • prop: string
          • values: any

          Returns void

        • Returns a new iterator object that contains the entities in the graph.

          Parameters

          • p: {
                filter: any;
                flat: boolean;
            } = {}
            • filter: any

              Filter the result based on the values of the properties defined in this object.

            • flat: boolean

              If true, return the copy of entity as a plain object.

          Returns {
              [iterator]() => { [Symbol.iterator](): ...; next(): { done: boolean; value: any; }; };
              next() => {
                  done: boolean;
                  value: any;
              };
          }

          • [iterator]:function
            • Returns { [Symbol.iterator](): ...; next(): { done: boolean; value: any; }; }

          • next:function
            • Returns {
                  done: boolean;
                  value: any;
              }

              • done: boolean
              • value: any
        • Experimental method to turn a graph into a flat dictionary eg for turning it into a table

          Parameters

          • item: any
          • depth: any
          • flatItem: any
          • propPath: any
          • seen: any

          Returns any

        • Get configuration value

          Parameters

          • key: "replace" | "link" | "array" | "merge" | "duplicate"

            Name of the config parameter

          Returns any

        • Get the context term definition. This method will also search for term defined locally in the graph. Make sure resolveContext() has been called prior calling this method.

          Parameters

          • term: string

          Returns any

        • Get an entity from the graph. If config.link is true, any reference (object with just "@id" property) is resolved as a nested object.

          Parameters

          • id: string

            An entity identifier

          Returns Entity

          A wrapper for entity that resolves properties as linked objects

        • Get an array of all nodes in the graph. Each node in the array is an Entity instance. If config.link is true, any link to other node will be made into nested object.

          Parameters

          • flat: boolean = false

            If true, return the copy of entity as a plain object.

          Returns any[]

        • Get named identifier

          Parameters

          • name: string

          Returns string

          the identifier

        • Returns {
              @context: any[];
              @graph: any[];
          }

          • @context: any[]
          • @graph: any[]

          Deprecated

          Use toJSON

        • Parameters

          • root: any
          • depth: number = 1

          Returns any

          Deprecated

          Use getTree with the following argument: { root, depth, allowCycle: true }

        • Get the property of an entity

          Parameters

          • idOrEntity: any
          • prop: string

          Returns any

          the value of the property

        • Get the context term name from it's definition id. Make sure resolveContext() has been called prior calling this method.

          Parameters

          • definition: any

          Returns any

        • Return a JSON.stringify-ready tree structure starting from the specified item with all values (apart from @id) as arrays and string-values expressed like: {"@value": "string-value"}

          Parameters

          • opt: {
                allowCycle: boolean;
                depth: number;
                root: any;
                valueObject: boolean;
            } = {}
            • allowCycle: boolean
            • depth: number

              The number of nesting the tree will have. Must be 0 or positive integer.

            • root: any
            • valueObject: boolean

          Returns any

          the root entity

        • Check if entity exists in the graph

          Parameters

          • id: string

            An entity identifier

          Returns boolean

        • Check if an entity has a type

          Parameters

          • item: any
          • type: string

          Returns boolean

        • Returns void

          Deprecated

          Not required anymore. Calling this method will do nothing.

        • Get the index of the entity in the graph array. This is an O(n) operation.

          Parameters

          • entityId: string

          Returns number

        • Create a simple tree-like object - but don't make circular structures

          Returns any

          Deprecated

          Use getTree with the valueObject argument set to false`

        • Add a value to an item's property array

          Parameters

          • item: any
          • prop: string
          • val: any
          • allowDuplicates: boolean = false

          Returns void

          Deprecated

          Use addValues

        • Parameters

          • items: any

            A JSON-LD item or array of [item]

          • pathArray: any[]

            An array of objects that represents a 'path' through the graph. Object must have a "property" to follow, eg: resolve(item, {"property": "miltaryService"}); and optionally a condition "includes", eg: "includes": {"@type", "Action"}} and optionally, a function "matchFn" which takes an item as argument and returns a boolean, eg: "matchFn": (item) => item['@id'].match(/anzsrc-for/)

          • Optional subgraph: any[]

            If present and true, all intervening items during the traversal will be stored. If an array is passed, the intervening items will be stored in the array.

          Returns any[]

          null, or an array of items

        • resolveAll does a resolve but collects and deduplicates intermediate items. Its first returned value is the final items (ie what resolve(..)) would have returned.

          Parameters

          • items: any
          • pathArray: any

          Returns any[][]

        • Generate a local flat lookup table for context terms

          Returns Promise<{
              getDefinition(term) => any;
              getTerm(definition) => any;
          }>

        • Expand a term into the IRI, which is the same as the @id of the term definition. Make sure resolveContext() has been called prior calling this method.

          Parameters

          • term: string

            a short word defined in the context

          Returns string

        • Set a property of an entity with the given value. If a property with the same name exists, its existing value will be replaced with the specified value. If values contain nested non-empty entities, they will be processed recursively.

          Parameters

          • idOrEntity: any

            The id of the entity to add the property to

          • prop: string

            The name of the property

          • values: any

            A value or an array of values

          • opt: {
                duplicate: boolean;
            } = {}
            • duplicate: boolean

              If true, allow a property to have duplicate values

          Returns boolean

        • Returns boolean

          Deprecated

          Specify {array: true, link: true} in the options when creating the ROCrate instance

        • Convert the rocrate into plain JSON object. The value returned by this method is used when JSON.stringify() is used on the ROCrate object.

          Returns {
              @context: any[];
              @graph: any[];
          }

          plain JSON object

          • @context: any[]
          • @graph: any[]
        • Generate a new unique id that does not match any existing id in the graph.

          Parameters

          • base: string

            The base string of the id.

          Returns string

          The base suffixed with the incremental number.

        • Update an entity by replacing the object with the same id. This operations will remove all properties of the existing entity and add the new ones contained in data, unless merge argument is true.

          Parameters

          • data: any
          • opt: {
                merge: boolean;
                recurse: boolean;
            } = {}
            • merge: boolean

              If true, new properties will be merged. Defaults to config.merge.

            • recurse: boolean

              If true, nested entities will be updated as well.

          Returns boolean

          false if there is no existing entity with the same id or data is empty.

        • Change the identifier of an entity node

          Parameters

          • idOrEntity: any
          • newId: string

          Returns boolean

        Generated using TypeDoc