Skip to content

Commit

Permalink
chore: add type hints to resources component
Browse files Browse the repository at this point in the history
  • Loading branch information
line-o committed Oct 26, 2022
1 parent 8f35e31 commit bba6fa5
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions components/resources.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,53 @@
/**
* @typedef { import("xmlrpc").Client } XMLRPCClient
*/

/**
* @typedef {Object} ResourceInfo
* @prop {string} name resource name or path
* @prop {"BinaryRerource"|"XMLResource"} type Resource type (XML or binary)
* @prop {string} owner DB user name
* @prop {string} group DB group name
* @prop {number} permissions as octet (e.g. 420)
* @prop {number} content-length length as 32-bit integer
* @prop {string} content-length-64bit length as BigInt string
* @prop {string} mime-type mimetype
* @prop {Date} created date the resource was created
* @prop {Date} modified date when the resource was last modified
* @prop {Array} acl Access Control List entries
*/

/**
* Gather information on a resource
* throws when resource does not exist, path points to a collection
*
* @param {XMLRPCClient} client RPC client instance
* @param {string} resourceIdentifier path to resource
* @returns {Promise<ResourceInfo>} Resource information
*/
function describe (client, resourceIdentifier) {
return client.promisedMethodCall('describeResource', [resourceIdentifier])
}

/**
* Set the permissions for a resource or collection
*
* @param {XMLRPCClient} client RPC client instance
* @param {string} resourceIdentifier path to resource
* @param {number} permission octet number
* @returns {Promise<boolean>} true if the action was succesful
*/
function setPermissions (client, resourceIdentifier, permission) {
return client.promisedMethodCall('setPermissions', [resourceIdentifier, permission])
}

/**
* Get the permissions for a resource or collection
*
* @param {XMLRPCClient} client RPC client instance
* @param {string} resourceIdentifier path to resource
* @returns {Promise<number>} permissions as octet number
*/
function getPermissions (client, resourceIdentifier) {
return client.promisedMethodCall('getPermissions', [resourceIdentifier])
}
Expand Down

0 comments on commit bba6fa5

Please sign in to comment.