javascript-solid-server 0.0.147 → 0.0.148

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javascript-solid-server",
3
- "version": "0.0.147",
3
+ "version": "0.0.148",
4
4
  "description": "A minimal, fast Solid server",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -182,10 +182,10 @@ export async function createPodStructure(name, webId, podUri, issuer, defaultQuo
182
182
  await storage.write(`${podPath}settings/prefs.jsonld`, serialize(prefs));
183
183
 
184
184
  // Generate and write type indexes
185
- const publicTypeIndex = generateTypeIndex(`${podUri}settings/publicTypeIndex.jsonld`);
185
+ const publicTypeIndex = generateTypeIndex(`${podUri}settings/publicTypeIndex.jsonld`, { listed: true });
186
186
  await storage.write(`${podPath}settings/publicTypeIndex.jsonld`, serialize(publicTypeIndex));
187
187
 
188
- const privateTypeIndex = generateTypeIndex(`${podUri}settings/privateTypeIndex.jsonld`);
188
+ const privateTypeIndex = generateTypeIndex(`${podUri}settings/privateTypeIndex.jsonld`, { listed: false });
189
189
  await storage.write(`${podPath}settings/privateTypeIndex.jsonld`, serialize(privateTypeIndex));
190
190
 
191
191
  // Create default ACL files
package/src/server.js CHANGED
@@ -606,10 +606,10 @@ export function createServer(options = {}) {
606
606
  const prefs = generatePreferences({ webId, podUri });
607
607
  await storage.write('/settings/prefs.jsonld', serialize(prefs));
608
608
 
609
- const publicTypeIndex = generateTypeIndex(`${podUri}settings/publicTypeIndex.jsonld`);
609
+ const publicTypeIndex = generateTypeIndex(`${podUri}settings/publicTypeIndex.jsonld`, { listed: true });
610
610
  await storage.write('/settings/publicTypeIndex.jsonld', serialize(publicTypeIndex));
611
611
 
612
- const privateTypeIndex = generateTypeIndex(`${podUri}settings/privateTypeIndex.jsonld`);
612
+ const privateTypeIndex = generateTypeIndex(`${podUri}settings/privateTypeIndex.jsonld`, { listed: false });
613
613
  await storage.write('/settings/privateTypeIndex.jsonld', serialize(privateTypeIndex));
614
614
 
615
615
  // ACL files
@@ -98,17 +98,25 @@ export function generatePreferences({ webId, podUri }) {
98
98
  }
99
99
 
100
100
  /**
101
- * Generate an empty type index
101
+ * Generate an empty type index.
102
+ * Per the Solid Type Indexes spec, a public index is additionally typed
103
+ * `solid:ListedDocument` and a private one `solid:UnlistedDocument`.
102
104
  * @param {string} uri - URI of the type index
105
+ * @param {object} [opts]
106
+ * @param {boolean} [opts.listed] - true for publicTypeIndex, false for privateTypeIndex.
107
+ * If omitted, only `solid:TypeIndex` is set (back-compat).
103
108
  * @returns {object} JSON-LD type index document
104
109
  */
105
- export function generateTypeIndex(uri) {
110
+ export function generateTypeIndex(uri, opts = {}) {
111
+ const types = ['solid:TypeIndex'];
112
+ if (opts.listed === true) types.push('solid:ListedDocument');
113
+ else if (opts.listed === false) types.push('solid:UnlistedDocument');
106
114
  return {
107
115
  '@context': {
108
116
  'solid': SOLID
109
117
  },
110
118
  '@id': uri,
111
- '@type': 'solid:TypeIndex'
119
+ '@type': types.length === 1 ? types[0] : types
112
120
  };
113
121
  }
114
122
 
package/test/pod.test.js CHANGED
@@ -131,5 +131,33 @@ describe('Pod Lifecycle', () => {
131
131
  const prefs = await request('/elsa/settings/prefs.jsonld');
132
132
  assertStatus(prefs, 401);
133
133
  });
134
+
135
+ it('should mark type indexes as ListedDocument / UnlistedDocument', async () => {
136
+ await createTestPod('frida');
137
+
138
+ const pub = await request('/frida/settings/publicTypeIndex.jsonld');
139
+ assertStatus(pub, 200);
140
+ const pubBody = await pub.json();
141
+ assert.ok(
142
+ Array.isArray(pubBody['@type']) && pubBody['@type'].includes('solid:ListedDocument'),
143
+ 'publicTypeIndex should be solid:ListedDocument'
144
+ );
145
+ assert.ok(
146
+ Array.isArray(pubBody['@type']) && pubBody['@type'].includes('solid:TypeIndex'),
147
+ 'publicTypeIndex should be solid:TypeIndex'
148
+ );
149
+
150
+ const priv = await request('/frida/settings/privateTypeIndex.jsonld', { auth: 'frida' });
151
+ assertStatus(priv, 200);
152
+ const privBody = await priv.json();
153
+ assert.ok(
154
+ Array.isArray(privBody['@type']) && privBody['@type'].includes('solid:UnlistedDocument'),
155
+ 'privateTypeIndex should be solid:UnlistedDocument'
156
+ );
157
+ assert.ok(
158
+ Array.isArray(privBody['@type']) && privBody['@type'].includes('solid:TypeIndex'),
159
+ 'privateTypeIndex should be solid:TypeIndex'
160
+ );
161
+ });
134
162
  });
135
163
  });