@yaks/tracker 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 (198) hide show
  1. package/Histogram.js +71 -0
  2. package/Histogram.js.map +1 -0
  3. package/Histogram.ts +100 -0
  4. package/LICENSE +202 -0
  5. package/README.md +639 -2
  6. package/_dist/brief.d.ts +25 -0
  7. package/_dist/brief.d.ts.map +1 -0
  8. package/_dist/changes.d.ts +9 -0
  9. package/_dist/changes.d.ts.map +1 -0
  10. package/_dist/chart.d.ts +24 -0
  11. package/_dist/chart.d.ts.map +1 -0
  12. package/_dist/digest.d.ts +64 -0
  13. package/_dist/digest.d.ts.map +1 -0
  14. package/_dist/effects.d.ts +73 -0
  15. package/_dist/effects.d.ts.map +1 -0
  16. package/_dist/errors.d.ts +14 -0
  17. package/_dist/errors.d.ts.map +1 -0
  18. package/_dist/everywhere.d.ts +13 -0
  19. package/_dist/everywhere.d.ts.map +1 -0
  20. package/_dist/fault.d.ts +29 -0
  21. package/_dist/fault.d.ts.map +1 -0
  22. package/_dist/file.d.ts +6 -0
  23. package/_dist/file.d.ts.map +1 -0
  24. package/_dist/fixtime.d.ts +20 -0
  25. package/_dist/fixtime.d.ts.map +1 -0
  26. package/_dist/frames.d.ts +6 -0
  27. package/_dist/frames.d.ts.map +1 -0
  28. package/_dist/graph.d.ts +3 -0
  29. package/_dist/graph.d.ts.map +1 -0
  30. package/_dist/group.d.ts +21 -0
  31. package/_dist/group.d.ts.map +1 -0
  32. package/_dist/instrument.d.ts +37 -0
  33. package/_dist/instrument.d.ts.map +1 -0
  34. package/_dist/intake.d.ts +21 -0
  35. package/_dist/intake.d.ts.map +1 -0
  36. package/_dist/merge.d.ts +11 -0
  37. package/_dist/merge.d.ts.map +1 -0
  38. package/_dist/mod.d.ts +7 -0
  39. package/_dist/mod.d.ts.map +1 -0
  40. package/_dist/model.d.ts +20 -0
  41. package/_dist/model.d.ts.map +1 -0
  42. package/_dist/outage.d.ts +7 -0
  43. package/_dist/outage.d.ts.map +1 -0
  44. package/_dist/people.d.ts +3 -0
  45. package/_dist/people.d.ts.map +1 -0
  46. package/_dist/poll.d.ts +101 -0
  47. package/_dist/poll.d.ts.map +1 -0
  48. package/_dist/poll_thread.d.ts +8 -0
  49. package/_dist/poll_thread.d.ts.map +1 -0
  50. package/_dist/reading.d.ts +34 -0
  51. package/_dist/reading.d.ts.map +1 -0
  52. package/_dist/remote.d.ts +61 -0
  53. package/_dist/remote.d.ts.map +1 -0
  54. package/_dist/report.d.ts +324 -0
  55. package/_dist/report.d.ts.map +1 -0
  56. package/_dist/resolution.d.ts +22 -0
  57. package/_dist/resolution.d.ts.map +1 -0
  58. package/_dist/routes.d.ts +33 -0
  59. package/_dist/routes.d.ts.map +1 -0
  60. package/_dist/script.d.ts +8 -0
  61. package/_dist/script.d.ts.map +1 -0
  62. package/_dist/service.d.ts +30 -0
  63. package/_dist/service.d.ts.map +1 -0
  64. package/_dist/sync_health.d.ts +4 -0
  65. package/_dist/sync_health.d.ts.map +1 -0
  66. package/_dist/ticket.d.ts +14 -0
  67. package/_dist/ticket.d.ts.map +1 -0
  68. package/_dist/tools.d.ts +39 -0
  69. package/_dist/tools.d.ts.map +1 -0
  70. package/_dist/trace-intake.d.ts +25 -0
  71. package/_dist/trace-intake.d.ts.map +1 -0
  72. package/_dist/views.d.ts +11 -0
  73. package/_dist/views.d.ts.map +1 -0
  74. package/_dist/vocab.d.ts +9 -0
  75. package/_dist/vocab.d.ts.map +1 -0
  76. package/box.json +51 -0
  77. package/brief.js +86 -0
  78. package/brief.js.map +1 -0
  79. package/brief.ts +120 -0
  80. package/changes.js +57 -0
  81. package/changes.js.map +1 -0
  82. package/changes.ts +70 -0
  83. package/chart.js +186 -0
  84. package/chart.js.map +1 -0
  85. package/chart.ts +193 -0
  86. package/deno.json +1 -0
  87. package/digest.js +329 -0
  88. package/digest.js.map +1 -0
  89. package/digest.ts +406 -0
  90. package/effects.js +136 -0
  91. package/effects.js.map +1 -0
  92. package/effects.ts +178 -0
  93. package/errors.js +130 -0
  94. package/errors.js.map +1 -0
  95. package/errors.ts +185 -0
  96. package/everywhere.js +46 -0
  97. package/everywhere.js.map +1 -0
  98. package/everywhere.ts +66 -0
  99. package/fault.js +65 -0
  100. package/fault.js.map +1 -0
  101. package/fault.ts +107 -0
  102. package/file.js +87 -0
  103. package/file.js.map +1 -0
  104. package/file.ts +93 -0
  105. package/fixtime.js +67 -0
  106. package/fixtime.js.map +1 -0
  107. package/fixtime.ts +86 -0
  108. package/frames.js +77 -0
  109. package/frames.js.map +1 -0
  110. package/frames.ts +69 -0
  111. package/graph.js +7 -0
  112. package/graph.js.map +1 -0
  113. package/graph.ts +8 -0
  114. package/group.js +444 -0
  115. package/group.js.map +1 -0
  116. package/group.ts +533 -0
  117. package/inspect.js +471 -0
  118. package/inspect.js.map +1 -0
  119. package/inspect.ts +693 -0
  120. package/instrument.js +69 -0
  121. package/instrument.js.map +1 -0
  122. package/instrument.ts +93 -0
  123. package/intake.js +43 -0
  124. package/intake.js.map +1 -0
  125. package/intake.ts +84 -0
  126. package/merge.js +126 -0
  127. package/merge.js.map +1 -0
  128. package/merge.ts +115 -0
  129. package/migrate.ts +36 -0
  130. package/mod.js +8 -0
  131. package/mod.js.map +1 -0
  132. package/mod.ts +19 -0
  133. package/model.js +8 -0
  134. package/model.js.map +1 -0
  135. package/model.ts +27 -0
  136. package/outage.js +129 -0
  137. package/outage.js.map +1 -0
  138. package/outage.ts +158 -0
  139. package/package.json +133 -4
  140. package/page.d.ts +2 -0
  141. package/page.js +905 -0
  142. package/people.js +51 -0
  143. package/people.js.map +1 -0
  144. package/people.ts +82 -0
  145. package/poll.js +277 -0
  146. package/poll.js.map +1 -0
  147. package/poll.ts +411 -0
  148. package/poll_thread.js +104 -0
  149. package/poll_thread.js.map +1 -0
  150. package/poll_thread.ts +126 -0
  151. package/poll_worker.ts +45 -0
  152. package/reading.js +122 -0
  153. package/reading.js.map +1 -0
  154. package/reading.ts +162 -0
  155. package/reconcile.js +113 -0
  156. package/reconcile.js.map +1 -0
  157. package/reconcile.ts +130 -0
  158. package/remote.js +312 -0
  159. package/remote.js.map +1 -0
  160. package/remote.ts +397 -0
  161. package/report.js +825 -0
  162. package/report.js.map +1 -0
  163. package/report.ts +944 -0
  164. package/resolution.js +114 -0
  165. package/resolution.js.map +1 -0
  166. package/resolution.ts +123 -0
  167. package/routes.js +130 -0
  168. package/routes.js.map +1 -0
  169. package/routes.ts +163 -0
  170. package/script.js +13 -0
  171. package/script.js.map +1 -0
  172. package/script.ts +16 -0
  173. package/service.js +174 -0
  174. package/service.js.map +1 -0
  175. package/service.ts +215 -0
  176. package/spread.js +94 -0
  177. package/spread.js.map +1 -0
  178. package/spread.ts +101 -0
  179. package/sync_health.js +36 -0
  180. package/sync_health.js.map +1 -0
  181. package/sync_health.ts +65 -0
  182. package/ticket.js +6 -0
  183. package/ticket.js.map +1 -0
  184. package/ticket.ts +24 -0
  185. package/tools.js +305 -0
  186. package/tools.js.map +1 -0
  187. package/tools.ts +411 -0
  188. package/trace-intake.js +164 -0
  189. package/trace-intake.js.map +1 -0
  190. package/trace-intake.ts +148 -0
  191. package/views.js +247 -0
  192. package/views.js.map +1 -0
  193. package/views.ts +254 -0
  194. package/vocab.js +20 -0
  195. package/vocab.js.map +1 -0
  196. package/vocab.json +834 -0
  197. package/vocab.ts +14 -0
  198. package/yak-tracker@.service +22 -0
