@fedify/testing 2.3.0-dev.1347 → 2.3.0-dev.1361
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 +42 -1
- package/dist/mod.js +42 -1
- package/package.json +3 -2
package/dist/mod.cjs
CHANGED
|
@@ -38,7 +38,7 @@ const noopMeterProvider$1 = { getMeter: () => ({
|
|
|
38
38
|
removeBatchObservableCallback: () => void 0
|
|
39
39
|
}) };
|
|
40
40
|
function createContext(values) {
|
|
41
|
-
const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, meterProvider, tracerProvider, clone, getNodeInfoUri, getActorUri, getObjectUri, getCollectionUri, getOutboxUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject, traverseCollection, lookupNodeInfo, lookupWebFinger, sendActivity, routeActivity } = values;
|
|
41
|
+
const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, meterProvider, tracerProvider, clone, getNodeInfoUri, getActorUri, getObjectUri, getCollectionUri, getOutboxUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject, traverseCollection, lookupNodeInfo, lookupWebFinger, sendActivity, routeActivity, enqueueTask, enqueueTaskMany } = values;
|
|
42
42
|
function throwRouterError() {
|
|
43
43
|
throw new _fedify_fedify_federation.RouterError("Not implemented");
|
|
44
44
|
}
|
|
@@ -98,6 +98,12 @@ function createContext(values) {
|
|
|
98
98
|
}),
|
|
99
99
|
routeActivity: routeActivity ?? ((_params) => {
|
|
100
100
|
throw new Error("Not implemented");
|
|
101
|
+
}),
|
|
102
|
+
enqueueTask: enqueueTask ?? ((_task, _data, _options) => {
|
|
103
|
+
throw new Error("Not implemented");
|
|
104
|
+
}),
|
|
105
|
+
enqueueTaskMany: enqueueTaskMany ?? ((_task, _payloads, _options) => {
|
|
106
|
+
throw new Error("Not implemented");
|
|
101
107
|
})
|
|
102
108
|
};
|
|
103
109
|
}
|
|
@@ -286,6 +292,7 @@ var MockFederation = class {
|
|
|
286
292
|
sharedInboxPath;
|
|
287
293
|
objectPaths = /* @__PURE__ */ new Map();
|
|
288
294
|
objectDispatchers = /* @__PURE__ */ new Map();
|
|
295
|
+
taskDefinitions = /* @__PURE__ */ new Map();
|
|
289
296
|
inboxDispatcher;
|
|
290
297
|
outboxDispatcher;
|
|
291
298
|
outboxAuthorizePredicate;
|
|
@@ -309,6 +316,19 @@ var MockFederation = class {
|
|
|
309
316
|
this.nodeInfoDispatcher = dispatcher;
|
|
310
317
|
this.nodeInfoPath = path;
|
|
311
318
|
}
|
|
319
|
+
defineTask(name, options) {
|
|
320
|
+
if (this.taskDefinitions.has(name)) throw new TypeError(`Task ${JSON.stringify(name)} is already defined.`);
|
|
321
|
+
const handle = {
|
|
322
|
+
name,
|
|
323
|
+
schema: options.schema
|
|
324
|
+
};
|
|
325
|
+
this.taskDefinitions.set(name, {
|
|
326
|
+
name,
|
|
327
|
+
...options,
|
|
328
|
+
handle
|
|
329
|
+
});
|
|
330
|
+
return handle;
|
|
331
|
+
}
|
|
312
332
|
setWebFingerLinksDispatcher(dispatcher) {
|
|
313
333
|
this.webFingerDispatcher = dispatcher;
|
|
314
334
|
}
|
|
@@ -459,6 +479,7 @@ var MockFederation = class {
|
|
|
459
479
|
this.activeQueues.add("inbox");
|
|
460
480
|
this.activeQueues.add("outbox");
|
|
461
481
|
this.activeQueues.add("fanout");
|
|
482
|
+
this.activeQueues.add("task");
|
|
462
483
|
}
|
|
463
484
|
}
|
|
464
485
|
async processQueuedTask(contextData, _message) {
|
|
@@ -738,6 +759,26 @@ var MockContext = class MockContext {
|
|
|
738
759
|
getSignedKeyOwner() {
|
|
739
760
|
return Promise.resolve(null);
|
|
740
761
|
}
|
|
762
|
+
#resolveTaskDefinition(task) {
|
|
763
|
+
if (!(this.federation instanceof MockFederation)) throw new TypeError("No task definitions are available.");
|
|
764
|
+
const def = this.federation.taskDefinitions.get(task.name);
|
|
765
|
+
if (def == null || def.handle !== task) throw new TypeError(`Task ${JSON.stringify(task.name)} is not defined on this federation; pass a handle returned by its defineTask().`);
|
|
766
|
+
return def;
|
|
767
|
+
}
|
|
768
|
+
async #validateTaskPayload(def, data) {
|
|
769
|
+
const result = await def.schema["~standard"].validate(data);
|
|
770
|
+
if (result.issues != null && result.issues.length > 0) throw new TypeError(`Task data failed schema validation: ${JSON.stringify(result.issues)}`);
|
|
771
|
+
return result.value;
|
|
772
|
+
}
|
|
773
|
+
async enqueueTask(task, data, _options) {
|
|
774
|
+
const def = this.#resolveTaskDefinition(task);
|
|
775
|
+
await def.handler(this, await this.#validateTaskPayload(def, data));
|
|
776
|
+
}
|
|
777
|
+
async enqueueTaskMany(task, payloads, _options) {
|
|
778
|
+
const def = this.#resolveTaskDefinition(task);
|
|
779
|
+
const values = await Promise.all(payloads.map((data) => this.#validateTaskPayload(def, data)));
|
|
780
|
+
for (const value of values) await def.handler(this, value);
|
|
781
|
+
}
|
|
741
782
|
clone(data) {
|
|
742
783
|
return new MockContext({
|
|
743
784
|
url: this.url,
|
package/dist/mod.js
CHANGED
|
@@ -37,7 +37,7 @@ const noopMeterProvider$1 = { getMeter: () => ({
|
|
|
37
37
|
removeBatchObservableCallback: () => void 0
|
|
38
38
|
}) };
|
|
39
39
|
function createContext(values) {
|
|
40
|
-
const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, meterProvider, tracerProvider, clone, getNodeInfoUri, getActorUri, getObjectUri, getCollectionUri, getOutboxUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject: lookupObject$1, traverseCollection: traverseCollection$1, lookupNodeInfo, lookupWebFinger, sendActivity, routeActivity } = values;
|
|
40
|
+
const { federation, url = new URL("http://example.com/"), canonicalOrigin, data, documentLoader, contextLoader, meterProvider, tracerProvider, clone, getNodeInfoUri, getActorUri, getObjectUri, getCollectionUri, getOutboxUri, getInboxUri, getFollowingUri, getFollowersUri, getLikedUri, getFeaturedUri, getFeaturedTagsUri, parseUri, getActorKeyPairs, getDocumentLoader, lookupObject: lookupObject$1, traverseCollection: traverseCollection$1, lookupNodeInfo, lookupWebFinger, sendActivity, routeActivity, enqueueTask, enqueueTaskMany } = values;
|
|
41
41
|
function throwRouterError() {
|
|
42
42
|
throw new RouterError("Not implemented");
|
|
43
43
|
}
|
|
@@ -97,6 +97,12 @@ function createContext(values) {
|
|
|
97
97
|
}),
|
|
98
98
|
routeActivity: routeActivity ?? ((_params) => {
|
|
99
99
|
throw new Error("Not implemented");
|
|
100
|
+
}),
|
|
101
|
+
enqueueTask: enqueueTask ?? ((_task, _data, _options) => {
|
|
102
|
+
throw new Error("Not implemented");
|
|
103
|
+
}),
|
|
104
|
+
enqueueTaskMany: enqueueTaskMany ?? ((_task, _payloads, _options) => {
|
|
105
|
+
throw new Error("Not implemented");
|
|
100
106
|
})
|
|
101
107
|
};
|
|
102
108
|
}
|
|
@@ -285,6 +291,7 @@ var MockFederation = class {
|
|
|
285
291
|
sharedInboxPath;
|
|
286
292
|
objectPaths = /* @__PURE__ */ new Map();
|
|
287
293
|
objectDispatchers = /* @__PURE__ */ new Map();
|
|
294
|
+
taskDefinitions = /* @__PURE__ */ new Map();
|
|
288
295
|
inboxDispatcher;
|
|
289
296
|
outboxDispatcher;
|
|
290
297
|
outboxAuthorizePredicate;
|
|
@@ -308,6 +315,19 @@ var MockFederation = class {
|
|
|
308
315
|
this.nodeInfoDispatcher = dispatcher;
|
|
309
316
|
this.nodeInfoPath = path;
|
|
310
317
|
}
|
|
318
|
+
defineTask(name, options) {
|
|
319
|
+
if (this.taskDefinitions.has(name)) throw new TypeError(`Task ${JSON.stringify(name)} is already defined.`);
|
|
320
|
+
const handle = {
|
|
321
|
+
name,
|
|
322
|
+
schema: options.schema
|
|
323
|
+
};
|
|
324
|
+
this.taskDefinitions.set(name, {
|
|
325
|
+
name,
|
|
326
|
+
...options,
|
|
327
|
+
handle
|
|
328
|
+
});
|
|
329
|
+
return handle;
|
|
330
|
+
}
|
|
311
331
|
setWebFingerLinksDispatcher(dispatcher) {
|
|
312
332
|
this.webFingerDispatcher = dispatcher;
|
|
313
333
|
}
|
|
@@ -458,6 +478,7 @@ var MockFederation = class {
|
|
|
458
478
|
this.activeQueues.add("inbox");
|
|
459
479
|
this.activeQueues.add("outbox");
|
|
460
480
|
this.activeQueues.add("fanout");
|
|
481
|
+
this.activeQueues.add("task");
|
|
461
482
|
}
|
|
462
483
|
}
|
|
463
484
|
async processQueuedTask(contextData, _message) {
|
|
@@ -737,6 +758,26 @@ var MockContext = class MockContext {
|
|
|
737
758
|
getSignedKeyOwner() {
|
|
738
759
|
return Promise.resolve(null);
|
|
739
760
|
}
|
|
761
|
+
#resolveTaskDefinition(task) {
|
|
762
|
+
if (!(this.federation instanceof MockFederation)) throw new TypeError("No task definitions are available.");
|
|
763
|
+
const def = this.federation.taskDefinitions.get(task.name);
|
|
764
|
+
if (def == null || def.handle !== task) throw new TypeError(`Task ${JSON.stringify(task.name)} is not defined on this federation; pass a handle returned by its defineTask().`);
|
|
765
|
+
return def;
|
|
766
|
+
}
|
|
767
|
+
async #validateTaskPayload(def, data) {
|
|
768
|
+
const result = await def.schema["~standard"].validate(data);
|
|
769
|
+
if (result.issues != null && result.issues.length > 0) throw new TypeError(`Task data failed schema validation: ${JSON.stringify(result.issues)}`);
|
|
770
|
+
return result.value;
|
|
771
|
+
}
|
|
772
|
+
async enqueueTask(task, data, _options) {
|
|
773
|
+
const def = this.#resolveTaskDefinition(task);
|
|
774
|
+
await def.handler(this, await this.#validateTaskPayload(def, data));
|
|
775
|
+
}
|
|
776
|
+
async enqueueTaskMany(task, payloads, _options) {
|
|
777
|
+
const def = this.#resolveTaskDefinition(task);
|
|
778
|
+
const values = await Promise.all(payloads.map((data) => this.#validateTaskPayload(def, data)));
|
|
779
|
+
for (const value of values) await def.handler(this, value);
|
|
780
|
+
}
|
|
740
781
|
clone(data) {
|
|
741
782
|
return new MockContext({
|
|
742
783
|
url: this.url,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/testing",
|
|
3
|
-
"version": "2.3.0-dev.
|
|
3
|
+
"version": "2.3.0-dev.1361+15c6e619",
|
|
4
4
|
"description": "Testing utilities for Fedify applications",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fedify",
|
|
@@ -50,13 +50,14 @@
|
|
|
50
50
|
"package.json"
|
|
51
51
|
],
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@fedify/fedify": "^2.3.0-dev.
|
|
53
|
+
"@fedify/fedify": "^2.3.0-dev.1361+15c6e619"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"es-toolkit": "1.46.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
59
|
"@js-temporal/polyfill": "^0.5.1",
|
|
60
|
+
"@standard-schema/spec": "^1.1.0",
|
|
60
61
|
"@std/assert": "npm:@jsr/std__assert@^1.0.13",
|
|
61
62
|
"@std/async": "npm:@jsr/std__async@^1.0.13",
|
|
62
63
|
"tsdown": "^0.22.0",
|