projectserver

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 54 Imported by: 0

README

Project Server Package

This package contains the code for the Inox Project Server. The Project Server is basically an LSP server with extra features:

Subpackages:

  • jsonrpc
  • logs
  • lsp: language-agnostic logic & types

Architecture

Current (temporary)
graph TB

Spawner(inoxd or user) --> |$ inox project-server -config='...'| InoxBinary


subgraph InoxBinary[Inox Binary]
    direction TB

    ProjectServer
    NodeAgent


    ProjectServer --> |asks to deploy/stop apps| NodeAgent

    NodeAgent --> InoxRuntime1
    NodeAgent --> InoxRuntime2

end

ProjectServer[Project Server] --> |stores data in| ProjectsDir
InoxRuntime1[Inox Runtime - App 1] --> |stores data in| ProdDir
InoxRuntime2[Inox Runtime - App 2] --> |stores data in| ProdDir


ProjectsDir(/var/lib/inoxd/projects)
ProdDir(/var/lib/inoxd/prod)

The next version is way more secure and resilient.

Next

In this version every important component runs in a separate inox process.

graph TB

Inoxd(inoxd) --> |$ inox project-server -config='...'| ProjectServer
Inoxd --> |spawns| NodeAgent
NodeAgent("Node Agent \n [uses cgroups]") --> |creates process| DeployedApp1(Deployed Application 1)
NodeAgent --> |creates process| DeployedApp2(Deployed Application 2)
DeployedApp1 --> |stores data in| ProdDir
DeployedApp2 --> |stores data in| ProdDir


ProjectServer[Project Server] --> |stores data in| ProjectsDir
ProjectServer --> |asks to deploy/stop apps| NodeAgent

ProjectsDir(/var/lib/inoxd/projects)
ProdDir(/var/lib/inoxd/prod)

The next version may be slightly different from what is planned here.

Documentation

Index

Constants

