@fedify/testing 1.10.5 → 1.10.6
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/dist/mod.cjs +20 -50
- package/dist/mod.js +12 -20
- package/package.json +3 -3
package/dist/mod.cjs
CHANGED
|
@@ -1,36 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
-
key = keys[i];
|
|
11
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
-
get: ((k) => from[k]).bind(null, key),
|
|
13
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
-
value: mod,
|
|
20
|
-
enumerable: true
|
|
21
|
-
}) : target, mod));
|
|
22
|
-
|
|
23
|
-
//#endregion
|
|
24
|
-
const __fedify_fedify_vocab = __toESM(require("@fedify/fedify/vocab"));
|
|
25
|
-
const __fedify_fedify_federation = __toESM(require("@fedify/fedify/federation"));
|
|
26
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _fedify_fedify_vocab = require("@fedify/fedify/vocab");
|
|
3
|
+
let _fedify_fedify_federation = require("@fedify/fedify/federation");
|
|
27
4
|
//#region src/docloader.ts
|
|
28
5
|
const mockDocumentLoader = async (url) => ({
|
|
29
6
|
contextUrl: null,
|
|
30
7
|
document: {},
|
|
31
8
|
documentUrl: url
|
|
32
9
|
});
|
|
33
|
-
|
|
34
10
|
//#endregion
|
|
35
11
|
//#region src/context.ts
|
|
36
12
|
const noopTracerProvider$1 = { getTracer: () => ({
|
|
@@ -40,7 +16,7 @@ const noopTracerProvider$1 = { getTracer: () => ({
|
|
|
40
16
|
function createContext(values) {
|
|
41
17
|
const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, tracerProvider, clone, getNodeInfoUri, getActorUri, getObjectUri, getCollectionUri, getOutboxUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject, traverseCollection, lookupNodeInfo, lookupWebFinger, sendActivity, routeActivity } = values;
|
|
42
18
|
function throwRouteError() {
|
|
43
|
-
throw new
|
|
19
|
+
throw new _fedify_fedify_federation.RouterError("Not implemented");
|
|
44
20
|
}
|
|
45
21
|
return {
|
|
46
22
|
federation,
|
|
@@ -52,9 +28,9 @@ function createContext(values) {
|
|
|
52
28
|
documentLoader: documentLoader ?? mockDocumentLoader,
|
|
53
29
|
contextLoader: contextLoader ?? mockDocumentLoader,
|
|
54
30
|
tracerProvider: tracerProvider ?? noopTracerProvider$1,
|
|
55
|
-
clone: clone ?? ((data
|
|
31
|
+
clone: clone ?? ((data) => createContext({
|
|
56
32
|
...values,
|
|
57
|
-
data
|
|
33
|
+
data
|
|
58
34
|
})),
|
|
59
35
|
getNodeInfoUri: getNodeInfoUri ?? throwRouteError,
|
|
60
36
|
getActorUri: getActorUri ?? throwRouteError,
|
|
@@ -75,13 +51,13 @@ function createContext(values) {
|
|
|
75
51
|
}),
|
|
76
52
|
getActorKeyPairs: getActorKeyPairs ?? ((_handle) => Promise.resolve([])),
|
|
77
53
|
lookupObject: lookupObject ?? ((uri, options = {}) => {
|
|
78
|
-
return (0,
|
|
54
|
+
return (0, _fedify_fedify_vocab.lookupObject)(uri, {
|
|
79
55
|
documentLoader: options.documentLoader ?? documentLoader ?? mockDocumentLoader,
|
|
80
56
|
contextLoader: options.contextLoader ?? contextLoader ?? mockDocumentLoader
|
|
81
57
|
});
|
|
82
58
|
}),
|
|
83
59
|
traverseCollection: traverseCollection ?? ((collection, options = {}) => {
|
|
84
|
-
return (0,
|
|
60
|
+
return (0, _fedify_fedify_vocab.traverseCollection)(collection, {
|
|
85
61
|
documentLoader: options.documentLoader ?? documentLoader ?? mockDocumentLoader,
|
|
86
62
|
contextLoader: options.contextLoader ?? contextLoader ?? mockDocumentLoader
|
|
87
63
|
});
|
|
@@ -145,7 +121,6 @@ function createInboxContext(args) {
|
|
|
145
121
|
})
|
|
146
122
|
};
|
|
147
123
|
}
|
|
148
|
-
|
|
149
124
|
//#endregion
|
|
150
125
|
//#region src/mock.ts
|
|
151
126
|
const noopTracerProvider = { getTracer: () => ({
|
|
@@ -363,9 +338,8 @@ var MockFederation = class {
|
|
|
363
338
|
}
|
|
364
339
|
createContext(baseUrlOrRequest, contextData) {
|
|
365
340
|
const mockFederation = this;
|
|
366
|
-
const url = baseUrlOrRequest instanceof Request ? new URL(baseUrlOrRequest.url) : baseUrlOrRequest;
|
|
367
341
|
return new MockContext({
|
|
368
|
-
url,
|
|
342
|
+
url: baseUrlOrRequest instanceof Request ? new URL(baseUrlOrRequest.url) : baseUrlOrRequest,
|
|
369
343
|
data: contextData,
|
|
370
344
|
federation: mockFederation
|
|
371
345
|
});
|
|
@@ -387,13 +361,10 @@ var MockFederation = class {
|
|
|
387
361
|
const typeName = activity.constructor.name;
|
|
388
362
|
const listeners = this.inboxListeners.get(typeName) || [];
|
|
389
363
|
if (listeners.length > 0 && this.contextData === void 0) throw new Error("MockFederation.receiveActivity(): contextData is not initialized. Please provide contextData through the constructor or call startQueue() before receiving activities.");
|
|
390
|
-
for (const listener of listeners) {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
});
|
|
395
|
-
await listener(context, activity);
|
|
396
|
-
}
|
|
364
|
+
for (const listener of listeners) await listener(createInboxContext({
|
|
365
|
+
data: this.contextData,
|
|
366
|
+
federation: this
|
|
367
|
+
}), activity);
|
|
397
368
|
}
|
|
398
369
|
/**
|
|
399
370
|
* Clears all sent activities from the mock federation.
|
|
@@ -527,10 +498,10 @@ var MockContext = class MockContext {
|
|
|
527
498
|
this.request = new Request(url);
|
|
528
499
|
this.data = options.data;
|
|
529
500
|
this.federation = options.federation;
|
|
530
|
-
this.documentLoader = options.documentLoader ?? (async (url
|
|
501
|
+
this.documentLoader = options.documentLoader ?? (async (url) => ({
|
|
531
502
|
contextUrl: null,
|
|
532
503
|
document: {},
|
|
533
|
-
documentUrl: url
|
|
504
|
+
documentUrl: url
|
|
534
505
|
}));
|
|
535
506
|
this.contextLoader = options.contextLoader ?? this.documentLoader;
|
|
536
507
|
this.tracerProvider = options.tracerProvider ?? noopTracerProvider;
|
|
@@ -586,8 +557,8 @@ var MockContext = class MockContext {
|
|
|
586
557
|
if (this.federation instanceof MockFederation) {
|
|
587
558
|
const pathTemplate = this.federation.objectPaths.get(cls.typeId.href);
|
|
588
559
|
if (pathTemplate) {
|
|
589
|
-
const path
|
|
590
|
-
return new URL(path
|
|
560
|
+
const path = expandUriTemplate(pathTemplate, values);
|
|
561
|
+
return new URL(path, this.origin);
|
|
591
562
|
}
|
|
592
563
|
}
|
|
593
564
|
const path = globalThis.Object.entries(values).map(([key, value]) => `${key}/${value}`).join("/");
|
|
@@ -688,12 +659,12 @@ var MockContext = class MockContext {
|
|
|
688
659
|
const owner = this.getActorUri(identifier);
|
|
689
660
|
return keyPairs.map((kp) => ({
|
|
690
661
|
...kp,
|
|
691
|
-
cryptographicKey: new
|
|
662
|
+
cryptographicKey: new _fedify_fedify_vocab.CryptographicKey({
|
|
692
663
|
id: kp.keyId,
|
|
693
664
|
owner,
|
|
694
665
|
publicKey: kp.publicKey
|
|
695
666
|
}),
|
|
696
|
-
multikey: new
|
|
667
|
+
multikey: new _fedify_fedify_vocab.Multikey({
|
|
697
668
|
id: kp.keyId,
|
|
698
669
|
controller: owner,
|
|
699
670
|
publicKey: kp.publicKey
|
|
@@ -757,9 +728,8 @@ var MockContext = class MockContext {
|
|
|
757
728
|
this.sentActivities = [];
|
|
758
729
|
}
|
|
759
730
|
};
|
|
760
|
-
|
|
761
731
|
//#endregion
|
|
762
732
|
exports.createContext = createContext;
|
|
763
733
|
exports.createFederation = createFederation;
|
|
764
734
|
exports.createInboxContext = createInboxContext;
|
|
765
|
-
exports.createRequestContext = createRequestContext;
|
|
735
|
+
exports.createRequestContext = createRequestContext;
|
package/dist/mod.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { CryptographicKey, Multikey, lookupObject, traverseCollection } from "@fedify/fedify/vocab";
|
|
2
2
|
import { RouterError } from "@fedify/fedify/federation";
|
|
3
|
-
|
|
4
3
|
//#region src/docloader.ts
|
|
5
4
|
const mockDocumentLoader = async (url) => ({
|
|
6
5
|
contextUrl: null,
|
|
7
6
|
document: {},
|
|
8
7
|
documentUrl: url
|
|
9
8
|
});
|
|
10
|
-
|
|
11
9
|
//#endregion
|
|
12
10
|
//#region src/context.ts
|
|
13
11
|
const noopTracerProvider$1 = { getTracer: () => ({
|
|
@@ -29,9 +27,9 @@ function createContext(values) {
|
|
|
29
27
|
documentLoader: documentLoader ?? mockDocumentLoader,
|
|
30
28
|
contextLoader: contextLoader ?? mockDocumentLoader,
|
|
31
29
|
tracerProvider: tracerProvider ?? noopTracerProvider$1,
|
|
32
|
-
clone: clone ?? ((data
|
|
30
|
+
clone: clone ?? ((data) => createContext({
|
|
33
31
|
...values,
|
|
34
|
-
data
|
|
32
|
+
data
|
|
35
33
|
})),
|
|
36
34
|
getNodeInfoUri: getNodeInfoUri ?? throwRouteError,
|
|
37
35
|
getActorUri: getActorUri ?? throwRouteError,
|
|
@@ -122,7 +120,6 @@ function createInboxContext(args) {
|
|
|
122
120
|
})
|
|
123
121
|
};
|
|
124
122
|
}
|
|
125
|
-
|
|
126
123
|
//#endregion
|
|
127
124
|
//#region src/mock.ts
|
|
128
125
|
const noopTracerProvider = { getTracer: () => ({
|
|
@@ -340,9 +337,8 @@ var MockFederation = class {
|
|
|
340
337
|
}
|
|
341
338
|
createContext(baseUrlOrRequest, contextData) {
|
|
342
339
|
const mockFederation = this;
|
|
343
|
-
const url = baseUrlOrRequest instanceof Request ? new URL(baseUrlOrRequest.url) : baseUrlOrRequest;
|
|
344
340
|
return new MockContext({
|
|
345
|
-
url,
|
|
341
|
+
url: baseUrlOrRequest instanceof Request ? new URL(baseUrlOrRequest.url) : baseUrlOrRequest,
|
|
346
342
|
data: contextData,
|
|
347
343
|
federation: mockFederation
|
|
348
344
|
});
|
|
@@ -364,13 +360,10 @@ var MockFederation = class {
|
|
|
364
360
|
const typeName = activity.constructor.name;
|
|
365
361
|
const listeners = this.inboxListeners.get(typeName) || [];
|
|
366
362
|
if (listeners.length > 0 && this.contextData === void 0) throw new Error("MockFederation.receiveActivity(): contextData is not initialized. Please provide contextData through the constructor or call startQueue() before receiving activities.");
|
|
367
|
-
for (const listener of listeners) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
});
|
|
372
|
-
await listener(context, activity);
|
|
373
|
-
}
|
|
363
|
+
for (const listener of listeners) await listener(createInboxContext({
|
|
364
|
+
data: this.contextData,
|
|
365
|
+
federation: this
|
|
366
|
+
}), activity);
|
|
374
367
|
}
|
|
375
368
|
/**
|
|
376
369
|
* Clears all sent activities from the mock federation.
|
|
@@ -504,10 +497,10 @@ var MockContext = class MockContext {
|
|
|
504
497
|
this.request = new Request(url);
|
|
505
498
|
this.data = options.data;
|
|
506
499
|
this.federation = options.federation;
|
|
507
|
-
this.documentLoader = options.documentLoader ?? (async (url
|
|
500
|
+
this.documentLoader = options.documentLoader ?? (async (url) => ({
|
|
508
501
|
contextUrl: null,
|
|
509
502
|
document: {},
|
|
510
|
-
documentUrl: url
|
|
503
|
+
documentUrl: url
|
|
511
504
|
}));
|
|
512
505
|
this.contextLoader = options.contextLoader ?? this.documentLoader;
|
|
513
506
|
this.tracerProvider = options.tracerProvider ?? noopTracerProvider;
|
|
@@ -563,8 +556,8 @@ var MockContext = class MockContext {
|
|
|
563
556
|
if (this.federation instanceof MockFederation) {
|
|
564
557
|
const pathTemplate = this.federation.objectPaths.get(cls.typeId.href);
|
|
565
558
|
if (pathTemplate) {
|
|
566
|
-
const path
|
|
567
|
-
return new URL(path
|
|
559
|
+
const path = expandUriTemplate(pathTemplate, values);
|
|
560
|
+
return new URL(path, this.origin);
|
|
568
561
|
}
|
|
569
562
|
}
|
|
570
563
|
const path = globalThis.Object.entries(values).map(([key, value]) => `${key}/${value}`).join("/");
|
|
@@ -734,6 +727,5 @@ var MockContext = class MockContext {
|
|
|
734
727
|
this.sentActivities = [];
|
|
735
728
|
}
|
|
736
729
|
};
|
|
737
|
-
|
|
738
730
|
//#endregion
|
|
739
|
-
export { createContext, createFederation, createInboxContext, createRequestContext };
|
|
731
|
+
export { createContext, createFederation, createInboxContext, createRequestContext };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/testing",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.6",
|
|
4
4
|
"description": "Testing utilities for Fedify applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -50,13 +50,13 @@
|
|
|
50
50
|
"package.json"
|
|
51
51
|
],
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@fedify/fedify": "^1.10.
|
|
53
|
+
"@fedify/fedify": "^1.10.6"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@js-temporal/polyfill": "^0.5.1",
|
|
57
57
|
"@std/assert": "npm:@jsr/std__assert@^1.0.13",
|
|
58
58
|
"@std/async": "npm:@jsr/std__async@^1.0.13",
|
|
59
|
-
"tsdown": "^0.
|
|
59
|
+
"tsdown": "^0.21.6",
|
|
60
60
|
"typescript": "^5.9.2"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|