@atproto/syntax 0.6.3 → 0.6.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.
Files changed (45) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/at-identifier.d.ts +2 -2
  3. package/dist/at-identifier.d.ts.map +1 -1
  4. package/dist/at-identifier.js.map +1 -1
  5. package/dist/aturi.d.ts +5 -5
  6. package/dist/aturi.d.ts.map +1 -1
  7. package/dist/aturi.js +1 -1
  8. package/dist/aturi.js.map +1 -1
  9. package/dist/aturi_validation.d.ts +3 -3
  10. package/dist/aturi_validation.d.ts.map +1 -1
  11. package/dist/aturi_validation.js.map +1 -1
  12. package/dist/language.js +1 -1
  13. package/dist/language.js.map +1 -1
  14. package/dist/nsid.d.ts +1 -1
  15. package/dist/nsid.d.ts.map +1 -1
  16. package/dist/nsid.js.map +1 -1
  17. package/package.json +15 -14
  18. package/benchmark.cjs +0 -208
  19. package/src/at-identifier.ts +0 -104
  20. package/src/aturi.ts +0 -197
  21. package/src/aturi_validation.ts +0 -321
  22. package/src/datetime.ts +0 -369
  23. package/src/did.ts +0 -71
  24. package/src/handle.ts +0 -128
  25. package/src/index.ts +0 -10
  26. package/src/language.ts +0 -39
  27. package/src/lib/result.ts +0 -11
  28. package/src/nsid.ts +0 -182
  29. package/src/recordkey.ts +0 -51
  30. package/src/tid.ts +0 -22
  31. package/src/uri.ts +0 -5
  32. package/tests/aturi-string.test.ts +0 -223
  33. package/tests/aturi.test.ts +0 -428
  34. package/tests/datetime.test.ts +0 -280
  35. package/tests/did.test.ts +0 -104
  36. package/tests/handle.test.ts +0 -239
  37. package/tests/language.test.ts +0 -88
  38. package/tests/nsid.test.ts +0 -174
  39. package/tests/recordkey.test.ts +0 -43
  40. package/tests/tid.test.ts +0 -43
  41. package/tsconfig.build.json +0 -12
  42. package/tsconfig.build.tsbuildinfo +0 -1
  43. package/tsconfig.json +0 -7
  44. package/tsconfig.tests.json +0 -8
  45. package/vitest.config.ts +0 -5
