cargo-json-docs 0.5.0
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/LICENCE +21 -0
- package/dist/errors.d.ts +23 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +26 -0
- package/dist/errors.js.map +1 -0
- package/dist/item.d.ts +100 -0
- package/dist/item.d.ts.map +1 -0
- package/dist/item.js +589 -0
- package/dist/item.js.map +1 -0
- package/dist/json.d.ts +81 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +226 -0
- package/dist/json.js.map +1 -0
- package/dist/lib.d.ts +21 -0
- package/dist/lib.d.ts.map +1 -0
- package/dist/lib.js +36 -0
- package/dist/lib.js.map +1 -0
- package/package.json +26 -0
- package/readme.md +95 -0
- package/src/errors.ts +31 -0
- package/src/item.ts +658 -0
- package/src/json.ts +274 -0
- package/src/lib.ts +30 -0
- package/src/types.d.ts +84 -0
- package/test/item.test.d.ts +2 -0
- package/test/item.test.d.ts.map +1 -0
- package/test/item.test.js +107 -0
- package/test/item.test.js.map +1 -0
- package/test/item.test.ts +128 -0
- package/test/json.test.d.ts +2 -0
- package/test/json.test.d.ts.map +1 -0
- package/test/json.test.js +24 -0
- package/test/json.test.js.map +1 -0
- package/test/json.test.ts +29 -0
- package/test/test_crate/Cargo.lock +74 -0
- package/test/test_crate/Cargo.toml +7 -0
- package/test/test_crate/src/lib.rs +50 -0
- package/test/test_crate/src/module_a.rs +16 -0
- package/test/test_crate/src/module_b/inner_b.rs +10 -0
- package/test/test_crate/src/module_b.rs +1 -0
- package/tsconfig.json +23 -0
package/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Richard Carson
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An error that occurs when resolving an item path.
|
|
3
|
+
*/
|
|
4
|
+
export declare class ResolutionError extends Error {
|
|
5
|
+
/**
|
|
6
|
+
* The last successfully resolved parent path.
|
|
7
|
+
*/
|
|
8
|
+
last_good_parent: string;
|
|
9
|
+
/**
|
|
10
|
+
* The unresolved item name.
|
|
11
|
+
*/
|
|
12
|
+
unresolved: string;
|
|
13
|
+
constructor(last_good_parent: string, unresolved: string);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* An error that occurs when the documentation JSON format is not as expected.
|
|
17
|
+
* Usually means the format has changed for the version of Rust used to generate the docs.
|
|
18
|
+
* Open a GitHub issue if you encounter this error.
|
|
19
|
+
*/
|
|
20
|
+
export declare class CargoFormatError extends Error {
|
|
21
|
+
constructor(message: string);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACtC;;OAEG;IACH,gBAAgB,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;gBAEP,gBAAgB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;CAK3D;AACD;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAG9B"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CargoFormatError = exports.ResolutionError = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* An error that occurs when resolving an item path.
|
|
6
|
+
*/
|
|
7
|
+
class ResolutionError extends Error {
|
|
8
|
+
constructor(last_good_parent, unresolved) {
|
|
9
|
+
super(`${last_good_parent}::${unresolved} does not exist or could not be resolved.`);
|
|
10
|
+
this.last_good_parent = last_good_parent;
|
|
11
|
+
this.unresolved = unresolved;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ResolutionError = ResolutionError;
|
|
15
|
+
/**
|
|
16
|
+
* An error that occurs when the documentation JSON format is not as expected.
|
|
17
|
+
* Usually means the format has changed for the version of Rust used to generate the docs.
|
|
18
|
+
* Open a GitHub issue if you encounter this error.
|
|
19
|
+
*/
|
|
20
|
+
class CargoFormatError extends Error {
|
|
21
|
+
constructor(message) {
|
|
22
|
+
super(`JSON format unrecognized or invalid. Please open a GitHub issue if you see this message.\nDetails: ${message}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.CargoFormatError = CargoFormatError;
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AACA;;GAEG;AACH,MAAa,eAAgB,SAAQ,KAAK;IAWtC,YAAY,gBAAwB,EAAE,UAAkB;QACpD,KAAK,CAAC,GAAG,gBAAgB,KAAK,UAAU,2CAA2C,CAAC,CAAC;QACrF,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IACjC,CAAC;CACJ;AAhBD,0CAgBC;AACD;;;;GAIG;AACH,MAAa,gBAAiB,SAAQ,KAAK;IACvC,YAAY,OAAe;QACvB,KAAK,CAAC,sGAAsG,OAAO,EAAE,CAAC,CAAC;IAC3H,CAAC;CACJ;AAJD,4CAIC"}
|
package/dist/item.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type { IndexEntry, CrateEntry, PathEntry, DocumentedItem, ItemKind } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* A node in the cargo item tree.
|
|
4
|
+
* Used for resolving item paths.
|
|
5
|
+
*/
|
|
6
|
+
declare class CargoItemNode {
|
|
7
|
+
id: number;
|
|
8
|
+
name: string;
|
|
9
|
+
kind: ItemKind;
|
|
10
|
+
parentKind: ItemKind;
|
|
11
|
+
children: Map<string, CargoItemNode>;
|
|
12
|
+
docs_md: string | null;
|
|
13
|
+
/** The full path to this node, populated during tree walks. */
|
|
14
|
+
path: string;
|
|
15
|
+
/** Whether the children of this node have been populated. */
|
|
16
|
+
childrenPopulated: boolean;
|
|
17
|
+
/** If true, start the path over from the given crate */
|
|
18
|
+
shouldJumpToCrate: string | null;
|
|
19
|
+
/** Whether to suppress presence in urls */
|
|
20
|
+
silent: boolean;
|
|
21
|
+
/** Creates a new CargoItemNode. */
|
|
22
|
+
constructor(id: number, name: string, kind: ItemKind, parentKind: ItemKind, path: string, docs_md?: string | null);
|
|
23
|
+
/** Adds a child node. */
|
|
24
|
+
addChild(child: CargoItemNode): void;
|
|
25
|
+
/** Gets a child node by name. */
|
|
26
|
+
childNamed(name: string): CargoItemNode | null;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Parses the cargo JSON documentation format into a clean graph structure.
|
|
30
|
+
*/
|
|
31
|
+
declare class CargoJsonParser {
|
|
32
|
+
index: Map<string, IndexEntry>;
|
|
33
|
+
crates: Map<string, CrateEntry>;
|
|
34
|
+
paths: Map<string, PathEntry>;
|
|
35
|
+
next_id: number;
|
|
36
|
+
lookup_tree: CargoItemNode;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new CrateDocs instance.
|
|
39
|
+
* @param name The name of the crate.
|
|
40
|
+
* @param docs_root The root URL for the crate's documentation.
|
|
41
|
+
* @param source The JSON source. You can get this from DocumentationSource.getJson().
|
|
42
|
+
* @returns A new CrateDocs instance.
|
|
43
|
+
*/
|
|
44
|
+
constructor(name: string, docs_root: string, source: any);
|
|
45
|
+
/** Gets the URL component for a given CargoItemNode. */
|
|
46
|
+
urlComponentEncode(node: CargoItemNode): string;
|
|
47
|
+
/**
|
|
48
|
+
* Searches for a path entry by its path components
|
|
49
|
+
* If nothing is found, invents a module
|
|
50
|
+
*/
|
|
51
|
+
private pathEntryByPath;
|
|
52
|
+
private pathEntry;
|
|
53
|
+
private indexEntryContents;
|
|
54
|
+
/**
|
|
55
|
+
* First we make sure the start is a crate name
|
|
56
|
+
* If not, append the current crate name
|
|
57
|
+
* If 'crate' replaced with current crate name
|
|
58
|
+
* If it's a crate that cannot be a root module only try that crate
|
|
59
|
+
* Else try current crate first, then other one
|
|
60
|
+
* @param path Path to fix
|
|
61
|
+
* @returns All viable candidate paths.
|
|
62
|
+
*/
|
|
63
|
+
private fixPathCrate;
|
|
64
|
+
/** Populates the children of a given CargoItemNode. */
|
|
65
|
+
private populateChildren;
|
|
66
|
+
/**
|
|
67
|
+
* When going through paths, we may come across modules that are not directly represented in the index.
|
|
68
|
+
* This walks up the path to populate missing modules as needed.
|
|
69
|
+
*/
|
|
70
|
+
private populateMissingPathModules;
|
|
71
|
+
/**
|
|
72
|
+
* Walks the item tree to find a node by path.
|
|
73
|
+
* @param path The path to walk.
|
|
74
|
+
* @returns The path to the found CargoItemNode.
|
|
75
|
+
* @throws ResolutionError if the path cannot be resolved.
|
|
76
|
+
*/
|
|
77
|
+
walkTree(path: string[]): CargoItemNode[];
|
|
78
|
+
/** Gets the current crate name. */
|
|
79
|
+
ownCrateName(): string;
|
|
80
|
+
}
|
|
81
|
+
export declare class CrateDocs {
|
|
82
|
+
parser: CargoJsonParser;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a new CrateDocs instance.
|
|
85
|
+
* @param name The name of the crate.
|
|
86
|
+
* @param docs_root The root URL for the crate's documentation.
|
|
87
|
+
* @param source The JSON source. You can get this from DocumentationSource.getJson().
|
|
88
|
+
* @returns A new CrateDocs instance.
|
|
89
|
+
*/
|
|
90
|
+
constructor(name: string, docs_root: string, source: any);
|
|
91
|
+
/**
|
|
92
|
+
* Gets a documented item by its path.
|
|
93
|
+
* @param path The item path, e.g., "crate::module::Item" or "Item".
|
|
94
|
+
* @returns The documented item.
|
|
95
|
+
* @throws ResolutionError if the item cannot be found.
|
|
96
|
+
*/
|
|
97
|
+
get(path: string): DocumentedItem;
|
|
98
|
+
}
|
|
99
|
+
export {};
|
|
100
|
+
//# sourceMappingURL=item.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item.d.ts","sourceRoot":"","sources":["../src/item.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAER,UAAU,EAAE,UAAU,EAAE,SAAS,EACjC,cAAc,EAAE,QAAQ,EAC3B,MAAM,SAAS,CAAC;AAEjB;;;GAGG;AACH,cAAM,aAAa;IACf,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,EAAE,QAAQ,CAAC;I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