-
Notifications
You must be signed in to change notification settings - Fork 3
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
api
should be strict - The
api
should be consistent - The
api
should make as few decisions as possible - The
api
should 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_provider
will be thrown from this as well
- Errors thrown by
- Notes
-
init
is called automatically on import ofnetman.api
and 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_buffer
will be called automatically when aNetman
managed buffer is closed by vim (due to the an autocommand that is registered toBufUnload
for the specific protocol that the buffer was opened with) -
unload_buffer
will 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_path
should 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_provider
is 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
init
function if it has one - Ensures that core providers do not override 3rd party providers. This means that
Netman
will 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
autocommands
that link the providersprotocols
toNetman
to 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
-
read
returns 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
LINK
orDESTINATION
For a traditional filesystem, acceptLINK
as a "directory" andDESTINATION
as a "file"
- This will be either
- METADATA: table
- Whatever (
stat
compatible) 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/dir
would 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
:Nmread
command which is made available bynetman.init
. It is also automatically called onFileReadCmd
andBufReadCmd
vim 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
-
delete
does 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 -
delete
is available to be called via the:Nmdelete
vim command -
delete
does 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 theURI
that 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
-
write
is available to be called via the:Nmwrite
vim 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
api
will 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
message
attribute (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
,value
pairs table where the key is each item inmetadata_keys
and thevalue
is 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's
memory as well aslua
as 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_event
and 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 uri
s 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
uri
cache
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
table
object that is stored and managed by theapi
. Theapi
gets this object from theprovider
'sinit
. For more details on how the cache works, consult the Developer Guide
- Returns
- table
-
read
must 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
message
attribute. 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
type
that is returned along side the data.- TYPE == 'STREAM'
- For a
STREAM
type, 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
EXPLORE
type, 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
FILE
type, 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
read
process 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
table
object that is stored and managed by theapi
. Theapi
gets 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
message
attribute. 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
-
api
does 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
table
object that is stored and managed by theapi
. Theapi
gets 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
message
attribute. 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
-
api
does 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
message
attribute (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
message
attribute (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_metadata
an array of values where each value in the array can be located in theNetman METADATA Table
.
- Returns
- Should return a Table where the
key
in each entry of the table should be from the inputrequested_metadata
array
- Should return a Table where the
- Throws: nil
- Notes
- This will be called by
api
whenever the user requests additional metadata about a link/destination. Thekeys
are all validstat
flags andapi
will expect the data returned to conform to the datatypes thatstat
will 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
/false
depending on if the provider was able to properly initialize itself
- Should return a
- Throws: nil
- Notes
init
is an optional function that will be called immediately after import of theprovider
if it exists- This function's intended purpose is to allow the
provider
to verify that the environment it is being ran in is capable of handling it (IE, the environment meets whatever requirements theprovider
has), though it can be used for whatever theprovider
need in order to ensure it is ready to run
- Version Added: 0.1
- Updated : 1.01
-
uri
-
cache
- Type: Table
- Details: The
table
object that is stored and managed by theapi
. Theapi
gets this object from theprovider
'sinit
. For more details on how the cache works, consult the Developer Guide
- Returns: nil
- Throws: nil
- Notes
close_connection
is an optional function that will be called immediately after aBufUnload
event if called fromvim
, ifclose_connection
exists on the provider- This function's intended purpose is to allow the
provider
to clean up after a buffer has been closed. The intent being to allow theprovider
a 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_patterns
should be an array of the various protocols (not blobs) that the provider supports. - **NOTE:
protocol_patterns
is 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