You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.6 KiB
3.6 KiB
A module system for your data sources.
{
system: {
metrics: {
loadAverage: true
},
hardware: {
drives: {
path: true,
size: true
}
},
lvm: {
physicalVolumes: {
$collection: {
$$create: { path: "/dev/sda1" }
},
path: true
$$update: { enabled: true }
}
}
}
}
Special schema keys
$anyKey
: specifies a wildcard/fallback handler, that will handle any property specified in the query that isn't explicitly specified in the schema. Use sparingly, as it poses API design/maintenance hazards; it will be difficult to add new explicit keys later on without breaking existing queries.$mutations
: used to specify mutation methods that the user can call on objects. Specified as an object that maps mutation names to their corresponding functions.{ $get, $mutations }
: specified as an object in place of where normally a function or literal value would be expected to be returned; specifically meant for collections where you want to both allow the collection to be fetched, and for the user to specify collection-related mutations (eg. "create new item") within it in a query. This special syntax exists because collections/lists are "transparent" in dlayer and there is no way to specify collection-level behaviour otherwise.$mutations
works the same as in its standalone version.
Special query keys
$recurse
: set totrue
if you want the query to recursively traverse nested objects; eg.... children: { $recurse: true } ...
. The recursive query will be for all the keys of the parent object, as well as any additional properties specified adjacent to the$recurse
key. The key under which this special object is specified, determines what key will be assumed to contain the recursive children.$recurseLimit
(default10
): how many levels of depth the recursion may continue for until being cut off. reaching the limit does not fail the query; it merely stops recursing any further.$allowErrors
: this property may yield an error upon evaluation without failing the query as a whole. instead of returning the value for the property directly, a Result object will be produced that represents either the success value or the error that was encountered. Your code still needs to handle the error case in some way. Typically useful when components of the query are expected to fail due to external circumstances that the requesting user cannot control (eg. a dependency on another network service).$arguments
: used to specify an object of named arguments for either a property or a mutation. Optional for properties; required for mutations (even if left empty).$key
: used to override what schema key to fetch; it will attempt to access the specified key, instead of assuming that the schema key equals the key in the query. Typically used to either alias properties (using a different name in the response than how it is defined in the schema), or to access the same property multiple times with different arguments (eg. filters) and expose the results as different keys.$collection
: used to invoke mutations on a (transparent) collection instead of its members
Special context keys
These keys can be used within property handlers.
$getProperty(object, property)
: evaluate/fetch a different property on the object, and return it (in a Promise). You can referencethis
within the property handler as theobject
to evaluate a property of the object you're currently working with.$getPropertyPath(object, propertyPath)
: the same as above, but for a property path represented as an array of property names (or a dotpath string).