Nanotechnology Promises Much
    Wondering what’s next for npm?Check out our public roadmap! »

    @concordant/c-service
    TypeScript icon, indicating that this package has built-in type declarations

    1.1.6 • Public • Published

    C-Service

    License pipeline status coverage report

    The first version of C-Service: a distributed database service for CRDTs of the C-CRDTlib.

    The C-Service is meant to run on edge devices (terminal or PoP) and (will) support transactions and replication between services. It (will) run as a ServiceWorker in web browsers or as a standalone application.

    The C-Service exposes a REST API which should not be accessed directly, as it may not be stable; use the C-Client library instead.

    Getting started

    Requirements

    For the next steps, you will need the following software:

    • Make sure you have the latest stable version of Node.js;
    • C-Service runs on top of CouchDB.

    In addition, you will need to enable CORS in CouchDB. You can use the dedicated NPM package from PouchDB:

    npx add-cors-to-couchdb [http://mycouchDBserver.org] \
        [-u myusername] [-p mypassword]
    (server defaults to localhost)

    or the CouchDB user panel.

    Start C-Service

    Ensure CouchDB is running before starting C-Service. If it is running on another host, set the COUCHDB_URL accordingly. You will also need to provide CouchDB credentials:

    export COUCHDB_URL=my-couchdb-server.org
    export COUCHDB_USER=my-user COUCHDB_PASSWORD=my-passwd

    Then run the service:

    npx @concordant/c-service

    This launches an Express server listening on TCP port 4000.

    Setup C-Service as a Systemd service

    First ensure CouchDB is setup as a systemd service named couchdb.service (or adapt the name in c-service.service file).

    Put the c-service folder in /opt/ or adapt the c-service.service file.

    Put the provided file c-service.service in /etc/systemd/system/.

    Create the file /etc/systemd/system/c-service.conf containing CouchDB admin credentials:

    COUCHDB_USER=<couchdb_id>
    COUCHDB_PASSWORD=<couchdb_password>

    Then start the service:

    systemctl start c-service

    Test C-Service using curl

    The C-Service exposes a REST API on /api, whose description can be found in file swagger.yml.

    Once your C-Service is running you can query its REST API with curl. You can view your changes in the CouchDB user pannel.

    Create the myapp database:

    curl --request POST                               \
         --header "Content-Type: application/json"    \
         --data '{"appName":"myapp"}'                 \
         http://127.0.0.1:4000/api/create-app

    Insert/update a PNCounter named myobject in myapp database:

    curl --request POST                               \
         --header "Content-Type: application/json"    \
         --data '{"appName":"myapp","id":"{\"name\":\"myobject\",\"type\":\"PNCounter\"}","document":"{\"type\":\"PNCounter\",\"metadata\":{\"increment\":[{\"name\":\"clientid\"},{\"first\":60,\"second\":{\"uid\":{\"name\":\"clientid\"},\"cnt\":-21474836}}],\"decrement\":[]},\"value\":60}"}'  \
         http://127.0.0.1:4000/api/update-object

    Get the PNCounter named myobject in myapp database:

    curl --request POST                               \
         --header "Content-Type: application/json"    \
         --data '{"appName":"myapp","id":"{\"name\":\"myobject\",\"type\":\"PNCounter\"}"}'                       \
         http://127.0.0.1:4000/api/get-object

    Get all objects of myapp database:

    curl --request POST                               \
         --header "Content-Type: application/json"    \
         --data '{"appName":"myapp"}'                 \
         http://127.0.0.1:4000/api/get-objects

    Delete myapp database:

    curl --request POST                               \
         --header "Content-Type: application/json"    \
         --data '{"appName":"myapp"}'                 \
         http://127.0.0.1:4000/api/delete-app

    Install

    npm i @concordant/c-service

    DownloadsWeekly Downloads

    13

    Version

    1.1.6

    License

    MIT

    Unpacked Size

    47.4 kB

    Total Files

    20

    Last publish

    Collaborators

    • avatar