Skip to content

Commit 5d2708b

Browse files
committed
Preserve baseUrl for cached re-parse of preprocessed properties
Store the baseUrl from fromJsonLd() on the instance as a protected #_baseUrl field and thread it through accessor re-parse paths. This ensures relative Link href values embedded inside icon/image properties can be resolved when the accessor is called without an explicit baseUrl and the parent object has no id. The stored URL is defensively copied to prevent callers from mutating the original URL and affecting later lazy resolution. Assisted-by: OpenCode:deepseek-v4-pro Assisted-by: Codex:gpt-5.5
1 parent f1a9bde commit 5d2708b

7 files changed

Lines changed: 355 additions & 14 deletions

File tree

packages/vocab-tools/src/__snapshots__/class.test.ts.deno.snap

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class Object {
4848
values?: Record<string, unknown>;
4949
};
5050
#cachedJsonLd?: unknown;
51+
readonly #_baseUrl?: URL;
5152
readonly id: URL | null;
5253

5354
protected get _documentLoader(): DocumentLoader | undefined {
@@ -77,6 +78,10 @@ export class Object {
7778
protected set _cachedJsonLd(value: unknown | undefined) {
7879
this.#cachedJsonLd = value;
7980
}
81+
82+
protected get _baseUrl(): URL | undefined {
83+
return this.#_baseUrl;
84+
}
8085

8186
/**
8287
* The type URI of {@link Object}: \`https://www.w3.org/ns/activitystreams#Object\`.
@@ -205,6 +210,8 @@ proofs?: (DataIntegrityProof | URL)[];interactionPolicy?: InteractionPolicy | nu
205210
this.#documentLoader = options.documentLoader;
206211
this.#contextLoader = options.contextLoader;
207212
this.#tracerProvider = options.tracerProvider;
213+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
214+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
208215
if (\\"\$warning\\" in options) {
209216
this.#warning = options.\$warning as unknown as {
210217
category: string[];
@@ -3784,7 +3791,7 @@ get names(): ((string | LanguageString))[] {
37843791
v = await this.#icon_fromJsonLd(doc, {
37853792
...options,
37863793
baseUrl: (options as { baseUrl?: URL }).baseUrl ?? this.id ??
3787-
undefined,
3794+
this._baseUrl,
37883795
});
37893796

37903797
}
@@ -3886,7 +3893,7 @@ get names(): ((string | LanguageString))[] {
38863893
v = await this.#icon_fromJsonLd(obj, {
38873894
...options,
38883895
baseUrl: (options as { baseUrl?: URL }).baseUrl ?? this.id ??
3889-
undefined,
3896+
this._baseUrl,
38903897
});
38913898

38923899
}
@@ -4131,7 +4138,7 @@ get names(): ((string | LanguageString))[] {
41314138
v = await this.#image_fromJsonLd(doc, {
41324139
...options,
41334140
baseUrl: (options as { baseUrl?: URL }).baseUrl ?? this.id ??
4134-
undefined,
4141+
this._baseUrl,
41354142
});
41364143

41374144
}
@@ -4233,7 +4240,7 @@ get names(): ((string | LanguageString))[] {
42334240
v = await this.#image_fromJsonLd(obj, {
42344241
...options,
42354242
baseUrl: (options as { baseUrl?: URL }).baseUrl ?? this.id ??
4236-
undefined,
4243+
this._baseUrl,
42374244
});
42384245

42394246
}
@@ -18148,6 +18155,7 @@ export class PropertyValue {
1814818155
values?: Record<string, unknown>;
1814918156
};
1815018157
#cachedJsonLd?: unknown;
18158+
readonly #_baseUrl?: URL;
1815118159
readonly id: URL | null;
1815218160

1815318161
protected get _documentLoader(): DocumentLoader | undefined {
@@ -18177,6 +18185,10 @@ export class PropertyValue {
1817718185
protected set _cachedJsonLd(value: unknown | undefined) {
1817818186
this.#cachedJsonLd = value;
1817918187
}
18188+
18189+
protected get _baseUrl(): URL | undefined {
18190+
return this.#_baseUrl;
18191+
}
1818018192

1818118193
/**
1818218194
* The type URI of {@link PropertyValue}: \`http://schema.org#PropertyValue\`.
@@ -18208,6 +18220,8 @@ name?: string | LanguageString | null;value?: string | LanguageString | null;}
1820818220
this.#documentLoader = options.documentLoader;
1820918221
this.#contextLoader = options.contextLoader;
1821018222
this.#tracerProvider = options.tracerProvider;
18223+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
18224+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
1821118225
if (\\"\$warning\\" in options) {
1821218226
this.#warning = options.\$warning as unknown as {
1821318227
category: string[];
@@ -18749,6 +18763,7 @@ export class Measure {
1874918763
values?: Record<string, unknown>;
1875018764
};
1875118765
#cachedJsonLd?: unknown;
18766+
readonly #_baseUrl?: URL;
1875218767
readonly id: URL | null;
1875318768

1875418769
protected get _documentLoader(): DocumentLoader | undefined {
@@ -18778,6 +18793,10 @@ export class Measure {
1877818793
protected set _cachedJsonLd(value: unknown | undefined) {
1877918794
this.#cachedJsonLd = value;
1878018795
}
18796+
18797+
protected get _baseUrl(): URL | undefined {
18798+
return this.#_baseUrl;
18799+
}
1878118800

1878218801
/**
1878318802
* The type URI of {@link Measure}: \`http://www.ontology-of-units-of-measure.org/resource/om-2/Measure\`.
@@ -18809,6 +18828,8 @@ unit?: string | null;numericalValue?: Decimal | null;}
1880918828
this.#documentLoader = options.documentLoader;
1881018829
this.#contextLoader = options.contextLoader;
1881118830
this.#tracerProvider = options.tracerProvider;
18831+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
18832+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
1881218833
if (\\"\$warning\\" in options) {
1881318834
this.#warning = options.\$warning as unknown as {
1881418835
category: string[];
@@ -20696,6 +20717,7 @@ export class InteractionPolicy {
2069620717
values?: Record<string, unknown>;
2069720718
};
2069820719
#cachedJsonLd?: unknown;
20720+
readonly #_baseUrl?: URL;
2069920721
readonly id: URL | null;
2070020722

2070120723
protected get _documentLoader(): DocumentLoader | undefined {
@@ -20725,6 +20747,10 @@ export class InteractionPolicy {
2072520747
protected set _cachedJsonLd(value: unknown | undefined) {
2072620748
this.#cachedJsonLd = value;
2072720749
}
20750+
20751+
protected get _baseUrl(): URL | undefined {
20752+
return this.#_baseUrl;
20753+
}
2072820754

2072920755
/**
2073020756
* The type URI of {@link InteractionPolicy}: \`https://gotosocial.org/ns#InteractionPolicy\`.
@@ -20758,6 +20784,8 @@ canLike?: InteractionRule | null;canReply?: InteractionRule | null;canAnnounce?:
2075820784
this.#documentLoader = options.documentLoader;
2075920785
this.#contextLoader = options.contextLoader;
2076020786
this.#tracerProvider = options.tracerProvider;
20787+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
20788+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
2076120789
if (\\"\$warning\\" in options) {
2076220790
this.#warning = options.\$warning as unknown as {
2076320791
category: string[];
@@ -21488,6 +21516,7 @@ export class InteractionRule {
2148821516
values?: Record<string, unknown>;
2148921517
};
2149021518
#cachedJsonLd?: unknown;
21519+
readonly #_baseUrl?: URL;
2149121520
readonly id: URL | null;
2149221521

2149321522
protected get _documentLoader(): DocumentLoader | undefined {
@@ -21517,6 +21546,10 @@ export class InteractionRule {
2151721546
protected set _cachedJsonLd(value: unknown | undefined) {
2151821547
this.#cachedJsonLd = value;
2151921548
}
21549+
21550+
protected get _baseUrl(): URL | undefined {
21551+
return this.#_baseUrl;
21552+
}
2152021553

2152121554
/**
2152221555
* The type URI of {@link InteractionRule}: \`https://gotosocial.org/ns#InteractionRule\`.
@@ -21550,6 +21583,8 @@ manualApprovals?: (URL)[];}
2155021583
this.#documentLoader = options.documentLoader;
2155121584
this.#contextLoader = options.contextLoader;
2155221585
this.#tracerProvider = options.tracerProvider;
21586+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
21587+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
2155321588
if (\\"\$warning\\" in options) {
2155421589
this.#warning = options.\$warning as unknown as {
2155521590
category: string[];
@@ -26283,6 +26318,7 @@ export class DidService {
2628326318
values?: Record<string, unknown>;
2628426319
};
2628526320
#cachedJsonLd?: unknown;
26321+
readonly #_baseUrl?: URL;
2628626322
readonly id: URL | null;
2628726323

2628826324
protected get _documentLoader(): DocumentLoader | undefined {
@@ -26312,6 +26348,10 @@ export class DidService {
2631226348
protected set _cachedJsonLd(value: unknown | undefined) {
2631326349
this.#cachedJsonLd = value;
2631426350
}
26351+
26352+
protected get _baseUrl(): URL | undefined {
26353+
return this.#_baseUrl;
26354+
}
2631526355

2631626356
/**
2631726357
* The type URI of {@link DidService}: \`https://www.w3.org/ns/did#Service\`.
@@ -26343,6 +26383,8 @@ endpoints?: (URL)[];}
2634326383
this.#documentLoader = options.documentLoader;
2634426384
this.#contextLoader = options.contextLoader;
2634526385
this.#tracerProvider = options.tracerProvider;
26386+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
26387+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
2634626388
if (\\"\$warning\\" in options) {
2634726389
this.#warning = options.\$warning as unknown as {
2634826390
category: string[];
@@ -27087,6 +27129,7 @@ export class DataIntegrityProof {
2708727129
values?: Record<string, unknown>;
2708827130
};
2708927131
#cachedJsonLd?: unknown;
27132+
readonly #_baseUrl?: URL;
2709027133
readonly id: URL | null;
2709127134

2709227135
protected get _documentLoader(): DocumentLoader | undefined {
@@ -27116,6 +27159,10 @@ export class DataIntegrityProof {
2711627159
protected set _cachedJsonLd(value: unknown | undefined) {
2711727160
this.#cachedJsonLd = value;
2711827161
}
27162+
27163+
protected get _baseUrl(): URL | undefined {
27164+
return this.#_baseUrl;
27165+
}
2711927166

2712027167
/**
2712127168
* The type URI of {@link DataIntegrityProof}: \`https://w3id.org/security#DataIntegrityProof\`.
@@ -27152,6 +27199,8 @@ cryptosuite?: \\"eddsa-jcs-2022\\" | null;verificationMethod?: Multikey | URL |
2715227199
this.#documentLoader = options.documentLoader;
2715327200
this.#contextLoader = options.contextLoader;
2715427201
this.#tracerProvider = options.tracerProvider;
27202+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
27203+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
2715527204
if (\\"\$warning\\" in options) {
2715627205
this.#warning = options.\$warning as unknown as {
2715727206
category: string[];
@@ -28126,6 +28175,7 @@ export class CryptographicKey {
2812628175
values?: Record<string, unknown>;
2812728176
};
2812828177
#cachedJsonLd?: unknown;
28178+
readonly #_baseUrl?: URL;
2812928179
readonly id: URL | null;
2813028180

2813128181
protected get _documentLoader(): DocumentLoader | undefined {
@@ -28155,6 +28205,10 @@ export class CryptographicKey {
2815528205
protected set _cachedJsonLd(value: unknown | undefined) {
2815628206
this.#cachedJsonLd = value;
2815728207
}
28208+
28209+
protected get _baseUrl(): URL | undefined {
28210+
return this.#_baseUrl;
28211+
}
2815828212

2815928213
/**
2816028214
* The type URI of {@link CryptographicKey}: \`https://w3id.org/security#Key\`.
@@ -28188,6 +28242,8 @@ owner?: Application | Group | Organization | Person | Service | URL | null;publi
2818828242
this.#documentLoader = options.documentLoader;
2818928243
this.#contextLoader = options.contextLoader;
2819028244
this.#tracerProvider = options.tracerProvider;
28245+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
28246+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
2819128247
if (\\"\$warning\\" in options) {
2819228248
this.#warning = options.\$warning as unknown as {
2819328249
category: string[];
@@ -29019,6 +29075,7 @@ export class Multikey {
2901929075
values?: Record<string, unknown>;
2902029076
};
2902129077
#cachedJsonLd?: unknown;
29078+
readonly #_baseUrl?: URL;
2902229079
readonly id: URL | null;
2902329080

2902429081
protected get _documentLoader(): DocumentLoader | undefined {
@@ -29048,6 +29105,10 @@ export class Multikey {
2904829105
protected set _cachedJsonLd(value: unknown | undefined) {
2904929106
this.#cachedJsonLd = value;
2905029107
}
29108+
29109+
protected get _baseUrl(): URL | undefined {
29110+
return this.#_baseUrl;
29111+
}
2905129112

2905229113
/**
2905329114
* The type URI of {@link Multikey}: \`https://w3id.org/security#Multikey\`.
@@ -29081,6 +29142,8 @@ controller?: Application | Group | Organization | Person | Service | URL | null;
2908129142
this.#documentLoader = options.documentLoader;
2908229143
this.#contextLoader = options.contextLoader;
2908329144
this.#tracerProvider = options.tracerProvider;
29145+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
29146+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
2908429147
if (\\"\$warning\\" in options) {
2908529148
this.#warning = options.\$warning as unknown as {
2908629149
category: string[];
@@ -29917,6 +29980,7 @@ export class Intent {
2991729980
values?: Record<string, unknown>;
2991829981
};
2991929982
#cachedJsonLd?: unknown;
29983+
readonly #_baseUrl?: URL;
2992029984
readonly id: URL | null;
2992129985

2992229986
protected get _documentLoader(): DocumentLoader | undefined {
@@ -29946,6 +30010,10 @@ export class Intent {
2994630010
protected set _cachedJsonLd(value: unknown | undefined) {
2994730011
this.#cachedJsonLd = value;
2994830012
}
30013+
30014+
protected get _baseUrl(): URL | undefined {
30015+
return this.#_baseUrl;
30016+
}
2994930017

2995030018
/**
2995130019
* The type URI of {@link Intent}: \`https://w3id.org/valueflows/ont/vf#Intent\`.
@@ -29980,6 +30048,8 @@ action?: string | null;resourceConformsTo?: URL | null;resourceQuantity?: Measur
2998030048
this.#documentLoader = options.documentLoader;
2998130049
this.#contextLoader = options.contextLoader;
2998230050
this.#tracerProvider = options.tracerProvider;
30051+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
30052+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
2998330053
if (\\"\$warning\\" in options) {
2998430054
this.#warning = options.\$warning as unknown as {
2998530055
category: string[];
@@ -49828,6 +49898,7 @@ export class Endpoints {
4982849898
values?: Record<string, unknown>;
4982949899
};
4983049900
#cachedJsonLd?: unknown;
49901+
readonly #_baseUrl?: URL;
4983149902
readonly id: URL | null;
4983249903

4983349904
protected get _documentLoader(): DocumentLoader | undefined {
@@ -49857,6 +49928,10 @@ export class Endpoints {
4985749928
protected set _cachedJsonLd(value: unknown | undefined) {
4985849929
this.#cachedJsonLd = value;
4985949930
}
49931+
49932+
protected get _baseUrl(): URL | undefined {
49933+
return this.#_baseUrl;
49934+
}
4986049935

4986149936
/**
4986249937
* The type URI of {@link Endpoints}: \`https://www.w3.org/ns/activitystreams#Endpoints\`.
@@ -49892,6 +49967,8 @@ proxyUrl?: URL | null;oauthAuthorizationEndpoint?: URL | null;oauthTokenEndpoint
4989249967
this.#documentLoader = options.documentLoader;
4989349968
this.#contextLoader = options.contextLoader;
4989449969
this.#tracerProvider = options.tracerProvider;
49970+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
49971+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
4989549972
if (\\"\$warning\\" in options) {
4989649973
this.#warning = options.\$warning as unknown as {
4989749974
category: string[];
@@ -58785,6 +58862,7 @@ export class Link {
5878558862
values?: Record<string, unknown>;
5878658863
};
5878758864
#cachedJsonLd?: unknown;
58865+
readonly #_baseUrl?: URL;
5878858866
readonly id: URL | null;
5878958867

5879058868
protected get _documentLoader(): DocumentLoader | undefined {
@@ -58814,6 +58892,10 @@ export class Link {
5881458892
protected set _cachedJsonLd(value: unknown | undefined) {
5881558893
this.#cachedJsonLd = value;
5881658894
}
58895+
58896+
protected get _baseUrl(): URL | undefined {
58897+
return this.#_baseUrl;
58898+
}
5881758899

5881858900
/**
5881958901
* The type URI of {@link Link}: \`https://www.w3.org/ns/activitystreams#Link\`.
@@ -58855,6 +58937,8 @@ names?: ((string | LanguageString))[];language?: Intl.Locale | null;height?: num
5885558937
this.#documentLoader = options.documentLoader;
5885658938
this.#contextLoader = options.contextLoader;
5885758939
this.#tracerProvider = options.tracerProvider;
58940+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
58941+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
5885858942
if (\\"\$warning\\" in options) {
5885958943
this.#warning = options.\$warning as unknown as {
5886058944
category: string[];
@@ -93516,6 +93600,7 @@ export class Source {
9351693600
values?: Record<string, unknown>;
9351793601
};
9351893602
#cachedJsonLd?: unknown;
93603+
readonly #_baseUrl?: URL;
9351993604
readonly id: URL | null;
9352093605

9352193606
protected get _documentLoader(): DocumentLoader | undefined {
@@ -93545,6 +93630,10 @@ export class Source {
9354593630
protected set _cachedJsonLd(value: unknown | undefined) {
9354693631
this.#cachedJsonLd = value;
9354793632
}
93633+
93634+
protected get _baseUrl(): URL | undefined {
93635+
return this.#_baseUrl;
93636+
}
9354893637

9354993638
/**
9355093639
* The type URI of {@link Source}: \`https://www.w3.org/ns/activitystreams#Source\`.
@@ -93577,6 +93666,8 @@ contents?: ((string | LanguageString))[];mediaType?: string | null;}
9357793666
this.#documentLoader = options.documentLoader;
9357893667
this.#contextLoader = options.contextLoader;
9357993668
this.#tracerProvider = options.tracerProvider;
93669+
const baseUrl = (options as { baseUrl?: URL }).baseUrl;
93670+
this.#_baseUrl = baseUrl == null ? undefined : new URL(baseUrl.href);
9358093671
if (\\"\$warning\\" in options) {
9358193672
this.#warning = options.\$warning as unknown as {
9358293673
category: string[];

0 commit comments

Comments
 (0)