Skip to content

Commit

Permalink
review adaptations
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieusieben committed Dec 2, 2024
1 parent fb16f40 commit 617d86c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 33 deletions.
41 changes: 10 additions & 31 deletions packages/lexicon/src/validators/complex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,46 +19,25 @@ export function validate(
def: LexUserType,
value: unknown,
): ValidationResult {
// Order based on the number of occurrences in the Bluesky official lexicons:

// grep -oh -R -E '"type": "[^"]+"' lexicons | sort | uniq -c | sort -r
// 873 "type": "string"
// 386 "type": "object"
// 256 "type": "ref"
// 198 "type": "array"
// 136 "type": "integer"
// 103 "type": "query"
// 96 "type": "boolean"
// 93 "type": "params"
// 76 "type": "procedure"
// 52 "type": "union"
// 31 "type": "unknown"
// 29 "type": "token"
// 15 "type": "record"
// 10 "type": "blob"
// 4 "type": "cid-link"
// 2 "type": "subscription"
// 2 "type": "bytes"

switch (def.type) {
case 'boolean':
return boolean(lexicons, path, def, value)
case 'integer':
return integer(lexicons, path, def, value)
case 'string':
return string(lexicons, path, def, value)
case 'bytes':
return bytes(lexicons, path, def, value)
case 'cid-link':
return cidLink(lexicons, path, def, value)
case 'unknown':
return unknown(lexicons, path, def, value)
case 'object':
return object(lexicons, path, def, value)
case 'array':
return array(lexicons, path, def, value)
case 'integer':
return integer(lexicons, path, def, value)
case 'boolean':
return boolean(lexicons, path, def, value)
case 'unknown':
return unknown(lexicons, path, def, value)
case 'blob':
return blob(lexicons, path, def, value)
case 'bytes':
return bytes(lexicons, path, def, value)
case 'cid-link':
return cidLink(lexicons, path, def, value)
default:
return {
success: false,
Expand Down
4 changes: 2 additions & 2 deletions packages/syntax/src/tid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ const TID_LENGTH = 13
const TID_REGEX = /^[234567abcdefghij][234567abcdefghijklmnopqrstuvwxyz]{12}$/

export const ensureValidTid = (tid: string): void => {
if (tid.length !== 13) {
throw new InvalidTidError('TID must be 13 characters')
if (tid.length !== TID_LENGTH) {
throw new InvalidTidError(`TID must be ${TID_LENGTH} characters`)
}
// simple regex to enforce most constraints via just regex and length.
if (!TID_REGEX.test(tid)) {
Expand Down

0 comments on commit 617d86c

Please sign in to comment.