Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cohere

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cohere

Simple schemas

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
768
decreased by-4.6%
Maintainers
1
Weekly downloads
 
Created
Source

Cohere

Declaratively define a schema with types and their associations with other types, then compile.

// schema.js
import Schema, { hasMany, hasOne, belongsTo } from 'cohere';

export const schema = new Schema()

  // create the user type
  .defineType('user', {
    attributes: {
      name: true,
      email: true,
    },
    relationships: {
      blogs: hasMany('blog', 'author'),
    },
  })

  // create the blog type
  .defineType('blog', {
    attributes: {
      title: true,
      content: true,
      createdOn: true,
    },
    relationships: {
      author: belongsTo('user', 'blogs'),
    },
  })

  // link types together and hydrate every relationship's inverse
  .compile();

Iterating over types, attributes, and relationships

The following iterators are supported for iterating over a type and its attributes/relationships:

  • forEach
  • map
  • some
  • every
  • filter
  • find
  • reduce
import schema from './schema.js';

schema.types.forEach(type => {
  const { attributes, relationships } = type;

  attributes.forEach(attribute => {
    const { field, type: attrType } = attribute;
    doSomething();
  });

  relationships.forEach(relationship => {
    const { field, name, relation, inverse, ...options } = relationship;
    doSomething();
  });
});

Keywords

FAQs

Package last updated on 28 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc