@@ -90,7 +90,6 @@ import {
9090 runtimeNonQueryDependencyContext ,
9191 runtimeQueryDependencyContext ,
9292 type RuntimeDependencyTrackingContext ,
93- resolveCardReference ,
9493 rri ,
9594 type RealmResourceIdentifier ,
9695 type VirtualNetwork ,
@@ -471,8 +470,8 @@ export type GetSearchResourceFunc<T extends CardDef | FileDef = CardDef> = (
471470export interface CardStore {
472471 // The VirtualNetwork that owns this store's realm mappings, used for
473472 // prefix/RRI resolution during (de)serialization. Optional so test doubles
474- // don't need to implement it; resolution sites fall back to the deprecated
475- // module-level resolver when it's absent .
473+ // don't need to implement it; resolution sites degrade — URL-form refs
474+ // still URL-join, prefix-form refs pass through unchanged .
476475 virtualNetwork? : VirtualNetwork ;
477476 getCard(url : string ): CardDef | undefined ;
478477 getFileMeta(url : string ): FileDef | undefined ;
@@ -4647,25 +4646,46 @@ function getStore(instance: BaseDef): CardStore {
46474646
46484647// The VirtualNetwork associated with an instance's store, for prefix/RRI
46494648// resolution outside this module. Returns undefined when the store can't
4650- // supply one, so callers fall back to the deprecated module-level resolver .
4649+ // supply one — callers handle that by degrading to URL math or throwing .
46514650export function virtualNetworkFor(
46524651 instance : BaseDef ,
46534652): VirtualNetwork | undefined {
46544653 return getStore (instance ).virtualNetwork ;
46554654}
46564655
46574656// Resolve a (possibly prefix-form or relative) reference to an absolute URL
4658- // string through the store's VirtualNetwork when available, falling back to
4659- // the deprecated module-level resolver when it's absent.
4657+ // string through the store's VirtualNetwork. When the store doesn't carry
4658+ // a VN (test stubs, detached instances), fall back to plain URL math: it
4659+ // covers URL-form refs and relative refs against URL-form bases. Prefix-form
4660+ // refs and refs against prefix-form bases can't be resolved without a VN —
4661+ // `new URL()` throws on those, so we return the raw reference unchanged
4662+ // instead of bubbling the error to callers (e.g. relationship deserialize
4663+ // uses the returned string as a "did this resolve?" signal).
46604664function resolveRef(
46614665 store : CardStore | undefined ,
46624666 reference : string ,
46634667 relativeTo : RealmResourceIdentifier | URL | undefined ,
46644668): string {
46654669 let vn = store ?.virtualNetwork ;
4666- return vn
4667- ? vn .resolveURL (reference , relativeTo ).href
4668- : resolveCardReference (reference , relativeTo );
4670+ if (vn ) {
4671+ return vn .resolveURL (reference , relativeTo ).href ;
4672+ }
4673+ let base: URL | string | undefined ;
4674+ if (relativeTo instanceof URL ) {
4675+ base = relativeTo ;
4676+ } else if (typeof relativeTo === ' string' ) {
4677+ if (
4678+ relativeTo .startsWith (' http://' ) ||
4679+ relativeTo .startsWith (' https://' )
4680+ ) {
4681+ base = relativeTo ;
4682+ }
4683+ }
4684+ try {
4685+ return new URL (reference , base ).href ;
4686+ } catch {
4687+ return reference ;
4688+ }
46694689}
46704690
46714691function myLoader(): Loader {
@@ -4747,7 +4767,13 @@ class FallbackCardStore implements CardStore {
47474767 opts ? : { dependencyTrackingContext? : RuntimeDependencyTrackingContext },
47484768 ) {
47494769 trackRuntimeInstanceDependency (url , opts ?.dependencyTrackingContext );
4750- let promise = loadCardDocument (fetch , url , this .virtualNetwork );
4770+ let vn = this .virtualNetwork ;
4771+ if (! vn ) {
4772+ throw new Error (
4773+ ` CardStore.loadCardDocument requires a Loader with a VirtualNetwork ` ,
4774+ );
4775+ }
4776+ let promise = loadCardDocument (fetch , url , vn );
47514777 this .trackLoad (promise );
47524778 return await promise ;
47534779 }
@@ -4757,7 +4783,13 @@ class FallbackCardStore implements CardStore {
47574783 opts ? : { dependencyTrackingContext? : RuntimeDependencyTrackingContext },
47584784 ) {
47594785 trackRuntimeFileDependency (url , opts ?.dependencyTrackingContext );
4760- let promise = loadFileMetaDocument (fetch , url , this .virtualNetwork );
4786+ let vn = this .virtualNetwork ;
4787+ if (! vn ) {
4788+ throw new Error (
4789+ ` CardStore.loadFileMetaDocument requires a Loader with a VirtualNetwork ` ,
4790+ );
4791+ }
4792+ let promise = loadFileMetaDocument (fetch , url , vn );
47614793 this .trackLoad (promise );
47624794 return await promise ;
47634795 }
0 commit comments