View Source
const (
	INITIALIZE_DEBUG_METHOD          = "debug/initialize"
	DEBUG_CONFIG_DONE_METHOD         = "debug/configurationDone"
	DEBUG_LAUNCH_METHOD              = "debug/launch"
	GET_THREADS_METHOD               = "debug/threads"
	GET_STACK_TRACE_METHOD           = "debug/stackTrace"
	GET_SCOPES_METHOD                = "debug/scopes"
	GET_VARIABLES_METHOD             = "debug/variables"
	SET_BREAKPOINTS_METHOD           = "debug/setBreakpoints"
	SET_EXCEPTION_BREAKPOINTS_METHOD = "debug/setExceptionBreakpoints"
	DEBUG_PAUSE_METHOD               = "debug/pause"
	DEBUG_CONTINUE_METHOD            = "debug/continue"
	DEBUG_STEP_IN_METHOD             = "debug/stepIn"
	DEBUG_STEP_OUT_METHOD            = "debug/stepOut"
	DEBUG_NEXT_METHOD                = "debug/next"
	DEBUG_DISCONNECT_METHOD          = "debug/disconnect"

	DEFAULT_DEBUG_COMMAND_TIMEOUT = 2 * time.Second
	EXCEPTION_ERROR_FILTER        = "exception"

	DEFAULT_MAX_SESSION_COUNT = 2
	DEFAULT_LOG_LEVEL         = zerolog.DebugLevel

	POST_DONE_DEBUGGED_PROGRAM_DELAY = 100 * time.Millisecond
)
View Source
const (
	ImportantDebugEvent = "important"
	StdoutDebugEvent    = "stdout"
	ConsoleDebugEvent   = "console"
)
View Source
const (
	FILE_STAT_METHOD         = "fs/fileStat"
	READ_FILE_METHOD         = "fs/readFile"
	WRITE_FILE_METHOD        = "fs/writeFile"
	START_UPLOAD_METHOD      = "fs/startUpload"
	WRITE_UPLOAD_PART_METHOD = "fs/writeUploadPart"
	RENAME_FILE_METHOD       = "fs/renameFile"
	DELETE_FILE_METHOD       = "fs/deleteFile"

	CREATE_DIR_METHOD = "fs/createDir"
	READ_DIR_METHOD   = "fs/readDir"

	FS_STRUCTURE_EVENT_NOTIF_METHOD = "fs/structureEvent"

	MIN_LAST_CHANGE_AGE_FOR_UNSAVED_DOC_SYNC               = time.Second / 2
	MIN_LAST_FILE_WRITE_AGE_FOR_UNSAVED_DOC_SYNC_REVERSING = time.Second / 2

	FS_EVENT_BATCH_NOTIF_INTERVAL = time.Second
)
View Source
const (
	UnknownFsFile = 0
	FsFile        = 1
	FsDir         = 2
	FsSymLink     = 64
)
View Source
const (
	GET_TUTORIAL_SERIES_METHOD = "learn/getTutorialSeries"
	GET_LEARN_INFO_METHOD      = "learn/getInfo"
)
View Source
const (
	LSP_LOG_SRC                 = "lsp"
	DEFAULT_PROJECT_SERVER_PORT = "8305"
)
View Source
const (
	CLEAR_UNUSED_CACHE_TIMEOUT        = 5 * time.Second
	REMOVE_UNUSED_CACHE_ENTRY_TIMEOUT = 10 * time.Second
)
View Source
const (
	VERY_RECENT_ACTIVITY_DELTA = time.Second
	MAX_PREPARATION_DEPTH      = 2
)
View Source
const (
	CURRENT_PROJECT_CTX_DATA_PATH = core.Path("/current-project")
	LSP_FS_CTX_DATA_PATH          = core.Path("/current-filesystem")

	OPEN_PROJECT_METHOD              = "project/open"
	CREATE_PROJECT_METHOD            = "project/create"
	REGISTER_APPLICATION_METHOD      = "project/registerApplication"
	LIST_APPLICATION_STATUSES_METHOD = "project/listApplicationStatuses"
)
View Source
const (
	LIST_SECRETS_METHOD  = "secrets/list"
	UPSERT_SECRET_METHOD = "secrets/upsert"
	DELETE_SECRET_METHOD = "secrets/delete"
)
View Source
const (
	ENABLE_TEST_DISCOVERY_METHOD = "testing/enableContinousDiscovery"
	TEST_FILE_METHOD             = "testing/testFileAsync"
	STOP_TEST_RUN_METHOD         = "testing/stopRun"

	TEST_OUTPUT_EVENT_METHOD = "testing/outputEvent"
	TEST_RUN_FINISHED_METHOD = "testing/runFinished"
)
View Source
const (
	DEFAULT_MAX_IN_MEM_FS_STORAGE_SIZE = 10_000_000
)
View Source
const DEPLOY_PROD_APP_METHOD = "prod/deployApplication"
View Source
const (
	INOX_FS_SCHEME = "inox"
)
View Source
const (
	//we set the timeout to a small value so that:
	// - inactive file states are garbage collected quickly
	// - users do not have too wait long to retry an upload if they encountered an error
	PROJECT_FILE_STATE_CLEANUP_TIMEOUT = 5 * time.Second
)
View Source
const (
	SERVER_API_UPDATE_DEBOUNCE_DURATION = time.Second / 2
)
View Source
const STOP_PROD_APP_METHOD = "prod/stopApplication"

Variables

