Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@atproto/syntax

Package Overview
Dependencies
Maintainers
4
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atproto/syntax - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

tsconfig.build.tsbuildinfo

6

CHANGELOG.md
# @atproto/syntax
## 0.3.1
### Patch Changes
- [#2911](https://github.com/bluesky-social/atproto/pull/2911) [`bac9be2d3`](https://github.com/bluesky-social/atproto/commit/bac9be2d3ec904d1f984a871f43cf89aca17289d) Thanks [@matthieusieben](https://github.com/matthieusieben)! - Improve performances of did validation
## 0.3.0

@@ -4,0 +10,0 @@

8

dist/aturi_validation.js

@@ -33,3 +33,3 @@ "use strict";

const parts = uri.split('/');
if (parts.length >= 3 && (parts[0] != 'at:' || parts[1].length != 0)) {
if (parts.length >= 3 && (parts[0] !== 'at:' || parts[1].length !== 0)) {
throw new Error('ATURI must start with "at://"');

@@ -52,3 +52,3 @@ }

if (parts.length >= 4) {
if (parts[3].length == 0) {
if (parts[3].length === 0) {
throw new Error('ATURI can not have a slash after authority without a path segment');

@@ -64,3 +64,3 @@ }

if (parts.length >= 5) {
if (parts[4].length == 0) {
if (parts[4].length === 0) {
throw new Error('ATURI can not have a slash after collection, unless record key is provided');

@@ -77,3 +77,3 @@ }

if (fragmentPart != null) {
if (fragmentPart.length == 0 || fragmentPart[0] != '/') {
if (fragmentPart.length === 0 || fragmentPart[0] !== '/') {
throw new Error('ATURI fragment must be non-empty and start with slash');

@@ -80,0 +80,0 @@ }

@@ -18,2 +18,5 @@ "use strict";

const ensureValidDid = (did) => {
if (!did.startsWith('did:')) {
throw new InvalidDidError('DID requires "did:" prefix');
}
// check that all chars are boring ASCII

@@ -23,10 +26,7 @@ if (!/^[a-zA-Z0-9._:%-]*$/.test(did)) {

}
const parts = did.split(':');
if (parts.length < 3) {
const { length, 1: method } = did.split(':');
if (length < 3) {
throw new InvalidDidError('DID requires prefix, method, and method-specific content');
}
if (parts[0] != 'did') {
throw new InvalidDidError('DID requires "did:" prefix');
}
if (!/^[a-z]+$/.test(parts[1])) {
if (!/^[a-z]+$/.test(method)) {
throw new InvalidDidError('DID method must be lower-case letters');

@@ -33,0 +33,0 @@ }

@@ -64,3 +64,3 @@ "use strict";

}
if (i + 1 == labels.length && !/^[a-zA-Z]/.test(l)) {
if (i + 1 === labels.length && !/^[a-zA-Z]/.test(l)) {
throw new InvalidHandleError('Handle final component (TLD) must start with ASCII letter');

@@ -67,0 +67,0 @@ }

@@ -84,6 +84,6 @@ "use strict";

}
if (/^[0-9]/.test(l) && i == 0) {
if (/^[0-9]/.test(l) && i === 0) {
throw new InvalidNsidError('NSID first part may not start with a digit');
}
if (!/^[a-zA-Z]+$/.test(l) && i + 1 == labels.length) {
if (!/^[a-zA-Z]+$/.test(l) && i + 1 === labels.length) {
throw new InvalidNsidError('NSID name part must be only letters');

@@ -90,0 +90,0 @@ }

@@ -12,3 +12,3 @@ "use strict";

}
if (rkey == '.' || rkey == '..')
if (rkey === '.' || rkey === '..')
throw new InvalidRecordKeyError('record key can not be "." or ".."');

@@ -15,0 +15,0 @@ };

@@ -5,3 +5,3 @@ "use strict";

const ensureValidTid = (tid) => {
if (tid.length != 13) {
if (tid.length !== 13) {
throw new InvalidTidError('TID must be 13 characters');

@@ -8,0 +8,0 @@ }

{
"name": "@atproto/syntax",
"version": "0.3.0",
"version": "0.3.1",
"license": "MIT",

@@ -20,5 +20,5 @@ "description": "Validation for atproto identifiers and formats: DID, handle, NSID, AT URI, etc",

"types": "dist/index.d.ts",
"dependencies": {},
"devDependencies": {
"jest": "^28.1.2"
"jest": "^28.1.2",
"typescript": "^5.6.3"
},

@@ -25,0 +25,0 @@ "browser": {

@@ -33,3 +33,3 @@ import { ensureValidHandle, ensureValidHandleRegex } from './handle'

const parts = uri.split('/')
if (parts.length >= 3 && (parts[0] != 'at:' || parts[1].length != 0)) {
if (parts.length >= 3 && (parts[0] !== 'at:' || parts[1].length !== 0)) {
throw new Error('ATURI must start with "at://"')

@@ -52,3 +52,3 @@ }

if (parts.length >= 4) {
if (parts[3].length == 0) {
if (parts[3].length === 0) {
throw new Error(

@@ -68,3 +68,3 @@ 'ATURI can not have a slash after authority without a path segment',

if (parts.length >= 5) {
if (parts[4].length == 0) {
if (parts[4].length === 0) {
throw new Error(

@@ -88,3 +88,3 @@ 'ATURI can not have a slash after collection, unless record key is provided',

if (fragmentPart != null) {
if (fragmentPart.length == 0 || fragmentPart[0] != '/') {
if (fragmentPart.length === 0 || fragmentPart[0] !== '/') {
throw new Error('ATURI fragment must be non-empty and start with slash')

@@ -91,0 +91,0 @@ }

@@ -15,2 +15,6 @@ // Human-readable constraints:

export const ensureValidDid = (did: string): void => {
if (!did.startsWith('did:')) {
throw new InvalidDidError('DID requires "did:" prefix')
}
// check that all chars are boring ASCII

@@ -23,4 +27,4 @@ if (!/^[a-zA-Z0-9._:%-]*$/.test(did)) {

const parts = did.split(':')
if (parts.length < 3) {
const { length, 1: method } = did.split(':')
if (length < 3) {
throw new InvalidDidError(

@@ -31,7 +35,3 @@ 'DID requires prefix, method, and method-specific content',

if (parts[0] != 'did') {
throw new InvalidDidError('DID requires "did:" prefix')
}
if (!/^[a-z]+$/.test(parts[1])) {
if (!/^[a-z]+$/.test(method)) {
throw new InvalidDidError('DID method must be lower-case letters')

@@ -38,0 +38,0 @@ }

@@ -68,3 +68,3 @@ export const INVALID_HANDLE = 'handle.invalid'

}
if (i + 1 == labels.length && !/^[a-zA-Z]/.test(l)) {
if (i + 1 === labels.length && !/^[a-zA-Z]/.test(l)) {
throw new InvalidHandleError(

@@ -71,0 +71,0 @@ 'Handle final component (TLD) must start with ASCII letter',

@@ -87,6 +87,6 @@ /*

}
if (/^[0-9]/.test(l) && i == 0) {
if (/^[0-9]/.test(l) && i === 0) {
throw new InvalidNsidError('NSID first part may not start with a digit')
}
if (!/^[a-zA-Z]+$/.test(l) && i + 1 == labels.length) {
if (!/^[a-zA-Z]+$/.test(l) && i + 1 === labels.length) {
throw new InvalidNsidError('NSID name part must be only letters')

@@ -93,0 +93,0 @@ }

@@ -9,3 +9,3 @@ export const ensureValidRecordKey = (rkey: string): void => {

}
if (rkey == '.' || rkey == '..')
if (rkey === '.' || rkey === '..')
throw new InvalidRecordKeyError('record key can not be "." or ".."')

@@ -12,0 +12,0 @@ }

export const ensureValidTid = (tid: string): void => {
if (tid.length != 13) {
if (tid.length !== 13) {
throw new InvalidTidError('TID must be 13 characters')

@@ -4,0 +4,0 @@ }

@@ -517,3 +517,3 @@ import { AtUri, ensureValidAtUri, ensureValidAtUriRegex } from '../src/index'

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -520,0 +520,0 @@ }

@@ -29,3 +29,3 @@ import {

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -48,3 +48,3 @@ }

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -64,3 +64,3 @@ }

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -67,0 +67,0 @@ }

@@ -78,3 +78,3 @@ import { ensureValidDid, ensureValidDidRegex, InvalidDidError } from '../src'

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -94,3 +94,3 @@ }

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -97,0 +97,0 @@ }

@@ -204,3 +204,3 @@ import {

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -220,3 +220,3 @@ }

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -223,0 +223,0 @@ }

@@ -137,3 +137,3 @@ import {

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -153,3 +153,3 @@ }

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -156,0 +156,0 @@ }

@@ -21,3 +21,3 @@ import { ensureValidRecordKey, InvalidRecordKeyError } from '../src'

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -37,3 +37,3 @@ }

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -40,0 +40,0 @@ }

@@ -21,3 +21,3 @@ import { ensureValidTid, InvalidTidError } from '../src'

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -37,3 +37,3 @@ }

lineReader.on('line', (line) => {
if (line.startsWith('#') || line.length == 0) {
if (line.startsWith('#') || line.length === 0) {
return

@@ -40,0 +40,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc