Skip to content

Commit d2ebe52

Browse files
author
CI Fix
committed
update esm and tests
1 parent 562a91b commit d2ebe52

File tree

14 files changed

+3734
-1369
lines changed

14 files changed

+3734
-1369
lines changed

index.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import createApp from './lib/create-app.mjs'
22
import createServer from './lib/create-server.mjs'
3-
import startCli from './bin/lib/cli.js'
3+
// import startCli from './bin/lib/cli.js'
4+
import { createRequire } from 'module'
5+
const require = createRequire(import.meta.url)
6+
const startCli = require('./bin/lib/cli.js')
47

58
export default createApp
6-
export { createServer, startCli }
9+
export { createServer, startCli }

lib/create-server.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import http from 'http'
55
import SolidWs from 'solid-ws'
66
import createApp from './create-app.mjs'
77
import globalTunnel from 'global-tunnel-ng'
8-
import { handlers as debug } from './debug.mjs'
8+
import { settings as debugSettings } from './debug.mjs'
99
import { createRequire } from 'module'
1010

1111
function createServer (argv, app) {
@@ -20,7 +20,7 @@ function createServer (argv, app) {
2020
mount = mount.slice(0, -1)
2121
}
2222
app.use(mount, ldpApp)
23-
debug.settings('Base URL (--mount): ' + mount)
23+
debugSettings('Base URL (--mount): ' + mount)
2424

2525
if (argv.idp) {
2626
console.warn('The idp configuration option has been renamed to multiuser.')
@@ -37,8 +37,8 @@ function createServer (argv, app) {
3737
if (!needsTLS) {
3838
server = http.createServer(app)
3939
} else {
40-
debug.settings('SSL Private Key path: ' + argv.sslKey)
41-
debug.settings('SSL Certificate path: ' + argv.sslCert)
40+
debugSettings('SSL Private Key path: ' + argv.sslKey)
41+
debugSettings('SSL Certificate path: ' + argv.sslCert)
4242

4343
if (!argv.sslCert && !argv.sslKey) {
4444
throw new Error('Missing SSL cert and SSL key to enable WebIDs')

lib/debug.mjs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,23 @@ export const accounts = debug('solid:accounts')
1515
export const email = debug('solid:email')
1616
export const ldp = debug('solid:ldp')
1717
export const fs = debug('solid:fs')
18-
export const prep = debug('solid:prep')
18+
export const prep = debug('solid:prep')
19+
20+
export default {
21+
handlers,
22+
errors,
23+
ACL,
24+
cache,
25+
parse,
26+
metadata,
27+
authentication,
28+
settings,
29+
server,
30+
subscription,
31+
container,
32+
accounts,
33+
email,
34+
ldp,
35+
fs,
36+
prep
37+
}

lib/handlers/index.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import path from 'path'
44
import { createRequire } from 'module'
55
const require = createRequire(import.meta.url)
6-
const debug = require('debug')('solid:index')
6+
import debugModule from 'debug'
7+
const debug = debugModule('solid:index')
78
const Negotiator = require('negotiator')
89
import url from 'url'
910
const URI = require('urijs')

lib/handlers/put.mjs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import bodyParser from 'body-parser'
22
import debugModule from 'debug'
3-
const debug = debugModule('solid:put')
3+
const debugPut = debugModule('solid:put')
44
import { getContentType, stringToStream } from '../utils.mjs'
55
import HTTPError from '../http-error.mjs'
66

77
export default async function handler (req, res, next) {
8-
debug(req.originalUrl)
98
// deprecated kept for compatibility
109
res.header('MS-Author-Via', 'SPARQL') // is this needed ?
1110
const contentType = req.get('content-type')
@@ -35,7 +34,7 @@ function isAuxiliary (req) {
3534
}
3635

3736
async function putValidRdf (req, res, next) {
38-
debug('Parsing RDF for ' + req.originalUrl)
37+
debugPut('Parsing RDF for ' + req.originalUrl)
3938
const ldp = req.app.locals.ldp
4039
const contentType = getContentType(req.headers) || 'text/turtle'
4140

@@ -44,16 +43,16 @@ async function putValidRdf (req, res, next) {
4443
req.body = stringToStream(req.body)
4544
return putResource(req, res, next)
4645
} catch (err) {
47-
debug(`Invalid RDF file: ${req.originalUrl} - ${err}`)
46+
debugPut(`Invalid RDF file: ${req.originalUrl} - ${err}`)
4847
return next(HTTPError(400, `Invalid RDF file: ${err}`))
4948
}
5049
}
5150

5251
async function putResource (req, res, next) {
5352
const ldp = req.app.locals.ldp
5453
const contentType = getContentType(req.headers)
55-
debug('Request ' + req.originalUrl)
56-
debug('content-type is', contentType)
54+
debugPut('Request ' + req.originalUrl)
55+
debugPut('content-type is', contentType)
5756

5857
// check whether a folder or resource with same name exists
5958
try {
@@ -65,23 +64,24 @@ async function putResource (req, res, next) {
6564
const stream = req
6665
const result = await putStream(ldp, req, res, stream, contentType)
6766
res.set('MS-Author-Via', 'SPARQL') // ??? really?
67+
console.log('PUT result code:', result)
6868
if (result === 201) {
69-
debug('new file created')
69+
debugPut('new file created')
7070
res.sendStatus(result)
7171
} else {
72-
debug('file updated')
72+
debugPut('file updated')
7373
res.sendStatus(result)
7474
}
7575
next()
7676
} catch (e) {
77-
debug('putResource error:' + e.status + ' ' + e.message)
77+
debugPut('putResource error:' + e.status + ' ' + e.message)
7878
next(e)
7979
}
8080
}
8181

82-
function putStream (ldp, req, res, stream, contentType) {
82+
async function putStream (ldp, req, res, stream, contentType) {
8383
const uri = res.locals.target.url
84-
return new Promise((resolve, reject) => {
84+
/* return new Promise((resolve, reject) => {
8585
ldp.put(req, res, uri, contentType, stream, (err, result) => {
8686
if (err) {
8787
debug('putResource error:' + err.status + ' ' + err.message)
@@ -91,5 +91,14 @@ function putStream (ldp, req, res, stream, contentType) {
9191
}
9292
resolve(result)
9393
})
94-
})
94+
}) */
95+
try {
96+
return await ldp.put(uri, stream, contentType);
97+
} catch (err) {
98+
debugPut('putResource error:' + err.status + ' ' + err.message);
99+
err.status = err.status || 500
100+
err.message = err.message || 'Unknown error'
101+
throw err
102+
}
103+
95104
}

lib/ldp.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import url from 'url'
88
import fs from 'fs'
99
const $rdf = require('rdflib')
1010
const { mkdirp } = require('fs-extra')
11-
const uuid = require('uuid')
11+
import uuid from'uuid' // there seem to be an esm module
1212
import debug from './debug.mjs'
1313
import error from './http-error.mjs'
1414
import { stringToStream, serialize, overQuota, getContentType, parse } from './utils.mjs'
@@ -183,6 +183,7 @@ class LDP {
183183
createIfNotExists: true,
184184
searchIndex: false
185185
})
186+
debug.handlers('PUT -- Mapped url to file: ' + path)
186187

187188
return await this.putResource(url, stream, contentType, path)
188189
}

lib/rdf-notification-template.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createRequire } from 'module'
22
const require = createRequire(import.meta.url)
3-
const uuid = require('uuid')
3+
import uuid from 'uuid'
44

55
const CONTEXT_ACTIVITYSTREAMS = 'https://www.w3.org/ns/activitystreams'
66
const CONTEXT_NOTIFICATION = 'https://www.w3.org/ns/solid/notification/v1'

0 commit comments

Comments
 (0)