@serenity-js/core 2.32.4 → 3.0.0-rc.3
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/CHANGELOG.md +76 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +4 -1
- package/lib/index.js.map +1 -1
- package/lib/io/ErrorSerialiser.js +4 -1
- package/lib/io/ErrorSerialiser.js.map +1 -1
- package/lib/io/asyncMap.d.ts +8 -0
- package/lib/io/asyncMap.js +18 -0
- package/lib/io/asyncMap.js.map +1 -0
- package/lib/io/format.d.ts +37 -0
- package/lib/io/format.js +49 -0
- package/lib/io/format.js.map +1 -0
- package/lib/io/formatted.d.ts +5 -1
- package/lib/io/formatted.js +6 -13
- package/lib/io/formatted.js.map +1 -1
- package/lib/io/index.d.ts +2 -1
- package/lib/io/index.js +2 -1
- package/lib/io/index.js.map +1 -1
- package/lib/io/inspected.d.ts +9 -1
- package/lib/io/inspected.js +50 -14
- package/lib/io/inspected.js.map +1 -1
- package/lib/model/Timestamp.d.ts +4 -2
- package/lib/model/Timestamp.js +8 -2
- package/lib/model/Timestamp.js.map +1 -1
- package/lib/screenplay/Question.d.ts +6 -83
- package/lib/screenplay/Question.js +14 -98
- package/lib/screenplay/Question.js.map +1 -1
- package/lib/screenplay/actor/Actor.js +2 -2
- package/lib/screenplay/actor/Actor.js.map +1 -1
- package/lib/screenplay/index.d.ts +1 -1
- package/lib/screenplay/index.js +1 -1
- package/lib/screenplay/index.js.map +1 -1
- package/lib/screenplay/model/Adapter.d.ts +8 -0
- package/lib/{io/collections/reducible.js → screenplay/model/Adapter.js} +1 -1
- package/lib/screenplay/model/Adapter.js.map +1 -0
- package/lib/screenplay/model/createAdapter.d.ts +3 -0
- package/lib/screenplay/model/createAdapter.js +112 -0
- package/lib/screenplay/model/createAdapter.js.map +1 -0
- package/lib/screenplay/model/index.d.ts +2 -0
- package/lib/screenplay/{tasks → model}/index.js +2 -1
- package/lib/screenplay/model/index.js.map +1 -0
- package/lib/screenplay/questions/Expectation.d.ts +11 -0
- package/lib/screenplay/questions/Expectation.js +18 -1
- package/lib/screenplay/questions/Expectation.js.map +1 -1
- package/lib/screenplay/questions/List.d.ts +22 -191
- package/lib/screenplay/questions/List.js +162 -208
- package/lib/screenplay/questions/List.js.map +1 -1
- package/lib/screenplay/questions/Note.d.ts +10 -0
- package/lib/screenplay/questions/Note.js +17 -1
- package/lib/screenplay/questions/Note.js.map +1 -1
- package/lib/screenplay/questions/index.d.ts +0 -3
- package/lib/screenplay/questions/index.js +0 -5
- package/lib/screenplay/questions/index.js.map +1 -1
- package/package.json +7 -7
- package/src/index.ts +2 -1
- package/src/io/ErrorSerialiser.ts +5 -1
- package/src/io/asyncMap.ts +18 -0
- package/src/io/format.ts +46 -0
- package/src/io/formatted.ts +7 -15
- package/src/io/index.ts +2 -1
- package/src/io/inspected.ts +66 -14
- package/src/model/Timestamp.ts +10 -2
- package/src/screenplay/Question.ts +21 -119
- package/src/screenplay/actor/Actor.ts +2 -2
- package/src/screenplay/index.ts +1 -1
- package/src/screenplay/model/Adapter.ts +14 -0
- package/src/screenplay/model/createAdapter.ts +142 -0
- package/src/screenplay/model/index.ts +2 -0
- package/src/screenplay/questions/Expectation.ts +20 -1
- package/src/screenplay/questions/List.ts +228 -232
- package/src/screenplay/questions/Note.ts +21 -1
- package/src/screenplay/questions/index.ts +0 -3
- package/lib/io/collections/index.d.ts +0 -2
- package/lib/io/collections/index.js +0 -15
- package/lib/io/collections/index.js.map +0 -1
- package/lib/io/collections/mappable.d.ts +0 -52
- package/lib/io/collections/mappable.js +0 -28
- package/lib/io/collections/mappable.js.map +0 -1
- package/lib/io/collections/reducible.d.ts +0 -16
- package/lib/io/collections/reducible.js.map +0 -1
- package/lib/screenplay/questions/Property.d.ts +0 -91
- package/lib/screenplay/questions/Property.js +0 -99
- package/lib/screenplay/questions/Property.js.map +0 -1
- package/lib/screenplay/questions/Transform.d.ts +0 -31
- package/lib/screenplay/questions/Transform.js +0 -46
- package/lib/screenplay/questions/Transform.js.map +0 -1
- package/lib/screenplay/questions/lists/ArrayListAdapter.d.ts +0 -88
- package/lib/screenplay/questions/lists/ArrayListAdapter.js +0 -152
- package/lib/screenplay/questions/lists/ArrayListAdapter.js.map +0 -1
- package/lib/screenplay/questions/lists/ListAdapter.d.ts +0 -20
- package/lib/screenplay/questions/lists/ListAdapter.js +0 -3
- package/lib/screenplay/questions/lists/ListAdapter.js.map +0 -1
- package/lib/screenplay/questions/lists/index.d.ts +0 -2
- package/lib/screenplay/questions/lists/index.js +0 -15
- package/lib/screenplay/questions/lists/index.js.map +0 -1
- package/lib/screenplay/questions/mappings/AnswerMappingFunction.d.ts +0 -11
- package/lib/screenplay/questions/mappings/AnswerMappingFunction.js +0 -3
- package/lib/screenplay/questions/mappings/AnswerMappingFunction.js.map +0 -1
- package/lib/screenplay/questions/mappings/index.d.ts +0 -2
- package/lib/screenplay/questions/mappings/index.js +0 -15
- package/lib/screenplay/questions/mappings/index.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/append.d.ts +0 -14
- package/lib/screenplay/questions/mappings/string/append.js +0 -25
- package/lib/screenplay/questions/mappings/string/append.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/index.d.ts +0 -11
- package/lib/screenplay/questions/mappings/string/index.js +0 -24
- package/lib/screenplay/questions/mappings/string/index.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/normalize.d.ts +0 -20
- package/lib/screenplay/questions/mappings/string/normalize.js +0 -30
- package/lib/screenplay/questions/mappings/string/normalize.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/replace.d.ts +0 -17
- package/lib/screenplay/questions/mappings/string/replace.js +0 -30
- package/lib/screenplay/questions/mappings/string/replace.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/slice.d.ts +0 -28
- package/lib/screenplay/questions/mappings/string/slice.js +0 -47
- package/lib/screenplay/questions/mappings/string/slice.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/split.d.ts +0 -19
- package/lib/screenplay/questions/mappings/string/split.js +0 -36
- package/lib/screenplay/questions/mappings/string/split.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/toLocaleLowerCase.d.ts +0 -17
- package/lib/screenplay/questions/mappings/string/toLocaleLowerCase.js +0 -28
- package/lib/screenplay/questions/mappings/string/toLocaleLowerCase.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/toLocaleUpperCase.d.ts +0 -17
- package/lib/screenplay/questions/mappings/string/toLocaleUpperCase.js +0 -29
- package/lib/screenplay/questions/mappings/string/toLocaleUpperCase.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/toLowerCase.d.ts +0 -10
- package/lib/screenplay/questions/mappings/string/toLowerCase.js +0 -19
- package/lib/screenplay/questions/mappings/string/toLowerCase.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/toNumber.d.ts +0 -10
- package/lib/screenplay/questions/mappings/string/toNumber.js +0 -18
- package/lib/screenplay/questions/mappings/string/toNumber.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/toUpperCase.d.ts +0 -10
- package/lib/screenplay/questions/mappings/string/toUpperCase.js +0 -19
- package/lib/screenplay/questions/mappings/string/toUpperCase.js.map +0 -1
- package/lib/screenplay/questions/mappings/string/trim.d.ts +0 -12
- package/lib/screenplay/questions/mappings/string/trim.js +0 -21
- package/lib/screenplay/questions/mappings/string/trim.js.map +0 -1
- package/lib/screenplay/questions/proxies/PropertyPathKey.d.ts +0 -4
- package/lib/screenplay/questions/proxies/PropertyPathKey.js +0 -3
- package/lib/screenplay/questions/proxies/PropertyPathKey.js.map +0 -1
- package/lib/screenplay/questions/proxies/createMetaQuestionProxy.d.ts +0 -14
- package/lib/screenplay/questions/proxies/createMetaQuestionProxy.js +0 -35
- package/lib/screenplay/questions/proxies/createMetaQuestionProxy.js.map +0 -1
- package/lib/screenplay/questions/proxies/createQuestionProxy.d.ts +0 -13
- package/lib/screenplay/questions/proxies/createQuestionProxy.js +0 -34
- package/lib/screenplay/questions/proxies/createQuestionProxy.js.map +0 -1
- package/lib/screenplay/questions/proxies/describePath.d.ts +0 -5
- package/lib/screenplay/questions/proxies/describePath.js +0 -19
- package/lib/screenplay/questions/proxies/describePath.js.map +0 -1
- package/lib/screenplay/questions/proxies/index.d.ts +0 -2
- package/lib/screenplay/questions/proxies/index.js +0 -15
- package/lib/screenplay/questions/proxies/index.js.map +0 -1
- package/lib/screenplay/questions/proxies/key.d.ts +0 -8
- package/lib/screenplay/questions/proxies/key.js +0 -16
- package/lib/screenplay/questions/proxies/key.js.map +0 -1
- package/lib/screenplay/tasks/Loop.d.ts +0 -198
- package/lib/screenplay/tasks/Loop.js +0 -222
- package/lib/screenplay/tasks/Loop.js.map +0 -1
- package/lib/screenplay/tasks/index.d.ts +0 -1
- package/lib/screenplay/tasks/index.js.map +0 -1
- package/src/io/collections/index.ts +0 -2
- package/src/io/collections/mappable.ts +0 -60
- package/src/io/collections/reducible.ts +0 -16
- package/src/screenplay/questions/Property.ts +0 -98
- package/src/screenplay/questions/Transform.ts +0 -51
- package/src/screenplay/questions/lists/ArrayListAdapter.ts +0 -186
- package/src/screenplay/questions/lists/ListAdapter.ts +0 -33
- package/src/screenplay/questions/lists/index.ts +0 -2
- package/src/screenplay/questions/mappings/AnswerMappingFunction.ts +0 -13
- package/src/screenplay/questions/mappings/index.ts +0 -2
- package/src/screenplay/questions/mappings/string/append.ts +0 -28
- package/src/screenplay/questions/mappings/string/index.ts +0 -11
- package/src/screenplay/questions/mappings/string/normalize.ts +0 -33
- package/src/screenplay/questions/mappings/string/replace.ts +0 -34
- package/src/screenplay/questions/mappings/string/slice.ts +0 -53
- package/src/screenplay/questions/mappings/string/split.ts +0 -38
- package/src/screenplay/questions/mappings/string/toLocaleLowerCase.ts +0 -31
- package/src/screenplay/questions/mappings/string/toLocaleUpperCase.ts +0 -30
- package/src/screenplay/questions/mappings/string/toLowerCase.ts +0 -20
- package/src/screenplay/questions/mappings/string/toNumber.ts +0 -19
- package/src/screenplay/questions/mappings/string/toUpperCase.ts +0 -20
- package/src/screenplay/questions/mappings/string/trim.ts +0 -22
- package/src/screenplay/questions/proxies/PropertyPathKey.ts +0 -4
- package/src/screenplay/questions/proxies/createMetaQuestionProxy.ts +0 -51
- package/src/screenplay/questions/proxies/createQuestionProxy.ts +0 -49
- package/src/screenplay/questions/proxies/describePath.ts +0 -23
- package/src/screenplay/questions/proxies/index.ts +0 -2
- package/src/screenplay/questions/proxies/key.ts +0 -14
- package/src/screenplay/tasks/Loop.ts +0 -240
- package/src/screenplay/tasks/index.ts +0 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Note = void 0;
|
|
4
|
+
const io_1 = require("../../io");
|
|
4
5
|
const abilities_1 = require("../abilities");
|
|
5
6
|
const Question_1 = require("../Question");
|
|
6
7
|
/**
|
|
@@ -46,8 +47,9 @@ class Note extends Question_1.Question {
|
|
|
46
47
|
* @param {Question<Promise<Answer>> | Question<Answer> | string} topic
|
|
47
48
|
*/
|
|
48
49
|
constructor(topic) {
|
|
49
|
-
super(
|
|
50
|
+
super();
|
|
50
51
|
this.topic = topic;
|
|
52
|
+
this.subject = (0, io_1.formatted) `a note of ${topic}`;
|
|
51
53
|
}
|
|
52
54
|
/**
|
|
53
55
|
* @desc
|
|
@@ -75,6 +77,20 @@ class Note extends Question_1.Question {
|
|
|
75
77
|
answeredBy(actor) {
|
|
76
78
|
return abilities_1.TakeNotes.as(actor).answerTo(this.topic);
|
|
77
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* @desc
|
|
82
|
+
* Changes the description of this question's subject.
|
|
83
|
+
*
|
|
84
|
+
* @param {string} subject
|
|
85
|
+
* @returns {Question<T>}
|
|
86
|
+
*/
|
|
87
|
+
describedAs(subject) {
|
|
88
|
+
this.subject = subject;
|
|
89
|
+
return this;
|
|
90
|
+
}
|
|
91
|
+
toString() {
|
|
92
|
+
return this.subject;
|
|
93
|
+
}
|
|
78
94
|
}
|
|
79
95
|
exports.Note = Note;
|
|
80
96
|
//# sourceMappingURL=Note.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Note.js","sourceRoot":"","sources":["../../../src/screenplay/questions/Note.ts"],"names":[],"mappings":";;;AAAA,4CAAyC;AAEzC,0CAAuC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAa,IAAa,SAAQ,mBAAyB;
|
|
1
|
+
{"version":3,"file":"Note.js","sourceRoot":"","sources":["../../../src/screenplay/questions/Note.ts"],"names":[],"mappings":";;;AAAA,iCAAqC;AACrC,4CAAyC;AAEzC,0CAAuC;AAEvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAa,IAAa,SAAQ,mBAAyB;IAgBvD;;OAEG;IACH,YAA6B,KAA4D;QACrF,KAAK,EAAE,CAAC;QADiB,UAAK,GAAL,KAAK,CAAuD;QAErF,IAAI,CAAC,OAAO,GAAG,IAAA,cAAS,EAAC,aAAc,KAAM,EAAE,CAAC;IACpD,CAAC;IAlBD;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,CAAI,KAAkD;QAC3D,OAAO,IAAI,IAAI,CAAI,KAAK,CAAC,CAAC;IAC9B,CAAC;IAUD;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,KAAuC;QAC9C,OAAO,qBAAS,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;OAMG;IACH,WAAW,CAAC,OAAe;QACvB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,QAAQ;QACJ,OAAO,IAAI,CAAC,OAAO,CAAC;IACxB,CAAC;CACJ;AAvDD,oBAuDC"}
|
|
@@ -2,9 +2,6 @@ export * from './Check';
|
|
|
2
2
|
export * from './Expectation';
|
|
3
3
|
export * from './expectations';
|
|
4
4
|
export * from './List';
|
|
5
|
-
export * from './mappings';
|
|
6
5
|
export * from './MetaQuestion';
|
|
7
6
|
export * from './Note';
|
|
8
|
-
export { Property } from './Property';
|
|
9
7
|
export * from './q';
|
|
10
|
-
export * from './Transform';
|
|
@@ -10,16 +10,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.Property = void 0;
|
|
14
13
|
__exportStar(require("./Check"), exports);
|
|
15
14
|
__exportStar(require("./Expectation"), exports);
|
|
16
15
|
__exportStar(require("./expectations"), exports);
|
|
17
16
|
__exportStar(require("./List"), exports);
|
|
18
|
-
__exportStar(require("./mappings"), exports);
|
|
19
17
|
__exportStar(require("./MetaQuestion"), exports);
|
|
20
18
|
__exportStar(require("./Note"), exports);
|
|
21
|
-
var Property_1 = require("./Property");
|
|
22
|
-
Object.defineProperty(exports, "Property", { enumerable: true, get: function () { return Property_1.Property; } });
|
|
23
19
|
__exportStar(require("./q"), exports);
|
|
24
|
-
__exportStar(require("./Transform"), exports);
|
|
25
20
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/questions/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/screenplay/questions/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0CAAwB;AACxB,gDAA8B;AAC9B,iDAA+B;AAC/B,yCAAuB;AACvB,iDAA+B;AAC/B,yCAAuB;AACvB,sCAAoB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serenity-js/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-rc.3",
|
|
4
4
|
"description": "Serenity/JS Screenplay, reporting engine and core interfaces.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Jan Molak",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
],
|
|
28
28
|
"scripts": {
|
|
29
29
|
"clean": "rimraf .nyc_output lib target",
|
|
30
|
-
"lint": "eslint --ext ts --config ../../.eslintrc.
|
|
30
|
+
"lint": "eslint --ext ts --config ../../.eslintrc.yml .",
|
|
31
31
|
"lint:fix": "npm run lint -- --fix",
|
|
32
32
|
"test": "nyc --report-dir ../../target/coverage/core mocha --config ../../.mocharc.yml 'spec/**/*.spec.*'",
|
|
33
33
|
"compile": "tsc --project tsconfig.json",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"graceful-fs": "^4.2.8",
|
|
43
43
|
"moment": "^2.29.1",
|
|
44
44
|
"semver": "^7.3.5",
|
|
45
|
-
"tiny-types": "^1.
|
|
45
|
+
"tiny-types": "^1.17.0",
|
|
46
46
|
"upath": "^2.0.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@documentation/esdoc-template": "
|
|
50
|
-
"@types/chai": "^4.
|
|
49
|
+
"@documentation/esdoc-template": "3.0.0",
|
|
50
|
+
"@types/chai": "^4.3.0",
|
|
51
51
|
"@types/cuid": "^1.3.1",
|
|
52
52
|
"@types/diff": "^5.0.1",
|
|
53
53
|
"@types/filenamify": "^2.0.2",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"url": "https://github.com/serenity-js/serenity-js/issues"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
|
-
"node": "^
|
|
70
|
+
"node": "^14 || ^16",
|
|
71
71
|
"npm": "^6 || ^7 || ^8"
|
|
72
72
|
},
|
|
73
73
|
"nyc": {
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"cache": true,
|
|
93
93
|
"all": true
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "69da7444e581c457e29e87edcd910ec06a069338"
|
|
96
96
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './errors';
|
|
2
2
|
export * from './instance';
|
|
3
|
-
export {
|
|
3
|
+
export { format } from './io';
|
|
4
|
+
export { Duration, Timestamp } from './model';
|
|
4
5
|
export * from './screenplay';
|
|
5
6
|
export * from './Serenity';
|
|
6
7
|
export { SerenityConfig } from './SerenityConfig';
|
|
@@ -39,10 +39,14 @@ export class ErrorSerialiser {
|
|
|
39
39
|
];
|
|
40
40
|
|
|
41
41
|
static serialise(error: Error): string {
|
|
42
|
+
const name = error && error.constructor && error.constructor.name
|
|
43
|
+
? error.constructor.name
|
|
44
|
+
: error.name;
|
|
45
|
+
|
|
42
46
|
const serialisedError = Object.getOwnPropertyNames(error).reduce((serialised, key) => {
|
|
43
47
|
serialised[key] = error[key]
|
|
44
48
|
return serialised;
|
|
45
|
-
}, { name
|
|
49
|
+
}, { name }) as SerialisedError;
|
|
46
50
|
|
|
47
51
|
return stringify(serialisedError);
|
|
48
52
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc
|
|
3
|
+
* Maps an Array<Item_Type> to an Array<Result_Type>, one element at a time.
|
|
4
|
+
*
|
|
5
|
+
* @param {Array<Item_Type>} items
|
|
6
|
+
* @param {function(item: Item_Type): Promise<Result_Type>} mappingFunction
|
|
7
|
+
*/
|
|
8
|
+
export function asyncMap<Item_Type, Result_Type>(items: Item_Type[], mappingFunction: (item: Item_Type) => Promise<Result_Type> | Result_Type): Promise<Result_Type[]> {
|
|
9
|
+
return items.reduce(
|
|
10
|
+
(previous, item) =>
|
|
11
|
+
previous.then(async (acc) => {
|
|
12
|
+
const result = await mappingFunction(item);
|
|
13
|
+
|
|
14
|
+
return acc.concat(result);
|
|
15
|
+
})
|
|
16
|
+
, Promise.resolve([])
|
|
17
|
+
);
|
|
18
|
+
}
|
package/src/io/format.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Answerable } from '../screenplay';
|
|
2
|
+
import { inspected } from './inspected';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @desc
|
|
6
|
+
* A factory function returning a tag function that produces a human-readable description of a template containing one or more {@link Answerable}s.
|
|
7
|
+
*
|
|
8
|
+
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import { format, Question } from '@serenity-js/core';
|
|
12
|
+
*
|
|
13
|
+
* const someQuestion = () =>
|
|
14
|
+
* Question.about('some question', actor => 'some value');
|
|
15
|
+
*
|
|
16
|
+
* format({ markQuestions: true }) `actor answers ${ question() }`;
|
|
17
|
+
* // returns: actor answers <<some question>>
|
|
18
|
+
*
|
|
19
|
+
* format({ markQuestions: false }) `actor answers ${ question() }`;
|
|
20
|
+
* // returns: actor answers <<some question>>
|
|
21
|
+
*
|
|
22
|
+
* @example <caption>Aliasing</caption>
|
|
23
|
+
* import { format, Question } from '@serenity-js/core';
|
|
24
|
+
*
|
|
25
|
+
* const f = format({ markQuestions: true });
|
|
26
|
+
*
|
|
27
|
+
* const someQuestion = () =>
|
|
28
|
+
* Question.about('some question', actor => 'some value');
|
|
29
|
+
*
|
|
30
|
+
* f `actor answers ${ question() }`;
|
|
31
|
+
* // produces: actor answers <<some question>>
|
|
32
|
+
*
|
|
33
|
+
* @param {object} config
|
|
34
|
+
* - `markQuestions`: boolean - if set to true, descriptions of questions passed in as arguments will be surrounded with double angled brackets, i.e. `<<description>>`
|
|
35
|
+
* @returns {function(templates: TemplateStringsArray, placeholders: ...Array<Answerable<any>>): string}
|
|
36
|
+
*/
|
|
37
|
+
export function format(config: { markQuestions: boolean }): (templates: TemplateStringsArray, ...placeholders: Array<Answerable<any>>) => string {
|
|
38
|
+
return (templates: TemplateStringsArray, ...placeholders: Array<Answerable<any>>): string => {
|
|
39
|
+
return templates
|
|
40
|
+
.map((template, i) => i < placeholders.length
|
|
41
|
+
? [ template, inspected(placeholders[i], { inline: true, markQuestions: config.markQuestions }) ]
|
|
42
|
+
: [ template ])
|
|
43
|
+
.reduce((acc, tuple) => acc.concat(tuple))
|
|
44
|
+
.join('');
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/io/formatted.ts
CHANGED
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
import { Answerable } from '../screenplay
|
|
2
|
-
import {
|
|
1
|
+
import { Answerable } from '../screenplay';
|
|
2
|
+
import { format } from './format';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* @desc
|
|
6
6
|
* A tag function returning a human-readable description of a template containing one or more {@link Answerable}s.
|
|
7
|
+
* This function is deprecated, please use {@link format} instead.
|
|
7
8
|
*
|
|
8
9
|
* @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#Tagged_template_literals
|
|
9
10
|
*
|
|
11
|
+
*
|
|
12
|
+
* @deprecated
|
|
13
|
+
*
|
|
10
14
|
* @param {TemplateStringsArray} templates
|
|
11
15
|
* @param {Array<Answerable<any>>} placeholders
|
|
12
16
|
* @returns {string}
|
|
13
17
|
*/
|
|
14
18
|
export function formatted(templates: TemplateStringsArray, ...placeholders: Array<Answerable<any>>): string {
|
|
15
|
-
return templates
|
|
16
|
-
.map((template, i) => i < placeholders.length
|
|
17
|
-
? [ template, compacted(inspected(placeholders[i])) ]
|
|
18
|
-
: [ template ])
|
|
19
|
-
.reduce((acc, tuple) => acc.concat(tuple))
|
|
20
|
-
.join('');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/** @private */
|
|
24
|
-
function compacted(multiline: string) {
|
|
25
|
-
return multiline
|
|
26
|
-
.replace(/\r?\n/g, ' ')
|
|
27
|
-
.replace(/\s+/g, ' ');
|
|
19
|
+
return format({ markQuestions: false })(templates, ...placeholders);
|
|
28
20
|
}
|
package/src/io/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './AssertionReportDiffer';
|
|
2
|
-
export * from './
|
|
2
|
+
export * from './asyncMap';
|
|
3
3
|
export * from './commaSeparated';
|
|
4
4
|
export * from './Config';
|
|
5
5
|
export * from './ErrorSerialiser';
|
|
@@ -7,6 +7,7 @@ export * from './ErrorStackParser';
|
|
|
7
7
|
export * from './FileFinder';
|
|
8
8
|
export * from './FileSystem';
|
|
9
9
|
export * from './FileSystemLocation';
|
|
10
|
+
export * from './format';
|
|
10
11
|
export * from './formatted';
|
|
11
12
|
export * from './json';
|
|
12
13
|
export * from './ModuleLoader';
|
package/src/io/inspected.ts
CHANGED
|
@@ -3,6 +3,11 @@ import { inspect } from 'util';
|
|
|
3
3
|
import { Answerable } from '../screenplay/Answerable';
|
|
4
4
|
import { Question } from '../screenplay/Question';
|
|
5
5
|
|
|
6
|
+
interface InspectedConfig {
|
|
7
|
+
inline: boolean;
|
|
8
|
+
markQuestions?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
/**
|
|
7
12
|
* @desc
|
|
8
13
|
* Provides a human-readable description of the {@link Answerable<T>}.
|
|
@@ -10,27 +15,29 @@ import { Question } from '../screenplay/Question';
|
|
|
10
15
|
*
|
|
11
16
|
* @public
|
|
12
17
|
* @param {Answerable<any>} value
|
|
18
|
+
* @param config
|
|
19
|
+
* - inline - Return a single-line string instead of the default potentially multi-line description
|
|
20
|
+
* - markQuestions - Surround the description of async values, such as Promises and Questions with <<value>>
|
|
13
21
|
* @return {string}
|
|
14
22
|
*/
|
|
15
|
-
export function inspected(value: Answerable<any
|
|
23
|
+
export function inspected(value: Answerable<any>, config?: InspectedConfig): string {
|
|
24
|
+
|
|
25
|
+
const { inline, markQuestions } = { inline: false, markQuestions: false, ...config };
|
|
26
|
+
|
|
16
27
|
if (! isDefined(value)) {
|
|
17
28
|
return inspect(value);
|
|
18
29
|
}
|
|
19
30
|
|
|
20
31
|
if (Array.isArray(value)) {
|
|
21
|
-
return
|
|
22
|
-
'[',
|
|
23
|
-
value.map(item => ` ${ inspected(item) }`).join(',\n'),
|
|
24
|
-
']',
|
|
25
|
-
].join('\n');
|
|
32
|
+
return stringifiedArray(value, inline);
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
if (isAPromise(value)) {
|
|
29
|
-
return
|
|
36
|
+
return markAs('Promise', true);
|
|
30
37
|
}
|
|
31
38
|
|
|
32
39
|
if (Question.isAQuestion(value)) {
|
|
33
|
-
return value.toString();
|
|
40
|
+
return markAs(value.toString(), markQuestions);
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
if (isADate(value)) {
|
|
@@ -45,15 +52,49 @@ export function inspected(value: Answerable<any>): string {
|
|
|
45
52
|
return value.inspect();
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
if (
|
|
49
|
-
return
|
|
55
|
+
if (isAFunction(value)) {
|
|
56
|
+
return hasName(value)
|
|
57
|
+
? value.name
|
|
58
|
+
: markAs(`Function`, true);
|
|
50
59
|
}
|
|
51
60
|
|
|
52
61
|
if (! hasCustomInspectionFunction(value) && isPlainObject(value) && isSerialisableAsJSON(value)) {
|
|
53
|
-
return
|
|
62
|
+
return stringifiedToJson(value, inline);
|
|
54
63
|
}
|
|
55
64
|
|
|
56
|
-
return inspect(value, { breakLength: Number.POSITIVE_INFINITY, compact:
|
|
65
|
+
return inspect(value, { breakLength: Number.POSITIVE_INFINITY, compact: inline ? 3 : false, sorted: false });
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function stringifiedToJson(value: any, inline: boolean): string {
|
|
69
|
+
const indentation = inline ? 0 : 4;
|
|
70
|
+
|
|
71
|
+
return JSON.stringify(value, undefined, indentation);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function stringifiedArray(value: any[], inline: boolean): string {
|
|
75
|
+
const indentation = inline ? '' : ' ';
|
|
76
|
+
const separator = inline ? ' ' : '\n';
|
|
77
|
+
|
|
78
|
+
const inspectedItem = (item: unknown, index: number) =>
|
|
79
|
+
[
|
|
80
|
+
indentation,
|
|
81
|
+
inspected(item, { inline, markQuestions: true }),
|
|
82
|
+
index < value.length - 1 ? ',' : ''
|
|
83
|
+
].join('')
|
|
84
|
+
|
|
85
|
+
return [
|
|
86
|
+
'[',
|
|
87
|
+
...value.map(inspectedItem),
|
|
88
|
+
']',
|
|
89
|
+
].join(separator);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function markAs(value: string, markValue: boolean): string {
|
|
93
|
+
const [left, right] = markValue && ! value.startsWith('<<')
|
|
94
|
+
? [ '<<', '>>' ]
|
|
95
|
+
: ['', ''];
|
|
96
|
+
|
|
97
|
+
return [ left, value, right ].join('');
|
|
57
98
|
}
|
|
58
99
|
|
|
59
100
|
/**
|
|
@@ -121,8 +162,19 @@ function isAPromise<T>(v: Answerable<T>): v is Promise<T> {
|
|
|
121
162
|
* @private
|
|
122
163
|
* @param {Answerable<any>} v
|
|
123
164
|
*/
|
|
124
|
-
function
|
|
125
|
-
return Object.prototype.toString.call(v) === '[object Function]'
|
|
165
|
+
function isAFunction(v: any): v is Function { // eslint-disable-line @typescript-eslint/ban-types
|
|
166
|
+
return Object.prototype.toString.call(v) === '[object Function]';
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @desc
|
|
171
|
+
* Checks if the value is has a property called 'name' with a non-empty value.
|
|
172
|
+
*
|
|
173
|
+
* @private
|
|
174
|
+
* @param {Answerable<any>} v
|
|
175
|
+
*/
|
|
176
|
+
function hasName(v: any): v is { name: string } {
|
|
177
|
+
return typeof (v as any).name === 'string' && (v as any).name !== '';
|
|
126
178
|
}
|
|
127
179
|
|
|
128
180
|
/**
|
package/src/model/Timestamp.ts
CHANGED
|
@@ -8,7 +8,11 @@ export class Timestamp extends TinyType {
|
|
|
8
8
|
return new Timestamp(new Date(ensure(Timestamp.name, v, isSerialisedISO8601Date())));
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
static
|
|
11
|
+
static fromTimestampInSeconds(v: number): Timestamp {
|
|
12
|
+
return Timestamp.fromTimestampInMilliseconds(v * 1000);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static fromTimestampInMilliseconds(v: number): Timestamp {
|
|
12
16
|
return new Timestamp(moment(v).toDate());
|
|
13
17
|
}
|
|
14
18
|
|
|
@@ -29,10 +33,14 @@ export class Timestamp extends TinyType {
|
|
|
29
33
|
return new Timestamp(moment(this.value).subtract(duration.inMilliseconds(), 'ms').toDate());
|
|
30
34
|
}
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
toMilliseconds(): number {
|
|
33
37
|
return moment(this.value).valueOf();
|
|
34
38
|
}
|
|
35
39
|
|
|
40
|
+
toSeconds(): number {
|
|
41
|
+
return moment(this.value).unix();
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
toJSON(): string {
|
|
37
45
|
return this.value.toJSON();
|
|
38
46
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { inspected } from '../io/inspected';
|
|
2
2
|
import { AnswersQuestions, UsesAbilities } from './actor';
|
|
3
|
-
import {
|
|
3
|
+
import { Adapter, createAdapter } from './model';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @desc
|
|
@@ -53,15 +53,6 @@ import { AnswerMappingFunction } from './questions/mappings';
|
|
|
53
53
|
*/
|
|
54
54
|
export abstract class Question<T> {
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
* @param {string} subject
|
|
58
|
-
* The subject of this question
|
|
59
|
-
*
|
|
60
|
-
* @protected
|
|
61
|
-
*/
|
|
62
|
-
protected constructor(protected subject: string) {
|
|
63
|
-
}
|
|
64
|
-
|
|
65
56
|
/**
|
|
66
57
|
* @desc
|
|
67
58
|
* Factory method that simplifies the process of defining custom questions.
|
|
@@ -77,8 +68,8 @@ export abstract class Question<T> {
|
|
|
77
68
|
*
|
|
78
69
|
* @returns {Question<R>}
|
|
79
70
|
*/
|
|
80
|
-
static about<R>(description: string, body: (actor: AnswersQuestions & UsesAbilities) => R): Question<R> {
|
|
81
|
-
return new AnonymousQuestion<R>(description, body);
|
|
71
|
+
static about<R>(description: string, body: (actor: AnswersQuestions & UsesAbilities) => R): Question<R> & Adapter<Awaited<R>> {
|
|
72
|
+
return createAdapter<R>(new AnonymousQuestion<R>(description, body));
|
|
82
73
|
}
|
|
83
74
|
|
|
84
75
|
/**
|
|
@@ -102,9 +93,7 @@ export abstract class Question<T> {
|
|
|
102
93
|
*
|
|
103
94
|
* @returns {string}
|
|
104
95
|
*/
|
|
105
|
-
toString(): string
|
|
106
|
-
return this.subject;
|
|
107
|
-
}
|
|
96
|
+
abstract toString(): string;
|
|
108
97
|
|
|
109
98
|
/**
|
|
110
99
|
* @desc
|
|
@@ -113,122 +102,31 @@ export abstract class Question<T> {
|
|
|
113
102
|
* @param {string} subject
|
|
114
103
|
* @returns {Question<T>}
|
|
115
104
|
*/
|
|
116
|
-
describedAs(subject: string): this
|
|
117
|
-
this.subject = subject;
|
|
118
|
-
|
|
119
|
-
return this;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @desc
|
|
124
|
-
* Creates a new {@link Question}, which value is a result of applying the `mapping`
|
|
125
|
-
* function to the value of this {@link Question}.
|
|
126
|
-
*
|
|
127
|
-
* @example <caption>Mapping a Question<Promise<string>> to Question<Promise<number>></caption>
|
|
128
|
-
* import { Question, replace, toNumber } from '@serenity-js/core';
|
|
129
|
-
*
|
|
130
|
-
* Question.about('the price of some item', actor => '$3.99')
|
|
131
|
-
* .map(replace('$', ''))
|
|
132
|
-
* .map(toNumber)
|
|
133
|
-
*
|
|
134
|
-
* // => Question<Promise<number>>
|
|
135
|
-
* // 3.99
|
|
136
|
-
*
|
|
137
|
-
* @example <caption>Mapping all items of Question<string[]> to Question<Promise<number>></caption>
|
|
138
|
-
* import { Question, trim } from '@serenity-js/core';
|
|
139
|
-
*
|
|
140
|
-
* Question.about('things to do', actor => [ ' walk the dog ', ' read a book ' ])
|
|
141
|
-
* .map(trim())
|
|
142
|
-
*
|
|
143
|
-
* // => Question<Promise<string[]>>
|
|
144
|
-
* // [ 'walk the dog', 'read a book' ]
|
|
145
|
-
*
|
|
146
|
-
* @example <caption>Using a custom mapping function</caption>
|
|
147
|
-
* import { Question } from '@serenity-js/core';
|
|
148
|
-
*
|
|
149
|
-
* Question.about('normalised percentages', actor => [ 0.1, 0.3, 0.6 ])
|
|
150
|
-
* .map((actor: AnswersQuestions) => (value: number) => value * 100)
|
|
151
|
-
*
|
|
152
|
-
* // => Question<Promise<number[]>>
|
|
153
|
-
* // [ 10, 30, 60 ]
|
|
154
|
-
*
|
|
155
|
-
* @example <caption>Extracting values from LastResponse.body()</caption>
|
|
156
|
-
* import { Question } from '@serenity-js/core';
|
|
157
|
-
* import { LastResponse } from '@serenity-js/rest';
|
|
158
|
-
*
|
|
159
|
-
* interface UserDetails {
|
|
160
|
-
* id: number;
|
|
161
|
-
* name: string;
|
|
162
|
-
* }
|
|
163
|
-
*
|
|
164
|
-
* LastResponse.body<UserDetails>().map(actor => details => details.id)
|
|
165
|
-
*
|
|
166
|
-
* // => Question<number>
|
|
167
|
-
*
|
|
168
|
-
* @param {function(value: A, index?: number): Promise<O> | O} mapping
|
|
169
|
-
* A mapping function that receives a value of type `<A>`, which is either:
|
|
170
|
-
* - an answer to the original question, if the question is defined as `Question<Promise<A>>` or `Question<A>`
|
|
171
|
-
* - or, if the question is defined as `Question<Promise<Mappable<A>>`, `Question<Mappable<A>>` - each item of the {@link Mappable} collection,
|
|
172
|
-
*
|
|
173
|
-
* @returns {Question<Promise<Mapped>>}
|
|
174
|
-
* A new Question which value is a result of applying the `mapping` function
|
|
175
|
-
* to the value of the current question, so that:
|
|
176
|
-
* - if the answer to the current question is a `Mappable<A>`, the result becomes `Question<Promise<O[]>>`
|
|
177
|
-
* - if the answer is a value `<A>` or `Promise<A>`, the result becomes `Question<Promise<O>>`
|
|
178
|
-
*
|
|
179
|
-
* @see {@link AnswerMappingFunction}
|
|
180
|
-
* @see {@link Mappable}
|
|
181
|
-
*/
|
|
182
|
-
map<O>(mapping: AnswerMappingFunction<AnswerOrItemOfMappableCollection<T>, O>): Question<Promise<Mapped<T, O>>> {
|
|
183
|
-
return Question.about(this.subject, actor =>
|
|
184
|
-
actor.answer(this).then(value =>
|
|
185
|
-
(isMappable(value)
|
|
186
|
-
? Promise.all(((value).map(mapping(actor)) as Array<PromiseLike<O> | O>))
|
|
187
|
-
: mapping(actor)(value as AnswerOrItemOfMappableCollection<T>)
|
|
188
|
-
) as Promise<Mapped<T, O>>
|
|
189
|
-
)
|
|
190
|
-
) as Question<Promise<Mapped<T, O>>>;
|
|
191
|
-
}
|
|
105
|
+
abstract describedAs(subject: string): this;
|
|
192
106
|
|
|
193
107
|
/**
|
|
194
108
|
* @abstract
|
|
109
|
+
* // todo check why api docs are not getting generated for this methods
|
|
195
110
|
*/
|
|
196
111
|
abstract answeredBy(actor: AnswersQuestions & UsesAbilities): T;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* @package
|
|
201
|
-
*/
|
|
202
|
-
type AnswerOrItemOfMappableCollection<V> =
|
|
203
|
-
V extends PromiseLike<infer PromisedValue>
|
|
204
|
-
? PromisedValue extends Mappable<infer Item>
|
|
205
|
-
? Item
|
|
206
|
-
: PromisedValue
|
|
207
|
-
: V extends Mappable<infer Item>
|
|
208
|
-
? Item
|
|
209
|
-
: V;
|
|
210
112
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
: O
|
|
219
|
-
: T extends Mappable<infer Item> // eslint-disable-line @typescript-eslint/no-unused-vars
|
|
220
|
-
? O[]
|
|
221
|
-
: O
|
|
113
|
+
public as<O>(mapping: (answer: Awaited<T>) => Promise<O> | O): Question<Promise<O>> {
|
|
114
|
+
return Question.about<Promise<O>>(`${ this.toString() } as ${ inspected(mapping, { inline: true }) }`, async actor => {
|
|
115
|
+
const answer = (await actor.answer(this)) as Awaited<T>;
|
|
116
|
+
return mapping(answer);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
222
120
|
|
|
223
121
|
/**
|
|
224
122
|
* @package
|
|
225
123
|
*/
|
|
226
124
|
class AnonymousQuestion<T> extends Question<T> {
|
|
227
|
-
constructor(private
|
|
228
|
-
super(
|
|
125
|
+
constructor(private subject: string, private body: (actor: AnswersQuestions & UsesAbilities) => T) {
|
|
126
|
+
super();
|
|
229
127
|
}
|
|
230
128
|
|
|
231
|
-
answeredBy(actor: AnswersQuestions & UsesAbilities) {
|
|
129
|
+
answeredBy(actor: AnswersQuestions & UsesAbilities): T {
|
|
232
130
|
return this.body(actor);
|
|
233
131
|
}
|
|
234
132
|
|
|
@@ -244,4 +142,8 @@ class AnonymousQuestion<T> extends Question<T> {
|
|
|
244
142
|
|
|
245
143
|
return this;
|
|
246
144
|
}
|
|
145
|
+
|
|
146
|
+
toString(): string {
|
|
147
|
+
return this.subject;
|
|
148
|
+
}
|
|
247
149
|
}
|
|
@@ -114,11 +114,11 @@ export class Actor implements
|
|
|
114
114
|
*/
|
|
115
115
|
answer<T>(answerable: Answerable<T>): Promise<T> {
|
|
116
116
|
function isAPromise<V>(v: Answerable<V>): v is Promise<V> {
|
|
117
|
-
return
|
|
117
|
+
return Object.prototype.hasOwnProperty.call(v, 'then');
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
function isDefined<V>(v: Answerable<V>) {
|
|
121
|
-
return ! (
|
|
121
|
+
return ! (v === undefined || v === null);
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
if (isDefined(answerable) && isAPromise(answerable)) {
|
package/src/screenplay/index.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * from './actor';
|
|
|
6
6
|
export * from './Answerable';
|
|
7
7
|
export * from './Interaction';
|
|
8
8
|
export * from './interactions';
|
|
9
|
+
export * from './model';
|
|
9
10
|
export * from './Question';
|
|
10
11
|
export * from './questions';
|
|
11
12
|
export * from './Task';
|
|
12
|
-
export * from './tasks';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Answerable } from '../Answerable';
|
|
2
|
+
import { Interaction } from '../Interaction';
|
|
3
|
+
import { Question } from '../Question';
|
|
4
|
+
|
|
5
|
+
export type Adapter<OriginalType> = {
|
|
6
|
+
[Field in keyof Omit<OriginalType, keyof Question<OriginalType>>]:
|
|
7
|
+
// is it a method?
|
|
8
|
+
OriginalType[Field] extends (...args: infer OriginalParameters) => infer OriginalMethodResult
|
|
9
|
+
// make the method signature asynchronous, accepting Answerables and returning a Promise
|
|
10
|
+
? (...args: { [P in keyof OriginalParameters]: Answerable<OriginalParameters[P]> }) => Question<Promise<Awaited<OriginalMethodResult>>> & Interaction & Adapter<Awaited<OriginalMethodResult>>
|
|
11
|
+
// is it an object? wrap each field
|
|
12
|
+
: Question<Promise<Awaited<OriginalType[Field]>>> & Interaction & Adapter<Awaited<OriginalType[Field]>>
|
|
13
|
+
}
|
|
14
|
+
|