Skip to content

Instantly share code, notes, and snippets.

@tpluscode
Last active February 5, 2020 16:11
Show Gist options
  • Save tpluscode/04894a50289df076a031596c624f8767 to your computer and use it in GitHub Desktop.
Save tpluscode/04894a50289df076a031596c624f8767 to your computer and use it in GitHub Desktop.
Alcaeus breaking changes

Main export

-import { Hydra } from 'alcaeus'
+import Hydra from 'alcaeus'

Remove Vocab export

-import { Vocab } from 'alcaeus'

Resource identifier

Was string. Now is NamedNode | BlankNode

More conveniently referred to as import { ResourceIdentifier } from 'alcaeus'

API Documentation loaded separately

API Documentation resources are downloaded automatically but as a separate promise

import Hydra from 'alcaeus'

const resoruce = await Hydra.loadeResource(uri)
+const docs: ApiDocumentation[] = await Hydra.apiDocumentations

Resource#types

Changed implementation, now extends Set<RdfResource>

Changes in interface and their exports

  • All resource interface lose the I prefix according to TypeScript best practices
  • additionally, all can be imported from main module
-import { IOperation } from 'alcaeus/types/Resources'
+import { Operation } from 'alcaeus'

invokeOperation signature

-invokeOperation(operation: Operation, uri: string, body?: BodyInit, headers?: string | HeadersInit): Promise<HydraResponse>;
+invokeOperation(operation: Operation, body?: BodyInit, headers?: string | HeadersInit): Promise<HydraResponse>;

The called URI is retrieved from the id of operation.target

No default parser

Parsers have to be added explicitly to have Alcaeus recognize RDF serializations. Either one-by-one

import Hydra from 'alcaeus'
import ParserJsonLd from '@rdfjs/parser-jsonld'

Hydra.parsers.set('application/ld+json', new ParserJsonLd())

Or importing a set of common parser (large in size; not ideal for browser)

import Hydra from 'alcaeus'
import { parsers } from '@rdfjs/formats-common'

parsers.forEach((parser, mediaType) => Hydra.parsers.set(mediaType, parser))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment