@@ -14,21 +14,11 @@ import { mimeMatch } from "./utilities.js";
14
14
* @import { JsonCompatible } from "../json/jsonast.js"
15
15
* @import { UriSchemePlugin } from "./uri-schemes/uri-scheme-plugin.js"
16
16
* @import { DocumentNode, MediaTypePlugin } from "./media-types/media-type-plugin.js"
17
- * @import { JsonPointerError } from "../json/jsonast-util.js"
17
+ * @import * as API from "./hyperjump.d.ts";
18
18
*/
19
19
20
20
21
- /**
22
- * @typedef {{} } HyperjumpConfig
23
- */
24
-
25
21
// TODO: Support fetch options in get
26
- /**
27
- * @typedef {{
28
- * referencedFrom?: string;
29
- * }} GetOptions
30
- */
31
-
32
22
// TODO: Support filters
33
23
34
24
export class Hyperjump {
@@ -44,11 +34,11 @@ export class Hyperjump {
44
34
/** @type Record<string, MediaTypePlugin<DocumentNode>> */
45
35
#mediaTypePlugins;
46
36
47
- /** @type GetOptions */
37
+ /** @type API. GetOptions */
48
38
#defaultGetOptions;
49
39
50
40
/**
51
- * @param {HyperjumpConfig } [config]
41
+ * @param {API. HyperjumpConfig } [config]
52
42
*/
53
43
constructor ( config = { } ) {
54
44
this . #config = config ;
@@ -69,22 +59,7 @@ export class Hyperjump {
69
59
this . addMediaTypePlugin ( new JsonMediaTypePlugin ( ) ) ;
70
60
}
71
61
72
- /**
73
- * Retrieve a document located at the given URI. URIs can be relative if a
74
- * base URI can be determined. On the server-side, the base URI is the CWD. In
75
- * browser, the base URI is the URI of the page.
76
- *
77
- * @see Use {@link Hyperjump.addUriSchemePlugin} to add support for additional
78
- * URI schemes.
79
- * @see Support for {@link JrefMediaTypePlugin | JRef} and
80
- * {@link JsonMediaTypePlugin | JSON} is built in. Use
81
- * {@link Hyperjump.addMediaTypePlugin} to add support for additional media
82
- * types.
83
- *
84
- * @type (uri: string, options?: GetOptions) => Promise<JsonCompatible<JrefNode>>
85
- * @throws {@link RetrievalError}
86
- * @throws {@link JsonPointerError}
87
- */
62
+ /** @type API.Hyperjump["get"] */
88
63
async get ( uri , options = this . #defaultGetOptions) {
89
64
uri = resolveIri ( uri , contextUri ( ) ) ;
90
65
const id = toAbsoluteIri ( uri ) ;
@@ -127,39 +102,19 @@ export class Hyperjump {
127
102
}
128
103
}
129
104
130
- /**
131
- * Add support for a
132
- * {@link https://www.rfc-editor.org/rfc/rfc3986#section-3.1 | URI scheme}.
133
- * Support for the {@link HttpUriSchemePlugin | `http(s):`} and
134
- * {@link FileUriSchemePlugin | `file:`} URI schemes are enabled by default.
135
- *
136
- * @type (plugin: UriSchemePlugin) => void
137
- */
105
+ /** @type API.Hyperjump["addUriSchemePlugin"] */
138
106
addUriSchemePlugin ( plugin ) {
139
107
for ( const scheme of plugin . schemes ) {
140
108
this . #uriSchemePlugins[ scheme ] = plugin ;
141
109
}
142
110
}
143
111
144
- /**
145
- * This is mostly useful for disabling a scheme that's enabled by default.
146
- *
147
- * @type (scheme: string) => void
148
- */
112
+ /** @type API.Hyperjump["removeUriSchemePlugin"] */
149
113
removeUriSchemePlugin ( scheme ) {
150
114
delete this . #uriSchemePlugins[ scheme ] ;
151
115
}
152
116
153
- /**
154
- * Unless you're using it in a {@link UriSchemePlugin.retrieve} method, this
155
- * is not the method you're looking for. It's used internally to fetch a
156
- * resource before processing it based on its media type. You might use it for
157
- * implementing {@link UriSchemePlugin}s for URI schemes that don't have
158
- * locating semantics (such as `urn:`) and instead map to another URI where
159
- * the resource can be retrieved from. See the example in the README.
160
- *
161
- * @type (uri: string, options: GetOptions) => Promise<Response>
162
- */
117
+ /** @type API.Hyperjump["retrieve"] */
163
118
async retrieve ( uri , options ) {
164
119
const { scheme } = parseIri ( uri ) ;
165
120
@@ -170,11 +125,7 @@ export class Hyperjump {
170
125
return this . #uriSchemePlugins[ scheme ] . retrieve ( uri , options ) ;
171
126
}
172
127
173
- /**
174
- * Constructs an `Accept` header based on the registered media types.
175
- *
176
- * @type () => string
177
- */
128
+ /** @type API.Hyperjump["acceptableMediaTypes"] */
178
129
acceptableMediaTypes ( ) {
179
130
let accept = "" ;
180
131
@@ -198,12 +149,7 @@ export class Hyperjump {
198
149
return accept ;
199
150
}
200
151
201
- /**
202
- * Returns the media type of the resource based on its URI. This is usually
203
- * based on the extension and configured by {@link MediaTypePlugin}s.
204
- *
205
- * @type (uri: string) => string
206
- */
152
+ /** @type API.Hyperjump["getMediaType"] */
207
153
getMediaType ( uri ) {
208
154
for ( const contentType in this . #mediaTypePlugins) {
209
155
for ( const extension of this . #mediaTypePlugins[ contentType ] . extensions ) {
@@ -218,34 +164,17 @@ export class Hyperjump {
218
164
throw new UnknownMediaTypeError ( `The media type of the file at '${ uri } ' could not be determined. Use the 'addMediaTypePlugin' function to add support for this media type.` ) ;
219
165
}
220
166
221
- /**
222
- * Add support for a media tpe. Support for the
223
- * {@link JrefMediaTypePlugin | `JRef`} and
224
- * {@link JsonMediaTypePlugin | `JSON`} media types are enabled by default.
225
- *
226
- * @type <T extends DocumentNode>(plugin: MediaTypePlugin<T>) => void
227
- */
167
+ /** @type API.Hyperjump["addMediaTypePlugin"] */
228
168
addMediaTypePlugin ( plugin ) {
229
169
this . #mediaTypePlugins[ plugin . mediaType ] = plugin ;
230
170
}
231
171
232
- /**
233
- * This is mostly useful for disabling a scheme that's enabled by default.
234
- *
235
- * @type (contentType: string) => void
236
- */
172
+ /** @type API.Hyperjump["removeMediaTypePlugin"] */
237
173
removeMediaTypePlugin ( contentType ) {
238
174
delete this . #mediaTypePlugins[ contentType ] ;
239
175
}
240
176
241
- /**
242
- * Set the
243
- * {@link https://developer.mozilla.org/en-US/docs/Glossary/Quality_values | quality}
244
- * that will be used in the Accept header of requests to indicate to servers
245
- * which media types are preferred over others.
246
- *
247
- * @type (contentType: string, quality: number) => void
248
- */
177
+ /** @type API.Hyperjump["setMediaTypeQuality"] */
249
178
setMediaTypeQuality ( contentType , quality ) {
250
179
this . #mediaTypePlugins[ contentType ] . quality = quality ;
251
180
}
@@ -271,22 +200,12 @@ export class Hyperjump {
271
200
typeOf = jsonTypeOf ;
272
201
has = jsonObjectHas ;
273
202
274
- /**
275
- * This is like indexing into an object or array. It will follow any
276
- * references it encounters so it always returns a JSON compatible value.
277
- *
278
- * @type (key: string, node: JsonCompatible<JrefNode>) => Promise<JsonCompatible<JrefNode>>
279
- */
203
+ /** @type API.Hyperjump["step"] */
280
204
async step ( key , node ) {
281
205
return await this . #followReferences( pointerStep ( key , node ) ) ;
282
206
}
283
207
284
- /**
285
- * Iterate over an array node. It will follow any references it encounters so
286
- * it always yields JSON compatible values.
287
- *
288
- * @type (node: JsonCompatible<JrefNode>) => AsyncGenerator<JsonCompatible<JrefNode>, void, unknown>
289
- */
208
+ /** @type API.Hyperjump["iter"] */
290
209
async * iter ( node ) {
291
210
if ( node . jsonType === "array" ) {
292
211
for ( const itemNode of node . children ) {
@@ -297,12 +216,7 @@ export class Hyperjump {
297
216
298
217
keys = jsonObjectKeys ;
299
218
300
- /**
301
- * Iterate over the values of an object. It will follow any references it
302
- * encounters so it always yields JSON compatible values.
303
- *
304
- * @type (node: JsonCompatible<JrefNode>) => AsyncGenerator<JsonCompatible<JrefNode>, void, unknown>
305
- */
219
+ /** @type API.Hyperjump["values"] */
306
220
async * values ( node ) {
307
221
if ( node . jsonType === "object" ) {
308
222
for ( const propertyNode of node . children ) {
@@ -311,12 +225,7 @@ export class Hyperjump {
311
225
}
312
226
}
313
227
314
- /**
315
- * Iterate over key/value pairs of an object. It will follow any references it
316
- * encounters so it always yields JSON compatible values.
317
- *
318
- * @type (node: JsonCompatible<JrefNode>) => AsyncGenerator<[string, JsonCompatible<JrefNode>], void, unknown>
319
- */
228
+ /** @type API.Hyperjump["entries"] */
320
229
async * entries ( node ) {
321
230
if ( node . jsonType === "object" ) {
322
231
for ( const propertyNode of node . children ) {
0 commit comments