javascript-solid-server 0.0.203 → 0.0.205
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +28 -0
- package/package.json +2 -1
- package/src/cli/install.js +22 -6
- package/src/mashlib/index.js +12 -6
- package/src/rdf/turtle.js +0 -0
- package/src/utils/url.js +10 -15
- package/test/turtle.test.js +42 -1
- package/test/url.test.js +22 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(gh issue *)",
|
|
5
|
+
"Bash(sort -t: -k3 -n)",
|
|
6
|
+
"Bash(sed -n '1,30p' docs/features/overview.md)",
|
|
7
|
+
"Bash(npm run *)",
|
|
8
|
+
"Bash(git add *)",
|
|
9
|
+
"Bash(git commit -q -m 'docs: add Account Management page with API endpoints \\(#23\\) *)",
|
|
10
|
+
"Bash(git push *)",
|
|
11
|
+
"Bash(gh pr create --title 'docs: Account Management page \\(change password, backup/export, delete\\) — closes #23' --body ' *)",
|
|
12
|
+
"Bash(gh pr *)",
|
|
13
|
+
"Bash(git checkout *)",
|
|
14
|
+
"Bash(git pull *)",
|
|
15
|
+
"Bash(gh api *)",
|
|
16
|
+
"Bash(git fetch *)",
|
|
17
|
+
"Bash(grep *)",
|
|
18
|
+
"Bash(node --check src/cli/install.js)",
|
|
19
|
+
"Bash(git commit -q -m 'fix\\(install\\): drop spawnSync\\('\\\\''rm'\\\\''\\) shell-out for fs.rmSync — works on Windows *)",
|
|
20
|
+
"Bash(node --test --test-concurrency=1 test/turtle.test.js)",
|
|
21
|
+
"Bash(npm test *)",
|
|
22
|
+
"Bash(git commit -q -m 'fix\\(rdf\\): preserve blank-node SUBJECTS through Turtle ↔ JSON-LD \\(#536\\) *)",
|
|
23
|
+
"Bash(npm view *)",
|
|
24
|
+
"Bash(git branch *)",
|
|
25
|
+
"Bash(git commit -q -m 'bump version to 0.0.205 *)"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "javascript-solid-server",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.205",
|
|
4
4
|
"description": "A minimal, fast Solid server",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"fs-extra": "^11.2.0",
|
|
37
37
|
"jose": "^6.1.3",
|
|
38
38
|
"microfed": "^0.0.14",
|
|
39
|
+
"mime-types": "^2.1.35",
|
|
39
40
|
"n3": "^1.26.0",
|
|
40
41
|
"oidc-provider": "^9.6.0",
|
|
41
42
|
"sql.js": "^1.13.0",
|
package/src/cli/install.js
CHANGED
|
@@ -25,8 +25,9 @@
|
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { spawnSync } from 'child_process';
|
|
28
|
-
import { existsSync, readFileSync } from 'fs';
|
|
28
|
+
import { existsSync, readFileSync, rmSync } from 'fs';
|
|
29
29
|
import { join, isAbsolute } from 'path';
|
|
30
|
+
import { tmpdir } from 'os';
|
|
30
31
|
import { nip98Token } from '../nostr/event.js';
|
|
31
32
|
|
|
32
33
|
// ANSI helpers — keep zero-dep so this works in any embedded usage.
|
|
@@ -221,6 +222,18 @@ async function fetchToken({ pod, user, password }) {
|
|
|
221
222
|
}
|
|
222
223
|
}
|
|
223
224
|
|
|
225
|
+
// Best-effort recursive cleanup of the scratch clone dir. fs.rmSync
|
|
226
|
+
// with `force: true` silently ignores ENOENT (so no existsSync guard
|
|
227
|
+
// is needed), and the try/catch absorbs the rare EBUSY / EACCES that
|
|
228
|
+
// can fire on Windows when an editor or antivirus still holds a
|
|
229
|
+
// handle inside the tree. Mirrors the original `spawnSync('rm',
|
|
230
|
+
// '-rf', ..., { stdio: 'ignore' })` contract: an install must not
|
|
231
|
+
// fail after a successful clone/push just because tmp cleanup didn't
|
|
232
|
+
// go through. Portable: no shell-out, no /tmp assumptions.
|
|
233
|
+
function cleanupTmp(tmp) {
|
|
234
|
+
try { rmSync(tmp, { recursive: true, force: true }); } catch { /* best-effort */ }
|
|
235
|
+
}
|
|
236
|
+
|
|
224
237
|
/**
|
|
225
238
|
* Install one app spec to one pod. Returns a status object the caller
|
|
226
239
|
* uses for per-app output + exit-code aggregation.
|
|
@@ -228,10 +241,13 @@ async function fetchToken({ pod, user, password }) {
|
|
|
228
241
|
async function installOne({ spec, pod, token, nostrPrivkey }) {
|
|
229
242
|
const { source, name, ref } = spec;
|
|
230
243
|
const dest = `${pod}/public/apps/${name}`;
|
|
231
|
-
|
|
244
|
+
// Respect the platform's tmp dir — '/tmp' is hardcoded out on
|
|
245
|
+
// Termux (Android), where the writable tmp is at $PREFIX/tmp.
|
|
246
|
+
// os.tmpdir() respects $TMPDIR and falls back sensibly everywhere.
|
|
247
|
+
const tmp = join(tmpdir(), `jss-install-${name}-${process.pid}`);
|
|
232
248
|
|
|
233
249
|
// Clean any stale tmp from a prior failed run.
|
|
234
|
-
|
|
250
|
+
cleanupTmp(tmp);
|
|
235
251
|
|
|
236
252
|
// Clone (no --depth: shallow pushes are rejected by JSS git-receive).
|
|
237
253
|
// --branch picks a tag or branch when pinned (e.g. `foo/bar#v2`).
|
|
@@ -285,7 +301,7 @@ async function installOne({ spec, pod, token, nostrPrivkey }) {
|
|
|
285
301
|
// Auto-init refuses on a non-empty target dir → 404 / "not found".
|
|
286
302
|
// Distinguish "path already in use" from real errors.
|
|
287
303
|
if (pushMain.status !== 0 && (errMain.includes('not found') || errMain.includes('404'))) {
|
|
288
|
-
|
|
304
|
+
cleanupTmp(tmp);
|
|
289
305
|
return { name, status: 'skipped', reason: 'path already in use' };
|
|
290
306
|
}
|
|
291
307
|
|
|
@@ -293,11 +309,11 @@ async function installOne({ spec, pod, token, nostrPrivkey }) {
|
|
|
293
309
|
|
|
294
310
|
if (pushMain.status !== 0 && pushPages.status !== 0) {
|
|
295
311
|
const err = (errMain + '\n' + (pushPages.stderr?.toString?.() || '')).trim();
|
|
296
|
-
|
|
312
|
+
cleanupTmp(tmp);
|
|
297
313
|
return { name, status: 'failed', reason: `push failed: ${err.slice(0, 400)}` };
|
|
298
314
|
}
|
|
299
315
|
|
|
300
|
-
|
|
316
|
+
cleanupTmp(tmp);
|
|
301
317
|
return { name, status: 'installed', dest: `${dest}/` };
|
|
302
318
|
}
|
|
303
319
|
|
package/src/mashlib/index.js
CHANGED
|
@@ -356,8 +356,12 @@ export function shouldServeMashlib(request, mashlibEnabled, contentType) {
|
|
|
356
356
|
}
|
|
357
357
|
}
|
|
358
358
|
|
|
359
|
-
//
|
|
360
|
-
|
|
359
|
+
// Serve the mashlib shell only for content types that have a pane to
|
|
360
|
+
// render them. RDF + markdown + playlists, plus any single audio type
|
|
361
|
+
// (the audio pane). Do NOT add video/image types here until panes exist
|
|
362
|
+
// for them — wrapping them would show "No data found" instead of the
|
|
363
|
+
// browser's native inline render. See #533.
|
|
364
|
+
const viewableTypes = [
|
|
361
365
|
'text/turtle',
|
|
362
366
|
'application/ld+json',
|
|
363
367
|
'application/json',
|
|
@@ -365,13 +369,15 @@ export function shouldServeMashlib(request, mashlibEnabled, contentType) {
|
|
|
365
369
|
'application/n-triples',
|
|
366
370
|
'application/rdf+xml',
|
|
367
371
|
'text/markdown',
|
|
368
|
-
'
|
|
369
|
-
'application/vnd.apple.mpegurl',
|
|
370
|
-
'audio/x-scpls'
|
|
372
|
+
'application/vnd.apple.mpegurl'
|
|
371
373
|
];
|
|
372
374
|
|
|
373
375
|
const baseType = contentType.split(';')[0].trim().toLowerCase();
|
|
374
|
-
|
|
376
|
+
// Any audio/* type (mpeg, ogg, wave, x-flac, mpegurl playlists, ...) has a
|
|
377
|
+
// pane (audio or playlist), so match the whole family rather than enumerate
|
|
378
|
+
// the exact spellings the mime-types db happens to use.
|
|
379
|
+
if (baseType.startsWith('audio/')) return true;
|
|
380
|
+
return viewableTypes.includes(baseType);
|
|
375
381
|
}
|
|
376
382
|
|
|
377
383
|
/**
|
package/src/rdf/turtle.js
CHANGED
|
Binary file
|
package/src/utils/url.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
|
+
import * as mime from 'mime-types';
|
|
2
3
|
|
|
3
4
|
// Base directory for storing all pods
|
|
4
5
|
// Use a getter function to read env var at runtime (not import time)
|
|
@@ -218,28 +219,19 @@ function getPodNameFromPath(urlPath) {
|
|
|
218
219
|
*/
|
|
219
220
|
export function getContentType(filePath) {
|
|
220
221
|
const ext = path.extname(filePath).toLowerCase();
|
|
221
|
-
|
|
222
|
+
|
|
223
|
+
// Solid-specific overrides — types the `mime-types` db doesn't know, or
|
|
224
|
+
// where Solid semantics differ. Checked before falling back to mime-types
|
|
225
|
+
// (which covers the long tail: audio/video/fonts/archives/office/etc.).
|
|
226
|
+
const overrides = {
|
|
222
227
|
'.jsonld': 'application/ld+json',
|
|
223
|
-
'.json': 'application/json',
|
|
224
|
-
'.html': 'text/html',
|
|
225
|
-
'.txt': 'text/plain',
|
|
226
|
-
'.css': 'text/css',
|
|
227
|
-
'.js': 'application/javascript',
|
|
228
|
-
'.png': 'image/png',
|
|
229
|
-
'.jpg': 'image/jpeg',
|
|
230
|
-
'.jpeg': 'image/jpeg',
|
|
231
|
-
'.gif': 'image/gif',
|
|
232
|
-
'.svg': 'image/svg+xml',
|
|
233
|
-
'.pdf': 'application/pdf',
|
|
234
228
|
'.ttl': 'text/turtle',
|
|
235
229
|
'.n3': 'text/n3',
|
|
236
230
|
'.nt': 'application/n-triples',
|
|
237
231
|
'.rdf': 'application/rdf+xml',
|
|
238
232
|
'.nq': 'application/n-quads',
|
|
239
233
|
'.trig': 'application/trig',
|
|
240
|
-
'.md': 'text/markdown',
|
|
241
234
|
'.m3u': 'audio/mpegurl',
|
|
242
|
-
'.m3u8': 'application/vnd.apple.mpegurl',
|
|
243
235
|
'.pls': 'audio/x-scpls',
|
|
244
236
|
// Solid ACL/meta as extensions (e.g. publicTypeIndex.jsonld.acl)
|
|
245
237
|
'.acl': 'application/ld+json',
|
|
@@ -255,7 +247,10 @@ export function getContentType(filePath) {
|
|
|
255
247
|
const base = path.basename(filePath);
|
|
256
248
|
if (base === '.acl' || base === '.meta') return 'application/ld+json';
|
|
257
249
|
|
|
258
|
-
|
|
250
|
+
// Overrides first, then the comprehensive mime-types database (as CSS and
|
|
251
|
+
// NSS do), then octet-stream. This is what makes audio/video/etc. resolve
|
|
252
|
+
// to a real type instead of forcing a download. See #533.
|
|
253
|
+
return overrides[ext] || mime.lookup(filePath) || 'application/octet-stream';
|
|
259
254
|
}
|
|
260
255
|
|
|
261
256
|
/**
|
package/test/turtle.test.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import { describe, it } from 'node:test';
|
|
14
14
|
import assert from 'node:assert';
|
|
15
|
-
import { fromJsonLd } from '../src/rdf/conneg.js';
|
|
15
|
+
import { fromJsonLd, toJsonLd } from '../src/rdf/conneg.js';
|
|
16
16
|
|
|
17
17
|
describe('turtle converter — unit (#320 follow-ups)', () => {
|
|
18
18
|
it('expandUri does not recurse forever on a cyclic context (a → b → a)', async () => {
|
|
@@ -258,4 +258,45 @@ describe('turtle converter — unit (#320 follow-ups)', () => {
|
|
|
258
258
|
assert.ok(content.includes('https://example.test/a'), 'node a should appear');
|
|
259
259
|
assert.ok(content.includes('https://example.test/b'), 'node b should appear');
|
|
260
260
|
});
|
|
261
|
+
|
|
262
|
+
describe('blank-node subject roundtrip (#536)', () => {
|
|
263
|
+
const baseUri = 'https://example.test/u/c/bn.ttl';
|
|
264
|
+
const input = '@prefix ex: <http://example.org/> .\n<#s> ex:p [ ex:a 1 ; ex:b 2 ] .\n';
|
|
265
|
+
|
|
266
|
+
it('Turtle → JSON-LD emits blank-node SUBJECTS with the "_:" prefix', async () => {
|
|
267
|
+
// Previously the subject side dropped "_:", producing a bare label
|
|
268
|
+
// ("n3-0") that resolved as a relative IRI on read; the object side
|
|
269
|
+
// (termToJsonLd) already kept "_:". Result: severed graph.
|
|
270
|
+
const doc = await toJsonLd(input, 'text/turtle', baseUri, true);
|
|
271
|
+
const nodes = Array.isArray(doc) ? doc : [doc];
|
|
272
|
+
// The blank-node subject is the one carrying ex:a / ex:b.
|
|
273
|
+
const bn = nodes.find(n => 'ex:a' in n);
|
|
274
|
+
assert.ok(bn, 'expected a node carrying ex:a');
|
|
275
|
+
assert.ok(typeof bn['@id'] === 'string' && bn['@id'].startsWith('_:'),
|
|
276
|
+
`blank-node subject @id should start with "_:", got ${JSON.stringify(bn['@id'])}`);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('Turtle → JSON-LD → Turtle preserves the blank-node connection', async () => {
|
|
280
|
+
// End-to-end: parse output Turtle and verify the blank node carrying
|
|
281
|
+
// ex:a / ex:b is the SAME node that <#s> ex:p points at — i.e. the
|
|
282
|
+
// graph is not severed.
|
|
283
|
+
const doc = await toJsonLd(input, 'text/turtle', baseUri, true);
|
|
284
|
+
const { content: outTurtle } = await fromJsonLd(doc, 'text/turtle', baseUri, true);
|
|
285
|
+
|
|
286
|
+
const { Parser } = await import('n3');
|
|
287
|
+
const quads = new Parser({ baseIRI: baseUri }).parse(outTurtle);
|
|
288
|
+
|
|
289
|
+
const pQuad = quads.find(q => q.predicate.value === 'http://example.org/p');
|
|
290
|
+
assert.ok(pQuad, 'ex:p triple should be present');
|
|
291
|
+
assert.strictEqual(pQuad.object.termType, 'BlankNode',
|
|
292
|
+
'ex:p object must remain a blank node, not be promoted to a named IRI');
|
|
293
|
+
|
|
294
|
+
const aQuad = quads.find(q => q.predicate.value === 'http://example.org/a');
|
|
295
|
+
assert.ok(aQuad, 'ex:a triple should be present');
|
|
296
|
+
assert.strictEqual(aQuad.subject.termType, 'BlankNode',
|
|
297
|
+
'ex:a subject must remain a blank node');
|
|
298
|
+
assert.strictEqual(aQuad.subject.value, pQuad.object.value,
|
|
299
|
+
'the blank node carrying ex:a must be the same one ex:p references');
|
|
300
|
+
});
|
|
301
|
+
});
|
|
261
302
|
});
|
package/test/url.test.js
CHANGED
|
@@ -94,7 +94,28 @@ describe('getContentType', () => {
|
|
|
94
94
|
assert.strictEqual(getContentType('/x/card.ttl'), 'text/turtle');
|
|
95
95
|
});
|
|
96
96
|
it('falls back to application/octet-stream for unknown extensions', () => {
|
|
97
|
-
|
|
97
|
+
// .zzz is not in the mime-types db (unlike .xyz → chemical/x-xyz)
|
|
98
|
+
assert.strictEqual(getContentType('/x/file.zzz'), 'application/octet-stream');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('media types via mime-types db (#533)', () => {
|
|
103
|
+
it('maps .mp3 → audio/mpeg (was octet-stream → forced download)', () => {
|
|
104
|
+
assert.strictEqual(getContentType('/music/song.mp3'), 'audio/mpeg');
|
|
105
|
+
});
|
|
106
|
+
it('maps common audio extensions to audio/*', () => {
|
|
107
|
+
for (const f of ['a.ogg', 'a.wav', 'a.m4a', 'a.flac', 'a.opus', 'a.aac']) {
|
|
108
|
+
assert.ok(getContentType(f).startsWith('audio/'), f + ' should be audio/*, got ' + getContentType(f));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
it('maps video and other common types', () => {
|
|
112
|
+
assert.strictEqual(getContentType('v.mp4'), 'video/mp4');
|
|
113
|
+
assert.strictEqual(getContentType('d.pdf'), 'application/pdf');
|
|
114
|
+
});
|
|
115
|
+
it('keeps Solid overrides ahead of the mime-types db', () => {
|
|
116
|
+
assert.strictEqual(getContentType('card.ttl'), 'text/turtle');
|
|
117
|
+
assert.strictEqual(getContentType('x.jsonld'), 'application/ld+json');
|
|
118
|
+
assert.strictEqual(getContentType('p.m3u'), 'audio/mpegurl');
|
|
98
119
|
});
|
|
99
120
|
});
|
|
100
121
|
|