Fix more errors, Uint8Array<ArrayBuffer> disambiguation

This commit is contained in:
2025-10-09 16:43:59 +02:00
parent cbdd93e6ba
commit 6717e6b0de
5 changed files with 22 additions and 9 deletions

View File

@@ -40,7 +40,7 @@ export interface AttachmentTable extends AttachmentData, SystemInformation {
export interface FileTable {
sha256: ColumnType<Sha256, Sha256, never>;
data: ColumnType<Uint8Array, Uint8Array, never>;
data: ColumnType<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>, never>;
}
export interface OptionTable {

View File

@@ -2,6 +2,7 @@
import { describe, test } from "bun:test";
import * as cbor from "cbor2";
import { Uint8ArrayArrayBufferFromSelf } from "common";
import { Effect, Schema } from "effect";
import * as Cbor from "./Cbor";
import * as Test from "./Test";
@@ -61,7 +62,7 @@ describe("encodeSchema", () => {
const schema = Schema.Struct({
x: Schema.String,
y: Schema.DateFromSelf,
z: Schema.Uint8ArrayFromSelf,
z: Uint8ArrayArrayBufferFromSelf,
});
const object = schema.make({
@@ -84,7 +85,7 @@ describe("decodeSchema", () => {
const schema = Schema.Struct({
x: Schema.String,
y: Schema.DateFromSelf,
z: Schema.Uint8ArrayFromSelf,
z: Uint8ArrayArrayBufferFromSelf,
});
const object = schema.make({

View File

@@ -1,7 +1,19 @@
import { pipe, Schema } from "effect";
import { Arbitrary, Array, Equal, Equivalence, pipe, Predicate, Pretty, Schema } from "effect";
export const isUint8ArrayArrayBuffer = (input: unknown): input is Uint8Array<ArrayBuffer> => input instanceof Uint8Array && input.buffer instanceof ArrayBuffer;
export class Uint8ArrayArrayBufferFromSelf extends Schema.declare(
isUint8ArrayArrayBuffer,
{
identifier: "Uint8ArrayArrayBufferFromSelf",
pretty: (): Pretty.Pretty<Uint8Array<ArrayBuffer>> => (u8arr) => `new Uint8Array<ArrayBuffer>(${JSON.stringify(globalThis.Array.from(u8arr))})`,
arbitrary: (): Arbitrary.LazyArbitrary<Uint8Array<ArrayBuffer>> => (fc) => fc.uint8Array() as any,
equivalence: (): Equivalence.Equivalence<Uint8Array> => Array.getEquivalence(Equal.equals) as any,
},
) { }
export const Sha256 = pipe(
Schema.Uint8ArrayFromSelf,
Uint8ArrayArrayBufferFromSelf,
Schema.filter((arr) => arr.byteLength === 32),
Schema.brand("Sha256"),
);

View File

@@ -1,4 +1,4 @@
import { AttachmentId, PieceId, RepertoireId, Sha256, UserId } from "common";
import { AttachmentId, PieceId, RepertoireId, Sha256, Uint8ArrayArrayBufferFromSelf, UserId } from "common";
import { pipe, Schema } from "effect";
import { constant } from "effect/Function";
import * as Api from "./Api";
@@ -173,7 +173,7 @@ export default Api.bundle({
pieceId: PieceId,
filename: Schema.NonEmptyString,
mediaType: Schema.NonEmptyString,
data: Schema.Uint8ArrayFromSelf,
data: Uint8ArrayArrayBufferFromSelf,
}),
Attachment,
Schema.Union(Unauthenticated, Unauthorized, NotFound),
@@ -183,7 +183,7 @@ export default Api.bundle({
Schema.Struct({
filename: Schema.NonEmptyString,
mediaType: Schema.NonEmptyString,
data: Schema.Uint8ArrayFromSelf,
data: Uint8ArrayArrayBufferFromSelf,
}),
Schema.Union(Unauthenticated, Unauthorized, NotFound),
),

View File

@@ -21,7 +21,7 @@ export function Repertoires() {
const { isLoading, error, data: repertoireIds } = useLoading(Effect.gen(function* () {
yield* debounce.current;
const data = yield* client.queryRepertoire({
const data = yield* client.queryRepertoires({
name: name !== "" ? Option.some(name) : Option.none(),
offset: 0,
limit: 100,