6.2.0 • Published 2 years ago

@indicia-js/remote v6.2.0

Weekly downloads
8
License
GNU GPL v3
Repository
github
Last release
2 years ago

@indicia-js/remote version Build Status

Indicia Warehouse REST API data synchronization functions.

Usage

import { Sample, Occurrence, Media } from '@indicia-js/core';
import withRemote from '@indicia-js/remote';

const SampleWithRemote = withRemote(Sample);
const OccurrenceWithRemote = withRemote(Occurrence);
const MediaWithRemote = withRemote(Media);

const sample = new SampleWithRemote();

sample.metadata = {
  survey_id: 1,
  training: true, // optional
  confidential: true, // optional
  sensitive: true, // optional
  release_status: 'R', // optional R-eleased/P-recheck/...
  record_status: 'C', // optional C-omplete/I-ncomplete/...
};

sample.remote.url = '<WAREHOUSE_HOST>/index.php/services/rest';
sample.remote.headers = {}; // can be an async function

sample.attrs.date = '12/2/2012';
sample.attrs.location = '12.345, -12.345';

var occ = new OccurrenceWithRemote();

sample.occurrences.push(occ);

// Upload to Indicia warehouse
await sample.saveRemote();

Initialization

npm i @indicia-js/remote

Configuration

You can set human friendly warehouse attribute names (ids) and values for both Sample and Occurrence attributes:

So instead of occurrence.attrs[232] = 12343 one can occurrence.attrs.taxon = 'bee', examples:

// Sample.keys
Occurrence.keys = {
  // no value mapping
  certain: {
    id: 398,
  },
  // object
  taxon: {
    id: 232,
    values: {
      1: 272198,
      bee: 12343,
    },
  },
  // array
  weather: {
    id: 122,
    values: [
      { value: 'sunny', id: 272398 },
      { value: 'rainy', id: 132343 },
    ],
  },
  // function
  colour: {
    id: 251,
    values(value) {
      return 'ome calculated value here';
    },
  },
};

API

// all models

model.id: null | Number
model.keys: Object | Function
model.getSubmission() ⇒ Object

// Sample
sample.remote: Object
sample.saveRemote() ⇒ Promise

// Media
media.remote: Object
media.upload() ⇒ Promise
media.getRemoteURL() ⇒ string

Bugs and feature requests

Have a bug or a feature request? Search for existing and closed issues. Please open a new issue.

Creators

Karolis Kazlauskis

Copyright and license

Code and documentation copyright 2020 CEH. Code released under the GNU GPL v3 license.

6.2.0

2 years ago

6.1.5

2 years ago

6.1.4

2 years ago

6.1.3

2 years ago

6.1.0

2 years ago

6.1.2

2 years ago

6.1.1

2 years ago

6.0.0

3 years ago

5.6.8

3 years ago

5.6.7

3 years ago

5.6.6

3 years ago

5.6.5

3 years ago

5.6.4

4 years ago

5.6.3

4 years ago

5.6.2

4 years ago

5.6.0

4 years ago

5.6.1

4 years ago

5.5.0

4 years ago