@egildo/provenance 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +173 -2
- package/dist/css.d.ts +2 -0
- package/dist/css.js +77 -0
- package/dist/html.d.ts +2 -0
- package/dist/html.js +128 -0
- package/dist/index.d.ts +397 -0
- package/dist/index.js +3 -0
- package/dist/memory.d.ts +6 -0
- package/dist/memory.js +83 -0
- package/dist/node.d.ts +4 -0
- package/dist/node.js +110 -0
- package/dist/offsets.d.ts +6 -0
- package/dist/offsets.js +43 -0
- package/dist/resolvers.d.ts +4 -0
- package/dist/resolvers.js +42 -0
- package/dist/session.d.ts +11 -0
- package/dist/session.js +1057 -0
- package/package.json +59 -4
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// The shipped resolvers, chosen by request scheme (specs/source-graph-kernel/research.md, Resolution).
|
|
2
|
+
export const hasScheme = (request) => /^[a-z][a-z0-9+.-]*:/i.test(request);
|
|
3
|
+
const isWeb = (url) => /^https?:/i.test(url);
|
|
4
|
+
/** `data:`, an empty request, and a request that is only a fragment make no edge. */
|
|
5
|
+
const none = {
|
|
6
|
+
claims: request => request === "" || request.startsWith("#") || /^data:/i.test(request),
|
|
7
|
+
resolve: async () => null,
|
|
8
|
+
};
|
|
9
|
+
/** `http(s):` and `//host/…` are external leaves, never read. */
|
|
10
|
+
const external = {
|
|
11
|
+
claims: request => isWeb(request) || request.startsWith("//"),
|
|
12
|
+
resolve: async (request) => ({ external: request.startsWith("//") ? `https:${request}` : request }),
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A path relative to `base`, a directory location. Query and fragment are dropped and the path is
|
|
16
|
+
* percent-decoded. The one location computed is the probe; the host saying nothing is there
|
|
17
|
+
* leaves the edge unresolved. A web `base` (an HTML `<base href="https://…">`) makes it external.
|
|
18
|
+
*/
|
|
19
|
+
const relative = {
|
|
20
|
+
claims: request => !hasScheme(request) && !request.startsWith("/"),
|
|
21
|
+
async resolve(request, base, host) {
|
|
22
|
+
if (isWeb(base))
|
|
23
|
+
return { external: new URL(request, base).href };
|
|
24
|
+
const path = request.replace(/[?#].*$/s, "");
|
|
25
|
+
let decoded = path;
|
|
26
|
+
try {
|
|
27
|
+
decoded = decodeURIComponent(path);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// A malformed escape stays as written.
|
|
31
|
+
}
|
|
32
|
+
const location = host.paths.resolve(base, decoded);
|
|
33
|
+
const target = await host.canonicalize(location);
|
|
34
|
+
return target === undefined ? { probes: [location] } : { probes: [location], target };
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
const shipped = [none, external, relative];
|
|
38
|
+
/** Tries the embedder's resolvers first, then the shipped ones. Unclaimed means unresolved, no probes. */
|
|
39
|
+
export function resolve(request, base, host, resolvers = []) {
|
|
40
|
+
const resolver = [...resolvers, ...shipped].find(r => r.claims(request));
|
|
41
|
+
return resolver ? resolver.resolve(request, base, host) : Promise.resolve({ probes: [] });
|
|
42
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Handler, Host, Resolver, Session, Writer } from "./index.ts";
|
|
2
|
+
export declare function openSession(options: {
|
|
3
|
+
host: Host;
|
|
4
|
+
entry: string;
|
|
5
|
+
handlers: readonly Handler[];
|
|
6
|
+
resolvers?: readonly Resolver[];
|
|
7
|
+
/** The editing half of the format plug-ins; the first that claims a location is its writer. */
|
|
8
|
+
writers?: readonly Writer[];
|
|
9
|
+
/** Locations under which a commit may write. Absent means nothing is writable. */
|
|
10
|
+
writable?: readonly string[];
|
|
11
|
+
}): Promise<Session>;
|