@yaks/draft 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 +157 -2
- package/_dist/browser.d.ts +30 -0
- package/_dist/browser.d.ts.map +1 -0
- package/_dist/desk.d.ts +55 -0
- package/_dist/desk.d.ts.map +1 -0
- package/_dist/gateway.d.ts +42 -0
- package/_dist/gateway.d.ts.map +1 -0
- package/_dist/graph.d.ts +6 -0
- package/_dist/graph.d.ts.map +1 -0
- package/_dist/input.d.ts +22 -0
- package/_dist/input.d.ts.map +1 -0
- package/_dist/merge.d.ts +15 -0
- package/_dist/merge.d.ts.map +1 -0
- package/_dist/mod.d.ts +24 -0
- package/_dist/mod.d.ts.map +1 -0
- package/_dist/plugin.d.ts +29 -0
- package/_dist/plugin.d.ts.map +1 -0
- package/_dist/vocab.d.ts +7 -0
- package/_dist/vocab.d.ts.map +1 -0
- package/browser.js +300 -0
- package/browser.js.map +1 -0
- package/browser.ts +350 -0
- package/deno.json +1 -0
- package/desk.js +383 -0
- package/desk.js.map +1 -0
- package/desk.ts +477 -0
- package/gateway.js +112 -0
- package/gateway.js.map +1 -0
- package/gateway.ts +129 -0
- package/graph.js +13 -0
- package/graph.js.map +1 -0
- package/graph.ts +17 -0
- package/input.js +65 -0
- package/input.js.map +1 -0
- package/input.ts +90 -0
- package/merge.js +60 -0
- package/merge.js.map +1 -0
- package/merge.ts +65 -0
- package/mod.js +24 -0
- package/mod.js.map +1 -0
- package/mod.ts +38 -0
- package/package.json +37 -4
- package/plugin.js +157 -0
- package/plugin.js.map +1 -0
- package/plugin.ts +122 -0
- package/vocab.js +17 -0
- package/vocab.js.map +1 -0
- package/vocab.json +119 -0
- package/vocab.ts +18 -0
package/plugin.js
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
// The package as a graph plugin: the two components, and the one hook that
|
|
2
|
+
// makes a draft safe to type into from two places at once.
|
|
3
|
+
//
|
|
4
|
+
// A draft's text is written whole, each time, by whichever interface the
|
|
5
|
+
// person is typing in. Two of them writing over the same text would each
|
|
6
|
+
// replace the other's, so each write says what it was typed over (the
|
|
7
|
+
// `typed{over}` event beside it), and the store merges: what is stored now,
|
|
8
|
+
// the text the writer started from, and what it wrote, made one by `merge`
|
|
9
|
+
// (./merge.ts), which never drops what either typed. Every write of the text
|
|
10
|
+
// also counts one more `rev`, so an interface hearing two answers keeps the
|
|
11
|
+
// newer. It runs inside the transaction, where what is stored now is what the
|
|
12
|
+
// write lands on.
|
|
13
|
+
import { derivedEid } from "@yaks/graph/identity";
|
|
14
|
+
import { after } from "@yaks/fp";
|
|
15
|
+
import { draftDoc } from "./vocab.js";
|
|
16
|
+
import { merge } from "./merge.js";
|
|
17
|
+
let orderOf = (b)=>{
|
|
18
|
+
let typed = b.typed;
|
|
19
|
+
let { writer, order } = typed ?? {};
|
|
20
|
+
if (writer == null || order == null) return;
|
|
21
|
+
return {
|
|
22
|
+
eid: derivedEid(`draft writer|${b.entity.eid}|${writer}`),
|
|
23
|
+
order,
|
|
24
|
+
confirmed: typed?.confirmed
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The hook: each draft whose text is written is merged over what the store
|
|
29
|
+
* holds when it says what it was typed over, and counted.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* import { assertEquals } from '@std/assert'
|
|
33
|
+
* import { graph } from '@yaks/graph'
|
|
34
|
+
* import { ram } from '@yaks/ram'
|
|
35
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
36
|
+
* import { draftDoc, drafts } from '@yaks/draft'
|
|
37
|
+
*
|
|
38
|
+
* let vocab = loadVocab([draftDoc])
|
|
39
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins: [drafts()] })
|
|
40
|
+
* let write = (text: string, over: string) =>
|
|
41
|
+
* g.apply([{ entity: { eid: 'd' }, draft: { text }, typed: { over } }])
|
|
42
|
+
* await write('ship it', '')
|
|
43
|
+
* await write('ship it now', 'ship it') // one interface typed on
|
|
44
|
+
* await write('Ship it', 'ship it') // another, not having heard it
|
|
45
|
+
* let [d] = await g.get(['d'])
|
|
46
|
+
* assertEquals(d.draft, { text: 'Ship it now', rev: 3 })
|
|
47
|
+
* ```
|
|
48
|
+
*/ export let merging = (bundles, tx)=>{
|
|
49
|
+
let written = bundles.filter((b)=>typeof b.draft?.text == 'string');
|
|
50
|
+
if (!written.length) return bundles;
|
|
51
|
+
let orders = new Map(written.map((b)=>[
|
|
52
|
+
b,
|
|
53
|
+
orderOf(b)
|
|
54
|
+
]));
|
|
55
|
+
let eids = written.flatMap((b)=>{
|
|
56
|
+
let writer = orders.get(b);
|
|
57
|
+
return writer ? [
|
|
58
|
+
b.entity.eid,
|
|
59
|
+
writer.eid
|
|
60
|
+
] : [
|
|
61
|
+
b.entity.eid
|
|
62
|
+
];
|
|
63
|
+
});
|
|
64
|
+
return after(tx.get(eids, [
|
|
65
|
+
'draft',
|
|
66
|
+
'draft_writer'
|
|
67
|
+
]), (found)=>{
|
|
68
|
+
let held = new Map(found.map((b)=>[
|
|
69
|
+
b.entity.eid,
|
|
70
|
+
b.draft ?? {}
|
|
71
|
+
]));
|
|
72
|
+
let writers = new Map(found.map((b)=>[
|
|
73
|
+
b.entity.eid,
|
|
74
|
+
b.draft_writer
|
|
75
|
+
]));
|
|
76
|
+
return bundles.flatMap((b)=>{
|
|
77
|
+
let d = b.draft;
|
|
78
|
+
if (typeof d?.text != 'string') return [
|
|
79
|
+
b
|
|
80
|
+
];
|
|
81
|
+
let now = held.get(b.entity.eid) ?? {};
|
|
82
|
+
let over = b.typed?.over;
|
|
83
|
+
let order = orders.get(b);
|
|
84
|
+
let advanced = [];
|
|
85
|
+
if (order) {
|
|
86
|
+
let { eid, order: n, confirmed } = order;
|
|
87
|
+
let last = writers.get(eid) ?? {};
|
|
88
|
+
let saved = last.saved ?? 0, spent = last.spent ?? 0;
|
|
89
|
+
if (n <= spent || confirmed == null && n <= saved) {
|
|
90
|
+
return [
|
|
91
|
+
{
|
|
92
|
+
...b,
|
|
93
|
+
draft: now
|
|
94
|
+
}
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
if (confirmed != null && saved > confirmed && saved < n) {
|
|
98
|
+
over = last.text;
|
|
99
|
+
}
|
|
100
|
+
let next = confirmed == null ? {
|
|
101
|
+
...last,
|
|
102
|
+
saved: n,
|
|
103
|
+
text: d.text
|
|
104
|
+
} : {
|
|
105
|
+
...last,
|
|
106
|
+
spent: n,
|
|
107
|
+
...saved < n ? {
|
|
108
|
+
text: ''
|
|
109
|
+
} : {}
|
|
110
|
+
};
|
|
111
|
+
writers.set(eid, next);
|
|
112
|
+
advanced.push({
|
|
113
|
+
entity: {
|
|
114
|
+
eid
|
|
115
|
+
},
|
|
116
|
+
draft_writer: {
|
|
117
|
+
...next,
|
|
118
|
+
draft: b.entity.eid,
|
|
119
|
+
by: d.by
|
|
120
|
+
},
|
|
121
|
+
$actor: b.$actor
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
let text = over == null ? d.text : merge(over, d.text, now.text ?? '');
|
|
125
|
+
let next = {
|
|
126
|
+
...d,
|
|
127
|
+
text,
|
|
128
|
+
rev: (now.rev ?? 0) + 1
|
|
129
|
+
};
|
|
130
|
+
held.set(b.entity.eid, next);
|
|
131
|
+
return [
|
|
132
|
+
{
|
|
133
|
+
...b,
|
|
134
|
+
draft: next
|
|
135
|
+
},
|
|
136
|
+
...advanced
|
|
137
|
+
];
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* The draft plugin: `draft{by, place, text, rev}`, the `typed{over}` event,
|
|
143
|
+
* and {@link merging}. Compose it wherever drafts are stored: the server an
|
|
144
|
+
* interface writes to, or a page's own graph that keeps them itself.
|
|
145
|
+
*/ export let drafts = ()=>({
|
|
146
|
+
name: '@yaks/draft',
|
|
147
|
+
// Merging reads the transaction and rewrites its batch, with no external
|
|
148
|
+
// effects. Admission can rehearse it without calling storage's writer.
|
|
149
|
+
admission: ()=>true,
|
|
150
|
+
vocab: [
|
|
151
|
+
draftDoc
|
|
152
|
+
],
|
|
153
|
+
hooks: {
|
|
154
|
+
precondition: merging
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
//# sourceMappingURL=plugin.js.map
|
package/plugin.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["./plugin.ts"],"names":[],"mappings":"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"}
|
package/plugin.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// The package as a graph plugin: the two components, and the one hook that
|
|
2
|
+
// makes a draft safe to type into from two places at once.
|
|
3
|
+
//
|
|
4
|
+
// A draft's text is written whole, each time, by whichever interface the
|
|
5
|
+
// person is typing in. Two of them writing over the same text would each
|
|
6
|
+
// replace the other's, so each write says what it was typed over (the
|
|
7
|
+
// `typed{over}` event beside it), and the store merges: what is stored now,
|
|
8
|
+
// the text the writer started from, and what it wrote, made one by `merge`
|
|
9
|
+
// (./merge.ts), which never drops what either typed. Every write of the text
|
|
10
|
+
// also counts one more `rev`, so an interface hearing two answers keeps the
|
|
11
|
+
// newer. It runs inside the transaction, where what is stored now is what the
|
|
12
|
+
// write lands on.
|
|
13
|
+
|
|
14
|
+
import type { Bundle, Hook, Plugin } from 'jsr:@yaks/graph@0.2.36'
|
|
15
|
+
import { derivedEid } from '@yaks/graph/identity'
|
|
16
|
+
import { after } from '@yaks/fp'
|
|
17
|
+
import { draftDoc } from './vocab.js'
|
|
18
|
+
import { merge } from './merge.js'
|
|
19
|
+
|
|
20
|
+
type Draft = { by?: string; text?: string | null; rev?: number }
|
|
21
|
+
type Writer = { saved?: number; text?: string; spent?: number }
|
|
22
|
+
|
|
23
|
+
let orderOf = (b: Bundle) => {
|
|
24
|
+
let typed = b.typed as
|
|
25
|
+
| { over?: string; writer?: string; order?: number; confirmed?: number }
|
|
26
|
+
| undefined
|
|
27
|
+
let { writer, order } = typed ?? {}
|
|
28
|
+
if (writer == null || order == null) return
|
|
29
|
+
return {
|
|
30
|
+
eid: derivedEid(`draft writer|${b.entity.eid}|${writer}`),
|
|
31
|
+
order,
|
|
32
|
+
confirmed: typed?.confirmed,
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The hook: each draft whose text is written is merged over what the store
|
|
38
|
+
* holds when it says what it was typed over, and counted.
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* import { assertEquals } from '@std/assert'
|
|
42
|
+
* import { graph } from '@yaks/graph'
|
|
43
|
+
* import { ram } from '@yaks/ram'
|
|
44
|
+
* import { loadVocab } from '@yaks/vocab'
|
|
45
|
+
* import { draftDoc, drafts } from '@yaks/draft'
|
|
46
|
+
*
|
|
47
|
+
* let vocab = loadVocab([draftDoc])
|
|
48
|
+
* let g = graph({ storage: ram(vocab), vocab, plugins: [drafts()] })
|
|
49
|
+
* let write = (text: string, over: string) =>
|
|
50
|
+
* g.apply([{ entity: { eid: 'd' }, draft: { text }, typed: { over } }])
|
|
51
|
+
* await write('ship it', '')
|
|
52
|
+
* await write('ship it now', 'ship it') // one interface typed on
|
|
53
|
+
* await write('Ship it', 'ship it') // another, not having heard it
|
|
54
|
+
* let [d] = await g.get(['d'])
|
|
55
|
+
* assertEquals(d.draft, { text: 'Ship it now', rev: 3 })
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export let merging: Hook = (bundles, tx) => {
|
|
59
|
+
let written = bundles.filter((b) =>
|
|
60
|
+
typeof (b.draft as Draft | null)?.text == 'string'
|
|
61
|
+
)
|
|
62
|
+
if (!written.length) return bundles
|
|
63
|
+
let orders = new Map(written.map((b) => [b, orderOf(b)]))
|
|
64
|
+
let eids = written.flatMap((b) => {
|
|
65
|
+
let writer = orders.get(b)
|
|
66
|
+
return writer ? [b.entity.eid, writer.eid] : [b.entity.eid]
|
|
67
|
+
})
|
|
68
|
+
return after(tx.get(eids, ['draft', 'draft_writer']), (found) => {
|
|
69
|
+
let held = new Map(
|
|
70
|
+
found.map((b) => [b.entity.eid, (b.draft ?? {}) as Draft]),
|
|
71
|
+
)
|
|
72
|
+
let writers = new Map(
|
|
73
|
+
found.map((b) => [b.entity.eid, b.draft_writer as Writer]),
|
|
74
|
+
)
|
|
75
|
+
return bundles.flatMap((b): Bundle[] => {
|
|
76
|
+
let d = b.draft as Draft | null | undefined
|
|
77
|
+
if (typeof d?.text != 'string') return [b]
|
|
78
|
+
let now = held.get(b.entity.eid) ?? {}
|
|
79
|
+
let over = (b.typed as { over?: string } | undefined)?.over
|
|
80
|
+
let order = orders.get(b)
|
|
81
|
+
let advanced: Bundle[] = []
|
|
82
|
+
if (order) {
|
|
83
|
+
let { eid, order: n, confirmed } = order
|
|
84
|
+
let last = writers.get(eid) ?? {}
|
|
85
|
+
let saved = last.saved ?? 0, spent = last.spent ?? 0
|
|
86
|
+
if (n <= spent || (confirmed == null && n <= saved)) {
|
|
87
|
+
return [{ ...b, draft: now }]
|
|
88
|
+
}
|
|
89
|
+
if (confirmed != null && saved > confirmed && saved < n) {
|
|
90
|
+
over = last.text
|
|
91
|
+
}
|
|
92
|
+
let next = confirmed == null
|
|
93
|
+
? { ...last, saved: n, text: d.text }
|
|
94
|
+
: { ...last, spent: n, ...(saved < n ? { text: '' } : {}) }
|
|
95
|
+
writers.set(eid, next)
|
|
96
|
+
advanced.push({
|
|
97
|
+
entity: { eid },
|
|
98
|
+
draft_writer: { ...next, draft: b.entity.eid, by: d.by },
|
|
99
|
+
$actor: b.$actor,
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
let text = over == null ? d.text : merge(over, d.text, now.text ?? '')
|
|
103
|
+
let next = { ...d, text, rev: (now.rev ?? 0) + 1 }
|
|
104
|
+
held.set(b.entity.eid, next)
|
|
105
|
+
return [{ ...b, draft: next }, ...advanced]
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The draft plugin: `draft{by, place, text, rev}`, the `typed{over}` event,
|
|
112
|
+
* and {@link merging}. Compose it wherever drafts are stored: the server an
|
|
113
|
+
* interface writes to, or a page's own graph that keeps them itself.
|
|
114
|
+
*/
|
|
115
|
+
export let drafts = (): Plugin => ({
|
|
116
|
+
name: '@yaks/draft',
|
|
117
|
+
// Merging reads the transaction and rewrites its batch, with no external
|
|
118
|
+
// effects. Admission can rehearse it without calling storage's writer.
|
|
119
|
+
admission: () => true,
|
|
120
|
+
vocab: [draftDoc],
|
|
121
|
+
hooks: { precondition: merging },
|
|
122
|
+
})
|
package/vocab.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// The component declarations, and nothing else: the module a server or a
|
|
2
|
+
// browser page imports at `@yaks/draft/vocab`. It reaches no storage and no
|
|
3
|
+
// runtime.
|
|
4
|
+
import doc from './vocab.json' with {
|
|
5
|
+
type: 'json'
|
|
6
|
+
};
|
|
7
|
+
import manifest from './package.json' with {
|
|
8
|
+
type: 'json'
|
|
9
|
+
};
|
|
10
|
+
/** The draft vocabulary: `draft{by, place, text, rev}` and the `typed{over}`
|
|
11
|
+
* event, in the form `loadVocab` accepts. */ export let draftDoc = doc;
|
|
12
|
+
/** What this package is: its manifest's description, the one place it is
|
|
13
|
+
* written, which a host stamps on each document here. */ export let description = manifest.description;
|
|
14
|
+
/** Every document this package declares. */ export let docs = [
|
|
15
|
+
draftDoc
|
|
16
|
+
];
|
|
17
|
+
//# sourceMappingURL=vocab.js.map
|
package/vocab.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vocab.js","sources":["./vocab.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,4EAA4E;AAC5E,WAAW;AAGX,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AACpD,OAAO,cAAc,sBAAsB;EAAE,MAAM;AAAO,EAAC;AAE3D;2CAC2C,GAC3C,OAAO,IAAI,WAAqB,IAAe;AAE/C;uDACuD,GACvD,OAAO,IAAI,cAAsB,SAAS,WAAW,CAAA;AAErD,0CAA0C,GAC1C,OAAO,IAAI,OAAmB;EAAC;CAAS,CAAA"}
|
package/vocab.json
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$id": "urn:uuid:75ae2566-c38d-456b-b3c9-87b3ab37492a",
|
|
3
|
+
"$vocabulary": {
|
|
4
|
+
"https://yak.sh/vocab/core": true,
|
|
5
|
+
"https://yak.sh/vocab/member": true
|
|
6
|
+
},
|
|
7
|
+
"title": "draft",
|
|
8
|
+
"$defs": {
|
|
9
|
+
"draft": {
|
|
10
|
+
"$id": "urn:uuid:8422da8a-3258-4953-a850-84393d27511b",
|
|
11
|
+
"component": true,
|
|
12
|
+
"type": "object",
|
|
13
|
+
"embed": false,
|
|
14
|
+
"description": "what a person has typed in one place and not yet sent, on an entity whose eid is derived from the person and the place (draftEid), so every interface they use finds the same one; sending it or discarding it empties its text",
|
|
15
|
+
"properties": {
|
|
16
|
+
"by": {
|
|
17
|
+
"$id": "urn:uuid:8b615d50-5d1e-41f5-a8ef-b6c2f65959c3",
|
|
18
|
+
"type": "string",
|
|
19
|
+
"ref": "entity",
|
|
20
|
+
"death": "keep",
|
|
21
|
+
"description": "the person typing it"
|
|
22
|
+
},
|
|
23
|
+
"place": {
|
|
24
|
+
"$id": "urn:uuid:18e55035-119c-4da1-bd35-6ece1d4b500a",
|
|
25
|
+
"type": "string",
|
|
26
|
+
"description": "where it is typed, as its interface names it: `<eid>.comment`, `edit:<eid>:doc.title`, `search`"
|
|
27
|
+
},
|
|
28
|
+
"text": {
|
|
29
|
+
"$id": "urn:uuid:9dfed182-bcf8-41f8-93d5-63010422c1a6",
|
|
30
|
+
"type": "string",
|
|
31
|
+
"description": "what is typed; empty once it is sent or discarded"
|
|
32
|
+
},
|
|
33
|
+
"rev": {
|
|
34
|
+
"$id": "urn:uuid:3b20e298-0ad3-4771-a577-9972d7fed7a5",
|
|
35
|
+
"type": "integer",
|
|
36
|
+
"stamped": true,
|
|
37
|
+
"description": "how many writes of its text the store has taken, so an interface tells the newer text from the older"
|
|
38
|
+
},
|
|
39
|
+
"via": {
|
|
40
|
+
"$id": "urn:uuid:997886cf-466b-4536-8acf-dcf2decff3d2",
|
|
41
|
+
"type": "string",
|
|
42
|
+
"ref": "entity",
|
|
43
|
+
"death": "keep",
|
|
44
|
+
"description": "the vouched browser instrument owning guest input before it is handed to a person"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"personal": "by"
|
|
48
|
+
},
|
|
49
|
+
"typed": {
|
|
50
|
+
"$id": "urn:uuid:39d24090-864c-45df-a53d-805728c12958",
|
|
51
|
+
"component": true,
|
|
52
|
+
"type": "object",
|
|
53
|
+
"durable": "0s",
|
|
54
|
+
"description": "an event beside a draft's text: the text it was typed over, so the store keeps what another interface wrote meanwhile",
|
|
55
|
+
"properties": {
|
|
56
|
+
"over": {
|
|
57
|
+
"$id": "urn:uuid:c70aab4f-9501-4e0a-b80c-da5fd2ade4b5",
|
|
58
|
+
"type": "string",
|
|
59
|
+
"description": "the text the writer last heard from the store"
|
|
60
|
+
},
|
|
61
|
+
"writer": {
|
|
62
|
+
"$id": "urn:uuid:1f422d85-c6db-4bf0-9c9b-09c421a1fa37",
|
|
63
|
+
"type": "string",
|
|
64
|
+
"description": "the UUID of the desk issuing ordered saves and spends"
|
|
65
|
+
},
|
|
66
|
+
"order": {
|
|
67
|
+
"$id": "urn:uuid:4e227bb0-c7ad-45eb-a445-9cdb270edbc4",
|
|
68
|
+
"type": "integer",
|
|
69
|
+
"description": "the order in which that desk issued this write"
|
|
70
|
+
},
|
|
71
|
+
"confirmed": {
|
|
72
|
+
"$id": "urn:uuid:9a95efea-566e-41d1-a1d6-4f1e3607ec60",
|
|
73
|
+
"type": "integer",
|
|
74
|
+
"description": "on a spend, the last write this desk heard back from the store before sending"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"draft_writer": {
|
|
79
|
+
"$id": "urn:uuid:44ca0877-e9ee-425f-9e01-7a6274dd4681",
|
|
80
|
+
"component": true,
|
|
81
|
+
"type": "object",
|
|
82
|
+
"journal": false,
|
|
83
|
+
"wire": false,
|
|
84
|
+
"sync": "none",
|
|
85
|
+
"embed": false,
|
|
86
|
+
"personal": "by",
|
|
87
|
+
"description": "a desk's last saved text and spend order, used to absorb delayed autosaves",
|
|
88
|
+
"properties": {
|
|
89
|
+
"draft": {
|
|
90
|
+
"$id": "urn:uuid:c716e475-8d27-4189-b3d3-6ac292a773a1",
|
|
91
|
+
"type": "string",
|
|
92
|
+
"ref": "entity",
|
|
93
|
+
"death": "cascade"
|
|
94
|
+
},
|
|
95
|
+
"by": {
|
|
96
|
+
"$id": "urn:uuid:28c24ef4-6b58-4368-8cab-7af167c96348",
|
|
97
|
+
"type": "string",
|
|
98
|
+
"ref": "entity",
|
|
99
|
+
"death": "keep"
|
|
100
|
+
},
|
|
101
|
+
"saved": {
|
|
102
|
+
"$id": "urn:uuid:6896f4f3-a094-4d9a-9c07-2dad45fcb311",
|
|
103
|
+
"type": "integer",
|
|
104
|
+
"stamped": true
|
|
105
|
+
},
|
|
106
|
+
"text": {
|
|
107
|
+
"$id": "urn:uuid:0b43f847-c367-46c0-b2e9-2bb7db3b5b97",
|
|
108
|
+
"type": "string",
|
|
109
|
+
"stamped": true
|
|
110
|
+
},
|
|
111
|
+
"spent": {
|
|
112
|
+
"$id": "urn:uuid:53d3eb13-b018-4222-a874-04427f5d48aa",
|
|
113
|
+
"type": "integer",
|
|
114
|
+
"stamped": true
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
package/vocab.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// The component declarations, and nothing else: the module a server or a
|
|
2
|
+
// browser page imports at `@yaks/draft/vocab`. It reaches no storage and no
|
|
3
|
+
// runtime.
|
|
4
|
+
|
|
5
|
+
import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
|
|
6
|
+
import doc from './vocab.json' with { type: 'json' }
|
|
7
|
+
import manifest from './package.json' with { type: 'json' }
|
|
8
|
+
|
|
9
|
+
/** The draft vocabulary: `draft{by, place, text, rev}` and the `typed{over}`
|
|
10
|
+
* event, in the form `loadVocab` accepts. */
|
|
11
|
+
export let draftDoc: VocabDoc = doc as VocabDoc
|
|
12
|
+
|
|
13
|
+
/** What this package is: its manifest's description, the one place it is
|
|
14
|
+
* written, which a host stamps on each document here. */
|
|
15
|
+
export let description: string = manifest.description
|
|
16
|
+
|
|
17
|
+
/** Every document this package declares. */
|
|
18
|
+
export let docs: VocabDoc[] = [draftDoc]
|