@atproto/syntax 0.5.3 → 0.5.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.
- package/CHANGELOG.md +14 -0
- package/dist/aturi.d.ts.map +1 -1
- package/dist/aturi.js +14 -7
- package/dist/aturi.js.map +1 -1
- package/dist/aturi_validation.d.ts +137 -4
- package/dist/aturi_validation.d.ts.map +1 -1
- package/dist/aturi_validation.js +176 -94
- package/dist/aturi_validation.js.map +1 -1
- package/dist/datetime.d.ts +5 -0
- package/dist/datetime.d.ts.map +1 -1
- package/dist/datetime.js +37 -7
- package/dist/datetime.js.map +1 -1
- package/dist/lib/result.d.ts +12 -0
- package/dist/lib/result.d.ts.map +1 -0
- package/dist/lib/result.js +11 -0
- package/dist/lib/result.js.map +1 -0
- package/dist/nsid.d.ts +3 -10
- package/dist/nsid.d.ts.map +1 -1
- package/dist/nsid.js +15 -62
- package/dist/nsid.js.map +1 -1
- package/package.json +1 -1
- package/src/aturi.ts +13 -7
- package/src/aturi_validation.ts +279 -110
- package/src/datetime.ts +41 -8
- package/src/lib/result.ts +11 -0
- package/src/nsid.ts +20 -56
- package/tests/aturi-string.test.ts +68 -40
- package/tests/aturi.test.ts +4 -4
- package/tests/datetime.test.ts +22 -0
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs'
|
|
2
2
|
import { describe, expect, test } from 'vitest'
|
|
3
|
-
import {
|
|
3
|
+
import { InvalidAtUriError, assertAtUriString, isAtUriString } from '../src'
|
|
4
4
|
|
|
5
5
|
describe('valid interop', () => {
|
|
6
6
|
for (const value of readLines(
|
|
@@ -10,13 +10,13 @@ describe('valid interop', () => {
|
|
|
10
10
|
}
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
describe('invalid interop', () => {
|
|
14
|
+
for (const value of readLines(
|
|
15
|
+
`${__dirname}/../../../interop-test-files/syntax/aturi_syntax_invalid.txt`,
|
|
16
|
+
)) {
|
|
17
|
+
testInvalid(value)
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
20
|
|
|
21
21
|
describe('custom cases', () => {
|
|
22
22
|
describe('valid spec basics', () => {
|
|
@@ -65,6 +65,16 @@ describe('custom cases', () => {
|
|
|
65
65
|
testInvalid('at://did:plc:asdf123/-com.atproto.feed.post')
|
|
66
66
|
testInvalid('at://did:plc:asdf@123/com.atproto.feed.post')
|
|
67
67
|
|
|
68
|
+
testInvalid('at://did:plc:asdf123?a')
|
|
69
|
+
testInvalid('at://user.bsky.social?a=B')
|
|
70
|
+
testInvalid('at://did:plc:asdf123/com.atproto.feed.post?foo=bar')
|
|
71
|
+
testInvalid('at://did:plc:asdf123/com.atproto.feed.post/record?q=3')
|
|
72
|
+
|
|
73
|
+
testInvalid('at://did:plc:asdf123?a=b#/frag')
|
|
74
|
+
testInvalid('at://user.bsky.social?a=b#/frag')
|
|
75
|
+
testInvalid('at://did:plc:asdf123/com.atproto.feed.post?a=b#/frag')
|
|
76
|
+
testInvalid('at://did:plc:asdf123/com.atproto.feed.post/record?a=b#/frag')
|
|
77
|
+
|
|
68
78
|
testInvalid('at://DID:plc:asdf123')
|
|
69
79
|
testInvalid('at://user.bsky.123')
|
|
70
80
|
testInvalid('at://bsky')
|
|
@@ -74,8 +84,11 @@ describe('custom cases', () => {
|
|
|
74
84
|
})
|
|
75
85
|
|
|
76
86
|
describe('very long strings', () => {
|
|
77
|
-
testValid('at://did:plc:asdf123/com.atproto.feed.post/' + 'o'.repeat(
|
|
87
|
+
testValid('at://did:plc:asdf123/com.atproto.feed.post/' + 'o'.repeat(512))
|
|
88
|
+
testValid(`at://did:web:x${'.y'.repeat(100)}/com.atproto.feed.post/record`)
|
|
78
89
|
testInvalid(`at://did:plc:${'o'.repeat(8200)}/com.atproto.feed.post/record`)
|
|
90
|
+
testInvalid('at://did:plc:asdf123/com.atproto.feed.post/' + 'o'.repeat(513))
|
|
91
|
+
testInvalid('at://did:plc:asdf123/com.atproto.feed.post/' + 'o'.repeat(800))
|
|
79
92
|
})
|
|
80
93
|
|
|
81
94
|
describe('invalid collection', () => {
|
|
@@ -107,36 +120,39 @@ describe('custom cases', () => {
|
|
|
107
120
|
testValid('at://did:plc:asdf123/com.atproto.feed.post/asdf123')
|
|
108
121
|
})
|
|
109
122
|
|
|
110
|
-
describe('
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
123
|
+
describe('loosely valid trailing slash', () => {
|
|
124
|
+
testLoose('at://did:plc:asdf123/')
|
|
125
|
+
testLoose('at://user.bsky.social/')
|
|
126
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/')
|
|
127
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/record/')
|
|
128
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/record/#/frag')
|
|
116
129
|
})
|
|
117
130
|
|
|
118
|
-
describe('
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
131
|
+
describe('loosely valid record keys', () => {
|
|
132
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/%23')
|
|
133
|
+
|
|
134
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/$@!*)(:,;~.sdf123')
|
|
135
|
+
testLoose("at://did:plc:asdf123/com.atproto.feed.post/~'sdf123")
|
|
136
|
+
|
|
137
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/$')
|
|
138
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/@')
|
|
139
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/!')
|
|
140
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/*')
|
|
141
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/(')
|
|
142
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/,')
|
|
143
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/;')
|
|
144
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/abc%30123')
|
|
145
|
+
|
|
146
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/%30')
|
|
147
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/%3')
|
|
148
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/%')
|
|
149
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/%zz')
|
|
150
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/%%%')
|
|
151
|
+
|
|
152
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/[]')
|
|
153
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/foo[')
|
|
154
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/bar]')
|
|
155
|
+
testLoose('at://did:plc:asdf123/com.atproto.feed.post/[baz]')
|
|
140
156
|
})
|
|
141
157
|
|
|
142
158
|
describe('valid fragment', () => {
|
|
@@ -165,14 +181,26 @@ describe('custom cases', () => {
|
|
|
165
181
|
|
|
166
182
|
function testValid(value: string) {
|
|
167
183
|
test(value, () => {
|
|
168
|
-
expect(
|
|
169
|
-
expect((
|
|
184
|
+
expect(isAtUriString(value)).toBe(true)
|
|
185
|
+
expect(isAtUriString(value, { strict: false })).toBe(true)
|
|
186
|
+
expect(() => assertAtUriString(value)).not.toThrow()
|
|
187
|
+
expect(() => assertAtUriString(value, { strict: false })).not.toThrow()
|
|
170
188
|
})
|
|
171
189
|
}
|
|
172
190
|
|
|
173
191
|
function testInvalid(value: string) {
|
|
174
192
|
test(value, () => {
|
|
175
|
-
expect(
|
|
193
|
+
expect(isAtUriString(value)).toBe(false)
|
|
194
|
+
expect(() => assertAtUriString(value)).toThrow(InvalidAtUriError)
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function testLoose(value: string) {
|
|
199
|
+
test(value, () => {
|
|
200
|
+
expect(isAtUriString(value)).toBe(false)
|
|
201
|
+
expect(isAtUriString(value, { strict: false })).toBe(true)
|
|
202
|
+
expect(() => assertAtUriString(value)).toThrow()
|
|
203
|
+
expect(() => assertAtUriString(value, { strict: false })).not.toThrow()
|
|
176
204
|
})
|
|
177
205
|
}
|
|
178
206
|
|
package/tests/aturi.test.ts
CHANGED
|
@@ -294,16 +294,16 @@ describe(AtUri, () => {
|
|
|
294
294
|
|
|
295
295
|
it('supports modifications', () => {
|
|
296
296
|
const urip = new AtUri('at://foo.com')
|
|
297
|
-
expect(urip.toString()).toBe('at://foo.com
|
|
297
|
+
expect(urip.toString()).toBe('at://foo.com')
|
|
298
298
|
|
|
299
299
|
urip.host = 'bar.com'
|
|
300
|
-
expect(urip.toString()).toBe('at://bar.com
|
|
300
|
+
expect(urip.toString()).toBe('at://bar.com')
|
|
301
301
|
urip.host = 'did:web:localhost%3A1234'
|
|
302
|
-
expect(urip.toString()).toBe('at://did:web:localhost%3A1234
|
|
302
|
+
expect(urip.toString()).toBe('at://did:web:localhost%3A1234')
|
|
303
303
|
urip.host = 'foo.com'
|
|
304
304
|
|
|
305
305
|
urip.pathname = '/'
|
|
306
|
-
expect(urip.toString()).toBe('at://foo.com
|
|
306
|
+
expect(urip.toString()).toBe('at://foo.com')
|
|
307
307
|
urip.pathname = '/foo'
|
|
308
308
|
expect(urip.toString()).toBe('at://foo.com/foo')
|
|
309
309
|
urip.pathname = 'foo'
|
package/tests/datetime.test.ts
CHANGED
|
@@ -128,9 +128,28 @@ describe(normalizeDatetime, () => {
|
|
|
128
128
|
expect(normalizeDatetime('1985-04-12T10:20:50.1+01:00')).toEqual(
|
|
129
129
|
'1985-04-12T09:20:50.100Z',
|
|
130
130
|
)
|
|
131
|
+
expect(normalizeDatetime('Fri, 02 Jan 1999 12:34:56+1212')).toEqual(
|
|
132
|
+
'1999-01-02T00:22:56.000Z',
|
|
133
|
+
)
|
|
134
|
+
expect(normalizeDatetime('Fri, 02 Jan 1999 12:34:56Z')).toEqual(
|
|
135
|
+
'1999-01-02T12:34:56.000Z',
|
|
136
|
+
)
|
|
131
137
|
expect(normalizeDatetime('Fri, 02 Jan 1999 12:34:56 GMT')).toEqual(
|
|
132
138
|
'1999-01-02T12:34:56.000Z',
|
|
133
139
|
)
|
|
140
|
+
expect(normalizeDatetime('Fri, 02 Jan 1999 12:34:56 PST')).toEqual(
|
|
141
|
+
'1999-01-02T20:34:56.000Z',
|
|
142
|
+
)
|
|
143
|
+
expect(normalizeDatetime('Fri, 02 Jan 1999 12:34:56 EST')).toEqual(
|
|
144
|
+
'1999-01-02T17:34:56.000Z',
|
|
145
|
+
)
|
|
146
|
+
// @NOTE "(Central European Standard Time)" is not used by "Date" to infer
|
|
147
|
+
// the right timezone offset, so these will be parsed as UTC
|
|
148
|
+
expect(
|
|
149
|
+
normalizeDatetime(
|
|
150
|
+
'Fri, 02 Jan 1999 12:34:56 (Central European Standard Time)',
|
|
151
|
+
),
|
|
152
|
+
).toEqual('1999-01-02T12:34:56.000Z')
|
|
134
153
|
expect(normalizeDatetime('0001-01-01T00:00:00+01:00')).toEqual(
|
|
135
154
|
'0000-12-31T23:00:00.000Z',
|
|
136
155
|
)
|
|
@@ -170,6 +189,9 @@ describe(normalizeDatetime, () => {
|
|
|
170
189
|
expect(() => normalizeDatetime('1999-19-39T23:20:50.123Z')).toThrow(
|
|
171
190
|
InvalidDatetimeError,
|
|
172
191
|
)
|
|
192
|
+
expect(() => normalizeDatetime('Fri, 02 Jan 1999 12:34:56 AFT')).toThrow(
|
|
193
|
+
InvalidDatetimeError,
|
|
194
|
+
)
|
|
173
195
|
expect(() => normalizeDatetime('-000001-12-31T23:00:00.000Z')).toThrow(
|
|
174
196
|
InvalidDatetimeError,
|
|
175
197
|
)
|
|
@@ -1 +1 @@
|
|
|
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"],"version":"5.8.2"}
|
|
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"],"version":"5.8.2"}
|