@yaks/journal 0.0.0-stage → 0.2.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +522 -2
  3. package/_dist/backed.d.ts +9 -0
  4. package/_dist/backed.d.ts.map +1 -0
  5. package/_dist/batch.d.ts +45 -0
  6. package/_dist/batch.d.ts.map +1 -0
  7. package/_dist/feed.d.ts +108 -0
  8. package/_dist/feed.d.ts.map +1 -0
  9. package/_dist/graph.d.ts +104 -0
  10. package/_dist/graph.d.ts.map +1 -0
  11. package/_dist/kept.d.ts +63 -0
  12. package/_dist/kept.d.ts.map +1 -0
  13. package/_dist/log.d.ts +142 -0
  14. package/_dist/log.d.ts.map +1 -0
  15. package/_dist/merge.d.ts +41 -0
  16. package/_dist/merge.d.ts.map +1 -0
  17. package/_dist/mod.d.ts +101 -0
  18. package/_dist/mod.d.ts.map +1 -0
  19. package/_dist/service.d.ts +68 -0
  20. package/_dist/service.d.ts.map +1 -0
  21. package/_dist/tools.d.ts +5 -0
  22. package/_dist/tools.d.ts.map +1 -0
  23. package/_dist/undo.d.ts +48 -0
  24. package/_dist/undo.d.ts.map +1 -0
  25. package/_dist/value.d.ts +6 -0
  26. package/_dist/value.d.ts.map +1 -0
  27. package/_dist/views.d.ts +25 -0
  28. package/_dist/views.d.ts.map +1 -0
  29. package/_dist/vocab.d.ts +7 -0
  30. package/_dist/vocab.d.ts.map +1 -0
  31. package/backed.js +225 -0
  32. package/backed.js.map +1 -0
  33. package/backed.ts +274 -0
  34. package/batch.js +12 -0
  35. package/batch.js.map +1 -0
  36. package/batch.ts +84 -0
  37. package/deno.json +1 -0
  38. package/feed.js +295 -0
  39. package/feed.js.map +1 -0
  40. package/feed.ts +368 -0
  41. package/graph.js +224 -0
  42. package/graph.js.map +1 -0
  43. package/graph.ts +329 -0
  44. package/held.js +25 -0
  45. package/held.js.map +1 -0
  46. package/held.ts +24 -0
  47. package/kept.js +61 -0
  48. package/kept.js.map +1 -0
  49. package/kept.ts +100 -0
  50. package/log.js +1161 -0
  51. package/log.js.map +1 -0
  52. package/log.ts +1299 -0
  53. package/merge.js +158 -0
  54. package/merge.js.map +1 -0
  55. package/merge.ts +185 -0
  56. package/mod.js +101 -0
  57. package/mod.js.map +1 -0
  58. package/mod.ts +102 -0
  59. package/names.js +206 -0
  60. package/names.js.map +1 -0
  61. package/names.ts +230 -0
  62. package/package.json +52 -4
  63. package/page.js +160 -0
  64. package/page.js.map +1 -0
  65. package/page.ts +233 -0
  66. package/service.js +118 -0
  67. package/service.js.map +1 -0
  68. package/service.ts +148 -0
  69. package/tools.js +110 -0
  70. package/tools.js.map +1 -0
  71. package/tools.ts +113 -0
  72. package/undo.js +187 -0
  73. package/undo.js.map +1 -0
  74. package/undo.ts +190 -0
  75. package/value.js +26 -0
  76. package/value.js.map +1 -0
  77. package/value.ts +35 -0
  78. package/views.js +85 -0
  79. package/views.js.map +1 -0
  80. package/views.ts +91 -0
  81. package/vocab.js +20 -0
  82. package/vocab.js.map +1 -0
  83. package/vocab.json +308 -0
  84. package/vocab.ts +22 -0
