https://github.com/movableink/ember-data-json-api-bulk-ext
Decorator to add support to Ember Data for the JSON:API Bulk Extension
https://github.com/movableink/ember-data-json-api-bulk-ext
Last synced: 12 months ago
JSON representation
Decorator to add support to Ember Data for the JSON:API Bulk Extension
- Host: GitHub
- URL: https://github.com/movableink/ember-data-json-api-bulk-ext
- Owner: movableink
- License: mit
- Created: 2020-03-19T15:04:55.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T16:29:25.000Z (about 3 years ago)
- Last Synced: 2025-04-06T05:23:20.941Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 1.92 MB
- Stars: 5
- Watchers: 8
- Forks: 1
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ember-data-json-api-bulk-ext

Decorator to add support to Ember Data for the [JSON:API Bulk Extension](https://github.com/json-api/json-api/blob/9c7a03dbc37f80f6ca81b16d444c960e96dd7a57/extensions/bulk/index.md).
## Compatibility
- Ember.js v3.24 or above
- Ember CLI v2.13 or above
- Node.js v12 or above
## Installation
```
ember install ember-data-json-api-bulk-ext
```
If you have not yet created a subclass of the Ember Data Store, do so now. You will want to import and apply the decorator to this class.
```javascript
// app/services/store.js
import Store from '@ember-data/store';
import { withBulkActions } from 'ember-data-json-api-bulk-ext';
@withBulkActions()
class CustomStore extends Store {}
export default CustomStore;
```
## Usage
With the decorator applied to your Store subclass, you'll have new methods on the store available to you for dealing with bulk API actions.
```javascript
const first = this.store.createRecord('post', { title: 'First Post' });
const second = this.store.createRecord('post', { title: 'Second Post' });
await this.store.bulkCreate([first, second]);
assert.ok(first.id, 'First record was given an ID');
assert.ok(second.id, 'First record was given an ID');
```
Note the following limitations:
- The models being operated on _must_ use the `JSONAPIAdapter` and `JSONAPISerializer`
- All records must be of the same type (for now)
- Records can only be created in bulk (for now)
### Using the extension MIME type
The bulk extension for JSON:API describes a custom MIME type for your requests. To override the default JSON:API MIME type and use the one from the extension, pass the following option to the `withBulkActions` decorator:
```javascript
@withBulkActions({ useExtensionMimeType: true })
class CustomStore extends Store {
```
## Contributing
See the [Contributing](CONTRIBUTING.md) guide for details.
## License
This project is licensed under the [MIT License](LICENSE.md).