# next-core-model

> The Augmented.js Next - Model & Collection.

Latest version **3.1.5** (published 2020-07-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install next-core-model
pnpm add next-core-model
yarn add next-core-model
bun add next-core-model
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.1.5 |
| Published | 2020-07-18 |
| First published | 2018-08-20 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 12 |
| Unpacked size | 318.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Bob Warren |
| Maintainers | thedocbwarren |
| Keywords | augmentedjs, presentation |

## Links

- npm: https://www.npmjs.com/package/next-core-model
- Repository: https://github.com/Augmentedjs/next-core-model
- Homepage: http://www.augmentedjs.com
- Issues: https://github.com/Augmentedjs/next-core-model/issues
- npm.io page: https://npm.io/package/next-core-model

## Dependencies (12)

- [lodash.has](https://npm.io/package/lodash.has.md) ^4.5.2
- [lodash.clone](https://npm.io/package/lodash.clone.md) ^4.5.0
- [lodash.defer](https://npm.io/package/lodash.defer.md) ^4.1.0
- [lodash.escape](https://npm.io/package/lodash.escape.md) ^4.0.1
- [lodash.result](https://npm.io/package/lodash.result.md) ^4.5.2
- [lodash.isempty](https://npm.io/package/lodash.isempty.md) ^4.4.0
- [lodash.isequal](https://npm.io/package/lodash.isequal.md) ^4.5.0
- [lodash.defaults](https://npm.io/package/lodash.defaults.md) ^4.2.0
- [lodash.iteratee](https://npm.io/package/lodash.iteratee.md) ^4.7.0
- [next-core-object](https://npm.io/package/next-core-object.md) ^3.0.0
- [next-core-utilities](https://npm.io/package/next-core-utilities.md) ^2.9.0
- [next-core-validation](https://npm.io/package/next-core-validation.md) ^2.5.5

## Recent versions

- 3.1.5 (latest) — 2020-07-18
- 3.1.4 — 2020-07-04
- 3.1.3 — 2020-06-09
- 3.1.1 — 2020-06-08
- 3.1.0 — 2020-06-08
- 3.0.1 — 2020-05-14
- 3.0.0 — 2020-05-13
- 2.7.0 — 2019-10-04
- 2.6.2 — 2019-08-08
- 2.6.1 — 2019-06-23
- 2.6.0 — 2019-03-20
- 2.5.6 — 2019-03-20
- 2.5.5 — 2018-11-16
- 2.5.4 — 2018-09-15
- 2.5.3 — 2018-08-20

## README

# next-core-model

Augmented.js Next Core - Model & Collection

# API

<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

### Table of Contents

-   [AbstractModel](#abstractmodel)
    -   [Parameters](#parameters)
    -   [uriRoot](#uriroot)
        -   [Properties](#properties)
    -   [schema](#schema)
        -   [Properties](#properties-1)
    -   [validationMessages](#validationmessages)
        -   [Properties](#properties-2)
    -   [get](#get)
        -   [Parameters](#parameters-1)
    -   [set](#set)
        -   [Parameters](#parameters-2)
    -   [escape](#escape)
        -   [Parameters](#parameters-3)
    -   [has](#has)
        -   [Parameters](#parameters-4)
    -   [matches](#matches)
        -   [Parameters](#parameters-5)
    -   [unset](#unset)
        -   [Parameters](#parameters-6)
    -   [clear](#clear)
        -   [Parameters](#parameters-7)
    -   [toJSON](#tojson)
    -   [fetch](#fetch)
        -   [Parameters](#parameters-8)
    -   [fetch](#fetch-1)
        -   [Parameters](#parameters-9)
    -   [save](#save)
        -   [Parameters](#parameters-10)
    -   [save](#save-1)
        -   [Parameters](#parameters-11)
    -   [destroy](#destroy)
        -   [Parameters](#parameters-12)
    -   [destroy](#destroy-1)
        -   [Parameters](#parameters-13)
    -   [url](#url)
    -   [uri](#uri)
    -   [keys](#keys)
    -   [values](#values)
    -   [parse](#parse)
        -   [Parameters](#parameters-14)
    -   [clone](#clone)
    -   [isNew](#isnew)
    -   [hasChanged](#haschanged)
        -   [Parameters](#parameters-15)
    -   [changedAttributes](#changedattributes)
        -   [Parameters](#parameters-16)
    -   [previous](#previous)
        -   [Parameters](#parameters-17)
    -   [previousAttributes](#previousattributes)
    -   [supportsValidation](#supportsvalidation)
    -   [isValid](#isvalid)
        -   [Parameters](#parameters-18)
    -   [validate](#validate)
    -   [getValidationMessages](#getvalidationmessages)
    -   [sync](#sync)
        -   [Parameters](#parameters-19)
    -   [reset](#reset)
        -   [Parameters](#parameters-20)
    -   [isEmpty](#isempty)
    -   [toString](#tostring)
    -   [update](#update)
        -   [Parameters](#parameters-21)
-   [AbstractCollection](#abstractcollection)
    -   [Parameters](#parameters-22)
    -   [preinitialize](#preinitialize)
        -   [Parameters](#parameters-23)
        -   [Properties](#properties-3)
    -   [preinitialize](#preinitialize-1)
        -   [Parameters](#parameters-24)
        -   [Properties](#properties-4)
    -   [toJSON](#tojson-1)
    -   [add](#add)
        -   [Parameters](#parameters-25)
    -   [addModels](#addmodels)
        -   [Parameters](#parameters-26)
    -   [removeModels](#removemodels)
        -   [Parameters](#parameters-27)
    -   [set](#set-1)
        -   [Parameters](#parameters-28)
    -   [reset](#reset-1)
        -   [Parameters](#parameters-29)
    -   [push](#push)
        -   [Parameters](#parameters-30)
    -   [pop](#pop)
        -   [Parameters](#parameters-31)
    -   [unshift](#unshift)
        -   [Parameters](#parameters-32)
    -   [shift](#shift)
        -   [Parameters](#parameters-33)
    -   [slice](#slice)
        -   [Parameters](#parameters-34)
    -   [get](#get-1)
        -   [Parameters](#parameters-35)
    -   [has](#has-1)
        -   [Parameters](#parameters-36)
    -   [at](#at)
        -   [Parameters](#parameters-37)
    -   [find](#find)
        -   [Parameters](#parameters-38)
    -   [filter](#filter)
        -   [Parameters](#parameters-39)
    -   [where](#where)
        -   [Parameters](#parameters-40)
    -   [findWhere](#findwhere)
        -   [Parameters](#parameters-41)
    -   [sort](#sort)
        -   [Parameters](#parameters-42)
    -   [pluck](#pluck)
        -   [Parameters](#parameters-43)
    -   [fetch](#fetch-2)
        -   [Parameters](#parameters-44)
    -   [create](#create)
        -   [Parameters](#parameters-45)
    -   [parse](#parse-1)
        -   [Parameters](#parameters-46)
    -   [clone](#clone-1)
    -   [modelId](#modelid)
        -   [Parameters](#parameters-47)
    -   [values](#values-1)
    -   [keys](#keys-1)
    -   [entries](#entries)
    -   [supportsValidation](#supportsvalidation-1)
    -   [isValid](#isvalid-1)
    -   [getValidationMessages](#getvalidationmessages-1)
    -   [validate](#validate-1)
    -   [sync](#sync-1)
        -   [Parameters](#parameters-48)
    -   [save](#save-2)
        -   [Parameters](#parameters-49)
    -   [update](#update-1)
        -   [Parameters](#parameters-50)
    -   [remove](#remove)
        -   [Parameters](#parameters-51)
    -   [sortByKey](#sortbykey)
        -   [Parameters](#parameters-52)
    -   [isEmpty](#isempty-1)
    -   [size](#size)
    -   [toString](#tostring-1)
-   [CollectionIterator](#collectioniterator)
    -   [Parameters](#parameters-53)
    -   [next](#next)

## AbstractModel

**Extends AugmentedObject**

AbstractModel <br/>
Supports: <ul>

<li>Validation and Schemas</li>
<li>Security</li>
</ul>

### Parameters

-   `attributes`  
-   `options`   (optional, default `{}`)
-   `args` **...any** 

### uriRoot

uri root property

#### Properties

-   `uriRoot` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** Root of the URI

### schema

Schema property

#### Properties

-   `schema` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The JSON schema from this model

### validationMessages

Validation Message property

#### Properties

-   `validationMessages` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The property holding validation message data

### get

Get the attribute form the Model

#### Parameters

-   `attribute`  

Returns **any** The model attribute

### set

Set a hash of model attributes on the object, firing `"change"`. This is
the core primitive operation of a model, updating the data and notifying
anyone who needs to know about the change in state.

#### Parameters

-   `key`  
-   `value`  
-   `options`  

### escape

Escape the attribute data

#### Parameters

-   `attribute`  

### has

Has an attribute in the Model

#### Parameters

-   `attribute`  

Returns **bolean** Returns true if exists

### matches

Special-cased proxy to underscore's `matches` method.

#### Parameters

-   `attrs`  

### unset

Remove an attribute from the model, firing `"change"`. `unset` is a noop
if the attribute doesn't exist.

#### Parameters

-   `attr`  
-   `options`  

### clear

Clear all attributes on the model, firing `"change"`.

#### Parameters

-   `options`  

### toJSON

Transforms model to pure toJSON

### fetch

Fetch the model from the server, merging the response with the model's
local attributes. Any changed attributes will trigger a "change" event.

#### Parameters

-   `options`   (optional, default `{}`)

### fetch

fetch - Fetches the model as a 'get'

#### Parameters

-   `options`  

### save

Set a hash of model attributes, and sync the model to the server.
If the server returns an attributes hash that differs, the model's
state will be `set` again.

#### Parameters

-   `key`  
-   `val`  
-   `options`   (optional, default `{}`)

### save

save - Saves the model as a 'create'

#### Parameters

-   `options`  

### destroy

Destroy this model on the server if it was already persisted.
Optimistically removes the model from its collection, if it has one.
If `wait: true` is passed, waits for the server to respond before removal.

#### Parameters

-   `options`   (optional, default `{}`)

### destroy

destroy - Deletes the model as a 'delete'

#### Parameters

-   `options`  

### url

Default URL for the model's representation on the server -- use uri()

**Meta**

-   **deprecated**: use uri


### uri

Default URI for the model's representation on the server -- if you're
using restful methods, override this to change the endpoint
that will be called.

### keys

Keys of the attributes in this Model

### values

Values of the attributes in this Model

### parse

Converts a response into the hash of attributes to be `set` on
the model. The default implementation is just to pass the response along.

#### Parameters

-   `resp`  
-   `options`  

### clone

Create a new model with identical attributes to this one.

### isNew

A model is new if it has never been saved to the server, and lacks an id.

### hasChanged

Determine if the model has changed since the last `"change"` event.
If you specify an attribute name, determine if that attribute has changed.

#### Parameters

-   `attr`  

### changedAttributes

Return an object containing all the attributes that have changed, or
false if there are no changed attributes. Useful for determining what
parts of a view need to be updated and/or what attributes need to be
persisted to the server. Unset attributes will be set to undefined.
You can also pass an attributes object to diff against the model,
determining if there _would be_ a change.

#### Parameters

-   `diff`  

### previous

Get the previous value of an attribute, recorded at the time the last
`"change"` event was fired.

#### Parameters

-   `attr`  

### previousAttributes

Get all of the attributes of the model at the time of the previous
`"change"` event.

### supportsValidation

supportsValidation - Returns True if this model supports validation

Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns True if this model supports validation

### isValid

isValid - Returns True if this model is valid
Runs two level validation, attribute-level then JSON Schema

#### Parameters

-   `options`   (optional, default `{}`)

Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns True if this model is valid

### validate

Validates the model

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Returns array of messages from validation

### getValidationMessages

Gets the validation messages only in an array

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Returns array of messages from validation

### sync

Sync model data (Should override as needed)

#### Parameters

-   `method`  
-   `model`  
-   `options`  

### reset

reset - clear and rewrite the model with passed data

#### Parameters

-   `data` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The data to replace the model with (optional)

### isEmpty

isEmpty - returns true is the model is empty

Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** returns true is the model is empty

### toString

toString - returns the model data as a string

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** returns the model data as a string

### update

update - Updates the model as a 'update'

#### Parameters

-   `options`  

## AbstractCollection

**Extends AugmentedObject**

Abstract Augmented Collection <br/>
Supports: <ul>

<li>Validation and Schemas</li>
<li>Security</li>
</ul>

### Parameters

-   `models`  
-   `options`   (optional, default `{}`)

### preinitialize

Schema property

#### Parameters

-   `models`  
-   `options`  

#### Properties

-   `schema` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The JSON schema from this collection

### preinitialize

Validation Message property

#### Parameters

-   `models`  
-   `options`  

#### Properties

-   `validationMessages` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The property holding validation message data

### toJSON

The JSON representation of a Collection is an array of the
models" attributes.

### add

Add a model, or list of models to the set. `models` may be
Models or raw JavaScript objects to be converted to Models, or any
combination of the two.

#### Parameters

-   `models`  
-   `options`   (optional, default `{}`)

**Meta**

-   **deprecated**: call addModels


### addModels

Add a model, or list of models to the set. `models` may be
Models or raw JavaScript objects to be converted to Models, or any
combination of the two.

#### Parameters

-   `models` **(Model | [array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** Models to add or single model
-   `options` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** Option s to add

Returns **Model** Return the added (or merged) model (or models).

### removeModels

Remove a model, or a list of models from the set.

#### Parameters

-   `models`   (optional, default `[]`)
-   `options`   (optional, default `{}`)

### set

Update a collection by `set`-ing a new list of models, adding new ones,
removing models that are no longer present, and merging models that
already exist in the collection, as necessary. Similar to **Model#set**,
the core operation for updating the data contained by the collection.

#### Parameters

-   `models`  
-   `options`   (optional, default `{}`)

### reset

When you have more items than you want to add or remove individually,
you can reset the entire set with a new list of models, without firing
any granular `add` or `remove` events. Fires `reset` when finished.
Useful for bulk operations and optimizations.

#### Parameters

-   `models`  
-   `options`  

### push

Add a model to the end of the collection.

#### Parameters

-   `model`  
-   `options`  

### pop

Remove a model from the end of the collection.

#### Parameters

-   `options`  

### unshift

Add a model to the beginning of the collection.

#### Parameters

-   `model`  
-   `options`  

### shift

Remove a model from the beginning of the collection.

#### Parameters

-   `options`  

### slice

Slice out a sub-array of models from the collection.

#### Parameters

-   `args` **...any** 

### get

Get a model from the set by id, cid, model object with id or cid
properties, or an attributes object that is transformed through modelId.

#### Parameters

-   `obj`  

### has

Returns `true` if the model is in the collection.

#### Parameters

-   `obj`  

### at

Get the model at the given index.

#### Parameters

-   `index`  

### find

find the model that matches these properties

#### Parameters

-   `attrs` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** properties to match

Returns **Augmented.AbstractModel** model that matched

### filter

filter the models that match these properties

#### Parameters

-   `attrs` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** properties to match

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** models that matched

### where

Return models with matching attributes. Useful for simple cases of `filter`.

#### Parameters

-   `attrs` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** properties to match
-   `first`  

Returns **(Model | [array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array))** models that matched

### findWhere

Return the first model with matching attributes. Useful for simple cases
of `find`.

#### Parameters

-   `attrs`  

### sort

Force the collection to re-sort itself. You don"t need to call this under
normal circumstances, as the set will maintain sort order as each item
is added.

#### Parameters

-   `options`   (optional, default `{}`)

### pluck

Pluck an attribute from each model in the collection.

#### Parameters

-   `attr`  

### fetch

Fetch the collection

#### Parameters

-   `options`  

### create

Create a new instance of a model in this collection. Add the model to the
collection immediately, unless `wait: true` is passed, in which case we
wait for the server to agree.

#### Parameters

-   `model`  
-   `options`  

### parse

**parse** converts a response into a list of models to be added to the
collection. The default implementation is just to pass it through.

#### Parameters

-   `resp`  
-   `options`  

### clone

Create a new collection with an identical list of models as this one.

### modelId

Define how to uniquely identify models in the collection.

#### Parameters

-   `attrs`  

### values

Get an iterator of all models in this collection.

### keys

Get an iterator of all model IDs in this collection.

### entries

Get an iterator of all [ID, model] tuples in this collection.

### supportsValidation

supportsValidation - Returns True if this collection supports validation

Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns True if this collection supports validation

### isValid

isValid - Returns True if this collection is valid

Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Returns True if this collection is valid

### getValidationMessages

getValidationMessages - Returns the validation messages

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Returns the message is an array of objects.

### validate

Validates the collection

Returns **[array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)** Returns array of message from validation

### sync

Collecion.sync

#### Parameters

-   `method`  
-   `model`  
-   `options`  

### save

save - Saves the collection as a "create"

#### Parameters

-   `options`   (optional, default `{}`)

### update

update - Updates the collection as an "update"

#### Parameters

-   `options`   (optional, default `{}`)

### remove

remove - Remove from the collection as a "delete"

#### Parameters

-   `options`   (optional, default `{}`)

### sortByKey

sortByKey - Sorts the collection by a property key

#### Parameters

-   `key` **[object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** The key to sort by

### isEmpty

isEmpty - returns true is the collection is empty

Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** returns true is the collection is empty

### size

size - returns the size of the collection

Returns **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)** returns the size of the collection

### toString

toString - returns the collection data as a string

Returns **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** returns the collection data as a string

## CollectionIterator

A CollectionIterator implements JavaScript's Iterator protocol, allowing the
use of `for of` loops in modern browsers and interoperation between
Collection and other JavaScript functions and third-party libraries
which can operate on Iterables.

### Parameters

-   `collection`  
-   `kind`  

### next

Next model in collection<br/>
Once exhausted, remove the reference to the collection so future
calls to the next method always return done.

---
_Source: https://npm.io/package/next-core-model · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
