Initial Commit

This commit is contained in:
2026-05-27 23:47:53 +01:00
parent fbc70f96e6
commit 9b28db724f
18103 changed files with 1600554 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
// Polyfills for test environment — none required; Node 18+ provides
// `URL`, `AbortController`, `ReadableStream`, and `Response` natively.
// File exists so vitest has a stable setup entry and to mirror sibling
// storage packages.
export {};

View File

@@ -0,0 +1,54 @@
// Test-only helpers used by the resolver test suite. Coverage excluded via
// vitest config's `*.test.ts` filter — this file is `.ts` rather than
// `.test.ts` so it can be imported from multiple test files.
import type { StorageLike } from "@suaveplan/types";
/**
* Minimal in-memory `StorageLike` for resolver dispatch tests. NOT a mock —
* it's a real implementation of the structural contract, written by hand
* because rule 2 forbids `vi.mock`. Test files attach this to a
* `UriPlugin` to exercise scheme dispatch.
*/
export class MemoryStorageLike implements StorageLike {
public readonly store = new Map<string, Uint8Array>();
public lastSignal: AbortSignal | undefined;
public getCalls = 0;
public setCalls = 0;
public deleteCalls = 0;
public existsCalls = 0;
public listCalls = 0;
public async get(key: string): Promise<Uint8Array | undefined> {
this.getCalls += 1;
return this.store.get(key);
}
public async set(key: string, value: Uint8Array): Promise<void> {
this.setCalls += 1;
this.store.set(key, value);
}
public async delete(key: string): Promise<boolean> {
this.deleteCalls += 1;
return this.store.delete(key);
}
public async exists(key: string): Promise<boolean> {
this.existsCalls += 1;
return this.store.has(key);
}
public async list(options?: { prefix?: string; limit?: number }): Promise<{
keys: string[];
total: number;
hasMore: boolean;
continuationToken?: string | undefined;
}> {
this.listCalls += 1;
const prefix = options?.prefix ?? "";
const all = [...this.store.keys()].filter((k) => k.startsWith(prefix));
const limit = options?.limit ?? all.length;
const keys = all.slice(0, limit);
return { keys, total: all.length, hasMore: keys.length < all.length };
}
public async clear(): Promise<void> {
this.store.clear();
}
}