Skip to content

Commit c7223f9

Browse files
committed
Remove build step
1 parent 4e8adf2 commit c7223f9

38 files changed

+466
-359
lines changed

bin/postpack.js

-10
This file was deleted.

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@
2929
"scripts": {
3030
"lint": "eslint src",
3131
"test": "vitest --watch=false",
32-
"coverage": "vitest run --coverage",
3332
"type-check": "tsc --noEmit",
34-
"docs": "typedoc",
35-
"prepack": "tsc --project tsconfig.build.json",
36-
"postpack": "node ./bin/postpack.js"
33+
"docs": "typedoc --excludeExternals"
3734
},
3835
"devDependencies": {
3936
"@stylistic/eslint-plugin": "*",

src/hyperjump/hyperjump.d.ts

+136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import type { JsonCompatible } from "../json/jsonast.d.ts";
2+
import type { JrefNode } from "../jref/jref-ast.d.ts";
3+
import type { UriSchemePlugin } from "./uri-schemes/uri-scheme-plugin.d.ts";
4+
import type { DocumentNode, MediaTypePlugin } from "./media-types/media-type-plugin.d.ts";
5+
import { jsonObjectHas, jsonObjectKeys, jsonTypeOf, jsonValue } from "../json/jsonast-util.js";
6+
7+
8+
export type HyperjumpConfig = object;
9+
10+
export type GetOptions = {
11+
referencedFrom?: string;
12+
};
13+
14+
export class Hyperjump {
15+
constructor(config?: HyperjumpConfig);
16+
17+
/**
18+
* Retrieve a document located at the given URI. URIs can be relative if a
19+
* base URI can be determined. On the server-side, the base URI is the CWD. In
20+
* browser, the base URI is the URI of the page.
21+
*
22+
* @see Use {@link Hyperjump.addUriSchemePlugin} to add support for additional
23+
* URI schemes.
24+
* @see Support for {@link JrefMediaTypePlugin | JRef} and
25+
* {@link JsonMediaTypePlugin | JSON} is built in. Use
26+
* {@link Hyperjump.addMediaTypePlugin} to add support for additional media
27+
* types.
28+
*
29+
* @throws {@link RetrievalError}
30+
* @throws {@link json.JsonPointerError}
31+
*/
32+
get: (uri: string, options?: GetOptions) => Promise<JsonCompatible<JrefNode>>;
33+
34+
/**
35+
* Add support for a
36+
* {@link https://www.rfc-editor.org/rfc/rfc3986#section-3.1 | URI scheme}.
37+
* Support for the {@link HttpUriSchemePlugin | `http(s):`} and
38+
* {@link FileUriSchemePlugin | `file:`} URI schemes are enabled by default.
39+
*/
40+
addUriSchemePlugin: (plugin: UriSchemePlugin) => void;
41+
42+
/**
43+
* This is mostly useful for disabling a scheme that's enabled by default.
44+
*/
45+
removeUriSchemePlugin: (scheme: string) => void;
46+
47+
/**
48+
* Unless you're using it in a {@link UriSchemePlugin.retrieve} method, this
49+
* is not the method you're looking for. It's used internally to fetch a
50+
* resource before processing it based on its media type. You might use it for
51+
* implementing {@link hyperjump.UriSchemePlugin}s for URI schemes that don't
52+
* have locating semantics (such as `urn:`) and instead map to another URI
53+
* where the resource can be retrieved from. See the example in the README.
54+
*/
55+
retrieve: (uri: string, options: GetOptions) => Promise<Response>;
56+
57+
/**
58+
* Constructs an `Accept` header based on the registered media types.
59+
*/
60+
acceptableMediaTypes: () => string;
61+
62+
/**
63+
* Returns the media type of the resource based on its URI. This is usually
64+
* based on the extension and configured by {@link hyperjump.MediaTypePlugin}s.
65+
*/
66+
getMediaType: (uri: string) => string;
67+
68+
/**
69+
* Add support for a media tpe. Support for the
70+
* {@link hyperjump.JrefMediaTypePlugin | `JRef`} and
71+
* {@link hyperjump.JsonMediaTypePlugin | `JSON`} media types are enabled by
72+
* default.
73+
*/
74+
addMediaTypePlugin: <T extends DocumentNode>(plugin: MediaTypePlugin<T>) => void;
75+
76+
/**
77+
* This is mostly useful for disabling a scheme that's enabled by default.
78+
*/
79+
removeMediaTypePlugin: (contentType: string) => void;
80+
81+
/**
82+
* Set the
83+
* {@link https://developer.mozilla.org/en-US/docs/Glossary/Quality_values | quality}
84+
* that will be used in the Accept header of requests to indicate to servers
85+
* which media types are preferred over others.
86+
*/
87+
setMediaTypeQuality: (contentType: string, quality: number) => void;
88+
89+
value: typeof jsonValue;
90+
typeOf: typeof jsonTypeOf;
91+
has: typeof jsonObjectHas;
92+
93+
/**
94+
* This is like indexing into an object or array. It will follow any
95+
* references it encounters so it always returns a JSON compatible value.
96+
*/
97+
step: (key: string, node: JsonCompatible<JrefNode>) => Promise<JsonCompatible<JrefNode>>;
98+
99+
/**
100+
* Iterate over an array node. It will follow any references it encounters so
101+
* it always yields JSON compatible values.
102+
*/
103+
iter: (node: JsonCompatible<JrefNode>) => AsyncGenerator<JsonCompatible<JrefNode>, void, unknown>;
104+
105+
keys: typeof jsonObjectKeys;
106+
107+
/**
108+
* Iterate over the values of an object. It will follow any references it
109+
* encounters so it always yields JSON compatible values.
110+
*/
111+
values: (node: JsonCompatible<JrefNode>) => AsyncGenerator<JsonCompatible<JrefNode>, void, unknown>;
112+
113+
/**
114+
* Iterate over key/value pairs of an object. It will follow any references it
115+
* encounters so it always yields JSON compatible values.
116+
*/
117+
entries: (node: JsonCompatible<JrefNode>) => AsyncGenerator<[string, JsonCompatible<JrefNode>], void, unknown>;
118+
}
119+
120+
export class RetrievalError extends Error {
121+
constructor(message: string, options: { cause: unknown });
122+
}
123+
124+
export class UnsupportedUriSchemeError extends Error {
125+
constructor(scheme: string, message?: string);
126+
}
127+
128+
export class UnsupportedMediaTypeError extends Error {
129+
mediaType: string;
130+
131+
constructor(mediaType: string, message?: string);
132+
}
133+
134+
export class UnknownMediaTypeError extends Error {
135+
constructor(message?: string);
136+
}

src/hyperjump/hyperjump.js

+16-107
Original file line numberDiff line numberDiff line change
@@ -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

3424
export 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 &nbsp;{@link RetrievalError}
86-
* @throws &nbsp;{@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) {

src/hyperjump/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
*/
44

55
export * from "./hyperjump.js";
6+
export * from "./uri-schemes/uri-scheme-plugin.js"; // eslint-disable-line import/export
67
export * from "./uri-schemes/file-scheme-plugin.js";
78
export * from "./uri-schemes/http-scheme-plugin.js";
9+
export * from "./media-types/media-type-plugin.js"; // eslint-disable-line import/export
810
export * from "./media-types/json-media-type-plugin.js";
911
export * from "./media-types/jref-media-type-plugin.js";

0 commit comments

Comments
 (0)