MCPcopy Index your code
hub / github.com/nodeSolidServer/node-solid-server / readGraph

Function readGraph

lib/handlers/patch.mjs:113–144  ·  view source on GitHub ↗
(resource)

Source from the content-addressed store, hash-verified

111
112// Reads the RDF graph in the given resource
113function readGraph (resource) {
114 // Read the resource's file
115 return new Promise((resolve, reject) =>
116 fs.readFile(resource.path, { encoding: 'utf8' }, function (err, fileContents) {
117 if (err) {
118 // If the file does not exist, assume empty contents
119 // (it will be created after a successful patch)
120 if (err.code === 'ENOENT') {
121 fileContents = contentForNew(resource.contentType)
122 // Fail on all other errors
123 } else {
124 return reject(error(500, `Original file read error: ${err}`))
125 }
126 }
127 debug('PATCH -- Read target file (%d bytes)', fileContents.length)
128 fileContents = resource.contentType.includes('json') ? JSON.parse(fileContents) : fileContents
129 resolve(fileContents)
130 })
131 )
132 // Parse the resource's file contents
133 .then((fileContents) => {
134 const graph = $rdf.graph()
135 debug('PATCH -- Reading %s with content type %s', resource.url, resource.contentType)
136 try {
137 $rdf.parse(fileContents, graph, resource.url, resource.contentType)
138 } catch (err) {
139 throw error(500, `Patch: Target ${resource.contentType} file syntax error: ${err}`)
140 }
141 debug('PATCH -- Parsed target file')
142 return graph
143 })
144}
145
146// Verifies whether the user is allowed to perform the patch on the target
147async function checkPermission (request, patchObject, resourceExists) {

Callers 1

patchHandlerFunction · 0.85

Calls 2

contentForNewFunction · 0.85
graphMethod · 0.80

Tested by

no test coverage detected