View Source
var (
	ErrUnknowSessionId                = errors.New("unknown session id")
	ErrSessionAlreadyExists           = errors.New("session already exists")
	ErrMaxParallelDebugSessionReached = errors.New("the maximum number of parallel debug sessions is already reached")
)
View Source
var (
	ErrFileBeingCreatedOrModifiedByAnotherSession = errors.New("file is being created or edited by another session")
	ErrFileBeingCreatedBySameSession              = errors.New("file is being created by the same session")
)
View Source
var (
	ErrFileURIExpected = errors.New("a file: URI was expected")
	ErrInoxURIExpected = errors.New("a inox: URI was expected")

	True  = true
	False = false
)
View Source
var (
	CACHE_CLEARING_INTERVAL = 100 * time.Millisecond
)
View Source
var (
	DEFAULT_PROJECT_SERVER_PORT_INT = utils.Must(strconv.Atoi(DEFAULT_PROJECT_SERVER_PORT))
)
View Source
var HOVER_PRETTY_PRINT_CONFIG = &pprint.PrettyPrintConfig{
	MaxDepth: 7,
	Indent:   []byte{' ', ' '},
	Colorize: false,
	Compact:  false,
}

Functions

func MakeProjectServerCmd

func MakeProjectServerCmd(args ProjectServerCmdParams) *exec.Cmd

func NewShowMessage

func NewShowMessage(typ defines.MessageType, text string) jsonrpc.NotificationMessage

func StartLSPServer

func StartLSPServer(ctx *core.Context, serverConfig LSPServerConfiguration) (finalErr error)

Types

type CreateProjectParams

type CreateProjectParams struct {
	Name       string `json:"name"`
	AddTutFile bool   `json:"addTutFile"`
	Template   string `json:"template"`
}

type DebugConfigurationDoneParams

type DebugConfigurationDoneParams struct {
	SessionId string                       `json:"sessionID"`
	Request   dap.ConfigurationDoneRequest `json:"request"`
}

type DebugContinueParams

type DebugContinueParams struct {
	SessionId string              `json:"sessionID"`
	Request   dap.ContinueRequest `json:"request"`
}

type DebugDisconnectParams

type DebugDisconnectParams struct {
	SessionId string                `json:"sessionID"`
	Request   dap.DisconnectRequest `json:"request"`
}

type DebugEventCategory

type DebugEventCategory string

type DebugInitializeParams

type DebugInitializeParams struct {
	SessionId string                `json:"sessionID"`
	Request   dap.InitializeRequest `json:"request"`
}

type DebugLaunchArgs

type DebugLaunchArgs struct {
	Program   string         `json:"program"`
	LogLevels map[string]any `json:"logLevels,omitempty"`
}

type DebugLaunchRequestParams

type DebugLaunchRequestParams struct {
	SessionId string            `json:"sessionID"`
	Request   dap.LaunchRequest `json:"request"`
}

type DebugNextParams

type DebugNextParams struct {
	SessionId string              `json:"sessionID"`
	Request   dap.ContinueRequest `json:"request"`
}

type DebugPauseParams

type DebugPauseParams struct {
	SessionId string           `json:"sessionID"`
	Request   dap.PauseRequest `json:"request"`
}

type DebugScopesParams

type DebugScopesParams struct {
	SessionId string            `json:"sessionID"`
	Request   dap.ScopesRequest `json:"request"`
}

type DebugSecondaryEvent

type DebugSecondaryEvent struct {
	dap.Event
	Body any `json:"body"`
}

type DebugSession

type DebugSession struct {
	// contains filtered or unexported fields
}

func (*DebugSession) NextSeq

func (s *DebugSession) NextSeq() int

type DebugSessions

type DebugSessions struct {
	// contains filtered or unexported fields
}

func (*DebugSessions) AddSession

func (sessions *DebugSessions) AddSession(s *DebugSession)

TODO: limit running sessions to 2.

func (*DebugSessions) GetSession

func (sessions *DebugSessions) GetSession(sessionId string) (*DebugSession, bool)

func (*DebugSessions) RemoveSession

func (sessions *DebugSessions) RemoveSession(s *DebugSession)

type DebugSetBreakpointsParams

type DebugSetBreakpointsParams struct {
	SessionId string                    `json:"sessionID"`
	Request   dap.SetBreakpointsRequest `json:"request"`
}

type DebugSetExceptionBreakpointsParams

