@mnfst/sdk
TypeScript icon, indicating that this package has built-in type declarations

1.3.1 • Public • Published

Manifest JavaScript SDK

Official JavaScript SDK for interacting with the Manifest API.

📚 Full JS SDK documentation: manifest.build/docs

Installation:

npm i @mnfst/sdk

Usage

Use the SDK directly in your frontend:

import Manifest from '@mnfst/sdk'

// Initialize client (default: http://localhost:1111, or pass a custom base URL)
const manifest = new Manifest('https://example.com')

// Perform CRUD operations...
const posts = await manifest.from('posts').find()

Common operations

Create an item

// Create a new item in the "pokemons" entity.
const newPokemon = await manifest.from('pokemons').create({
  name: 'Pikachu',
  type: 'electric',
  level: 3
})

Get a list

// Get all users.
const users = await manifest.from('users').find()

Get a single item

// Get cat with ID `2c4e6a8b-0d1f-4357-9ace-bdf024681357`.
const cat = await manifest
  .from('cats')
  .findOneById('2c4e6a8b-0d1f-4357-9ace-bdf024681357')

Update an item

// Updates the Pokemon item with ID `a1b2c3d4-e5f6-4789-abcd-ef0123456789`.
const newPokemon = await manifest
  .from('pokemons')
  .update('a1b2c3d4-e5f6-4789-abcd-ef0123456789', {
    name: 'Raichu',
    type: 'electric',
    level: 8
  })

Patch an item

// Patches the Pokemon item with ID `a1b2c3d4-e5f6-4789-abcd-ef0123456789`.
const newPokemon = await manifest
  .from('pokemons')
  .patch('a1b2c3d4-e5f6-4789-abcd-ef0123456789', {
    level: 5
  })

Delete an item

// Delete the cat with ID `550e8400-e29b-41d4-a716-446655440000`.
const deletedCat = await manifest
  .from('cats')
  .delete('550e8400-e29b-41d4-a716-446655440000')

Load relations

// Fetch entities with 2 relations.
const cities = await manifest.from('cities').with(['region', 'mayor']).find()

// Fetch nested relations.
const cities = await manifest
  .from('cities')
  .with(['region', 'region.country', 'region.country.planet'])
  .find()

Filter by relations

// Get all cats that belong to owner with id 3f2504e0-4f89-11d3-9a0c-0305e82c3301.
const cats = await manifest
  .from('cats')
  .with(['owner'])
  .where('owner.id = 3f2504e0-4f89-11d3-9a0c-0305e82c3301')
  .find()

// Get all cats that have an owner with name "Jorge".
const cats = await manifest
  .from('cats')
  .with(['owner'])
  .where('owner.name = Jorge')
  .find()

Store relations

// Store a new player with relations Team and Skill.
const newPlayer = await manifest.from('players').create({
  name: 'Mike',
  teamId: 'e4d5c6b7-a890-4123-9876-543210fedcba',
  skillIds: [
    '12345678-1234-5678-9abc-123456789012',
    '3f2504e0-4f89-11d3-9a0c-0305e82c3301'
  ]
})

Update relations

// Replaces the whole skill relations by the new skillIds array.
await manifest.from('players').update('e4d5c6b7-a890-4123-9876-543210fedcba', {
  name: 'Mike',
  teamId: 'e4d5c6b7-a890-4123-9876-543210fedcba',
  skillIds: [
    '12345678-1234-5678-9abc-123456789012',
    '3f2504e0-4f89-11d3-9a0c-0305e82c3301'
  ]
})

// Updates the team without changing the skills or the name.
await manifest.from('players').patch('e4d5c6b7-a890-4123-9876-543210fedcba', {
  teamId: '9b2fff23-ec93-4b48-9322-bbd4b6b5b123'
})

Full documentation:

Contribute

To contribute to the Manifest JS SDK, please read first the general contributing.md file.

The best way to work with the SDK is using the /sandbox folder that hosts a minimalistic Angular app that imports the Manifest SDK. You can run the app with the following commands:

cd sandbox
npm install
npm run start

Package Sidebar

Install

npm i @mnfst/sdk

Weekly Downloads

68

Version

1.3.1

License

MIT

Unpacked Size

66.8 kB

Total Files

87

Last publish

Collaborators

  • sebastien-conejo
  • brunobuddy