Skip to content

Commit 2823e20

Browse files
committed
Uint8Array => Uint8Array<ArrayBuffer>
microsoft/TypeScript#59417
1 parent d0f86b0 commit 2823e20

File tree

12 files changed

+27
-26
lines changed

12 files changed

+27
-26
lines changed

app-ugc/src/serviceWorker.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ async function getLocalMediaResponse(
8282
? new Response(media, { status: 404 })
8383
: new Response(media, {
8484
headers: {
85-
8685
// "image" seems like a valid content-type https://stackoverflow.com/a/28390633
8786
'content-type': mediaId.endsWith('.svg') ? 'image/svg+xml' : 'image',
8887
'cache-control': 'max-age=604800, immutable', // 7 days
89-
9088
},
9189
})
9290
}

app/src/domain/sync.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import { throwExp } from 'shared/utility'
1616
export async function postMedia(
1717
type: 'note' | 'template',
1818
mediaId: MediaId,
19-
ids: Array<[NoteId | TemplateId, RemoteNoteId | RemoteTemplateId, RemoteMediaId]>,
19+
ids: Array<
20+
[NoteId | TemplateId, RemoteNoteId | RemoteTemplateId, RemoteMediaId]
21+
>,
2022
data: ArrayBuffer,
2123
) {
2224
const remoteEntityIdAndRemoteMediaId = ids.map(
@@ -39,7 +41,7 @@ export async function postMedia(
3941
}),
4042
},
4143
)
42-
44+
4345
if (200 <= response.status && response.status <= 299) {
4446
await C.db.updateUploadDate(ids)
4547
} else {

app/src/serviceWorker.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,9 @@ async function getLocalMediaResponse(
9292
? new Response(media, { status: 404 })
9393
: new Response(media, {
9494
headers: {
95-
9695
// "image" seems like a valid content-type https://stackoverflow.com/a/28390633
9796
'content-type': mediaId.endsWith('.svg') ? 'image/svg+xml' : 'image',
9897
'cache-control': 'max-age=604800, immutable', // 7 days
99-
10098
},
10199
})
102100
}

app/src/sqlite/database.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export interface Media {
4545
id: MediaId
4646
created: number
4747
edited: number
48-
data: Uint8Array
49-
hash: Uint8Array
48+
data: Uint8Array<ArrayBuffer>
49+
hash: Uint8Array<ArrayBuffer>
5050
}
5151

5252
export interface NoteBase {
@@ -118,7 +118,7 @@ export interface Plugin {
118118
dependencies: string | null
119119
created: number
120120
edited: number
121-
script: Uint8Array
121+
script: Uint8Array<ArrayBuffer>
122122
}
123123

124124
export interface RemoteMedia {
@@ -178,7 +178,6 @@ export interface Setting {
178178
}
179179

180180
export interface DB {
181-
182181
sqlite_temp_master: SqliteTempMaster
183182
distinctCardTag: DistinctCardTag
184183
distinctNoteTag: DistinctNoteTag

app/src/sqlite/settings.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ export function encodeValue(rawValue: SettingValue) {
133133
? encoder.encode(JSON.stringify(rawValue))
134134
: rawValue
135135
}
136-
function decodeValue(value: Uint8Array) {
136+
function decodeValue(value: Uint8Array<ArrayBuffer>) {
137137
return JSON.parse(decoder.decode(value)) as SettingValue
138138
}
139139

hub-ugc/src/serviceWorker.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,9 @@ async function getLocalMediaResponse(
8282
? new Response(media, { status: 404 })
8383
: new Response(media, {
8484
headers: {
85-
8685
// "image" seems like a valid content-type https://stackoverflow.com/a/28390633
8786
'content-type': mediaId.endsWith('.svg') ? 'image/svg+xml' : 'image',
8887
'cache-control': 'max-age=604800, immutable', // 7 days
89-
9088
},
9189
})
9290
}

lrpc/src/config.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,17 @@ if (rawConfig.error !== undefined) {
1212
}
1313

1414
const envZ = z.object({
15-
1615
tursoDbUrl: z.string(),
1716
tursoAuthToken: z.string(),
1817
hubSessionSecret: z.string(),
1918
IS_OFFLINE: z.literal('true').or(z.undefined()),
20-
2119
})
2220

2321
const config = envZ.parse(rawConfig.parsed)
2422
export default config
2523

2624
// grep 8AB879F7-16F0-409F-BAAB-5FB8EB32000D
27-
export function base64ToArray(base64: string): Uint8Array {
25+
export function base64ToArray(base64: string): Uint8Array<ArrayBuffer> {
2826
const binaryString = atob(base64)
2927
const len = binaryString.length
3028
const bytes = new Uint8Array(len)

shared-edge/src/kysely.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,7 +1115,7 @@ async function toTemplateCreates(
11151115

11161116
async function toTemplateCreate(
11171117
n: EditRemoteTemplate | CreateRemoteTemplate,
1118-
remoteId: Uint8Array,
1118+
remoteId: Uint8Array<ArrayBuffer>,
11191119
nook: NookId,
11201120
) {
11211121
const edited = 'remoteId' in n ? new Date().getTime() / 1000 : undefined

shared-edge/src/publicToken.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ grep 69D0971A-FE47-4D4F-91B9-15A6FAA3CAF1
2626

2727
export async function buildPublicToken(
2828
entityId: Base64Url,
29-
mediaHash: Uint8Array,
29+
mediaHash: Uint8Array<ArrayBuffer>,
3030
publicMediaSecret: PublicMediaSecret,
3131
) {
3232
const data = concat(base64urlToArray(entityId), mediaHash)

shared-edge/src/userId.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ export async function getUserId<T extends { hubSessionSecret: Base64 }>(
4141
}
4242
}
4343

44-
let hubSessionSecret: null | Uint8Array = null
44+
let hubSessionSecret: null | Uint8Array<ArrayBuffer> = null
4545

46-
function getHubSessionSecret(hubSessionSecretString: Base64): Uint8Array {
46+
function getHubSessionSecret(
47+
hubSessionSecretString: Base64,
48+
): Uint8Array<ArrayBuffer> {
4749
if (hubSessionSecret === null) {
4850
hubSessionSecret = base64ToArray(hubSessionSecretString)
4951
}

shared/src/binary.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import { type Base64Url, type Base64 } from './brand'
44

55
// https://web.dev/articles/base64-encoding#btoa_and_atob_with_unicode
6-
export function arrayToBase64(bytes: Uint8Array): Base64 {
6+
export function arrayToBase64(bytes: Uint8Array<ArrayBuffer>): Base64 {
77
const binString = String.fromCodePoint(...bytes)
88
return btoa(binString).replaceAll('=', '') as Base64
99
}
1010

1111
// https://web.dev/articles/base64-encoding#btoa_and_atob_with_unicode
12-
export function base64ToArray(base64: Base64): Uint8Array {
12+
export function base64ToArray(base64: Base64): Uint8Array<ArrayBuffer> {
1313
const binString = atob(base64)
1414
return Uint8Array.from(binString, (m) => m.codePointAt(0)!)
1515
}
@@ -22,10 +22,10 @@ export function fromBase64URL(base64url: Base64Url): Base64 {
2222
return base64url.replaceAll('-', '+').replaceAll('_', '/') as Base64
2323
}
2424

25-
export function arrayToBase64url(bytes: Uint8Array): Base64Url {
25+
export function arrayToBase64url(bytes: Uint8Array<ArrayBuffer>): Base64Url {
2626
return toBase64URL(arrayToBase64(bytes))
2727
}
2828

29-
export function base64urlToArray(base64: Base64Url): Uint8Array {
29+
export function base64urlToArray(base64: Base64Url): Uint8Array<ArrayBuffer> {
3030
return base64ToArray(fromBase64URL(base64))
3131
}

shared/src/utility.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,19 @@ export function escapeRegExp(string: string): string {
108108
export const dayInMs = 86_400_000
109109

110110
// https://gist.github.com/72lions/4528834
111-
export function concat(a1: Uint8Array, a2: ArrayBuffer): Uint8Array {
111+
export function concat(
112+
a1: Uint8Array<ArrayBuffer>,
113+
a2: ArrayBuffer,
114+
): Uint8Array<ArrayBuffer> {
112115
const tmp = new Uint8Array(a1.byteLength + a2.byteLength)
113116
tmp.set(a1, 0)
114117
tmp.set(new Uint8Array(a2), a1.byteLength)
115118
return tmp
116119
}
117-
export function concatAB(a1: ArrayBuffer, a2: ArrayBuffer): Uint8Array {
120+
export function concatAB(
121+
a1: ArrayBuffer,
122+
a2: ArrayBuffer,
123+
): Uint8Array<ArrayBuffer> {
118124
const tmp = new Uint8Array(a1.byteLength + a2.byteLength)
119125
tmp.set(new Uint8Array(a1), 0)
120126
tmp.set(new Uint8Array(a2), a1.byteLength)

0 commit comments

Comments
 (0)