Create a node
Define the data model
To define a Frost Entity (Object), You have to:
- Create A class with the name of the Entity you desire. In this case it's "User"
- This Class must extend the FrostObject class.
- FrostObject takes a generic parameter of the class itself (
class A extends FrostObject<A>
), this will extract the type for the constructor.
- FrostObject takes a generic parameter of the class itself (
- Annotate the class with the FrostEntity decorator.
Pass the options(FrostEntityDecoratorOptions) that you desire to the decorator.
So far the only available option is the collectionPath which is the name of the node that will contain all the instances for this entity. In this case its
/users/
infoSince you don't have to define a constructor, then Typescript will throw an error because it cannot detect the initialization of the object properties. So you'll have to either use
?
for optional parameters or!
for non-optional parameters to let Typescript know that they'll be initialized.
All (FrostObject)s have the id property, you don't have to define. If you want to define it yourself, you might need to add the override
modifier; depending on the Typescript version and the compile options.
:::
@FrostEntity({collectionPath:"/users"})
class User extends FrostObject<User>{
id?:string
name!:string
userType!: "Customer" | "Admin"
birthday?:string
...
}
Instantiation
To create an instance from the Entity
new User({id:"user1",name:"User One",userType:"Customer"})
Available methods
Since the Entity extends FrostObject it inherits a few useful methods from it. Please check them out they might be of help to you.
Define the API
To define a Frost API, You have to:
- Create A class with the name you desire. In this case it's "UserApi"
- This Class must extend the FrostApi class. and the Entity class must be passed to the generic type.
- Annotate the class with the FrostNode decorator. Pass the Corresponding Entity to the decorator.
@FrostNode({entity:User})
class UserApi extends FrostApi<User>{}