@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/comp.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// The one component this package ships, as a vocabulary document to load
|
|
2
|
+
// beside your own.
|
|
3
|
+
//
|
|
4
|
+
// doc{title, body} the text a person reads
|
|
5
|
+
//
|
|
6
|
+
// The component itself is declared in `./vocab.json` — plain JSON Schema,
|
|
7
|
+
// readable by anything that reads JSON. This file re-exports it under the name
|
|
8
|
+
// callers import and keeps the explanation of why it is shaped this way.
|
|
9
|
+
//
|
|
10
|
+
// It describes one aspect of an entity, not the whole entity. A task, a letter,
|
|
11
|
+
// a recipe and a comment are all different things, and every one of them has
|
|
12
|
+
// something a person reads — so the title and the body live in one component
|
|
13
|
+
// any kind can carry, instead of a `title` property repeated down twenty
|
|
14
|
+
// tables. That is what makes one search index, one editor and one card renderer
|
|
15
|
+
// possible: they are written against `doc`, and they work on anything that
|
|
16
|
+
// carries it.
|
|
17
|
+
//
|
|
18
|
+
// Two properties, and why not A third. A `slug`, an `excerpt`, a `format`, an
|
|
19
|
+
// `updated_at` all look like they belong here and none of them do: a slug is
|
|
20
|
+
// addressing, an excerpt is derived, a format is a rendering decision, and the
|
|
21
|
+
// clock is the graph's. Each is its own component on the same entity, which is
|
|
22
|
+
// the whole point of components.
|
|
23
|
+
//
|
|
24
|
+
// `body` Declares `store: "blob"`, which is @yaks/blob's keyword — this package
|
|
25
|
+
// does not import that package (Jeff, 2026-09-05: "yak-doc does *not* depend on
|
|
26
|
+
// yak-blob. it is `{title: string, body: text}`"). A keyword is carried by the
|
|
27
|
+
// loader and interpreted by whoever registered it, so the declaration does
|
|
28
|
+
// nothing until somebody composes @yaks/blob in: load without `blobKeywords`
|
|
29
|
+
// and `body` is an ordinary text property; load with them and the text is
|
|
30
|
+
// swapped for its content address on the way into the row and back on the way
|
|
31
|
+
// out, without `doc` or the application being involved. The `$vocabulary` URI
|
|
32
|
+
// is written out in the file for the same reason — it names the keyword's
|
|
33
|
+
// namespace without depending on the package that interprets it.
|
|
34
|
+
//
|
|
35
|
+
// No `before`. The fleet's own `doc` sorts before its `alias` kind, and a
|
|
36
|
+
// `before` may only name a kind the loaded vocabulary declares — so a package
|
|
37
|
+
// that ordered itself against a kind it does not ship could not load on its
|
|
38
|
+
// own. Which of `doc` and your own kind wins is for your vocabulary to decide:
|
|
39
|
+
// declare `before: ['doc']` on the component that is the more specific thing an
|
|
40
|
+
// entity IS, the way @yaks/task's `task` and a yaks.app manifest both do.
|
|
41
|
+
import doc from './vocab.json' with {
|
|
42
|
+
type: 'json'
|
|
43
|
+
};
|
|
44
|
+
/** The component carrying the text a person reads. */ export let DOC = 'doc';
|
|
45
|
+
/** The property carrying the one-line name. */ export let TITLE = 'title';
|
|
46
|
+
/** The property carrying the prose. */ export let BODY = 'body';
|
|
47
|
+
/**
|
|
48
|
+
* The document vocabulary, to load beside your own:
|
|
49
|
+
* `loadVocab([docDoc, ...mine])`. It declares nothing about what a task or a
|
|
50
|
+
* letter is — those are plain entities in your own vocabulary — only the title
|
|
51
|
+
* and the body they read back as.
|
|
52
|
+
*
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
55
|
+
* import { docDoc } from '@yaks/doc'
|
|
56
|
+
*
|
|
57
|
+
* let vocab = loadVocab([docDoc])
|
|
58
|
+
* // { entity: { eid: 'r1' }, doc: { title: 'Lemon cake', body: '3 lemons…' } }
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* Register {@link https://jsr.io/@yaks/blob | @yaks/blob}'s `blobKeywords` when
|
|
62
|
+
* you load and `body` becomes content-addressed; register nothing and it is a
|
|
63
|
+
* text property. The document is the same either way.
|
|
64
|
+
*/ export let docDoc = doc;
|
|
65
|
+
//# sourceMappingURL=comp.js.map
|
package/comp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"comp.js","sources":["./comp.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,mBAAmB;AACnB,EAAE;AACF,+CAA+C;AAC/C,EAAE;AACF,0EAA0E;AAC1E,+EAA+E;AAC/E,yEAAyE;AACzE,EAAE;AACF,gFAAgF;AAChF,6EAA6E;AAC7E,6EAA6E;AAC7E,yEAAyE;AACzE,gFAAgF;AAChF,2EAA2E;AAC3E,cAAc;AACd,EAAE;AACF,8EAA8E;AAC9E,6EAA6E;AAC7E,+EAA+E;AAC/E,+EAA+E;AAC/E,iCAAiC;AACjC,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,+EAA+E;AAC/E,2EAA2E;AAC3E,6EAA6E;AAC7E,0EAA0E;AAC1E,8EAA8E;AAC9E,8EAA8E;AAC9E,0EAA0E;AAC1E,iEAAiE;AACjE,EAAE;AACF,0EAA0E;AAC1E,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AAC/E,gFAAgF;AAChF,0EAA0E;AAG1E,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AAEpD,oDAAoD,GACpD,OAAO,IAAI,MAAM,MAAK;AAEtB,6CAA6C,GAC7C,OAAO,IAAI,QAAQ,QAAO;AAE1B,qCAAqC,GACrC,OAAO,IAAI,OAAO,OAAM;AAExB;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,IAAI,SAAmB,IAAG"}
|
package/comp.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The one component this package ships, as a vocabulary document to load
|
|
2
|
+
// beside your own.
|
|
3
|
+
//
|
|
4
|
+
// doc{title, body} the text a person reads
|
|
5
|
+
//
|
|
6
|
+
// The component itself is declared in `./vocab.json` — plain JSON Schema,
|
|
7
|
+
// readable by anything that reads JSON. This file re-exports it under the name
|
|
8
|
+
// callers import and keeps the explanation of why it is shaped this way.
|
|
9
|
+
//
|
|
10
|
+
// It describes one aspect of an entity, not the whole entity. A task, a letter,
|
|
11
|
+
// a recipe and a comment are all different things, and every one of them has
|
|
12
|
+
// something a person reads — so the title and the body live in one component
|
|
13
|
+
// any kind can carry, instead of a `title` property repeated down twenty
|
|
14
|
+
// tables. That is what makes one search index, one editor and one card renderer
|
|
15
|
+
// possible: they are written against `doc`, and they work on anything that
|
|
16
|
+
// carries it.
|
|
17
|
+
//
|
|
18
|
+
// Two properties, and why not A third. A `slug`, an `excerpt`, a `format`, an
|
|
19
|
+
// `updated_at` all look like they belong here and none of them do: a slug is
|
|
20
|
+
// addressing, an excerpt is derived, a format is a rendering decision, and the
|
|
21
|
+
// clock is the graph's. Each is its own component on the same entity, which is
|
|
22
|
+
// the whole point of components.
|
|
23
|
+
//
|
|
24
|
+
// `body` Declares `store: "blob"`, which is @yaks/blob's keyword — this package
|
|
25
|
+
// does not import that package (Jeff, 2026-09-05: "yak-doc does *not* depend on
|
|
26
|
+
// yak-blob. it is `{title: string, body: text}`"). A keyword is carried by the
|
|
27
|
+
// loader and interpreted by whoever registered it, so the declaration does
|
|
28
|
+
// nothing until somebody composes @yaks/blob in: load without `blobKeywords`
|
|
29
|
+
// and `body` is an ordinary text property; load with them and the text is
|
|
30
|
+
// swapped for its content address on the way into the row and back on the way
|
|
31
|
+
// out, without `doc` or the application being involved. The `$vocabulary` URI
|
|
32
|
+
// is written out in the file for the same reason — it names the keyword's
|
|
33
|
+
// namespace without depending on the package that interprets it.
|
|
34
|
+
//
|
|
35
|
+
// No `before`. The fleet's own `doc` sorts before its `alias` kind, and a
|
|
36
|
+
// `before` may only name a kind the loaded vocabulary declares — so a package
|
|
37
|
+
// that ordered itself against a kind it does not ship could not load on its
|
|
38
|
+
// own. Which of `doc` and your own kind wins is for your vocabulary to decide:
|
|
39
|
+
// declare `before: ['doc']` on the component that is the more specific thing an
|
|
40
|
+
// entity IS, the way @yaks/task's `task` and a yaks.app manifest both do.
|
|
41
|
+
|
|
42
|
+
import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
|
|
43
|
+
import doc from './vocab.json' with { type: 'json' }
|
|
44
|
+
|
|
45
|
+
/** The component carrying the text a person reads. */
|
|
46
|
+
export let DOC = 'doc'
|
|
47
|
+
|
|
48
|
+
/** The property carrying the one-line name. */
|
|
49
|
+
export let TITLE = 'title'
|
|
50
|
+
|
|
51
|
+
/** The property carrying the prose. */
|
|
52
|
+
export let BODY = 'body'
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The document vocabulary, to load beside your own:
|
|
56
|
+
* `loadVocab([docDoc, ...mine])`. It declares nothing about what a task or a
|
|
57
|
+
* letter is — those are plain entities in your own vocabulary — only the title
|
|
58
|
+
* and the body they read back as.
|
|
59
|
+
*
|
|
60
|
+
* ```ts
|
|
61
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
62
|
+
* import { docDoc } from '@yaks/doc'
|
|
63
|
+
*
|
|
64
|
+
* let vocab = loadVocab([docDoc])
|
|
65
|
+
* // { entity: { eid: 'r1' }, doc: { title: 'Lemon cake', body: '3 lemons…' } }
|
|
66
|
+
* ```
|
|
67
|
+
*
|
|
68
|
+
* Register {@link https://jsr.io/@yaks/blob | @yaks/blob}'s `blobKeywords` when
|
|
69
|
+
* you load and `body` becomes content-addressed; register nothing and it is a
|
|
70
|
+
* text property. The document is the same either way.
|
|
71
|
+
*/
|
|
72
|
+
export let docDoc: VocabDoc = doc
|
package/deno.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"publish":{"exclude":["**/*_test.ts"]},"name":"@yaks/doc","version":"0.2.36","license":"Apache-2.0","description":"A shared doc component for an entity's title and Markdown body, with portable views for displaying both.","exports":{".":"./mod.ts","./vocab":"./vocab.ts","./graph":"./graph.ts","./views":"./views.ts"},"imports":{"@yaks/doc":"./mod.ts","@yaks/doc/vocab":"./vocab.ts","@yaks/doc/graph":"./graph.ts","@yaks/doc/views":"./views.ts"}}
|
package/freshness.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// Document freshness at the read/write boundary. The graph owns the token
|
|
2
|
+
// and atomic precondition check; every document uses the same bundle guard.
|
|
3
|
+
import { token } from "@yaks/graph/sha256";
|
|
4
|
+
import { BODY, DOC } from "./comp.js";
|
|
5
|
+
/** Carry the token for the body this answer shows. A projected title alone
|
|
6
|
+
* says nothing about the body and must not claim it was absent.
|
|
7
|
+
*
|
|
8
|
+
* The token is hashed the first time it is read, by a caller or by whatever
|
|
9
|
+
* serializes the answer. A body can be megabytes, and most reads never guard
|
|
10
|
+
* a write with it: a search hashed 27 MB of bodies to name twenty hits. */ export let witnessed = (b)=>{
|
|
11
|
+
let doc = b[DOC];
|
|
12
|
+
if (!doc || !Object.hasOwn(doc, BODY)) return b;
|
|
13
|
+
let body = doc[BODY], made;
|
|
14
|
+
let was = Object.defineProperty({
|
|
15
|
+
...b.$was?.[DOC]
|
|
16
|
+
}, BODY, {
|
|
17
|
+
get: ()=>(made ??= {
|
|
18
|
+
token: token(body)
|
|
19
|
+
}).token,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
...b,
|
|
25
|
+
$was: {
|
|
26
|
+
...b.$was,
|
|
27
|
+
[DOC]: was
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
/** Guard a body replacement when its caller supplies a read token. Omission
|
|
32
|
+
* keeps a blind write; null explicitly guards an absent body. */ export let guarded = (b, was)=>{
|
|
33
|
+
let doc = b[DOC];
|
|
34
|
+
if (was === undefined || !doc || !Object.hasOwn(doc, BODY)) return b;
|
|
35
|
+
return {
|
|
36
|
+
...b,
|
|
37
|
+
$was: {
|
|
38
|
+
...b.$was,
|
|
39
|
+
[DOC]: {
|
|
40
|
+
...b.$was?.[DOC],
|
|
41
|
+
[BODY]: was
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=freshness.js.map
|
package/freshness.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"freshness.js","sources":["./freshness.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,4EAA4E;AAG5E,SAAS,KAAK,kCAAuC;AACrD,SAAS,IAAI,EAAE,GAAG,oBAAmB;AAErC;;;;;yEAKyE,GACzE,OAAO,IAAI,YAAY,CAAC;EACtB,IAAI,MAAM,CAAC,CAAC,IAAI;EAChB,IAAI,CAAC,OAAO,CAAC,OAAO,MAAM,CAAC,KAAK,OAAO,OAAO;EAC9C,IAAI,OAAO,GAAG,CAAC,KAAK,EAAE;EACtB,IAAI,MAAM,OAAO,cAAc,CAAC;IAAE,GAAG,EAAE,IAAI,EAAE,CAAC,IAAI;EAAC,GAAG,MAAM;IAC1D,KAAK,IAAM,CAAC,SAAS;QAAE,OAAO,MAAM;MAAM,CAAC,EAAE,KAAK;IAClD,YAAY;IACZ,cAAc;EAChB;EACA,OAAO;IAAE,GAAG,CAAC;IAAE,MAAM;MAAE,GAAG,EAAE,IAAI;MAAE,CAAC,IAAI,EAAE;IAAI;EAAE;AACjD,EAAC;AAED;+DAC+D,GAC/D,OAAO,IAAI,UAAU,CAAC,GAAW;EAC/B,IAAI,MAAM,CAAC,CAAC,IAAI;EAChB,IAAI,QAAQ,aAAa,CAAC,OAAO,CAAC,OAAO,MAAM,CAAC,KAAK,OAAO,OAAO;EACnE,OAAO;IACL,GAAG,CAAC;IACJ,MAAM;MAAE,GAAG,EAAE,IAAI;MAAE,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,IAAI,EAAE,CAAC,IAAI;QAAE,CAAC,KAAK,EAAE;MAAI;IAAE;EAC9D;AACF,EAAC"}
|
package/freshness.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Document freshness at the read/write boundary. The graph owns the token
|
|
2
|
+
// and atomic precondition check; every document uses the same bundle guard.
|
|
3
|
+
|
|
4
|
+
import type { Bundle, Comp } from 'jsr:@yaks/graph@0.2.36'
|
|
5
|
+
import { token } from '@yaks/graph/sha256'
|
|
6
|
+
import { BODY, DOC } from './comp.js'
|
|
7
|
+
|
|
8
|
+
/** Carry the token for the body this answer shows. A projected title alone
|
|
9
|
+
* says nothing about the body and must not claim it was absent.
|
|
10
|
+
*
|
|
11
|
+
* The token is hashed the first time it is read, by a caller or by whatever
|
|
12
|
+
* serializes the answer. A body can be megabytes, and most reads never guard
|
|
13
|
+
* a write with it: a search hashed 27 MB of bodies to name twenty hits. */
|
|
14
|
+
export let witnessed = (b: Bundle): Bundle => {
|
|
15
|
+
let doc = b[DOC] as Comp | undefined
|
|
16
|
+
if (!doc || !Object.hasOwn(doc, BODY)) return b
|
|
17
|
+
let body = doc[BODY], made: { token: string | null } | undefined
|
|
18
|
+
let was = Object.defineProperty({ ...b.$was?.[DOC] }, BODY, {
|
|
19
|
+
get: () => (made ??= { token: token(body) }).token,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
})
|
|
23
|
+
return { ...b, $was: { ...b.$was, [DOC]: was } }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Guard a body replacement when its caller supplies a read token. Omission
|
|
27
|
+
* keeps a blind write; null explicitly guards an absent body. */
|
|
28
|
+
export let guarded = (b: Bundle, was: string | null | undefined): Bundle => {
|
|
29
|
+
let doc = b[DOC] as Comp | undefined
|
|
30
|
+
if (was === undefined || !doc || !Object.hasOwn(doc, BODY)) return b
|
|
31
|
+
return {
|
|
32
|
+
...b,
|
|
33
|
+
$was: { ...b.$was, [DOC]: { ...b.$was?.[DOC], [BODY]: was } },
|
|
34
|
+
}
|
|
35
|
+
}
|
package/graph.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// The graph plugins this package contributes: the module a server imports at
|
|
2
|
+
// `@yaks/doc/graph`. There are no write-time rules here, only the component
|
|
3
|
+
// itself and its body read token.
|
|
4
|
+
import { docs as plugin } from "./plugin.js";
|
|
5
|
+
/** `doc{title, body}`, as a graph plugin. */ export let plugins = ()=>[
|
|
6
|
+
plugin()
|
|
7
|
+
];
|
|
8
|
+
//# sourceMappingURL=graph.js.map
|
package/graph.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph.js","sources":["./graph.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,kCAAkC;AAGlC,SAAS,QAAQ,MAAM,sBAAqB;AAE5C,2CAA2C,GAC3C,OAAO,IAAI,UAAU,IAAgB;IAAC;GAAS,CAAA"}
|
package/graph.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// The graph plugins this package contributes: the module a server imports at
|
|
2
|
+
// `@yaks/doc/graph`. There are no write-time rules here, only the component
|
|
3
|
+
// itself and its body read token.
|
|
4
|
+
|
|
5
|
+
import type { Plugin } from 'jsr:@yaks/graph@0.2.36'
|
|
6
|
+
import { docs as plugin } from './plugin.js'
|
|
7
|
+
|
|
8
|
+
/** `doc{title, body}`, as a graph plugin. */
|
|
9
|
+
export let plugins = (): Plugin[] => [plugin()]
|
package/mod.js
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.js.map
|
package/mod.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.js","sources":["./mod.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8DC,GAED,0BAAyB;AACzB,4BAA2B;AAC3B,+BAA8B"}
|
package/mod.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
*/
|
|
64
|
+
|
|
65
|
+
export * from './comp.js'
|
|
66
|
+
export * from './plugin.js'
|
|
67
|
+
export * from './freshness.js'
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yaks/doc",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.36",
|
|
4
|
+
"homepage": "https://jsr.io/@yaks/doc",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./_dist/mod.d.ts",
|
|
9
|
+
"default": "./mod.js"
|
|
10
|
+
},
|
|
11
|
+
"./vocab": {
|
|
12
|
+
"types": "./_dist/vocab.d.ts",
|
|
13
|
+
"default": "./vocab.js"
|
|
14
|
+
},
|
|
15
|
+
"./graph": {
|
|
16
|
+
"types": "./_dist/graph.d.ts",
|
|
17
|
+
"default": "./graph.js"
|
|
18
|
+
},
|
|
19
|
+
"./views": {
|
|
20
|
+
"types": "./_dist/views.d.ts",
|
|
21
|
+
"default": "./views.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"license": "Apache-2.0",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@yaks/graph": "0.2.36",
|
|
27
|
+
"@yaks/markdown": "0.2.36",
|
|
28
|
+
"@yaks/query": "0.2.36",
|
|
29
|
+
"@yaks/render": "0.2.36",
|
|
30
|
+
"@yaks/vocab": "0.2.36"
|
|
31
|
+
},
|
|
32
|
+
"description": "A shared doc component for an entity's title and Markdown body, with portable views for displaying both.",
|
|
33
|
+
"repository": "https://github.com/yak-sh/yak.git"
|
|
34
|
+
}
|
package/plugin.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Document reads carry the body token used by the graph precondition.
|
|
2
|
+
import { witnessed } from "./freshness.js";
|
|
3
|
+
import { docDoc } from "./comp.js";
|
|
4
|
+
/**
|
|
5
|
+
* The document plugin: `doc{title, body}` and its read token.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { graph } from '@yaks/graph'
|
|
9
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
10
|
+
* import { ram } from '@yaks/ram'
|
|
11
|
+
* import { docDoc, docs } from '@yaks/doc'
|
|
12
|
+
*
|
|
13
|
+
* let vocab = loadVocab([docDoc])
|
|
14
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins: [docs()] })
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Compose it once per graph. A vocabulary rejects a component declared twice,
|
|
18
|
+
* so a package that needs `doc` — {@link https://jsr.io/@yaks/mail | @yaks/mail}
|
|
19
|
+
* is one — depends on this one and leaves composing it to you, rather than
|
|
20
|
+
* shipping a second copy of the component.
|
|
21
|
+
*/ export let docs = ()=>({
|
|
22
|
+
name: '@yaks/doc',
|
|
23
|
+
vocab: [
|
|
24
|
+
docDoc
|
|
25
|
+
],
|
|
26
|
+
answer: (_ctx, bundles)=>bundles.map(witnessed)
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=plugin.js.map
|
package/plugin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["./plugin.ts"],"names":[],"mappings":"AAAA,sEAAsE;AAGtE,SAAS,SAAS,yBAAwB;AAC1C,SAAS,MAAM,oBAAmB;AAElC;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,IAAI,OAAO,IAAc,CAAC;IAC/B,MAAM;IACN,OAAO;MAAC;KAAO;IACf,QAAQ,CAAC,MAAM,UAAY,QAAQ,GAAG,CAAC;EACzC,CAAC,EAAC"}
|
package/plugin.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Document reads carry the body token used by the graph precondition.
|
|
2
|
+
|
|
3
|
+
import type { Plugin } from 'jsr:@yaks/graph@0.2.36'
|
|
4
|
+
import { witnessed } from './freshness.js'
|
|
5
|
+
import { docDoc } from './comp.js'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The document plugin: `doc{title, body}` and its read token.
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { graph } from '@yaks/graph'
|
|
12
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
13
|
+
* import { ram } from '@yaks/ram'
|
|
14
|
+
* import { docDoc, docs } from '@yaks/doc'
|
|
15
|
+
*
|
|
16
|
+
* let vocab = loadVocab([docDoc])
|
|
17
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins: [docs()] })
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Compose it once per graph. A vocabulary rejects a component declared twice,
|
|
21
|
+
* so a package that needs `doc` — {@link https://jsr.io/@yaks/mail | @yaks/mail}
|
|
22
|
+
* is one — depends on this one and leaves composing it to you, rather than
|
|
23
|
+
* shipping a second copy of the component.
|
|
24
|
+
*/
|
|
25
|
+
export let docs = (): Plugin => ({
|
|
26
|
+
name: '@yaks/doc',
|
|
27
|
+
vocab: [docDoc],
|
|
28
|
+
answer: (_ctx, bundles) => bundles.map(witnessed),
|
|
29
|
+
})
|
package/views.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// How a document reads, in every interface: its title is the line the entity
|
|
2
|
+
// is known by, and its body is markdown. Portable @yaks/render renderers, so
|
|
3
|
+
// the same two views print in a terminal (@yaks/text) and mount in a browser
|
|
4
|
+
// (@yaks/preact); which one draws them is the caller's `h`.
|
|
5
|
+
//
|
|
6
|
+
// An empty title is no title: a comment carries a `doc` for its body alone, and
|
|
7
|
+
// a view that answered with an empty string would hide the fallback a more
|
|
8
|
+
// general `Title` gives (the entity's id).
|
|
9
|
+
import { parse } from "@yaks/query/core";
|
|
10
|
+
import { define } from "@yaks/render";
|
|
11
|
+
import { BODY, DOC, TITLE } from "./comp.js";
|
|
12
|
+
let text = (b, prop)=>{
|
|
13
|
+
let v = b[DOC]?.[prop];
|
|
14
|
+
return typeof v == 'string' ? v : '';
|
|
15
|
+
};
|
|
16
|
+
/** `Title` and `Body` for anything that carries a `doc`. */ export let views = define([
|
|
17
|
+
{
|
|
18
|
+
view: 'Title',
|
|
19
|
+
match: parse(`.${DOC}.${TITLE}`),
|
|
20
|
+
render: (b, h)=>h('span', null, text(b, TITLE))
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
view: 'Body',
|
|
24
|
+
match: parse(`.${DOC}.${BODY}`),
|
|
25
|
+
load: ()=>import("./body.js").then((m)=>m.body)
|
|
26
|
+
}
|
|
27
|
+
]);
|
|
28
|
+
//# sourceMappingURL=views.js.map
|
package/views.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"views.js","sources":["./views.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,4DAA4D;AAC5D,EAAE;AACF,gFAAgF;AAChF,2EAA2E;AAC3E,2CAA2C;AAE3C,SAAS,KAAK,gCAAqC;AACnD,SAAS,MAAM,4BAAgD;AAC/D,SAAS,IAAI,EAAE,GAAG,EAAE,KAAK,oBAAmB;AAE5C,IAAI,OAAO,CAAC,GAA4B;EACtC,IAAI,IAAK,CAAC,CAAC,IAAI,EAA0C,CAAC,KAAK;EAC/D,OAAO,OAAO,KAAK,WAAW,IAAI;AACpC;AAEA,0DAA0D,GAC1D,OAAO,IAAI,QAAkB,OAAO;EAClC;IACE,MAAM;IACN,OAAO,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,OAAO;IAC/B,QAAQ,CAAC,GAAG,IAAM,EAAE,QAAQ,MAAM,KAAK,GAAG;EAC5C;EACA;IACE,MAAM;IACN,OAAO,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,MAAM;IAC9B,MAAM,IAAM,MAAM,CAAC,aAAa,IAAI,CAAC,CAAC,IAAM,EAAE,IAAI;EACpD;CACD,EAAC"}
|
package/views.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// How a document reads, in every interface: its title is the line the entity
|
|
2
|
+
// is known by, and its body is markdown. Portable @yaks/render renderers, so
|
|
3
|
+
// the same two views print in a terminal (@yaks/text) and mount in a browser
|
|
4
|
+
// (@yaks/preact); which one draws them is the caller's `h`.
|
|
5
|
+
//
|
|
6
|
+
// An empty title is no title: a comment carries a `doc` for its body alone, and
|
|
7
|
+
// a view that answered with an empty string would hide the fallback a more
|
|
8
|
+
// general `Title` gives (the entity's id).
|
|
9
|
+
|
|
10
|
+
import { parse } from '@yaks/query/core'
|
|
11
|
+
import { define, type Registry } from '@yaks/render'
|
|
12
|
+
import { BODY, DOC, TITLE } from './comp.js'
|
|
13
|
+
|
|
14
|
+
let text = (b: Record<string, unknown>, prop: string): string => {
|
|
15
|
+
let v = (b[DOC] as Record<string, unknown> | undefined)?.[prop]
|
|
16
|
+
return typeof v == 'string' ? v : ''
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** `Title` and `Body` for anything that carries a `doc`. */
|
|
20
|
+
export let views: Registry = define([
|
|
21
|
+
{
|
|
22
|
+
view: 'Title',
|
|
23
|
+
match: parse(`.${DOC}.${TITLE}`),
|
|
24
|
+
render: (b, h) => h('span', null, text(b, TITLE)),
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
view: 'Body',
|
|
28
|
+
match: parse(`.${DOC}.${BODY}`),
|
|
29
|
+
load: () => import('./body.js').then((m) => m.body),
|
|
30
|
+
},
|
|
31
|
+
])
|
package/vocab.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// The component declaration, and nothing else: the module a server or a browser
|
|
2
|
+
// page imports at `@yaks/doc/vocab`. It reaches no storage, no SQL and no
|
|
3
|
+
// runtime, so a browser tab loading this vocabulary loads nothing else.
|
|
4
|
+
import { docDoc } from "./comp.js";
|
|
5
|
+
import manifest from './package.json' with {
|
|
6
|
+
type: 'json'
|
|
7
|
+
};
|
|
8
|
+
export { docDoc };
|
|
9
|
+
/** What this package is: its manifest's description, the one place it is
|
|
10
|
+
* written, which a host stamps on each document here. */ export let description = manifest.description;
|
|
11
|
+
/** Every document this plugin declares. */ export let docs = [
|
|
12
|
+
docDoc
|
|
13
|
+
];
|
|
14
|
+
//# sourceMappingURL=vocab.js.map
|
package/vocab.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.js","sources":["./vocab.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,0EAA0E;AAC1E,wEAAwE;AAGxE,SAAS,MAAM,oBAAmB;AAClC,OAAO,cAAc,sBAAsB;EAAE,MAAM;AAAO,EAAC;AAE3D,SAAS,MAAM,GAAE;AAEjB;uDACuD,GACvD,OAAO,IAAI,cAAsB,SAAS,WAAW,CAAA;AAErD,yCAAyC,GACzC,OAAO,IAAI,OAAmB;EAAC;CAAO,CAAA"}
|
package/vocab.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "urn:uuid:b617d629-f91e-460c-a597-536f4d99142b",
|
|
3
|
+
"$vocabulary": {
|
|
4
|
+
"https://yak.sh/vocab/core": true,
|
|
5
|
+
"https://yak.sh/vocab/blob": true
|
|
6
|
+
},
|
|
7
|
+
"title": "doc",
|
|
8
|
+
"$defs": {
|
|
9
|
+
"doc": {
|
|
10
|
+
"$id": "urn:uuid:e8a36111-d334-4772-a0f9-89512f1e76ea",
|
|
11
|
+
"component": true,
|
|
12
|
+
"type": "object",
|
|
13
|
+
"description": "the text a person reads: a title and a body",
|
|
14
|
+
"properties": {
|
|
15
|
+
"title": {
|
|
16
|
+
"$id": "urn:uuid:08bc6a17-08d6-4894-8628-ebebfe5ac2f3",
|
|
17
|
+
"type": "string",
|
|
18
|
+
"search": true,
|
|
19
|
+
"contains": "property",
|
|
20
|
+
"description": "the one line an entity is known by"
|
|
21
|
+
},
|
|
22
|
+
"body": {
|
|
23
|
+
"$id": "urn:uuid:51f0daea-5680-4a8b-a222-165555d74600",
|
|
24
|
+
"type": "string",
|
|
25
|
+
"store": "blob",
|
|
26
|
+
"search": true,
|
|
27
|
+
"contains": true,
|
|
28
|
+
"prose": true,
|
|
29
|
+
"description": "the prose, as markdown — content-addressed when @yaks/blob is composed in, plain text otherwise"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"kinds": {
|
|
35
|
+
"doc": {
|
|
36
|
+
"$id": "urn:uuid:e8a36111-d334-4772-a0f9-89512f1e76ea",
|
|
37
|
+
"description": "the text a person reads: a title and a body",
|
|
38
|
+
"examples": [
|
|
39
|
+
{
|
|
40
|
+
"doc": {
|
|
41
|
+
"title": "Reading list",
|
|
42
|
+
"body": "Books to start this winter"
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
package/vocab.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// The component declaration, and nothing else: the module a server or a browser
|
|
2
|
+
// page imports at `@yaks/doc/vocab`. It reaches no storage, no SQL and no
|
|
3
|
+
// runtime, so a browser tab loading this vocabulary loads nothing else.
|
|
4
|
+
|
|
5
|
+
import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
|
|
6
|
+
import { docDoc } from './comp.js'
|
|
7
|
+
import manifest from './package.json' with { type: 'json' }
|
|
8
|
+
|
|
9
|
+
export { docDoc }
|
|
10
|
+
|
|
11
|
+
/** What this package is: its manifest's description, the one place it is
|
|
12
|
+
* written, which a host stamps on each document here. */
|
|
13
|
+
export let description: string = manifest.description
|
|
14
|
+
|
|
15
|
+
/** Every document this plugin declares. */
|
|
16
|
+
export let docs: VocabDoc[] = [docDoc]
|