@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/outage.js ADDED
@@ -0,0 +1,129 @@
1
+ // When a platform tracker that does not answer is a failure.
2
+ //
3
+ // The box asks the platform tracker on clocks of its own: the heal service's
4
+ // poll of its bugs (./poll.ts), and the tracker service's standing and
5
+ // delivery syncs (./service.ts). A pass the tracker could not answer for now
6
+ // (it threw `Unavailable`, ./remote.ts) is a line in the log, and its
7
+ // answering again another; the next pass tries again. Only a tracker that has
8
+ // not answered for OUTAGE is reported, once, with the last failure as its
9
+ // cause, since the box is the witness when the platform tracker is down. A
10
+ // tracker that answered `Stopped` (past its rows, ./remote.ts) is not down:
11
+ // it said how long to wait, and its stop was reported where it happened, so
12
+ // no pass goes until the wait is over, and nothing is reported. A
13
+ // pass that has not finished in OUTAGE has hung on this side, and reports
14
+ // that, once. A pass this side could not set up (`Misconfigured`: no
15
+ // address, no secret, a bad address) reports at once, and once until a pass
16
+ // ends otherwise: the remote is read at each use, so the pass after its fix
17
+ // goes out. Any other failure (a refusal of what was asked, a bad answer, a
18
+ // failure on this side) is a bug now, and reports at once. Both the outage and
19
+ // the setup failure are @yaks/effects/outage's record, as the mail pull's and
20
+ // the embedding drain's are: a pass decides on its own clock whether the
21
+ // outage has lasted OUTAGE, and only a hang needs a timer.
22
+ import { failing } from "@yaks/effects/outage";
23
+ import { system } from "@yaks/fp";
24
+ import { Misconfigured, Stopped, Unavailable } from "./remote.js";
25
+ /** How long the platform tracker may go unanswered before a pass reports it,
26
+ * in ms: five minutes, ten polls at the default pace. Each request already
27
+ * retries for up to a minute (./remote.ts), and what has passed on its own (a
28
+ * Durable Object reset, a runtime that stalls for half a minute, a bad path to
29
+ * one colo) was over well within it. Past it, the platform's own reports may
30
+ * not be landing, and nobody else is saying so. */ export const OUTAGE = 300_000;
31
+ let failed = (n)=>`${n} failed ${n == 1 ? 'pass' : 'passes'}`;
32
+ let minutes = `${OUTAGE / 60_000} minutes`;
33
+ /** The passes of one asker of the platform tracker, each deciding what its
34
+ * failure is. */ export let outage = ({ name, every, report = ()=>{}, log = console.warn, clock = system, signal })=>{
35
+ // Since the tracker last answered, counted from the start of the first pass
36
+ // it could not answer: how many it could not.
37
+ let down;
38
+ // The setup failure already reported, its message the cause, while passes
39
+ // keep failing by it.
40
+ let unset;
41
+ // The stop the tracker last answered, and when its wait is over: a pass
42
+ // before then fails by it again, without asking.
43
+ let held;
44
+ let pass = async (run)=>{
45
+ if (held && clock.now() < held.until) throw held.stop;
46
+ // Each pass sets a clock as it starts. A pass still running when it rings
47
+ // has hung: each request to the tracker ends within a minute
48
+ // (./remote.ts), so the hold-up is this side's. It is reported as that,
49
+ // and let go, so the next pass runs.
50
+ let began = clock.now();
51
+ let hang = new AbortController();
52
+ let hung = Promise.withResolvers();
53
+ let cancel = clock.after(OUTAGE, ()=>{
54
+ if (signal?.aborted) return;
55
+ let error = Error(`A pass has run for ${minutes} without finishing`);
56
+ hang.abort(error);
57
+ report(error);
58
+ hung.reject(error);
59
+ });
60
+ // The tracker answered: an outage it was in is over.
61
+ let back = ()=>{
62
+ if (down) {
63
+ log(`${name}: Remote tracker answered again after ${failed(down.failed)}`);
64
+ }
65
+ down = undefined;
66
+ };
67
+ try {
68
+ let value = await Promise.race([
69
+ run(signal ? AbortSignal.any([
70
+ signal,
71
+ hang.signal
72
+ ]) : hang.signal),
73
+ hung.promise
74
+ ]);
75
+ cancel();
76
+ if (held) log(`${name}: Remote tracker takes passes again`);
77
+ held = undefined;
78
+ if (unset) log(`${name}: Remote tracker is set up again`);
79
+ unset = undefined;
80
+ back();
81
+ return value;
82
+ } catch (error) {
83
+ cancel();
84
+ if (hang.signal.aborted || signal?.aborted) throw error;
85
+ if (!(error instanceof Misconfigured)) unset = undefined;
86
+ let was = held;
87
+ held = undefined;
88
+ if (error instanceof Stopped) {
89
+ back();
90
+ if (!was) log(`${name}: ${error.message}; waiting it out`);
91
+ held = {
92
+ stop: error,
93
+ until: clock.now() + error.retry.after
94
+ };
95
+ } else if (error instanceof Unavailable) {
96
+ let { outage, fresh, stayed } = failing(down, began, {
97
+ limit: OUTAGE
98
+ });
99
+ if (fresh) {
100
+ log(`${name}: ${error.message}; trying again every ${every / 1000} s`);
101
+ }
102
+ down = {
103
+ ...outage,
104
+ failed: (down?.failed ?? 0) + 1
105
+ };
106
+ if (stayed != null) {
107
+ report(Error(`Remote tracker has not answered for ${minutes}`, {
108
+ cause: error
109
+ }));
110
+ }
111
+ } else {
112
+ // It answered, wrongly, or this side failed: a bug now, not an outage.
113
+ down = undefined;
114
+ if (error instanceof Misconfigured) {
115
+ let made = failing(unset, began, {
116
+ cause: error.message
117
+ });
118
+ unset = made.outage;
119
+ if (made.fresh) report(error);
120
+ } else report(error);
121
+ }
122
+ throw error;
123
+ }
124
+ };
125
+ return Object.assign(pass, {
126
+ close: ()=>void (down = undefined)
127
+ });
128
+ };
129
+ //# sourceMappingURL=outage.js.map
package/outage.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"outage.js","sources":["./outage.ts"],"names":[],"mappings":"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"}
package/outage.ts ADDED
@@ -0,0 +1,158 @@
1
+ // When a platform tracker that does not answer is a failure.
2
+ //
3
+ // The box asks the platform tracker on clocks of its own: the heal service's
4
+ // poll of its bugs (./poll.ts), and the tracker service's standing and
5
+ // delivery syncs (./service.ts). A pass the tracker could not answer for now
6
+ // (it threw `Unavailable`, ./remote.ts) is a line in the log, and its
7
+ // answering again another; the next pass tries again. Only a tracker that has
8
+ // not answered for OUTAGE is reported, once, with the last failure as its
9
+ // cause, since the box is the witness when the platform tracker is down. A
10
+ // tracker that answered `Stopped` (past its rows, ./remote.ts) is not down:
11
+ // it said how long to wait, and its stop was reported where it happened, so
12
+ // no pass goes until the wait is over, and nothing is reported. A
13
+ // pass that has not finished in OUTAGE has hung on this side, and reports
14
+ // that, once. A pass this side could not set up (`Misconfigured`: no
15
+ // address, no secret, a bad address) reports at once, and once until a pass
16
+ // ends otherwise: the remote is read at each use, so the pass after its fix
17
+ // goes out. Any other failure (a refusal of what was asked, a bad answer, a
18
+ // failure on this side) is a bug now, and reports at once. Both the outage and
19
+ // the setup failure are @yaks/effects/outage's record, as the mail pull's and
20
+ // the embedding drain's are: a pass decides on its own clock whether the
21
+ // outage has lasted OUTAGE, and only a hang needs a timer.
22
+ import { failing, type Outage } from '@yaks/effects/outage'
23
+ import { type Clock, system } from '@yaks/fp'
24
+ import { Misconfigured, Stopped, Unavailable } from './remote.js'
25
+
26
+ /** How long the platform tracker may go unanswered before a pass reports it,
27
+ * in ms: five minutes, ten polls at the default pace. Each request already
28
+ * retries for up to a minute (./remote.ts), and what has passed on its own (a
29
+ * Durable Object reset, a runtime that stalls for half a minute, a bad path to
30
+ * one colo) was over well within it. Past it, the platform's own reports may
31
+ * not be landing, and nobody else is saying so. */
32
+ export const OUTAGE = 300_000
33
+
34
+ export type Watching = {
35
+ /** what makes the passes, at the head of each line: `Tracker poll` */
36
+ name: string
37
+ /** time between passes, in ms */
38
+ every: number
39
+ /** a failure to fix: a pass that failed other than by `Unavailable`, at
40
+ * once (`Misconfigured` once until a pass ends otherwise), the tracker not
41
+ * answering for OUTAGE, once, and a pass running for OUTAGE, once */
42
+ report?: (error: unknown) => void
43
+ /** a pass the tracker could not answer or answered `Stopped`, and its
44
+ * answering again or being set up again (default: `console.warn`) */
45
+ log?: (line: string) => void
46
+ /** what time it is and how a wait is set (default: the runtime's), so a
47
+ * test can hold the clock */
48
+ clock?: Clock
49
+ /** a stop: a pass failing after it decides nothing */
50
+ signal?: AbortSignal
51
+ }
52
+
53
+ /** Runs one pass and keeps its outcome; `close` ends the outage it may be
54
+ * riding out. The pass is handed a signal that aborts once it has hung. */
55
+ export type Watched =
56
+ & (<T>(pass: (signal: AbortSignal) => Promise<T>) => Promise<T>)
57
+ & { close: () => void }
58
+
59
+ let failed = (n: number) => `${n} failed ${n == 1 ? 'pass' : 'passes'}`
60
+ let minutes = `${OUTAGE / 60_000} minutes`
61
+
62
+ /** The passes of one asker of the platform tracker, each deciding what its
63
+ * failure is. */
64
+ export let outage = (
65
+ {
66
+ name,
67
+ every,
68
+ report = () => {},
69
+ log = console.warn,
70
+ clock = system,
71
+ signal,
72
+ }: Watching,
73
+ ): Watched => {
74
+ // Since the tracker last answered, counted from the start of the first pass
75
+ // it could not answer: how many it could not.
76
+ let down: (Outage & { failed: number }) | undefined
77
+ // The setup failure already reported, its message the cause, while passes
78
+ // keep failing by it.
79
+ let unset: Outage | undefined
80
+ // The stop the tracker last answered, and when its wait is over: a pass
81
+ // before then fails by it again, without asking.
82
+ let held: { stop: Stopped; until: number } | undefined
83
+ let pass = async <T>(
84
+ run: (signal: AbortSignal) => Promise<T>,
85
+ ): Promise<T> => {
86
+ if (held && clock.now() < held.until) throw held.stop
87
+ // Each pass sets a clock as it starts. A pass still running when it rings
88
+ // has hung: each request to the tracker ends within a minute
89
+ // (./remote.ts), so the hold-up is this side's. It is reported as that,
90
+ // and let go, so the next pass runs.
91
+ let began = clock.now()
92
+ let hang = new AbortController()
93
+ let hung = Promise.withResolvers<never>()
94
+ let cancel = clock.after(OUTAGE, () => {
95
+ if (signal?.aborted) return
96
+ let error = Error(`A pass has run for ${minutes} without finishing`)
97
+ hang.abort(error)
98
+ report(error)
99
+ hung.reject(error)
100
+ })
101
+ // The tracker answered: an outage it was in is over.
102
+ let back = () => {
103
+ if (down) {
104
+ log(
105
+ `${name}: Remote tracker answered again after ${failed(down.failed)}`,
106
+ )
107
+ }
108
+ down = undefined
109
+ }
110
+ try {
111
+ let value = await Promise.race([
112
+ run(signal ? AbortSignal.any([signal, hang.signal]) : hang.signal),
113
+ hung.promise,
114
+ ])
115
+ cancel()
116
+ if (held) log(`${name}: Remote tracker takes passes again`)
117
+ held = undefined
118
+ if (unset) log(`${name}: Remote tracker is set up again`)
119
+ unset = undefined
120
+ back()
121
+ return value
122
+ } catch (error) {
123
+ cancel()
124
+ if (hang.signal.aborted || signal?.aborted) throw error
125
+ if (!(error instanceof Misconfigured)) unset = undefined
126
+ let was = held
127
+ held = undefined
128
+ if (error instanceof Stopped) {
129
+ back()
130
+ if (!was) log(`${name}: ${error.message}; waiting it out`)
131
+ held = { stop: error, until: clock.now() + error.retry.after }
132
+ } else if (error instanceof Unavailable) {
133
+ let { outage, fresh, stayed } = failing(down, began, { limit: OUTAGE })
134
+ if (fresh) {
135
+ log(`${name}: ${error.message}; trying again every ${every / 1000} s`)
136
+ }
137
+ down = { ...outage, failed: (down?.failed ?? 0) + 1 }
138
+ if (stayed != null) {
139
+ report(
140
+ Error(`Remote tracker has not answered for ${minutes}`, {
141
+ cause: error,
142
+ }),
143
+ )
144
+ }
145
+ } else {
146
+ // It answered, wrongly, or this side failed: a bug now, not an outage.
147
+ down = undefined
148
+ if (error instanceof Misconfigured) {
149
+ let made = failing(unset, began, { cause: error.message })
150
+ unset = made.outage
151
+ if (made.fresh) report(error)
152
+ } else report(error)
153
+ }
154
+ throw error
155
+ }
156
+ }
157
+ return Object.assign(pass, { close: () => void (down = undefined) })
158
+ }
package/package.json CHANGED
@@ -1,6 +1,135 @@
1
1
  {
2
2
  "name": "@yaks/tracker",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.36",
4
+ "homepage": "https://jsr.io/@yaks/tracker",
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
+ "./resolution": {
20
+ "types": "./_dist/resolution.d.ts",
21
+ "default": "./resolution.js"
22
+ },
23
+ "./intake": {
24
+ "types": "./_dist/intake.d.ts",
25
+ "default": "./intake.js"
26
+ },
27
+ "./report": {
28
+ "types": "./_dist/report.d.ts",
29
+ "default": "./report.js"
30
+ },
31
+ "./page": {
32
+ "types": "./page.d.ts",
33
+ "default": "./page.js"
34
+ },
35
+ "./script": {
36
+ "types": "./_dist/script.d.ts",
37
+ "default": "./script.js"
38
+ },
39
+ "./effects": {
40
+ "types": "./_dist/effects.d.ts",
41
+ "default": "./effects.js"
42
+ },
43
+ "./tools": {
44
+ "types": "./_dist/tools.d.ts",
45
+ "default": "./tools.js"
46
+ },
47
+ "./service": {
48
+ "types": "./_dist/service.d.ts",
49
+ "default": "./service.js"
50
+ },
51
+ "./file": {
52
+ "types": "./_dist/file.d.ts",
53
+ "default": "./file.js"
54
+ },
55
+ "./views": {
56
+ "types": "./_dist/views.d.ts",
57
+ "default": "./views.js"
58
+ },
59
+ "./routes": {
60
+ "types": "./_dist/routes.d.ts",
61
+ "default": "./routes.js"
62
+ },
63
+ "./ticket": {
64
+ "types": "./_dist/ticket.d.ts",
65
+ "default": "./ticket.js"
66
+ },
67
+ "./remote": {
68
+ "types": "./_dist/remote.d.ts",
69
+ "default": "./remote.js"
70
+ },
71
+ "./poll": {
72
+ "types": "./_dist/poll.d.ts",
73
+ "default": "./poll.js"
74
+ },
75
+ "./fixtime": {
76
+ "types": "./_dist/fixtime.d.ts",
77
+ "default": "./fixtime.js"
78
+ },
79
+ "./brief": {
80
+ "types": "./_dist/brief.d.ts",
81
+ "default": "./brief.js"
82
+ },
83
+ "./errors": {
84
+ "types": "./_dist/errors.d.ts",
85
+ "default": "./errors.js"
86
+ },
87
+ "./everywhere": {
88
+ "types": "./_dist/everywhere.d.ts",
89
+ "default": "./everywhere.js"
90
+ },
91
+ "./merge": {
92
+ "types": "./_dist/merge.d.ts",
93
+ "default": "./merge.js"
94
+ },
95
+ "./instrument": {
96
+ "types": "./_dist/instrument.d.ts",
97
+ "default": "./instrument.js"
98
+ },
99
+ "./digest": {
100
+ "types": "./_dist/digest.d.ts",
101
+ "default": "./digest.js"
102
+ },
103
+ "./chart": {
104
+ "types": "./_dist/chart.d.ts",
105
+ "default": "./chart.js"
106
+ }
107
+ },
108
+ "license": "Apache-2.0",
109
+ "dependencies": {
110
+ "@yaks/api": "0.2.36",
111
+ "@yaks/blob": "0.2.36",
112
+ "@yaks/effects": "0.2.36",
113
+ "@yaks/file": "0.2.36",
114
+ "@yaks/fp": "0.2.36",
115
+ "@yaks/graph": "0.2.36",
116
+ "@yaks/id": "0.2.36",
117
+ "@yaks/inspect": "0.2.36",
118
+ "@yaks/match": "0.2.36",
119
+ "@yaks/process": "0.2.36",
120
+ "@yaks/query": "0.2.36",
121
+ "@yaks/render": "0.2.36",
122
+ "@yaks/secrets": "0.2.36",
123
+ "@yaks/sql": "0.2.36",
124
+ "@yaks/timing": "0.2.36",
125
+ "@yaks/tools": "0.2.36",
126
+ "@yaks/ui": "0.2.36",
127
+ "@yaks/ux": "0.2.36",
128
+ "@yaks/vocab": "0.2.36",
129
+ "@yaks/wake": "0.2.36",
130
+ "@types/react": "19.3.0",
131
+ "react": "19.3.0"
132
+ },
133
+ "description": "Groups tracked errors into bugs, reports without interrupting callers, and retains and notifies their occurrences.",
134
+ "repository": "https://github.com/yak-sh/yak.git"
135
+ }
package/page.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ // The classic-script browser reporter has no module exports.
2
+ export {}