package/views.ts ADDED
@@ -0,0 +1,91 @@
1
+ /**
2
+ * What this package draws. Anywhere: a row of an entity's history (the
3
+ * `history` tool, ./tools.ts) as one line, when · who · what it wrote —
4
+ * `2 minutes ago · yak task new Buy the cake · task; doc: Buy the cake`. In the
5
+ * browsing app: the History page, which the sidebar offers over the days'
6
+ * measurements, loaded when first drawn (./page.ts).
7
+ *
8
+ * @module
9
+ */
10
+ import type { View } from 'jsr:@yaks/inspect@0.2.36'
11
+ import { parse } from '@yaks/query/core'
12
+ import { type Bundle, define, type H, type Registry } from '@yaks/render'
13
+ import type { Shown } from 'jsr:@yaks/render@0.2.36/views'
14
+ // @ts-types="@yaks/ui/lucide"
15
+ import History from 'lucide/dist/esm/icons/rotate-ccw-clock.mjs'
16
+
17
+ type Tx = { seq?: number; at?: string; by?: string; via?: string }
18
+
19
+ let EID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
20
+ let AT = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/
21
+ let LONG = 60
22
+
23
+ // A value a line has room for: a word, a number, a short text. Who and when
24
+ // lead the line already, so the entities and moments a write stamps are left
25
+ // to its page; a long text is its opening words.
26
+ let brief = (v: unknown): string | undefined => {
27
+ if (typeof v == 'number' || typeof v == 'boolean') return String(v)
28
+ if (typeof v != 'string' || !v.trim() || EID.test(v) || AT.test(v)) return
29
+ let flat = v.replace(/\s+/g, ' ').trim()
30
+ return flat.length > LONG ? `${flat.slice(0, LONG - 1)}…` : flat
31
+ }
32
+
33
+ // What a row wrote, a component apiece: its name, then what it set that a
34
+ // line has room for — `doc: Buy the cake`, `removed claim`, `deleted`.
35
+ let wrote = (b: Bundle): string =>
36
+ b.$delete ? 'deleted' : Object.entries(b)
37
+ .filter(([c]) => c != 'entity' && c != '_tx' && !c.startsWith('$'))
38
+ .map(([c, v]) => {
39
+ if (v == null) return `removed ${c}`
40
+ let said = Object.values(v as Record<string, unknown>)
41
+ .flatMap((p) => brief(p) ?? [])
42
+ return said.length ? `${c}: ${said.join(', ')}` : c
43
+ })
44
+ .join('; ')
45
+
46
+ // One row of a history: when, who, and what it wrote.
47
+ let change = <Node>(b: Bundle, h: H<Node>, s: Shown<Node>): Node => {
48
+ let tx = b._tx as Tx
49
+ let parts = [
50
+ tx.at && h('time', { datetime: tx.at }, s.when(tx.at)),
51
+ tx.by &&
52
+ s.show(s.get?.(tx.by) ?? { entity: { eid: tx.by } }, 'Reference.Inline'),
53
+ wrote(b),
54
+ ].filter((p): p is Node => !!p)
55
+ return h(
56
+ 'span',
57
+ { class: 'Change' },
58
+ ...parts.flatMap((p, i) => i ? [' · ', p] : [p]),
59
+ )
60
+ }
61
+
62
+ let line = {
63
+ match: parse('._tx'),
64
+ needs: (b: Bundle) => [(b._tx as Tx).by].filter((e): e is string => !!e),
65
+ render: <Node>(b: Bundle, h: H<Node>, ctx: unknown): Node =>
66
+ change(b, h, ctx as Shown<Node>),
67
+ }
68
+
69
+ /** A history row as one line, in a list or alone. */
70
+ export let views: Registry = define([
71
+ { view: 'Tile', ...line },
72
+ { view: 'Page', ...line },
73
+ ])
74
+
75
+ /** The page, loaded when first drawn. */
76
+ export let inspectViews = (): Promise<View[]> =>
77
+ import('./page.js').then((m) => m.inspectViews)
78
+
79
+ /** The page the sidebar offers: what history keeps, over the days. */
80
+ export let destinations = [
81
+ {
82
+ key: 'history',
83
+ name: 'History',
84
+ icon: 'history',
85
+ query: '.kept * .order=-kept.day',
86
+ view: 'History.Page',
87
+ },
88
+ ]
89
+
90
+ /** The glyph it wears there. */
91
+ export let icons = { history: History }
package/vocab.js ADDED
@@ -0,0 +1,20 @@
1
+ // `@yaks/journal/vocab` — the declarations, and only the declarations: the
2
+ // `history` tool implemented in ./tools.ts, and the two components the journal
3
+ // is read as, `_tx` and `_change`. Both are computed: the journal is the record
4
+ // of what was applied, never part of it, so no table holds them and nothing
5
+ // writes them, and `backed` names the journal's own rows as what they are read
6
+ // from (./backed.ts).
7
+ import doc from './vocab.json' with {
8
+ type: 'json'
9
+ };
10
+ import manifest from './package.json' with {
11
+ type: 'json'
12
+ };
13
+ export { backed } from "./backed.js";
14
+ /** The declarations this plugin contributes. */ export let journalDoc = doc;
15
+ /** What this package is: its manifest's description, the one place it is
16
+ * written, which a host stamps on each document here. */ export let description = manifest.description;
17
+ /** Every document this plugin declares. */ export let docs = [
18
+ journalDoc
19
+ ];
20
+ //# sourceMappingURL=vocab.js.map
package/vocab.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vocab.js","sources":["./vocab.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,+EAA+E;AAC/E,gFAAgF;AAChF,4EAA4E;AAC5E,+EAA+E;AAC/E,sBAAsB;AAGtB,OAAO,SAAS,oBAAoB;EAAE,MAAM;AAAO,EAAC;AACpD,OAAO,cAAc,sBAAsB;EAAE,MAAM;AAAO,EAAC;AAE3D,SAAS,MAAM,sBAAqB;AAEpC,8CAA8C,GAC9C,OAAO,IAAI,aAAuB,IAAG;AAErC;uDACuD,GACvD,OAAO,IAAI,cAAsB,SAAS,WAAW,CAAA;AAErD,yCAAyC,GACzC,OAAO,IAAI,OAAmB;EAAC;CAAW,CAAA"}
package/vocab.json ADDED
@@ -0,0 +1,308 @@
1
+ {
2
+ "$id": "urn:uuid:de4b07e4-bed4-4479-b581-3e70aa37ee82",
3
+ "$vocabulary": {
4
+ "https://yak.sh/vocab/core": true
5
+ },
6
+ "title": "journal",
7
+ "$defs": {
8
+ "_tx": {
9
+ "$id": "urn:uuid:f6fd3747-f157-4fa3-ae7b-832ef5164b76",
10
+ "component": true,
11
+ "computed": true,
12
+ "type": "object",
13
+ "description": "A committed transaction, read from the journal: one call to apply(), whose bundles all committed together.",
14
+ "properties": {
15
+ "seq": {
16
+ "$id": "urn:uuid:ec85f5f4-920e-4b16-8906-c6c64a3c3ff8",
17
+ "type": "integer",
18
+ "description": "its place in the journal's total order, the cursor a feed holds"
19
+ },
20
+ "at": {
21
+ "$id": "urn:uuid:500a621e-da7c-4c98-9ecd-d25d0dec9aba",
22
+ "type": "string",
23
+ "format": "date-time",
24
+ "description": "when it committed"
25
+ },
26
+ "by": {
27
+ "$id": "urn:uuid:788db1bb-7436-4fff-8e54-0d35ea114d3f",
28
+ "type": "string",
29
+ "ref": "entity",
30
+ "death": "keep",
31
+ "description": "whom the write acted for"
32
+ },
33
+ "via": {
34
+ "$id": "urn:uuid:5850cf02-1f3a-4277-8a94-e9cea77fba9a",
35
+ "type": "string",
36
+ "ref": "entity",
37
+ "death": "keep",
38
+ "description": "the session, connector or other entity it was made through"
39
+ },
40
+ "host": {
41
+ "$id": "urn:uuid:d988bc41-ea9d-459f-b25b-3998c3788f21",
42
+ "type": "string",
43
+ "description": "the process that wrote it"
44
+ },
45
+ "note": {
46
+ "$id": "urn:uuid:1aa1b4fb-052b-4c51-860e-24468d4fbbd9",
47
+ "type": "string",
48
+ "description": "a note its writer left"
49
+ }
50
+ }
51
+ },
52
+ "_change": {
53
+ "$id": "urn:uuid:67ef9841-b93a-4f61-845f-c007147182c2",
54
+ "component": true,
55
+ "computed": true,
56
+ "type": "object",
57
+ "description": "One component a transaction wrote or removed, read from the journal.",
58
+ "properties": {
59
+ "tx": {
60
+ "$id": "urn:uuid:cd24e6de-0905-4f38-be97-2cf3efc9c315",
61
+ "type": "string",
62
+ "ref": "_tx",
63
+ "death": "keep",
64
+ "description": "the transaction it belongs to"
65
+ },
66
+ "target": {
67
+ "$id": "urn:uuid:f8e842a6-f3ca-41a4-976d-83bc7cdf92b0",
68
+ "type": "string",
69
+ "ref": "entity",
70
+ "death": "keep",
71
+ "description": "the entity it changed"
72
+ },
73
+ "comp": {
74
+ "$id": "urn:uuid:de9dee4e-a26f-4e64-8b47-544d39f5708d",
75
+ "type": "string",
76
+ "ref": "_comp",
77
+ "death": "keep",
78
+ "description": "the component it wrote or removed; entity for a deletion"
79
+ },
80
+ "component": {
81
+ "$id": "urn:uuid:b1f3ccac-1d75-4d3f-abc4-e85ccb2d03d4",
82
+ "type": "string",
83
+ "description": "that component's name, which a graph that does not describe its vocabulary as _comp rows reads in place of comp"
84
+ },
85
+ "value": {
86
+ "$id": "urn:uuid:13915bcc-223f-4f15-b349-73185cc91fbe",
87
+ "type": "object",
88
+ "description": "the properties it wrote; absent where it removed the component"
89
+ }
90
+ }
91
+ },
92
+ "kept": {
93
+ "$id": "urn:uuid:0327d0a6-6b99-4bc4-8cb9-27bf776aa2d0",
94
+ "component": true,
95
+ "journal": false,
96
+ "wire": false,
97
+ "embed": false,
98
+ "type": "object",
99
+ "description": "what the store's file kept on one UTC day, measured once that day from its page statistics, so history can be read against the rest of the file: the file's bytes, how many of them were free, each table's bytes with its indexes and its rows, and the changes the journal held per component. History is the journal's tables (`journal_*`) and each component's versions (`<comp>$versions`)",
100
+ "properties": {
101
+ "day": {
102
+ "$id": "urn:uuid:bc2e8e30-2f58-43be-b5df-9bb6a964a19a",
103
+ "type": "string",
104
+ "identity": true,
105
+ "description": "the UTC day, `2026-10-21`"
106
+ },
107
+ "at": {
108
+ "$id": "urn:uuid:ed64c46e-e690-4497-b912-b858ae26d21b",
109
+ "type": "string",
110
+ "format": "date-time",
111
+ "stamped": true,
112
+ "description": "when it was measured"
113
+ },
114
+ "bytes": {
115
+ "$id": "urn:uuid:00c9cd8a-83c5-47e5-b465-a5d9722a4379",
116
+ "type": "integer",
117
+ "stamped": true,
118
+ "description": "the file's bytes"
119
+ },
120
+ "free": {
121
+ "$id": "urn:uuid:ec0caddc-4de5-4031-afb4-a77dc48568e1",
122
+ "type": "integer",
123
+ "stamped": true,
124
+ "description": "how many of them were free pages"
125
+ },
126
+ "file": {
127
+ "$id": "urn:uuid:f158dc98-4283-4111-9876-2f4fe228bad7",
128
+ "type": "string",
129
+ "ref": "file",
130
+ "death": "keep",
131
+ "stamped": true,
132
+ "description": "the file it measured, where the store keeps one on a disk"
133
+ },
134
+ "tables": {
135
+ "$id": "urn:uuid:1597e56d-c1ec-4ffb-a9c8-678dbb211add",
136
+ "type": "object",
137
+ "additionalProperties": {
138
+ "type": "array",
139
+ "items": {
140
+ "type": "integer"
141
+ },
142
+ "minItems": 2,
143
+ "maxItems": 2
144
+ },
145
+ "stamped": true,
146
+ "description": "by table: [bytes, rows], its indexes' bytes folded into its own"
147
+ },
148
+ "changes": {
149
+ "$id": "urn:uuid:1b6bc08a-9071-4977-a892-ce8c61306256",
150
+ "type": "object",
151
+ "additionalProperties": {
152
+ "type": "integer"
153
+ },
154
+ "stamped": true,
155
+ "description": "by component name: the changes the journal held for it, a deletion's under entity; absent where the store keeps no journal"
156
+ }
157
+ }
158
+ },
159
+ "history": {
160
+ "tool": true,
161
+ "noun": "history",
162
+ "title": "Read an entity\u2019s history",
163
+ "description": "List every committed transaction that touched one entity, newest first. Each is returned as the patch it applied (the named groups of fields it wrote, or $delete if it deleted the record) stamped with `_tx`: the transaction's place in the journal (`seq`), when it committed (`at`), whom it acted for (`by`) and through what (`via`). The journal is written inside the same transaction as the batch, so this gives attribution and a diff without a version table. It covers changes made since this graph started journaling.",
164
+ "input": {
165
+ "entity": {
166
+ "type": "string",
167
+ "ref": "entity",
168
+ "description": "record whose history to read: human-readable id, registered name, or unique entity id (eid)"
169
+ },
170
+ "limit": {
171
+ "type": "number",
172
+ "description": "return at most this many transactions, counting back from the newest",
173
+ "short": "n"
174
+ }
175
+ },
176
+ "required": [
177
+ "entity"
178
+ ],
179
+ "readOnly": true,
180
+ "positional": [
181
+ "entity"
182
+ ]
183
+ },
184
+ "branch_new": {
185
+ "tool": true,
186
+ "noun": "branch",
187
+ "verb": "new",
188
+ "title": "Make a branch",
189
+ "description": "Fork the whole graph at main's newest transaction; nothing is copied. Answers the branch: its id, the transaction it forked at (fork) and when. Pass the id as branch to graph_query, graph_show and graph_apply to read and write on it; main never sees its writes, and they reach no effect. Needs @yaks/journal with versions on.",
190
+ "input": {}
191
+ },
192
+ "branch_list": {
193
+ "tool": true,
194
+ "noun": "branch",
195
+ "verb": "list",
196
+ "title": "List branches",
197
+ "description": "Active branches of the graph, oldest first: id, the transaction of main it forked at (fork) and when it was made. Pass trash to list trashed branches, including when each was trashed.",
198
+ "input": {
199
+ "trash": {
200
+ "type": "boolean",
201
+ "description": "List trashed branches instead of active ones."
202
+ }
203
+ },
204
+ "readOnly": true
205
+ },
206
+ "branch_delete": {
207
+ "tool": true,
208
+ "noun": "branch",
209
+ "verb": "delete",
210
+ "title": "Trash a branch",
211
+ "description": "Move a branch to trash; every version written on it stays recoverable and main is untouched. Answers the trashed branch. Use branch_list with trash to find it and branch_restore to return it. Nothing is permanently erased.",
212
+ "input": {
213
+ "id": {
214
+ "type": "integer",
215
+ "description": "The branch's id, as branch_new and branch_list give it."
216
+ }
217
+ },
218
+ "required": [
219
+ "id"
220
+ ],
221
+ "positional": [
222
+ "id"
223
+ ]
224
+ },
225
+ "branch_restore": {
226
+ "tool": true,
227
+ "noun": "branch",
228
+ "verb": "restore",
229
+ "title": "Restore a branch",
230
+ "description": "Return a trashed branch with every version written on it. Answers the active branch. Find its id with branch_list and trash.",
231
+ "input": {
232
+ "id": {
233
+ "type": "integer",
234
+ "description": "The branch's id, as branch_new and branch_list give it."
235
+ }
236
+ },
237
+ "required": [
238
+ "id"
239
+ ],
240
+ "positional": [
241
+ "id"
242
+ ]
243
+ },
244
+ "branch_merge": {
245
+ "tool": true,
246
+ "noun": "branch",
247
+ "verb": "merge",
248
+ "title": "Merge a branch into main",
249
+ "description": "Write what a branch changed since its fork to main as one batch. Each property merges against its value at the fork: one only the branch changed takes the branch's value, one only main changed keeps main's. A property both changed to different values is a conflict, and nothing merges by itself: while any conflict has no pick, nothing is written, and the answer lists the conflicts, each with its value at the fork, on the branch and on main side by side. Pass a pick for each to merge. A removed component or deleted entity against the other side's edit is a conflict too. Answers the conflicts left and the bundles written; the branch is left as it is.",
250
+ "input": {
251
+ "id": {
252
+ "type": "integer",
253
+ "description": "The branch's id, as branch_new and branch_list give it."
254
+ },
255
+ "pick": {
256
+ "type": "array",
257
+ "description": "Which value each conflict takes: its eid, comp and prop as the conflicts list them, and take, branch or main.",
258
+ "items": {
259
+ "type": "object",
260
+ "properties": {
261
+ "eid": {
262
+ "type": "string"
263
+ },
264
+ "comp": {
265
+ "type": "string"
266
+ },
267
+ "prop": {
268
+ "type": "string"
269
+ },
270
+ "take": {
271
+ "type": "string",
272
+ "enum": [
273
+ "branch",
274
+ "main"
275
+ ]
276
+ },
277
+ "main": {
278
+ "description": "The value main held as the conflict listed it. A main that has moved since is one the pick never saw, so the conflict stands again."
279
+ }
280
+ },
281
+ "required": [
282
+ "eid",
283
+ "comp",
284
+ "prop",
285
+ "take"
286
+ ]
287
+ }
288
+ }
289
+ },
290
+ "required": [
291
+ "id"
292
+ ],
293
+ "positional": [
294
+ "id"
295
+ ]
296
+ }
297
+ },
298
+ "kinds": {
299
+ "_tx": {
300
+ "$id": "urn:uuid:f6fd3747-f157-4fa3-ae7b-832ef5164b76",
301
+ "description": "A committed transaction, read from the journal: one call to apply(), whose bundles all committed together."
302
+ },
303
+ "_change": {
304
+ "$id": "urn:uuid:67ef9841-b93a-4f61-845f-c007147182c2",
305
+ "description": "One component a transaction wrote or removed, read from the journal."
306
+ }
307
+ }
308
+ }
package/vocab.ts ADDED
@@ -0,0 +1,22 @@
1
+ // `@yaks/journal/vocab` — the declarations, and only the declarations: the
2
+ // `history` tool implemented in ./tools.ts, and the two components the journal
3
+ // is read as, `_tx` and `_change`. Both are computed: the journal is the record
4
+ // of what was applied, never part of it, so no table holds them and nothing
5
+ // writes them, and `backed` names the journal's own rows as what they are read
6
+ // from (./backed.ts).
7
+
8
+ import type { VocabDoc } from 'jsr:@yaks/vocab@0.2.36'
9
+ import doc from './vocab.json' with { type: 'json' }
10
+ import manifest from './package.json' with { type: 'json' }
11
+
12
+ export { backed } from './backed.js'
13
+
14
+ /** The declarations this plugin contributes. */
15
+ export let journalDoc: VocabDoc = doc
16
+
17
+ /** What this package is: its manifest's description, the one place it is
18
+ * written, which a host stamps on each document here. */
19
+ export let description: string = manifest.description
20
+
21
+ /** Every document this plugin declares. */
22
+ export let docs: VocabDoc[] = [journalDoc]