type DebugSetExceptionBreakpointsParams struct {
	SessionId string                             `json:"sessionID"`
	Request   dap.SetExceptionBreakpointsRequest `json:"request"`
}

type DebugStackTraceParams

type DebugStackTraceParams struct {
	SessionId string                `json:"sessionID"`
	Request   dap.StackTraceRequest `json:"request"`
}

type DebugStepInParams

type DebugStepInParams struct {
	SessionId string              `json:"sessionID"`
	Request   dap.ContinueRequest `json:"request"`
}

type DebugStepOutParams

type DebugStepOutParams struct {
	SessionId string              `json:"sessionID"`
	Request   dap.ContinueRequest `json:"request"`
}

type DebugThreadsParams

type DebugThreadsParams struct {
	SessionId string             `json:"sessionID"`
	Request   dap.ThreadsRequest `json:"request"`
}

type DebugVariablesParams

type DebugVariablesParams struct {
	SessionId string               `json:"sessionID"`
	Request   dap.VariablesRequest `json:"request"`
}

type DeleteSecretParams

type DeleteSecretParams struct {
	Name string
}

type DeployAppParams

type DeployAppParams struct {
	AppName          string `json:"name"`
	UpdateRunningApp bool   `json:"updateRunningApp"`
}

type DeployAppResponse

type DeployAppResponse struct {
	Error string `json:"error,omitempty"`
}

type EnableContinuousTestDiscoveryParams

type EnableContinuousTestDiscoveryParams struct {
}

type Filesystem

type Filesystem struct {
	afs.Filesystem
	// contains filtered or unexported fields
}

Filesystem is a filesystem that stores the unsaved documents in a separate filesystem.

func NewDefaultFilesystem

func NewDefaultFilesystem() *Filesystem

func NewFilesystem

func NewFilesystem(base afs.Filesystem, unsavedDocumentFs afs.Filesystem) *Filesystem

NewFilesystem creates a new Filesystem with a persistsed filesystem and a filesystem for storing the state of unsave documents. unsavedDocumentFs should be fast.

func (*Filesystem) Close

func (fs *Filesystem) Close(ctx *core.Context) error

func (*Filesystem) Events

func (fs *Filesystem) Events() *memds.TSArrayQueue[fs_ns.Event]

func (*Filesystem) GetWatchers

func (fs *Filesystem) GetWatchers() []*fs_ns.VirtualFilesystemWatcher

func (*Filesystem) OpenFile

func (fs *Filesystem) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error)

OpenFile opens the unsaved document if flag is os.O_RDONLY, otherwise the persisted file is open.

func (*Filesystem) Watcher

type FsCreateDirParams

type FsCreateDirParams struct {
	DirURI defines.URI `json:"uri"`
}

type FsDeleteFileParams

type FsDeleteFileParams struct {
	FileURI   defines.URI `json:"uri"`
	Recursive bool        `json:"recursive,omitempty"`
}

type FsDirEntries

type FsDirEntries []FsDirEntry

type FsDirEntry

type FsDirEntry struct {
	Name     string     `json:"name"`
	FileType FsFileType `json:"type"`

	//The modification timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
	ModificationTime int64 `json:"mtime"`
}

type FsFileContentBase64

type FsFileContentBase64 struct {
	Content string `json:"content"`
}

type FsFileStat

type FsFileStat struct {
	//The creation timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
	CreationTime int64 `json:"ctime"`

	//The modification timestamp in milliseconds elapsed since January 1, 1970 00:00:00 UTC.
	ModificationTime int64 `json:"mtime"`

	//The size in bytes.
	Size int64 `json:"size"`

	FileType FsFileType `json:"type"`
}

type FsFileStatParams

type FsFileStatParams struct {
	FileURI defines.URI `json:"uri"`
}

type FsFileType

type FsFileType int

func FileTypeFromInfo

func FileTypeFromInfo(i fs.FileInfo) FsFileType

type FsNonCriticalError

