@credo-ts/question-answer 0.6.1-pr-2091-20241119140918 → 0.6.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.
Files changed (118) hide show
  1. package/build/QuestionAnswerApi.d.mts +60 -0
  2. package/build/QuestionAnswerApi.d.mts.map +1 -0
  3. package/build/QuestionAnswerApi.mjs +97 -0
  4. package/build/QuestionAnswerApi.mjs.map +1 -0
  5. package/build/QuestionAnswerEvents.d.mts +19 -0
  6. package/build/QuestionAnswerEvents.d.mts.map +1 -0
  7. package/build/QuestionAnswerEvents.mjs +9 -0
  8. package/build/QuestionAnswerEvents.mjs.map +1 -0
  9. package/build/QuestionAnswerModule.d.mts +15 -0
  10. package/build/QuestionAnswerModule.d.mts.map +1 -0
  11. package/build/QuestionAnswerModule.mjs +38 -0
  12. package/build/QuestionAnswerModule.mjs.map +1 -0
  13. package/build/QuestionAnswerRole.d.mts +8 -0
  14. package/build/QuestionAnswerRole.d.mts.map +1 -0
  15. package/build/QuestionAnswerRole.mjs +10 -0
  16. package/build/QuestionAnswerRole.mjs.map +1 -0
  17. package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs +10 -0
  18. package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs +7 -0
  19. package/build/_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateParam.mjs +9 -0
  20. package/build/handlers/AnswerMessageHandler.mjs +17 -0
  21. package/build/handlers/AnswerMessageHandler.mjs.map +1 -0
  22. package/build/handlers/QuestionMessageHandler.mjs +17 -0
  23. package/build/handlers/QuestionMessageHandler.mjs.map +1 -0
  24. package/build/handlers/index.mjs +2 -0
  25. package/build/index.d.mts +15 -0
  26. package/build/index.mjs +16 -0
  27. package/build/messages/AnswerMessage.d.mts +21 -0
  28. package/build/messages/AnswerMessage.d.mts.map +1 -0
  29. package/build/messages/AnswerMessage.mjs +33 -0
  30. package/build/messages/AnswerMessage.mjs.map +1 -0
  31. package/build/messages/QuestionMessage.d.mts +29 -0
  32. package/build/messages/QuestionMessage.d.mts.map +1 -0
  33. package/build/messages/QuestionMessage.mjs +61 -0
  34. package/build/messages/QuestionMessage.mjs.map +1 -0
  35. package/build/messages/index.d.mts +2 -0
  36. package/build/messages/index.mjs +2 -0
  37. package/build/models/QuestionAnswerState.d.mts +15 -0
  38. package/build/models/QuestionAnswerState.d.mts.map +1 -0
  39. package/build/models/QuestionAnswerState.mjs +17 -0
  40. package/build/models/QuestionAnswerState.mjs.map +1 -0
  41. package/build/models/ValidResponse.d.mts +8 -0
  42. package/build/models/ValidResponse.d.mts.map +1 -0
  43. package/build/models/ValidResponse.mjs +10 -0
  44. package/build/models/ValidResponse.mjs.map +1 -0
  45. package/build/repository/QuestionAnswerRecord.d.mts +53 -0
  46. package/build/repository/QuestionAnswerRecord.d.mts.map +1 -0
  47. package/build/repository/QuestionAnswerRecord.mjs +44 -0
  48. package/build/repository/QuestionAnswerRecord.mjs.map +1 -0
  49. package/build/repository/QuestionAnswerRepository.d.mts +10 -0
  50. package/build/repository/QuestionAnswerRepository.d.mts.map +1 -0
  51. package/build/repository/QuestionAnswerRepository.mjs +22 -0
  52. package/build/repository/QuestionAnswerRepository.mjs.map +1 -0
  53. package/build/repository/index.d.mts +2 -0
  54. package/build/repository/index.mjs +2 -0
  55. package/build/services/QuestionAnswerService.d.mts +116 -0
  56. package/build/services/QuestionAnswerService.d.mts.map +1 -0
  57. package/build/services/QuestionAnswerService.mjs +239 -0
  58. package/build/services/QuestionAnswerService.mjs.map +1 -0
  59. package/build/services/index.d.mts +1 -0
  60. package/build/services/index.mjs +1 -0
  61. package/package.json +16 -15
  62. package/build/QuestionAnswerApi.d.ts +0 -53
  63. package/build/QuestionAnswerApi.js +0 -106
  64. package/build/QuestionAnswerApi.js.map +0 -1
  65. package/build/QuestionAnswerEvents.d.ts +0 -13
  66. package/build/QuestionAnswerEvents.js +0 -8
  67. package/build/QuestionAnswerEvents.js.map +0 -1
  68. package/build/QuestionAnswerModule.d.ts +0 -9
  69. package/build/QuestionAnswerModule.js +0 -29
  70. package/build/QuestionAnswerModule.js.map +0 -1
  71. package/build/QuestionAnswerRole.d.ts +0 -4
  72. package/build/QuestionAnswerRole.js +0 -9
  73. package/build/QuestionAnswerRole.js.map +0 -1
  74. package/build/handlers/AnswerMessageHandler.d.ts +0 -9
  75. package/build/handlers/AnswerMessageHandler.js +0 -15
  76. package/build/handlers/AnswerMessageHandler.js.map +0 -1
  77. package/build/handlers/QuestionMessageHandler.d.ts +0 -9
  78. package/build/handlers/QuestionMessageHandler.js +0 -15
  79. package/build/handlers/QuestionMessageHandler.js.map +0 -1
  80. package/build/handlers/index.d.ts +0 -2
  81. package/build/handlers/index.js +0 -19
  82. package/build/handlers/index.js.map +0 -1
  83. package/build/index.d.ts +0 -8
  84. package/build/index.js +0 -25
  85. package/build/index.js.map +0 -1
  86. package/build/messages/AnswerMessage.d.ts +0 -15
  87. package/build/messages/AnswerMessage.js +0 -42
  88. package/build/messages/AnswerMessage.js.map +0 -1
  89. package/build/messages/QuestionMessage.d.ts +0 -23
  90. package/build/messages/QuestionMessage.js +0 -70
  91. package/build/messages/QuestionMessage.js.map +0 -1
  92. package/build/messages/index.d.ts +0 -2
  93. package/build/messages/index.js +0 -19
  94. package/build/messages/index.js.map +0 -1
  95. package/build/models/QuestionAnswerState.d.ts +0 -11
  96. package/build/models/QuestionAnswerState.js +0 -16
  97. package/build/models/QuestionAnswerState.js.map +0 -1
  98. package/build/models/ValidResponse.d.ts +0 -4
  99. package/build/models/ValidResponse.js +0 -12
  100. package/build/models/ValidResponse.js.map +0 -1
  101. package/build/models/index.d.ts +0 -2
  102. package/build/models/index.js +0 -19
  103. package/build/models/index.js.map +0 -1
  104. package/build/repository/QuestionAnswerRecord.d.ts +0 -48
  105. package/build/repository/QuestionAnswerRecord.js +0 -44
  106. package/build/repository/QuestionAnswerRecord.js.map +0 -1
  107. package/build/repository/QuestionAnswerRepository.d.ts +0 -5
  108. package/build/repository/QuestionAnswerRepository.js +0 -29
  109. package/build/repository/QuestionAnswerRepository.js.map +0 -1
  110. package/build/repository/index.d.ts +0 -2
  111. package/build/repository/index.js +0 -19
  112. package/build/repository/index.js.map +0 -1
  113. package/build/services/QuestionAnswerService.d.ts +0 -107
  114. package/build/services/QuestionAnswerService.js +0 -234
  115. package/build/services/QuestionAnswerService.js.map +0 -1
  116. package/build/services/index.d.ts +0 -1
  117. package/build/services/index.js +0 -18
  118. package/build/services/index.js.map +0 -1
