@fedify/vocab-runtime 2.4.0-pr.936.41 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/deno.json +4 -2
- package/dist/{tests/docloader-Ck8bcBir.mjs → contexts-B09jb9Pi.cjs} +173 -274
- package/dist/{tests/docloader-S_gQZ2tt.cjs → contexts-DWrj4AGR.js} +169 -293
- package/dist/{docloader-C_dir7Xb.d.ts → docloader-BMHljyYb.d.cts} +68 -2
- package/dist/{docloader-D2DTRiyA.d.cts → docloader-BMHljyYb.d.ts} +68 -2
- package/dist/internal/jsonld-cache.cjs +70 -1
- package/dist/internal/jsonld-cache.d.cts +35 -2
- package/dist/internal/jsonld-cache.d.ts +35 -2
- package/dist/internal/jsonld-cache.js +67 -2
- package/dist/internal/portable-dereference.cjs +721 -0
- package/dist/internal/portable-dereference.d.cts +349 -0
- package/dist/internal/portable-dereference.d.ts +349 -0
- package/dist/internal/portable-dereference.js +702 -0
- package/dist/internal/signed-representation.cjs +378 -0
- package/dist/internal/signed-representation.d.cts +144 -0
- package/dist/internal/signed-representation.d.ts +144 -0
- package/dist/internal/signed-representation.js +371 -0
- package/dist/jsonld.cjs +2 -2
- package/dist/mod.cjs +762 -4529
- package/dist/mod.d.cts +427 -9
- package/dist/mod.d.ts +427 -10
- package/dist/mod.js +742 -4524
- package/dist/portable-6Aj-7dZJ.d.cts +160 -0
- package/dist/portable-nkTiqH0w.d.ts +160 -0
- package/dist/tests/body-DpC9p-iG.mjs +130 -0
- package/dist/tests/body-cKLBprYm.cjs +153 -0
- package/dist/tests/body.test.cjs +89 -0
- package/dist/tests/body.test.d.cts +1 -0
- package/dist/tests/body.test.d.mts +1 -0
- package/dist/tests/body.test.mjs +90 -0
- package/dist/tests/contexts-C9Lj11SC.cjs +4533 -0
- package/dist/tests/contexts-duRA_dDC.mjs +4522 -0
- package/dist/tests/decimal.test.cjs +9 -7
- package/dist/tests/decimal.test.mjs +9 -6
- package/dist/tests/digest-3FeH2Y-Q.cjs +176 -0
- package/dist/tests/digest-COC7xDiQ.mjs +141 -0
- package/dist/tests/digest.test.cjs +102 -0
- package/dist/tests/digest.test.d.cts +1 -0
- package/dist/tests/digest.test.d.mts +1 -0
- package/dist/tests/digest.test.mjs +103 -0
- package/dist/tests/docloader-DyZ1JGIl.cjs +398 -0
- package/dist/tests/docloader-tUmMeXjU.mjs +375 -0
- package/dist/tests/docloader.test.cjs +816 -39
- package/dist/tests/docloader.test.mjs +810 -34
- package/dist/tests/internal/multicodec.test.cjs +2 -3
- package/dist/tests/internal/multicodec.test.mjs +2 -2
- package/dist/tests/internal/portable-dereference.test.cjs +172 -0
- package/dist/tests/internal/portable-dereference.test.d.cts +1 -0
- package/dist/tests/internal/portable-dereference.test.d.mts +1 -0
- package/dist/tests/internal/portable-dereference.test.mjs +173 -0
- package/dist/tests/jsonld-CmDhHNTx.cjs +12 -0
- package/dist/tests/jsonld-DweIJ07b.mjs +5 -0
- package/dist/tests/jsonld-cache-BEXiiM-V.cjs +386 -0
- package/dist/tests/jsonld-cache-DFnWsLuZ.mjs +339 -0
- package/dist/tests/jsonld-cache.test.cjs +102 -298
- package/dist/tests/jsonld-cache.test.mjs +95 -289
- package/dist/tests/{key-_wXwomh_.cjs → key-C-AYkdJJ.cjs} +11 -4
- package/dist/tests/{key-CDGDH_vC.mjs → key-C2Db_TAJ.mjs} +11 -3
- package/dist/tests/key.test.cjs +6 -5
- package/dist/tests/key.test.mjs +6 -4
- package/dist/tests/{langstr-Di5AvKpB.mjs → langstr-DYRmJqFn.mjs} +5 -2
- package/dist/tests/{langstr-CbAxaeEZ.cjs → langstr-_PqsL1ae.cjs} +5 -2
- package/dist/tests/langstr.test.cjs +11 -4
- package/dist/tests/langstr.test.mjs +9 -2
- package/dist/tests/langtag-CUppHs_s.mjs +45 -0
- package/dist/tests/langtag-Czjvxfzx.cjs +50 -0
- package/dist/tests/langtag.test.cjs +45 -0
- package/dist/tests/langtag.test.d.cts +1 -0
- package/dist/tests/langtag.test.d.mts +1 -0
- package/dist/tests/langtag.test.mjs +46 -0
- package/dist/tests/link.test.cjs +2 -3
- package/dist/tests/link.test.mjs +2 -2
- package/dist/tests/multibase/multibase.test.cjs +8 -9
- package/dist/tests/multibase/multibase.test.mjs +6 -6
- package/dist/tests/{multibase-Bz_UUDtL.cjs → multibase-B5Mea7Ip.cjs} +19 -2
- package/dist/tests/{multibase-B4bvakyA.mjs → multibase-BPnF_L4e.mjs} +12 -1
- package/dist/tests/portable-dereference-DmTYDy2p.mjs +250 -0
- package/dist/tests/portable-dereference-qTLMqe2_.cjs +279 -0
- package/dist/tests/portable-media-5p8azal0.cjs +153 -0
- package/dist/tests/portable-media-B_lt9MMA.mjs +148 -0
- package/dist/tests/portable-media.test.cjs +222 -0
- package/dist/tests/portable-media.test.d.cts +1 -0
- package/dist/tests/portable-media.test.d.mts +1 -0
- package/dist/tests/portable-media.test.mjs +223 -0
- package/dist/tests/portable-workers.test.cjs +36 -0
- package/dist/tests/portable-workers.test.d.cts +2 -0
- package/dist/tests/portable-workers.test.d.mts +2 -0
- package/dist/tests/portable-workers.test.mjs +35 -0
- package/dist/tests/{request-uk51rkhO.cjs → request-BgjA9wyl.cjs} +10 -4
- package/dist/tests/{request-C8CaGwtt.mjs → request-DodZNukP.mjs} +8 -2
- package/dist/tests/request.test.cjs +7 -4
- package/dist/tests/request.test.mjs +5 -2
- package/dist/tests/signed-representation.test.cjs +588 -0
- package/dist/tests/signed-representation.test.d.cts +1 -0
- package/dist/tests/signed-representation.test.d.mts +1 -0
- package/dist/tests/signed-representation.test.mjs +589 -0
- package/dist/tests/temporal.test.cjs +1 -2
- package/dist/tests/temporal.test.mjs +1 -1
- package/dist/tests/url-BNakuZ8k.cjs +998 -0
- package/dist/tests/url-DMxmp7ZG.mjs +859 -0
- package/dist/tests/url.test.cjs +489 -6
- package/dist/tests/url.test.mjs +489 -5
- package/dist/url-DrGTR8yv.cjs +993 -0
- package/dist/url-Dzyp-NsC.js +860 -0
- package/package.json +27 -4
- package/scripts/test-bun.mjs +17 -0
- package/src/body.test.ts +125 -0
- package/src/body.ts +152 -0
- package/src/contexts/cid-v1.json +114 -0
- package/src/contexts/fep-22cd.json +21 -0
- package/src/contexts/fep-6757.json +12 -0
- package/src/contexts/joinmastodon.json +1 -1
- package/src/contexts/miscellany.json +17 -0
- package/src/contexts.ts +47 -1
- package/src/digest.test.ts +220 -0
- package/src/digest.ts +229 -0
- package/src/docloader.test.ts +1066 -27
- package/src/docloader.ts +322 -105
- package/src/internal/jsonld-cache.ts +97 -1
- package/src/internal/portable-dereference.test.ts +254 -0
- package/src/internal/portable-dereference.ts +1000 -0
- package/src/internal/signed-representation.ts +565 -0
- package/src/jsonld-cache.test.ts +89 -0
- package/src/key.test.ts +9 -0
- package/src/key.ts +11 -1
- package/src/langstr.test.ts +18 -1
- package/src/langstr.ts +6 -2
- package/src/langtag.test.ts +53 -0
- package/src/langtag.ts +76 -0
- package/src/mod.ts +29 -0
- package/src/multibase/multibase.test.ts +5 -5
- package/src/portable-media.test.ts +293 -0
- package/src/portable-media.ts +264 -0
- package/src/portable-workers.test.ts +81 -0
- package/src/portable.ts +180 -0
- package/src/preprocessor.ts +7 -0
- package/src/request.test.ts +10 -1
- package/src/request.ts +9 -1
- package/src/signed-representation.test.ts +338 -0
- package/src/url.test.ts +823 -3
- package/src/url.ts +700 -23
- package/tsdown.config.ts +2 -0
- package/dist/tests/url-CsOV_B_P.cjs +0 -482
- package/dist/tests/url-Du7RQQgP.mjs +0 -392
- package/dist/url-DD4F0ULf.cjs +0 -483
- package/dist/url-DGVbSVVi.js +0 -393
- /package/dist/{chunk-M78iaK0I.cjs → rolldown-runtime-B7lfambq.cjs} +0 -0
- /package/dist/tests/{link-NUUWCdnK.mjs → link-Cevmc87v.mjs} +0 -0
- /package/dist/tests/{link-FguCydMA.cjs → link-DlKm8bEr.cjs} +0 -0
- /package/dist/tests/{multicodec-CxGVGa91.cjs → multicodec-CLRPeW4N.cjs} +0 -0
- /package/dist/tests/{multicodec-CyFp54fI.mjs → multicodec-CRIj_05H.mjs} +0 -0
- /package/dist/tests/{chunk-C2EiDwsr.cjs → rolldown-runtime-emK7D4bc.cjs} +0 -0
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const require_request = require("./request-uk51rkhO.cjs");
|
|
3
|
-
const require_link = require("./link-FguCydMA.cjs");
|
|
4
|
-
const require_url = require("./url-CsOV_B_P.cjs");
|
|
5
|
-
let _logtape_logtape = require("@logtape/logtape");
|
|
6
|
-
let _opentelemetry_api = require("@opentelemetry/api");
|
|
1
|
+
|
|
7
2
|
//#endregion
|
|
8
3
|
//#region src/contexts.ts
|
|
9
4
|
const preloadedContexts = {
|
|
@@ -4240,6 +4235,34 @@ const preloadedContexts = {
|
|
|
4240
4235
|
"@type": "@id"
|
|
4241
4236
|
}
|
|
4242
4237
|
} },
|
|
4238
|
+
"https://w3id.org/fep/22cd": { "@context": {
|
|
4239
|
+
"fep-22cd": "https://w3id.org/fep/22cd#",
|
|
4240
|
+
"schema": "https://schema.org/",
|
|
4241
|
+
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
|
4242
|
+
"translations": {
|
|
4243
|
+
"@id": "fep-22cd:translations",
|
|
4244
|
+
"@container": "@set"
|
|
4245
|
+
},
|
|
4246
|
+
"Translation": "fep-22cd:Translation",
|
|
4247
|
+
"sourceUpdated": {
|
|
4248
|
+
"@id": "fep-22cd:sourceUpdated",
|
|
4249
|
+
"@type": "xsd:dateTime"
|
|
4250
|
+
},
|
|
4251
|
+
"translator": {
|
|
4252
|
+
"@id": "schema:translator",
|
|
4253
|
+
"@type": "@id",
|
|
4254
|
+
"@container": "@set"
|
|
4255
|
+
},
|
|
4256
|
+
"inLanguage": "schema:inLanguage",
|
|
4257
|
+
"translationOfWork": {
|
|
4258
|
+
"@id": "schema:translationOfWork",
|
|
4259
|
+
"@type": "@id"
|
|
4260
|
+
},
|
|
4261
|
+
"isBasedOn": {
|
|
4262
|
+
"@id": "schema:isBasedOn",
|
|
4263
|
+
"@type": "@id"
|
|
4264
|
+
}
|
|
4265
|
+
} },
|
|
4243
4266
|
"https://w3id.org/fep/5711": { "@context": {
|
|
4244
4267
|
"likesOf": {
|
|
4245
4268
|
"@id": "https://w3id.org/fep/5711#likesOf",
|
|
@@ -4274,6 +4297,125 @@ const preloadedContexts = {
|
|
|
4274
4297
|
"@type": "@id"
|
|
4275
4298
|
}
|
|
4276
4299
|
} },
|
|
4300
|
+
"https://www.w3.org/ns/cid/v1": { "@context": {
|
|
4301
|
+
"@protected": true,
|
|
4302
|
+
"id": "@id",
|
|
4303
|
+
"type": "@type",
|
|
4304
|
+
"alsoKnownAs": {
|
|
4305
|
+
"@id": "https://www.w3.org/ns/activitystreams#alsoKnownAs",
|
|
4306
|
+
"@type": "@id"
|
|
4307
|
+
},
|
|
4308
|
+
"assertionMethod": {
|
|
4309
|
+
"@id": "https://w3id.org/security#assertionMethod",
|
|
4310
|
+
"@type": "@id",
|
|
4311
|
+
"@container": "@set"
|
|
4312
|
+
},
|
|
4313
|
+
"authentication": {
|
|
4314
|
+
"@id": "https://w3id.org/security#authenticationMethod",
|
|
4315
|
+
"@type": "@id",
|
|
4316
|
+
"@container": "@set"
|
|
4317
|
+
},
|
|
4318
|
+
"capabilityDelegation": {
|
|
4319
|
+
"@id": "https://w3id.org/security#capabilityDelegationMethod",
|
|
4320
|
+
"@type": "@id",
|
|
4321
|
+
"@container": "@set"
|
|
4322
|
+
},
|
|
4323
|
+
"capabilityInvocation": {
|
|
4324
|
+
"@id": "https://w3id.org/security#capabilityInvocationMethod",
|
|
4325
|
+
"@type": "@id",
|
|
4326
|
+
"@container": "@set"
|
|
4327
|
+
},
|
|
4328
|
+
"controller": {
|
|
4329
|
+
"@id": "https://w3id.org/security#controller",
|
|
4330
|
+
"@type": "@id"
|
|
4331
|
+
},
|
|
4332
|
+
"keyAgreement": {
|
|
4333
|
+
"@id": "https://w3id.org/security#keyAgreementMethod",
|
|
4334
|
+
"@type": "@id",
|
|
4335
|
+
"@container": "@set"
|
|
4336
|
+
},
|
|
4337
|
+
"service": {
|
|
4338
|
+
"@id": "https://www.w3.org/ns/did#service",
|
|
4339
|
+
"@type": "@id",
|
|
4340
|
+
"@context": {
|
|
4341
|
+
"@protected": true,
|
|
4342
|
+
"id": "@id",
|
|
4343
|
+
"type": "@type",
|
|
4344
|
+
"serviceEndpoint": {
|
|
4345
|
+
"@id": "https://www.w3.org/ns/did#serviceEndpoint",
|
|
4346
|
+
"@type": "@id"
|
|
4347
|
+
}
|
|
4348
|
+
}
|
|
4349
|
+
},
|
|
4350
|
+
"verificationMethod": {
|
|
4351
|
+
"@id": "https://w3id.org/security#verificationMethod",
|
|
4352
|
+
"@type": "@id"
|
|
4353
|
+
},
|
|
4354
|
+
"Multikey": {
|
|
4355
|
+
"@id": "https://w3id.org/security#Multikey",
|
|
4356
|
+
"@context": {
|
|
4357
|
+
"@protected": true,
|
|
4358
|
+
"id": "@id",
|
|
4359
|
+
"type": "@type",
|
|
4360
|
+
"controller": {
|
|
4361
|
+
"@id": "https://w3id.org/security#controller",
|
|
4362
|
+
"@type": "@id"
|
|
4363
|
+
},
|
|
4364
|
+
"revoked": {
|
|
4365
|
+
"@id": "https://w3id.org/security#revoked",
|
|
4366
|
+
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
|
|
4367
|
+
},
|
|
4368
|
+
"expires": {
|
|
4369
|
+
"@id": "https://w3id.org/security#expiration",
|
|
4370
|
+
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
|
|
4371
|
+
},
|
|
4372
|
+
"publicKeyMultibase": {
|
|
4373
|
+
"@id": "https://w3id.org/security#publicKeyMultibase",
|
|
4374
|
+
"@type": "https://w3id.org/security#multibase"
|
|
4375
|
+
},
|
|
4376
|
+
"secretKeyMultibase": {
|
|
4377
|
+
"@id": "https://w3id.org/security#secretKeyMultibase",
|
|
4378
|
+
"@type": "https://w3id.org/security#multibase"
|
|
4379
|
+
}
|
|
4380
|
+
}
|
|
4381
|
+
},
|
|
4382
|
+
"JsonWebKey": {
|
|
4383
|
+
"@id": "https://w3id.org/security#JsonWebKey",
|
|
4384
|
+
"@context": {
|
|
4385
|
+
"@protected": true,
|
|
4386
|
+
"id": "@id",
|
|
4387
|
+
"type": "@type",
|
|
4388
|
+
"controller": {
|
|
4389
|
+
"@id": "https://w3id.org/security#controller",
|
|
4390
|
+
"@type": "@id"
|
|
4391
|
+
},
|
|
4392
|
+
"revoked": {
|
|
4393
|
+
"@id": "https://w3id.org/security#revoked",
|
|
4394
|
+
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
|
|
4395
|
+
},
|
|
4396
|
+
"expires": {
|
|
4397
|
+
"@id": "https://w3id.org/security#expiration",
|
|
4398
|
+
"@type": "http://www.w3.org/2001/XMLSchema#dateTime"
|
|
4399
|
+
},
|
|
4400
|
+
"publicKeyJwk": {
|
|
4401
|
+
"@id": "https://w3id.org/security#publicKeyJwk",
|
|
4402
|
+
"@type": "@json"
|
|
4403
|
+
},
|
|
4404
|
+
"secretKeyJwk": {
|
|
4405
|
+
"@id": "https://w3id.org/security#secretKeyJwk",
|
|
4406
|
+
"@type": "@json"
|
|
4407
|
+
}
|
|
4408
|
+
}
|
|
4409
|
+
}
|
|
4410
|
+
} },
|
|
4411
|
+
"https://w3id.org/fep/ef61": { "@context": {
|
|
4412
|
+
"gateways": {
|
|
4413
|
+
"@id": "https://w3id.org/fep/ef61/gateways",
|
|
4414
|
+
"@type": "@id",
|
|
4415
|
+
"@container": "@list"
|
|
4416
|
+
},
|
|
4417
|
+
"digestMultibase": "https://www.w3.org/ns/credentials/v2#digestMultibase"
|
|
4418
|
+
} },
|
|
4277
4419
|
"https://w3id.org/fep/7aa9": { "@context": {
|
|
4278
4420
|
"FeaturedCollection": "https://w3id.org/fep/7aa9#FeaturedCollection",
|
|
4279
4421
|
"FeaturedItem": "https://w3id.org/fep/7aa9#FeaturedItem",
|
|
@@ -4296,13 +4438,15 @@ const preloadedContexts = {
|
|
|
4296
4438
|
"@type": "@id"
|
|
4297
4439
|
}
|
|
4298
4440
|
} },
|
|
4299
|
-
"https://w3id.org/fep/
|
|
4300
|
-
"
|
|
4301
|
-
"@id": "
|
|
4302
|
-
"@type": "@id"
|
|
4303
|
-
"@container": "@list"
|
|
4441
|
+
"https://w3id.org/fep/6757": { "@context": {
|
|
4442
|
+
"license": {
|
|
4443
|
+
"@id": "http://purl.org/dc/terms/license",
|
|
4444
|
+
"@type": "@id"
|
|
4304
4445
|
},
|
|
4305
|
-
"
|
|
4446
|
+
"preferredLicense": {
|
|
4447
|
+
"@id": "https://w3id.org/fep/6757#preferredLicense",
|
|
4448
|
+
"@type": "@id"
|
|
4449
|
+
}
|
|
4306
4450
|
} },
|
|
4307
4451
|
"https://join-lemmy.org/context.json": { "@context": ["https://w3id.org/security/v1", {
|
|
4308
4452
|
"as": "https://www.w3.org/ns/activitystreams#",
|
|
@@ -4355,288 +4499,20 @@ const preloadedContexts = {
|
|
|
4355
4499
|
"suspended": "toot:suspended",
|
|
4356
4500
|
"attributionDomains": {
|
|
4357
4501
|
"@id": "toot:attributionDomains",
|
|
4358
|
-
"@
|
|
4502
|
+
"@container": "@set"
|
|
4359
4503
|
}
|
|
4504
|
+
} },
|
|
4505
|
+
"https://purl.archive.org/miscellany": { "@context": {
|
|
4506
|
+
"as": "https://www.w3.org/ns/activitystreams#",
|
|
4507
|
+
"xsd": "http://www.w3.org/2001/XMLSchema#",
|
|
4508
|
+
"Hashtag": "as:Hashtag",
|
|
4509
|
+
"manuallyApprovesFollowers": { "@id": "as:manuallyApprovesFollowers" },
|
|
4510
|
+
"movedTo": {
|
|
4511
|
+
"@id": "as:movedTo",
|
|
4512
|
+
"@type": "@id"
|
|
4513
|
+
},
|
|
4514
|
+
"sensitive": { "@id": "as:sensitive" }
|
|
4360
4515
|
} }
|
|
4361
4516
|
};
|
|
4362
4517
|
//#endregion
|
|
4363
|
-
|
|
4364
|
-
const logger = (0, _logtape_logtape.getLogger)([
|
|
4365
|
-
"fedify",
|
|
4366
|
-
"runtime",
|
|
4367
|
-
"docloader"
|
|
4368
|
-
]);
|
|
4369
|
-
const DEFAULT_MAX_REDIRECTION = 20;
|
|
4370
|
-
const MAX_HTML_SIZE = 1024 * 1024;
|
|
4371
|
-
function createResponseMetadata(response) {
|
|
4372
|
-
return new Response(null, {
|
|
4373
|
-
headers: response.headers,
|
|
4374
|
-
status: response.status,
|
|
4375
|
-
statusText: response.statusText
|
|
4376
|
-
});
|
|
4377
|
-
}
|
|
4378
|
-
async function cancelResponseBody(response) {
|
|
4379
|
-
if (response.body != null) await response.body.cancel();
|
|
4380
|
-
}
|
|
4381
|
-
async function readBoundedText(response, maxBytes) {
|
|
4382
|
-
const contentLength = response.headers.get("Content-Length");
|
|
4383
|
-
if (contentLength != null) {
|
|
4384
|
-
const size = Number(contentLength);
|
|
4385
|
-
if (size > maxBytes) {
|
|
4386
|
-
await cancelResponseBody(response);
|
|
4387
|
-
return {
|
|
4388
|
-
text: "",
|
|
4389
|
-
size,
|
|
4390
|
-
tooLarge: true
|
|
4391
|
-
};
|
|
4392
|
-
}
|
|
4393
|
-
}
|
|
4394
|
-
if (response.body == null) return {
|
|
4395
|
-
text: "",
|
|
4396
|
-
size: 0,
|
|
4397
|
-
tooLarge: false
|
|
4398
|
-
};
|
|
4399
|
-
const reader = response.body.getReader();
|
|
4400
|
-
const decoder = new TextDecoder();
|
|
4401
|
-
let text = "";
|
|
4402
|
-
let size = 0;
|
|
4403
|
-
try {
|
|
4404
|
-
while (true) {
|
|
4405
|
-
const result = await reader.read();
|
|
4406
|
-
if (result.done) break;
|
|
4407
|
-
const chunkSize = result.value.byteLength;
|
|
4408
|
-
if (size + chunkSize > maxBytes) {
|
|
4409
|
-
size += chunkSize;
|
|
4410
|
-
await reader.cancel();
|
|
4411
|
-
return {
|
|
4412
|
-
text: "",
|
|
4413
|
-
size,
|
|
4414
|
-
tooLarge: true
|
|
4415
|
-
};
|
|
4416
|
-
}
|
|
4417
|
-
size += chunkSize;
|
|
4418
|
-
text += decoder.decode(result.value, { stream: true });
|
|
4419
|
-
}
|
|
4420
|
-
text += decoder.decode();
|
|
4421
|
-
return {
|
|
4422
|
-
text,
|
|
4423
|
-
size,
|
|
4424
|
-
tooLarge: false
|
|
4425
|
-
};
|
|
4426
|
-
} finally {
|
|
4427
|
-
reader.releaseLock();
|
|
4428
|
-
}
|
|
4429
|
-
}
|
|
4430
|
-
/**
|
|
4431
|
-
* Gets a {@link RemoteDocument} from the given response.
|
|
4432
|
-
* @param url The URL of the document to load.
|
|
4433
|
-
* @param response The response to get the document from.
|
|
4434
|
-
* @param fetch The function to fetch the document.
|
|
4435
|
-
* @returns The loaded remote document.
|
|
4436
|
-
* @throws {FetchError} If the response is not OK.
|
|
4437
|
-
* @internal
|
|
4438
|
-
*/
|
|
4439
|
-
async function getRemoteDocument(url, response, fetch) {
|
|
4440
|
-
const documentUrl = response.url === "" ? url : response.url;
|
|
4441
|
-
const docUrl = new URL(documentUrl);
|
|
4442
|
-
if (!response.ok) {
|
|
4443
|
-
logger.error("Failed to fetch document: {status} {url} {headers}", {
|
|
4444
|
-
status: response.status,
|
|
4445
|
-
url: documentUrl,
|
|
4446
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
4447
|
-
});
|
|
4448
|
-
throw new require_request.FetchError(documentUrl, `HTTP ${response.status}: ${documentUrl}`, response.clone());
|
|
4449
|
-
}
|
|
4450
|
-
const contentType = response.headers.get("Content-Type");
|
|
4451
|
-
const jsonLd = contentType == null || contentType === "application/activity+json" || contentType.startsWith("application/activity+json;") || contentType === "application/ld+json" || contentType.startsWith("application/ld+json;");
|
|
4452
|
-
const linkHeader = response.headers.get("Link");
|
|
4453
|
-
let contextUrl = null;
|
|
4454
|
-
if (linkHeader != null) {
|
|
4455
|
-
let link;
|
|
4456
|
-
try {
|
|
4457
|
-
link = new require_link.HttpHeaderLink(linkHeader);
|
|
4458
|
-
} catch (e) {
|
|
4459
|
-
if (e instanceof SyntaxError) link = new require_link.HttpHeaderLink();
|
|
4460
|
-
else throw e;
|
|
4461
|
-
}
|
|
4462
|
-
if (jsonLd) {
|
|
4463
|
-
const entries = link.getByRel("http://www.w3.org/ns/json-ld#context");
|
|
4464
|
-
for (const [uri, params] of entries) if ("type" in params && params.type === "application/ld+json") {
|
|
4465
|
-
contextUrl = uri;
|
|
4466
|
-
break;
|
|
4467
|
-
}
|
|
4468
|
-
} else {
|
|
4469
|
-
const entries = link.getByRel("alternate");
|
|
4470
|
-
for (const [uri, params] of entries) {
|
|
4471
|
-
const altUri = new URL(uri, docUrl);
|
|
4472
|
-
if ("type" in params && (params.type === "application/activity+json" || params.type === "application/ld+json" || params.type.startsWith("application/ld+json;")) && altUri.href !== docUrl.href) {
|
|
4473
|
-
logger.debug("Found alternate document: {alternateUrl} from {url}", {
|
|
4474
|
-
alternateUrl: altUri.href,
|
|
4475
|
-
url: documentUrl
|
|
4476
|
-
});
|
|
4477
|
-
return await fetch(altUri.href);
|
|
4478
|
-
}
|
|
4479
|
-
}
|
|
4480
|
-
}
|
|
4481
|
-
}
|
|
4482
|
-
let document;
|
|
4483
|
-
if (!jsonLd && (contentType === "text/html" || contentType?.startsWith("text/html;") || contentType === "application/xhtml+xml" || contentType?.startsWith("application/xhtml+xml;"))) {
|
|
4484
|
-
const errorResponse = createResponseMetadata(response);
|
|
4485
|
-
const html = await readBoundedText(response, MAX_HTML_SIZE);
|
|
4486
|
-
if (html.tooLarge) {
|
|
4487
|
-
logger.warn("HTML response too large, skipping alternate link discovery: {url}", {
|
|
4488
|
-
url: documentUrl,
|
|
4489
|
-
size: html.size
|
|
4490
|
-
});
|
|
4491
|
-
throw new require_request.FetchError(documentUrl, `HTML document is too large to scan for an ActivityPub alternate link (Content-Type: ${contentType})`, errorResponse);
|
|
4492
|
-
} else {
|
|
4493
|
-
const tagPattern = /<(a|link)\s+([^>]*?)\s*\/?>/gi;
|
|
4494
|
-
const attrPattern = /([a-z][a-z:_-]*)=(?:"([^"]*)"|'([^']*)'|([^\s>]+))/gi;
|
|
4495
|
-
let tagMatch;
|
|
4496
|
-
while ((tagMatch = tagPattern.exec(html.text)) !== null) {
|
|
4497
|
-
const tagContent = tagMatch[2];
|
|
4498
|
-
let attrMatch;
|
|
4499
|
-
const attribs = {};
|
|
4500
|
-
attrPattern.lastIndex = 0;
|
|
4501
|
-
while ((attrMatch = attrPattern.exec(tagContent)) !== null) {
|
|
4502
|
-
const key = attrMatch[1].toLowerCase();
|
|
4503
|
-
attribs[key] = attrMatch[2] ?? attrMatch[3] ?? attrMatch[4] ?? "";
|
|
4504
|
-
}
|
|
4505
|
-
if (attribs.rel === "alternate" && "type" in attribs && (attribs.type === "application/activity+json" || attribs.type === "application/ld+json" || attribs.type.startsWith("application/ld+json;")) && "href" in attribs && new URL(attribs.href, docUrl).href !== docUrl.href) {
|
|
4506
|
-
logger.debug("Found alternate document: {alternateUrl} from {url}", {
|
|
4507
|
-
alternateUrl: attribs.href,
|
|
4508
|
-
url: documentUrl
|
|
4509
|
-
});
|
|
4510
|
-
return await fetch(new URL(attribs.href, docUrl).href);
|
|
4511
|
-
}
|
|
4512
|
-
}
|
|
4513
|
-
try {
|
|
4514
|
-
document = JSON.parse(html.text);
|
|
4515
|
-
} catch (error) {
|
|
4516
|
-
if (!(error instanceof SyntaxError)) throw error;
|
|
4517
|
-
throw new require_request.FetchError(documentUrl, `HTML document has no ActivityPub alternate link (Content-Type: ${contentType})`, errorResponse);
|
|
4518
|
-
}
|
|
4519
|
-
}
|
|
4520
|
-
} else document = await response.json();
|
|
4521
|
-
logger.debug("Fetched document: {status} {url} {headers}", {
|
|
4522
|
-
status: response.status,
|
|
4523
|
-
url: documentUrl,
|
|
4524
|
-
headers: Object.fromEntries(response.headers.entries())
|
|
4525
|
-
});
|
|
4526
|
-
return {
|
|
4527
|
-
contextUrl,
|
|
4528
|
-
document,
|
|
4529
|
-
documentUrl
|
|
4530
|
-
};
|
|
4531
|
-
}
|
|
4532
|
-
/**
|
|
4533
|
-
* Creates a JSON-LD document loader that utilizes the browser's `fetch` API.
|
|
4534
|
-
*
|
|
4535
|
-
* The created loader preloads the below frequently used contexts by default
|
|
4536
|
-
* (unless `options.skipPreloadedContexts` is set to `true`):
|
|
4537
|
-
*
|
|
4538
|
-
* - <https://www.w3.org/ns/activitystreams>
|
|
4539
|
-
* - <https://w3id.org/security/v1>
|
|
4540
|
-
* - <https://w3id.org/security/data-integrity/v1>
|
|
4541
|
-
* - <https://w3id.org/security/data-integrity/v2>
|
|
4542
|
-
* - <https://www.w3.org/ns/did/v1>
|
|
4543
|
-
* - <https://w3id.org/security/multikey/v1>
|
|
4544
|
-
* - <https://w3id.org/fep/ef61>
|
|
4545
|
-
* - <https://purl.archive.org/socialweb/webfinger>
|
|
4546
|
-
* - <http://schema.org/>
|
|
4547
|
-
* @param options Options for the document loader.
|
|
4548
|
-
* @returns The document loader.
|
|
4549
|
-
* @since 1.3.0
|
|
4550
|
-
*/
|
|
4551
|
-
function getDocumentLoader({ allowPrivateAddress, maxRedirection, skipPreloadedContexts, userAgent } = {}) {
|
|
4552
|
-
const tracer = _opentelemetry_api.trace.getTracerProvider().getTracer(require_request.name, require_request.version);
|
|
4553
|
-
const maximumRedirection = maxRedirection ?? DEFAULT_MAX_REDIRECTION;
|
|
4554
|
-
async function load(url, options, redirected = 0, visited = /* @__PURE__ */ new Set()) {
|
|
4555
|
-
options?.signal?.throwIfAborted();
|
|
4556
|
-
const currentUrl = new URL(url).href;
|
|
4557
|
-
if (!skipPreloadedContexts && currentUrl in preloadedContexts) {
|
|
4558
|
-
logger.debug("Using preloaded context: {url}.", { url: currentUrl });
|
|
4559
|
-
return {
|
|
4560
|
-
contextUrl: null,
|
|
4561
|
-
document: preloadedContexts[currentUrl],
|
|
4562
|
-
documentUrl: currentUrl
|
|
4563
|
-
};
|
|
4564
|
-
}
|
|
4565
|
-
if (!allowPrivateAddress) try {
|
|
4566
|
-
await require_url.validatePublicUrl(currentUrl);
|
|
4567
|
-
} catch (error) {
|
|
4568
|
-
if (error instanceof require_url.UrlError) logger.error("Disallowed private URL: {url}", {
|
|
4569
|
-
url: currentUrl,
|
|
4570
|
-
error
|
|
4571
|
-
});
|
|
4572
|
-
throw error;
|
|
4573
|
-
}
|
|
4574
|
-
visited.add(currentUrl);
|
|
4575
|
-
return await tracer.startActiveSpan("activitypub.fetch_document", {
|
|
4576
|
-
kind: _opentelemetry_api.SpanKind.CLIENT,
|
|
4577
|
-
attributes: { "url.full": currentUrl }
|
|
4578
|
-
}, async (span) => {
|
|
4579
|
-
try {
|
|
4580
|
-
const request = require_request.createActivityPubRequest(currentUrl, { userAgent });
|
|
4581
|
-
require_request.logRequest(logger, request);
|
|
4582
|
-
const response = await fetch(request, {
|
|
4583
|
-
redirect: "manual",
|
|
4584
|
-
signal: options?.signal
|
|
4585
|
-
});
|
|
4586
|
-
span.setAttribute("http.response.status_code", response.status);
|
|
4587
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
4588
|
-
if (redirected >= maximumRedirection) {
|
|
4589
|
-
logger.error("Too many redirections ({redirections}) while fetching document.", {
|
|
4590
|
-
redirections: redirected + 1,
|
|
4591
|
-
url: currentUrl
|
|
4592
|
-
});
|
|
4593
|
-
throw new require_request.FetchError(currentUrl, `Too many redirections (${redirected + 1})`);
|
|
4594
|
-
}
|
|
4595
|
-
const redirectUrl = new URL(response.headers.get("Location"), response.url === "" ? currentUrl : response.url).href;
|
|
4596
|
-
span.setAttribute("http.redirect.url", redirectUrl);
|
|
4597
|
-
if (visited.has(redirectUrl)) {
|
|
4598
|
-
logger.error("Detected a redirect loop while fetching document: {url} -> {redirectUrl}", {
|
|
4599
|
-
url: currentUrl,
|
|
4600
|
-
redirectUrl
|
|
4601
|
-
});
|
|
4602
|
-
throw new require_request.FetchError(currentUrl, `Redirect loop detected: ${redirectUrl}`);
|
|
4603
|
-
}
|
|
4604
|
-
return await load(redirectUrl, options, redirected + 1, visited);
|
|
4605
|
-
}
|
|
4606
|
-
const result = await getRemoteDocument(currentUrl, response, load);
|
|
4607
|
-
span.setAttribute("docloader.document_url", result.documentUrl);
|
|
4608
|
-
if (result.contextUrl != null) span.setAttribute("docloader.context_url", result.contextUrl);
|
|
4609
|
-
return result;
|
|
4610
|
-
} catch (error) {
|
|
4611
|
-
span.recordException(error);
|
|
4612
|
-
span.setStatus({
|
|
4613
|
-
code: _opentelemetry_api.SpanStatusCode.ERROR,
|
|
4614
|
-
message: String(error)
|
|
4615
|
-
});
|
|
4616
|
-
throw error;
|
|
4617
|
-
} finally {
|
|
4618
|
-
span.end();
|
|
4619
|
-
}
|
|
4620
|
-
});
|
|
4621
|
-
}
|
|
4622
|
-
return load;
|
|
4623
|
-
}
|
|
4624
|
-
//#endregion
|
|
4625
|
-
Object.defineProperty(exports, "getDocumentLoader", {
|
|
4626
|
-
enumerable: true,
|
|
4627
|
-
get: function() {
|
|
4628
|
-
return getDocumentLoader;
|
|
4629
|
-
}
|
|
4630
|
-
});
|
|
4631
|
-
Object.defineProperty(exports, "getRemoteDocument", {
|
|
4632
|
-
enumerable: true,
|
|
4633
|
-
get: function() {
|
|
4634
|
-
return getRemoteDocument;
|
|
4635
|
-
}
|
|
4636
|
-
});
|
|
4637
|
-
Object.defineProperty(exports, "preloadedContexts", {
|
|
4638
|
-
enumerable: true,
|
|
4639
|
-
get: function() {
|
|
4640
|
-
return preloadedContexts;
|
|
4641
|
-
}
|
|
4642
|
-
});
|
|
4518
|
+
export { preloadedContexts as t };
|
|
@@ -100,6 +100,13 @@ interface DocumentLoaderOptions {
|
|
|
100
100
|
* @since 1.8.0
|
|
101
101
|
*/
|
|
102
102
|
signal?: AbortSignal;
|
|
103
|
+
/**
|
|
104
|
+
* Whether to lower error-level logs for recoverable document loading
|
|
105
|
+
* failures to warning-level logs. The loader still throws the error.
|
|
106
|
+
* @default `false`
|
|
107
|
+
* @since 2.4.0
|
|
108
|
+
*/
|
|
109
|
+
suppressError?: boolean;
|
|
103
110
|
}
|
|
104
111
|
/**
|
|
105
112
|
* A JSON-LD document loader that fetches documents from the Web.
|
|
@@ -140,6 +147,28 @@ interface DocumentLoaderFactoryOptions {
|
|
|
140
147
|
* @since 2.2.0
|
|
141
148
|
*/
|
|
142
149
|
maxRedirection?: number;
|
|
150
|
+
/**
|
|
151
|
+
* The timeout in milliseconds for each call of the created document
|
|
152
|
+
* loader. The timeout is shared by all the steps of a call, including
|
|
153
|
+
* URL validation, every HTTP redirect and alternate document link it
|
|
154
|
+
* follows, retries, and reading the response body; it does not restart
|
|
155
|
+
* for each of them. It does not interrupt synchronous work such as
|
|
156
|
+
* parsing a document that has already been received.
|
|
157
|
+
*
|
|
158
|
+
* When a call times out, the loader throws a {@link FetchError} without
|
|
159
|
+
* a {@link FetchError.response}, whose `cause` is a `DOMException` named
|
|
160
|
+
* `"TimeoutError"`. An `AbortSignal` passed through
|
|
161
|
+
* {@link DocumentLoaderOptions.signal} still cancels a call; in that case
|
|
162
|
+
* the loader throws the signal's reason as before.
|
|
163
|
+
*
|
|
164
|
+
* Fractional values are rounded up. Set it to `null` to turn off the
|
|
165
|
+
* timeout.
|
|
166
|
+
* @default `10000` (10 seconds)
|
|
167
|
+
* @throws {RangeError} If the value is not a positive finite number or is
|
|
168
|
+
* greater than 2,147,483,647 (about 24.8 days).
|
|
169
|
+
* @since 2.4.0
|
|
170
|
+
*/
|
|
171
|
+
timeout?: number | null;
|
|
143
172
|
}
|
|
144
173
|
/**
|
|
145
174
|
* A factory function that creates an authenticated {@link DocumentLoader} for
|
|
@@ -160,11 +189,39 @@ type AuthenticatedDocumentLoaderFactory = (identity: {
|
|
|
160
189
|
* @param url The URL of the document to load.
|
|
161
190
|
* @param response The response to get the document from.
|
|
162
191
|
* @param fetch The function to fetch the document.
|
|
192
|
+
* @param options The options for loading the document.
|
|
163
193
|
* @returns The loaded remote document.
|
|
164
194
|
* @throws {FetchError} If the response is not OK.
|
|
165
195
|
* @internal
|
|
166
196
|
*/
|
|
167
|
-
declare function getRemoteDocument(url: string, response: Response, fetch: (url: string, options?: DocumentLoaderOptions) => Promise<RemoteDocument
|
|
197
|
+
declare function getRemoteDocument(url: string, response: Response, fetch: (url: string, options?: DocumentLoaderOptions) => Promise<RemoteDocument>, options?: DocumentLoaderOptions): Promise<RemoteDocument>;
|
|
198
|
+
/**
|
|
199
|
+
* Resolves {@link DocumentLoaderFactoryOptions.timeout} into milliseconds.
|
|
200
|
+
* @param timeout The timeout option. `undefined` means the default timeout,
|
|
201
|
+
* and `null` means no timeout.
|
|
202
|
+
* @returns The timeout in milliseconds, or `null` if it is turned off.
|
|
203
|
+
* @throws {RangeError} If the timeout is invalid.
|
|
204
|
+
* @internal
|
|
205
|
+
*/
|
|
206
|
+
declare function resolveDocumentLoaderTimeout(timeout: number | null | undefined): number | null;
|
|
207
|
+
/**
|
|
208
|
+
* Bounds each call of the given document loader by the given timeout.
|
|
209
|
+
* The timeout is combined with the caller's `signal`, and the combined
|
|
210
|
+
* signal is passed to the loader. The call settles no later than the
|
|
211
|
+
* timeout even if the loader is stuck in a step that cannot be aborted,
|
|
212
|
+
* e.g., a DNS lookup.
|
|
213
|
+
*
|
|
214
|
+
* A timed-out call throws a {@link FetchError} without a response, whose
|
|
215
|
+
* `cause` is a `DOMException` named `"TimeoutError"`. If the caller's
|
|
216
|
+
* signal is aborted, its reason is thrown instead.
|
|
217
|
+
* @param loader The document loader to bound.
|
|
218
|
+
* @param timeout The timeout in milliseconds, or `null` for no timeout.
|
|
219
|
+
* It is assumed to have been resolved by
|
|
220
|
+
* {@link resolveDocumentLoaderTimeout}.
|
|
221
|
+
* @returns The bounded document loader.
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
declare function withDocumentLoaderTimeout(loader: DocumentLoader, timeout: number | null): DocumentLoader;
|
|
168
225
|
/**
|
|
169
226
|
* Options for {@link getDocumentLoader}.
|
|
170
227
|
* @since 1.3.0
|
|
@@ -177,6 +234,10 @@ interface GetDocumentLoaderOptions extends DocumentLoaderFactoryOptions {
|
|
|
177
234
|
}
|
|
178
235
|
/**
|
|
179
236
|
* Creates a JSON-LD document loader that utilizes the browser's `fetch` API.
|
|
237
|
+
* At most 20 HTTP redirects and alternate document links are followed in total
|
|
238
|
+
* per call. Revisiting a URL within that chain throws a {@link FetchError}.
|
|
239
|
+
* Each call times out after 10 seconds by default; see
|
|
240
|
+
* {@link DocumentLoaderFactoryOptions.timeout}.
|
|
180
241
|
*
|
|
181
242
|
* The created loader preloads the below frequently used contexts by default
|
|
182
243
|
* (unless `options.skipPreloadedContexts` is set to `true`):
|
|
@@ -186,8 +247,12 @@ interface GetDocumentLoaderOptions extends DocumentLoaderFactoryOptions {
|
|
|
186
247
|
* - <https://w3id.org/security/data-integrity/v1>
|
|
187
248
|
* - <https://w3id.org/security/data-integrity/v2>
|
|
188
249
|
* - <https://www.w3.org/ns/did/v1>
|
|
250
|
+
* - <https://www.w3.org/ns/cid/v1>
|
|
189
251
|
* - <https://w3id.org/security/multikey/v1>
|
|
190
252
|
* - <https://w3id.org/fep/ef61>
|
|
253
|
+
* - <https://w3id.org/fep/7aa9>
|
|
254
|
+
* - <https://w3id.org/fep/6757>
|
|
255
|
+
* - <https://w3id.org/fep/22cd>
|
|
191
256
|
* - <https://purl.archive.org/socialweb/webfinger>
|
|
192
257
|
* - <http://schema.org/>
|
|
193
258
|
* @param options Options for the document loader.
|
|
@@ -198,7 +263,8 @@ declare function getDocumentLoader({
|
|
|
198
263
|
allowPrivateAddress,
|
|
199
264
|
maxRedirection,
|
|
200
265
|
skipPreloadedContexts,
|
|
266
|
+
timeout,
|
|
201
267
|
userAgent
|
|
202
268
|
}?: GetDocumentLoaderOptions): DocumentLoader;
|
|
203
269
|
//#endregion
|
|
204
|
-
export { DocumentLoaderOptions as a, getDocumentLoader as c,
|
|
270
|
+
export { logRequest as _, DocumentLoaderOptions as a, getDocumentLoader as c, withDocumentLoaderTimeout as d, CreateRequestOptions as f, getUserAgent as g, createActivityPubRequest as h, DocumentLoaderFactoryOptions as i, getRemoteDocument as l, GetUserAgentOptions as m, DocumentLoader as n, GetDocumentLoaderOptions as o, FetchError as p, DocumentLoaderFactory as r, RemoteDocument as s, AuthenticatedDocumentLoaderFactory as t, resolveDocumentLoaderTimeout as u };
|