@dasl/tile-loader 3.1.0 → 3.2.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/README.md +818 -34
- package/dist/at.d.ts +126 -12
- package/dist/at.d.ts.map +1 -1
- package/dist/at.js +574 -90
- package/dist/at.js.map +1 -1
- package/dist/car.d.ts +21 -2
- package/dist/car.d.ts.map +1 -1
- package/dist/car.js +78 -15
- package/dist/car.js.map +1 -1
- package/dist/content-scheme.d.ts +17 -3
- package/dist/content-scheme.d.ts.map +1 -1
- package/dist/content-scheme.js +32 -6
- package/dist/content-scheme.js.map +1 -1
- package/dist/guard.d.ts +242 -0
- package/dist/guard.d.ts.map +1 -0
- package/dist/guard.js +956 -0
- package/dist/guard.js.map +1 -0
- package/dist/index.d.ts +247 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +746 -51
- package/dist/index.js.map +1 -1
- package/dist/lib/cid.d.ts +25 -0
- package/dist/lib/cid.d.ts.map +1 -0
- package/dist/lib/cid.js +65 -0
- package/dist/lib/cid.js.map +1 -0
- package/dist/lib/defaults.d.ts +8 -0
- package/dist/lib/defaults.d.ts.map +1 -0
- package/dist/lib/defaults.js +14 -0
- package/dist/lib/defaults.js.map +1 -0
- package/dist/lib/destinations.d.ts +25 -0
- package/dist/lib/destinations.d.ts.map +1 -0
- package/dist/lib/destinations.js +94 -0
- package/dist/lib/destinations.js.map +1 -0
- package/dist/lib/drisl.d.ts +10 -0
- package/dist/lib/drisl.d.ts.map +1 -0
- package/dist/lib/drisl.js +169 -0
- package/dist/lib/drisl.js.map +1 -0
- package/dist/lib/errors.d.ts +80 -0
- package/dist/lib/errors.d.ts.map +1 -0
- package/dist/lib/errors.js +44 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/fetching.d.ts +24 -0
- package/dist/lib/fetching.d.ts.map +1 -0
- package/dist/lib/fetching.js +135 -0
- package/dist/lib/fetching.js.map +1 -0
- package/dist/lib/limits.d.ts +34 -0
- package/dist/lib/limits.d.ts.map +1 -0
- package/dist/lib/limits.js +33 -0
- package/dist/lib/limits.js.map +1 -0
- package/dist/lib/pointer.d.ts +83 -0
- package/dist/lib/pointer.d.ts.map +1 -0
- package/dist/lib/pointer.js +244 -0
- package/dist/lib/pointer.js.map +1 -0
- package/dist/link.d.ts +110 -13
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +336 -43
- package/dist/link.js.map +1 -1
- package/dist/memory.d.ts +1 -0
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +5 -0
- package/dist/memory.js.map +1 -1
- package/dist/mount.d.ts +54 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/mount.js +286 -0
- package/dist/mount.js.map +1 -0
- package/dist/size.d.ts +43 -2
- package/dist/size.d.ts.map +1 -1
- package/dist/size.js +296 -15
- package/dist/size.js.map +1 -1
- package/package.json +13 -3
- package/src/at.ts +582 -84
- package/src/car.ts +75 -16
- package/src/content-scheme.ts +38 -7
- package/src/guard.ts +1013 -0
- package/src/index.ts +837 -52
- package/src/lib/cid.ts +65 -0
- package/src/lib/defaults.ts +12 -0
- package/src/lib/destinations.ts +79 -0
- package/src/lib/drisl.ts +160 -0
- package/src/lib/errors.ts +111 -0
- package/src/lib/fetching.ts +138 -0
- package/src/lib/limits.ts +61 -0
- package/src/lib/pointer.ts +290 -0
- package/src/link.ts +365 -48
- package/src/memory.ts +5 -0
- package/src/mount.ts +356 -0
- package/src/size.ts +304 -16
package/dist/at.d.ts
CHANGED
|
@@ -1,16 +1,43 @@
|
|
|
1
1
|
import { Tile } from "./index.js";
|
|
2
|
-
import type { TileMothership } from "./index.js";
|
|
2
|
+
import type { TileMothership, TileLoadOptions } from "./index.js";
|
|
3
3
|
import type { StoredMasl, MaslResponse } from "@dasl/tile-lexicon";
|
|
4
4
|
import type { LoaderOptions } from "./content-scheme.js";
|
|
5
|
-
type Fetch
|
|
5
|
+
import type { Fetch } from "./lib/fetching.js";
|
|
6
|
+
export { publicHost, publicEndpoint, localEndpoint } from "./lib/destinations.js";
|
|
7
|
+
export { recordCid } from "./lib/cid.js";
|
|
8
|
+
export { DEFAULT_LIMITS } from "./lib/limits.js";
|
|
9
|
+
export type { LoaderLimits } from "./lib/limits.js";
|
|
10
|
+
/**
|
|
11
|
+
* Which hosts the loader may be sent to. A tile's author writes the DID
|
|
12
|
+
* document that names them, and it is the viewer's browser that goes there.
|
|
13
|
+
*/
|
|
14
|
+
export interface Destinations {
|
|
15
|
+
/** Whether a did:web's host may be asked for its document. `publicHost` unless given. */
|
|
16
|
+
did?: (host: string) => boolean;
|
|
17
|
+
/** The origin to fetch from for the PDS endpoint a DID document names, or false. `publicEndpoint` unless given. */
|
|
18
|
+
pds?: (endpoint: string) => string | false;
|
|
19
|
+
}
|
|
20
|
+
export interface ATLoaderOptions extends LoaderOptions {
|
|
21
|
+
/** The PLC directory, for a deployment with one of its own or a local one. `https://plc.directory` unless given. */
|
|
22
|
+
plcUrl?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Which hosts to fetch from. Unless given, only https on public names, with
|
|
25
|
+
* no port and nothing else in the endpoint: see `publicEndpoint`. For local
|
|
26
|
+
* development, `{ pds: localEndpoint }` adds a PDS on this machine, over
|
|
27
|
+
* http and on any port. An embedder whose `fetch` goes through a proxy
|
|
28
|
+
* that makes checks of its own can pass its own rule; nobody else should.
|
|
29
|
+
*/
|
|
30
|
+
destinations?: Destinations;
|
|
31
|
+
}
|
|
6
32
|
/**
|
|
7
33
|
* Where a DID's document is, for the two methods AT uses, or false for a DID
|
|
8
34
|
* we do not resolve. `did:plc` documents come from the PLC directory.
|
|
9
35
|
* `did:web` as AT allows it names a host and nothing more: no path, and no
|
|
10
36
|
* port (AT keeps ports for local development, which a tile host is not), so
|
|
11
|
-
* the document is that host's `/.well-known/did.json`.
|
|
37
|
+
* the document is that host's `/.well-known/did.json`. The host has to be one
|
|
38
|
+
* to fetch from: a public name, unless `options.destinations` says otherwise.
|
|
12
39
|
*/
|
|
13
|
-
export declare function didDocumentUrl(did: string): string | false;
|
|
40
|
+
export declare function didDocumentUrl(did: string, options?: ATLoaderOptions): string | false;
|
|
14
41
|
/** The resolver handles are looked up with unless a loader is told otherwise. */
|
|
15
42
|
export declare const DEFAULT_DNS_OVER_HTTPS = "https://cloudflare-dns.com/dns-query";
|
|
16
43
|
/**
|
|
@@ -25,19 +52,106 @@ export declare const DEFAULT_DNS_OVER_HTTPS = "https://cloudflare-dns.com/dns-qu
|
|
|
25
52
|
* that, anyone with a domain could point at somebody else's repo, or a
|
|
26
53
|
* resolver could.
|
|
27
54
|
*/
|
|
28
|
-
export declare function resolveHandle(handle: string, options?:
|
|
29
|
-
fetch?: Fetch;
|
|
30
|
-
dnsOverHttps?: string | false;
|
|
31
|
-
}): Promise<string | false>;
|
|
55
|
+
export declare function resolveHandle(handle: string, options?: ATLoaderOptions): Promise<string | false>;
|
|
32
56
|
export declare class ATTileLoader {
|
|
33
57
|
#private;
|
|
34
|
-
constructor(options?:
|
|
35
|
-
|
|
58
|
+
constructor(options?: ATLoaderOptions);
|
|
59
|
+
/**
|
|
60
|
+
* The tile at `url`: false for what is not an AT address, undefined for one
|
|
61
|
+
* that is not a tile's. A tile that could not be had is a rejection with a
|
|
62
|
+
* TileLoadError, whose `code` says what stood in the way: the handle or the
|
|
63
|
+
* DID has no answer (`not-found`), the record is not there (`not-found`),
|
|
64
|
+
* is not a tile's that can be run (`record-invalid`) or lists more than a
|
|
65
|
+
* tile may have (`over-budget`), a server is busy (`rate-limited`) or
|
|
66
|
+
* failing (`upstream`), did not answer in time (`timeout`) or could not be
|
|
67
|
+
* reached (`network`), or is not one to fetch from (`destination`).
|
|
68
|
+
*
|
|
69
|
+
* Loading a tile fetches its record and nothing else. Its resources are
|
|
70
|
+
* fetched when the host runs it, all of them and before it runs: see
|
|
71
|
+
* ATPathLoader.
|
|
72
|
+
*
|
|
73
|
+
* `options.cid` and `options.manifestCid` say which tile is expected: the
|
|
74
|
+
* CID of its record, the CID of its manifest alone, or both, of which
|
|
75
|
+
* either will do. A caller with only a string to say it in can give them
|
|
76
|
+
* at the end of the address, as `?cid=…&manifestCid=…`: they are read when
|
|
77
|
+
* the options give neither, and never beside them, since an address is
|
|
78
|
+
* often not the host's own writing. The record's CID is computed here, from
|
|
79
|
+
* the record as it came, and so is the manifest's: what the PDS says a
|
|
80
|
+
* record's CID is plays no part. A tile that is not the one expected is not
|
|
81
|
+
* loaded: the load fails with a TileLoadError, `record-changed`, which
|
|
82
|
+
* carries the CID that was `expected`, the `actual` one, and the
|
|
83
|
+
* `manifestCid` of what is there now. The tile that loads has its CIDs
|
|
84
|
+
* (`cid`, `manifestCid`) for a host to keep.
|
|
85
|
+
*
|
|
86
|
+
* The same content published again is a new record, with a new date and so
|
|
87
|
+
* a new CID, and the same manifest: a host that keeps the manifest's CID
|
|
88
|
+
* does not see a change where there is none.
|
|
89
|
+
*/
|
|
90
|
+
load(url: string, mothership: TileMothership, options?: TileLoadOptions): Promise<Tile | false | undefined>;
|
|
36
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* The resources of a tile on AT, from its author's PDS, each checked against
|
|
94
|
+
* the CID its record names before any of it is served.
|
|
95
|
+
*
|
|
96
|
+
* What a tile asks for, and when, would be a message to its author's server
|
|
97
|
+
* if each request went there as it was made. So when the host runs the tile
|
|
98
|
+
* everything its record lists is fetched once (`prepare()`), in an order the
|
|
99
|
+
* record alone decides, and the tile is answered from memory: what it asks
|
|
100
|
+
* for after that reaches nobody, and what the PDS is asked depends on the
|
|
101
|
+
* record alone. The fetch is refused, not narrowed, when the record lists
|
|
102
|
+
* more than a tile may have: fetching the rest as the tile asked would bring
|
|
103
|
+
* the message back.
|
|
104
|
+
*
|
|
105
|
+
* Before the tile is run only the host can be asking, for a card's picture:
|
|
106
|
+
* that one resource is fetched by itself, within a size fit for a card.
|
|
107
|
+
*
|
|
108
|
+
* It is the tile the AT loader makes that calls `prepare()` when it is run.
|
|
109
|
+
* A host that makes a path loader of its own and runs it under a Tile of its
|
|
110
|
+
* own has to call `prepare()` itself, and run the tile once that has
|
|
111
|
+
* resolved: until it is called, every resource is fetched as it is asked
|
|
112
|
+
* for, the tile's requests among them.
|
|
113
|
+
*/
|
|
37
114
|
export declare class ATPathLoader {
|
|
38
115
|
#private;
|
|
39
|
-
|
|
116
|
+
/**
|
|
117
|
+
* `from` is the loader that made the tile, whose limits and requests in
|
|
118
|
+
* flight it shares, or the options for one on its own (a function is taken
|
|
119
|
+
* for its `fetch`, which is what this argument used to be). `pds` is the
|
|
120
|
+
* origin of the repo's PDS when it is known already: the loader has just
|
|
121
|
+
* asked, and a tile does not ask again. Throws a TileLoadError for a
|
|
122
|
+
* manifest that cannot be run (`record-invalid`) or that lists more than a
|
|
123
|
+
* tile may have (`over-budget`).
|
|
124
|
+
*/
|
|
125
|
+
constructor(did: string, manifest: StoredMasl, from?: ATTileLoader | ATLoaderOptions | Fetch, pds?: string);
|
|
126
|
+
/**
|
|
127
|
+
* Fetches everything the tile lists, once, checked, in the order of the
|
|
128
|
+
* record: first what the record declares the size of, `concurrency`
|
|
129
|
+
* requests at a time, then what it declares no size for, one at a time and
|
|
130
|
+
* each no further than what the tile has left. Resolves when all of it is
|
|
131
|
+
* in memory. Rejects with a TileLoadError when any of it could not be had,
|
|
132
|
+
* or was not all here within `prepareMs`; calling again then tries again,
|
|
133
|
+
* for what is still missing. The host's rendering the tile calls this;
|
|
134
|
+
* from then on `resolvePath()` asks nobody.
|
|
135
|
+
*/
|
|
136
|
+
prepare(): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Calls off a fetch of everything that has not come to its end: nothing
|
|
139
|
+
* more is asked for. What is here stays, and the requests already made run
|
|
140
|
+
* their course, since another tile may be waiting on them. For a tile that
|
|
141
|
+
* is closed before it could run, which is then as it was before the host
|
|
142
|
+
* ran it. A tile that is all here is left as it is.
|
|
143
|
+
*/
|
|
144
|
+
stop(): void;
|
|
145
|
+
/**
|
|
146
|
+
* The resource at `path`. A path the tile does not list is a 404, and
|
|
147
|
+
* nobody is asked. Once the host has run the tile the answer comes from
|
|
148
|
+
* memory, when all of the tile is there; if it could not all be had, every
|
|
149
|
+
* path is answered with that failure (a 502, a 503 when the PDS is busy, a
|
|
150
|
+
* 504 when it took too long, a 507 when it is more than a tile may have),
|
|
151
|
+
* which carries the TileLoadError that says why. Before that, the one
|
|
152
|
+
* resource is fetched and checked by itself, if it is no larger than
|
|
153
|
+
* `cardBytes`.
|
|
154
|
+
*/
|
|
40
155
|
resolvePath(path: string): Promise<MaslResponse>;
|
|
41
156
|
}
|
|
42
|
-
export {};
|
|
43
157
|
//# sourceMappingURL=at.d.ts.map
|
package/dist/at.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"at.d.ts","sourceRoot":"","sources":["../src/at.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"at.d.ts","sourceRoot":"","sources":["../src/at.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAgB,MAAM,YAAY,CAAC;AAEhF,OAAO,KAAK,EAAE,UAAU,EAAuB,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAClF,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;GAGG;AACH,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