type FsNonCriticalError string
const (
	FsFileNotFound FsNonCriticalError = "not-found"
	FsFileExists   FsNonCriticalError = "exists"
	FsFileIsDir    FsNonCriticalError = "is-dir"
	FsFileIsNotDir FsNonCriticalError = "is-not-dir"
	FsNoFilesystem FsNonCriticalError = "no-filesystem"
)

type FsReadFileParams

type FsReadFileParams struct {
	FileURI defines.URI `json:"uri"`
}

type FsReadirParams

type FsReadirParams struct {
	DirURI defines.URI `json:"uri"`
}

type FsRenameFileParams

type FsRenameFileParams struct {
	FileURI    defines.URI `json:"uri"`
	NewFileURI defines.URI `json:"newUri"`
	Overwrite  bool        `json:"overwrite"`
}

type FsStartUploadParams

type FsStartUploadParams struct {
	Create            bool        `json:"create"`
	Overwrite         bool        `json:"overwrite"`
	FileURI           defines.URI `json:"uri"`
	PartContentBase64 string      `json:"content,omitempty"`
	Last              bool        `json:"last"`
}

type FsStartUploadResponse

type FsStartUploadResponse struct {
	UploadId uploadId `json:"uploadId,omitempty"`
	Done     bool     `json:"done"`
}

type FsStructureEvent

type FsStructureEvent struct {
	Path     string    `json:"path"`
	CreateOp bool      `json:"createOp,omitempty"`
	RemoveOp bool      `json:"removeOp,omitempty"`
	ChmodOp  bool      `json:"chmodOp,omitempty"`
	RenameOp bool      `json:"renameOp,omitempty"`
	DateTime time.Time `json:"datetime,omitempty"`
}

type FsWriteFileParams

type FsWriteFileParams struct {
	FileURI       defines.URI `json:"uri"`
	ContentBase64 string      `json:"content"`
	Create        bool        `json:"create"`
	Overwrite     bool        `json:"overwrite"`
}

type FsWriteUploadPartParams

type FsWriteUploadPartParams struct {
	UploadId uploadId    `json:"uploadId,omitempty"`
	FileURI  defines.URI `json:"uri"`

	PartContentBase64 string `json:"content,omitempty"`
	Last              bool   `son:"content,last"`
}

type GetLearnInfoParams

type GetLearnInfoParams struct {
}

type GetTutorialSeriesParamss

type GetTutorialSeriesParamss struct {
}

type IndividualServerConfig

type IndividualServerConfig struct {
	MaxWebSocketPerIp      int  `json:"maxWebsocketPerIp,omitempty"`
	IgnoreInstalledBrowser bool `json:"ignoreInstalledBrowser,omitempty"`

	ProjectsDir string `json:"projectsDir,omitempty"` //if not set, defaults to filepath.Join(config.USER_HOME, "inox-projects")
	ProdDir     string `json:"prodDir,omitempty"`     //if not set deployment in production is not allowed

	BehindCloudProxy       bool `json:"behindCloudProxy,omitempty"`
	Port                   int  `json:"port,omitempty"`
	BindToAllInterfaces    bool `json:"bindToAllInterfaces,omitempty"`
	ExposeWebServers       bool `json:"exposeWebServers,omitempty"`
	AllowBrowserAutomation bool `json:"allowBrowserAutomation,omitempty"`
}

type InternalStdio

type InternalStdio struct {
	StdioInput  io.Reader
	StdioOutput io.Writer
}

type LSPServerConfiguration

type LSPServerConfiguration struct {
	InternalStdio       *InternalStdio
	Websocket           *WebsocketServerConfiguration
	MessageReaderWriter jsonrpc.MessageReaderWriter
	UseContextLogger    bool

	ProjectMode           bool
	ProjectsDir           core.Path
	ProdDir               core.Path //if empty deployment in producation is not allowed
	ProjectsDirFilesystem afs.Filesystem
	ExposeWebServers      bool

	OnSession jsonrpc.SessionCreationCallbackFn
}

