@atproto/lexicon 0.4.2 → 0.4.4

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.
@@ -567,26 +567,207 @@ describe('Record validation', () => {
567
567
  })
568
568
 
569
569
  it('Applies string length constraint', () => {
570
+ // Shorter than two UTF8 characters
571
+ expect(() =>
572
+ lex.assertValidRecord('com.example.stringLength', {
573
+ $type: 'com.example.stringLength',
574
+ string: '',
575
+ }),
576
+ ).toThrow('Record/string must not be shorter than 2 characters')
577
+ expect(() =>
578
+ lex.assertValidRecord('com.example.stringLength', {
579
+ $type: 'com.example.stringLength',
580
+ string: 'a',
581
+ }),
582
+ ).toThrow('Record/string must not be shorter than 2 characters')
583
+
584
+ // Two to four UTF8 characters
585
+ lex.assertValidRecord('com.example.stringLength', {
586
+ $type: 'com.example.stringLength',
587
+ string: 'ab',
588
+ })
589
+ lex.assertValidRecord('com.example.stringLength', {
590
+ $type: 'com.example.stringLength',
591
+ string: '\u0301', // Combining acute accent (2 bytes)
592
+ })
593
+ lex.assertValidRecord('com.example.stringLength', {
594
+ $type: 'com.example.stringLength',
595
+ string: 'a\u0301', // 'a' + combining acute accent (1 + 2 bytes = 3 bytes)
596
+ })
597
+ lex.assertValidRecord('com.example.stringLength', {
598
+ $type: 'com.example.stringLength',
599
+ string: 'aé', // 'a' (1 byte) + 'é' (2 bytes) = 3 bytes
600
+ })
601
+ lex.assertValidRecord('com.example.stringLength', {
602
+ $type: 'com.example.stringLength',
603
+ string: 'abc',
604
+ })
570
605
  lex.assertValidRecord('com.example.stringLength', {
571
606
  $type: 'com.example.stringLength',
572
- string: '123',
607
+ string: '', // CJK character (3 bytes)
573
608
  })
609
+ lex.assertValidRecord('com.example.stringLength', {
610
+ $type: 'com.example.stringLength',
611
+ string: '\uD83D', // Unpaired high surrogate (3 bytes)
612
+ })
613
+ lex.assertValidRecord('com.example.stringLength', {
614
+ $type: 'com.example.stringLength',
615
+ string: 'abcd',
616
+ })
617
+ lex.assertValidRecord('com.example.stringLength', {
618
+ $type: 'com.example.stringLength',
619
+ string: 'éé', // 'é' + 'é' (2 + 2 bytes = 4 bytes)
620
+ })
621
+ lex.assertValidRecord('com.example.stringLength', {
622
+ $type: 'com.example.stringLength',
623
+ string: 'aaé', // 1 + 1 + 2 = 4 bytes
624
+ })
625
+ lex.assertValidRecord('com.example.stringLength', {
626
+ $type: 'com.example.stringLength',
627
+ string: '👋', // 4 bytes
628
+ })
629
+
574
630
  expect(() =>
575
631
  lex.assertValidRecord('com.example.stringLength', {
576
632
  $type: 'com.example.stringLength',
577
- string: '1',
633
+ string: 'abcde',
578
634
  }),
579
- ).toThrow('Record/string must not be shorter than 2 characters')
635
+ ).toThrow('Record/string must not be longer than 4 characters')
580
636
  expect(() =>
581
637
  lex.assertValidRecord('com.example.stringLength', {
582
638
  $type: 'com.example.stringLength',
583
- string: '12345',
639
+ string: 'a\u0301\u0301', // 1 + (2 * 2) = 5 bytes
584
640
  }),
585
641
  ).toThrow('Record/string must not be longer than 4 characters')
586
642
  expect(() =>
587
643
  lex.assertValidRecord('com.example.stringLength', {
588
644
  $type: 'com.example.stringLength',
589
- string: '👨‍👩‍👧‍👧',
645
+ string: '\uD83D\uD83D', // Two unpaired high surrogates (3 * 2 = 6 bytes)
646
+ }),
647
+ ).toThrow('Record/string must not be longer than 4 characters')
648
+ expect(() =>
649
+ lex.assertValidRecord('com.example.stringLength', {
650
+ $type: 'com.example.stringLength',
651
+ string: 'ééé', // 2 + 2 + 2 bytes = 6 bytes
652
+ }),
653
+ ).toThrow('Record/string must not be longer than 4 characters')
654
+ expect(() =>
655
+ lex.assertValidRecord('com.example.stringLength', {
656
+ $type: 'com.example.stringLength',
657
+ string: '👋a', // 4 + 1 bytes = 5 bytes
658
+ }),
659
+ ).toThrow('Record/string must not be longer than 4 characters')
660
+ expect(() =>
661
+ lex.assertValidRecord('com.example.stringLength', {
662
+ $type: 'com.example.stringLength',
663
+ string: '👨👨', // 4 + 4 = 8 bytes
664
+ }),
665
+ ).toThrow('Record/string must not be longer than 4 characters')
666
+ expect(() =>
667
+ lex.assertValidRecord('com.example.stringLength', {
668
+ $type: 'com.example.stringLength',
669
+ string: '👨‍👩‍👧‍👧', // 4 emojis × 4 bytes + 3 ZWJs × 3 bytes = 25 bytes
670
+ }),
671
+ ).toThrow('Record/string must not be longer than 4 characters')
672
+ })
673
+
674
+ it('Applies string length constraint (no minLength)', () => {
675
+ // Shorter than two UTF8 characters
676
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
677
+ $type: 'com.example.stringLengthNoMinLength',
678
+ string: '',
679
+ })
680
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
681
+ $type: 'com.example.stringLengthNoMinLength',
682
+ string: 'a',
683
+ })
684
+
685
+ // Two to four UTF8 characters
686
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
687
+ $type: 'com.example.stringLengthNoMinLength',
688
+ string: 'ab',
689
+ })
690
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
691
+ $type: 'com.example.stringLengthNoMinLength',
692
+ string: '\u0301', // Combining acute accent (2 bytes)
693
+ })
694
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
695
+ $type: 'com.example.stringLengthNoMinLength',
696
+ string: 'a\u0301', // 'a' + combining acute accent (1 + 2 bytes = 3 bytes)
697
+ })
698
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
699
+ $type: 'com.example.stringLengthNoMinLength',
700
+ string: 'aé', // 'a' (1 byte) + 'é' (2 bytes) = 3 bytes
701
+ })
702
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
703
+ $type: 'com.example.stringLengthNoMinLength',
704
+ string: 'abc',
705
+ })
706
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
707
+ $type: 'com.example.stringLengthNoMinLength',
708
+ string: '一', // CJK character (3 bytes)
709
+ })
710
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
711
+ $type: 'com.example.stringLengthNoMinLength',
712
+ string: '\uD83D', // Unpaired high surrogate (3 bytes)
713
+ })
714
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
715
+ $type: 'com.example.stringLengthNoMinLength',
716
+ string: 'abcd',
717
+ })
718
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
719
+ $type: 'com.example.stringLengthNoMinLength',
720
+ string: 'éé', // 'é' + 'é' (2 + 2 bytes = 4 bytes)
721
+ })
722
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
723
+ $type: 'com.example.stringLengthNoMinLength',
724
+ string: 'aaé', // 1 + 1 + 2 = 4 bytes
725
+ })
726
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
727
+ $type: 'com.example.stringLengthNoMinLength',
728
+ string: '👋', // 4 bytes
729
+ })
730
+
731
+ expect(() =>
732
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
733
+ $type: 'com.example.stringLengthNoMinLength',
734
+ string: 'abcde',
735
+ }),
736
+ ).toThrow('Record/string must not be longer than 4 characters')
737
+ expect(() =>
738
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
739
+ $type: 'com.example.stringLengthNoMinLength',
740
+ string: 'a\u0301\u0301', // 1 + (2 * 2) = 5 bytes
741
+ }),
742
+ ).toThrow('Record/string must not be longer than 4 characters')
743
+ expect(() =>
744
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
745
+ $type: 'com.example.stringLengthNoMinLength',
746
+ string: '\uD83D\uD83D', // Two unpaired high surrogates (3 * 2 = 6 bytes)
747
+ }),
748
+ ).toThrow('Record/string must not be longer than 4 characters')
749
+ expect(() =>
750
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
751
+ $type: 'com.example.stringLengthNoMinLength',
752
+ string: 'ééé', // 2 + 2 + 2 bytes = 6 bytes
753
+ }),
754
+ ).toThrow('Record/string must not be longer than 4 characters')
755
+ expect(() =>
756
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
757
+ $type: 'com.example.stringLengthNoMinLength',
758
+ string: '👋a', // 4 + 1 bytes = 5 bytes
759
+ }),
760
+ ).toThrow('Record/string must not be longer than 4 characters')
761
+ expect(() =>
762
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
763
+ $type: 'com.example.stringLengthNoMinLength',
764
+ string: '👨👨', // 4 + 4 = 8 bytes
765
+ }),
766
+ ).toThrow('Record/string must not be longer than 4 characters')
767
+ expect(() =>
768
+ lex.assertValidRecord('com.example.stringLengthNoMinLength', {
769
+ $type: 'com.example.stringLengthNoMinLength',
770
+ string: '👨‍👩‍👧‍👧', // 4 emojis × 4 bytes + 3 ZWJs × 3 bytes = 25 bytes
590
771
  }),
591
772
  ).toThrow('Record/string must not be longer than 4 characters')
592
773
  })
@@ -0,0 +1 @@
1
+ {"root":["./src/blob-refs.ts","./src/index.ts","./src/lexicons.ts","./src/serialize.ts","./src/types.ts","./src/util.ts","./src/validation.ts","./src/validators/blob.ts","./src/validators/complex.ts","./src/validators/formats.ts","./src/validators/primitives.ts","./src/validators/xrpc.ts"],"version":"5.6.3"}
@@ -0,0 +1 @@
1
+ {"root":["./tests/general.test.ts","./tests/_scaffolds/lexicons.ts"],"version":"5.6.3"}