Giter Club home page Giter Club logo

js-coalaip's Introduction

Javascript implementation for COALA IP.

Install

This project is available through npm. To install run

> npm install coalaip --save

Linked Metadata

This project provides tools for structuring metadata, using schema definitions with the ability to set arbitrary properties on type instances. Metadata is translatable to linked-data formats (e.g. IPLD) for persistence to different databases/storage layers.

Module Overview

Core

This module contains the types outlined in the specification. Additional types have been included because types in the specification inherit from them or certain properties expect other types.

Music

This module extends the core module with the following types: MusicAlbum, MusicComposition, MusicGroup, MusicPlaylist, MusicRecording, and MusicRelease.

Getting Started

Some code to get started structuring metadata. In order to persist to a storage layer, consider using Constellate.

Create a Person

const Person = require('coalaip/lib/core').Person

const man = new Person()
man.setGivenName('John')
man.setFamilyName('Smith')
man.setEmail('[email protected]')
man.set('arbitrary', 'value')

// or if the object is already structured
const woman = {
  givenName: 'Jane',
  familyName: 'Smith',
  email: '[email protected]',
  arbitrary: 'value'
}

const person = new Person()
person.withData(woman)

Access the Person's data

console.log(man.data())

// {
//   "@context": "http://schema.org",
//   "@type": "Person",
//   "givenName": "John",
//   "familyName": "Smith",
//   "email": "[email protected]",
//   "arbitrary": "value"
// }

// or if you want the data canonically ordered...

console.log(man.dataOrdered())

// {
//   "@context": "http://schema.org",
//   "@type": "Person",
//   "arbitrary": "value",
//   "email": "[email protected]",
//   "familyName": "Smith",
//   "givenName": "John"
// }

Add/Set sub-instances

addProperty for property that expects an array

setProperty for property that expects a single value

const {
  MusicComposition,
  MusicGroup,
  MusicRecording
} = require('coalaip/lib/music')

// 'member' expects an array of Parties
const group = new MusicGroup()
group.setDescription('descriptive')
group.setName('Beatles')
group.addMember(man)
group.path = '<placeholder group path>'

const composition = new MusicComposition()
// 'composer' expects an array of Parties
composition.addComposer(man)
composition.path = '<placeholder composition path>'

const recording = new MusicRecording()
// 'byArtist' expects an array of MusicGroups
recording.addByArtist(group)
// 'recordingOf' expects a MusicComposition
recording.setRecordingOf(comp)

console.log(recording.data())

// {  
//   "@context": "http://coalaip.org",
//   "@type": "MusicRecording",
//   "byArtist": [  
//     {  
//       "@context": "http://schema.org",
//       "@type": "MusicGroup",
//       "name": "Beatles",
//       "description": "descriptive",
//       "member": [  
//         {  
//           "@context": "http://schema.org",
//           "@type": "Person",
//           "givenName": "John",
//           "familyName": "Smith",
//           "email": "[email protected]"
//         }
//       ]
//     }
//   ],
//   "recordingOf": {  
//     "@context": "http://coalaip.org",
//     "@type": "MusicComposition",
//     "composer": [  
//       {  
//         "@context": "http://schema.org",
//         "@type": "Person",
//         "givenName": "John",
//         "familyName": "Smith",
//         "email": "[email protected]"
//       }
//     ]
//   }
// }

// and the ipld...

console.log(recording.ipld())

// {  
//   "@context": "http://coalaip.org",
//   "@type": "MusicRecording",
//   "byArtist": [  
//     {  
//       "/": "<placeholder group path>"
//     }
//   ],
//   "recordingOf": {  
//     "/": "<placeholder composition path>"
//   }
// }

Access sub-instances

instance.subInstances() returns a flattened array with instance and the unique instances nested within instance. To ease handling of metadata in other programs, the instances are ordered based on the other instances they contain.

const metadata = recording.subInstances()
console.log(metadata)

// [man, group, composition, recording]

// (1) man contains no other instances
// (2,3) group and composition contain man
// (4) recording contains composition and group

js-coalaip's People

Contributors

listenaddress avatar oftenfrequent avatar zachb14 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-coalaip's Issues

Traversing the links or How to validating the rights

Came across this while looking for linked model for assets to be stored in BigChainDB.

After converting data into this particular format, how to take advantage of its structure? For example, how to enforce if a person is the author or not (or has the required rights to it or not) ? or how to traverse the links and get the related data? Does the API cover such tasks?

auto enumerating the properties

Is it possible to automatically (programatically) get the list of properties of any type?
For example, something like

const man = new Person()

man.getListOfAllProperties(); // returns ["givenName", "familyName", ...]

Separate Party class?

@TimDaub I forgot to mention this implementation has a Party class, then I subclass Person and Organization from Party. Would like to hear your thoughts on this change.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.