Retire the objectid builtin; ship it as data instead

This commit is contained in:
lilleman
2026-08-27 23:21:26 +02:00
committed by lilleman-tw
parent c11ae5f04f
commit 43d3a752b3
3 changed files with 11 additions and 9 deletions
+5 -6
View File
@@ -20,18 +20,17 @@ const (
// the digits emitted so far in the current expansion (luhn, mod11, ean — place
// them after their payload); generators read only the rng (uuid, ulid, ...). All
// must stay pure over (rng, emitted, args) so a seeded faker is reproducible — a
// time-based id (uuid v7, ulid, objectid) draws its timestamp from the rng, not
// time-based id (uuid v7, ulid) draws its timestamp from the rng, not
// the wall clock. Add a builtin only for what data can't express: a random v4
// UUID already ships as data (data/misc/uuid.json), so the builtin is v7.
var builtins = map[string]builtin{
"luhn": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string {
return string(rune('0' + luhnCheck(e)))
}},
"mod11": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string { return mod11Check(e) }},
"ean": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string { return eanCheck(e) }},
"uuid": {arity: 0, call: func(s *session, _ string, _ map[string]node, _ []string) string { return uuidV7(s) }},
"ulid": {arity: 0, call: func(s *session, _ string, _ map[string]node, _ []string) string { return ulid(s) }},
"objectid": {arity: 0, call: func(s *session, _ string, _ map[string]node, _ []string) string { return randHex(s, 24) }},
"mod11": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string { return mod11Check(e) }},
"ean": {arity: 0, call: func(_ *session, e string, _ map[string]node, _ []string) string { return eanCheck(e) }},
"uuid": {arity: 0, call: func(s *session, _ string, _ map[string]node, _ []string) string { return uuidV7(s) }},
"ulid": {arity: 0, call: func(s *session, _ string, _ map[string]node, _ []string) string { return ulid(s) }},
"nanoid": {arity: 1, check: posIntArg, prep: func(a []string) callFn {
n := atoi(a[0])
return func(s *session, _ string, _ map[string]node) string { return nanoid(s, n) }