Entity

Entity

Represents an Entity / a collection of pieces of data, like a row in a table view, a person, or a card with information.

Constructor

new Entity(berryfi, parentType, data)

Source:
Properties:
Name Type Description
berryfi Berryfi The Berryfi client instance. Circular reference.
parentType Type The Type this Entity is a child of
data object The data on this Entity. Object is identical to the API query result.
flag number The flag value for this type
field string A proxy to get/set data in the current Entity. E.g. "entity.field['user email']" or "entity.field.Name = 'Hello!'". Setter throws error if field does not exist.
berryfi Berryfi The Berryfi client instance
Creates a new entity
Parameters:
Name Type Description
berryfi Berryfi The Berryfi client instance
parentType Type The Type this Entity is a child of
data object The data to populate this entity

Members

appName :string

Source:
Returns the name of the App this Entity is a child of. The name and label is the same for apps.
Type:
  • string

created :Date

Source:
Returns the creation date of this Entitiy if it has an UUID
Type:
  • Date

fields :object

Source:
Return the object data reference for this Entity
Type:
  • object

(abstract) flag :number

Source:
The flags value for this thing. Is set when loaded by Berryfi.pull()
Type:
  • number

id :string

Source:
Returns the UUID of this Entitiy if it has one
Type:
  • string

isApp :boolean

Source:
Boolean - Check if this is a user created App
Type:
  • boolean

isAuxiliary :boolean

Source:
Boolean - Check if this is a Fibery helper type or field
Type:
  • boolean

isAuxiliaryField :boolean

Source:
Boolean - Check if this is a Fibery helper field
Type:
  • boolean

isAuxiliaryType :boolean

Source:
Boolean - Check if this is a Fibery helper type
Type:
  • boolean

isEntity :boolean

Source:
Boolean - Check if this is an entity
Type:
  • boolean

isField :boolean

Source:
Boolean - Check if this is a field inside a Type
Type:
  • boolean

isPrimitive :boolean

Source:
Boolean - Check if this is a primitive Fibery type
Type:
  • boolean

isType :boolean

Source:
Boolean - Check if this is a Type inside an App
Type:
  • boolean

isUserCreated :boolean

Source:
Boolean - Check if this type is directly created by a user
Type:
  • boolean

modified :Date

Source:
Date - Returns the date the entity was modified
Type:
  • Date

publicId :string

Source:
String - Returns the Entity["fibery/public-id"] value
Type:
  • string

rank :number

Source:
Number - Returns the Entity["fibery/rank"] value
Type:
  • number

typeLabel :string

Source:
Returns the label of the Type this Entity is a child of. The UI readable name instead of the Fibery name.
Type:
  • string

typeName :string

Source:
Returns the name of the Type this Entity is a child of. The Fibery API name, not UI readable name.
Type:
  • string

Methods

findFieldName(name) → {string}

Source:
Checks the Fields associated with this Entity's parent Type to resolve the Fibery name of a field
Parameters:
Name Type Description
name string The field to get Fibery name of
Returns:
Type
string

(async) insert()

Source:
Inserts this entity in to Fibery.
Example
const mike = people.makeEntity({
	name: "Mike",
	age: 24
});
await mike.insert(); // Create new
mike.field.email = "mike@email.com";
await mike.push(); // Update state

(async) pull()

Source:
Pulls the current state of this Entity from Fibery and update itself

(async) push() → {Array.<object>}

Source:
Push the current state of the entity to Fibery. Undefined/omitted fields will be left out of the update, so they will remain as-is in Fibery. Nulled values in this Entity will erase the values in Fibery.
Example
mike.field.email = "mike@email.com";
await mike.push(); // Update state
mike.field.age = 25;
await mike.push() // … another update
Returns:
The result API response of the update query
Type
Array.<object>

toObject(inputopt) → {object}

Source:
Returns a pure object of the entity and its fields. Basically strips out `Appname/, fibery/, ui/, app/, etc..` to "clean up" the keys.
Example
console.log(personEntity); // {"fibery/id": "123", "fibery/name": "John Doe", "Person/age": 24, "Person/workplaces": [{"Companies/name": "Fibery"}], "fibery/public-id": "1"};
console.log(personEntity.toObject()); // {id: "123", name: "John Doe", age: 24, workplaces: [{name: "Fibery"}], "public-id": "1"};
Parameters:
Name Type Attributes Description
input object <optional>
Default: the current entity's data. The data to convert from fibery notion to normal. Max 2 levels deep.
Returns:
Type
object

validate() → {object}

Source:
Corrects and checks if the schema is valid based on the field schema in cache. Updates its own state, but also return a de-referenced object of the object. Throws on if invalid, with an error stating what is invalid. You can use this method in a try...catch before sending to capture errors early. When sending, this method will be used automatically as well.
Throws:
If invalid, with an error stating what is invalid.
Type
Error
Returns:
Type
object