@atproto/common-web 0.5.2 → 0.5.3

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/tests/tid.test.ts DELETED
@@ -1,142 +0,0 @@
1
- import { TID } from '../src/tid.js'
2
-
3
- describe('TIDs', () => {
4
- it('creates a new TID', () => {
5
- const tid = TID.next()
6
- const str = tid.toString()
7
- expect(typeof str).toEqual('string')
8
- expect(str.length).toEqual(13)
9
- })
10
-
11
- it('parses a TID', () => {
12
- const tid = TID.next()
13
- const str = tid.toString()
14
- const parsed = TID.fromStr(str)
15
- expect(parsed.timestamp()).toEqual(tid.timestamp())
16
- expect(parsed.clockid()).toEqual(tid.clockid())
17
- })
18
-
19
- it('throws if invalid tid passed', () => {
20
- expect(() => new TID('')).toThrow('Poorly formatted TID: 0 length')
21
- })
22
-
23
- describe('nextStr', () => {
24
- it('returns next tid as a string', () => {
25
- const str = TID.nextStr()
26
- expect(typeof str).toEqual('string')
27
- expect(str.length).toEqual(13)
28
- })
29
-
30
- it('returns a next tid larger than a provided prev', () => {
31
- const prev = TID.fromTime((Date.now() + 5000) * 1000, 0).toString()
32
- const str = TID.nextStr(prev)
33
- expect(str > prev).toBe(true)
34
- })
35
- })
36
-
37
- describe('newestFirst', () => {
38
- it('sorts tids newest first', () => {
39
- const oldest = TID.next()
40
- const newest = TID.next()
41
-
42
- const tids = [oldest, newest]
43
-
44
- tids.sort(TID.newestFirst)
45
-
46
- expect(tids).toEqual([newest, oldest])
47
- })
48
- })
49
-
50
- describe('oldestFirst', () => {
51
- it('sorts tids oldest first', () => {
52
- const oldest = TID.next()
53
- const newest = TID.next()
54
-
55
- const tids = [newest, oldest]
56
-
57
- tids.sort(TID.oldestFirst)
58
-
59
- expect(tids).toEqual([oldest, newest])
60
- })
61
- })
62
-
63
- describe('is', () => {
64
- it('true for valid tids', () => {
65
- const tid = TID.next()
66
- const asStr = tid.toString()
67
-
68
- expect(TID.is(asStr)).toBe(true)
69
- })
70
-
71
- it('false for invalid tids', () => {
72
- expect(TID.is('')).toBe(false)
73
- })
74
- })
75
-
76
- describe('equals', () => {
77
- it('true when same tid', () => {
78
- const tid = TID.next()
79
- expect(tid.equals(tid)).toBe(true)
80
- })
81
-
82
- it('true when different instance, same tid', () => {
83
- const tid0 = TID.next()
84
- const tid1 = new TID(tid0.toString())
85
-
86
- expect(tid0.equals(tid1)).toBe(true)
87
- })
88
-
89
- it('false when different tid', () => {
90
- const tid0 = TID.next()
91
- const tid1 = TID.next()
92
-
93
- expect(tid0.equals(tid1)).toBe(false)
94
- })
95
- })
96
-
97
- describe('newerThan', () => {
98
- it('true for newer tid', () => {
99
- const tid0 = TID.next()
100
- const tid1 = TID.next()
101
-
102
- expect(tid1.newerThan(tid0)).toBe(true)
103
- })
104
-
105
- it('false for older tid', () => {
106
- const tid0 = TID.next()
107
- const tid1 = TID.next()
108
-
109
- expect(tid0.newerThan(tid1)).toBe(false)
110
- })
111
-
112
- it('false for identical tids', () => {
113
- const tid0 = TID.next()
114
- const tid1 = new TID(tid0.toString())
115
-
116
- expect(tid0.newerThan(tid1)).toBe(false)
117
- })
118
- })
119
-
120
- describe('olderThan', () => {
121
- it('true for older tid', () => {
122
- const tid0 = TID.next()
123
- const tid1 = TID.next()
124
-
125
- expect(tid0.olderThan(tid1)).toBe(true)
126
- })
127
-
128
- it('false for newer tid', () => {
129
- const tid0 = TID.next()
130
- const tid1 = TID.next()
131
-
132
- expect(tid1.olderThan(tid0)).toBe(false)
133
- })
134
-
135
- it('false for identical tids', () => {
136
- const tid0 = TID.next()
137
- const tid1 = new TID(tid0.toString())
138
-
139
- expect(tid0.olderThan(tid1)).toBe(false)
140
- })
141
- })
142
- })
@@ -1,107 +0,0 @@
1
- import { util } from '../src/index.js'
2
-
3
- describe('util', () => {
4
- describe('noUndefinedVals', () => {
5
- it('removes undefined top-level keys', () => {
6
- const obj: Record<string, unknown> = {
7
- foo: 123,
8
- bar: undefined,
9
- }
10
-
11
- const result = util.noUndefinedVals(obj)
12
-
13
- expect(result).toBe(obj)
14
- expect(result).toEqual({
15
- foo: 123,
16
- })
17
- })
18
-
19
- it('handles empty objects', () => {
20
- expect(util.noUndefinedVals({})).toEqual({})
21
- })
22
-
23
- it('leaves deep values intact', () => {
24
- const obj: Record<string, unknown> = {
25
- foo: 123,
26
- bar: {
27
- baz: undefined,
28
- },
29
- }
30
- const result = util.noUndefinedVals(obj)
31
-
32
- expect(result).toEqual({
33
- foo: 123,
34
- bar: {
35
- baz: undefined,
36
- },
37
- })
38
- })
39
- })
40
-
41
- describe('flattenUint8Arrays', () => {
42
- it('flattens to single array of values', () => {
43
- const arr = [new Uint8Array([0xa, 0xb]), new Uint8Array([0xc, 0xd])]
44
-
45
- const flat = util.flattenUint8Arrays(arr)
46
-
47
- expect([...flat]).toEqual([0xa, 0xb, 0xc, 0xd])
48
- })
49
-
50
- it('flattens empty arrays', () => {
51
- const arr = [new Uint8Array(0), new Uint8Array(0)]
52
- const flat = util.flattenUint8Arrays(arr)
53
-
54
- expect(flat.length).toBe(0)
55
- })
56
- })
57
-
58
- describe('streamToBuffer', () => {
59
- it('reads iterable into array', async () => {
60
- const iterable: AsyncIterable<Uint8Array> = {
61
- async *[Symbol.asyncIterator]() {
62
- yield new Uint8Array([0xa, 0xb])
63
- yield new Uint8Array([0xc, 0xd])
64
- },
65
- }
66
- const buffer = await util.streamToBuffer(iterable)
67
-
68
- expect([...buffer]).toEqual([0xa, 0xb, 0xc, 0xd])
69
- })
70
- })
71
-
72
- describe('asyncFilter', () => {
73
- it('filters array values', async () => {
74
- const result = await util.asyncFilter([0, 1, 2], (n) =>
75
- Promise.resolve(n === 0),
76
- )
77
-
78
- expect(result).toEqual([0])
79
- })
80
- })
81
-
82
- describe('range', () => {
83
- it('generates numeric range', () => {
84
- expect(util.range(4)).toEqual([0, 1, 2, 3])
85
- })
86
- })
87
-
88
- describe('dedupeStrs', () => {
89
- it('removes duplicates', () => {
90
- expect(util.dedupeStrs(['a', 'a', 'b'])).toEqual(['a', 'b'])
91
- })
92
- })
93
-
94
- describe('parseIntWithFallback', () => {
95
- it('accepts undefined', () => {
96
- expect(util.parseIntWithFallback(undefined, -10)).toBe(-10)
97
- })
98
-
99
- it('parses numbers', () => {
100
- expect(util.parseIntWithFallback('100', -10)).toBe(100)
101
- })
102
-
103
- it('supports non-numeric fallbacks', () => {
104
- expect(util.parseIntWithFallback(undefined, 'foo')).toBe('foo')
105
- })
106
- })
107
- })
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig/isomorphic.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- },
7
- "include": ["./src"],
8
- }
@@ -1 +0,0 @@
1
- {"version":"7.0.0-dev.20260614.1","root":["./src/arrays.ts","./src/async.ts","./src/check.ts","./src/did-doc.ts","./src/index.ts","./src/ipld.ts","./src/retry.ts","./src/strings.ts","./src/tid.ts","./src/times.ts","./src/types.ts","./src/util.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,7 +0,0 @@
1
- {
2
- "extends": "../../tsconfig/tests.json",
3
- "compilerOptions": {
4
- "rootDir": ".",
5
- },
6
- "include": ["./tests"],
7
- }