@@ -1,88 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { isValidLanguage, parseLanguageString } from '../src/index.js'
3
-
4
- describe(isValidLanguage, () => {
5
- it('validates BCP 47', () => {
6
- // valid
7
- expect(isValidLanguage('de')).toEqual(true)
8
- expect(isValidLanguage('de-CH')).toEqual(true)
9
- expect(isValidLanguage('de-DE-1901')).toEqual(true)
10
- expect(isValidLanguage('es-419')).toEqual(true)
11
- expect(isValidLanguage('sl-IT-nedis')).toEqual(true)
12
- expect(isValidLanguage('mn-Cyrl-MN')).toEqual(true)
13
- expect(isValidLanguage('x-fr-CH')).toEqual(true)
14
- expect(
15
- isValidLanguage('en-GB-boont-r-extended-sequence-x-private'),
16
- ).toEqual(true)
17
- expect(isValidLanguage('sr-Cyrl')).toEqual(true)
18
- expect(isValidLanguage('hy-Latn-IT-arevela')).toEqual(true)
19
- expect(isValidLanguage('i-klingon')).toEqual(true)
20
- // invalid
21
- expect(isValidLanguage('')).toEqual(false)
22
- expect(isValidLanguage('x')).toEqual(false)
23
- expect(isValidLanguage('de-CH-')).toEqual(false)
24
- expect(isValidLanguage('i-bad-grandfathered')).toEqual(false)
25
- })
26
- })
27
-
28
- describe(parseLanguageString, () => {
29
- it('parses BCP 47', () => {
30
- // valid
31
- expect(parseLanguageString('de')).toEqual({
32
- language: 'de',
33
- })
34
- expect(parseLanguageString('de-CH')).toEqual({
35
- language: 'de',
36
- region: 'CH',
37
- })
38
- expect(parseLanguageString('de-DE-1901')).toEqual({
39
- language: 'de',
40
- region: 'DE',
41
- variant: '1901',
42
- })
43
- expect(parseLanguageString('es-419')).toEqual({
44
- language: 'es',
45
- region: '419',
46
- })
47
- expect(parseLanguageString('sl-IT-nedis')).toEqual({
48
- language: 'sl',
49
- region: 'IT',
50
- variant: 'nedis',
51
- })
52
- expect(parseLanguageString('mn-Cyrl-MN')).toEqual({
53
- language: 'mn',
54
- script: 'Cyrl',
55
- region: 'MN',
56
- })
57
- expect(parseLanguageString('x-fr-CH')).toEqual({
58
- privateUse: 'x-fr-CH',
59
- })
60
- expect(
61
- parseLanguageString('en-GB-boont-r-extended-sequence-x-private'),
62
- ).toEqual({
63
- language: 'en',
64
- region: 'GB',
65
- variant: 'boont',
66
- extension: 'r-extended-sequence',
67
- privateUse: 'x-private',
68
- })
69
- expect(parseLanguageString('sr-Cyrl')).toEqual({
70
- language: 'sr',
71
- script: 'Cyrl',
72
- })
73
- expect(parseLanguageString('hy-Latn-IT-arevela')).toEqual({
74
- language: 'hy',
75
- script: 'Latn',
76
- region: 'IT',
77
- variant: 'arevela',
78
- })
79
- expect(parseLanguageString('i-klingon')).toEqual({
80
- grandfathered: 'i-klingon',
81
- })
82
- // invalid
83
- expect(parseLanguageString('')).toEqual(null)
84
- expect(parseLanguageString('x')).toEqual(null)
85
- expect(parseLanguageString('de-CH-')).toEqual(null)
86
- expect(parseLanguageString('i-bad-grandfathered')).toEqual(null)
87
- })
88
- })
@@ -1,174 +0,0 @@
1
- import * as fs from 'node:fs'
2
- import { describe, expect, it, test } from 'vitest'
3
- import {
4
- InvalidNsidError,
5
- NSID,
6
- ensureValidNsid,
7
- isValidNsid,
8
- parseNsid,
9
- validateNsid,
10
- validateNsidRegex,
11
- } from '../src/index.js'
12
-
13
- describe('NSID parsing & creation', () => {
14
- it('parses valid NSIDs', () => {
15
- expect(NSID.parse('com.example.foo').authority).toBe('example.com')
16
- expect(NSID.parse('com.example.foo').name).toBe('foo')
17
- expect(NSID.parse('com.example.foo').toString()).toBe('com.example.foo')
18
- expect(NSID.parse('com.long-thing1.cool.fooBarBaz').authority).toBe(
19
- 'cool.long-thing1.com',
20
- )
21
- expect(NSID.parse('com.long-thing1.cool.fooBarBaz').name).toBe('fooBarBaz')
22
- expect(NSID.parse('com.long-thing1.cool.fooBarBaz').toString()).toBe(
23
- 'com.long-thing1.cool.fooBarBaz',
24
- )
25
- })
26
-
27
- it('creates valid NSIDs', () => {
28
- expect(NSID.create('example.com', 'foo').authority).toBe('example.com')
29
- expect(NSID.create('example.com', 'foo').name).toBe('foo')
30
- expect(NSID.create('example.com', 'foo').toString()).toBe('com.example.foo')
31
- expect(NSID.create('cool.long-thing1.com', 'fooBarBaz').authority).toBe(
32
- 'cool.long-thing1.com',
33
- )
34
- expect(NSID.create('cool.long-thing1.com', 'fooBarBaz').name).toBe(
35
- 'fooBarBaz',
36
- )
37
- expect(NSID.create('cool.long-thing1.com', 'fooBarBaz').toString()).toBe(
38
- 'com.long-thing1.cool.fooBarBaz',
39
- )
40
- })
41
- })
42
-
43
- describe('NSID validation', () => {
44
- const expectValid = (h: string) => {
45
- expect(isValidNsid(h)).toBe(true)
46
- ensureValidNsid(h)
47
- expect(parseNsid(h)).toEqual(h.split('.'))
48
- expect(validateNsidRegex(h)).toMatchObject({
49
- success: true,
50
- value: expect.any(String),
51
- })
52
- expect(validateNsid(h)).toMatchObject({
53
- success: true,
54
- value: expect.any(Array),
55
- })
56
- }
57
- const expectInvalid = (h: string) => {
58
- expect(isValidNsid(h)).toBe(false)
59
- expect(() => parseNsid(h)).toThrow(InvalidNsidError)
60
- expect(() => ensureValidNsid(h)).toThrow(InvalidNsidError)
61
- expect(validateNsidRegex(h)).toMatchObject({
62
- success: false,
63
- message: expect.any(String),
64
- })
65
- expect(validateNsid(h)).toMatchObject({
66
- success: false,
67
- message: expect.any(String),
68
- })
69
- }
70
-
71
- it('enforces spec details', () => {
72
- expectValid('com.example.foo')
73
- const longNsid = 'com.' + 'o'.repeat(63) + '.foo'
74
- expectValid(longNsid)
75
-
76
- const tooLongNsid = 'com.' + 'o'.repeat(64) + '.foo'
77
- expectInvalid(tooLongNsid)
78
-
79
- const longEnd = 'com.example.' + 'o'.repeat(63)
80
- expectValid(longEnd)
81
-
82
- const tooLongEnd = 'com.example.' + 'o'.repeat(64)
83
- expectInvalid(tooLongEnd)
84
-
85
- const longOverall = 'com.' + 'middle.'.repeat(40) + 'foo'
86
- expect(longOverall.length).toBe(287)
87
- expectValid(longOverall)
88
-
89
- const tooLongOverall = 'com.' + 'middle.'.repeat(50) + 'foo'
90
- expect(tooLongOverall.length).toBe(357)
91
- expectInvalid(tooLongOverall)
92
- })
93
-
94
- describe('valid NSIDs', () => {
95
- test.each([
96
- 'com.example.foo',
97
- 'o'.repeat(63) + '.foo.bar',
98
- 'com.' + 'o'.repeat(63) + '.foo',
99
- 'com.example.' + 'o'.repeat(63),
100
- 'com.' + 'middle.'.repeat(40) + 'foo',
101
-
102
- 'a-0.b-1.c',
103
- 'a.0.c',
104
- 'a.b.c',
105
- 'a0.b1.c3',
106
- 'a0.b1.cc',
107
- 'a01.thing.record',
108
- 'cn.8.lex.stuff',
109
- 'com.example.f00',
110
- 'com.example.fooBar',
111
- 'm.xn--masekowski-d0b.pl',
112
- 'net.users.bob.ping',
113
- 'one.2.three',
114
- 'one.two.three',
115
- 'one.two.three.four-and.FiVe',
116
- 'onion.2gzyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid.lex.deleteThing',
117
- 'onion.expyuzz4wqqyqhjn.spec.getThing',
118
- 'onion.g2zyxa5ihm7nsggfxnu52rck2vv4rvmdlkiu3zzui5du4xyclen53wid.lex.deleteThing',
119
- 'org.4chan.lex.getThing',
120
- 'test.12345.record',
121
- 'xn--fiqs8s.xn--fiqa61au8b7zsevnm8ak20mc4a87e.record.two',
122
- ])('%s', expectValid)
123
- })
124
-
125
- describe('invalid NSIDs', () => {
126
- test.each([
127
- 'o'.repeat(64) + '.foo.bar',
128
- 'com.' + 'o'.repeat(64) + '.foo',
129
- 'com.example.' + 'o'.repeat(64),
130
- 'com.' + 'middle.'.repeat(50) + 'foo',
131
- 'com.example.foo.*',
132
- 'com.example.foo.blah*',
133
- 'com.example.foo.*blah',
134
- 'com.exa💩ple.thing',
135
- 'a-0.b-1.c-3',
136
- 'a-0.b-1.c-o',
137
- '1.0.0.127.record',
138
- '0two.example.foo',
139
- 'example.com',
140
- 'com.example',
141
- 'a.',
142
- '.one.two.three',
143
- 'one.two.three ',
144
- 'one.two..three',
145
- 'one .two.three',
146
- ' one.two.three',
147
- 'com.atproto.feed.p@st',
148
- 'com.atproto.feed.p_st',
149
- 'com.atproto.feed.p*st',
150
- 'com.atproto.feed.po#t',
151
- 'com.atproto.feed.p!ot',
152
- 'com.example-.foo',
153
- 'com.-example.foo',
154
- 'com.example.0foo',
155
- 'com.example.f-o',
156
- ])('%s', expectInvalid)
157
- })
158
-
159
- describe('conforms to interop valid NSIDs', () => {
160
- test.each(readInteropLines('nsid_syntax_valid.txt'))('%s', expectValid)
161
- })
162
-
163
- describe('conforms to interop invalid NSIDs', () => {
164
- test.each(readInteropLines('nsid_syntax_invalid.txt'))('%s', expectInvalid)
165
- })
166
- })
167
-
168
- function readInteropLines(filename: string): string[] {
169
- return fs
170
- .readFileSync(`${__dirname}/interop-files/${filename}`)
171
- .toString()
172
- .split('\n')
173
- .filter((line) => line.length > 0 && !line.startsWith('#'))
174
- }
@@ -1,43 +0,0 @@
1
- import * as fs from 'node:fs'
2
- import * as readline from 'node:readline'
3
- import { describe, expect, it } from 'vitest'
4
- import { InvalidRecordKeyError, ensureValidRecordKey } from '../src/index.js'
5
-
6
- describe('recordkey validation', () => {
7
- const expectValid = (r: string) => {
8
- ensureValidRecordKey(r)
9
- }
10
- const expectInvalid = (r: string) => {
11
- expect(() => ensureValidRecordKey(r)).toThrow(InvalidRecordKeyError)
12
- }
13
-
14
- it('conforms to interop valid recordkey', () => {
15
- const lineReader = readline.createInterface({
16
- input: fs.createReadStream(
17
- `${__dirname}/interop-files/recordkey_syntax_valid.txt`,
18
- ),
19
- terminal: false,
20
- })
21
- lineReader.on('line', (line) => {
22
- if (line.startsWith('#') || line.length === 0) {
23
- return
24
- }
25
- expectValid(line)
26
- })
27
- })
28
-
29
- it('conforms to interop invalid recordkeys', () => {
30
- const lineReader = readline.createInterface({
31
- input: fs.createReadStream(
32
- `${__dirname}/interop-files/recordkey_syntax_invalid.txt`,
33
- ),
34
- terminal: false,
35
- })
36
- lineReader.on('line', (line) => {
37
- if (line.startsWith('#') || line.length === 0) {
38
- return
39
- }
40
- expectInvalid(line)
41
- })
42
- })
43
- })
package/tests/tid.test.ts DELETED
@@ -1,43 +0,0 @@
1
- import * as fs from 'node:fs'
2
- import * as readline from 'node:readline'
3
- import { describe, expect, it } from 'vitest'
4
- import { InvalidTidError, ensureValidTid } from '../src/index.js'
5
-
6
- describe('tid validation', () => {
7
- const expectValid = (t: string) => {
8
- ensureValidTid(t)
9
- }
10
- const expectInvalid = (t: string) => {
11
- expect(() => ensureValidTid(t)).toThrow(InvalidTidError)
12
- }
13
-
14
- it('conforms to interop valid tid', () => {
15
- const lineReader = readline.createInterface({
16
- input: fs.createReadStream(
17
- `${__dirname}/interop-files/tid_syntax_valid.txt`,
18
- ),
19
- terminal: false,
20
- })
21
- lineReader.on('line', (line) => {
22
- if (line.startsWith('#') || line.length === 0) {
23
- return
24
- }
25
- expectValid(line)
26
- })
27
- })
28
-
29
- it('conforms to interop invalid tids', () => {
30
- const lineReader = readline.createInterface({
31
- input: fs.createReadStream(
32
- `${__dirname}/interop-files/tid_syntax_invalid.txt`,
33
- ),
34
- terminal: false,
35
- })
36
- lineReader.on('line', (line) => {
37
- if (line.startsWith('#') || line.length === 0) {
38
- return
39
- }
40
- expectInvalid(line)
41
- })
42
- })
43
- })
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "../../tsconfig/isomorphic.json",
3
- "include": ["./src"],
4
- "exclude": ["**/*.test.ts"],
5
- "compilerOptions": {
6
- "noImplicitAny": true,
7
- "importHelpers": true,
8
- "target": "ES2023",
9
- "rootDir": "./src",
10
- "outDir": "./dist",
11
- },
12
- }
@@ -1 +0,0 @@
1
- {"version":"7.0.0-dev.20260614.1","root":["./src/at-identifier.ts","./src/aturi.ts","./src/aturi_validation.ts","./src/datetime.ts","./src/did.ts","./src/handle.ts","./src/index.ts","./src/language.ts","./src/nsid.ts","./src/recordkey.ts","./src/tid.ts","./src/uri.ts","./src/lib/result.ts"]}
package/tsconfig.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "include": [],
3
- "references": [
4
- { "path": "./tsconfig.build.json" },
5
- { "path": "./tsconfig.tests.json" },
6
- ],
7
- }
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig/vitest.json",
3
- "include": ["./tests", "./src/**/*.test.ts"],
4
- "compilerOptions": {
5
- "noImplicitAny": true,
6
- "rootDir": "./",
7
- },
8
- }
package/vitest.config.ts DELETED
@@ -1,5 +0,0 @@
1
- import { defineProject } from 'vitest/config'
2
-
3
- export default defineProject({
4
- test: {},
5
- })