type LearnInfo

type LearnInfo struct {
}

type ListApplicationStatusesParams

type ListApplicationStatusesParams struct {
}

type ListApplicationStatusesResponse

type ListApplicationStatusesResponse struct {
	Statuses map[node.ApplicationName]string `json:"statuses"`
}

type ListSecretsParams

type ListSecretsParams struct {
}

type ListSecretsResponse

type ListSecretsResponse struct {
	Secrets []core.ProjectSecretInfo `json:"secrets"`
}

type OpenProjectParams

type OpenProjectParams struct {
	ProjectId     core.ProjectID               `json:"projectId"`
	DevSideConfig project.DevSideProjectConfig `json:"config"`
	TempTokens    *project.TempProjectTokens   `json:"tempTokens,omitempty"`
}

type OpenProjectResponse

type OpenProjectResponse struct {
	project.TempProjectTokens `json:"tempTokens"`
	CanBeDeployedInProd       bool `json:"canBeDeployedInProd"`
}

type ProjectServerCmdParams

type ProjectServerCmdParams struct {
	GoCtx          context.Context
	Config         IndividualServerConfig
	InoxBinaryPath string
	Logger         zerolog.Logger
}

type RegisterApplicationParams

type RegisterApplicationParams struct {
	Name       string `json:"name"`
	ModulePath string `json:"modulePath"`
}

type RegisterApplicationResponse

type RegisterApplicationResponse struct {
	Error string `json:"error,omitempty"`
}

type RunFinishedParams

type RunFinishedParams struct {
}

type StopAppParams

type StopAppParams struct {
	AppName string `json:"name"`
}

type StopAppResponse

type StopAppResponse struct {
	Error string `json:"error,omitempty"`
}

type StopTestRunParams

type StopTestRunParams struct {
	TestRunId TestRunId `json:"testRunId"`
}

type TestFileParams

type TestFileParams struct {
	Path            string       `json:"path"`
	PositiveFilters []TestFilter `json:"positiveFilters"`
}

func (TestFileParams) Filters

func (p TestFileParams) Filters() core.TestFilters

type TestFileResponse

type TestFileResponse struct {
	TestRunId TestRunId `json:"testRunId"`
}

type TestFilter

type TestFilter struct {
	Regex        string         `json:"regex"`
	AbsolutePath string         `json:"path,omitempty"`
	NodeSpan     parse.NodeSpan `json:"span,omitempty"`
}

func (TestFilter) Filter

func (f TestFilter) Filter() core.TestFilter

type TestItem

type TestItem struct {
	// contains filtered or unexported fields
}

type TestItemKind

type TestItemKind int8
const (
	ModuleTestItem TestItemKind = iota + 1
	DirTestItem
	TestSuite
	TestCase
)

type TestOutputEvent

type TestOutputEvent struct {
	DataBase64 string `json:"data"`
}

type TestRun

type TestRun struct {
	// contains filtered or unexported fields
}

type TestRunId

type TestRunId string

type TestingController

type TestingController struct {
	// contains filtered or unexported fields
}

func (*TestingController) DoContinuousDiscovery

func (c *TestingController) DoContinuousDiscovery()

DoContinuousDiscovery discovers tests continuously by watching the filesystem for changes, DoContinuousDiscovery runs in the caller's goroutine.

type TutorialSeriesList

type TutorialSeriesList struct {
	TutorialSeries []learn.TutorialSeries `json:"tutorialSeries"`
}

type UpsertSecretParams

type UpsertSecretParams struct {
	Name  string
	Value string
}

type WebsocketServerConfiguration

type WebsocketServerConfiguration struct {
	Addr                  string //examples: localhost:8305, :8305
	Certificate           string
	CertificatePrivateKey string
	MaxWebsocketPerIp     int
	BehindCloudProxy      bool
}

Directories

Path Synopsis
lsp
code gen by methods_gen_test.go, do not edit!
code gen by methods_gen_test.go, do not edit!

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL