@yaks/page 0.0.0-stage → 0.2.36

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.
Files changed (60) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +190 -2
  3. package/_dist/comp.d.ts +7 -0
  4. package/_dist/comp.d.ts.map +1 -0
  5. package/_dist/effects.d.ts +8 -0
  6. package/_dist/effects.d.ts.map +1 -0
  7. package/_dist/freeze.d.ts +41 -0
  8. package/_dist/freeze.d.ts.map +1 -0
  9. package/_dist/graph.d.ts +3 -0
  10. package/_dist/graph.d.ts.map +1 -0
  11. package/_dist/host.d.ts +36 -0
  12. package/_dist/host.d.ts.map +1 -0
  13. package/_dist/mod.d.ts +57 -0
  14. package/_dist/mod.d.ts.map +1 -0
  15. package/_dist/plugin.d.ts +22 -0
  16. package/_dist/plugin.d.ts.map +1 -0
  17. package/_dist/routes.d.ts +10 -0
  18. package/_dist/routes.d.ts.map +1 -0
  19. package/_dist/scrub.d.ts +14 -0
  20. package/_dist/scrub.d.ts.map +1 -0
  21. package/_dist/url.d.ts +20 -0
  22. package/_dist/url.d.ts.map +1 -0
  23. package/_dist/vocab.d.ts +7 -0
  24. package/_dist/vocab.d.ts.map +1 -0
  25. package/comp.js +33 -0
  26. package/comp.js.map +1 -0
  27. package/comp.ts +36 -0
  28. package/deno.json +1 -0
  29. package/effects.js +21 -0
  30. package/effects.js.map +1 -0
  31. package/effects.ts +33 -0
  32. package/freeze.js +87 -0
  33. package/freeze.js.map +1 -0
  34. package/freeze.ts +111 -0
  35. package/graph.js +9 -0
  36. package/graph.js.map +1 -0
  37. package/graph.ts +10 -0
  38. package/host.js +51 -0
  39. package/host.js.map +1 -0
  40. package/host.ts +95 -0
  41. package/mod.js +57 -0
  42. package/mod.js.map +1 -0
  43. package/mod.ts +58 -0
  44. package/package.json +41 -4
  45. package/plugin.js +60 -0
  46. package/plugin.js.map +1 -0
  47. package/plugin.ts +52 -0
  48. package/routes.js +62 -0
  49. package/routes.js.map +1 -0
  50. package/routes.ts +68 -0
  51. package/scrub.js +94 -0
  52. package/scrub.js.map +1 -0
  53. package/scrub.ts +112 -0
  54. package/url.js +71 -0
  55. package/url.js.map +1 -0
  56. package/url.ts +76 -0
  57. package/vocab.js +14 -0
  58. package/vocab.js.map +1 -0
  59. package/vocab.json +52 -0
  60. package/vocab.ts +16 -0
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2026 Jeff Peterson
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,191 @@
1
- # Temporary Holding Version
1
+ # @yaks/page
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Store web page URLs and archived HTML in a [@yaks/graph](../graph/README.md), so
4
+ recorded sources can still be read after the original page changes or
5
+ disappears. Use it to save HTML captured in a browser or to archive URLs with an
6
+ external command.
7
+
8
+ The graph's storage adapter stores the `web` component:
9
+
10
+ | Property | Meaning |
11
+ | ----------- | --------------------------------------------------------------------- |
12
+ | `url` | Canonical page URL, used to derive the entity id. |
13
+ | `frozen_at` | When the archive was stored; absent until a capture is saved. |
14
+ | `bytes` | SHA-256 key for the HTML in an [@yaks/blob](../blob/README.md) store. |
15
+
16
+ `frozen_at` and `bytes` are server-owned properties. Ordinary client writes
17
+ cannot set them. Page titles and prose use the separate `doc` component from
18
+ [@yaks/doc](../doc/README.md). This package stores the latest archive reference
19
+ on each page entity; it does not maintain a list of snapshots.
20
+
21
+ ## Install
22
+
23
+ ```sh
24
+ deno add jsr:@yaks/page
25
+ # or: npx jsr add @yaks/page
26
+ ```
27
+
28
+ ## Use
29
+
30
+ For a graph that records URLs without fetching them:
31
+
32
+ ```ts
33
+ import { equal } from '@yaks/testing'
34
+ import { graph } from '@yaks/graph'
35
+ import { ram } from '@yaks/ram'
36
+ import { loadVocab } from '@yaks/vocab'
37
+ import { docDoc } from '@yaks/doc'
38
+ import { pageDoc, pageEid, pages } from '@yaks/page'
39
+
40
+ let vocab = loadVocab([docDoc, pageDoc])
41
+ let g = graph({
42
+ storage: ram(vocab),
43
+ vocab,
44
+ provenance: false,
45
+ plugins: [pages()],
46
+ })
47
+ let url = 'https://example.com/article'
48
+ let eid = pageEid(url)
49
+
50
+ await g.apply([{
51
+ entity: { eid },
52
+ web: { url },
53
+ doc: { title: 'An article' },
54
+ }])
55
+ let [saved] = await g.get([eid])
56
+ equal(saved.web, { url })
57
+ equal(saved.doc, { title: 'An article' })
58
+ ```
59
+
60
+ Each object passed to `apply()` is a **bundle**: one entity's components as a
61
+ JSON object. A **batch** is a list of bundles applied in one transaction. The
62
+ example uses memory storage; replace it with a persistent graph storage adapter
63
+ to keep records across restarts.
64
+
65
+ ## The address is the identity
66
+
67
+ `web.url` is declared `identity`, so the graph can derive a page's entity id
68
+ from its canonical URL when creating it under an alias. `pageEid()` computes
69
+ that same id directly:
70
+
71
+ ```ts
72
+ import { canon, pageEid } from '@yaks/page'
73
+
74
+ canon('HTTPS://Example.com/a/?utm_source=n#top') // 'https://example.com/a'
75
+ pageEid('https://example.com/a/') == pageEid('https://example.com/a') // true
76
+ ```
77
+
78
+ `pages()` normalizes URLs before the graph assigns ids. Use an alias or
79
+ `pageEid(url)` when creating a page so repeated records of the same URL update
80
+ one entity. Normalization removes fragments, credentials, recognized tracking
81
+ parameters, and trailing slashes from non-root paths. Other query parameters
82
+ retain their order. These are this package's identity rules; URLs that differ
83
+ only in these ways are treated as one page.
84
+
85
+ All inputs are trimmed. Invalid and non-HTTP(S) URLs are otherwise left alone by
86
+ `canon()`. Automatic fetching accepts only HTTP(S) addresses.
87
+
88
+ ## HTML processing
89
+
90
+ Before saving HTML, `scrub()` parses it with `linkedom` and removes scripts,
91
+ `base`, embedded documents (`iframe`, `frame`, `embed`, `object`), meta refresh,
92
+ and inline event handlers. It removes `link` elements unless their `href` starts
93
+ with `data:`. It also removes external values from the URL attributes listed in
94
+ [scrub.ts](./scrub.ts), including `src`, `href`, `srcset`, and form actions;
95
+ `data:`, fragment, and `about:` values are retained.
96
+
97
+ CSS `url()` references are emptied except for embedded `data:` values. This is a
98
+ specific set of HTML and CSS transformations, not a complete CSS sanitizer: for
99
+ example, quoted CSS `@import` rules are not removed. Served archives also
100
+ receive a restrictive Content-Security-Policy from `@yaks/blob`; that header is
101
+ not present when someone opens a copied HTML file directly.
102
+
103
+ `froze(page, html, { blobs, now? })` scrubs and stores the HTML, then returns
104
+ the bundles to apply with `{ trusted: true }`. It derives the blob key from the
105
+ stored HTML's SHA-256, so identical stored documents use the same key. It adds
106
+ the HTML title only if the page has no `doc` component.
107
+
108
+ ## How the bytes arrive
109
+
110
+ A host that already holds a document stores it with `froze()` and applies the
111
+ result. For URL-only records, the optional `created('web')` effect calls the
112
+ configured archiver after the transaction commits. It skips entities that
113
+ already have `web.bytes` and non-HTTP(S) URLs. A failed capture is reported by
114
+ the effects registry without rolling back the URL record. The effect is awaited,
115
+ so a slow capture can delay the caller even though the transaction has already
116
+ committed.
117
+
118
+ Both paths use the same HTML processing and blob storage. No archiver is
119
+ configured by default, so URL-only records remain unarchived until an
120
+ application supplies HTML or arranges a capture.
121
+
122
+ ## What each entry point exports
123
+
124
+ The root import `@yaks/page` provides `pageDoc`, `WEB`, `pages()`, `canon()`,
125
+ `pageEid()`, `fetchable()`, `scrub()`, `froze()`, `freezing()`, `archiver()`,
126
+ and `blobsOf()`, plus the types `Scrubbed`, `Archive`, `Keep`, `Capture`,
127
+ `Options`, and `Run`.
128
+
129
+ A **host** is the process that opened the graph, represented here by an object
130
+ containing the services a function uses. `effects()` and `blobsOf()` need a
131
+ SQLite `sql` driver; `routes()` also needs `storage`.
132
+
133
+ The server loader uses these separate sub-module exports:
134
+
135
+ | Import | Exports |
136
+ | -------------------- | --------------------------------------------------------------------------------------- |
137
+ | `@yaks/page/vocab` | `pageDoc` and `docs`, the `web` vocabulary document and its one-item array. |
138
+ | `@yaks/page/graph` | `plugins()`, returning the graph plugin and its normalization hook. |
139
+ | `@yaks/page/effects` | `effects(host, options)`, returning an archive handler when configured; also `Options`. |
140
+ | `@yaks/page/routes` | `routes(host, options)` and `PREFIX` for `GET /page/<eid>`. |
141
+
142
+ A plugin entry in a `yak serve` configuration can be:
143
+
144
+ ```json
145
+ {
146
+ "use": "@yaks/page",
147
+ "with": {
148
+ "archive": {
149
+ "run": ["monolith", "-j", "-f", "-I", "-q", "{url}"],
150
+ "timeout": 60000
151
+ },
152
+ "bytes": "/var/lib/yak/frozen"
153
+ }
154
+ }
155
+ ```
156
+
157
+ `archive.run` names the command and arguments. Each `{url}` in an argument is
158
+ replaced with the URL; if no argument contains it, the URL is appended. The
159
+ command must write HTML to stdout. Nonzero exit status, empty output, or timeout
160
+ fails the capture. The default timeout is 60,000 milliseconds. Install the
161
+ command separately; this package does not include it.
162
+
163
+ `bytes` selects a directory for archived HTML. Omit it to use the host's SQLite
164
+ blob table, which `blobsOf()` creates if needed. A directory can keep large HTML
165
+ documents outside the graph database. `GET /page/<eid>` reads from the
166
+ configured store in either case. A separately configured `GET /blob/<sha>` route
167
+ can serve the same bytes only if it uses the same store.
168
+
169
+ `GET /page/<eid>` returns HTML with a sandbox Content-Security-Policy that
170
+ blocks scripts, `X-Content-Type-Options: nosniff`, and `Cache-Control: no-cache`
171
+ because a later capture can replace the page's archive reference. It adds
172
+ `Memento-Datetime` from `frozen_at` and `Link: <url>; rel="original"` from
173
+ `url`, using the archive metadata headers defined by RFC 7089. Missing pages,
174
+ missing archives, and invalid entity ids return 404.
175
+
176
+ ## What this package does not own
177
+
178
+ Load [@yaks/doc](../doc/README.md) alongside this package for
179
+ `doc{title, body}`; it is not redeclared here. [@yaks/blob](../blob/README.md)
180
+ supplies byte storage. A reference to a place in source code is a `cites` edge
181
+ from [@yaks/git](../git/README.md).
182
+
183
+ ## Compatibility
184
+
185
+ `@yaks/page/vocab` exports a vocabulary document and has no runtime calls. The
186
+ configured archiver uses `Deno.Command`; the configured stores use SQLite or the
187
+ filesystem. The root import includes these server helpers and is not covered by
188
+ the package's browser type check, which checks only `./vocab`. URL
189
+ normalization, HTML processing, and capture composition do not themselves start
190
+ processes; `freezing()` accepts an application-supplied `Archive` function and
191
+ blob store.
@@ -0,0 +1,7 @@
1
+ import type { VocabDoc } from "@yaks/vocab";
2
+ /** The name of the component recording a page as it was seen. */ export declare let WEB: string;
3
+ /**
4
+ * The `web` component as a vocabulary document, to load beside your own:
5
+ * `loadVocab([docDoc, pageDoc, ...mine])`.
6
+ */ export declare let pageDoc: VocabDoc;
7
+ //# sourceMappingURL=comp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"comp.d.ts","sources":["../comp.ts"],"names":[],"mappings":"AAyBA,cAAc,QAAQ,2BAAgC;AAGtD,+DAA+D,GAC/D,OAAO,YAAI,YAAW;AAEtB;;;CAGC,GACD,OAAO,YAAI,SAAS,SAA0B"}
@@ -0,0 +1,8 @@
1
+ import type { Blobs } from "@yaks/blob";
2
+ import type { Handlers } from "@yaks/effects";
3
+ import { type Options } from "./host.js";
4
+ export type { Options };
5
+ /** The capture handler, when an archiver was configured. */ export declare let effects: (host: {
6
+ blobs: Blobs;
7
+ }, options?: Options) => Handlers;
8
+ //# sourceMappingURL=effects.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"effects.d.ts","sources":["../effects.ts"],"names":[],"mappings":"AAaA,cAAc,KAAK,0BAA+B;AAClD,cAAc,QAAQ,6BAAkC;AAExD,SAA4B,KAAK,OAAO,oBAAmB;AAE3D,cAAc,OAAO,GAAE;AAEvB,0DAA0D,GAC1D,OAAO,YAAI,UACT;EAAQ,OAAO;GACf,UAAS,YACR,SAQK"}
@@ -0,0 +1,41 @@
1
+ import type { Bundle } from "@yaks/graph";
2
+ import type { Handler } from "@yaks/effects";
3
+ import { type Blobs } from "@yaks/blob";
4
+ /**
5
+ * An archiver: one address in, one self-contained document out. It rejects when
6
+ * it could not produce one — the rejection's message is what the server
7
+ * records, so make it worth reading.
8
+ */ export type Archive = (url: string) => Promise<string>;
9
+ /** Where a capture is stored, and what supplies the timestamp. */ export type Keep = {
10
+ /** the content-addressed store the archived document is written to */ blobs: Blobs;
11
+ /** the clock, injected so a test can hold it still (default: now) */ now?: () => string;
12
+ };
13
+ /** Everything the freezing effect handler is built from. */ export type Capture = Keep & {
14
+ archive: Archive;
15
+ };
16
+ /**
17
+ * Store one page's bytes: scrub the document of every external reference, write
18
+ * it under its own SHA-256, and return the bundles that stamp the page with
19
+ * where it went and when.
20
+ *
21
+ * It is given the page as it stands, because the archive's `<title>` names the
22
+ * page only while nothing else does — a title somebody wrote by hand is never
23
+ * overwritten by a later capture.
24
+ *
25
+ * The bytes are content-addressed, so archiving a page whose document has not
26
+ * changed since the last capture stores nothing new; `bytes` is simply the same
27
+ * address again.
28
+ */ export declare let froze: (page: Bundle, raw: string, {}: Keep) => Promise<Bundle[]>;
29
+ /**
30
+ * The code behind `web_freeze`: fetch a page that was recorded by its address
31
+ * alone, and store its bytes.
32
+ *
33
+ * It is registered where effects are worked:
34
+ * `fx.handle({ web_freeze: freezing({ archive, blobs }) })`.
35
+ *
36
+ * Idempotent, which is what lets a start-up sweep re-run it: a page that
37
+ * already carries `bytes` is left alone, and so is one whose address is not
38
+ * something this package can fetch (a `file:` note, an application's own
39
+ * scheme).
40
+ */ export declare let freezing: ({}: Capture) => Handler;
41
+ //# sourceMappingURL=freeze.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"freeze.d.ts","sources":["../freeze.ts"],"names":[],"mappings":"AAsBA,cAAc,MAAM,2BAAsD;AAE1E,cAAc,OAAO,6BAAkC;AACvD,SAAkB,KAAK,KAAK,0BAAuC;AAKnE;;;;CAIC,GACD,YAAY,WAAW,KAAK,MAAM,KAAK,QAAQ,MAAM;AAErD,gEAAgE,GAChE,YAAY;EACV,oEAAoE,GACpE,OAAO;EACP,mEAAmE,GACnE,YAAY,MAAM;;AAGpB,0DAA0D,GAC1D,YAAY,UAAU;EAAS,SAAS;;AAaxC;;;;;;;;;;;;CAYC,GACD,OAAO,YAAI,QACT,MAAM,QACN,KAAK,MAAM,EACX,IAAwB,IAAI,KAC3B,QAAQ,UAYV;AAED;;;;;;;;;;;CAWC,GACD,OAAO,YAAI,WACR,IAAsB,OAAO,KAAG,QAO7B"}
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from "@yaks/graph";
2
+ /** The `web` component, plus canonicalization of its address. */ export declare let plugins: () => Plugin[];
3
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAKA,cAAc,MAAM,2BAAgC;AAGpD,+DAA+D,GAC/D,OAAO,YAAI,eAAc,SAAqB"}
@@ -0,0 +1,36 @@
1
+ import type { Blobs } from "@yaks/blob";
2
+ import type { Archive } from "./freeze.js";
3
+ /** The configuration `@yaks/page` reads. */ export type Options = {
4
+ /** the external command that archives a live URL, and how long it may take */ archive?: Run;
5
+ /** a directory the archived documents are written to; the server's own blob
6
+ * table otherwise */ bytes?: string;
7
+ };
8
+ /** An archiver, as the configuration names one. */ export type Run = {
9
+ /** the command and its arguments; `{url}` in an argument is replaced with the
10
+ * address, and where no argument mentions it the address is appended */ run: string[];
11
+ /** how long it may take, in milliseconds (default 60 seconds) */ timeout?: number;
12
+ };
13
+ /**
14
+ * A named command, wrapped as an {@link Archive}. The document is read from the
15
+ * command's stdout — there is no temporary file to name, collide over, or leave
16
+ * behind, and the bytes are addressed by their content the moment they arrive.
17
+ *
18
+ * ```ts
19
+ * import { archiver } from '@yaks/page'
20
+ *
21
+ * let archive = archiver({ run: ['monolith', '-j', '-f', '-I', '-q', '{url}'] })
22
+ * ```
23
+ */ export declare let archiver: ({}: Run) => Archive;
24
+ /**
25
+ * Where this server's archived documents are stored.
26
+ *
27
+ * The default is the host's own blob store — the same one @yaks/blob keeps
28
+ * its text properties in, so a page's bytes are not a second store to
29
+ * configure, back up and serve, and `GET /blob/<sha>` serves them as it does
30
+ * everything else. An archived page is one document with every asset inlined
31
+ * and is therefore often megabytes, so a server that would rather not carry
32
+ * that in its database names a directory instead.
33
+ */ export declare let blobsOf: (host: {
34
+ blobs: Blobs;
35
+ }, options?: Options) => Blobs;
36
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sources":["../host.ts"],"names":[],"mappings":"AAmBA,cAAc,KAAK,0BAA+B;AAElD,cAAc,OAAO,sBAAqB;AAE1C,0CAA0C,GAC1C,YAAY;EACV,4EAA4E,GAC5E,UAAU;EACV;qBACmB,GACnB,QAAQ,MAAM;;AAGhB,iDAAiD,GACjD,YAAY;EACV;wEACsE,GACtE,KAAK,MAAM;EACX,+DAA+D,GAC/D,UAAU,MAAM;;AAKlB;;;;;;;;;;CAUC,GACD,OAAO,YAAI,WAAY,IAA2B,GAAG,KAAG,QA2BvD;AAED;;;;;;;;;CASC,GACD,OAAO,YAAI,UAAW;EAAQ,OAAO;GAAS,UAAS,YAAe,MACf"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,57 @@
1
+ /**
2
+ * @yaks/page — records a web page as it was seen, not as it is now.
3
+ *
4
+ * Cite a URL and you have cited something that can change tonight and be gone
5
+ * by Friday. This package records the other reading. Its `web` component holds
6
+ * which address was read (`url`), when a copy of the document was taken
7
+ * (`frozen_at`) and where that copy is stored (`bytes`) — so a citation keeps
8
+ * its meaning after the page moves on.
9
+ *
10
+ * ```ts
11
+ * import { canon, pageEid } from '@yaks/page'
12
+ *
13
+ * canon('HTTPS://Example.com/a/?utm_source=x#top') // 'https://example.com/a'
14
+ * // pageEid(url) is the entity that address names, before anybody writes it
15
+ * ```
16
+ *
17
+ * ## The address is the identity
18
+ * `web.url` is declared `identity`, so a page's entity id is derived from its
19
+ * canonical address ({@link pageEid}). Recording one page twice writes one row
20
+ * by construction — no lookup to race, no uniqueness index to remember — and a
21
+ * client holding a URL can compute its entity id without asking. {@link canon}
22
+ * is the only place an address is rewritten, and the plugin calls it in
23
+ * @yaks/graph's `normalize` phase, so every code path gets the canonical form.
24
+ *
25
+ * ## An archived page renders from its own bytes
26
+ * {@link scrub} removes every external reference at freeze time — scripts,
27
+ * embedded documents, `link` tags, inline event handlers, every URL-bearing
28
+ * attribute that is not `data:`, and `url()` in CSS. That is the mechanism. A
29
+ * Content-Security-Policy header at serving time is defence in depth and
30
+ * nothing more: an archive that is mailed, copied or opened from a file has no
31
+ * header in front of it.
32
+ *
33
+ * ## Two ways the bytes arrive
34
+ * A host that already holds a page's document stores it with {@link froze}.
35
+ * Any other page is fetched afterwards by the {@link Archive} named in the
36
+ * configuration, in a handler that runs after
37
+ * the commit (`./effects`), so a slow capture is not a request somebody is
38
+ * holding open. Both end up the same way ({@link froze}): scrubbed, stored
39
+ * under its own SHA-256 in the server's
40
+ * {@link https://jsr.io/@yaks/blob | @yaks/blob} store, and stamped onto the
41
+ * page entity.
42
+ *
43
+ * ## What this package does not own
44
+ * The title and prose are `doc{title, body}`
45
+ * ({@link https://jsr.io/@yaks/doc | @yaks/doc}), the bytes belong to
46
+ * @yaks/blob, and a record of source code rather than of a web page — paths
47
+ * plus a git sha — is the `anchor` component, which
48
+ * {@link https://jsr.io/@yaks/git | @yaks/git} owns.
49
+ *
50
+ * @module
51
+ */ export * from "./comp.js";
52
+ export * from "./url.js";
53
+ export * from "./scrub.js";
54
+ export * from "./freeze.js";
55
+ export * from "./host.js";
56
+ export * from "./plugin.js";
57
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkDC,GAED,0BAAyB;AACzB,yBAAwB;AACxB,2BAA0B;AAC1B,4BAA2B;AAC3B,0BAAyB;AACzB,4BAA2B"}
@@ -0,0 +1,22 @@
1
+ import { type Plugin } from "@yaks/graph/plugin";
2
+ /**
3
+ * The page plugin: the `web` component, and the canonical address.
4
+ *
5
+ * ```ts
6
+ * import { graph } from '@yaks/graph'
7
+ * import { loadVocab } from '@yaks/vocab'
8
+ * import { docDoc, docs } from '@yaks/doc'
9
+ * import { pageDoc, pages } from '@yaks/page'
10
+ *
11
+ * let vocab = loadVocab([docDoc, pageDoc])
12
+ * // let g = graph({ storage, vocab, plugins: [docs(), pages()] })
13
+ * ```
14
+ *
15
+ * {@link https://jsr.io/@yaks/doc | @yaks/doc} is loaded beside it rather than
16
+ * redefined inside it: a page's title is `doc{title}`, and a vocabulary refuses
17
+ * a component declared twice.
18
+ *
19
+ * Capturing a page — fetching it and storing its bytes — is `./effects`, which
20
+ * needs an archiver named in the configuration.
21
+ */ export declare let pages: () => Plugin;
22
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sources":["../plugin.ts"],"names":[],"mappings":"AAiBA,SAAe,KAAK,MAAM,kCAAuC;AAUjE;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,YAAI,aAAY,OAIrB"}
@@ -0,0 +1,10 @@
1
+ import type { Route } from "@yaks/api";
2
+ import type { Storage } from "@yaks/graph";
3
+ import { type Blobs } from "@yaks/blob";
4
+ import { type Options } from "./host.js";
5
+ /** The path prefix an archived page is served under. */ export declare let PREFIX: string;
6
+ /** `GET /page/<eid>`. */ export declare let routes: (host: {
7
+ storage: Storage;
8
+ blobs: Blobs;
9
+ }, options?: Options) => Route[];
10
+ //# sourceMappingURL=routes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sources":["../routes.ts"],"names":[],"mappings":"AAgBA,cAAc,KAAK,yBAA8B;AACjD,cAA4B,OAAO,2BAAgC;AAEnE,SAAS,KAAK,KAAK,0BAAuC;AAE1D,SAAkB,KAAK,OAAO,oBAAmB;AAEjD,sDAAsD,GACtD,OAAO,YAAI,eAAiB;AAO5B,uBAAuB,GACvB,OAAO,YAAI,SACT;EAAQ,SAAS;EAAS,OAAO;GACjC,UAAS,YACR,QAgCF"}
@@ -0,0 +1,14 @@
1
+ /** An archived document, and the title it gave itself. */ export type Scrubbed = {
2
+ /** the document with every external reference removed */ html: string;
3
+ /** its `<title>`, when it had one — what the page calls itself */ title?: string;
4
+ };
5
+ /**
6
+ * One document with every external reference removed, and its title.
7
+ *
8
+ * ```ts
9
+ * import { scrub } from '@yaks/page'
10
+ *
11
+ * scrub('<title>Hi</title><img src="https://elsewhere/x.png">').title // 'Hi'
12
+ * ```
13
+ */ export declare let scrub: (raw: string) => Scrubbed;
14
+ //# sourceMappingURL=scrub.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scrub.d.ts","sources":["../scrub.ts"],"names":[],"mappings":"AAwBA,wDAAwD,GACxD,YAAY;EACV,uDAAuD,GACvD,MAAM,MAAM;EACZ,gEAAgE,GAChE,QAAQ,MAAM;;AA4BhB;;;;;;;;CAQC,GACD,OAAO,YAAI,QAAS,KAAK,MAAM,KAAG,SA6CjC"}