@yaks/doc 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.
- package/LICENSE +202 -0
- package/README.md +216 -2
- package/_dist/comp.d.ts +23 -0
- package/_dist/comp.d.ts.map +1 -0
- package/_dist/freshness.d.ts +10 -0
- package/_dist/freshness.d.ts.map +1 -0
- package/_dist/graph.d.ts +3 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/mod.d.ts +66 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/plugin.d.ts +20 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/views.d.ts +3 -0
- package/_dist/views.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/body.js +12 -0
- package/body.js.map +1 -0
- package/body.ts +19 -0
- package/comp.js +65 -0
- package/comp.js.map +1 -0
- package/comp.ts +72 -0
- package/deno.json +1 -0
- package/freshness.js +46 -0
- package/freshness.js.map +1 -0
- package/freshness.ts +35 -0
- package/graph.js +8 -0
- package/graph.js.map +1 -0
- package/graph.ts +9 -0
- package/mod.js +66 -0
- package/mod.js.map +1 -0
- package/mod.ts +67 -0
- package/package.json +32 -4
- package/plugin.js +28 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +29 -0
- package/views.js +28 -0
- package/views.js.map +1 -0
- package/views.ts +31 -0
- package/vocab.js +14 -0
- package/vocab.js.map +1 -0
- package/vocab.json +48 -0
- 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,217 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @yaks/doc
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A shared `doc` component for an entity's title and Markdown body, with portable
|
|
4
|
+
views for displaying both. Applications use the same text for editing, display,
|
|
5
|
+
and search while keeping domain-specific data in separate components.
|
|
6
|
+
|
|
7
|
+
A **doc** is the [component](../graph/README.md#data-model) carrying the text a
|
|
8
|
+
person reads: `doc: { title: 'Meeting notes', body: 'Ana chaired…' }`. Its
|
|
9
|
+
**title** is the one line an [entity](../graph/README.md#data-model) is known by
|
|
10
|
+
(`doc.title`); its **body** is the prose as Markdown (`doc.body`). Neither
|
|
11
|
+
property is required.
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
Load `docDoc` beside your own [vocabulary](../vocab/README.md#vocabulary) and
|
|
16
|
+
compose `docs()` once per [graph](../graph/README.md#data-model). The
|
|
17
|
+
[storage](../graph/README.md#data-model) you supply holds the title and body.
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { docDoc, docs } from '@yaks/doc'
|
|
21
|
+
import { graph, token } from '@yaks/graph'
|
|
22
|
+
import { ram } from '@yaks/ram'
|
|
23
|
+
import { equal } from '@yaks/testing'
|
|
24
|
+
import { loadVocab } from '@yaks/vocab'
|
|
25
|
+
|
|
26
|
+
const vocab = loadVocab([docDoc])
|
|
27
|
+
const g = graph({ storage: ram(vocab), vocab, plugins: [docs()] })
|
|
28
|
+
await g.install()
|
|
29
|
+
await g.apply([{
|
|
30
|
+
entity: { eid: 'meeting-1' },
|
|
31
|
+
doc: { title: 'Meeting notes', body: 'The release is scheduled for Friday.' },
|
|
32
|
+
}])
|
|
33
|
+
const body = 'The release is scheduled for Friday.'
|
|
34
|
+
equal(await g.read('.doc'), [{
|
|
35
|
+
entity: { eid: 'meeting-1' },
|
|
36
|
+
doc: { title: 'Meeting notes', body },
|
|
37
|
+
$was: { doc: { body: token(body) } },
|
|
38
|
+
}])
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Packages that need `doc`, such as [@yaks/mail](../mail/README.md), depend on
|
|
42
|
+
this package rather than declare a second copy. Compose its vocabulary once:
|
|
43
|
+
loading a component declaration twice is refused.
|
|
44
|
+
|
|
45
|
+
## Install
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
deno add jsr:@yaks/doc
|
|
49
|
+
# Node projects can use: npx jsr add @yaks/doc
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Exports
|
|
53
|
+
|
|
54
|
+
| Import | Exports | Purpose |
|
|
55
|
+
| ----------------- | ---------------------------------------------------------------- | ------------------------------------------------------------------ |
|
|
56
|
+
| `@yaks/doc` | `docDoc`, `docs`, `DOC`, `TITLE`, `BODY`, `witnessed`, `guarded` | Vocabulary document, plugin factory, and component/property names. |
|
|
57
|
+
| `@yaks/doc/vocab` | `docDoc`, `docs`, `description` | Vocabulary documents and package description for a loader. |
|
|
58
|
+
| `@yaks/doc/graph` | `plugins` | Plugin array factory for a loader. |
|
|
59
|
+
| `@yaks/doc/views` | `views` | Portable `Title` and `Body` views. |
|
|
60
|
+
|
|
61
|
+
Root `docs()` returns a [plugin](../graph/README.md#data-model) with the
|
|
62
|
+
vocabulary and a read hook carrying `$was.doc.body` when an answer shows the
|
|
63
|
+
body. In `./vocab`, `docs` is an array of vocabulary documents. `plugins()`
|
|
64
|
+
returns the root plugin in an array; it contributes no write-time rules.
|
|
65
|
+
|
|
66
|
+
```ts
|
|
67
|
+
import { BODY, DOC, docs as plugin, TITLE } from '@yaks/doc'
|
|
68
|
+
import { docs } from '@yaks/doc/vocab'
|
|
69
|
+
import { plugins } from '@yaks/doc/graph'
|
|
70
|
+
import { equal } from '@yaks/testing'
|
|
71
|
+
import { loadVocab } from '@yaks/vocab'
|
|
72
|
+
|
|
73
|
+
const vocab = loadVocab(docs)
|
|
74
|
+
equal(vocab.props(DOC), [TITLE, BODY])
|
|
75
|
+
equal(plugins()[0].name, plugin().name)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Freshness
|
|
79
|
+
|
|
80
|
+
A **body token** is the graph's SHA-256 of the body a reader saw. Document reads
|
|
81
|
+
carry it as `$was.doc.body`. Pass it back on a `graph_apply` bundle, or as `was`
|
|
82
|
+
with `task_update`'s `body`. `yak graph show` prints it as `was:`. The graph
|
|
83
|
+
refuses a stale replacement with the current body and its token, atomically with
|
|
84
|
+
the rest of the batch. Omitting the token keeps a blind write.
|
|
85
|
+
|
|
86
|
+
`witnessed(bundle)` adds the body token to a read answer. `guarded(bundle, was)`
|
|
87
|
+
adds the supplied token to a body replacement, preserving any other guards;
|
|
88
|
+
`undefined` leaves it unchanged, and `null` guards an absent body.
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { docDoc, docs, guarded } from '@yaks/doc'
|
|
92
|
+
import { graph } from '@yaks/graph'
|
|
93
|
+
import { ram } from '@yaks/ram'
|
|
94
|
+
import { equal } from '@yaks/testing'
|
|
95
|
+
import { loadVocab } from '@yaks/vocab'
|
|
96
|
+
|
|
97
|
+
const vocab = loadVocab([docDoc])
|
|
98
|
+
const g = graph({ vocab, storage: ram(vocab), plugins: [docs()] })
|
|
99
|
+
await g.apply([{ entity: { eid: 'notes' }, doc: { body: 'First draft' } }])
|
|
100
|
+
const [read] = await g.get(['notes'])
|
|
101
|
+
await g.apply([guarded({
|
|
102
|
+
entity: read.entity,
|
|
103
|
+
doc: { body: 'Revised draft' },
|
|
104
|
+
}, read.$was!.doc.body)])
|
|
105
|
+
equal((await g.get(['notes']))[0].doc, { body: 'Revised draft' })
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Views
|
|
109
|
+
|
|
110
|
+
`views` is a [registry](../render/README.md) containing a `Title` view for a
|
|
111
|
+
non-null title and a `Body` view for a non-null body. The body is parsed by
|
|
112
|
+
[@yaks/markdown](../markdown/README.md). A rendering backend supplies the
|
|
113
|
+
output: [@yaks/text](../text/README.md) produces Markdown or plain text, and
|
|
114
|
+
[@yaks/preact](../preact/README.md) produces browser nodes. A missing title
|
|
115
|
+
leaves selection to other registered views, such as a fallback title using the
|
|
116
|
+
eid. `Body` prepares its Markdown implementation through
|
|
117
|
+
[`prepared`](../render/README.md#preparation) before drawing. An empty string
|
|
118
|
+
still selects the corresponding view and renders empty text.
|
|
119
|
+
|
|
120
|
+
```ts
|
|
121
|
+
import { docDoc } from '@yaks/doc'
|
|
122
|
+
import { views } from '@yaks/doc/views'
|
|
123
|
+
import { prepared, resolve } from '@yaks/render'
|
|
124
|
+
import { equal } from '@yaks/testing'
|
|
125
|
+
import { render } from '@yaks/text'
|
|
126
|
+
import { loadVocab } from '@yaks/vocab'
|
|
127
|
+
|
|
128
|
+
const ready = await prepared(views)
|
|
129
|
+
const vocab = loadVocab([docDoc])
|
|
130
|
+
const bundle = {
|
|
131
|
+
entity: { eid: 'meeting-1' },
|
|
132
|
+
doc: { title: 'Meeting notes', body: 'Read **carefully**' },
|
|
133
|
+
}
|
|
134
|
+
equal(render(ready, bundle, 'Title', vocab), 'Meeting notes')
|
|
135
|
+
equal(render(ready, bundle, 'Body', vocab), 'Read **carefully**')
|
|
136
|
+
equal(
|
|
137
|
+
render(
|
|
138
|
+
ready,
|
|
139
|
+
{ entity: { eid: 'empty' }, doc: { title: '' } },
|
|
140
|
+
'Title',
|
|
141
|
+
vocab,
|
|
142
|
+
),
|
|
143
|
+
'',
|
|
144
|
+
)
|
|
145
|
+
equal(
|
|
146
|
+
resolve(
|
|
147
|
+
ready,
|
|
148
|
+
{ entity: { eid: 'empty' }, doc: { body: 'No title' } },
|
|
149
|
+
'Title',
|
|
150
|
+
vocab,
|
|
151
|
+
),
|
|
152
|
+
undefined,
|
|
153
|
+
)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Optional body storage
|
|
157
|
+
|
|
158
|
+
The body declares `store: 'blob'`, a
|
|
159
|
+
[keyword](../vocab/README.md#extension-keywords) owned by
|
|
160
|
+
[@yaks/blob](../blob/README.md). Without `blobKeywords`, it remains an ordinary
|
|
161
|
+
text property. Registering the keyword makes the declaration available to the
|
|
162
|
+
blob plugin; it does not configure storage by itself.
|
|
163
|
+
|
|
164
|
+
```ts
|
|
165
|
+
import { blobKeywords } from '@yaks/blob'
|
|
166
|
+
import { docDoc } from '@yaks/doc'
|
|
167
|
+
import { equal } from '@yaks/testing'
|
|
168
|
+
import { loadVocab } from '@yaks/vocab'
|
|
169
|
+
|
|
170
|
+
const plain = loadVocab([docDoc])
|
|
171
|
+
const addressed = loadVocab([docDoc], [blobKeywords])
|
|
172
|
+
equal(plain.prop('doc', 'body')!.keywords.store, undefined)
|
|
173
|
+
equal(addressed.prop('doc', 'body')!.keywords.store, 'blob')
|
|
174
|
+
equal(addressed.prop('doc', 'body')!.scalar, 'text')
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Compose the blob plugin and configure read resolution as shown in
|
|
178
|
+
[@yaks/blob's storage example](../blob/README.md#store-a-body) to keep callers
|
|
179
|
+
writing and reading text while storage holds content addresses. Both title and
|
|
180
|
+
body also declare `search: true`; composing [@yaks/fts](../fts/README.md)
|
|
181
|
+
provides search.
|
|
182
|
+
|
|
183
|
+
## Kind order
|
|
184
|
+
|
|
185
|
+
`doc` is a [kind](../vocab/README.md#vocabulary) and declares no `before`. Your
|
|
186
|
+
vocabulary can put a more specific kind before it for display:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
import { docDoc } from '@yaks/doc'
|
|
190
|
+
import { equal } from '@yaks/testing'
|
|
191
|
+
import { loadVocab } from '@yaks/vocab'
|
|
192
|
+
|
|
193
|
+
const vocab = loadVocab([docDoc, {
|
|
194
|
+
$defs: {
|
|
195
|
+
recipe: {
|
|
196
|
+
type: 'object',
|
|
197
|
+
component: true,
|
|
198
|
+
kind: true,
|
|
199
|
+
before: ['doc'],
|
|
200
|
+
properties: {},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
}])
|
|
204
|
+
equal(vocab.kindOf({ recipe: {}, doc: { title: 'Lemon cake' } }), 'recipe')
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Limits
|
|
208
|
+
|
|
209
|
+
This package provides no storage, search index, revisions, or access control.
|
|
210
|
+
[@yaks/blob](../blob/README.md) owns body storage, [@yaks/fts](../fts/README.md)
|
|
211
|
+
owns search, and [@yaks/member](../member/README.md) owns access control. A
|
|
212
|
+
slug, an excerpt, and timestamps belong in other components, rather than in
|
|
213
|
+
`doc`.
|
|
214
|
+
|
|
215
|
+
## License
|
|
216
|
+
|
|
217
|
+
Apache-2.0
|
package/_dist/comp.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
/** The component carrying the text a person reads. */ export declare let DOC: string;
|
|
3
|
+
/** The property carrying the one-line name. */ export declare let TITLE: string;
|
|
4
|
+
/** The property carrying the prose. */ export declare let BODY: string;
|
|
5
|
+
/**
|
|
6
|
+
* The document vocabulary, to load beside your own:
|
|
7
|
+
* `loadVocab([docDoc, ...mine])`. It declares nothing about what a task or a
|
|
8
|
+
* letter is — those are plain entities in your own vocabulary — only the title
|
|
9
|
+
* and the body they read back as.
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
13
|
+
* import { docDoc } from '@yaks/doc'
|
|
14
|
+
*
|
|
15
|
+
* let vocab = loadVocab([docDoc])
|
|
16
|
+
* // { entity: { eid: 'r1' }, doc: { title: 'Lemon cake', body: '3 lemons…' } }
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Register {@link https://jsr.io/@yaks/blob | @yaks/blob}'s `blobKeywords` when
|
|
20
|
+
* you load and `body` becomes content-addressed; register nothing and it is a
|
|
21
|
+
* text property. The document is the same either way.
|
|
22
|
+
*/ export declare let docDoc: VocabDoc;
|
|
23
|
+
//# sourceMappingURL=comp.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comp.d.ts","sources":["../comp.ts"],"names":[],"mappings":"AAyCA,cAAc,QAAQ,2BAAgC;AAGtD,oDAAoD,GACpD,OAAO,YAAI,YAAW;AAEtB,6CAA6C,GAC7C,OAAO,YAAI,cAAe;AAE1B,qCAAqC,GACrC,OAAO,YAAI,aAAa;AAExB;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,YAAI,QAAQ,SAAc"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Bundle } from "@yaks/graph";
|
|
2
|
+
/** Carry the token for the body this answer shows. A projected title alone
|
|
3
|
+
* says nothing about the body and must not claim it was absent.
|
|
4
|
+
*
|
|
5
|
+
* The token is hashed the first time it is read, by a caller or by whatever
|
|
6
|
+
* serializes the answer. A body can be megabytes, and most reads never guard
|
|
7
|
+
* a write with it: a search hashed 27 MB of bodies to name twenty hits. */ export declare let witnessed: (b: Bundle) => Bundle;
|
|
8
|
+
/** Guard a body replacement when its caller supplies a read token. Omission
|
|
9
|
+
* keeps a blind write; null explicitly guards an absent body. */ export declare let guarded: (b: Bundle, was: string | null | undefined) => Bundle;
|
|
10
|
+
//# sourceMappingURL=freshness.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"freshness.d.ts","sources":["../freshness.ts"],"names":[],"mappings":"AAGA,cAAc,MAAM,2BAAsC;AAI1D;;;;;yEAKyE,GACzE,OAAO,YAAI,YAAa,GAAG,WAAS,OAUnC;AAED;+DAC+D,GAC/D,OAAO,YAAI,UAAW,GAAG,QAAQ,KAAK,MAAM,GAAG,IAAI,GAAG,SAAS,KAAG,OAOjE"}
|
package/_dist/graph.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.d.ts","sources":["../graph.ts"],"names":[],"mappings":"AAIA,cAAc,MAAM,2BAAgC;AAGpD,2CAA2C,GAC3C,OAAO,YAAI,eAAc,SAAsB"}
|
package/_dist/mod.d.ts
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @yaks/doc — the text a person reads: the `doc{title, body}` component for a
|
|
3
|
+
* {@link https://jsr.io/@yaks/graph | @yaks/graph}.
|
|
4
|
+
*
|
|
5
|
+
* Suppose a book club keeps its reading list, its potluck sign-up and the
|
|
6
|
+
* minutes of last Tuesday in one graph. Three different things — and every one
|
|
7
|
+
* of them has a name and some prose. This package is that shared part:
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* // { entity: { eid: 'm1' },
|
|
11
|
+
* // doc: { title: 'Minutes, 3 March', body: 'Ana chaired…' },
|
|
12
|
+
* // minutes: { chaired_by: ana } }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* `doc` describes one aspect of an entity, not the whole entity. Adding it to
|
|
16
|
+
* something makes that thing readable without making it stop being what it
|
|
17
|
+
* was, and one search index, one editor and one card renderer are written
|
|
18
|
+
* against `doc` rather than against twenty tables that each grew a `title`
|
|
19
|
+
* property.
|
|
20
|
+
*
|
|
21
|
+
* ## Two properties `title` is the one line the entity is known by. `body` is
|
|
22
|
+
* the prose, as markdown. Nothing else: a slug is addressing, an excerpt is
|
|
23
|
+
* derived, a format is a rendering decision, and the clock belongs to the graph
|
|
24
|
+
* — each is its own component on the same entity.
|
|
25
|
+
*
|
|
26
|
+
* ## The body may be content-addressed, and `doc` never knows `body` declares
|
|
27
|
+
* `store: "blob"`, a keyword this package names but does not import. Load the
|
|
28
|
+
* vocabulary without {@link https://jsr.io/@yaks/blob | @yaks/blob}'s
|
|
29
|
+
* `blobKeywords` and `body` is an ordinary text property; load it with them and
|
|
30
|
+
* compose `blobs()`, and the text is swapped for its address on the way into
|
|
31
|
+
* the row and back on the way out. The same document, the same writes, the same
|
|
32
|
+
* reads — so a graph can grow into content-addressed storage without a
|
|
33
|
+
* migration of its vocabulary.
|
|
34
|
+
*
|
|
35
|
+
* ```ts
|
|
36
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
37
|
+
* import { graph } from '@yaks/graph'
|
|
38
|
+
* import { ram } from '@yaks/ram'
|
|
39
|
+
* import { docDoc, docs } from '@yaks/doc'
|
|
40
|
+
*
|
|
41
|
+
* let vocab = loadVocab([docDoc])
|
|
42
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins: [docs()] })
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* ## Who else uses it
|
|
46
|
+
* {@link https://jsr.io/@yaks/mail | @yaks/mail} keeps a letter's subject in
|
|
47
|
+
* `doc.title` and the letter itself in `doc.body`, so a letter is displayed by
|
|
48
|
+
* the same renderer as everything else. Packages that need `doc` depend on this
|
|
49
|
+
* one and leave the composing to you — a vocabulary rejects a component
|
|
50
|
+
* declared twice, so the component is declared in exactly one place.
|
|
51
|
+
*
|
|
52
|
+
* ## Kind order
|
|
53
|
+
* `doc` is a kind, and it deliberately declares no `before`: a `before` may only
|
|
54
|
+
* name a kind the loaded vocabulary declares, so a base package cannot order
|
|
55
|
+
* itself against components it does not ship. Your own vocabulary decides which
|
|
56
|
+
* wins — `before: ['doc']` on the component that is the more specific thing an
|
|
57
|
+
* entity IS.
|
|
58
|
+
*
|
|
59
|
+
* It imports no platform API, so the same document loads on a server, in a
|
|
60
|
+
* worker, and in a browser tab.
|
|
61
|
+
*
|
|
62
|
+
* @module
|
|
63
|
+
*/ export * from "./comp.js";
|
|
64
|
+
export * from "./plugin.js";
|
|
65
|
+
export * from "./freshness.js";
|
|
66
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8DC,GAED,0BAAyB;AACzB,4BAA2B;AAC3B,+BAA8B"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Plugin } from "@yaks/graph";
|
|
2
|
+
/**
|
|
3
|
+
* The document plugin: `doc{title, body}` and its read token.
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { graph } from '@yaks/graph'
|
|
7
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
8
|
+
* import { ram } from '@yaks/ram'
|
|
9
|
+
* import { docDoc, docs } from '@yaks/doc'
|
|
10
|
+
*
|
|
11
|
+
* let vocab = loadVocab([docDoc])
|
|
12
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins: [docs()] })
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Compose it once per graph. A vocabulary rejects a component declared twice,
|
|
16
|
+
* so a package that needs `doc` — {@link https://jsr.io/@yaks/mail | @yaks/mail}
|
|
17
|
+
* is one — depends on this one and leaves composing it to you, rather than
|
|
18
|
+
* shipping a second copy of the component.
|
|
19
|
+
*/ export declare let docs: () => Plugin;
|
|
20
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sources":["../plugin.ts"],"names":[],"mappings":"AAEA,cAAc,MAAM,2BAAgC;AAIpD;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,YAAI,YAAW,OAIpB"}
|
package/_dist/views.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.d.ts","sources":["../views.ts"],"names":[],"mappings":"AAUA,SAAiB,KAAK,QAAQ,4BAAiC;AAQ/D,0DAA0D,GAC1D,OAAO,YAAI,OAAO,SAWhB"}
|
package/_dist/vocab.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { VocabDoc } from "@yaks/vocab";
|
|
2
|
+
import { docDoc } from "./comp.js";
|
|
3
|
+
export { docDoc };
|
|
4
|
+
/** What this package is: its manifest's description, the one place it is
|
|
5
|
+
* written, which a host stamps on each document here. */ export declare let description: string;
|
|
6
|
+
/** Every document this plugin declares. */ export declare let docs: VocabDoc[];
|
|
7
|
+
//# sourceMappingURL=vocab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.d.ts","sources":["../vocab.ts"],"names":[],"mappings":"AAIA,cAAc,QAAQ,2BAAgC;AACtD,SAAS,MAAM,oBAAmB;AAGlC,SAAS,MAAM,GAAE;AAEjB;uDACuD,GACvD,OAAO,YAAI,aAAa,MAAM,CAAuB;AAErD,yCAAyC,GACzC,OAAO,YAAI,MAAM,WAAqB"}
|
package/body.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// A document body lowers Markdown to the caller's structural elements.
|
|
2
|
+
import { parse, render } from "@yaks/markdown/structural";
|
|
3
|
+
import { BODY, DOC } from "./comp.js";
|
|
4
|
+
export let body = (b, h)=>{
|
|
5
|
+
let value = b[DOC]?.[BODY];
|
|
6
|
+
return h('div', {
|
|
7
|
+
class: 'Md'
|
|
8
|
+
}, render(parse(typeof value == 'string' ? value : '', {
|
|
9
|
+
breaks: false
|
|
10
|
+
}), h));
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=body.js.map
|
package/body.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"body.js","sources":["./body.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,SAAS,KAAK,EAAE,MAAM,yCAA8C;AAEpE,SAAS,IAAI,EAAE,GAAG,oBAAmB;AAErC,OAAO,IAAI,OAAkB,CAAC,GAAG;EAC/B,IAAI,QAAS,CAAC,CAAC,IAAI,EAA0C,CAAC,KAAK;EACnE,OAAO,EACL,OACA;IAAE,OAAO;EAAK,GACd,OACE,MACE,OAAO,SAAS,WAAW,QAAQ,IACnC;IAAE,QAAQ;EAAM,IAElB;AAGN,EAAC"}
|
package/body.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// A document body lowers Markdown to the caller's structural elements.
|
|
2
|
+
import { parse, render } from '@yaks/markdown/structural'
|
|
3
|
+
import type { Rendering } from 'jsr:@yaks/render@0.2.36'
|
|
4
|
+
import { BODY, DOC } from './comp.js'
|
|
5
|
+
|
|
6
|
+
export let body: Rendering = (b, h) => {
|
|
7
|
+
let value = (b[DOC] as Record<string, unknown> | undefined)?.[BODY]
|
|
8
|
+
return h(
|
|
9
|
+
'div',
|
|
10
|
+
{ class: 'Md' },
|
|
11
|
+
render(
|
|
12
|
+
parse(
|
|
13
|
+
typeof value == 'string' ? value : '',
|
|
14
|
+
{ breaks: false },
|
|
15
|
+
),
|
|
16
|
+
h,
|
|
17
|
+
),
|
|
18
|
+
)
|
|
19
|
+
}
|