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,35 @@
import {
createStorageUriResolver,
type StorageUriResolver,
type UriPlugin,
} from "@suaveplan/storage-uri";
import { fallbackUriPlugin } from "../../src/plugin/plugin.js";
import type { FallbackPluginOptions } from "../../src/types/policy.types.js";
/**
* Build a resolver carrying the fallback plugin wired back to itself plus
* the supplied scheme plugins. Uses a late-bound proxy so the plugin can
* recurse through the same resolver instance.
*/
export function buildResolverWithFallback(
extraPlugins: readonly UriPlugin[],
options?: Omit<FallbackPluginOptions, "resolver">
): StorageUriResolver {
let captured: StorageUriResolver | undefined;
const lazy = new Proxy(
{},
{
get(_t, prop) {
if (captured === undefined)
throw new Error("resolver not initialised");
const v = (captured as unknown as Record<string, unknown>)[
prop as string
];
return typeof v === "function" ? v.bind(captured) : v;
},
}
) as StorageUriResolver;
const plugin = fallbackUriPlugin({ ...options, resolver: lazy });
captured = createStorageUriResolver([...extraPlugins, plugin]);
return captured;
}