Node.js API reference
App
The App
class represents a Teo server app.
constructor
Create an app.
Examples
Create an app
mainNamespace
Retrieve the main namespace from the app. Namespace is where models, handlers,
decorators and pipeline items are defined. See Namespace
.
Examples
Retrieve the main namespace
setup
Attach some code to run after the database is connected. The parameter Teo
is in generated entities.
Examples
Run custom setup code
program
Define a custom program to run with Teo CLI. The parameter Teo
is in
generated entities.
Examples
Define a custom program
run
Start the Teo server app.
Example
Run an server app
Namespace
Namespace is where things are defined and organized.
isMain
Whether the namespace is the main namespace.
isStd
Whether the namespace is the builtin standard namespace.
path
Get the namespace's path.
Example
Namespace's path
namespace
Get the namespace's child namespace by name
or None
.
namespaceOrCreate
Get the namespace's child namespace by name
. If not present, create and
return.
namespaceAtPath
Get the namespace's child namespace at path.
namespaceOrCreateAtPath
The the namespace's child namespace at path. If not present, create and return.
defineModelDecorator
Define a new model decorator on a namespace.
Example
Define a custom model decorator
defineModelFieldDecorator
Define a new model field decorator on a namespace.
Example
Define a custom model field decorator
defineModelRelationDecorator
Define a new model relation decorator on a namespace.
Example
Define a custom model relation decorator
defineModelPropertyDecorator
Define a new model property decorator on a namespace.
Example
Define a custom model property decorator
definePipelineItem
Define a custom pipeline item on a namespace.
Example
Define a custom pipeline item
defineTransformPipelineItem
Define a transformer pipeline item. This is a shortcut to
definePipelineItem
.
Example
Define a custom transformer
defineValidatorPipelineItem
Register a custom validate function.
Examples
Define a custom validator pipeline item with bool return value
Define a custom validator pipeline item with string return value
Define a custom validator pipeline item which errors
defineCallbackPipelineItem
Define a callback pipeline item. This is a shortcut to definePipelineItem
.
Example
Define a custom callback pipeline item
Define a custom callback pipeline item which errors
defineComparePipelineItem
Define a compare pipeline item. This is a shortcut to definePipelineItem
.
Example
Define a custom compare pipeline item
defineMiddleware
Define a middleware on a namespace.
Example
Define a custom middleware
defineHandler
Define a custom route handler on a namespace.
Example
Define a custom route handler
defineHandlerGroup
Define a handler group on a namespace.
Example
Define a custom handler group
defineModelHandlerGroup
Define model handlers on a namespace.
Example
Define a custom model handler group
HandlerGroup
A handler group is a container for defining custom route handlers.
defineHandler
Define a custom route handler on a handler group.
Example
Define a custom route handler
Request
A request represents an HTTP request.
method
Retrieve the request's method.
path
Retrieve the request's path.
queryString
Retrieve the request's query string.
contentType
Retrieve the request's content type.
headers
Retrieve the request's headers.
ReadOnlyHeaderMap
The ReadOnlyHeaderMap
class represents readonly headers on a request.
keys
Retrieve the header map's keys.
len
Retrieve the length of the header map.
containsKey
Whether the headers contain a specific key.
get
Retrieve the value of a header entry by key
.
Response
The Response
class represents an HTTP response.
empty
Create an empty response.
Example
Create an empty response
string
Create a string response.
Example
Create a string response
teon
Create a Teon response.
html
Create an HTML response.
Example
Create an HTML response
data
Create a Teon response which contains a data
field.
dataMeta
Create a Teon response which contains a data
field and a meta
field.
file
Create a file response.
Example
Create a file response
redirect
Create a redirect response.
Example
Create a redirect response
setCode
Set the response code.
code
Retrieve the response code.
headers
Retrieve the response headers.
isEmpty
Whether the response body is empty.
isFile
Whether the response body is a file.
getFile
Retrieve the response file path. If the response' type is not file, undefined
is returned.
isText
Whether the response body is text.
getText
Retrieve the response text. If the response' type is not text, undefined
is
returned.
isTeon
Whether the response body is a teon object.
getTeon
Retrieve the response Teon value. If the response' type is not Teon,
undefined
is returned.
ReadWriteHeaderMap
The ReadWriteHeaderMap
class represents readwrite headers on a response.
keys
Retrieve the header map's keys.
len
Retrieve the length of the header map.
containsKey
Whether the headers contain a specific key.
get
Retrieve the value of a header entry by key
.
set
Set a new value of a header entry at key
.
Entity model
API documentation for generated model entities.
findMany
Find many objects with params same as findMany
handler.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
finder | Yes | ModelFindManyArgs | The finder |
Examples
Find all users
Find users filtered by name
Find users ordered by createdAt
Find users with posts
findUnique
Find a unique object with params same as findUnique
handler.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
finder | Yes | ModelFindUniqueArgs | The finder |
Examples
Find a unique user
findFirst
Find an object with params same as findFirst
handler.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
finder | Yes | ModelFindManyArgs | The finder |
Examples
Find a user
count
Count objects or fields in the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
query | Yes | ModelCountArgs | The finder |
Examples
Count objects
aggregate
Aggregate on the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
query | Yes | &Value | The finder |
Examples
Aggregate on the model
groupBy
Group by on the model.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
query | Yes | &Value | The finder |
Example
Group by on the model
create
Create a new entity.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
input | No | ModelCreateArgs | The create data |
Examples
Create a new Post
Entity object
isNew
Returns true if object is new.
Examples
Check whether a post is new
isModified
Returns true if object is modified.
Examples
Check if a post is modified
set
Set values to an object. The onSet
pipeline is triggered.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
values | Yes | ModelUpdateInput | The set data |
Examples
Set values to a user
update
Update values on an object.
Signature
Arguments
Name | Required | Type | Description |
---|---|---|---|
values | No | ModelScalarUpdateInput | The update data |
Examples
Update values on a user
save
Save an object.
Signature
Examples
Save a post
delete
Delete an object.
Signature
Examples
Delete a post
toTeon
Convert the object to a teon result value.