@@ -0,0 +1,17 @@
1
+ //#region src/models/QuestionAnswerState.ts
2
+ /**
3
+ * QuestionAnswer states inferred from RFC 0113.
4
+ *
5
+ * @see https://github.com/hyperledger/aries-rfcs/blob/main/features/0113-question-answer/README.md
6
+ */
7
+ let QuestionAnswerState = /* @__PURE__ */ function(QuestionAnswerState$1) {
8
+ QuestionAnswerState$1["QuestionSent"] = "question-sent";
9
+ QuestionAnswerState$1["QuestionReceived"] = "question-received";
10
+ QuestionAnswerState$1["AnswerReceived"] = "answer-received";
11
+ QuestionAnswerState$1["AnswerSent"] = "answer-sent";
12
+ return QuestionAnswerState$1;
13
+ }({});
14
+
15
+ //#endregion
16
+ export { QuestionAnswerState };
17
+ //# sourceMappingURL=QuestionAnswerState.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionAnswerState.mjs","names":[],"sources":["../../src/models/QuestionAnswerState.ts"],"sourcesContent":["/**\n * QuestionAnswer states inferred from RFC 0113.\n *\n * @see https://github.com/hyperledger/aries-rfcs/blob/main/features/0113-question-answer/README.md\n */\nexport enum QuestionAnswerState {\n QuestionSent = 'question-sent',\n QuestionReceived = 'question-received',\n AnswerReceived = 'answer-received',\n AnswerSent = 'answer-sent',\n}\n"],"mappings":";;;;;;AAKA,IAAY,sEAAL;AACL;AACA;AACA;AACA"}
@@ -0,0 +1,8 @@
1
+ //#region src/models/ValidResponse.d.ts
2
+ declare class ValidResponse {
3
+ constructor(options: ValidResponse);
4
+ text: string;
5
+ }
6
+ //#endregion
7
+ export { ValidResponse };
8
+ //# sourceMappingURL=ValidResponse.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidResponse.d.mts","names":[],"sources":["../../src/models/ValidResponse.ts"],"sourcesContent":[],"mappings":";cAAa,aAAA;EAAA,WAAA,CAAA,OAAa,EACI,aAAA"}
@@ -0,0 +1,10 @@
1
+ //#region src/models/ValidResponse.ts
2
+ var ValidResponse = class {
3
+ constructor(options) {
4
+ if (options) this.text = options.text;
5
+ }
6
+ };
7
+
8
+ //#endregion
9
+ export { ValidResponse };
10
+ //# sourceMappingURL=ValidResponse.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ValidResponse.mjs","names":[],"sources":["../../src/models/ValidResponse.ts"],"sourcesContent":["export class ValidResponse {\n public constructor(options: ValidResponse) {\n if (options) {\n this.text = options.text\n }\n }\n\n public text!: string\n}\n"],"mappings":";AAAA,IAAa,gBAAb,MAA2B;CACzB,AAAO,YAAY,SAAwB;AACzC,MAAI,QACF,MAAK,OAAO,QAAQ"}
@@ -0,0 +1,53 @@
1
+ import { QuestionAnswerState } from "../models/QuestionAnswerState.mjs";
2
+ import { ValidResponse } from "../models/ValidResponse.mjs";
3
+ import { QuestionAnswerRole } from "../QuestionAnswerRole.mjs";
4
+ import { BaseRecord, RecordTags, TagsBase } from "@credo-ts/core";
5
+
6
+ //#region src/repository/QuestionAnswerRecord.d.ts
7
+ type CustomQuestionAnswerTags = TagsBase;
8
+ type DefaultQuestionAnswerTags = {
9
+ connectionId: string;
10
+ role: QuestionAnswerRole;
11
+ state: QuestionAnswerState;
12
+ threadId: string;
13
+ };
14
+ type QuestionAnswerTags = RecordTags<QuestionAnswerRecord>;
15
+ interface QuestionAnswerStorageProps {
16
+ id?: string;
17
+ createdAt?: Date;
18
+ connectionId: string;
19
+ role: QuestionAnswerRole;
20
+ signatureRequired: boolean;
21
+ state: QuestionAnswerState;
22
+ tags?: CustomQuestionAnswerTags;
23
+ threadId: string;
24
+ questionText: string;
25
+ questionDetail?: string;
26
+ validResponses: ValidResponse[];
27
+ response?: string;
28
+ }
29
+ declare class QuestionAnswerRecord extends BaseRecord<DefaultQuestionAnswerTags, CustomQuestionAnswerTags> {
30
+ questionText: string;
31
+ questionDetail?: string;
32
+ validResponses: ValidResponse[];
33
+ connectionId: string;
34
+ role: QuestionAnswerRole;
35
+ signatureRequired: boolean;
36
+ state: QuestionAnswerState;
37
+ threadId: string;
38
+ response?: string;
39
+ static readonly type = "QuestionAnswerRecord";
40
+ readonly type = "QuestionAnswerRecord";
41
+ constructor(props: QuestionAnswerStorageProps);
42
+ getTags(): {
43
+ connectionId: string;
44
+ role: QuestionAnswerRole;
45
+ state: QuestionAnswerState;
46
+ threadId: string;
47
+ };
48
+ assertRole(expectedRole: QuestionAnswerRole): void;
49
+ assertState(expectedStates: QuestionAnswerState | QuestionAnswerState[]): void;
50
+ }
51
+ //#endregion
52
+ export { CustomQuestionAnswerTags, DefaultQuestionAnswerTags, QuestionAnswerRecord, QuestionAnswerStorageProps, QuestionAnswerTags };
53
+ //# sourceMappingURL=QuestionAnswerRecord.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionAnswerRecord.d.mts","names":[],"sources":["../../src/repository/QuestionAnswerRecord.ts"],"sourcesContent":[],"mappings":";;;;;;KAKY,wBAAA,GAA2B;KAC3B,yBAAA;EADA,YAAA,EAAA,MAAA;EACA,IAAA,EAEJ,kBAFI;EAOA,KAAA,EAJH,mBAIqB;EAEb,QAAA,EAAA,MAAA;CAEH;AAEN,KANI,kBAAA,GAAqB,UAMzB,CANoC,oBAMpC,CAAA;AAEC,UANQ,0BAAA,CAMR;EACA,EAAA,CAAA,EAAA,MAAA;EAKS,SAAA,CAAA,EAVJ,IAUI;EAAa,YAAA,EAAA,MAAA;EAKlB,IAAA,EAbL,kBAa0B;EAAmB,iBAAA,EAAA,OAAA;EAA2B,KAAA,EAXvE,mBAWuE;EAGtD,IAAA,CAAA,EAbjB,wBAaiB;EAEV,QAAA,EAAA,MAAA;EAEC,YAAA,EAAA,MAAA;EAOW,cAAA,CAAA,EAAA,MAAA;kBAnBV;;;AAsDmB,cAjDxB,oBAAA,SAA6B,UAiDL,CAjDgB,yBAiDhB,EAjD2C,wBAiD3C,CAAA,CAAA;EAAsB,YAAA,EAAA,MAAA;EAjDjB,cAAA,CAAA,EAAA,MAAA;EAAU,cAAA,EAG1B,aAH0B,EAAA;;QAKpC;;SAEC;;;;;qBAOW;;;;;;;2BA6BM;8BAMG,sBAAsB"}
@@ -0,0 +1,44 @@
1
+ import { BaseRecord, CredoError, utils } from "@credo-ts/core";
2
+
3
+ //#region src/repository/QuestionAnswerRecord.ts
4
+ var QuestionAnswerRecord = class QuestionAnswerRecord extends BaseRecord {
5
+ constructor(props) {
6
+ super();
7
+ this.type = QuestionAnswerRecord.type;
8
+ if (props) {
9
+ this.id = props.id ?? utils.uuid();
10
+ this.createdAt = props.createdAt ?? /* @__PURE__ */ new Date();
11
+ this.questionText = props.questionText;
12
+ this.questionDetail = props.questionDetail;
13
+ this.validResponses = props.validResponses;
14
+ this.connectionId = props.connectionId;
15
+ this._tags = props.tags ?? {};
16
+ this.role = props.role;
17
+ this.signatureRequired = props.signatureRequired;
18
+ this.state = props.state;
19
+ this.threadId = props.threadId;
20
+ this.response = props.response;
21
+ }
22
+ }
23
+ getTags() {
24
+ return {
25
+ ...this._tags,
26
+ connectionId: this.connectionId,
27
+ role: this.role,
28
+ state: this.state,
29
+ threadId: this.threadId
30
+ };
31
+ }
32
+ assertRole(expectedRole) {
33
+ if (this.role !== expectedRole) throw new CredoError(`Invalid question answer record role ${this.role}, expected is ${expectedRole}.`);
34
+ }
35
+ assertState(expectedStates) {
36
+ if (!Array.isArray(expectedStates)) expectedStates = [expectedStates];
37
+ if (!expectedStates.includes(this.state)) throw new CredoError(`Question answer record is in invalid state ${this.state}. Valid states are: ${expectedStates.join(", ")}.`);
38
+ }
39
+ };
40
+ QuestionAnswerRecord.type = "QuestionAnswerRecord";
41
+
42
+ //#endregion
43
+ export { QuestionAnswerRecord };
44
+ //# sourceMappingURL=QuestionAnswerRecord.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionAnswerRecord.mjs","names":[],"sources":["../../src/repository/QuestionAnswerRecord.ts"],"sourcesContent":["import type { RecordTags, TagsBase } from '@credo-ts/core'\nimport { BaseRecord, CredoError, utils } from '@credo-ts/core'\nimport type { QuestionAnswerState, ValidResponse } from '../models'\nimport type { QuestionAnswerRole } from '../QuestionAnswerRole'\n\nexport type CustomQuestionAnswerTags = TagsBase\nexport type DefaultQuestionAnswerTags = {\n connectionId: string\n role: QuestionAnswerRole\n state: QuestionAnswerState\n threadId: string\n}\n\nexport type QuestionAnswerTags = RecordTags<QuestionAnswerRecord>\n\nexport interface QuestionAnswerStorageProps {\n id?: string\n createdAt?: Date\n connectionId: string\n role: QuestionAnswerRole\n signatureRequired: boolean\n state: QuestionAnswerState\n tags?: CustomQuestionAnswerTags\n threadId: string\n\n questionText: string\n questionDetail?: string\n validResponses: ValidResponse[]\n\n response?: string\n}\n\nexport class QuestionAnswerRecord extends BaseRecord<DefaultQuestionAnswerTags, CustomQuestionAnswerTags> {\n public questionText!: string\n public questionDetail?: string\n public validResponses!: ValidResponse[]\n public connectionId!: string\n public role!: QuestionAnswerRole\n public signatureRequired!: boolean\n public state!: QuestionAnswerState\n public threadId!: string\n public response?: string\n\n public static readonly type = 'QuestionAnswerRecord'\n public readonly type = QuestionAnswerRecord.type\n\n public constructor(props: QuestionAnswerStorageProps) {\n super()\n\n if (props) {\n this.id = props.id ?? utils.uuid()\n this.createdAt = props.createdAt ?? new Date()\n this.questionText = props.questionText\n this.questionDetail = props.questionDetail\n this.validResponses = props.validResponses\n this.connectionId = props.connectionId\n this._tags = props.tags ?? {}\n this.role = props.role\n this.signatureRequired = props.signatureRequired\n this.state = props.state\n this.threadId = props.threadId\n this.response = props.response\n }\n }\n\n public getTags() {\n return {\n ...this._tags,\n connectionId: this.connectionId,\n role: this.role,\n state: this.state,\n threadId: this.threadId,\n }\n }\n\n public assertRole(expectedRole: QuestionAnswerRole) {\n if (this.role !== expectedRole) {\n throw new CredoError(`Invalid question answer record role ${this.role}, expected is ${expectedRole}.`)\n }\n }\n\n public assertState(expectedStates: QuestionAnswerState | QuestionAnswerState[]) {\n if (!Array.isArray(expectedStates)) {\n expectedStates = [expectedStates]\n }\n\n if (!expectedStates.includes(this.state)) {\n throw new CredoError(\n `Question answer record is in invalid state ${this.state}. Valid states are: ${expectedStates.join(', ')}.`\n )\n }\n }\n}\n"],"mappings":";;;AAgCA,IAAa,uBAAb,MAAa,6BAA6B,WAAgE;CAcxG,AAAO,YAAY,OAAmC;AACpD,SAAO;OAHO,OAAO,qBAAqB;AAK1C,MAAI,OAAO;AACT,QAAK,KAAK,MAAM,MAAM,MAAM,MAAM;AAClC,QAAK,YAAY,MAAM,6BAAa,IAAI,MAAM;AAC9C,QAAK,eAAe,MAAM;AAC1B,QAAK,iBAAiB,MAAM;AAC5B,QAAK,iBAAiB,MAAM;AAC5B,QAAK,eAAe,MAAM;AAC1B,QAAK,QAAQ,MAAM,QAAQ,EAAE;AAC7B,QAAK,OAAO,MAAM;AAClB,QAAK,oBAAoB,MAAM;AAC/B,QAAK,QAAQ,MAAM;AACnB,QAAK,WAAW,MAAM;AACtB,QAAK,WAAW,MAAM;;;CAI1B,AAAO,UAAU;AACf,SAAO;GACL,GAAG,KAAK;GACR,cAAc,KAAK;GACnB,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,UAAU,KAAK;GAChB;;CAGH,AAAO,WAAW,cAAkC;AAClD,MAAI,KAAK,SAAS,aAChB,OAAM,IAAI,WAAW,uCAAuC,KAAK,KAAK,gBAAgB,aAAa,GAAG;;CAI1G,AAAO,YAAY,gBAA6D;AAC9E,MAAI,CAAC,MAAM,QAAQ,eAAe,CAChC,kBAAiB,CAAC,eAAe;AAGnC,MAAI,CAAC,eAAe,SAAS,KAAK,MAAM,CACtC,OAAM,IAAI,WACR,8CAA8C,KAAK,MAAM,sBAAsB,eAAe,KAAK,KAAK,CAAC,GAC1G;;;qBA9CkB,OAAO"}
@@ -0,0 +1,10 @@
1
+ import { QuestionAnswerRecord } from "./QuestionAnswerRecord.mjs";
2
+ import { EventEmitter, Repository, StorageService } from "@credo-ts/core";
3
+
4
+ //#region src/repository/QuestionAnswerRepository.d.ts
5
+ declare class QuestionAnswerRepository extends Repository<QuestionAnswerRecord> {
6
+ constructor(storageService: StorageService<QuestionAnswerRecord>, eventEmitter: EventEmitter);
7
+ }
8
+ //#endregion
9
+ export { QuestionAnswerRepository };
10
+ //# sourceMappingURL=QuestionAnswerRepository.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionAnswerRepository.d.mts","names":[],"sources":["../../src/repository/QuestionAnswerRepository.ts"],"sourcesContent":[],"mappings":";;;;cAKa,wBAAA,SAAiC,WAAW;8BAEI,eAAe,qCAC1D;AAJlB"}
@@ -0,0 +1,22 @@
1
+ import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
2
+ import { __decorate } from "../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
3
+ import { QuestionAnswerRecord } from "./QuestionAnswerRecord.mjs";
4
+ import { __decorateParam } from "../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateParam.mjs";
5
+ import { EventEmitter, InjectionSymbols, Repository, inject, injectable } from "@credo-ts/core";
6
+
7
+ //#region src/repository/QuestionAnswerRepository.ts
8
+ var _ref;
9
+ let QuestionAnswerRepository = class QuestionAnswerRepository$1 extends Repository {
10
+ constructor(storageService, eventEmitter) {
11
+ super(QuestionAnswerRecord, storageService, eventEmitter);
12
+ }
13
+ };
14
+ QuestionAnswerRepository = __decorate([
15
+ injectable(),
16
+ __decorateParam(0, inject(InjectionSymbols.StorageService)),
17
+ __decorateMetadata("design:paramtypes", [Object, typeof (_ref = typeof EventEmitter !== "undefined" && EventEmitter) === "function" ? _ref : Object])
18
+ ], QuestionAnswerRepository);
19
+
20
+ //#endregion
21
+ export { QuestionAnswerRepository };
22
+ //# sourceMappingURL=QuestionAnswerRepository.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionAnswerRepository.mjs","names":["QuestionAnswerRepository","storageService: StorageService<QuestionAnswerRecord>"],"sources":["../../src/repository/QuestionAnswerRepository.ts"],"sourcesContent":["import { EventEmitter, InjectionSymbols, inject, injectable, Repository, type StorageService } from '@credo-ts/core'\n\nimport { QuestionAnswerRecord } from './QuestionAnswerRecord'\n\n@injectable()\nexport class QuestionAnswerRepository extends Repository<QuestionAnswerRecord> {\n public constructor(\n @inject(InjectionSymbols.StorageService) storageService: StorageService<QuestionAnswerRecord>,\n eventEmitter: EventEmitter\n ) {\n super(QuestionAnswerRecord, storageService, eventEmitter)\n }\n}\n"],"mappings":";;;;;;;;AAKO,qCAAMA,mCAAiC,WAAiC;CAC7E,AAAO,YACL,AAAyCC,gBACzC,cACA;AACA,QAAM,sBAAsB,gBAAgB,aAAa;;;;CAN5D,YAAY;oBAGR,OAAO,iBAAiB,eAAe"}
@@ -0,0 +1,2 @@
1
+ import { CustomQuestionAnswerTags, DefaultQuestionAnswerTags, QuestionAnswerRecord, QuestionAnswerStorageProps, QuestionAnswerTags } from "./QuestionAnswerRecord.mjs";
2
+ import { QuestionAnswerRepository } from "./QuestionAnswerRepository.mjs";
@@ -0,0 +1,2 @@
1
+ import { QuestionAnswerRecord } from "./QuestionAnswerRecord.mjs";
2
+ import { QuestionAnswerRepository } from "./QuestionAnswerRepository.mjs";
@@ -0,0 +1,116 @@
1
+ import { AnswerMessage } from "../messages/AnswerMessage.mjs";
2
+ import { ValidResponse } from "../models/ValidResponse.mjs";
3
+ import { QuestionMessage } from "../messages/QuestionMessage.mjs";
4
+ import "../messages/index.mjs";
5
+ import { QuestionAnswerRecord } from "../repository/QuestionAnswerRecord.mjs";
6
+ import { QuestionAnswerRepository } from "../repository/QuestionAnswerRepository.mjs";
7
+ import "../repository/index.mjs";
8
+ import { DidCommInboundMessageContext } from "@credo-ts/didcomm";
9
+ import { AgentContext, EventEmitter, Logger, Query, QueryOptions } from "@credo-ts/core";
10
+
11
+ //#region src/services/QuestionAnswerService.d.ts
12
+ declare class QuestionAnswerService {
13
+ private questionAnswerRepository;
14
+ private eventEmitter;
15
+ private logger;
16
+ constructor(questionAnswerRepository: QuestionAnswerRepository, eventEmitter: EventEmitter, logger: Logger);
17
+ /**
18
+ * Create a question message and a new QuestionAnswer record for the questioner role
19
+ *
20
+ * @param question text for question message
21
+ * @param details optional details for question message
22
+ * @param connectionId connection for QuestionAnswer record
23
+ * @param validResponses array of valid responses for question
24
+ * @returns question message and QuestionAnswer record
25
+ */
26
+ createQuestion(agentContext: AgentContext, connectionId: string, config: {
27
+ question: string;
28
+ validResponses: ValidResponse[];
29
+ detail?: string;
30
+ }): Promise<{
31
+ questionMessage: QuestionMessage;
32
+ questionAnswerRecord: QuestionAnswerRecord;
33
+ }>;
34
+ /**
35
+ * receive question message and create record for responder role
36
+ *
37
+ * @param messageContext the message context containing a question message
38
+ * @returns QuestionAnswer record
39
+ */
40
+ processReceiveQuestion(messageContext: DidCommInboundMessageContext<QuestionMessage>): Promise<QuestionAnswerRecord>;
41
+ /**
42
+ * create answer message, check that response is valid
43
+ *
44
+ * @param questionAnswerRecord record containing question and valid responses
45
+ * @param response response used in answer message
46
+ * @returns answer message and QuestionAnswer record
47
+ */
48
+ createAnswer(agentContext: AgentContext, questionAnswerRecord: QuestionAnswerRecord, response: string): Promise<{
49
+ answerMessage: AnswerMessage;
50
+ questionAnswerRecord: QuestionAnswerRecord;
51
+ }>;
52
+ /**
53
+ * receive answer as questioner
54
+ *
55
+ * @param messageContext the message context containing an answer message message
56
+ * @returns QuestionAnswer record
57
+ */
58
+ receiveAnswer(messageContext: DidCommInboundMessageContext<AnswerMessage>): Promise<QuestionAnswerRecord>;
59
+ /**
60
+ * Update the record to a new state and emit an state changed event. Also updates the record
61
+ * in storage.
62
+ *
63
+ * @param questionAnswerRecord The question answer record to update the state for
64
+ * @param newState The state to update to
65
+ *
66
+ */
67
+ private updateState;
68
+ private createRecord;
69
+ /**
70
+ * Retrieve a question answer record by connection id and thread id
71
+ *
72
+ * @param connectionId The connection id
73
+ * @param threadId The thread id
74
+ * @throws {RecordNotFoundError} If no record is found
75
+ * @throws {RecordDuplicateError} If multiple records are found
76
+ * @returns The question answer record
77
+ */
78
+ getByThreadAndConnectionId(agentContext: AgentContext, connectionId: string, threadId: string): Promise<QuestionAnswerRecord>;
79
+ /**
80
+ * Retrieve a question answer record by thread id
81
+ *
82
+ * @param connectionId The connection id
83
+ * @param threadId The thread id
84
+ * @returns The question answer record or null if not found
85
+ */
86
+ findByThreadAndConnectionId(agentContext: AgentContext, connectionId: string, threadId: string): Promise<QuestionAnswerRecord | null>;
87
+ /**
88
+ * Retrieve a question answer record by id
89
+ *
90
+ * @param questionAnswerId The questionAnswer record id
91
+ * @throws {RecordNotFoundError} If no record is found
92
+ * @return The question answer record
93
+ *
94
+ */
95
+ getById(agentContext: AgentContext, questionAnswerId: string): Promise<QuestionAnswerRecord>;
96
+ /**
97
+ * Retrieve a question answer record by id
98
+ *
99
+ * @param questionAnswerId The questionAnswer record id
100
+ * @return The question answer record or null if not found
101
+ *
102
+ */
103
+ findById(agentContext: AgentContext, questionAnswerId: string): Promise<QuestionAnswerRecord | null>;
104
+ /**
105
+ * Retrieve a question answer record by id
106
+ *
107
+ * @param questionAnswerId The questionAnswer record id
108
+ * @return The question answer record or null if not found
109
+ *
110
+ */
111
+ getAll(agentContext: AgentContext): Promise<QuestionAnswerRecord[]>;
112
+ findAllByQuery(agentContext: AgentContext, query: Query<QuestionAnswerRecord>, queryOptions?: QueryOptions): Promise<QuestionAnswerRecord[]>;
113
+ }
114
+ //#endregion
115
+ export { QuestionAnswerService };
116
+ //# sourceMappingURL=QuestionAnswerService.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionAnswerService.d.mts","names":[],"sources":["../../src/services/QuestionAnswerService.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;cAYa,qBAAA;;;;wCAMiB,wCACZ,sBAC2B;EARhC;;;;;;;;;EAmEoC,cAAA,CAAA,YAAA,EA3C/B,YA2C+B,EAAA,YAAA,EAAA,MAAA,EAAA,MAAA,EAAA;IAA7B,QAAA,EAAA,MAAA;IACP,cAAA,EAxCS,aAwCT,EAAA;IAAR,MAAA,CAAA,EAAA,MAAA;EA0CqC,CAAA,CAAA,EAhFrC,OAgFqC,CAAA;IAAoC,eAAA,iBAAA;;;EAAsC;;;;;;EA8GvG,sBAAA,CAAA,cAAA,EAzJO,4BAyJP,CAzJoC,eAyJpC,CAAA,CAAA,EAxJR,OAwJQ,CAxJA,oBAwJA,CAAA;EAAR;;;;;;;EA4C2B,YAAA,CAAA,YAAA,EA1JU,YA0JV,EAAA,oBAAA,EA1J8C,oBA0J9C,EAAA,QAAA,EAAA,MAAA,CAAA,EA1JoF,OA0JpF,CAAA;IAAiD,aAAA,eAAA;IAAR,oBAAA,sBAAA;EAW3C,CAAA,CAAA;EAAY;;;;;;EAOX,aAAA,CAAA,cAAA,EAtJX,4BAsJW,CAtJkB,aAsJlB,CAAA,CAAA,EArJ1B,OAqJ0B,CArJlB,oBAqJkB,CAAA;EAAA;;;;;;;;;;;;;;;;;;;2CAjEb,uDAGb,QAAQ;;;;;;;;4CAeK,uDAGb,QAAQ;;;;;;;;;wBAekB,yCAAyC,QAAQ;;;;;;;;yBAWhD,yCAAyC,QAAQ;;;;;;;;uBAWnD,eAAY,QAAA;+BAKxB,qBACP,MAAM,sCACE,eAAY,QAAA"}
@@ -0,0 +1,239 @@
1
+ import { __decorateMetadata } from "../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateMetadata.mjs";
2
+ import { __decorate } from "../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorate.mjs";
3
+ import { AnswerMessage } from "../messages/AnswerMessage.mjs";
4
+ import { QuestionAnswerState } from "../models/QuestionAnswerState.mjs";
5
+ import { QuestionMessage } from "../messages/QuestionMessage.mjs";
6
+ import "../messages/index.mjs";
7
+ import { QuestionAnswerEventTypes } from "../QuestionAnswerEvents.mjs";
8
+ import { QuestionAnswerRole } from "../QuestionAnswerRole.mjs";
9
+ import { QuestionAnswerRecord } from "../repository/QuestionAnswerRecord.mjs";
10
+ import { __decorateParam } from "../_virtual/_@oxc-project_runtime@0.99.0/helpers/decorateParam.mjs";
11
+ import { QuestionAnswerRepository } from "../repository/QuestionAnswerRepository.mjs";
12
+ import "../repository/index.mjs";
13
+ import { CredoError, EventEmitter, InjectionSymbols, inject, injectable } from "@credo-ts/core";
14
+
15
+ //#region src/services/QuestionAnswerService.ts
16
+ var _ref, _ref2;
17
+ let QuestionAnswerService = class QuestionAnswerService$1 {
18
+ constructor(questionAnswerRepository, eventEmitter, logger) {
19
+ this.questionAnswerRepository = questionAnswerRepository;
20
+ this.eventEmitter = eventEmitter;
21
+ this.logger = logger;
22
+ }
23
+ /**
24
+ * Create a question message and a new QuestionAnswer record for the questioner role
25
+ *
26
+ * @param question text for question message
27
+ * @param details optional details for question message
28
+ * @param connectionId connection for QuestionAnswer record
29
+ * @param validResponses array of valid responses for question
30
+ * @returns question message and QuestionAnswer record
31
+ */
32
+ async createQuestion(agentContext, connectionId, config) {
33
+ const questionMessage = new QuestionMessage({
34
+ questionText: config.question,
35
+ questionDetail: config?.detail,
36
+ signatureRequired: false,
37
+ validResponses: config.validResponses
38
+ });
39
+ const questionAnswerRecord = await this.createRecord({
40
+ questionText: questionMessage.questionText,
41
+ questionDetail: questionMessage.questionDetail,
42
+ threadId: questionMessage.threadId,
43
+ connectionId,
44
+ role: QuestionAnswerRole.Questioner,
45
+ signatureRequired: false,
46
+ state: QuestionAnswerState.QuestionSent,
47
+ validResponses: questionMessage.validResponses
48
+ });
49
+ await this.questionAnswerRepository.save(agentContext, questionAnswerRecord);
50
+ this.eventEmitter.emit(agentContext, {
51
+ type: QuestionAnswerEventTypes.QuestionAnswerStateChanged,
52
+ payload: {
53
+ previousState: null,
54
+ questionAnswerRecord
55
+ }
56
+ });
57
+ return {
58
+ questionMessage,
59
+ questionAnswerRecord
60
+ };
61
+ }
62
+ /**
63
+ * receive question message and create record for responder role
64
+ *
65
+ * @param messageContext the message context containing a question message
66
+ * @returns QuestionAnswer record
67
+ */
68
+ async processReceiveQuestion(messageContext) {
69
+ const { message: questionMessage } = messageContext;
70
+ this.logger.debug(`Receiving question message with id ${questionMessage.id}`);
71
+ const connection = messageContext.assertReadyConnection();
72
+ if (await this.findByThreadAndConnectionId(messageContext.agentContext, connection.id, questionMessage.id)) throw new CredoError(`Question answer record with thread Id ${questionMessage.id} already exists.`);
73
+ const questionAnswerRecord = await this.createRecord({
74
+ questionText: questionMessage.questionText,
75
+ questionDetail: questionMessage.questionDetail,
76
+ connectionId: connection?.id,
77
+ threadId: questionMessage.threadId,
78
+ role: QuestionAnswerRole.Responder,
79
+ signatureRequired: false,
80
+ state: QuestionAnswerState.QuestionReceived,
81
+ validResponses: questionMessage.validResponses
82
+ });
83
+ await this.questionAnswerRepository.save(messageContext.agentContext, questionAnswerRecord);
84
+ this.eventEmitter.emit(messageContext.agentContext, {
85
+ type: QuestionAnswerEventTypes.QuestionAnswerStateChanged,
86
+ payload: {
87
+ previousState: null,
88
+ questionAnswerRecord
89
+ }
90
+ });
91
+ return questionAnswerRecord;
92
+ }
93
+ /**
94
+ * create answer message, check that response is valid
95
+ *
96
+ * @param questionAnswerRecord record containing question and valid responses
97
+ * @param response response used in answer message
98
+ * @returns answer message and QuestionAnswer record
99
+ */
100
+ async createAnswer(agentContext, questionAnswerRecord, response) {
101
+ const answerMessage = new AnswerMessage({
102
+ response,
103
+ threadId: questionAnswerRecord.threadId
104
+ });
105
+ questionAnswerRecord.assertState(QuestionAnswerState.QuestionReceived);
106
+ questionAnswerRecord.response = response;
107
+ if (questionAnswerRecord.validResponses.some((e) => e.text === response)) await this.updateState(agentContext, questionAnswerRecord, QuestionAnswerState.AnswerSent);
108
+ else throw new CredoError("Response does not match valid responses");
109
+ return {
110
+ answerMessage,
111
+ questionAnswerRecord
112
+ };
113
+ }
114
+ /**
115
+ * receive answer as questioner
116
+ *
117
+ * @param messageContext the message context containing an answer message message
118
+ * @returns QuestionAnswer record
119
+ */
120
+ async receiveAnswer(messageContext) {
121
+ const { message: answerMessage } = messageContext;
122
+ this.logger.debug(`Receiving answer message with id ${answerMessage.id}`);
123
+ const connection = messageContext.assertReadyConnection();
124
+ const questionAnswerRecord = await this.findByThreadAndConnectionId(messageContext.agentContext, connection.id, answerMessage.threadId);
125
+ if (!questionAnswerRecord) throw new CredoError(`Question Answer record with thread Id ${answerMessage.threadId} not found.`);
126
+ questionAnswerRecord.assertState(QuestionAnswerState.QuestionSent);
127
+ questionAnswerRecord.assertRole(QuestionAnswerRole.Questioner);
128
+ questionAnswerRecord.response = answerMessage.response;
129
+ await this.updateState(messageContext.agentContext, questionAnswerRecord, QuestionAnswerState.AnswerReceived);
130
+ return questionAnswerRecord;
131
+ }
132
+ /**
133
+ * Update the record to a new state and emit an state changed event. Also updates the record
134
+ * in storage.
135
+ *
136
+ * @param questionAnswerRecord The question answer record to update the state for
137
+ * @param newState The state to update to
138
+ *
139
+ */
140
+ async updateState(agentContext, questionAnswerRecord, newState) {
141
+ const previousState = questionAnswerRecord.state;
142
+ questionAnswerRecord.state = newState;
143
+ await this.questionAnswerRepository.update(agentContext, questionAnswerRecord);
144
+ this.eventEmitter.emit(agentContext, {
145
+ type: QuestionAnswerEventTypes.QuestionAnswerStateChanged,
146
+ payload: {
147
+ previousState,
148
+ questionAnswerRecord
149
+ }
150
+ });
151
+ }
152
+ async createRecord(options) {
153
+ return new QuestionAnswerRecord({
154
+ questionText: options.questionText,
155
+ questionDetail: options.questionDetail,
156
+ connectionId: options.connectionId,
157
+ threadId: options.threadId,
158
+ role: options.role,
159
+ signatureRequired: options.signatureRequired,
160
+ state: options.state,
161
+ validResponses: options.validResponses
162
+ });
163
+ }
164
+ /**
165
+ * Retrieve a question answer record by connection id and thread id
166
+ *
167
+ * @param connectionId The connection id
168
+ * @param threadId The thread id
169
+ * @throws {RecordNotFoundError} If no record is found
170
+ * @throws {RecordDuplicateError} If multiple records are found
171
+ * @returns The question answer record
172
+ */
173
+ getByThreadAndConnectionId(agentContext, connectionId, threadId) {
174
+ return this.questionAnswerRepository.getSingleByQuery(agentContext, {
175
+ connectionId,
176
+ threadId
177
+ });
178
+ }
179
+ /**
180
+ * Retrieve a question answer record by thread id
181
+ *
182
+ * @param connectionId The connection id
183
+ * @param threadId The thread id
184
+ * @returns The question answer record or null if not found
185
+ */
186
+ findByThreadAndConnectionId(agentContext, connectionId, threadId) {
187
+ return this.questionAnswerRepository.findSingleByQuery(agentContext, {
188
+ connectionId,
189
+ threadId
190
+ });
191
+ }
192
+ /**
193
+ * Retrieve a question answer record by id
194
+ *
195
+ * @param questionAnswerId The questionAnswer record id
196
+ * @throws {RecordNotFoundError} If no record is found
197
+ * @return The question answer record
198
+ *
199
+ */
200
+ getById(agentContext, questionAnswerId) {
201
+ return this.questionAnswerRepository.getById(agentContext, questionAnswerId);
202
+ }
203
+ /**
204
+ * Retrieve a question answer record by id
205
+ *
206
+ * @param questionAnswerId The questionAnswer record id
207
+ * @return The question answer record or null if not found
208
+ *
209
+ */
210
+ findById(agentContext, questionAnswerId) {
211
+ return this.questionAnswerRepository.findById(agentContext, questionAnswerId);
212
+ }
213
+ /**
214
+ * Retrieve a question answer record by id
215
+ *
216
+ * @param questionAnswerId The questionAnswer record id
217
+ * @return The question answer record or null if not found
218
+ *
219
+ */
220
+ getAll(agentContext) {
221
+ return this.questionAnswerRepository.getAll(agentContext);
222
+ }
223
+ async findAllByQuery(agentContext, query, queryOptions) {
224
+ return this.questionAnswerRepository.findByQuery(agentContext, query, queryOptions);
225
+ }
226
+ };
227
+ QuestionAnswerService = __decorate([
228
+ injectable(),
229
+ __decorateParam(2, inject(InjectionSymbols.Logger)),
230
+ __decorateMetadata("design:paramtypes", [
231
+ typeof (_ref = typeof QuestionAnswerRepository !== "undefined" && QuestionAnswerRepository) === "function" ? _ref : Object,
232
+ typeof (_ref2 = typeof EventEmitter !== "undefined" && EventEmitter) === "function" ? _ref2 : Object,
233
+ Object
234
+ ])
235
+ ], QuestionAnswerService);
236
+
237
+ //#endregion
238
+ export { QuestionAnswerService };
239
+ //# sourceMappingURL=QuestionAnswerService.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QuestionAnswerService.mjs","names":["QuestionAnswerService","logger: Logger"],"sources":["../../src/services/QuestionAnswerService.ts"],"sourcesContent":["import type { AgentContext, Query, QueryOptions } from '@credo-ts/core'\nimport { CredoError, EventEmitter, InjectionSymbols, inject, injectable, type Logger } from '@credo-ts/core'\nimport type { DidCommInboundMessageContext } from '@credo-ts/didcomm'\nimport { AnswerMessage, QuestionMessage } from '../messages'\nimport type { ValidResponse } from '../models'\nimport { QuestionAnswerState } from '../models'\nimport type { QuestionAnswerStateChangedEvent } from '../QuestionAnswerEvents'\nimport { QuestionAnswerEventTypes } from '../QuestionAnswerEvents'\nimport { QuestionAnswerRole } from '../QuestionAnswerRole'\nimport { QuestionAnswerRecord, QuestionAnswerRepository } from '../repository'\n\n@injectable()\nexport class QuestionAnswerService {\n private questionAnswerRepository: QuestionAnswerRepository\n private eventEmitter: EventEmitter\n private logger: Logger\n\n public constructor(\n questionAnswerRepository: QuestionAnswerRepository,\n eventEmitter: EventEmitter,\n @inject(InjectionSymbols.Logger) logger: Logger\n ) {\n this.questionAnswerRepository = questionAnswerRepository\n this.eventEmitter = eventEmitter\n this.logger = logger\n }\n /**\n * Create a question message and a new QuestionAnswer record for the questioner role\n *\n * @param question text for question message\n * @param details optional details for question message\n * @param connectionId connection for QuestionAnswer record\n * @param validResponses array of valid responses for question\n * @returns question message and QuestionAnswer record\n */\n public async createQuestion(\n agentContext: AgentContext,\n connectionId: string,\n config: {\n question: string\n validResponses: ValidResponse[]\n detail?: string\n }\n ) {\n const questionMessage = new QuestionMessage({\n questionText: config.question,\n questionDetail: config?.detail,\n signatureRequired: false,\n validResponses: config.validResponses,\n })\n\n const questionAnswerRecord = await this.createRecord({\n questionText: questionMessage.questionText,\n questionDetail: questionMessage.questionDetail,\n threadId: questionMessage.threadId,\n connectionId: connectionId,\n role: QuestionAnswerRole.Questioner,\n signatureRequired: false,\n state: QuestionAnswerState.QuestionSent,\n validResponses: questionMessage.validResponses,\n })\n\n await this.questionAnswerRepository.save(agentContext, questionAnswerRecord)\n\n this.eventEmitter.emit<QuestionAnswerStateChangedEvent>(agentContext, {\n type: QuestionAnswerEventTypes.QuestionAnswerStateChanged,\n payload: { previousState: null, questionAnswerRecord },\n })\n\n return { questionMessage, questionAnswerRecord }\n }\n\n /**\n * receive question message and create record for responder role\n *\n * @param messageContext the message context containing a question message\n * @returns QuestionAnswer record\n */\n public async processReceiveQuestion(\n messageContext: DidCommInboundMessageContext<QuestionMessage>\n ): Promise<QuestionAnswerRecord> {\n const { message: questionMessage } = messageContext\n\n this.logger.debug(`Receiving question message with id ${questionMessage.id}`)\n\n const connection = messageContext.assertReadyConnection()\n const questionRecord = await this.findByThreadAndConnectionId(\n messageContext.agentContext,\n connection.id,\n questionMessage.id\n )\n if (questionRecord) {\n throw new CredoError(`Question answer record with thread Id ${questionMessage.id} already exists.`)\n }\n const questionAnswerRecord = await this.createRecord({\n questionText: questionMessage.questionText,\n questionDetail: questionMessage.questionDetail,\n connectionId: connection?.id,\n threadId: questionMessage.threadId,\n role: QuestionAnswerRole.Responder,\n signatureRequired: false,\n state: QuestionAnswerState.QuestionReceived,\n validResponses: questionMessage.validResponses,\n })\n\n await this.questionAnswerRepository.save(messageContext.agentContext, questionAnswerRecord)\n\n this.eventEmitter.emit<QuestionAnswerStateChangedEvent>(messageContext.agentContext, {\n type: QuestionAnswerEventTypes.QuestionAnswerStateChanged,\n payload: { previousState: null, questionAnswerRecord },\n })\n\n return questionAnswerRecord\n }\n\n /**\n * create answer message, check that response is valid\n *\n * @param questionAnswerRecord record containing question and valid responses\n * @param response response used in answer message\n * @returns answer message and QuestionAnswer record\n */\n public async createAnswer(agentContext: AgentContext, questionAnswerRecord: QuestionAnswerRecord, response: string) {\n const answerMessage = new AnswerMessage({ response: response, threadId: questionAnswerRecord.threadId })\n\n questionAnswerRecord.assertState(QuestionAnswerState.QuestionReceived)\n\n questionAnswerRecord.response = response\n\n if (questionAnswerRecord.validResponses.some((e) => e.text === response)) {\n await this.updateState(agentContext, questionAnswerRecord, QuestionAnswerState.AnswerSent)\n } else {\n throw new CredoError('Response does not match valid responses')\n }\n return { answerMessage, questionAnswerRecord }\n }\n\n /**\n * receive answer as questioner\n *\n * @param messageContext the message context containing an answer message message\n * @returns QuestionAnswer record\n */\n public async receiveAnswer(\n messageContext: DidCommInboundMessageContext<AnswerMessage>\n ): Promise<QuestionAnswerRecord> {\n const { message: answerMessage } = messageContext\n\n this.logger.debug(`Receiving answer message with id ${answerMessage.id}`)\n\n const connection = messageContext.assertReadyConnection()\n const questionAnswerRecord = await this.findByThreadAndConnectionId(\n messageContext.agentContext,\n connection.id,\n answerMessage.threadId\n )\n if (!questionAnswerRecord) {\n throw new CredoError(`Question Answer record with thread Id ${answerMessage.threadId} not found.`)\n }\n questionAnswerRecord.assertState(QuestionAnswerState.QuestionSent)\n questionAnswerRecord.assertRole(QuestionAnswerRole.Questioner)\n\n questionAnswerRecord.response = answerMessage.response\n\n await this.updateState(messageContext.agentContext, questionAnswerRecord, QuestionAnswerState.AnswerReceived)\n\n return questionAnswerRecord\n }\n\n /**\n * Update the record to a new state and emit an state changed event. Also updates the record\n * in storage.\n *\n * @param questionAnswerRecord The question answer record to update the state for\n * @param newState The state to update to\n *\n */\n private async updateState(\n agentContext: AgentContext,\n questionAnswerRecord: QuestionAnswerRecord,\n newState: QuestionAnswerState\n ) {\n const previousState = questionAnswerRecord.state\n questionAnswerRecord.state = newState\n await this.questionAnswerRepository.update(agentContext, questionAnswerRecord)\n\n this.eventEmitter.emit<QuestionAnswerStateChangedEvent>(agentContext, {\n type: QuestionAnswerEventTypes.QuestionAnswerStateChanged,\n payload: {\n previousState,\n questionAnswerRecord: questionAnswerRecord,\n },\n })\n }\n\n private async createRecord(options: {\n questionText: string\n questionDetail?: string\n connectionId: string\n role: QuestionAnswerRole\n signatureRequired: boolean\n state: QuestionAnswerState\n threadId: string\n validResponses: ValidResponse[]\n }): Promise<QuestionAnswerRecord> {\n const questionMessageRecord = new QuestionAnswerRecord({\n questionText: options.questionText,\n questionDetail: options.questionDetail,\n connectionId: options.connectionId,\n threadId: options.threadId,\n role: options.role,\n signatureRequired: options.signatureRequired,\n state: options.state,\n validResponses: options.validResponses,\n })\n\n return questionMessageRecord\n }\n\n /**\n * Retrieve a question answer record by connection id and thread id\n *\n * @param connectionId The connection id\n * @param threadId The thread id\n * @throws {RecordNotFoundError} If no record is found\n * @throws {RecordDuplicateError} If multiple records are found\n * @returns The question answer record\n */\n public getByThreadAndConnectionId(\n agentContext: AgentContext,\n connectionId: string,\n threadId: string\n ): Promise<QuestionAnswerRecord> {\n return this.questionAnswerRepository.getSingleByQuery(agentContext, {\n connectionId,\n threadId,\n })\n }\n\n /**\n * Retrieve a question answer record by thread id\n *\n * @param connectionId The connection id\n * @param threadId The thread id\n * @returns The question answer record or null if not found\n */\n public findByThreadAndConnectionId(\n agentContext: AgentContext,\n connectionId: string,\n threadId: string\n ): Promise<QuestionAnswerRecord | null> {\n return this.questionAnswerRepository.findSingleByQuery(agentContext, {\n connectionId,\n threadId,\n })\n }\n\n /**\n * Retrieve a question answer record by id\n *\n * @param questionAnswerId The questionAnswer record id\n * @throws {RecordNotFoundError} If no record is found\n * @return The question answer record\n *\n */\n public getById(agentContext: AgentContext, questionAnswerId: string): Promise<QuestionAnswerRecord> {\n return this.questionAnswerRepository.getById(agentContext, questionAnswerId)\n }\n\n /**\n * Retrieve a question answer record by id\n *\n * @param questionAnswerId The questionAnswer record id\n * @return The question answer record or null if not found\n *\n */\n public findById(agentContext: AgentContext, questionAnswerId: string): Promise<QuestionAnswerRecord | null> {\n return this.questionAnswerRepository.findById(agentContext, questionAnswerId)\n }\n\n /**\n * Retrieve a question answer record by id\n *\n * @param questionAnswerId The questionAnswer record id\n * @return The question answer record or null if not found\n *\n */\n public getAll(agentContext: AgentContext) {\n return this.questionAnswerRepository.getAll(agentContext)\n }\n\n public async findAllByQuery(\n agentContext: AgentContext,\n query: Query<QuestionAnswerRecord>,\n queryOptions?: QueryOptions\n ) {\n return this.questionAnswerRepository.findByQuery(agentContext, query, queryOptions)\n }\n}\n"],"mappings":"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"}
@@ -0,0 +1 @@
1
+ import { QuestionAnswerService } from "./QuestionAnswerService.mjs";
@@ -0,0 +1 @@
1
+ import { QuestionAnswerService } from "./QuestionAnswerService.mjs";