Refactor sysquery-mounts for async type factories

feature/node-rewrite
Sven Slootweg 1 year ago
parent 15577b2908
commit b83ae646e3

@ -10,6 +10,7 @@ const treeFilterFlatAsync = require("../tree-filter-flat-async");
const treeMapAsync = require("../tree-map-async"); const treeMapAsync = require("../tree-map-async");
const treeFind = require("../tree-find"); const treeFind = require("../tree-find");
const All = require("../graphql-interface/symbols/all"); const All = require("../graphql-interface/symbols/all");
const mapAsync = require("../map-async");
module.exports = { module.exports = {
name: "sysquery.mounts", name: "sysquery.mounts",
@ -83,7 +84,8 @@ module.exports = {
let mountTree = await findmnt.load(All); let mountTree = await findmnt.load(All);
let relevantMounts = await treeFilterFlatAsync(mountTree, async (mount) => { let relevantMounts = await treeFilterFlatAsync(mountTree, async (mount) => {
let mountObject = $make("sysquery.mounts.Mount", { mountpoint: mount.mountpoint }); let mountObject = await $make("sysquery.mounts.Mount", { mountpoint: mount.mountpoint });
// FIXME: Validate that this isn't an InvalidObject
// console.log({ sourceDevice: await $getProperty(mountObject, "sourceDevice") }); // console.log({ sourceDevice: await $getProperty(mountObject, "sourceDevice") });
let sourcePath = await $getPropertyPath(mountObject, "sourceDevice.path"); let sourcePath = await $getPropertyPath(mountObject, "sourceDevice.path");
let sourceName = await $getPropertyPath(mountObject, "sourceDevice.name"); let sourceName = await $getPropertyPath(mountObject, "sourceDevice.name");
@ -103,7 +105,7 @@ module.exports = {
}, { recurseFilteredSubtrees: true }); }, { recurseFilteredSubtrees: true });
// This is a bit hacky; this approach should probably be replaced by a map-filter instead. But for now, this will do - as this all happens in the same request context, there's no real penalty to re-creating the mount objects a second time. // This is a bit hacky; this approach should probably be replaced by a map-filter instead. But for now, this will do - as this all happens in the same request context, there's no real penalty to re-creating the mount objects a second time.
return relevantMounts.map((mount) => { return mapAsync(relevantMounts, (mount) => {
return $make("sysquery.mounts.Mount", { mountpoint: mount.mountpoint }); return $make("sysquery.mounts.Mount", { mountpoint: mount.mountpoint });
}); });
} }

Loading…
Cancel
Save