-
Notifications
You must be signed in to change notification settings - Fork 5
API Documentation
Source can be found here
The "API" of Netman consists of 4 parts. Those parts are
API (Redundant I know but 🤷♂️)
The api is the main abstraction point within Netman. This component is what sits between the end user, the providers and consumers. This abstraction layer allows users to not have to worry about how to interact with the underlying providers, it allows providers to not have to worry about how users will interact with the data, it allows consumers to not have to worry about how to interface with providers, etc. Everything comes and goes through the api.
Notable functions within the api are
The Provider is the bridge between the api and external data sources. Examples of providers are
Notable functions within a provider are
The Consumer is the bridge between the api and external file browsers.
Each of these 3 pieces have their own specification which is laid out below. For more details on how these parts interact, as well as how Netman as whole works, please checkout the Developer Guide
Each of the above parts will have their "public facing" items documented here. "Private" functions/variables will not be documented in this documentation as they are not meant to be used.
Private functions/variables will usually have a _ leading them (so for example, _my_private_variable or _my_private_function), or be a member of an internal attribute (so for example, internal.my_private_function)
Note, the specification for each function below is laid out in the follow example format
function_name(param1, param2, paramX)- Version Added:
- Updated :
- Param1
- Type: Expected Type
- Details: (Optional)
- Param2
- Type: Expected Type
- Details: (Optional)
- ParamX
- Type: Expected Type
- Details: (Optional)
- Returns
- Type: Expected Return Type
- Details: (Optional)
- Throws
- Details about potential errors that are thrown in this function
- Notes (Optional)
The api is the core of Netman and all processing of remote data is done through the api. It is worth noting that the api itself does not do much processing of the data, relegating that to the relevant provider to do. Instead, api acts as a sort of middle man between the user and the provider. API is designed with the following core concepts in mind
- The
apishould be strict - The
apishould be consistent - The
apishould make as few decisions as possible - The
apishould not manipulate data
With these concepts in mind, the api is able to ensure a stable contract between the user and provider without either having to interface much with the other.
Most communication with the api will revolve around "uris". A uri is the string representation of the remote data that the user wishes to interface with. A uri is traditionally represented in the following manner protocol://host_authentication_information/path and api makes this assumption when dealing with any uris from the user.
The process of interfacing with the api is outlined more in the Developer Guide
- Version Added: 0.1
- Updated : 1.01
- Returns: nil
- Throws
- Errors thrown by
load_providerwill be thrown from this as well
- Errors thrown by
- Notes
-
initis called automatically on import ofnetman.apiand has a lock in place to prevent side effects of multiple imports ofapi. - This function does not need to be called when importing
netman.api
-
- Version Added: 0.1
- Updated : 1.01
-
uri- Type: String
- Details: The string URI associated with the unloaded buffer
- Returns: nil
- Throws: nil
- Notes
-
unload_bufferwill be called automatically when aNetmanmanaged buffer is closed by vim (due to the an autocommand that is registered toBufUnloadfor the specific protocol that the buffer was opened with) -
unload_bufferwill cleanup the local file used for a remote file pull if the provider performed a remote file pull - Unload_buffer will call |close_connection| on the associated provider if the provider implemented
close_connection
-
- Version Added: 0.1
-
provider_path- Type: String
- Details:
provider_pathshould be the string path to import a provider. For examplenetman.provider.ssh
- Returns: nil
- Throws
- "Failed to initialize provider: " error
- This is thrown when an attempt to import the provider fails or the provider has no contents (IE, its an empty file)
- This is also thrown (with different sub details) if the provider is missing one of the required attributes. For more details on required attributes for a provider, please consult the Developer Guide
- "Failed to initialize provider: " error
- Notes
-
load_provideris the expected function to call when you are registering a new provider to handle a protocol, or registering an explorer to handle tree browsing. The function does a handful of things, which are laid out below- Attempts to import the provider. If there is a failure in the initial import, the above error(s) are thrown
- Validates the provider has the required attributes as laid out in the developer guide
- Calls the provider's
initfunction if it has one - Ensures that core providers do not override 3rd party providers. This means that
Netmanwill never attempt to override an existing provider for a protocol that netman supports.- NOTE: Netman does not prevent overriding of 3rd party providers by other 3rd party providers. Netman operates providers on "most recent provider" basis. This means that the most recent provider to register as the provider for a protocol will be used
- Register
autocommandsthat link the providersprotocolstoNetmanto be handled by theAPI
-
- Version Added: 0.1
- Updated : 1.01
-
uri- Type: String
- Details: The uri to open. This is passed directly to the associated provider for this uri
-
opts- Type: Table
- Details: Table containing read options. Valid options are
- force: boolean
- If provided, we will remove any cached version of the uri and call the provider to re-read the uri
- force: boolean
- Returns
-
readreturns a table that will have the following key/value pairs (some are optional)- success: boolean
- A boolean to indicate if the provider successfully read the uri
- error: table (optional)
- If provided, a message to be relayed to the user, usually given
by the provider. Should be a table that has a single attribute
(message) within. An example
{error = { message = "Something bad happened!"}}
- If provided, a message to be relayed to the user, usually given
by the provider. Should be a table that has a single attribute
(message) within. An example
- type: String
- Will be one of the following strings
- STREAM, EXPLORE, FILE These are enums found in netman.options.api.READ_TYPE
- Will be one of the following strings
- data: table (optional)
- If provided, the data that was read. This will be a table, though the contents will be based on what type is returned
- Type EXPLORE:
- A 1 dimensional array where each item in the array contains
the following keys
- ABSOLUTE_PATH: table
- A piece by piece break down of the path to follow to
reach the item in question. As an example, for
sftp://myhost///my/dir/, this would return > { name = 'my', uri = "sftp://myhost///my" }, { name = "dir", uri = "sftp://myhost///my/dir" } <
- A piece by piece break down of the path to follow to
reach the item in question. As an example, for
- FIELD_TYPE: string
- This will be either
LINKorDESTINATIONFor a traditional filesystem, acceptLINKas a "directory" andDESTINATIONas a "file"
- This will be either
- METADATA: table
- Whatever (
statcompatible) metadata the provider felt like providing with the item in question
- Whatever (
- NAME: string
- The "relative" name of the item. As an example:
sftp://myhost///my/dirwould have a name ofdir
- The "relative" name of the item. As an example:
- URI: string
- The "absolute" uri that can be followed to reach the item in question. This is more useful for LINK navigation (tree walking) as directories may be linked or nonexistent at times and this URI should ensure access to the same node at all times
- ABSOLUTE_PATH: table
- A 1 dimensional array where each item in the array contains
the following keys
- Type FILE:
- A table containing the following key/value pairs (or nil)
- data: table
- remote_path: string
- The remote absolute path to follow for this URI
- local_path: string
- The local absolute path to follow for this URI
- remote_path: string
- error: table (Optional)
- TODO
- data: table
- A table containing the following key/value pairs (or nil)
- Type STREAM:
- A 1 dimensional table with text (each item should be considered a line) to display to the buffer Notes
- success: boolean
- read is accessible via the
:Nmreadcommand which is made available bynetman.init. It is also automatically called onFileReadCmdandBufReadCmdvim events. The end user should not have to directly interface withnetman.api.read, instead preferring to let vim handle that via the above listed events.
-
- Version Added: 0.1
- Updated : 1.01
-
uri - Returns: nil
- Throws
- Notes
-
deletedoes not require the URI to be a loaded buffer, however it does require a provider be loaded (via load_provider that can handle the protocol of the URI that is being requested to delete -
deleteis available to be called via the:Nmdeletevim command -
deletedoes not require the URI to be a loaded buffer, however it does require a provider be loaded (viaload_provider) that can handle the protocol of theURIthat is being requested to delete
-
- Version Added: 0.1
- Updated : 1.01
-
buffer_index(optional)- Type: Integer
- Details: The buffer index associated with the write path. If provided, we will use the index to pull the buffer content and provide that to the provider. Otherwise, the provider will be given an empty array to write out to the file NOTE: this will almost certainly be destructive, be sure you know what you are doing if you are sending an empty write!
-
uri -
opts- Type: Table
- Details: Reserved for later use
- Returns: Table
- A table that contains the following key/value pairs - success: boolean A boolean indicating if the provider was successful in its write - uri: string A string of the path to the uri
- Throws
- Notes
-
writeis available to be called via the:Nmwritevim command
-
- Version Added: 1.01
-
old_uri- Type: String
- Details: The (current) uri path to rename
-
new_uri- Type: String
- Details: The (new) uri path. The path to rename to
Returns: Table
Returns a table that contains the following key/value pairs
- success: boolean A boolean indicating if the provider was successful in its write
- error: table (Optional)
- If provided, a message to be relayed to the user, usually given
by the provider. Should be a table that has a single attribute
(message) within. An example
{error = { message = "Something bad happened!"}} Notes
- If provided, a message to be relayed to the user, usually given
by the provider. Should be a table that has a single attribute
(message) within. An example
- The
apiwill prevent rename from "functioning" if the old_uri and new_uri do not share the same provider.
- Version Added: 1.01
-
uris- Type: table
- Details: The table of string URIs to copy
-
target_uri- Type: String
- Details: The string location to move the URIs to. Consider this a "parent" location to copy into
-
opts- Type: table
- Details: A table of options that can be provided to the provider.
Valid options are
- cleanup: boolean If provided, indicates to the provider that they should "clean" (remove) the originating file after copy is complete. Consider this the "move" option
- Returns: table
- Details
- A table should be returned with the following key/value pairs
(some are optional)
- success: boolean
- This should be a true or false to indicate if the copy was successful or not
- error: table (optional)
- This should be provided in the event that you have an
error to pass to the caller. The contents of this should
be a table with a single
messageattribute (which houses a string) EG:error = { message = "SOMETHING CATASTROPHIC HAPPENED!" }
- This should be provided in the event that you have an
error to pass to the caller. The contents of this should
be a table with a single
- success: boolean
- A table should be returned with the following key/value pairs
(some are optional)
- Details
Version Added: 1.01
See copy as this definition is the exact same (with the exception being that it tells copy to clean up after its complete)
- Version Added: 0.95
- Updated : 1.01
-
uri- Type: String
- Details: The uri to request metadata for
-
metadata_keys- Type: Table
- Details: A 1 dimensional table of metadata keys as found in netman.options.metadata
- Returns
-
key,valuepairs table where the key is each item inmetadata_keysand thevalueis what was returned by the provider
-
- Version Added: 0.1
- Notes
- It's a version tag, what notes do you need?
- Version Added: 0.95
- Updated : 1.01
-
provider_path- Type: String
- Details: The string path for the provider to unload
-
justification- Type: table (optional)
- Details:
If provided, this table should indicate why the provider is being unloaded from netman. Required keys (if the table is provided) are
- reason: string
- name: string The "require" path of the provider
- protocol: string A comma delimited list of the protocols the provider supported
- version: string The version of the provider
- Details:
If provided, this table should indicate why the provider is being unloaded from netman. Required keys (if the table is provided) are
- Type: table (optional)
- Returns: nil
- Throws: nil
- Notes
- This function is provided strictly for development use and is not required to be called in the lifecycle of a provider.
- Use cases for this function are mostly when working on a new provider. By calling this function, you will remove the provider
**both from
Netman'smemory as well asluaas a whole - Targeted use is live development of a provider without having to restart Neovim.
- Version Added: 0.95
-
provider_path- Type: String
- Details: The string path for the provider to reload
- Returns: nil
- Throws
- Any errors that load_provider throws
- Notes
- This is a helper function that simply calls unload_provider followed immediately by load_provider
- Version Added: 1.01
- Returns
logger
- Type: table
- Details: Returns a logger object that will log out to the provider
logs (located at
$XDG_DATA_HOME/netman/logs/provider)
- Version Added: 1.01
- Returns
logger
- Type: table
- Details: Returns a logger object that will log out to the provider
logs (located at
$XDG_DATA_HOME/netman/logs/consumer)
- Version Added: 1.01
- Returns
logger
- Type: table
- Details: Returns a logger object that will log out to the provider
logs (located at
$XDG_DATA_HOME/netman/logs/system)
- Version Added: 1.01
-
assume_yes- Type: boolean
- Default: false
- Details: If provided, no questions are asked to the end user and we will just remove purge any unused configurations. If not provided, we will prompt for each configuration that needs to be removed
- Returns: nil
- Version Added: 1.01
-
output_path- Type: string
- Default: nil
- Details: If provided, the session logs that are "generated" (more like gathered but whatever) will be saved into this file.
- Returns: nil
- Note
- This is one of the only functions in the api that interacts with vim's buffers. It will open a new buffer and set the contents of the buffer to the log gathered for the current session. This is very useful if you are trying to track down an odd event as the in memory logs are not filtered out
- Version Added: 1.01
-
event- Type: string
- Details: An event to listen for
-
callback- Type: function
- Details: The callback to be called when the event is emitted.
When this function is called by the API, it will be provided with
a table that contains the following key/value pairs
- event: string
- The event that was fired
- source: string (optional)
- The source that emitted the event. This is not required by
emit_eventand thus may be nil
- Returns:
id- An id that is used to associated the provided callback with the event Throws
-
INVALID_EVENT_ERROR- An error that is thrown if the requested event is nil
-
INVALID_EVENT_CALLBACK_ERROR- An error that is thrown if there is no callback provided
- Version Added: 1.01
-
id- Type: string
- Details: The id of the callback to unregister. This id is provided by |netman.api.register_event_callback| Returns: nil Throws
-
INVALID_ID_ERROR- An error that is thrown if the id is nil
- Version Added: 1.01
-
event- Type: string
- Details: The event to emit (I know, super clever!)
-
source- Type: string (optional)
- Details: The name of the caller. Usually this would be the require path of the caller but you can technically use whatever you want here Returns: nil Note:
- This is (currently) a synchronous call, so your callback needs to process the event quickly as it will hold up the rest of neovim
A provider is a program (Neovim plugin in the case of Netman) that acts as a middle man between api and external programs. The providers job is to communicate with said external programs and return consistently formatted data to the api so it can be returned to the user to be handled.
An example of a provider is netman.providers.ssh
When creating a provider, there are several key things to keep in mind.
api chooses which provider to use for a given uri based on the provider protocol_patterns. These patterns are extracted and analyzed when a provider registers itself with the api on its load_provider call (which is required in order to have your provider be made available to consume uris from the user)
There are several required attributes a provider must implement, those being
There are additional optional functions that if implemented, will be called during the lifecycle of the provider and buffers associated with it. Those being
There are 2 key variables that are provided with most calls to a provider by the api. Those are
uricache
The uri is the string representation of the remote data that the user wishes to interface with. A uri is traditionally represented in the following manner protocol://host_authentication_information/path and api uses this assumption to determine if a provider should handle that uri or not.
The cache object is a table that is created (as an empty table) by api after calling the provider's init function. This is a safe place for the provider to store state as it is not manipulated by anything else (including the api, other providers, etc) and stores any changes made to it by the provider. This is especially useful when establishing the initial details from the uri so the provider doesn't have to continually re-parse a uri
Details on how to implement a provider can be found within the Developer Guide
- Version Added: 0.1
- Updated : 1.01
-
uri -
cache- Type: Table
- Details: The
tableobject that is stored and managed by theapi. Theapigets this object from theprovider'sinit. For more details on how the cache works, consult the Developer Guide
- Returns
- table
-
readmust return a table with the following key/value pairs- success: boolean
- A true/false to indicate if the read was successful or not
- type: string
- A valid type as found in
api.read
- A valid type as found in
- error: table (optional)
- If there were any encountered errors, place the error here in a table where the error is attached to the
messageattribute. EGerror = {message = "SOMETHING CATASTROPHIC HAPPENED!"}
- If there were any encountered errors, place the error here in a table where the error is attached to the
- data: table
- A table that contains the data to consume. This data should be formed in one of the 3 following ways, depending on the
typethat is returned along side the data.- TYPE == 'STREAM'
- For a
STREAMtype, simply put your data into a 1 dimensional table (where each item in the table is a "line" of output)
- For a
- TYPE == 'EXPLORE'
- For a
EXPLOREtype, the returned table should be a 1 dimensional table of complex tables. Each "child" table should contain the following key/value pairs- URI: string
- The URI to follow to resolve this child object
- FIELD_TYPE: string
- The type of item being returned. See options for valid field types
- NAME: string
- The name of the item to be presented to the user
- ABSOLUTE_PATH: table
- Another complex table that is a "path" of URIs to follow to reach this URI. An example would better demonstrate this { { name = 'my', uri = "sftp://myhost///my" }, { name = "dir", uri = "sftp://myhost///my/dir" } }
- METADATA: table (optional)
- Stat compliant metadata for the item. If provided, the flags must match what are found in the options
- URI: string
- For a
- TYPE == 'FILE'
- For a
FILEtype, the returned table must include the following 2 key/value pairs- local_path: string
- The "local" path of the item. Useful for rendering a "local" representation of the "remote" system
- origin_path
- The uri that was followed for this item
- local_path: string
- For a
- TYPE == 'STREAM'
- For more information on how the
readprocess works, please consult theDeveloper Guide
- A table that contains the data to consume. This data should be formed in one of the 3 following ways, depending on the
- success: boolean
-
- table
- Throws: nil
- Notes
- IT IS NO LONGER ACCEPTABLE FOR READ TO THROW ERRORS. INSTEAD, RETURN THOSE ERRORS ALONG WITH A
success = false
- IT IS NO LONGER ACCEPTABLE FOR READ TO THROW ERRORS. INSTEAD, RETURN THOSE ERRORS ALONG WITH A
- Version Added: 0.1
- Updated : 1.01
-
uri -
cache- Type: Table
- Details: The
tableobject that is stored and managed by theapi. Theapigets this object from theprovider'sinit. For more details on how the cache works, consult the Developer Guide
-
data- Type: Table
- Details: A table of "lines" to write to the backing store
-
opts- Type: Table
- Details: Reserved for future use
- Returns: Table
- A table with the following key/value pairs is returned
- uri: string (optional)
- The URI of the written item. Useful if a new item was generated and needs to be returned, or if the provided URI is a shortcut URI (IE, not absolute)
- success: boolean
- error: table (optional)
- If there were any encountered errors, place the error here in a table where the error is attached to the
messageattribute. EGerror = {message = "SOMETHING CATASTROPHIC HAPPENED!"}
- If there were any encountered errors, place the error here in a table where the error is attached to the
- uri: string (optional)
- A table with the following key/value pairs is returned
- Notes
-
apidoes not currently provide any tools for dealing with oddities in the write process (permission error, network failure, etc), and those errors and validations are left up to the provider to handle.
-
- Version Added: 0.1
- Updated : 1.01
-
uri -
cache- Type: Table
- Details: The
tableobject that is stored and managed by theapi. Theapigets this object from theprovider'sinit. For more details on how the cache works, consult the Developer Guide
- Returns: Table
- A table with the following key/value pairs is returned
- success: boolean
- error: table (optional)
- If there were any encountered errors, place the error here in a table where the error is attached to the
messageattribute. EGerror = {message = "SOMETHING CATASTROPHIC HAPPENED!"}
- If there were any encountered errors, place the error here in a table where the error is attached to the
- A table with the following key/value pairs is returned
- Notes
-
apidoes not currently provide any tools for dealing with oddities in the delete process (user verification, permission error, network failure, etc), and those errors and validations are left up to the provider to handle.
-
- Version Added: 0.2
- Updated : 1.01
-
uris -
target_uri- Type: String
- Details: The string location to move the URIs to. Consider this a "parent" location to move into. Note, if a single uri is provided, it is expected that that the uri is "renamed" to the target_uri (as opposed to moving into that location)
-
cache - Returns: Table
- Details
- A table should be returned with the following key/value pairs (some are optional)
- success: boolean
- This should be a true or false to indicate if the move was successful or not
- error: table (optional)
- This should be provided in the event that you have an error to pass
to the caller.
The contents of this should be a table with a single
messageattribute (which houses a string) EG:error = { message = "SOMETHING CATASTROPHIC HAPPENED!" }
- This should be provided in the event that you have an error to pass
to the caller.
The contents of this should be a table with a single
- success: boolean
- A table should be returned with the following key/value pairs (some are optional)
- Details
- Version Added: 0.2
- Updated : 1.01
-
uris -
target_uri- Type: String
- Details: The string location to copy the URIs to. Consider this a "parent" location to copy into. Note, if a single uri is provided, it is expected that that the uri is named to the target_uri (as opposed to copied into that location)
-
cache - Returns: Table
- Details
- A table should be returned with the following key/value pairs (some are optional)
- success: boolean
- This should be a true or false to indicate if the copy was successful or not
- error: table (optional)
- This should be provided in the event that you have an error to pass
to the caller.
The contents of this should be a table with a single
messageattribute (which houses a string) EG:error = { message = "SOMETHING CATASTROPHIC HAPPENED!" }
- This should be provided in the event that you have an error to pass
to the caller.
The contents of this should be a table with a single
- success: boolean
- A table should be returned with the following key/value pairs (some are optional)
- Details
- Version Added: 0.95
-
uri -
requested_metadata- Type: Array
- Details:
requested_metadataan array of values where each value in the array can be located in theNetman METADATA Table.
- Returns
- Should return a Table where the
keyin each entry of the table should be from the inputrequested_metadataarray
- Should return a Table where the
- Throws: nil
- Notes
- This will be called by
apiwhenever the user requests additional metadata about a link/destination. Thekeysare all validstatflags andapiwill expect the data returned to conform to the datatypes thatstatwill return for those flags
- This will be called by
- Version Added: 0.1
-
configuration_options- Type: Table
- Details: WIP (currently unused)
- Returns
- Should return a
true/falsedepending on if the provider was able to properly initialize itself
- Should return a
- Throws: nil
- Notes
initis an optional function that will be called immediately after import of theproviderif it exists- This function's intended purpose is to allow the
providerto verify that the environment it is being ran in is capable of handling it (IE, the environment meets whatever requirements theproviderhas), though it can be used for whatever theproviderneed in order to ensure it is ready to run
- Version Added: 0.1
- Updated : 1.01
-
uri -
cache- Type: Table
- Details: The
tableobject that is stored and managed by theapi. Theapigets this object from theprovider'sinit. For more details on how the cache works, consult the Developer Guide
- Returns: nil
- Throws: nil
- Notes
close_connectionis an optional function that will be called immediately after aBufUnloadevent if called fromvim, ifclose_connectionexists on the provider- This function's intended purpose is to allow the
providerto clean up after a buffer has been closed. The intent being to allow theprovidera way to close out existing connections to remote locations, close files, etc
- Version Added: 0.1
- Notes: The string name of the provider
- Version Added: 0.1
- Notes
-
protocol_patternsshould be an array of the various protocols (not blobs) that the provider supports. - **NOTE:
protocol_patternsis sanitized on read in byapi
-
- Version Added: 0.1
- Notes
- You've come far in the documentation. I am proud of you :)
Options can be found in netman.options. These "options" are a table which acts as a sort of enum for the core of Netman. api relies on these options as a standard way of communicating "information" between itself and its providers. Below is a breakdown of each "option" that can be found here. These options will be referenced throughout various points in the API Documentation as well as the Developer Guide
- api
- READ_TYPE
- FILE
- STREAM
- EXPLORE
- ATTRIBUTES
- FILE
- DIRECTORY
- LINK
- READ_TYPE
- explorer
- METADATA
- PERMISSIONS
- OWNER_USER
- OWNER_GROUP
- SIZE_LABEL
- SIZE
- GROUP
- PARENT
- FIELD_TYPE
- TYPE
- INODE
- LASTACCESS
- FULLNAME
- URI
- NAME
- LINK
- DESTINATION
- FIELDS
- FIELD_TYPE
- NAME
- URI
- METADATA
- Version Added: 0.9
- Notes
- I'm tired, I am running out of quirky things to say here
A program that is used to visualize a directory tree
Term used to indicate method of network communication to use. EG: ssh, rsync, ftp, etc
Program that integrates with Netman to provide a bridge between a program that supports a protocol and vim
A string representation of a path to a stream/file. EG: sftp://host/file or ftp://ip_address/file. A more technical definition can be found on wikipedia