Skip to content

Commit 9f306ce

Browse files
committed
mods/telemetry: a Choice member may start with a digit; names and keys still start with a letter
1 parent c84f073 commit 9f306ce

6 files changed

Lines changed: 18 additions & 6 deletions

File tree

‎mods/telemetry/hooks/entries/checked-value/checked-value.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
import { CHOICE_TOKEN } from '../choice-token'
12
import { CHOICES_LIMIT } from '../choices-limit'
23
import { isRecord } from '../is-record'
34
import { refusal } from '../refusal'
4-
import { TOKEN } from '../token'
55

66
/**
77
* One property's value as it goes into the metadata: a finite number, a
@@ -49,7 +49,9 @@ export function checkedValue(
4949
const isTokenList =
5050
members.length > 0 &&
5151
members.length <= CHOICES_LIMIT &&
52-
members.every(member => typeof member === 'string' && TOKEN.test(member))
52+
members.every(
53+
member => typeof member === 'string' && CHOICE_TOKEN.test(member),
54+
)
5355

5456
if (!isTokenList) {
5557
throw refusal(
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* The shape of a Choice member: a snake_case token of at most 64 characters,
3+
* which may start with a digit (a bucket such as `110_to_143`), unlike a name
4+
* or a key (TOKEN).
5+
*/
6+
export const CHOICE_TOKEN = /^[a-z0-9][a-z0-9_]{0,63}$/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './choice-token.js'
2+
3+
export * as default from '.'

‎mods/telemetry/hooks/entries/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from './batch-of.js'
22
export * from './checked-fields.js'
33
export * from './checked-mark.js'
44
export * from './checked-value'
5+
export * from './choice-token'
56
export * from './choices-limit'
67
export * from './core-event-prefix'
78
export * from './event-prefix'
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* The shape of an event name, a property key and a Choice member: a
3-
* snake_case token of at most 64 characters, starting with a letter.
2+
* The shape of an event name and a property key: a snake_case token of at
3+
* most 64 characters, starting with a letter (a Choice member: CHOICE_TOKEN).
44
*/
55
export const TOKEN = /^[a-z][a-z0-9_]{0,63}$/

‎mods/telemetry/hooks/telemetry-types/choice/choice.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* A string property: the value and the list it is chosen from, declared
33
* beside it, so no free text reaches the row.
44
*
5-
* Every member of `of` is a snake_case token, at most CHOICES_LIMIT of
6-
* them; `value` is one of them.
5+
* Every member of `of` is a snake_case token, which may start with a digit,
6+
* at most CHOICES_LIMIT of them; `value` is one of them.
77
*/
88
export type Choice = { value: string; of: readonly string[] }

0 commit comments

Comments
 (0)