0.5.2 • Published 11 months ago

@lblod/ldes-producer v0.5.2

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

LDES Producer library

Usage

npm install @lblod/ldes-producer

Get Node

import {
  getNode as getNodeFn,
  addData as addDataFn,
  getConfigFromEnv,
  ACCEPTED_CONTENT_TYPES,
} from '@lblod/ldes-producer';

const config = getConfigFromEnv();

try {
  const contentType = req.accepts(ACCEPTED_CONTENT_TYPES) || '';

  const result = await getNodeFn(config, {
    folder: req.params.folder,
    contentType: contentType,
    nodeId: parseInt(req.params.nodeId ?? '1'),
    resource: req.params[0] || '',
  });

  if (result.fromCache) {
    res.header('Cache-Control', 'public, immutable');
  }

  res.header('Content-Type', contentType);

  result.stream.pipe(res);
} catch (e) {
  return next(e);
}

Add data

try {
  const contentType = req.headers['content-type'] as string;
  await addDataFn(config, {
    contentType,
    folder: req.params.folder,
    body: req.body,
    fragmenter: req.query.fragmenter as string,
  });

  res.status(201).send();
} catch (e) {
  return next(e);
}

Configuration

The following environment variables can be configured:

  • BASE_URL (required): the base-url on which this service is hosted. This ensures the service can resolve relative urls.
  • BASE_FOLDER: the parent folder to store the LDES streams in. (default: ./data)
  • LDES_STREAM_PREFIX: the stream prefix to use to identify the streams. This prefix is used in conjunction with the folder name of the stream. (default: http://mu.semte.ch/streams/)
  • TIME_TREE_RELATION_PATH: the path on which the relations should be defined when fragmenting resources using the time-fragmenter. This is also the predicate which is used when adding a timestamp to a new version of a resource. (default: http://www.w3.org/ns/prov#generatedAtTime)
  • PREFIX_TREE_RELATION_PATH: the path on which the relations should be defined when fragmenting resources using the prefix-tree-fragmenter. (default: https://example.org/name)
  • CACHE_SIZE: the maximum number of pages the cache should keep in memory. (default: 10)
  • FOLDER_DEPTH: the number of levels the data folder structure should contain. (default: 1, a flat folder structure)
  • PAGE_RESOURCES_COUNT: the number of resources (members) one page should contain. (default: 10)
  • SUBFOLDER_NODE_COUNT: the maximum number of nodes (pages) a subfolder should contain. (default: 10)
0.5.2

11 months ago

0.5.1

11 months ago

0.5.0-rc18

11 months ago

0.5.0-rc17

11 months ago

0.5.0-rc16

11 months ago

0.5.0-rc15

11 months ago

0.5.0-rc14

11 months ago

0.5.0-rc13

11 months ago

0.5.0-rc12

11 months ago

0.5.0-rc11

11 months ago

0.5.0-rc10

11 months ago

0.5.0-rc9

11 months ago

0.5.0-rc8

11 months ago

0.5.0-rc7

11 months ago

0.5.0-rc6

11 months ago

0.5.0-rc5

11 months ago

0.5.0-rc4

11 months ago

0.5.0-rc3

11 months ago

0.5.0-rc2

11 months ago

0.5.0-rc1

11 months ago