@refactorlabs/recount 0.6.0 → 0.7.0

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/llms.md CHANGED
@@ -48,10 +48,10 @@ recount.addSpan(type, name, options?);
48
48
  const result = await recount.addSpan(type, name, async () => { ... });
49
49
 
50
50
  // callback with options
51
- await recount.addSpan(type, name, { input: { ... }, alerts: [...] }, async () => { ... });
51
+ await recount.addSpan(type, name, { input: { ... } }, async () => { ... });
52
52
  ```
53
53
 
54
- Options: `description`, `input`, `output`, `durationMs`, `alerts`, `redact`, `public`
54
+ Options: `description`, `input`, `output`, `durationMs`, `redact`, `public`
55
55
  (db spans also accept: `metadata: { table, collection, queryType }`, `redactParams`)
56
56
 
57
57
  ### Empty span dropping
@@ -108,7 +108,7 @@ recount.addGroup(
108
108
  );
109
109
  ```
110
110
 
111
- The `g` object exposes `g.span(type, name, options?)` and `g.addMessage(name, text?, opts?)`. Import `SpanGroup` for typing helper functions:
111
+ The `g` object exposes `g.span(type, name, options?)`, `g.addMessage(name, text?, opts?)`, and `g.alert(label, level, opts?)`. Import `SpanGroup` for typing helper functions:
112
112
 
113
113
  ```ts
114
114
  import recount, { SpanGroup } from '@refactorlabs/recount';
@@ -117,7 +117,7 @@ import recount, { SpanGroup } from '@refactorlabs/recount';
117
117
  ## addMessage
118
118
 
119
119
  ```ts
120
- recount.addMessage(name, text?, { level?: 'info'|'warn'|'error', description?: string, alerts?: SpanAlert[], public?: boolean });
120
+ recount.addMessage(name, text?, { level?: 'info'|'warn'|'error', description?: string, public?: boolean });
121
121
  // text is optional - name alone is enough
122
122
  recount.addMessage('Cache warmed');
123
123
  ```
@@ -301,27 +301,26 @@ const users = wrapCollection(db.collection('users'), { redact: ['name'] });
301
301
 
302
302
  ## Alerts
303
303
 
304
+ Alerts are fired imperatively and attach to whichever span was most recently added (via `addSpan`/`addMessage`/`addGroup`) on the active trace. There's no built-in threshold comparison - use a plain `if` and decide the level yourself:
305
+
304
306
  ```ts
305
307
  recount.addSpan('table', 'Affordability', {
306
- alerts: [
307
- {
308
- label: 'Max DTI (40%)',
309
- level: 'error',
310
- gt: 0.4,
311
- checks: [{ target: 'Table title', value: dti }]
312
- },
313
- {
314
- label: 'Min income',
315
- level: 'warn',
316
- lt: 300,
317
- checks: [{ value: disposableIncome }]
318
- }
319
- ],
320
308
  output: recount.table().fromRecords(rows).build()
321
309
  });
310
+
311
+ if (dti > 0.4) {
312
+ recount.addAlert('Max DTI (40%)', 'error', {
313
+ checks: [{ target: 'DTI', value: dti }]
314
+ });
315
+ }
316
+ if (disposableIncome < 300) {
317
+ recount.addAlert('Min income', 'warn', {
318
+ checks: [{ value: disposableIncome }]
319
+ });
320
+ }
322
321
  ```
323
322
 
324
- `target` must match the title passed to `recount.table(title)`. Both `gt` and `lt` can be set on the same rule. At least one check required.
323
+ `recount.addAlert(label, level, opts?)` - `level` is `'warn' | 'error'`. `opts.checks` is optional context: `target` names the field a `value` came from (e.g. `'DTI'`), purely for display in the dashboard - it isn't compared against anything by the SDK. Inside `addGroup`, use `g.alert(label, level, opts?)` instead - it attaches to the last span pushed to that group.
325
324
 
326
325
  ## Redaction
327
326
 
@@ -398,16 +397,13 @@ await recount.startTrace(
398
397
  highlight: 'success'
399
398
  }
400
399
  ])
401
- .build(),
402
- alerts: [
403
- {
404
- label: 'High-value claim (>$5,000)',
405
- level: 'warn',
406
- gt: 5_000,
407
- checks: [{ value: total }]
408
- }
409
- ]
400
+ .build()
410
401
  });
402
+ if (total > 5_000) {
403
+ recount.addAlert('High-value claim (>$5,000)', 'warn', {
404
+ checks: [{ value: total }]
405
+ });
406
+ }
411
407
 
412
408
  recount.addSpan('chart', 'Cost breakdown', {
413
409
  output: recount
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@refactorlabs/recount",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Node.js SDK for Recount",
5
5
  "homepage": "https://recount.refactor.gg",
6
6
  "license": "MIT",