Source code for gam.ast.program
from typing import Optional, Literal, List
from gam.ast.base_ast import ASTNode, Field
from gam.ast.expr import CallExpression
from gam.ast.stmt import FunctionDeclaration, StructDeclaration, Statement
from gam.ast.event import EventHandler
from gam.ast.view import ViewPage
[docs]
class Repository(ASTNode):
"""Represents a repository.
A Repository is a collection of methods that are used to interact with the database.
It is used to perform CRUD operations on the database.
"""
name: Literal['Repository'] = Field(default='Repository')
methods: List["FunctionDeclaration"] = Field(
default_factory=list,
description="List of methods in the repository. Define by using the FunctionDeclaration class."
)
[docs]
class Controller(ASTNode):
"""Represents a controller.
A Controller is a collection of methods that are used to handle the requests and responses.
It is used to perform the business logic of the application.
"""
name: Literal['Controller'] = Field(default='Controller')
methods: List["FunctionDeclaration"] = Field(
default_factory=list,
description="List of methods in the controller. Define by using the FunctionDeclaration class."
)
[docs]
class Model(ASTNode):
"""Represents a model.
A Model is a collection of structs that are used to represent the data in the application.
It is used to store the data in the application.
"""
name: Literal['Model'] = Field(default='Model')
structs: List["StructDeclaration"] = Field(
default_factory=list,
description="List of structs in the model. Define by using the StructDeclaration class."
)
[docs]
class View(ASTNode):
"""Represents a view.
A View is a collection of methods, models (structs) that are used to render the UI.
It is used to display the data to the user.
"""
name: Literal['View'] = Field(default='View')
pages: List["ViewPage"] = Field(
default_factory=list,
description="List of view pages. Define by using the ViewPage class." \
"Each ViewPage is a page in the view. e.g. User Management, User Details, etc." \
)
[docs]
class Event(ASTNode):
"""Represents an event.
An Event is a collection of methods that are used to handle the events in the application.
It is used to handle the events in the application, data flow like:
User -> View -> Event -> EventHandler -> Controller -> Repository -> Database
"""
name: Literal['Event'] = Field(default='Event')
event_handlers: List[EventHandler] = Field(
default_factory=list,
description="List of event handlers in the event. Define by using the EventHandler class." \
"Event handlers are used to handle the events in the application. e.g. click, input, change, submit"
)
[docs]
class Module(ASTNode):
"""Represents a module.
A Module is a collection of components that are used to represent the application.
It is used to store the application components.
"""
name: Literal['Module'] = Field(default='Module')
id: str = Field(
description="The name of the module. It is used to identify the module."
)
controller: Optional["Controller"] = Field(
description="The controller of the module. It is used to handle the requests and responses."
)
event: Optional["Event"] = Field(
description="The event of the module. It is used to handle the events."
)
model: Optional["Model"] = Field(
description="The model of the module. It is used to store the data."
)
view: Optional["View"] = Field(
description="The view of the module. It is used to display the data."
)
repository: Optional["Repository"] = Field(
description="The repository of the module. It is used to interact with the database."
)
[docs]
class Program(ASTNode):
"""Represents a program
A Program is a collection of modules that are used to represent the application.
It is used to store the application.
"""
name: Literal['Program'] = Field(default='Program')
modules: List[Module] = Field(
default_factory=list,
description="List of modules in the program. Define by using the Module class."
)
view_index: "ViewPage" = Field(
description="Must provide the index page of the view. e.g. User Management, User Details, etc." \
"This is the entry point of user interface. Start point of the application UI."
)
statements: List["Statement"] = Field(
default_factory=list,
description="For frontend, will be considered as global context, then import to other views. \
All structs will be constructed in this file. \
Assign from result of repository or controller if needed. \
Using builtin reactive functions set."
)
entry_point: "CallExpression" = Field(
description="The entry point of the program. Define by using the CallExpression class."
)