@aeye/resources 0.3.9 → 0.7.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/aeye-resources-converters.md +191 -0
- package/aeye-resources-graph.md +61 -7
- package/aeye-resources-parsers.md +40 -13
- package/aeye-resources-slicers.md +76 -8
- package/aeye-resources.md +24 -9
- package/dist/converters/data.d.ts +9 -0
- package/dist/converters/data.d.ts.map +1 -0
- package/dist/converters/data.js +78 -0
- package/dist/converters/data.js.map +1 -0
- package/dist/converters/folder.d.ts +13 -0
- package/dist/converters/folder.d.ts.map +1 -0
- package/dist/converters/folder.js +63 -0
- package/dist/converters/folder.js.map +1 -0
- package/dist/converters/index.d.ts +9 -0
- package/dist/converters/index.d.ts.map +1 -0
- package/dist/converters/index.js +22 -0
- package/dist/converters/index.js.map +1 -0
- package/dist/converters/markup.d.ts +6 -0
- package/dist/converters/markup.d.ts.map +1 -0
- package/dist/converters/markup.js +59 -0
- package/dist/converters/markup.js.map +1 -0
- package/dist/converters/pdf.d.ts +6 -0
- package/dist/converters/pdf.d.ts.map +1 -0
- package/dist/converters/pdf.js +70 -0
- package/dist/converters/pdf.js.map +1 -0
- package/dist/converters/tables.d.ts +12 -0
- package/dist/converters/tables.d.ts.map +1 -0
- package/dist/converters/tables.js +64 -0
- package/dist/converters/tables.js.map +1 -0
- package/dist/default.d.ts +9 -5
- package/dist/default.d.ts.map +1 -1
- package/dist/default.js +23 -8
- package/dist/default.js.map +1 -1
- package/dist/graph.d.ts +64 -6
- package/dist/graph.d.ts.map +1 -1
- package/dist/graph.js +127 -32
- package/dist/graph.js.map +1 -1
- package/dist/html/dom.d.ts +31 -0
- package/dist/html/dom.d.ts.map +1 -0
- package/dist/html/dom.js +194 -0
- package/dist/html/dom.js.map +1 -0
- package/dist/html/entities.d.ts +3 -0
- package/dist/html/entities.d.ts.map +1 -0
- package/dist/html/entities.js +33 -0
- package/dist/html/entities.js.map +1 -0
- package/dist/html/markdown.d.ts +30 -0
- package/dist/html/markdown.d.ts.map +1 -0
- package/dist/html/markdown.js +429 -0
- package/dist/html/markdown.js.map +1 -0
- package/dist/http/index.d.ts +5 -0
- package/dist/http/index.d.ts.map +1 -0
- package/dist/http/index.js +3 -0
- package/dist/http/index.js.map +1 -0
- package/dist/http/loader.d.ts +74 -0
- package/dist/http/loader.d.ts.map +1 -0
- package/dist/http/loader.js +248 -0
- package/dist/http/loader.js.map +1 -0
- package/dist/http/sniff.d.ts +38 -0
- package/dist/http/sniff.d.ts.map +1 -0
- package/dist/http/sniff.js +131 -0
- package/dist/http/sniff.js.map +1 -0
- package/dist/imports.d.ts +29 -0
- package/dist/imports.d.ts.map +1 -0
- package/dist/imports.js +53 -0
- package/dist/imports.js.map +1 -0
- package/dist/index.d.ts +28 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -6
- package/dist/index.js.map +1 -1
- package/dist/optional.d.ts +9 -0
- package/dist/optional.d.ts.map +1 -0
- package/dist/optional.js +17 -0
- package/dist/optional.js.map +1 -0
- package/dist/parsers/code.d.ts +1 -1
- package/dist/parsers/code.d.ts.map +1 -1
- package/dist/parsers/code.js +2 -2
- package/dist/parsers/code.js.map +1 -1
- package/dist/parsers/convert.d.ts +8 -0
- package/dist/parsers/convert.d.ts.map +1 -0
- package/dist/parsers/convert.js +40 -0
- package/dist/parsers/convert.js.map +1 -0
- package/dist/parsers/data.d.ts +8 -0
- package/dist/parsers/data.d.ts.map +1 -0
- package/dist/parsers/data.js +20 -0
- package/dist/parsers/data.js.map +1 -0
- package/dist/parsers/docx.d.ts +2 -2
- package/dist/parsers/docx.d.ts.map +1 -1
- package/dist/parsers/docx.js +9 -68
- package/dist/parsers/docx.js.map +1 -1
- package/dist/parsers/excel.d.ts +4 -1
- package/dist/parsers/excel.d.ts.map +1 -1
- package/dist/parsers/excel.js +17 -136
- package/dist/parsers/excel.js.map +1 -1
- package/dist/parsers/folder.d.ts +3 -0
- package/dist/parsers/folder.d.ts.map +1 -0
- package/dist/parsers/folder.js +21 -0
- package/dist/parsers/folder.js.map +1 -0
- package/dist/parsers/html.d.ts +5 -2
- package/dist/parsers/html.d.ts.map +1 -1
- package/dist/parsers/html.js +11 -33
- package/dist/parsers/html.js.map +1 -1
- package/dist/parsers/image.d.ts +1 -1
- package/dist/parsers/image.d.ts.map +1 -1
- package/dist/parsers/image.js +2 -2
- package/dist/parsers/image.js.map +1 -1
- package/dist/parsers/index.d.ts +13 -9
- package/dist/parsers/index.d.ts.map +1 -1
- package/dist/parsers/index.js +12 -9
- package/dist/parsers/index.js.map +1 -1
- package/dist/parsers/markdown.d.ts +1 -1
- package/dist/parsers/markdown.d.ts.map +1 -1
- package/dist/parsers/markdown.js +2 -2
- package/dist/parsers/markdown.js.map +1 -1
- package/dist/parsers/pdf.d.ts +2 -2
- package/dist/parsers/pdf.d.ts.map +1 -1
- package/dist/parsers/pdf.js +99 -119
- package/dist/parsers/pdf.js.map +1 -1
- package/dist/parsers/text.d.ts +1 -1
- package/dist/parsers/text.d.ts.map +1 -1
- package/dist/parsers/text.js +2 -2
- package/dist/parsers/text.js.map +1 -1
- package/dist/parsers/version.d.ts +42 -0
- package/dist/parsers/version.d.ts.map +1 -0
- package/dist/parsers/version.js +100 -0
- package/dist/parsers/version.js.map +1 -0
- package/dist/parsers/zip.d.ts +1 -1
- package/dist/parsers/zip.d.ts.map +1 -1
- package/dist/parsers/zip.js +12 -5
- package/dist/parsers/zip.js.map +1 -1
- package/dist/registry.d.ts +46 -3
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +97 -39
- package/dist/registry.js.map +1 -1
- package/dist/renderers/index.d.ts +2 -2
- package/dist/renderers/index.d.ts.map +1 -1
- package/dist/renderers/index.js +1 -1
- package/dist/renderers/index.js.map +1 -1
- package/dist/renderers/poppler.d.ts +1 -1
- package/dist/renderers/poppler.d.ts.map +1 -1
- package/dist/renderers/poppler.js +1 -1
- package/dist/renderers/poppler.js.map +1 -1
- package/dist/resolvers/file.d.ts +7 -1
- package/dist/resolvers/file.d.ts.map +1 -1
- package/dist/resolvers/file.js +26 -6
- package/dist/resolvers/file.js.map +1 -1
- package/dist/resolvers/folder.d.ts +18 -0
- package/dist/resolvers/folder.d.ts.map +1 -0
- package/dist/resolvers/folder.js +89 -0
- package/dist/resolvers/folder.js.map +1 -0
- package/dist/resolvers/index.d.ts +4 -3
- package/dist/resolvers/index.d.ts.map +1 -1
- package/dist/resolvers/index.js +4 -3
- package/dist/resolvers/index.js.map +1 -1
- package/dist/resolvers/url.d.ts +5 -1
- package/dist/resolvers/url.d.ts.map +1 -1
- package/dist/resolvers/url.js +13 -74
- package/dist/resolvers/url.js.map +1 -1
- package/dist/resolvers/zip.d.ts +1 -1
- package/dist/resolvers/zip.d.ts.map +1 -1
- package/dist/resolvers/zip.js +2 -2
- package/dist/resolvers/zip.js.map +1 -1
- package/dist/section-keys.d.ts +16 -0
- package/dist/section-keys.d.ts.map +1 -0
- package/dist/section-keys.js +24 -0
- package/dist/section-keys.js.map +1 -0
- package/dist/sections.d.ts +39 -0
- package/dist/sections.d.ts.map +1 -0
- package/dist/sections.js +118 -0
- package/dist/sections.js.map +1 -0
- package/dist/segmenters/default.d.ts +1 -1
- package/dist/segmenters/default.d.ts.map +1 -1
- package/dist/segmenters/default.js +1 -1
- package/dist/segmenters/default.js.map +1 -1
- package/dist/segmenters/index.d.ts +3 -3
- package/dist/segmenters/index.d.ts.map +1 -1
- package/dist/segmenters/index.js +2 -2
- package/dist/segmenters/index.js.map +1 -1
- package/dist/segmenters/langchain.d.ts +1 -1
- package/dist/segmenters/langchain.d.ts.map +1 -1
- package/dist/segmenters/langchain.js +1 -1
- package/dist/segmenters/langchain.js.map +1 -1
- package/dist/slicers/code.d.ts +30 -1
- package/dist/slicers/code.d.ts.map +1 -1
- package/dist/slicers/code.js +118 -32
- package/dist/slicers/code.js.map +1 -1
- package/dist/slicers/index.d.ts +3 -3
- package/dist/slicers/index.d.ts.map +1 -1
- package/dist/slicers/index.js +3 -3
- package/dist/slicers/index.js.map +1 -1
- package/dist/slicers/markdown.d.ts +15 -1
- package/dist/slicers/markdown.d.ts.map +1 -1
- package/dist/slicers/markdown.js +56 -27
- package/dist/slicers/markdown.js.map +1 -1
- package/dist/slicers/text.d.ts +1 -1
- package/dist/slicers/text.d.ts.map +1 -1
- package/dist/slicers/text.js +6 -4
- package/dist/slicers/text.js.map +1 -1
- package/dist/stack.d.ts +41 -0
- package/dist/stack.d.ts.map +1 -0
- package/dist/stack.js +56 -0
- package/dist/stack.js.map +1 -0
- package/dist/summaries.d.ts +11 -0
- package/dist/summaries.d.ts.map +1 -0
- package/dist/summaries.js +131 -0
- package/dist/summaries.js.map +1 -0
- package/dist/tables.d.ts +21 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +113 -0
- package/dist/tables.js.map +1 -0
- package/dist/types.d.ts +140 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/utils.d.ts +59 -3
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +149 -159
- package/dist/utils.js.map +1 -1
- package/dist/versions.d.ts +207 -0
- package/dist/versions.d.ts.map +1 -0
- package/dist/versions.js +217 -0
- package/dist/versions.js.map +1 -0
- package/dist/zip-internal.d.ts +9 -4
- package/dist/zip-internal.d.ts.map +1 -1
- package/dist/zip-internal.js +45 -19
- package/dist/zip-internal.js.map +1 -1
- package/package.json +33 -3
package/dist/graph.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { ResourceRegistry } from "./registry";
|
|
2
|
-
import type { LoadResourceOptions, ParsedResource, ResourceLink, ResourceLocation, ResourceSlice, ResourceSource } from "./types";
|
|
1
|
+
import type { ResourceRegistry } from "./registry.js";
|
|
2
|
+
import type { LoadResourceOptions, ParsedResource, ResourceLink, ResourceLocation, ResourceSlice, ResourceSource } from "./types.js";
|
|
3
|
+
/** Default cap on graph size, so a crawl can't run away. Pass `Infinity` to lift it. */
|
|
4
|
+
export declare const DEFAULT_GRAPH_MAX_RESOURCES = 1000;
|
|
5
|
+
/** Default number of link targets loaded at once. */
|
|
6
|
+
export declare const DEFAULT_GRAPH_CONCURRENCY = 4;
|
|
3
7
|
/** Why a link's target was not loaded into the graph. */
|
|
4
|
-
export type GraphEdgeSkipReason = "external" | "resource-links-disabled" | "filtered" | "unresolved" | "max-depth" | "max-resources" | "skipped" | "error";
|
|
8
|
+
export type GraphEdgeSkipReason = "external" | "resource-links-disabled" | "filtered" | "cross-origin" | "unresolved" | "max-depth" | "max-resources" | "skipped" | "error";
|
|
5
9
|
export interface ResourceGraphEdge {
|
|
6
10
|
/** The originating link. */
|
|
7
11
|
link: ResourceLink;
|
|
@@ -16,6 +20,28 @@ export interface ResourceGraphEdge {
|
|
|
16
20
|
/** Error message when `reason` is "error". */
|
|
17
21
|
error?: string;
|
|
18
22
|
}
|
|
23
|
+
/** What fetching a web node found out (http(s) nodes only). */
|
|
24
|
+
export interface GraphNodeFetch {
|
|
25
|
+
/** The URL that was asked for. */
|
|
26
|
+
requestedUrl: string;
|
|
27
|
+
/** The URL the content came from, after redirects and a renderer's navigation (the node's `location`). */
|
|
28
|
+
url: string;
|
|
29
|
+
/** The response's status. */
|
|
30
|
+
status: number;
|
|
31
|
+
/** Whether a page renderer ran the page's scripts before it was parsed. */
|
|
32
|
+
rendered: boolean;
|
|
33
|
+
/** The renderer that ran the page, when one did. */
|
|
34
|
+
renderedBy?: string;
|
|
35
|
+
/** Why rendering failed, when it was tried and failed (the fetched html was parsed instead). */
|
|
36
|
+
renderError?: string;
|
|
37
|
+
}
|
|
38
|
+
/** What a stored node's bytes are, passed to {@link BuildGraphOptions.keepBytes} when it is a function. */
|
|
39
|
+
export interface GraphNodeBytes {
|
|
40
|
+
location: ResourceLocation;
|
|
41
|
+
type: string;
|
|
42
|
+
mimeType?: string;
|
|
43
|
+
bytes: Uint8Array;
|
|
44
|
+
}
|
|
19
45
|
export interface ResourceGraphNode {
|
|
20
46
|
id: string;
|
|
21
47
|
location: ResourceLocation;
|
|
@@ -25,11 +51,17 @@ export interface ResourceGraphNode {
|
|
|
25
51
|
/** Estimated last-modified time of the underlying source, in epoch milliseconds, if known. */
|
|
26
52
|
modifiedAt?: number;
|
|
27
53
|
resource: ParsedResource;
|
|
54
|
+
/** What the fetch found out, for nodes fetched over http(s) (not for reused or child nodes). */
|
|
55
|
+
fetch?: GraphNodeFetch;
|
|
56
|
+
/** The raw bytes the resource was parsed from, with `keepBytes: true` (not for reused or child nodes). */
|
|
57
|
+
bytes?: Uint8Array;
|
|
58
|
+
/** The ref `keepBytes` returned when it stored the raw bytes itself (not for reused or child nodes). */
|
|
59
|
+
contentRef?: string;
|
|
28
60
|
/** Slices for this resource, if `includeSlices` was enabled. */
|
|
29
61
|
slices?: ResourceSlice[];
|
|
30
62
|
/** True when the resource was reused from the caller's cache rather than freshly parsed. */
|
|
31
63
|
reused: boolean;
|
|
32
|
-
/** Outgoing link edges. */
|
|
64
|
+
/** Outgoing link edges, in the order the links appear in the resource. */
|
|
33
65
|
edges: ResourceGraphEdge[];
|
|
34
66
|
/** Locations of child resources (e.g. zip entries, rendered PDF pages) contained by this node. */
|
|
35
67
|
children: ResourceLocation[];
|
|
@@ -52,14 +84,36 @@ export interface GraphTarget {
|
|
|
52
84
|
export interface BuildGraphOptions extends LoadResourceOptions {
|
|
53
85
|
/** Maximum link/child distance from a root to traverse. Defaults to unlimited. */
|
|
54
86
|
maxDepth?: number;
|
|
55
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Maximum number of nodes to load. Defaults to {@link DEFAULT_GRAPH_MAX_RESOURCES} (1000); pass
|
|
89
|
+
* `Infinity` for no cap. Existing nodes are never re-counted.
|
|
90
|
+
*/
|
|
56
91
|
maxResources?: number;
|
|
92
|
+
/** How many link targets to probe/load at once. Defaults to {@link DEFAULT_GRAPH_CONCURRENCY} (4). */
|
|
93
|
+
concurrency?: number;
|
|
57
94
|
/** Traverse child resources (zip entries, rendered PDF pages, …) as nodes. Defaults to true. */
|
|
58
95
|
followChildren?: boolean;
|
|
59
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Follow external links (e.g. http links from a local file, or links to another site). Defaults to
|
|
98
|
+
* false. Links between pages of the same site are not external; they follow with
|
|
99
|
+
* {@link BuildGraphOptions.followResourceLinks}.
|
|
100
|
+
*/
|
|
60
101
|
followExternal?: boolean;
|
|
61
102
|
/** Follow internal/relative resource links. Defaults to true. */
|
|
62
103
|
followResourceLinks?: boolean;
|
|
104
|
+
/**
|
|
105
|
+
* Keep web crawling on one site: a link found on a web page is only followed when it points to the
|
|
106
|
+
* same origin. Links from non-web resources (local files, zips) to the web are not affected, so a
|
|
107
|
+
* local doc can still reach the pages it links to, which then stay on their own site. Only matters
|
|
108
|
+
* with `followExternal`. Defaults to true.
|
|
109
|
+
*/
|
|
110
|
+
sameOrigin?: boolean;
|
|
111
|
+
/**
|
|
112
|
+
* Keep each loaded node's raw bytes (what was fetched or read, before parsing). `true` puts them on
|
|
113
|
+
* {@link ResourceGraphNode.bytes}; a function stores them and the ref it returns goes on
|
|
114
|
+
* {@link ResourceGraphNode.contentRef}, so a big crawl does not hold every page in memory. Defaults to false.
|
|
115
|
+
*/
|
|
116
|
+
keepBytes?: boolean | ((bytes: GraphNodeBytes) => Promise<string>);
|
|
63
117
|
/** Also slice each loaded resource and attach the slices to its node. Defaults to false. */
|
|
64
118
|
includeSlices?: boolean;
|
|
65
119
|
/** Per-link filter; return false to skip following a link. */
|
|
@@ -86,6 +140,10 @@ export interface BuildGraphOptions extends LoadResourceOptions {
|
|
|
86
140
|
* each canonical location is loaded at most once, so cycles and shared references are handled and the
|
|
87
141
|
* traversal terminates even on infinitely cross-referencing content.
|
|
88
142
|
*
|
|
143
|
+
* The graph is walked one depth level at a time, with up to {@link BuildGraphOptions.concurrency}
|
|
144
|
+
* targets loading at once, so each node's `depth` is its true shortest distance from a root. Node
|
|
145
|
+
* insertion order in `nodes` may vary between runs when concurrency is above 1.
|
|
146
|
+
*
|
|
89
147
|
* Pass {@link BuildGraphOptions.shouldLoad} + {@link BuildGraphOptions.getCached} to perform
|
|
90
148
|
* incremental rebuilds against a target system, using each resource's `modifiedAt` to detect staleness.
|
|
91
149
|
*/
|
package/dist/graph.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,KAAK,EACV,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,cAAc,EACf,MAAM,YAAY,CAAC;AAIpB,wFAAwF;AACxF,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAChD,qDAAqD;AACrD,eAAO,MAAM,yBAAyB,IAAI,CAAC;AAE3C,yDAAyD;AACzD,MAAM,MAAM,mBAAmB,GAC3B,UAAU,GACV,yBAAyB,GACzB,UAAU,GACV,cAAc,GACd,YAAY,GACZ,WAAW,GACX,eAAe,GACf,SAAS,GACT,OAAO,CAAC;AAEZ,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,IAAI,EAAE,YAAY,CAAC;IACnB,4EAA4E;IAC5E,cAAc,CAAC,EAAE,gBAAgB,CAAC;IAClC,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,4DAA4D;IAC5D,MAAM,EAAE,OAAO,CAAC;IAChB,uEAAuE;IACvE,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,8CAA8C;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,+DAA+D;AAC/D,MAAM,WAAW,cAAc;IAC7B,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,0GAA0G;IAC1G,GAA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B,CACtC,QAAQ,EAAE,gBAAgB,EAC1B,MAAM,EAAE,MAAM,GAAG,cAAc,GAAG,KAAK,CAAC,MAAM,GAAG,cAAc,CAAC,EAChE,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,aAAa,CAAC,CAmOxB"}
|
package/dist/graph.js
CHANGED
|
@@ -1,28 +1,52 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createLimiter } from "./summaries.js";
|
|
2
|
+
import { assertNotAborted, collectInput, isHttpUrl, resolveAgainstUrl } from "./utils.js";
|
|
3
|
+
/** Default cap on graph size, so a crawl can't run away. Pass `Infinity` to lift it. */
|
|
4
|
+
export const DEFAULT_GRAPH_MAX_RESOURCES = 1000;
|
|
5
|
+
/** Default number of link targets loaded at once. */
|
|
6
|
+
export const DEFAULT_GRAPH_CONCURRENCY = 4;
|
|
2
7
|
/**
|
|
3
8
|
* Builds a graph of resources and the links between them, starting from one or more roots, by loading
|
|
4
9
|
* each link target as a resource and recursing into its links and children. Effort is de-duplicated:
|
|
5
10
|
* each canonical location is loaded at most once, so cycles and shared references are handled and the
|
|
6
11
|
* traversal terminates even on infinitely cross-referencing content.
|
|
7
12
|
*
|
|
13
|
+
* The graph is walked one depth level at a time, with up to {@link BuildGraphOptions.concurrency}
|
|
14
|
+
* targets loading at once, so each node's `depth` is its true shortest distance from a root. Node
|
|
15
|
+
* insertion order in `nodes` may vary between runs when concurrency is above 1.
|
|
16
|
+
*
|
|
8
17
|
* Pass {@link BuildGraphOptions.shouldLoad} + {@link BuildGraphOptions.getCached} to perform
|
|
9
18
|
* incremental rebuilds against a target system, using each resource's `modifiedAt` to detect staleness.
|
|
10
19
|
*/
|
|
11
20
|
export async function buildResourceGraph(registry, inputs, options = {}) {
|
|
12
21
|
const maxDepth = options.maxDepth ?? Number.POSITIVE_INFINITY;
|
|
13
|
-
const maxResources = options.maxResources ??
|
|
22
|
+
const maxResources = options.maxResources ?? DEFAULT_GRAPH_MAX_RESOURCES;
|
|
14
23
|
const followChildren = options.followChildren ?? true;
|
|
15
|
-
const followExternal = options.followExternal ??
|
|
24
|
+
const followExternal = options.followExternal ?? false;
|
|
16
25
|
const followResourceLinks = options.followResourceLinks ?? true;
|
|
26
|
+
const sameOrigin = options.sameOrigin ?? true;
|
|
27
|
+
const limit = createLimiter(options.concurrency ?? DEFAULT_GRAPH_CONCURRENCY);
|
|
17
28
|
const nodes = new Map();
|
|
18
29
|
const roots = [];
|
|
19
|
-
|
|
30
|
+
/** Targets being loaded right now, so concurrent links to the same target share one load. */
|
|
31
|
+
const pending = new Map();
|
|
32
|
+
let discovered = [];
|
|
33
|
+
const isFull = () => nodes.size + pending.size >= maxResources;
|
|
20
34
|
const addParent = (node, parent) => {
|
|
21
35
|
if (parent !== node.location && !node.parents.includes(parent)) {
|
|
22
36
|
node.parents.push(parent);
|
|
23
37
|
}
|
|
24
38
|
};
|
|
25
|
-
|
|
39
|
+
/** Resolves and parses one input, keeping its bytes first when `keepBytes` asks for them. */
|
|
40
|
+
const loadInput = async (input, loadOptions) => {
|
|
41
|
+
if (!options.keepBytes) {
|
|
42
|
+
return registry.parse(input, loadOptions);
|
|
43
|
+
}
|
|
44
|
+
const resolved = typeof input === "string" ? await registry.resolveLink(input, loadOptions) : input;
|
|
45
|
+
const bytes = await collectInput(resolved.input);
|
|
46
|
+
const { source, resource } = await registry.parse({ ...resolved, input: bytes }, loadOptions);
|
|
47
|
+
return { source, resource, bytes };
|
|
48
|
+
};
|
|
49
|
+
const registerNode = async (resource, depth, reused, loaded) => {
|
|
26
50
|
const existing = nodes.get(resource.location);
|
|
27
51
|
if (existing) {
|
|
28
52
|
existing.depth = Math.min(existing.depth, depth);
|
|
@@ -40,35 +64,55 @@ export async function buildResourceGraph(registry, inputs, options = {}) {
|
|
|
40
64
|
children: [],
|
|
41
65
|
parents: [],
|
|
42
66
|
};
|
|
67
|
+
const fetched = loaded ? fetchOf(loaded.source) : undefined;
|
|
68
|
+
if (fetched)
|
|
69
|
+
node.fetch = fetched;
|
|
70
|
+
// Claim the location before any await so concurrent loads see it.
|
|
71
|
+
nodes.set(node.location, node);
|
|
72
|
+
discovered.push(node);
|
|
73
|
+
if (loaded?.bytes) {
|
|
74
|
+
if (typeof options.keepBytes === "function") {
|
|
75
|
+
node.contentRef = await options.keepBytes({ location: node.location, type: node.type, ...(resource.mimeType !== undefined ? { mimeType: resource.mimeType } : {}), bytes: loaded.bytes });
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
node.bytes = loaded.bytes;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
43
81
|
if (options.includeSlices) {
|
|
44
82
|
node.slices = await registry.slice(resource, options);
|
|
45
83
|
}
|
|
46
|
-
nodes.set(node.location, node);
|
|
47
84
|
options.onNode?.(node);
|
|
48
|
-
queue.push(node.location);
|
|
49
85
|
return node;
|
|
50
86
|
};
|
|
51
|
-
// Seed roots.
|
|
87
|
+
// Seed roots (loaded concurrently, kept in input order).
|
|
52
88
|
const rootInputs = Array.isArray(inputs) ? inputs : [inputs];
|
|
53
|
-
|
|
89
|
+
const rootNodes = await Promise.all(rootInputs.map((input) => limit(async () => {
|
|
54
90
|
assertNotAborted(options.signal);
|
|
55
|
-
const
|
|
56
|
-
|
|
91
|
+
const loaded = await loadInput(input, options);
|
|
92
|
+
return registerNode(loaded.resource, 0, false, loaded);
|
|
93
|
+
})));
|
|
94
|
+
for (const node of rootNodes) {
|
|
57
95
|
if (!roots.includes(node.location)) {
|
|
58
96
|
roots.push(node.location);
|
|
59
97
|
}
|
|
60
98
|
}
|
|
61
|
-
// Breadth-first expansion.
|
|
62
|
-
|
|
99
|
+
// Breadth-first expansion, one depth level per wave.
|
|
100
|
+
let frontier = discovered;
|
|
101
|
+
discovered = [];
|
|
102
|
+
while (frontier.length > 0) {
|
|
63
103
|
assertNotAborted(options.signal);
|
|
64
|
-
|
|
65
|
-
|
|
104
|
+
await Promise.all(frontier.map((node) => expand(node)));
|
|
105
|
+
frontier = discovered;
|
|
106
|
+
discovered = [];
|
|
107
|
+
}
|
|
108
|
+
return { roots, nodes };
|
|
109
|
+
async function expand(node) {
|
|
66
110
|
if (node.depth >= maxDepth) {
|
|
67
|
-
|
|
111
|
+
return;
|
|
68
112
|
}
|
|
69
113
|
if (followChildren) {
|
|
70
114
|
for (const child of node.resource.children ?? []) {
|
|
71
|
-
if (!nodes.has(child.location) &&
|
|
115
|
+
if (!nodes.has(child.location) && isFull()) {
|
|
72
116
|
continue;
|
|
73
117
|
}
|
|
74
118
|
const childNode = await registerNode(child, node.depth + 1, false);
|
|
@@ -78,20 +122,37 @@ export async function buildResourceGraph(registry, inputs, options = {}) {
|
|
|
78
122
|
}
|
|
79
123
|
}
|
|
80
124
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
125
|
+
node.edges = await Promise.all(node.resource.links.map((link) => limit(() => followLink(link, node))));
|
|
126
|
+
}
|
|
127
|
+
/** The absolute http(s) URL a link points to, if it is a web link. */
|
|
128
|
+
function webTarget(link, from) {
|
|
129
|
+
try {
|
|
130
|
+
if (isHttpUrl(link.value))
|
|
131
|
+
return new URL(link.value);
|
|
132
|
+
if (isHttpUrl(from.location))
|
|
133
|
+
return new URL(resolveAgainstUrl(link.value, from.location));
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
// Not a valid URL.
|
|
84
137
|
}
|
|
138
|
+
return undefined;
|
|
85
139
|
}
|
|
86
|
-
return { roots, nodes };
|
|
87
140
|
async function followLink(link, from) {
|
|
88
|
-
|
|
141
|
+
assertNotAborted(options.signal);
|
|
142
|
+
const target = webTarget(link, from);
|
|
143
|
+
const fromWeb = isHttpUrl(from.location);
|
|
144
|
+
const crossOrigin = Boolean(target && fromWeb && target.origin !== new URL(from.location).origin);
|
|
145
|
+
// A link to another page of the same site is internal, however it is spelled.
|
|
146
|
+
const isExternal = link.kind === "external" && !(target && fromWeb && !crossOrigin);
|
|
89
147
|
if (isExternal && !followExternal) {
|
|
90
148
|
return { link, loaded: false, reason: "external" };
|
|
91
149
|
}
|
|
92
150
|
if (!isExternal && !followResourceLinks) {
|
|
93
151
|
return { link, loaded: false, reason: "resource-links-disabled" };
|
|
94
152
|
}
|
|
153
|
+
if (crossOrigin && sameOrigin) {
|
|
154
|
+
return { link, loaded: false, reason: "cross-origin", targetLocation: target?.toString() };
|
|
155
|
+
}
|
|
95
156
|
if (options.shouldFollow && !options.shouldFollow(link, from)) {
|
|
96
157
|
return { link, loaded: false, reason: "filtered" };
|
|
97
158
|
}
|
|
@@ -103,11 +164,20 @@ export async function buildResourceGraph(registry, inputs, options = {}) {
|
|
|
103
164
|
// Probe the canonical location (and modified time) cheaply for de-duplication / incrementality.
|
|
104
165
|
const stat = await registry.statLink(link.value, linkOptions).catch(() => undefined);
|
|
105
166
|
const probedLocation = stat?.location;
|
|
167
|
+
const connect = (node) => {
|
|
168
|
+
addParent(node, from.location);
|
|
169
|
+
return { link, loaded: true, targetLocation: node.location, targetId: node.id };
|
|
170
|
+
};
|
|
106
171
|
if (probedLocation) {
|
|
107
172
|
const known = nodes.get(probedLocation);
|
|
108
173
|
if (known) {
|
|
109
|
-
|
|
110
|
-
|
|
174
|
+
return connect(known);
|
|
175
|
+
}
|
|
176
|
+
const inFlight = pending.get(probedLocation);
|
|
177
|
+
if (inFlight) {
|
|
178
|
+
const node = await inFlight.catch(() => undefined);
|
|
179
|
+
if (node)
|
|
180
|
+
return connect(node);
|
|
111
181
|
}
|
|
112
182
|
}
|
|
113
183
|
if (targetDepth > maxDepth) {
|
|
@@ -124,23 +194,28 @@ export async function buildResourceGraph(registry, inputs, options = {}) {
|
|
|
124
194
|
if (!shouldLoad) {
|
|
125
195
|
const cached = options.getCached?.(probedLocation ?? link.value, stat?.modifiedAt);
|
|
126
196
|
if (cached) {
|
|
127
|
-
|
|
128
|
-
addParent(node, from.location);
|
|
129
|
-
return { link, loaded: true, targetLocation: node.location, targetId: node.id };
|
|
197
|
+
return connect(await registerNode(cached, targetDepth, true));
|
|
130
198
|
}
|
|
131
199
|
return { link, loaded: false, reason: "skipped", targetLocation: probedLocation };
|
|
132
200
|
}
|
|
133
201
|
}
|
|
134
|
-
if (
|
|
202
|
+
if (isFull()) {
|
|
135
203
|
return { link, loaded: false, reason: "max-resources", targetLocation: probedLocation };
|
|
136
204
|
}
|
|
205
|
+
// Without a probed location the load can't be shared; key it uniquely so it still counts as pending.
|
|
206
|
+
const key = probedLocation ?? `\0link:${from.location}:${link.id}`;
|
|
207
|
+
const load = (async () => {
|
|
208
|
+
const loaded = await loadInput(link.value, linkOptions);
|
|
209
|
+
// registerNode claims the location synchronously, so the node takes over from the reservation.
|
|
210
|
+
pending.delete(key);
|
|
211
|
+
return registerNode(loaded.resource, targetDepth, false, loaded);
|
|
212
|
+
})();
|
|
213
|
+
pending.set(key, load);
|
|
137
214
|
try {
|
|
138
|
-
|
|
139
|
-
const node = await registerNode(resource, targetDepth, false);
|
|
140
|
-
addParent(node, from.location);
|
|
141
|
-
return { link, loaded: true, targetLocation: node.location, targetId: node.id };
|
|
215
|
+
return connect(await load);
|
|
142
216
|
}
|
|
143
217
|
catch (error) {
|
|
218
|
+
assertNotAborted(options.signal);
|
|
144
219
|
return {
|
|
145
220
|
link,
|
|
146
221
|
loaded: false,
|
|
@@ -149,6 +224,26 @@ export async function buildResourceGraph(registry, inputs, options = {}) {
|
|
|
149
224
|
targetLocation: probedLocation,
|
|
150
225
|
};
|
|
151
226
|
}
|
|
227
|
+
finally {
|
|
228
|
+
pending.delete(key);
|
|
229
|
+
}
|
|
152
230
|
}
|
|
153
231
|
}
|
|
232
|
+
/** The fetch facts the url resolver records in a web source's metadata, when the source came from http(s). */
|
|
233
|
+
function fetchOf(source) {
|
|
234
|
+
const status = source.metadata?.status;
|
|
235
|
+
if (!isHttpUrl(source.location) || typeof status !== "number")
|
|
236
|
+
return undefined;
|
|
237
|
+
const requested = source.metadata?.requestedUrl;
|
|
238
|
+
const renderedBy = source.metadata?.renderedBy;
|
|
239
|
+
const renderError = source.metadata?.renderError;
|
|
240
|
+
return {
|
|
241
|
+
requestedUrl: typeof requested === "string" ? requested : source.location,
|
|
242
|
+
url: source.location,
|
|
243
|
+
status,
|
|
244
|
+
rendered: typeof renderedBy === "string",
|
|
245
|
+
...(typeof renderedBy === "string" ? { renderedBy } : {}),
|
|
246
|
+
...(typeof renderError === "string" ? { renderError } : {}),
|
|
247
|
+
};
|
|
248
|
+
}
|
|
154
249
|
//# sourceMappingURL=graph.js.map
|
package/dist/graph.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"graph.js","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAE1F,wFAAwF;AACxF,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAChD,qDAAqD;AACrD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAqJ3C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,QAA0B,EAC1B,MAAgE,EAChE,UAA6B,EAAE;IAE/B,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,MAAM,CAAC,iBAAiB,CAAC;IAC9D,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,2BAA2B,CAAC;IACzE,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,IAAI,CAAC;IACtD,MAAM,cAAc,GAAG,OAAO,CAAC,cAAc,IAAI,KAAK,CAAC;IACvD,MAAM,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,IAAI,IAAI,CAAC;IAChE,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,I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
+
export interface HtmlElement {
|
|
3
|
+
readonly kind: "element";
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly attributes: Readonly<Record<string, string>>;
|
|
6
|
+
readonly children: HtmlNode[];
|
|
7
|
+
}
|
|
8
|
+
/** Text between tags, with character references decoded. */
|
|
9
|
+
export interface HtmlText {
|
|
10
|
+
readonly kind: "text";
|
|
11
|
+
readonly text: string;
|
|
12
|
+
}
|
|
13
|
+
/** A node of the tree. */
|
|
14
|
+
export type HtmlNode = HtmlElement | HtmlText;
|
|
15
|
+
/** The name of the root element {@link parseHtml} returns. */
|
|
16
|
+
export declare const DOCUMENT_NODE_NAME = "#document";
|
|
17
|
+
/**
|
|
18
|
+
* Parses the attributes of a start tag (the text after its name): double-quoted, single-quoted, unquoted and bare
|
|
19
|
+
* (`hidden`, given the value "") attributes. Names are lower-cased and values decoded; the first of a repeated name
|
|
20
|
+
* wins, as in browsers.
|
|
21
|
+
*/
|
|
22
|
+
export declare function parseHtmlAttributes(input: string): Record<string, string>;
|
|
23
|
+
/** Parses html into a tree under a {@link DOCUMENT_NODE_NAME} root. Comments, doctypes and processing instructions are dropped. */
|
|
24
|
+
export declare function parseHtml(html: string): HtmlElement;
|
|
25
|
+
/** The elements under a node, depth first, in document order. */
|
|
26
|
+
export declare function descendants(node: HtmlElement): Generator<HtmlElement>;
|
|
27
|
+
/** The first element under a node that passes a test, depth first. */
|
|
28
|
+
export declare function findElement(node: HtmlElement, test: (element: HtmlElement) => boolean): HtmlElement | undefined;
|
|
29
|
+
/** All the text under a node, as written (whitespace kept). */
|
|
30
|
+
export declare function textContent(node: HtmlNode): string;
|
|
31
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../src/html/dom.ts"],"names":[],"mappings":"AAOA,wGAAwG;AACxG,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD,QAAQ,CAAC,QAAQ,EAAE,QAAQ,EAAE,CAAC;CAC/B;AAED,4DAA4D;AAC5D,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,0BAA0B;AAC1B,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE9C,8DAA8D;AAC9D,eAAO,MAAM,kBAAkB,cAAc,CAAC;AAqC9C;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CASzE;AA8DD,mIAAmI;AACnI,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CA6DnD;AAED,iEAAiE;AACjE,wBAAiB,WAAW,CAAC,IAAI,EAAE,WAAW,GAAG,SAAS,CAAC,WAAW,CAAC,CAOtE;AAED,sEAAsE;AACtE,wBAAgB,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,GAAG,WAAW,GAAG,SAAS,CAK/G;AAED,+DAA+D;AAC/D,wBAAgB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,MAAM,CAElD"}
|