package/resolution.js ADDED
@@ -0,0 +1,114 @@
1
+ // Every resolved bug says how it was fixed. Only an agent that fixed a bug's
2
+ // cause and saw the fix live resolves it; nothing resolves a bug on its own,
3
+ // and one that stopped stays open. The resolver explains it on the `resolved`
4
+ // mark: what broke, why, the commits that introduced and fixed it, and whether
5
+ // it can come back. The graph refuses a bug's resolution without
6
+ // its cause and recur at every door, so a letter or a page never meets a bare
7
+ // one, except on a bug resolved before explanations were kept.
8
+ import { after } from "@yaks/fp";
9
+ import { Refused } from "@yaks/graph/errors";
10
+ import { hook } from "@yaks/graph/plugin";
11
+ import { headline, sha } from "./brief.js";
12
+ import { comp, str } from "./model.js";
13
+ import { said } from "./reading.js";
14
+ let KEYS = [
15
+ 'broke',
16
+ 'cause',
17
+ 'since',
18
+ 'fix',
19
+ 'live',
20
+ 'recur'
21
+ ];
22
+ let SHA = /^[0-9a-f]{40}([0-9a-f]{24})?$/;
23
+ /// explanation({ bug: 'b', cause: 'a race', recur: 'no', fix: undefined }) -> { cause: 'a race', recur: 'no' }
24
+ /** The explanation a call or a body carries, and nothing else it says. */ export let explanation = (args)=>Object.fromEntries(KEYS.filter((k)=>args[k] != null).map((k)=>[
25
+ k,
26
+ String(args[k])
27
+ ]));
28
+ /// unexplained({ cause: 'a race', recur: 'no: the lock holds' }) -> []
29
+ /// unexplained({ cause: ' ', fix: 'abc1234' }) -> ['cause', 'recur', 'fix']
30
+ /** What a resolution lacks: its cause and recur, and a full sha for each
31
+ * commit it names. */ export let unexplained = (r)=>[
32
+ ...[
33
+ 'cause',
34
+ 'recur'
35
+ ].filter((k)=>!String(r[k] ?? '').trim()),
36
+ ...[
37
+ 'since',
38
+ 'fix'
39
+ ].filter((k)=>r[k] != null && !SHA.test(String(r[k])))
40
+ ];
41
+ let refused = (eid, missing)=>new Refused(`bug ${eid} is resolved with its explanation: why it broke ` + '(resolved.cause), whether it can come back (resolved.recur), and ' + 'any commit it names (since, fix) by its full sha. Missing or wrong: ' + missing.join(', '));
42
+ /** The precondition: each bug a batch resolves is explained, counting what
43
+ * its mark already holds. */ export let explaining = hook([
44
+ 'resolved'
45
+ ], (bundles, tx, _error, context)=>{
46
+ let writes = bundles.filter((b)=>b.resolved);
47
+ if (!writes.length) return bundles;
48
+ return after(tx.get(writes.map((b)=>b.entity.eid)), (rows)=>{
49
+ let held = new Map(rows.map((b)=>[
50
+ b.entity.eid,
51
+ b
52
+ ]));
53
+ for (let b of writes){
54
+ // Historical accepted marks can predate explanations. Only trusted
55
+ // writers pass admission with a stamped at; new resolutions still
56
+ // require the explanation and acquire their stamp after this hook.
57
+ if (context?.trusted && comp(b, 'resolved').at && !comp(b, 'resolved').cause && !comp(b, 'resolved').recur) continue;
58
+ let was = held.get(b.entity.eid);
59
+ if (!b.bug && !was?.bug) continue;
60
+ let missing = unexplained({
61
+ ...was?.resolved,
62
+ ...b.resolved
63
+ });
64
+ if (missing.length) throw refused(b.entity.eid, missing);
65
+ }
66
+ return bundles;
67
+ });
68
+ });
69
+ /// let fixed = { entity: { eid: 'b' }, bug: {}, doc: { title: 'TypeError: no row' }, resolved: { cause: 'a race', fix: 'f'.repeat(40), recur: 'no: the lock holds' } }
70
+ /// explained(fixed) -> [['What broke', 'TypeError: no row'], ['Why', 'a race'], ['Fixed in', 'fffffff'], ['Can it come back', 'no: the lock holds']]
71
+ /// explained({ ...fixed, resolved: { cause: 'a race', recur: 'it may' } })[2] -> ['Fixed in', 'no commit named']
72
+ /// explained({ entity: { eid: 'b' }, bug: {}, resolved: {} }) -> []
73
+ /** How a resolved bug was fixed, as its resolver explained it: a label and what
74
+ * it says, for each thing said, as a letter, a page and `yak admin errors`
75
+ * read it. What broke falls back to the bug's headline; `commit` writes a
76
+ * sha. Empty for a bug that is not resolved, or that was resolved before
77
+ * explanations were kept. */ export let explained = (e, commit = sha)=>{
78
+ let r = comp(e, 'resolved');
79
+ if (!r.cause) return [];
80
+ let lines = [
81
+ [
82
+ 'What broke',
83
+ str(r.broke) || headline(said(e))
84
+ ],
85
+ [
86
+ 'Why',
87
+ str(r.cause)
88
+ ],
89
+ [
90
+ 'Introduced in',
91
+ r.since ? commit(str(r.since)) : ''
92
+ ],
93
+ [
94
+ 'Fixed in',
95
+ r.fix ? commit(str(r.fix)) : 'no commit named'
96
+ ],
97
+ [
98
+ 'Went live',
99
+ str(r.live)
100
+ ],
101
+ [
102
+ 'Can it come back',
103
+ str(r.recur)
104
+ ]
105
+ ];
106
+ return lines.filter(([, line])=>line);
107
+ };
108
+ /** The tracker's graph plugin: the precondition that explains resolutions. */ export let resolutions = ()=>({
109
+ name: '@yaks/tracker',
110
+ hooks: {
111
+ precondition: explaining
112
+ }
113
+ });
114
+ //# sourceMappingURL=resolution.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolution.js","sources":["./resolution.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,+EAA+E;AAC/E,iEAAiE;AACjE,8EAA8E;AAC9E,+DAA+D;AAE/D,SAAS,KAAK,wBAA6B;AAE3C,SAAS,OAAO,kCAAuC;AACvD,SAAoB,IAAI,kCAAuC;AAC/D,SAAS,QAAQ,EAAE,GAAG,qBAAoB;AAC1C,SAAS,IAAI,EAAE,GAAG,qBAAoB;AACtC,SAAS,IAAI,uBAAsB;AAkBnC,IAAI,OAAO;EAAC;EAAS;EAAS;EAAS;EAAO;EAAQ;CAAQ;AAC9D,IAAI,MAAM;AAEV,+GAA+G;AAC/G,wEAAwE,GACxE,OAAO,IAAI,cAAc,CACvB,OAEA,OAAO,WAAW,CAChB,KAAK,MAAM,CAAC,CAAC,IAAM,IAAI,CAAC,EAAE,IAAI,MAAM,GAAG,CAAC,CAAC,IAAM;MAAC;MAAG,OAAO,IAAI,CAAC,EAAE;KAAE,GACpE;AAEH,uEAAuE;AACvE,4EAA4E;AAC5E;oBACoB,GACpB,OAAO,IAAI,cAAc,CAAC,IAAsB;OAC3C;MAAC;MAAS;KAAQ,CAAC,MAAM,CAAC,CAAC,IAAM,CAAC,OAAO,CAAC,CAAC,EAAE,IAAI,IAAI,IAAI;OACzD;MAAC;MAAS;KAAM,CAAC,MAAM,CAAC,CAAC,IAAM,CAAC,CAAC,EAAE,IAAI,QAAQ,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,EAAE;GACxE,CAAA;AAED,IAAI,UAAU,CAAC,KAAa,UAC1B,IAAI,QACF,CAAC,IAAI,EAAE,IAAI,gDAAgD,CAAC,GAC1D,sEACA,yEACA,QAAQ,IAAI,CAAC;AAGnB;2B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AAC;MAAiB,EAAE,KAAK,GAAG,OAAO,IAAI,EAAE,KAAK,KAAK;KAAG;IACtD;MAAC;MAAY,EAAE,GAAG,GAAG,OAAO,IAAI,EAAE,GAAG,KAAK;KAAkB;IAC5D;MAAC;MAAa,IAAI,EAAE,IAAI;KAAE;IAC1B;MAAC;MAAoB,IAAI,EAAE,KAAK;KAAE;GACnC;EACD,OAAO,MAAM,MAAM,CAAC,CAAC,GAAG,KAAK,GAAK;AACpC,EAAC;AAED,4EAA4E,GAC5E,OAAO,IAAI,cAAc,IAAc,CAAC;IACtC,MAAM;IACN,OAAO;MAAE,cAAc;IAAW;EACpC,CAAC,EAAC"}
package/resolution.ts ADDED
@@ -0,0 +1,123 @@
1
+ // Every resolved bug says how it was fixed. Only an agent that fixed a bug's
2
+ // cause and saw the fix live resolves it; nothing resolves a bug on its own,
3
+ // and one that stopped stays open. The resolver explains it on the `resolved`
4
+ // mark: what broke, why, the commits that introduced and fixed it, and whether
5
+ // it can come back. The graph refuses a bug's resolution without
6
+ // its cause and recur at every door, so a letter or a page never meets a bare
7
+ // one, except on a bug resolved before explanations were kept.
8
+
9
+ import { after } from '@yaks/fp'
10
+ import type { Bundle, Comp, Plugin } from 'jsr:@yaks/graph@0.2.36'
11
+ import { Refused } from '@yaks/graph/errors'
12
+ import { type Hook, hook } from '@yaks/graph/plugin'
13
+ import { headline, sha } from './brief.js'
14
+ import { comp, str } from './model.js'
15
+ import { said } from './reading.js'
16
+
17
+ /** What a resolver says about a bug: the part of `resolved` it writes. */
18
+ export type Explanation = {
19
+ /** what broke and whom it reached, in plain words */
20
+ broke?: string
21
+ /** why it broke */
22
+ cause: string
23
+ /** the full sha of the commit that introduced it, when known */
24
+ since?: string
25
+ /** the full sha of the commit that fixed it */
26
+ fix?: string
27
+ /** when the fix went live */
28
+ live?: string
29
+ /** whether it can happen again, and why */
30
+ recur: string
31
+ }
32
+
33
+ let KEYS = ['broke', 'cause', 'since', 'fix', 'live', 'recur'] as const
34
+ let SHA = /^[0-9a-f]{40}([0-9a-f]{24})?$/
35
+
36
+ /// explanation({ bug: 'b', cause: 'a race', recur: 'no', fix: undefined }) -> { cause: 'a race', recur: 'no' }
37
+ /** The explanation a call or a body carries, and nothing else it says. */
38
+ export let explanation = (
39
+ args: Record<string, unknown>,
40
+ ): Partial<Explanation> =>
41
+ Object.fromEntries(
42
+ KEYS.filter((k) => args[k] != null).map((k) => [k, String(args[k])]),
43
+ )
44
+
45
+ /// unexplained({ cause: 'a race', recur: 'no: the lock holds' }) -> []
46
+ /// unexplained({ cause: ' ', fix: 'abc1234' }) -> ['cause', 'recur', 'fix']
47
+ /** What a resolution lacks: its cause and recur, and a full sha for each
48
+ * commit it names. */
49
+ export let unexplained = (r: Comp): string[] => [
50
+ ...['cause', 'recur'].filter((k) => !String(r[k] ?? '').trim()),
51
+ ...['since', 'fix'].filter((k) => r[k] != null && !SHA.test(String(r[k]))),
52
+ ]
53
+
54
+ let refused = (eid: string, missing: string[]) =>
55
+ new Refused(
56
+ `bug ${eid} is resolved with its explanation: why it broke ` +
57
+ '(resolved.cause), whether it can come back (resolved.recur), and ' +
58
+ 'any commit it names (since, fix) by its full sha. Missing or wrong: ' +
59
+ missing.join(', '),
60
+ )
61
+
62
+ /** The precondition: each bug a batch resolves is explained, counting what
63
+ * its mark already holds. */
64
+ export let explaining: Hook = hook(
65
+ ['resolved'],
66
+ (bundles, tx, _error, context) => {
67
+ let writes = bundles.filter((b) => b.resolved)
68
+ if (!writes.length) return bundles
69
+ return after(tx.get(writes.map((b) => b.entity.eid)), (rows) => {
70
+ let held = new Map<string, Bundle>(rows.map((b) => [b.entity.eid, b]))
71
+ for (let b of writes) {
72
+ // Historical accepted marks can predate explanations. Only trusted
73
+ // writers pass admission with a stamped at; new resolutions still
74
+ // require the explanation and acquire their stamp after this hook.
75
+ if (
76
+ context?.trusted && comp(b, 'resolved').at &&
77
+ !comp(b, 'resolved').cause &&
78
+ !comp(b, 'resolved').recur
79
+ ) continue
80
+ let was = held.get(b.entity.eid)
81
+ if (!b.bug && !was?.bug) continue
82
+ let missing = unexplained({
83
+ ...was?.resolved as Comp | undefined,
84
+ ...b.resolved as Comp,
85
+ })
86
+ if (missing.length) throw refused(b.entity.eid, missing)
87
+ }
88
+ return bundles
89
+ })
90
+ },
91
+ )
92
+
93
+ /// let fixed = { entity: { eid: 'b' }, bug: {}, doc: { title: 'TypeError: no row' }, resolved: { cause: 'a race', fix: 'f'.repeat(40), recur: 'no: the lock holds' } }
94
+ /// explained(fixed) -> [['What broke', 'TypeError: no row'], ['Why', 'a race'], ['Fixed in', 'fffffff'], ['Can it come back', 'no: the lock holds']]
95
+ /// explained({ ...fixed, resolved: { cause: 'a race', recur: 'it may' } })[2] -> ['Fixed in', 'no commit named']
96
+ /// explained({ entity: { eid: 'b' }, bug: {}, resolved: {} }) -> []
97
+ /** How a resolved bug was fixed, as its resolver explained it: a label and what
98
+ * it says, for each thing said, as a letter, a page and `yak admin errors`
99
+ * read it. What broke falls back to the bug's headline; `commit` writes a
100
+ * sha. Empty for a bug that is not resolved, or that was resolved before
101
+ * explanations were kept. */
102
+ export let explained = (
103
+ e: Bundle,
104
+ commit: (sha: string) => string = sha,
105
+ ): [string, string][] => {
106
+ let r = comp(e, 'resolved')
107
+ if (!r.cause) return []
108
+ let lines: [string, string][] = [
109
+ ['What broke', str(r.broke) || headline(said(e))],
110
+ ['Why', str(r.cause)],
111
+ ['Introduced in', r.since ? commit(str(r.since)) : ''],
112
+ ['Fixed in', r.fix ? commit(str(r.fix)) : 'no commit named'],
113
+ ['Went live', str(r.live)],
114
+ ['Can it come back', str(r.recur)],
115
+ ]
116
+ return lines.filter(([, line]) => line)
117
+ }
118
+
119
+ /** The tracker's graph plugin: the precondition that explains resolutions. */
120
+ export let resolutions = (): Plugin => ({
121
+ name: '@yaks/tracker',
122
+ hooks: { precondition: explaining },
123
+ })
package/routes.js ADDED
@@ -0,0 +1,130 @@
1
+ /** Read-through doors to the independent tracker Worker. Options are read for
2
+ * every request so the CLI's vault-backed secret can rotate without a restart.
3
+ * Remote bundles are never applied to the box's graph. */ import { BARE } from "@yaks/id";
4
+ import { late, Misconfigured, request as upstream, unavailable } from "./remote.js";
5
+ let uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
6
+ let refused = (error, status)=>({
7
+ ok: false,
8
+ error,
9
+ status
10
+ });
11
+ /** One bounded remote read, shared by the HTTP door and graph tools. */ export let read = async (options, path, query, signal, go = fetch, /** the tag of the answer the caller holds: a remote with nothing moved
12
+ * since answers that, reading nothing */ tag)=>{
13
+ let scope = query.get('scope') ?? 'platform';
14
+ if (scope != 'platform' && !uuid.test(scope)) {
15
+ return refused('scope must be platform or a global space eid', 400);
16
+ }
17
+ let n = Number(query.get('limit') ?? 100);
18
+ if (!Number.isSafeInteger(n) || n < 1 || n > 100) {
19
+ return refused('limit must be 1..100', 400);
20
+ }
21
+ let params = new URLSearchParams({
22
+ scope,
23
+ limit: String(n)
24
+ });
25
+ for (let key of path == 'trace' ? [
26
+ 'eid',
27
+ 'after'
28
+ ] : path == 'bugs' ? [
29
+ 'app',
30
+ 'bug',
31
+ 'after'
32
+ ] : [
33
+ 'app',
34
+ 'after'
35
+ ]){
36
+ let value = query.get(key);
37
+ if (path == 'bugs' && key == 'app' && value == '') value = null;
38
+ // A bug may be named by the hex its eid starts with, as a knock quotes
39
+ // it (@yaks/id `BARE`); the Worker resolves it.
40
+ let handle = key == 'bug' && value != null && BARE.test(value);
41
+ if (value != null && !uuid.test(value) && !handle || key == 'eid' && !value) {
42
+ return refused(`${key} must be a global eid${key == 'bug' ? ' or its handle' : ''}`, 400);
43
+ }
44
+ if (value) params.set(key, value);
45
+ }
46
+ for (let key of path == 'bugs' ? [
47
+ 'query',
48
+ 'since'
49
+ ] : []){
50
+ if (query.has(key)) params.set(key, query.get(key));
51
+ }
52
+ let response;
53
+ try {
54
+ response = await upstream(options.remote ?? {}, path, params, {
55
+ signal,
56
+ ...tag ? {
57
+ headers: {
58
+ 'if-none-match': tag
59
+ }
60
+ } : {}
61
+ }, go);
62
+ } catch (error) {
63
+ // Neither a credential, ticket, configured URL nor upstream body is an error report.
64
+ if (error instanceof Misconfigured) return refused(error.message, 500);
65
+ return late(error) ? refused('Remote tracker did not answer in time', 504) : refused('Remote tracker is unavailable', 503);
66
+ }
67
+ let etag = response.headers.get('etag') ?? undefined;
68
+ if (response.status == 304 && etag) {
69
+ return {
70
+ ok: true,
71
+ tag: etag,
72
+ unchanged: true
73
+ };
74
+ }
75
+ let { status } = response;
76
+ if (status == 400) {
77
+ // A 400 refuses what was asked, so the reason the tracker's door gives,
78
+ // its own words in `error`, goes back to whoever asked it; no other
79
+ // answer's body leaves the read.
80
+ let said = await response.json().catch(()=>null);
81
+ let why = typeof said?.error == 'string' ? said.error.slice(0, 500) : '';
82
+ return refused(`Remote tracker refused the read (400)${why ? `: ${why}` : ''}`, 400);
83
+ }
84
+ // Box code can reach the new feed before the remote object upgrades. The
85
+ // old directory still serves discovery; its answer carries no versions,
86
+ // so followers keep polling bugs until the feed becomes available.
87
+ if (path == 'changes' && status == 404) {
88
+ let said = await response.json().catch(()=>null);
89
+ if (said?.error == 'tracker route not found') {
90
+ return read(options, 'scopes', new URLSearchParams({
91
+ scope
92
+ }), signal, go);
93
+ }
94
+ }
95
+ if (!response.ok) {
96
+ return refused(`Remote tracker refused the read (${status})`, status == 404 ? 404 : unavailable(status) ? 503 : 502);
97
+ }
98
+ try {
99
+ return {
100
+ ok: true,
101
+ value: await response.json(),
102
+ ...etag ? {
103
+ tag: etag
104
+ } : {}
105
+ };
106
+ } catch {
107
+ return refused('Remote tracker answered a read that is not JSON', 502);
108
+ }
109
+ };
110
+ /** Only bug and bounded trace reads leave the box. */ export let routes = (host, options = {}, go = host.fetch ?? fetch)=>[
111
+ 'traces',
112
+ 'trace',
113
+ 'bugs'
114
+ ].map((path)=>({
115
+ method: 'GET',
116
+ path: `/tracker/${path}`,
117
+ handle: async (request)=>{
118
+ let result = await read(options, path, new URL(request.url).searchParams, request.signal, go);
119
+ return result.ok ? Response.json(result.value, {
120
+ headers: {
121
+ 'cache-control': 'no-store'
122
+ }
123
+ }) : Response.json({
124
+ error: result.error
125
+ }, {
126
+ status: result.status
127
+ });
128
+ }
129
+ }));
130
+ //# sourceMappingURL=routes.js.map
package/routes.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.js","sources":["./routes.ts"],"names":[],"mappings":"AAAA;;wDAEwD,GAExD,SAAS,IAAI,wBAA6B;AAC1C,SACE,IAAI,EACJ,aAAa,EAEb,WAAW,QAAQ,EACnB,WAAW,sBACO;AAGpB,IAAI,OAAO;AAYX,IAAI,UAAU,CAAC,OAAe,SAAyB,CAAC;IACtD,IAAI;IACJ;IACA;EACF,CAAC;AAED,sEAAsE,GACtE,OAAO,IAAI,OAAO,OAChB,SACA,MACA,OACA,QACA,KAAmB,KAAK,EACxB;yCACuC,GACvC;EAEA,IAAI,QAAQ,MAAM,GAAG,CAAC,YAAY;EAClC,IAAI,SAAS,cAAc,CAAC,KAAK,IAAI,CAAC,QAAQ;IAC5C,OAAO,QAAQ,gDAAgD;EACjE;EACA,IAAI,IAAI,OAAO,MAAM,GAAG,CAAC,YAAY;EACrC,IAAI,CAAC,OAAO,aAAa,CAAC,MAAM,IAAI,KAAK,IAAI,KAAK;IAChD,OAAO,QAAQ,wBAAwB;EACzC;EACA,IAAI,SAAS,IAAI,gBAAgB;IAAE;IAAO,OAAO,OAAO;EAAG;EAC3D,KACE,IAAI,OAAO,QAAQ,UACf;IAAC;IAAO;GAAQ,GAChB,QAAQ,SACR;IAAC;IAAO;IAAO;GAAQ,GACvB;IAAC;IAAO;GAAQ,CACpB;IACA,IAAI,QAAQ,MAAM,GAAG,CAAC;IACtB,IAAI,QAAQ,UAAU,OAAO,SAAS,SAAS,IAAI,QAAQ;IAC3D,uEAAuE;IACvE,gDAAgD;IAChD,IAAI,SAAS,OAAO,SAAS,SAAS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2
+ * every request so the CLI's vault-backed secret can rotate without a restart.
3
+ * Remote bundles are never applied to the box's graph. */
4
+ import type { Route } from 'jsr:@yaks/api@0.2.36'
5
+ import { BARE } from '@yaks/id'
6
+ import {
7
+ late,
8
+ Misconfigured,
9
+ type Remote,
10
+ request as upstream,
11
+ unavailable,
12
+ } from './remote.js'
13
+
14
+ export type Options = { remote?: Remote }
15
+ let uuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
16
+
17
+ /** What a read answered: its value and the tag it was read at, or that
18
+ * nothing moved since the tag it was asked with, or the refusal and the
19
+ * status it is: 500 where this side cannot set the read up (./remote.ts
20
+ * `Misconfigured`), 503 where the tracker is out of reach or cannot answer
21
+ * for now, 504 where it did not answer in time, 400 with the tracker's reason
22
+ * where it refused what was asked, and 502 or 404 where it refused otherwise. */
23
+ export type Read =
24
+ | { ok: true; value: unknown; tag?: string; unchanged?: false }
25
+ | { ok: true; value?: undefined; tag: string; unchanged: true }
26
+ | { ok: false; error: string; status: number }
27
+ let refused = (error: string, status: number): Read => ({
28
+ ok: false,
29
+ error,
30
+ status,
31
+ })
32
+
33
+ /** One bounded remote read, shared by the HTTP door and graph tools. */
34
+ export let read = async (
35
+ options: Options,
36
+ path: 'bugs' | 'trace' | 'traces' | 'changes' | 'scopes',
37
+ query: URLSearchParams,
38
+ signal?: AbortSignal,
39
+ go: typeof fetch = fetch,
40
+ /** the tag of the answer the caller holds: a remote with nothing moved
41
+ * since answers that, reading nothing */
42
+ tag?: string,
43
+ ): Promise<Read> => {
44
+ let scope = query.get('scope') ?? 'platform'
45
+ if (scope != 'platform' && !uuid.test(scope)) {
46
+ return refused('scope must be platform or a global space eid', 400)
47
+ }
48
+ let n = Number(query.get('limit') ?? 100)
49
+ if (!Number.isSafeInteger(n) || n < 1 || n > 100) {
50
+ return refused('limit must be 1..100', 400)
51
+ }
52
+ let params = new URLSearchParams({ scope, limit: String(n) })
53
+ for (
54
+ let key of path == 'trace'
55
+ ? ['eid', 'after']
56
+ : path == 'bugs'
57
+ ? ['app', 'bug', 'after']
58
+ : ['app', 'after']
59
+ ) {
60
+ let value = query.get(key)
61
+ if (path == 'bugs' && key == 'app' && value == '') value = null
62
+ // A bug may be named by the hex its eid starts with, as a knock quotes
63
+ // it (@yaks/id `BARE`); the Worker resolves it.
64
+ let handle = key == 'bug' && value != null && BARE.test(value)
65
+ if (
66
+ value != null && !uuid.test(value) && !handle || key == 'eid' && !value
67
+ ) {
68
+ return refused(
69
+ `${key} must be a global eid${key == 'bug' ? ' or its handle' : ''}`,
70
+ 400,
71
+ )
72
+ }
73
+ if (value) params.set(key, value)
74
+ }
75
+ for (let key of path == 'bugs' ? ['query', 'since'] : []) {
76
+ if (query.has(key)) params.set(key, query.get(key)!)
77
+ }
78
+ let response: Response
79
+ try {
80
+ response = await upstream(
81
+ options.remote ?? {},
82
+ path,
83
+ params,
84
+ { signal, ...tag ? { headers: { 'if-none-match': tag } } : {} },
85
+ go,
86
+ )
87
+ } catch (error) {
88
+ // Neither a credential, ticket, configured URL nor upstream body is an error report.
89
+ if (error instanceof Misconfigured) return refused(error.message, 500)
90
+ return late(error)
91
+ ? refused('Remote tracker did not answer in time', 504)
92
+ : refused('Remote tracker is unavailable', 503)
93
+ }
94
+ let etag = response.headers.get('etag') ?? undefined
95
+ if (response.status == 304 && etag) {
96
+ return { ok: true, tag: etag, unchanged: true }
97
+ }
98
+ let { status } = response
99
+ if (status == 400) {
100
+ // A 400 refuses what was asked, so the reason the tracker's door gives,
101
+ // its own words in `error`, goes back to whoever asked it; no other
102
+ // answer's body leaves the read.
103
+ let said = await response.json().catch(() => null) as
104
+ | { error?: unknown }
105
+ | null
106
+ let why = typeof said?.error == 'string' ? said.error.slice(0, 500) : ''
107
+ return refused(
108
+ `Remote tracker refused the read (400)${why ? `: ${why}` : ''}`,
109
+ 400,
110
+ )
111
+ }
112
+ // Box code can reach the new feed before the remote object upgrades. The
113
+ // old directory still serves discovery; its answer carries no versions,
114
+ // so followers keep polling bugs until the feed becomes available.
115
+ if (path == 'changes' && status == 404) {
116
+ let said = await response.json().catch(() => null) as
117
+ | { error?: unknown }
118
+ | null
119
+ if (said?.error == 'tracker route not found') {
120
+ return read(options, 'scopes', new URLSearchParams({ scope }), signal, go)
121
+ }
122
+ }
123
+ if (!response.ok) {
124
+ return refused(
125
+ `Remote tracker refused the read (${status})`,
126
+ status == 404 ? 404 : unavailable(status) ? 503 : 502,
127
+ )
128
+ }
129
+ try {
130
+ return {
131
+ ok: true,
132
+ value: await response.json(),
133
+ ...etag ? { tag: etag } : {},
134
+ }
135
+ } catch {
136
+ return refused('Remote tracker answered a read that is not JSON', 502)
137
+ }
138
+ }
139
+
140
+ /** Only bug and bounded trace reads leave the box. */
141
+ export let routes = (
142
+ host: { fetch?: typeof fetch },
143
+ options: Options = {},
144
+ go: typeof fetch = host.fetch ?? fetch,
145
+ ): Route[] =>
146
+ (['traces', 'trace', 'bugs'] as const).map((path) => ({
147
+ method: 'GET',
148
+ path: `/tracker/${path}`,
149
+ handle: async (request) => {
150
+ let result = await read(
151
+ options,
152
+ path,
153
+ new URL(request.url).searchParams,
154
+ request.signal,
155
+ go,
156
+ )
157
+ return result.ok
158
+ ? Response.json(result.value, {
159
+ headers: { 'cache-control': 'no-store' },
160
+ })
161
+ : Response.json({ error: result.error }, { status: result.status })
162
+ },
163
+ }))
package/script.js ADDED
@@ -0,0 +1,13 @@
1
+ // The page reporter's source (./page.js) as text, for a server weaving it
2
+ // inline into a page it serves. Read beside this module, wherever the package
3
+ // is served from (@yaks/api/asset): a checkout's file, or JSR's, kept in Deno's
4
+ // module cache.
5
+ import { text } from "@yaks/api/asset";
6
+ /** The page reporter's source.
7
+ *
8
+ * ```ts
9
+ * import { assert } from '@std/assert'
10
+ * assert((await script()).includes('api/report'))
11
+ * ```
12
+ */ export let script = ()=>text(new URL('./page.js', import.meta.url));
13
+ //# sourceMappingURL=script.js.map
package/script.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script.js","sources":["./script.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8EAA8E;AAC9E,gFAAgF;AAChF,gBAAgB;AAEhB,SAAS,IAAI,+BAAoC;AAEjD;;;;;;CAMC,GACD,OAAO,IAAI,SAAS,IAClB,KAAK,IAAI,IAAI,aAAa,YAAY,GAAG,GAAE"}
package/script.ts ADDED
@@ -0,0 +1,16 @@
1
+ // The page reporter's source (./page.js) as text, for a server weaving it
2
+ // inline into a page it serves. Read beside this module, wherever the package
3
+ // is served from (@yaks/api/asset): a checkout's file, or JSR's, kept in Deno's
4
+ // module cache.
5
+
6
+ import { text } from '@yaks/api/asset'
7
+
8
+ /** The page reporter's source.
9
+ *
10
+ * ```ts
11
+ * import { assert } from '@std/assert'
12
+ * assert((await script()).includes('api/report'))
13
+ * ```
14
+ */
15
+ export let script = (): Promise<string> =>
16
+ text(new URL('./page.js', import.meta.url))