@atproto/lex-data 0.0.3 → 0.0.5
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 +22 -0
- package/dist/blob.d.ts +6 -0
- package/dist/blob.d.ts.map +1 -1
- package/dist/blob.js +2 -2
- package/dist/blob.js.map +1 -1
- package/dist/cid.d.ts +2 -3
- package/dist/cid.d.ts.map +1 -1
- package/dist/cid.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/language.d.ts +2 -2
- package/dist/language.d.ts.map +1 -1
- package/dist/language.js +4 -4
- package/dist/language.js.map +1 -1
- package/dist/lex-error.d.ts +17 -0
- package/dist/lex-error.d.ts.map +1 -0
- package/dist/lex-error.js +26 -0
- package/dist/lex-error.js.map +1 -0
- package/dist/lex.d.ts.map +1 -1
- package/dist/lex.js +49 -48
- package/dist/lex.js.map +1 -1
- package/dist/lib/nodejs-buffer.d.ts +1 -0
- package/dist/lib/nodejs-buffer.d.ts.map +1 -1
- package/dist/lib/nodejs-buffer.js +1 -1
- package/dist/lib/nodejs-buffer.js.map +1 -1
- package/dist/object.d.ts +13 -1
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +15 -2
- package/dist/object.js.map +1 -1
- package/dist/uint8array-concat.d.ts +3 -0
- package/dist/uint8array-concat.d.ts.map +1 -0
- package/dist/uint8array-concat.js +24 -0
- package/dist/uint8array-concat.js.map +1 -0
- package/dist/uint8array-from-base64.d.ts.map +1 -1
- package/dist/uint8array-from-base64.js +1 -1
- package/dist/uint8array-from-base64.js.map +1 -1
- package/dist/uint8array.d.ts +1 -0
- package/dist/uint8array.d.ts.map +1 -1
- package/dist/uint8array.js +14 -3
- package/dist/uint8array.js.map +1 -1
- package/dist/utf8-grapheme-len.d.ts.map +1 -1
- package/dist/utf8-grapheme-len.js +2 -2
- package/dist/utf8-grapheme-len.js.map +1 -1
- package/dist/utf8-len.d.ts.map +1 -1
- package/dist/utf8-len.js +1 -1
- package/dist/utf8-len.js.map +1 -1
- package/package.json +5 -5
- package/src/blob.test.ts +83 -2
- package/src/blob.ts +8 -2
- package/src/cid.test.ts +126 -0
- package/src/cid.ts +7 -7
- package/src/index.ts +1 -0
- package/src/language.test.ts +34 -33
- package/src/language.ts +2 -2
- package/src/lex-equals.test.ts +30 -0
- package/src/lex-error.ts +34 -0
- package/src/lex.test.ts +156 -1
- package/src/lex.ts +50 -43
- package/src/lib/nodejs-buffer.ts +2 -1
- package/src/object.test.ts +2 -0
- package/src/object.ts +16 -4
- package/src/uint8array-concat.test.ts +197 -0
- package/src/uint8array-concat.ts +21 -0
- package/src/uint8array-from-base64.test.ts +4 -1
- package/src/uint8array-from-base64.ts +1 -1
- package/src/uint8array-to-base64.test.ts +1 -1
- package/src/uint8array.test.ts +484 -0
- package/src/uint8array.ts +14 -2
- package/src/utf8-grapheme-len.test.ts +1 -0
- package/src/utf8-grapheme-len.ts +2 -2
- package/src/utf8-len.test.ts +1 -0
- package/src/utf8-len.ts +1 -1
- package/tsconfig.tests.json +2 -2
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { assert, describe, expect, it } from 'vitest'
|
|
2
|
+
import { ui8ConcatNode, ui8ConcatPonyfill } from './uint8array-concat.js'
|
|
3
|
+
import { ui8Equals } from './uint8array.js'
|
|
4
|
+
|
|
5
|
+
for (const ui8Concat of [ui8ConcatNode, ui8ConcatPonyfill] as const) {
|
|
6
|
+
// Tests should run in NodeJS where implementations are available.
|
|
7
|
+
assert(ui8Concat, 'ui8Concat implementation should not be undefined')
|
|
8
|
+
|
|
9
|
+
describe(ui8Concat.name, () => {
|
|
10
|
+
describe('empty array', () => {
|
|
11
|
+
it('returns empty Uint8Array when given empty array', () => {
|
|
12
|
+
const result = ui8Concat([])
|
|
13
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
14
|
+
expect(result.length).toBe(0)
|
|
15
|
+
})
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
describe('single array', () => {
|
|
19
|
+
it('returns copy of single Uint8Array', () => {
|
|
20
|
+
const input = new Uint8Array([1, 2, 3])
|
|
21
|
+
const result = ui8Concat([input])
|
|
22
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
23
|
+
expect(ui8Equals(result, input)).toBe(true)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('returns copy of single empty Uint8Array', () => {
|
|
27
|
+
const input = new Uint8Array(0)
|
|
28
|
+
const result = ui8Concat([input])
|
|
29
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
30
|
+
expect(result.length).toBe(0)
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('multiple arrays', () => {
|
|
35
|
+
it('concatenates two arrays', () => {
|
|
36
|
+
const a = new Uint8Array([1, 2, 3])
|
|
37
|
+
const b = new Uint8Array([4, 5, 6])
|
|
38
|
+
const result = ui8Concat([a, b])
|
|
39
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
40
|
+
expect(ui8Equals(result, new Uint8Array([1, 2, 3, 4, 5, 6]))).toBe(true)
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('concatenates three arrays', () => {
|
|
44
|
+
const a = new Uint8Array([1, 2])
|
|
45
|
+
const b = new Uint8Array([3, 4])
|
|
46
|
+
const c = new Uint8Array([5, 6])
|
|
47
|
+
const result = ui8Concat([a, b, c])
|
|
48
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
49
|
+
expect(ui8Equals(result, new Uint8Array([1, 2, 3, 4, 5, 6]))).toBe(true)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('concatenates many arrays', () => {
|
|
53
|
+
const arrays = [
|
|
54
|
+
new Uint8Array([0x00]),
|
|
55
|
+
new Uint8Array([0x01, 0x02]),
|
|
56
|
+
new Uint8Array([0x03, 0x04, 0x05]),
|
|
57
|
+
new Uint8Array([0x06, 0x07, 0x08, 0x09]),
|
|
58
|
+
new Uint8Array([0x0a]),
|
|
59
|
+
]
|
|
60
|
+
const result = ui8Concat(arrays)
|
|
61
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
62
|
+
expect(
|
|
63
|
+
ui8Equals(
|
|
64
|
+
result,
|
|
65
|
+
new Uint8Array([
|
|
66
|
+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
|
|
67
|
+
]),
|
|
68
|
+
),
|
|
69
|
+
).toBe(true)
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('arrays with different lengths', () => {
|
|
74
|
+
it('concatenates arrays of varying lengths', () => {
|
|
75
|
+
const a = new Uint8Array([1])
|
|
76
|
+
const b = new Uint8Array([2, 3, 4, 5, 6])
|
|
77
|
+
const c = new Uint8Array([7, 8])
|
|
78
|
+
const result = ui8Concat([a, b, c])
|
|
79
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
80
|
+
expect(
|
|
81
|
+
ui8Equals(result, new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8])),
|
|
82
|
+
).toBe(true)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('handles large arrays', () => {
|
|
86
|
+
const size = 10000
|
|
87
|
+
const a = new Uint8Array(size).fill(0xaa)
|
|
88
|
+
const b = new Uint8Array(size).fill(0xbb)
|
|
89
|
+
const result = ui8Concat([a, b])
|
|
90
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
91
|
+
expect(result.length).toBe(size * 2)
|
|
92
|
+
// Check first array portion
|
|
93
|
+
for (let i = 0; i < size; i++) {
|
|
94
|
+
expect(result[i]).toBe(0xaa)
|
|
95
|
+
}
|
|
96
|
+
// Check second array portion
|
|
97
|
+
for (let i = size; i < size * 2; i++) {
|
|
98
|
+
expect(result[i]).toBe(0xbb)
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
describe('empty Uint8Arrays in input', () => {
|
|
104
|
+
it('handles empty array at the beginning', () => {
|
|
105
|
+
const a = new Uint8Array(0)
|
|
106
|
+
const b = new Uint8Array([1, 2, 3])
|
|
107
|
+
const result = ui8Concat([a, b])
|
|
108
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
109
|
+
expect(ui8Equals(result, new Uint8Array([1, 2, 3]))).toBe(true)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('handles empty array in the middle', () => {
|
|
113
|
+
const a = new Uint8Array([1, 2])
|
|
114
|
+
const b = new Uint8Array(0)
|
|
115
|
+
const c = new Uint8Array([3, 4])
|
|
116
|
+
const result = ui8Concat([a, b, c])
|
|
117
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
118
|
+
expect(ui8Equals(result, new Uint8Array([1, 2, 3, 4]))).toBe(true)
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
it('handles empty array at the end', () => {
|
|
122
|
+
const a = new Uint8Array([1, 2, 3])
|
|
123
|
+
const b = new Uint8Array(0)
|
|
124
|
+
const result = ui8Concat([a, b])
|
|
125
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
126
|
+
expect(ui8Equals(result, new Uint8Array([1, 2, 3]))).toBe(true)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('handles multiple empty arrays', () => {
|
|
130
|
+
const a = new Uint8Array(0)
|
|
131
|
+
const b = new Uint8Array([1])
|
|
132
|
+
const c = new Uint8Array(0)
|
|
133
|
+
const d = new Uint8Array([2])
|
|
134
|
+
const e = new Uint8Array(0)
|
|
135
|
+
const result = ui8Concat([a, b, c, d, e])
|
|
136
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
137
|
+
expect(ui8Equals(result, new Uint8Array([1, 2]))).toBe(true)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
it('handles all empty arrays', () => {
|
|
141
|
+
const a = new Uint8Array(0)
|
|
142
|
+
const b = new Uint8Array(0)
|
|
143
|
+
const c = new Uint8Array(0)
|
|
144
|
+
const result = ui8Concat([a, b, c])
|
|
145
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
146
|
+
expect(result.length).toBe(0)
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
describe('byte value preservation', () => {
|
|
151
|
+
it('preserves all byte values from 0x00 to 0xff', () => {
|
|
152
|
+
const allBytes = new Uint8Array(256)
|
|
153
|
+
for (let i = 0; i < 256; i++) {
|
|
154
|
+
allBytes[i] = i
|
|
155
|
+
}
|
|
156
|
+
const result = ui8Concat([allBytes])
|
|
157
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
158
|
+
expect(ui8Equals(result, allBytes)).toBe(true)
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
it('preserves boundary byte values in concatenation', () => {
|
|
162
|
+
const a = new Uint8Array([0x00, 0x01, 0x7f])
|
|
163
|
+
const b = new Uint8Array([0x80, 0xfe, 0xff])
|
|
164
|
+
const result = ui8Concat([a, b])
|
|
165
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
166
|
+
expect(
|
|
167
|
+
ui8Equals(
|
|
168
|
+
result,
|
|
169
|
+
new Uint8Array([0x00, 0x01, 0x7f, 0x80, 0xfe, 0xff]),
|
|
170
|
+
),
|
|
171
|
+
).toBe(true)
|
|
172
|
+
})
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
describe('subarray handling', () => {
|
|
176
|
+
it('correctly concatenates subarrays', () => {
|
|
177
|
+
const fullArray = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
|
|
178
|
+
const sub1 = fullArray.subarray(0, 3) // [0, 1, 2]
|
|
179
|
+
const sub2 = fullArray.subarray(5, 8) // [5, 6, 7]
|
|
180
|
+
const result = ui8Concat([sub1, sub2])
|
|
181
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
182
|
+
expect(ui8Equals(result, new Uint8Array([0, 1, 2, 5, 6, 7]))).toBe(true)
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
it('correctly concatenates subarray with regular array', () => {
|
|
186
|
+
const fullArray = new Uint8Array([10, 20, 30, 40, 50])
|
|
187
|
+
const sub = fullArray.subarray(1, 4) // [20, 30, 40]
|
|
188
|
+
const regular = new Uint8Array([100, 200])
|
|
189
|
+
const result = ui8Concat([sub, regular])
|
|
190
|
+
expect(result).toBeInstanceOf(Uint8Array)
|
|
191
|
+
expect(ui8Equals(result, new Uint8Array([20, 30, 40, 100, 200]))).toBe(
|
|
192
|
+
true,
|
|
193
|
+
)
|
|
194
|
+
})
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { NodeJSBuffer } from './lib/nodejs-buffer.js'
|
|
2
|
+
|
|
3
|
+
const Buffer = NodeJSBuffer
|
|
4
|
+
|
|
5
|
+
export const ui8ConcatNode = Buffer
|
|
6
|
+
? function ui8ConcatNode(array: readonly Uint8Array[]): Uint8Array {
|
|
7
|
+
return Buffer.concat(array)
|
|
8
|
+
}
|
|
9
|
+
: /* v8 ignore next -- @preserve */ null
|
|
10
|
+
|
|
11
|
+
export function ui8ConcatPonyfill(array: readonly Uint8Array[]): Uint8Array {
|
|
12
|
+
let totalLength = 0
|
|
13
|
+
for (const arr of array) totalLength += arr.length
|
|
14
|
+
const result = new Uint8Array(totalLength)
|
|
15
|
+
let offset = 0
|
|
16
|
+
for (const arr of array) {
|
|
17
|
+
result.set(arr, offset)
|
|
18
|
+
offset += arr.length
|
|
19
|
+
}
|
|
20
|
+
return result
|
|
21
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import 'core-js/modules/es.uint8-array.from-base64.js'
|
|
2
2
|
import 'core-js/modules/es.uint8-array.to-base64.js'
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
import { assert, describe, expect, it } from 'vitest'
|
|
4
5
|
import {
|
|
5
6
|
fromBase64Native,
|
|
6
7
|
fromBase64Node,
|
|
@@ -110,6 +111,8 @@ for (const fromBase64 of [
|
|
|
110
111
|
'YWFh' + '====',
|
|
111
112
|
'YWFh' + '=====',
|
|
112
113
|
'YWFh' + '======',
|
|
114
|
+
'TWEé',
|
|
115
|
+
'TWE👍',
|
|
113
116
|
// More invalid padding
|
|
114
117
|
// 'TWE=', // 'Ma'
|
|
115
118
|
'TWE=' + '=',
|
|
@@ -45,7 +45,7 @@ export const fromBase64Node = Buffer
|
|
|
45
45
|
// results in unexpected behavior downstream (e.g. in tests)
|
|
46
46
|
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength)
|
|
47
47
|
}
|
|
48
|
-
: null
|
|
48
|
+
: /* v8 ignore next -- @preserve */ null
|
|
49
49
|
|
|
50
50
|
export function fromBase64Ponyfill(
|
|
51
51
|
b64: string,
|