@webiny/api-core-testing 0.0.0-unstable.5387e5f7c8 → 0.0.0-unstable.eb81deee7e
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/index.d.ts +0 -1
- package/index.js +0 -1
- package/package.json +5 -6
- package/mocks/InlineTaskService.d.ts +0 -6
- package/mocks/InlineTaskService.js +0 -85
- package/mocks/InlineTaskService.js.map +0 -1
package/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { TestIdentity, TestAuthenticator } from "./mocks/TestAuthenticator.js";
|
|
2
2
|
export { TestPermissions, TestAuthorizer } from "./mocks/TestAuthorizer.js";
|
|
3
3
|
export type { TestPermissionsHolder } from "./mocks/TestAuthorizer.js";
|
|
4
|
-
export { InlineTaskServiceFeature } from "./mocks/InlineTaskService.js";
|
|
5
4
|
export { AuthTriggerHandler } from "./handlers/AuthTriggerHandler.js";
|
|
6
5
|
export { RootTenantInitializer } from "./handlers/RootTenantInitializer.js";
|
|
7
6
|
export { createIdentity } from "./identity.js";
|
package/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { TestAuthenticator, TestIdentity } from "./mocks/TestAuthenticator.js";
|
|
2
2
|
export { TestAuthorizer, TestPermissions } from "./mocks/TestAuthorizer.js";
|
|
3
|
-
export { InlineTaskServiceFeature } from "./mocks/InlineTaskService.js";
|
|
4
3
|
export { AuthTriggerHandler } from "./handlers/AuthTriggerHandler.js";
|
|
5
4
|
export { RootTenantInitializer } from "./handlers/RootTenantInitializer.js";
|
|
6
5
|
export { createIdentity } from "./identity.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/api-core-testing",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.eb81deee7e",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -15,13 +15,12 @@
|
|
|
15
15
|
"author": "Webiny Ltd.",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@webiny/api-core": "0.0.0-unstable.
|
|
19
|
-
"@webiny/di": "
|
|
20
|
-
"@webiny/event-handler-core": "0.0.0-unstable.
|
|
21
|
-
"@webiny/feature": "0.0.0-unstable.5387e5f7c8"
|
|
18
|
+
"@webiny/api-core": "0.0.0-unstable.eb81deee7e",
|
|
19
|
+
"@webiny/di": "1.1.0",
|
|
20
|
+
"@webiny/event-handler-core": "0.0.0-unstable.eb81deee7e"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
23
|
+
"@webiny/build-tools": "0.0.0-unstable.eb81deee7e",
|
|
25
24
|
"rimraf": "6.1.3",
|
|
26
25
|
"typescript": "7.0.2"
|
|
27
26
|
},
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Result, createFeature } from "@webiny/feature/api";
|
|
2
|
-
import { TaskService } from "@webiny/api-core/features/task/TaskService/index.js";
|
|
3
|
-
import { TaskDefinition, TaskResultStatus } from "@webiny/api-core/features/task/TaskDefinition/index.js";
|
|
4
|
-
const MAX_RUNS = 100;
|
|
5
|
-
class InlineTaskServiceImpl {
|
|
6
|
-
constructor(container){
|
|
7
|
-
this.container = container;
|
|
8
|
-
this.nextId = 1;
|
|
9
|
-
}
|
|
10
|
-
async trigger(params) {
|
|
11
|
-
const definition = this.container.resolveAll(TaskDefinition).find((candidate)=>candidate.id === params.definition);
|
|
12
|
-
if (!definition) throw new Error(`No task definition "${params.definition}" is registered.`);
|
|
13
|
-
const handler = this.container.resolveImplementation(definition.handler);
|
|
14
|
-
const controller = this.createController();
|
|
15
|
-
let input = params.input ?? {};
|
|
16
|
-
for(let run = 1; run <= MAX_RUNS; run++){
|
|
17
|
-
const result = await handler.run({
|
|
18
|
-
input,
|
|
19
|
-
definition,
|
|
20
|
-
controller
|
|
21
|
-
});
|
|
22
|
-
if (result.status !== TaskResultStatus.CONTINUE) break;
|
|
23
|
-
if (run === MAX_RUNS) throw new Error(`Task "${definition.id}" was still continuing after ${MAX_RUNS} runs.`);
|
|
24
|
-
input = result.input;
|
|
25
|
-
}
|
|
26
|
-
const now = new Date().toISOString();
|
|
27
|
-
return Result.ok({
|
|
28
|
-
id: `inline-task-${this.nextId++}`,
|
|
29
|
-
definitionId: definition.id,
|
|
30
|
-
input,
|
|
31
|
-
createdOn: now,
|
|
32
|
-
savedOn: now
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
async abort() {
|
|
36
|
-
throw new Error("Inline tasks finish inside trigger(), so there is nothing to abort.");
|
|
37
|
-
}
|
|
38
|
-
async fetchServiceInfo() {
|
|
39
|
-
return Result.ok({});
|
|
40
|
-
}
|
|
41
|
-
createController() {
|
|
42
|
-
return {
|
|
43
|
-
runtime: {
|
|
44
|
-
isAborted: ()=>false,
|
|
45
|
-
isCloseToTimeout: ()=>false
|
|
46
|
-
},
|
|
47
|
-
response: {
|
|
48
|
-
done: (message, output)=>({
|
|
49
|
-
status: TaskResultStatus.DONE,
|
|
50
|
-
message,
|
|
51
|
-
output
|
|
52
|
-
}),
|
|
53
|
-
continue: (input)=>({
|
|
54
|
-
status: TaskResultStatus.CONTINUE,
|
|
55
|
-
input
|
|
56
|
-
}),
|
|
57
|
-
error: (error)=>({
|
|
58
|
-
status: TaskResultStatus.ERROR,
|
|
59
|
-
error
|
|
60
|
-
}),
|
|
61
|
-
aborted: ()=>({
|
|
62
|
-
status: TaskResultStatus.ABORTED
|
|
63
|
-
})
|
|
64
|
-
},
|
|
65
|
-
task: {
|
|
66
|
-
trigger: (params)=>this.trigger(params)
|
|
67
|
-
},
|
|
68
|
-
logger: {
|
|
69
|
-
info: async ()=>{},
|
|
70
|
-
error: async ()=>{},
|
|
71
|
-
warn: async ()=>{},
|
|
72
|
-
debug: async ()=>{}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
const InlineTaskServiceFeature = createFeature({
|
|
78
|
-
name: "Testing/InlineTaskService",
|
|
79
|
-
register (container) {
|
|
80
|
-
container.registerInstance(TaskService, new InlineTaskServiceImpl(container));
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
export { InlineTaskServiceFeature };
|
|
84
|
-
|
|
85
|
-
//# sourceMappingURL=InlineTaskService.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mocks/InlineTaskService.js","sources":["../../src/mocks/InlineTaskService.ts"],"sourcesContent":["import type { Container } from \"@webiny/di\";\nimport { createFeature, Result } from \"@webiny/feature/api\";\nimport {\n TaskService,\n type ITaskTriggerParams\n} from \"@webiny/api-core/features/task/TaskService/index.js\";\nimport {\n TaskDefinition,\n TaskResultStatus\n} from \"@webiny/api-core/features/task/TaskDefinition/index.js\";\n\n/** A task that keeps asking to continue is broken; stop it instead of hanging the test. */\nconst MAX_RUNS = 100;\n\n/*\n * A `TaskService` that runs the triggered task right away, inside `trigger`, and keeps calling it\n * while it asks to continue. Tests then see the task's effects as soon as the triggering call\n * returns, with no task records and no step function. The controller covers what the task handlers\n * use: runtime checks (never aborted, never out of time), responses, triggering further tasks and a\n * silent logger.\n */\nclass InlineTaskServiceImpl implements TaskService.Interface {\n private nextId = 1;\n\n constructor(private container: Container) {}\n\n async trigger<I extends TaskDefinition.TaskInput = TaskDefinition.TaskInput>(\n params: ITaskTriggerParams<I>\n ) {\n const definition = this.container\n .resolveAll(TaskDefinition)\n .find(candidate => candidate.id === params.definition);\n if (!definition) {\n throw new Error(`No task definition \"${params.definition}\" is registered.`);\n }\n\n const handler = this.container.resolveImplementation(definition.handler);\n const controller = this.createController();\n\n let input = params.input ?? ({} as I);\n for (let run = 1; run <= MAX_RUNS; run++) {\n const result = await handler.run({ input, definition, controller } as never);\n if (result.status !== TaskResultStatus.CONTINUE) {\n break;\n }\n if (run === MAX_RUNS) {\n throw new Error(\n `Task \"${definition.id}\" was still continuing after ${MAX_RUNS} runs.`\n );\n }\n input = (result as { input: I }).input;\n }\n\n const now = new Date().toISOString();\n return Result.ok({\n id: `inline-task-${this.nextId++}`,\n definitionId: definition.id,\n input,\n createdOn: now,\n savedOn: now\n }) as never;\n }\n\n async abort(): Promise<never> {\n throw new Error(\"Inline tasks finish inside trigger(), so there is nothing to abort.\");\n }\n\n async fetchServiceInfo() {\n return Result.ok({});\n }\n\n private createController() {\n return {\n runtime: {\n isAborted: () => false,\n isCloseToTimeout: () => false\n },\n response: {\n done: (message?: string, output?: unknown) => ({\n status: TaskResultStatus.DONE,\n message,\n output\n }),\n continue: (input: unknown) => ({ status: TaskResultStatus.CONTINUE, input }),\n error: (error: unknown) => ({ status: TaskResultStatus.ERROR, error }),\n aborted: () => ({ status: TaskResultStatus.ABORTED })\n },\n task: {\n trigger: (params: ITaskTriggerParams) => this.trigger(params)\n },\n logger: {\n info: async () => {},\n error: async () => {},\n warn: async () => {},\n debug: async () => {}\n }\n };\n }\n}\n\n/** Registers a {@link TaskService} that runs every triggered task inline. */\nexport const InlineTaskServiceFeature = createFeature({\n name: \"Testing/InlineTaskService\",\n register(container) {\n container.registerInstance(TaskService, new InlineTaskServiceImpl(container));\n }\n});\n"],"names":["MAX_RUNS","InlineTaskServiceImpl","container","params","definition","TaskDefinition","candidate","Error","handler","controller","input","run","result","TaskResultStatus","now","Date","Result","message","output","error","InlineTaskServiceFeature","createFeature","TaskService"],"mappings":";;;AAYA,MAAMA,WAAW;AASjB,MAAMC;IAGF,YAAoBC,SAAoB,CAAE;aAAtBA,SAAS,GAATA;aAFZ,MAAM,GAAG;IAE0B;IAE3C,MAAM,QACFC,MAA6B,EAC/B;QACE,MAAMC,aAAa,IAAI,CAAC,SAAS,CAC5B,UAAU,CAACC,gBACX,IAAI,CAACC,CAAAA,YAAaA,UAAU,EAAE,KAAKH,OAAO,UAAU;QACzD,IAAI,CAACC,YACD,MAAM,IAAIG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