Socket
Book a DemoInstallSign in
Socket

@bagaaravel/ember-data-extensions

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@bagaaravel/ember-data-extensions

Ember Data extensions to communicate with the Bagaaravel JSON API implementation.

2.0.0
latest
Source
npmnpm
Version published
Weekly downloads
4
-20%
Maintainers
1
Weekly downloads
 
Created
Source

Bagaaravel Ember Data Extensions

CI Code Style: Prettier Conventional Commits

Ember Data extensions to communicate with the Bagaaravel JSON API implementation.

Table of Contents

Introduction

@bagaaravel/ember-data-extensions is an addon that allows you to easily communicate with the Bagaaravel JSON API implementation.

Support

@bagaaravel/ember-data-extensions supports Ember v3.24 and up.

Installation

ember install @bagaaravel/ember-data-extensions

Usage

1. Extend the Application Serializer

// app/serializers/application.js

import {
  keyForAttribute,
  keyForRelationship,
  payloadKeyFromModelName,
  serialize,
  shouldSerializeHasMany
} from '@bagaaravel/ember-data-extensions/serializer'
import JSONAPISerializer from '@ember-data/serializer/json-api'

export default class ApplicationSerializer extends JSONAPISerializer {
  // Make sure attribute keys have the correct casing:
  keyForAttribute () {
    return keyForAttribute(...arguments)
  }

  // Make sure relationship keys have the correct casing:
  keyForRelationship () {
    return keyForRelationship(...arguments)
  }

  // Make sure model types have the correct casing:
  payloadKeyFromModelName () {
    return payloadKeyFromModelName(...arguments)
  }

  // Make sure relationships are correctly serialized:
  serialize () {
    const serialized = super.serialize(...arguments)

    return serialize(serialized, ...arguments)
  }

  // Check when 'hasMany' relationships should be serialized:
  shouldSerializeHasMany () {
    const superCheck = super.shouldSerializeHasMany(...arguments)

    return shouldSerializeHasMany(superCheck, ...arguments)
  }
}

2. Extend the Application Adapter

// app/adapters/application.js

import { urlForUpdateRecord } from '@bagaaravel/ember-data-extensions/adapter'
import JSONAPIAdapter from '@ember-data/adapter/json-api'

export default class ApplicationAdapter extends JSONAPIAdapter {
  // Make sure the correct URL is used when only saving a relationship:
  urlForUpdateRecord () {
    const baseUrl = super.urlForUpdateRecord(...arguments)

    return urlForUpdateRecord(baseUrl, ...arguments)
  }
}

3. Updating Relationships

import {
  saveRelationship,
  saveRelationships
} from '@bagaaravel/ember-data-extensions/model'

const user = await this.store.findRecord('user', '1')

// Update the user's projects:
saveRelationship(user, 'projects')

// Update the user's company:
saveRelationship(user, 'company')

// Update the user's projects and company:
saveRelationships(user, ['projects', 'company'])

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.

Maintenance

@bagaaravel/ember-data-extensions is built and maintained by Bagaar.

Keywords

bagaar

FAQs

Package last updated on 23 Jun 2022

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.