@@ -14,21 +14,11 @@ import { mimeMatch } from "./utilities.js";
1414 * @import { JsonCompatible } from "../json/jsonast.js"
1515 * @import { UriSchemePlugin } from "./uri-schemes/uri-scheme-plugin.js"
1616 * @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";
1818 */
1919
2020
21- /**
22- * @typedef {{} } HyperjumpConfig
23- */
24-
2521// TODO: Support fetch options in get
26- /**
27- * @typedef {{
28- * referencedFrom?: string;
29- * }} GetOptions
30- */
31-
3222// TODO: Support filters
3323
3424export class Hyperjump {
@@ -44,11 +34,11 @@ export class Hyperjump {
4434 /** @type Record<string, MediaTypePlugin<DocumentNode>> */
4535 #mediaTypePlugins;
4636
47- /** @type GetOptions */
37+ /** @type API. GetOptions */
4838 #defaultGetOptions;
4939
5040 /**
51- * @param {HyperjumpConfig } [config]
41+ * @param {API. HyperjumpConfig } [config]
5242 */
5343 constructor ( config = { } ) {
5444 this . #config = config ;
@@ -69,22 +59,7 @@ export class Hyperjump {
6959 this . addMediaTypePlugin ( new JsonMediaTypePlugin ( ) ) ;
7060 }
7161
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"] */
8863 async get ( uri , options = this . #defaultGetOptions) {
8964 uri = resolveIri ( uri , contextUri ( ) ) ;
9065 const id = toAbsoluteIri ( uri ) ;
@@ -127,39 +102,19 @@ export class Hyperjump {
127102 }
128103 }
129104
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"] */
138106 addUriSchemePlugin ( plugin ) {
139107 for ( const scheme of plugin . schemes ) {
140108 this . #uriSchemePlugins[ scheme ] = plugin ;
141109 }
142110 }
143111
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"] */
149113 removeUriSchemePlugin ( scheme ) {
150114 delete this . #uriSchemePlugins[ scheme ] ;
151115 }
152116
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"] */
163118 async retrieve ( uri , options ) {
164119 const { scheme } = parseIri ( uri ) ;
165120
@@ -170,11 +125,7 @@ export class Hyperjump {
170125 return this . #uriSchemePlugins[ scheme ] . retrieve ( uri , options ) ;
171126 }
172127
173- /**
174- * Constructs an `Accept` header based on the registered media types.
175- *
176- * @type () => string
177- */
128+ /** @type API.Hyperjump["acceptableMediaTypes"] */
178129 acceptableMediaTypes ( ) {
179130 let accept = "" ;
180131
@@ -198,12 +149,7 @@ export class Hyperjump {
198149 return accept ;
199150 }
200151
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"] */
207153 getMediaType ( uri ) {
208154 for ( const contentType in this . #mediaTypePlugins) {
209155 for ( const extension of this . #mediaTypePlugins[ contentType ] . extensions ) {
@@ -218,34 +164,17 @@ export class Hyperjump {
218164 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.` ) ;
219165 }
220166
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"] */
228168 addMediaTypePlugin ( plugin ) {
229169 this . #mediaTypePlugins[ plugin . mediaType ] = plugin ;
230170 }
231171
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"] */
237173 removeMediaTypePlugin ( contentType ) {
238174 delete this . #mediaTypePlugins[ contentType ] ;
239175 }
240176
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"] */
249178 setMediaTypeQuality ( contentType , quality ) {
250179 this . #mediaTypePlugins[ contentType ] . quality = quality ;
251180 }
@@ -271,22 +200,12 @@ export class Hyperjump {
271200 typeOf = jsonTypeOf ;
272201 has = jsonObjectHas ;
273202
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"] */
280204 async step ( key , node ) {
281205 return await this . #followReferences( pointerStep ( key , node ) ) ;
282206 }
283207
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"] */
290209 async * iter ( node ) {
291210 if ( node . jsonType === "array" ) {
292211 for ( const itemNode of node . children ) {
@@ -297,12 +216,7 @@ export class Hyperjump {
297216
298217 keys = jsonObjectKeys ;
299218
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"] */
306220 async * values ( node ) {
307221 if ( node . jsonType === "object" ) {
308222 for ( const propertyNode of node . children ) {
@@ -311,12 +225,7 @@ export class Hyperjump {
311225 }
312226 }
313227
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"] */
320229 async * entries ( node ) {
321230 if ( node . jsonType === "object" ) {
322231 for ( const propertyNode of node . children ) {
0 commit comments