@noldova/desktop.protocol 0.0.0-stage → 0.0.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 (245) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -2
  3. package/api/index.d.ts +8228 -0
  4. package/api/index.js +121 -0
  5. package/api/index.js.map +1 -0
  6. package/api/testing.d.ts +601 -0
  7. package/api/testing.js +11 -0
  8. package/api/testing.js.map +1 -0
  9. package/enums/edit-action.js +17 -0
  10. package/enums/edit-action.js.map +1 -0
  11. package/enums/failure-code.js +27 -0
  12. package/enums/failure-code.js.map +1 -0
  13. package/enums/module-state.js +16 -0
  14. package/enums/module-state.js.map +1 -0
  15. package/enums/notification-severity.js +15 -0
  16. package/enums/notification-severity.js.map +1 -0
  17. package/enums/quit-answer.js +13 -0
  18. package/enums/quit-answer.js.map +1 -0
  19. package/enums/quit-result.js +13 -0
  20. package/enums/quit-result.js.map +1 -0
  21. package/enums/secret-action.js +14 -0
  22. package/enums/secret-action.js.map +1 -0
  23. package/enums/secret-failure-kind.js +14 -0
  24. package/enums/secret-failure-kind.js.map +1 -0
  25. package/enums/secret-failure-reason.js +15 -0
  26. package/enums/secret-failure-reason.js.map +1 -0
  27. package/enums/setting-kind.js +19 -0
  28. package/enums/setting-kind.js.map +1 -0
  29. package/enums/setting-locality.js +13 -0
  30. package/enums/setting-locality.js.map +1 -0
  31. package/enums/stop-policy.js +13 -0
  32. package/enums/stop-policy.js.map +1 -0
  33. package/enums/web-view-action.js +20 -0
  34. package/enums/web-view-action.js.map +1 -0
  35. package/enums/web-view-event-kind.js +25 -0
  36. package/enums/web-view-event-kind.js.map +1 -0
  37. package/enums/web-view-failure-kind.js +21 -0
  38. package/enums/web-view-failure-kind.js.map +1 -0
  39. package/enums/web-view-navigation-kind.js +14 -0
  40. package/enums/web-view-navigation-kind.js.map +1 -0
  41. package/enums/window-action.js +14 -0
  42. package/enums/window-action.js.map +1 -0
  43. package/enums/wire-message-kind.js +16 -0
  44. package/enums/wire-message-kind.js.map +1 -0
  45. package/exceptions/desktop-protocol.exception.js +14 -0
  46. package/exceptions/desktop-protocol.exception.js.map +1 -0
  47. package/exceptions/protocol.exception.js +20 -0
  48. package/exceptions/protocol.exception.js.map +1 -0
  49. package/interfaces/i-key-stroke.js +9 -0
  50. package/interfaces/i-key-stroke.js.map +1 -0
  51. package/models/agent-control-state.js +28 -0
  52. package/models/agent-control-state.js.map +1 -0
  53. package/models/app-shortcut-list.js +27 -0
  54. package/models/app-shortcut-list.js.map +1 -0
  55. package/models/app-shortcut.js +35 -0
  56. package/models/app-shortcut.js.map +1 -0
  57. package/models/app-window-list.js +27 -0
  58. package/models/app-window-list.js.map +1 -0
  59. package/models/app-window.js +34 -0
  60. package/models/app-window.js.map +1 -0
  61. package/models/build-identity.js +53 -0
  62. package/models/build-identity.js.map +1 -0
  63. package/models/cancel.js +30 -0
  64. package/models/cancel.js.map +1 -0
  65. package/models/command-info.js +49 -0
  66. package/models/command-info.js.map +1 -0
  67. package/models/command-list.js +31 -0
  68. package/models/command-list.js.map +1 -0
  69. package/models/command-run.js +29 -0
  70. package/models/command-run.js.map +1 -0
  71. package/models/date-pattern.js +64 -0
  72. package/models/date-pattern.js.map +1 -0
  73. package/models/event.js +38 -0
  74. package/models/event.js.map +1 -0
  75. package/models/failure.js +34 -0
  76. package/models/failure.js.map +1 -0
  77. package/models/file-grant.js +80 -0
  78. package/models/file-grant.js.map +1 -0
  79. package/models/file-grants-discard.js +32 -0
  80. package/models/file-grants-discard.js.map +1 -0
  81. package/models/file-grants-ended.js +33 -0
  82. package/models/file-grants-ended.js.map +1 -0
  83. package/models/file-share-resolve.js +29 -0
  84. package/models/file-share-resolve.js.map +1 -0
  85. package/models/handshake.js +47 -0
  86. package/models/handshake.js.map +1 -0
  87. package/models/kept-runtime.js +29 -0
  88. package/models/kept-runtime.js.map +1 -0
  89. package/models/key-chord.js +115 -0
  90. package/models/key-chord.js.map +1 -0
  91. package/models/key-name.js +59 -0
  92. package/models/key-name.js.map +1 -0
  93. package/models/main-window.js +30 -0
  94. package/models/main-window.js.map +1 -0
  95. package/models/module-status-list.js +25 -0
  96. package/models/module-status-list.js.map +1 -0
  97. package/models/module-status.js +80 -0
  98. package/models/module-status.js.map +1 -0
  99. package/models/notification-action.js +36 -0
  100. package/models/notification-action.js.map +1 -0
  101. package/models/notification-broadcast.js +50 -0
  102. package/models/notification-broadcast.js.map +1 -0
  103. package/models/notification-list.js +27 -0
  104. package/models/notification-list.js.map +1 -0
  105. package/models/notification-post.js +81 -0
  106. package/models/notification-post.js.map +1 -0
  107. package/models/notification-reference.js +30 -0
  108. package/models/notification-reference.js.map +1 -0
  109. package/models/notification-state.js +44 -0
  110. package/models/notification-state.js.map +1 -0
  111. package/models/notification.js +54 -0
  112. package/models/notification.js.map +1 -0
  113. package/models/notifications-query.js +28 -0
  114. package/models/notifications-query.js.map +1 -0
  115. package/models/pre-shell-data.js +28 -0
  116. package/models/pre-shell-data.js.map +1 -0
  117. package/models/program-status-list.js +32 -0
  118. package/models/program-status-list.js.map +1 -0
  119. package/models/program-status.js +48 -0
  120. package/models/program-status.js.map +1 -0
  121. package/models/qualified-name.js +44 -0
  122. package/models/qualified-name.js.map +1 -0
  123. package/models/quit-answered.js +28 -0
  124. package/models/quit-answered.js.map +1 -0
  125. package/models/quit-report.js +28 -0
  126. package/models/quit-report.js.map +1 -0
  127. package/models/recent-command-use.js +31 -0
  128. package/models/recent-command-use.js.map +1 -0
  129. package/models/recent-commands-query.js +28 -0
  130. package/models/recent-commands-query.js.map +1 -0
  131. package/models/recent-commands.js +39 -0
  132. package/models/recent-commands.js.map +1 -0
  133. package/models/request.js +55 -0
  134. package/models/request.js.map +1 -0
  135. package/models/response.js +62 -0
  136. package/models/response.js.map +1 -0
  137. package/models/running-work.js +30 -0
  138. package/models/running-work.js.map +1 -0
  139. package/models/runtime-handover.js +32 -0
  140. package/models/runtime-handover.js.map +1 -0
  141. package/models/secret-answered.js +42 -0
  142. package/models/secret-answered.js.map +1 -0
  143. package/models/secret-command.js +52 -0
  144. package/models/secret-command.js.map +1 -0
  145. package/models/secret-failures.js +25 -0
  146. package/models/secret-failures.js.map +1 -0
  147. package/models/secret-reference.js +30 -0
  148. package/models/secret-reference.js.map +1 -0
  149. package/models/secret-value.js +37 -0
  150. package/models/secret-value.js.map +1 -0
  151. package/models/setting-change.js +31 -0
  152. package/models/setting-change.js.map +1 -0
  153. package/models/setting-definition.js +71 -0
  154. package/models/setting-definition.js.map +1 -0
  155. package/models/setting-entry.js +31 -0
  156. package/models/setting-entry.js.map +1 -0
  157. package/models/setting-key.js +41 -0
  158. package/models/setting-key.js.map +1 -0
  159. package/models/setting-option.js +33 -0
  160. package/models/setting-option.js.map +1 -0
  161. package/models/setting-scope.js +36 -0
  162. package/models/setting-scope.js.map +1 -0
  163. package/models/setting-type.js +156 -0
  164. package/models/setting-type.js.map +1 -0
  165. package/models/setting-value.js +28 -0
  166. package/models/setting-value.js.map +1 -0
  167. package/models/settings-query.js +30 -0
  168. package/models/settings-query.js.map +1 -0
  169. package/models/settings-snapshot.js +37 -0
  170. package/models/settings-snapshot.js.map +1 -0
  171. package/models/shell-clients.js +14 -0
  172. package/models/shell-clients.js.map +1 -0
  173. package/models/shell-events.js +25 -0
  174. package/models/shell-events.js.map +1 -0
  175. package/models/shell-keys.js +26 -0
  176. package/models/shell-keys.js.map +1 -0
  177. package/models/shell-methods.js +54 -0
  178. package/models/shell-methods.js.map +1 -0
  179. package/models/shell-notifications.js +17 -0
  180. package/models/shell-notifications.js.map +1 -0
  181. package/models/stop-request.js +30 -0
  182. package/models/stop-request.js.map +1 -0
  183. package/models/update-process.js +42 -0
  184. package/models/update-process.js.map +1 -0
  185. package/models/update-ready.js +35 -0
  186. package/models/update-ready.js.map +1 -0
  187. package/models/update-request.js +28 -0
  188. package/models/update-request.js.map +1 -0
  189. package/models/update-saved.js +37 -0
  190. package/models/update-saved.js.map +1 -0
  191. package/models/web-view-answered.js +43 -0
  192. package/models/web-view-answered.js.map +1 -0
  193. package/models/web-view-command.js +79 -0
  194. package/models/web-view-command.js.map +1 -0
  195. package/models/web-view-declaration.js +64 -0
  196. package/models/web-view-declaration.js.map +1 -0
  197. package/models/web-view-event.js +98 -0
  198. package/models/web-view-event.js.map +1 -0
  199. package/models/web-view-events.js +31 -0
  200. package/models/web-view-events.js.map +1 -0
  201. package/models/web-view-failure.js +41 -0
  202. package/models/web-view-failure.js.map +1 -0
  203. package/models/web-view-info.js +41 -0
  204. package/models/web-view-info.js.map +1 -0
  205. package/models/web-view-key.js +58 -0
  206. package/models/web-view-key.js.map +1 -0
  207. package/models/web-view-method.js +47 -0
  208. package/models/web-view-method.js.map +1 -0
  209. package/models/web-view-navigation.js +34 -0
  210. package/models/web-view-navigation.js.map +1 -0
  211. package/models/web-view-pane.js +36 -0
  212. package/models/web-view-pane.js.map +1 -0
  213. package/models/web-view-parameter.js +96 -0
  214. package/models/web-view-parameter.js.map +1 -0
  215. package/models/window-closed.js +29 -0
  216. package/models/window-closed.js.map +1 -0
  217. package/models/window-state-key.js +31 -0
  218. package/models/window-state-key.js.map +1 -0
  219. package/models/window-state-value.js +26 -0
  220. package/models/window-state-value.js.map +1 -0
  221. package/models/window-state-write.js +30 -0
  222. package/models/window-state-write.js.map +1 -0
  223. package/models/wire-message.js +17 -0
  224. package/models/wire-message.js.map +1 -0
  225. package/models/work-report.js +35 -0
  226. package/models/work-report.js.map +1 -0
  227. package/package.json +40 -3
  228. package/resources.js +476 -0
  229. package/resources.js.map +1 -0
  230. package/services/frame-writer.js +24 -0
  231. package/services/frame-writer.js.map +1 -0
  232. package/services/frame.reader.js +47 -0
  233. package/services/frame.reader.js.map +1 -0
  234. package/services/link-policy.js +20 -0
  235. package/services/link-policy.js.map +1 -0
  236. package/services/wire-contract.js +30 -0
  237. package/services/wire-contract.js.map +1 -0
  238. package/services/wire-decoder.js +35 -0
  239. package/services/wire-decoder.js.map +1 -0
  240. package/testing/exceptions/unanswered-call.exception.js +17 -0
  241. package/testing/exceptions/unanswered-call.exception.js.map +1 -0
  242. package/testing/models/fake-call.js +16 -0
  243. package/testing/models/fake-call.js.map +1 -0
  244. package/testing/models/fake.js +122 -0
  245. package/testing/models/fake.js.map +1 -0
@@ -0,0 +1,601 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+
9
+ import type { DesktopProtocolException, FailureCode } from "@noldova/desktop.protocol";
10
+
11
+ /**
12
+ * The exception a fake throws when the code under test calls a member that
13
+ * returns a value, or reads a property, that the test gave no answer for, so
14
+ * that no test passes on an answer the fake made up. It extends the
15
+ * package's base, {@link DesktopProtocolException}, rather than its `ProtocolException`, whose
16
+ * {@link FailureCode} names a failure the local protocol carries between
17
+ * processes: a missing answer is a test's own mistake, which never crosses
18
+ * the protocol, so it has no code.
19
+ */
20
+ export declare class UnansweredCallException extends DesktopProtocolException {
21
+ /**
22
+ * The member that had no answer.
23
+ */
24
+ public readonly member: string;
25
+
26
+ /**
27
+ * Creates the exception.
28
+ *
29
+ * @param member The member that had no answer.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { UnansweredCallException } from "@noldova/desktop.protocol/testing";
34
+ *
35
+ * export const failure: UnansweredCallException = new UnansweredCallException("readSetting");
36
+ * ```
37
+ */
38
+ public constructor(member: string);
39
+ }
40
+
41
+ /**
42
+ * One call the code under test made to a fake: the member it called and the
43
+ * arguments it passed, as it passed them.
44
+ *
45
+ * @typeParam T The interface the fake stands in for.
46
+ */
47
+ export declare class FakeCall<T extends object> {
48
+ /**
49
+ * The member that was called.
50
+ */
51
+ public readonly member: keyof T & string;
52
+
53
+ /**
54
+ * The arguments, in order, without the ones the caller left out.
55
+ */
56
+ public readonly args: readonly unknown[];
57
+
58
+ /**
59
+ * Creates the record of a call.
60
+ *
61
+ * @param member The member that was called.
62
+ * @param args The arguments it was called with.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import { FakeCall } from "@noldova/desktop.protocol/testing";
67
+ *
68
+ * interface ILog {
69
+ * write(message: string): void;
70
+ * }
71
+ *
72
+ * export const call: FakeCall<ILog> = new FakeCall<ILog>("write", ["Started."]);
73
+ * ```
74
+ */
75
+ public constructor(member: keyof T & string, args: readonly unknown[]);
76
+ }
77
+
78
+ /**
79
+ * The base of Noldova Desktop's fakes of the interfaces it hands a module: each
80
+ * fake records every call the code under test makes, in order, and a test
81
+ * gives the answer of each member that returns a value with
82
+ * {@link Fake.answer}. A member that returns a value and has no answer throws
83
+ * {@link UnansweredCallException}; a member that returns nothing records the
84
+ * call and calls its answer, if any; a registration or a listener records the
85
+ * call and returns a disposer that ends it. A test that calls
86
+ * {@link Fake.beStrict} makes an unanswered member that returns nothing, a
87
+ * registration or a listener throw too, unless it named the member with
88
+ * {@link Fake.allow}.
89
+ *
90
+ * @typeParam T The interface the fake stands in for.
91
+ */
92
+ export declare abstract class Fake<T extends object> {
93
+ /**
94
+ * The answers the test gave, by member.
95
+ */
96
+ protected readonly answers: { -readonly [K in keyof T]?: T[K] };
97
+
98
+ /**
99
+ * Every call the code under test made, in order.
100
+ */
101
+ public get calls(): readonly FakeCall<T>[];
102
+
103
+ /**
104
+ * What the fake's listeners threw or rejected with while a raiser that
105
+ * catches them called them, in order, where the real part reports such an
106
+ * error in a place a module's test can't read.
107
+ */
108
+ public get errors(): readonly unknown[];
109
+
110
+ /**
111
+ * Lists the arguments of each call to one member.
112
+ *
113
+ * @param member The member.
114
+ * @returns The arguments of each call to it, in the order of the calls; empty
115
+ * when it wasn't called.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * import type { Fake } from "@noldova/desktop.protocol/testing";
120
+ *
121
+ * interface ILog {
122
+ * write(message: string): void;
123
+ * }
124
+ *
125
+ * export function written(log: Fake<ILog>): readonly string[] {
126
+ * return log.callsOf("write").map(t => String(t[0]));
127
+ * }
128
+ * ```
129
+ */
130
+ public callsOf(member: keyof T & string): readonly (readonly unknown[])[];
131
+
132
+ /**
133
+ * Lists the arguments of each registration or listener of one member that is
134
+ * still in place, its disposer not yet called.
135
+ *
136
+ * @param member The member.
137
+ * @returns The arguments of each call to it whose disposer hasn't run, in the
138
+ * order of the calls.
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * import type { Fake } from "@noldova/desktop.protocol/testing";
143
+ *
144
+ * interface IClock {
145
+ * onTick(listener: () => void): () => void;
146
+ * }
147
+ *
148
+ * export function isListening(clock: Fake<IClock>): boolean {
149
+ * return clock.activeCallsOf("onTick").length > 0;
150
+ * }
151
+ * ```
152
+ */
153
+ public activeCallsOf(member: keyof T & string): readonly (readonly unknown[])[];
154
+
155
+ /**
156
+ * Gives a member's answer: the implementation the fake calls, after it
157
+ * records the call, from then on, or a property's value.
158
+ *
159
+ * @param member The member.
160
+ * @param implementation What the member does or holds, typed as the
161
+ * interface declares it.
162
+ *
163
+ * @example
164
+ * ```ts
165
+ * import type { Fake } from "@noldova/desktop.protocol/testing";
166
+ *
167
+ * interface ISettings {
168
+ * read(name: string): string;
169
+ * }
170
+ *
171
+ * export function answerDark(settings: Fake<ISettings>): void {
172
+ * settings.answer("read", () => "dark");
173
+ * }
174
+ * ```
175
+ */
176
+ public answer<K extends keyof T>(member: K, implementation: T[K]): void;
177
+
178
+ /**
179
+ * Makes the fake strict, and each fake it holds, such as a context's
180
+ * settings: from then on, a call to a member that returns nothing, a
181
+ * registration or a listener that the test neither answered nor named with
182
+ * {@link Fake.allow} records the call and then throws
183
+ * {@link UnansweredCallException}, naming the member, as an unanswered
184
+ * member that returns a value does. A fake is lenient until a test calls
185
+ * this.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * import type { Fake } from "@noldova/desktop.protocol/testing";
190
+ *
191
+ * interface ILog {
192
+ * write(message: string): void;
193
+ * }
194
+ *
195
+ * export function strict(log: Fake<ILog>): void {
196
+ * log.beStrict();
197
+ * }
198
+ * ```
199
+ */
200
+ public beStrict(): void;
201
+
202
+ /**
203
+ * Lets a strict fake take calls to members that return nothing,
204
+ * registrations and listeners that the test gives no answer, as a lenient
205
+ * fake does: it records them and, for a listener, keeps it for the fake's
206
+ * raisers. It changes nothing for a member that returns a value, or a
207
+ * property, which throws {@link UnansweredCallException} until the test
208
+ * answers it, strict or not.
209
+ *
210
+ * @param members The members the test lets the code under test call.
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * import type { Fake } from "@noldova/desktop.protocol/testing";
215
+ *
216
+ * interface IClock {
217
+ * onTick(listener: (count: number) => void): () => void;
218
+ * }
219
+ *
220
+ * export function strictWithTicks(clock: Fake<IClock>): void {
221
+ * clock.beStrict();
222
+ * clock.allow("onTick");
223
+ * }
224
+ * ```
225
+ */
226
+ public allow(...members: (keyof T & string)[]): void;
227
+
228
+ /**
229
+ * Records a call to a member that returns a value and returns what its
230
+ * answer returns.
231
+ *
232
+ * @param member The member.
233
+ * @param args The arguments it was called with.
234
+ * @param answer The member's answer, if the test gave one.
235
+ * @returns What the answer returns.
236
+ * @throws {UnansweredCallException} Synchronously, when the member has no
237
+ * answer.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * import { Fake } from "@noldova/desktop.protocol/testing";
242
+ *
243
+ * interface ISettings {
244
+ * read(name: string): string;
245
+ * }
246
+ *
247
+ * export class FakeSettings extends Fake<ISettings> implements ISettings {
248
+ * public readonly read: ISettings["read"] = (...args) => this.ask("read", args, this.answers.read);
249
+ * }
250
+ * ```
251
+ */
252
+ protected ask<A extends unknown[], R>(member: keyof T & string, args: A, answer: ((...args: A) => R) | undefined): R;
253
+
254
+ /**
255
+ * Records a call to a member that returns a promise and returns what its
256
+ * answer returns.
257
+ *
258
+ * @param member The member.
259
+ * @param args The arguments it was called with.
260
+ * @param answer The member's answer, if the test gave one.
261
+ * @returns What the answer returns.
262
+ * @throws {UnansweredCallException} By rejecting the promise it returns,
263
+ * when the member has no answer, as the real member fails.
264
+ *
265
+ * @example
266
+ * ```ts
267
+ * import { Fake } from "@noldova/desktop.protocol/testing";
268
+ *
269
+ * interface ISecrets {
270
+ * readAsync(name: string): Promise<string | null>;
271
+ * }
272
+ *
273
+ * export class FakeSecrets extends Fake<ISecrets> implements ISecrets {
274
+ * public readonly readAsync: ISecrets["readAsync"] = (...args) => this.respondAsync("readAsync", args, this.answers.readAsync);
275
+ * }
276
+ * ```
277
+ */
278
+ protected respondAsync<A extends unknown[], R>(member: keyof T & string, args: A, answer: ((...args: A) => Promise<R>) | undefined): Promise<R>;
279
+
280
+ /**
281
+ * Records a call to a generic member that returns a value and returns its
282
+ * answer, for the caller to call with its own type arguments.
283
+ *
284
+ * @param member The member.
285
+ * @param args The arguments it was called with.
286
+ * @param answer The member's answer, if the test gave one.
287
+ * @returns The answer.
288
+ * @throws {UnansweredCallException} Synchronously, when the member has no
289
+ * answer.
290
+ *
291
+ * @example
292
+ * ```ts
293
+ * import { Fake } from "@noldova/desktop.protocol/testing";
294
+ *
295
+ * interface IServices {
296
+ * find<T>(name: string): T | null;
297
+ * }
298
+ *
299
+ * export class FakeServices extends Fake<IServices> implements IServices {
300
+ * public find<T>(name: string): T | null {
301
+ * return this.answerOf("find", [name], this.answers.find)<T>(name);
302
+ * }
303
+ * }
304
+ * ```
305
+ */
306
+ protected answerOf<F>(member: keyof T & string, args: readonly unknown[], answer: F | undefined): F;
307
+
308
+ /**
309
+ * Records a call to a generic member that returns a promise and returns what
310
+ * the caller's call of its answer returns; an answer that throws rejects the
311
+ * promise, as the real member would fail.
312
+ *
313
+ * @param member The member.
314
+ * @param args The arguments it was called with.
315
+ * @param answer The member's answer, if the test gave one.
316
+ * @param call Calls the answer with the member's own type arguments.
317
+ * @returns What the call returns.
318
+ * @throws {UnansweredCallException} By rejecting the promise it returns,
319
+ * when the member has no answer.
320
+ *
321
+ * @example
322
+ * ```ts
323
+ * import { Fake } from "@noldova/desktop.protocol/testing";
324
+ *
325
+ * interface IServices {
326
+ * findAsync<T>(name: string): Promise<T | null>;
327
+ * }
328
+ *
329
+ * export class FakeServices extends Fake<IServices> implements IServices {
330
+ * public findAsync<T>(name: string): Promise<T | null> {
331
+ * return this.answerOfAsync("findAsync", [name], this.answers.findAsync, t => t<T>(name));
332
+ * }
333
+ * }
334
+ * ```
335
+ */
336
+ protected answerOfAsync<F, R>(member: keyof T & string, args: readonly unknown[], answer: F | undefined, call: (answer: F) => Promise<R>): Promise<R>;
337
+
338
+ /**
339
+ * Records a call to a member that returns nothing and calls its answer, if
340
+ * the test gave one.
341
+ *
342
+ * @param member The member.
343
+ * @param args The arguments it was called with.
344
+ * @param answer The member's answer, if the test gave one.
345
+ *
346
+ * @example
347
+ * ```ts
348
+ * import { Fake } from "@noldova/desktop.protocol/testing";
349
+ *
350
+ * interface ILog {
351
+ * write(message: string): void;
352
+ * }
353
+ *
354
+ * export class FakeLog extends Fake<ILog> implements ILog {
355
+ * public readonly write: ILog["write"] = (...args) => this.tell("write", args, this.answers.write);
356
+ * }
357
+ * ```
358
+ */
359
+ protected tell<A extends unknown[]>(member: keyof T & string, args: A, answer: ((...args: A) => void) | undefined): void;
360
+
361
+ /**
362
+ * Records a registration, which stays among {@link Fake.activeCallsOf} until
363
+ * its disposer runs.
364
+ *
365
+ * @param member The member.
366
+ * @param args The arguments it was called with.
367
+ * @returns The disposer that ends the registration.
368
+ *
369
+ * @example
370
+ * ```ts
371
+ * import { Fake } from "@noldova/desktop.protocol/testing";
372
+ *
373
+ * interface IMarks {
374
+ * mark(name: string): () => void;
375
+ * }
376
+ *
377
+ * export class FakeMarks extends Fake<IMarks> implements IMarks {
378
+ * public readonly mark: IMarks["mark"] = (...args) => this.track("mark", args);
379
+ * }
380
+ * ```
381
+ */
382
+ protected track(member: keyof T & string, args: readonly unknown[]): () => void;
383
+
384
+ /**
385
+ * Records a listener's registration and keeps the listener in a set, for the
386
+ * fake's raisers to call, until its disposer runs.
387
+ *
388
+ * @param member The member.
389
+ * @param args The arguments it was called with.
390
+ * @param listeners The set that holds the member's listeners.
391
+ * @param listener What the set keeps.
392
+ * @returns The disposer that ends the registration and drops the listener.
393
+ *
394
+ * @example
395
+ * ```ts
396
+ * import { Fake } from "@noldova/desktop.protocol/testing";
397
+ *
398
+ * interface IClock {
399
+ * onTick(listener: () => void): () => void;
400
+ * }
401
+ *
402
+ * export class FakeClock extends Fake<IClock> implements IClock {
403
+ * private readonly ticks: Set<() => void> = new Set<() => void>();
404
+ *
405
+ * public readonly onTick: IClock["onTick"] = listener => this.listen("onTick", [listener], this.ticks, listener);
406
+ * }
407
+ * ```
408
+ */
409
+ protected listen<L>(member: keyof T & string, args: readonly unknown[], listeners: Set<L>, listener: L): () => void;
410
+
411
+ /**
412
+ * Reads a property's answer.
413
+ *
414
+ * @param member The property.
415
+ * @param answer The property's answer, if the test gave one.
416
+ * @returns The answer.
417
+ * @throws {UnansweredCallException} When the property has no answer.
418
+ *
419
+ * @example
420
+ * ```ts
421
+ * import { Fake } from "@noldova/desktop.protocol/testing";
422
+ *
423
+ * interface IModule {
424
+ * readonly id: string;
425
+ * }
426
+ *
427
+ * export class FakeModule extends Fake<IModule> implements IModule {
428
+ * public get id(): string {
429
+ * return this.propertyOf("id", this.answers.id);
430
+ * }
431
+ * }
432
+ * ```
433
+ */
434
+ protected propertyOf<V>(member: keyof T & string, answer: V | undefined): V;
435
+
436
+ /**
437
+ * Calls each listener a set holds when the call starts, in the order they
438
+ * were added, for a real dispatch that loops over a copy of its listeners:
439
+ * a listener added during the call waits for the next, one an earlier one
440
+ * removes is still called, and one that throws stops the rest and throws to
441
+ * the raiser's caller.
442
+ *
443
+ * @param listeners The set that {@link Fake.listen} added the listeners to;
444
+ * it is read when the call starts.
445
+ * @param call Gets each listener in turn and calls it with the raised
446
+ * values.
447
+ *
448
+ * @example
449
+ * ```ts
450
+ * import { Fake } from "@noldova/desktop.protocol/testing";
451
+ *
452
+ * interface IClock {
453
+ * onTick(listener: () => void): () => void;
454
+ * }
455
+ *
456
+ * export class FakeClock extends Fake<IClock> implements IClock {
457
+ * private readonly ticks: Set<() => void> = new Set<() => void>();
458
+ *
459
+ * public readonly onTick: IClock["onTick"] = listener => this.listen("onTick", [listener], this.ticks, listener);
460
+ *
461
+ * public raiseTick(): void {
462
+ * this.raise(this.ticks, t => t());
463
+ * }
464
+ * }
465
+ * ```
466
+ */
467
+ protected raise<L>(listeners: ReadonlySet<L>, call: (listener: L) => void): void;
468
+
469
+ /**
470
+ * The fakes this fake holds, which {@link Fake.beStrict} makes strict with
471
+ * it; none, unless a fake that holds others overrides it.
472
+ *
473
+ * @returns The fakes it holds.
474
+ *
475
+ * @example
476
+ * ```ts
477
+ * import { Fake } from "@noldova/desktop.protocol/testing";
478
+ *
479
+ * interface ILog {
480
+ * write(message: string): void;
481
+ * }
482
+ *
483
+ * interface IHost {
484
+ * readonly log: ILog;
485
+ * }
486
+ *
487
+ * class FakeLog extends Fake<ILog> implements ILog {
488
+ * public readonly write: ILog["write"] = (...args) => this.tell("write", args, this.answers.write);
489
+ * }
490
+ *
491
+ * export class FakeHost extends Fake<IHost> implements IHost {
492
+ * public readonly log: FakeLog = new FakeLog();
493
+ *
494
+ * protected override parts(): readonly Pick<Fake<object>, "beStrict">[] {
495
+ * return [this.log];
496
+ * }
497
+ * }
498
+ * ```
499
+ */
500
+ protected parts(): readonly Pick<Fake<object>, "beStrict">[];
501
+
502
+ /**
503
+ * Calls each listener a set holds when the call starts, as
504
+ * {@link Fake.raise} does, but reports a throw and goes on to the next
505
+ * listener, for a real dispatch that catches each listener's error.
506
+ *
507
+ * @param listeners The set that {@link Fake.listen} added the listeners to;
508
+ * it is read when the call starts.
509
+ * @param call Gets each listener in turn and calls it with the raised
510
+ * values.
511
+ * @param report What to do with an error a listener throws; by default, keep
512
+ * it in {@link Fake.errors}.
513
+ *
514
+ * @example
515
+ * ```ts
516
+ * import { Fake } from "@noldova/desktop.protocol/testing";
517
+ *
518
+ * interface ITabs {
519
+ * onClosed(listener: () => void): () => void;
520
+ * }
521
+ *
522
+ * export class FakeTabs extends Fake<ITabs> implements ITabs {
523
+ * private readonly closed: Set<() => void> = new Set<() => void>();
524
+ *
525
+ * public readonly onClosed: ITabs["onClosed"] = listener => this.listen("onClosed", [listener], this.closed, listener);
526
+ *
527
+ * public raiseClosed(): void {
528
+ * this.raiseIsolated(this.closed, t => t());
529
+ * }
530
+ * }
531
+ * ```
532
+ */
533
+ protected raiseIsolated<L>(listeners: ReadonlySet<L>, call: (listener: L) => void, report?: (error: unknown) => void): void;
534
+
535
+ /**
536
+ * Calls each listener a set holds as {@link Fake.raiseIsolated} does, but
537
+ * skips one that an earlier one removes during the call, for a real dispatch
538
+ * that checks each listener is still in place.
539
+ *
540
+ * @param listeners The set that {@link Fake.listen} added the listeners to;
541
+ * it is read when the call starts, and checked again before each listener.
542
+ * @param call Gets each listener in turn and calls it with the raised
543
+ * values.
544
+ * @param report What to do with an error a listener throws; by default, keep
545
+ * it in {@link Fake.errors}.
546
+ *
547
+ * @example
548
+ * ```ts
549
+ * import { Fake } from "@noldova/desktop.protocol/testing";
550
+ *
551
+ * interface IModules {
552
+ * onChanged(listener: () => void): () => void;
553
+ * }
554
+ *
555
+ * export class FakeModules extends Fake<IModules> implements IModules {
556
+ * private readonly changed: Set<() => void> = new Set<() => void>();
557
+ *
558
+ * public readonly onChanged: IModules["onChanged"] = listener => this.listen("onChanged", [listener], this.changed, listener);
559
+ *
560
+ * public raiseChanged(): void {
561
+ * this.raiseLive(this.changed, t => t());
562
+ * }
563
+ * }
564
+ * ```
565
+ */
566
+ protected raiseLive<L>(listeners: ReadonlySet<L>, call: (listener: L) => void, report?: (error: unknown) => void): void;
567
+
568
+ /**
569
+ * Calls each listener a set holds as {@link Fake.raiseLive} does, and waits
570
+ * for what each returns; a listener that throws or rejects is reported and
571
+ * stops no other.
572
+ *
573
+ * @param listeners The set that {@link Fake.listen} added the listeners to;
574
+ * it is read when the call starts, and checked again before each listener.
575
+ * @param call Gets each listener in turn and calls it with the raised
576
+ * values.
577
+ * @param report What to do with an error a listener throws or rejects with;
578
+ * by default, keep it in {@link Fake.errors}.
579
+ * @returns A promise that settles once every listener's work has.
580
+ *
581
+ * @example
582
+ * ```ts
583
+ * import { Fake } from "@noldova/desktop.protocol/testing";
584
+ *
585
+ * interface IClients {
586
+ * onClosed(listener: () => Promise<void>): () => void;
587
+ * }
588
+ *
589
+ * export class FakeClients extends Fake<IClients> implements IClients {
590
+ * private readonly closed: Set<() => Promise<void>> = new Set<() => Promise<void>>();
591
+ *
592
+ * public readonly onClosed: IClients["onClosed"] = listener => this.listen("onClosed", [listener], this.closed, listener);
593
+ *
594
+ * public raiseClosedAsync(): Promise<void> {
595
+ * return this.raiseLiveAsync(this.closed, t => t());
596
+ * }
597
+ * }
598
+ * ```
599
+ */
600
+ protected raiseLiveAsync<L>(listeners: ReadonlySet<L>, call: (listener: L) => void | Promise<void>, report?: (error: unknown) => void): Promise<void>;
601
+ }
package/api/testing.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export { UnansweredCallException } from "../testing/exceptions/unanswered-call.exception.js";
9
+ export { Fake } from "../testing/models/fake.js";
10
+ export { FakeCall } from "../testing/models/fake-call.js";
11
+ //# sourceMappingURL=testing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"testing.js","sourceRoot":"","sources":["../../../../src/noldova.desktop.protocol/src/api/testing.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,oDAAoD,CAAC;AAC7F,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AACjD,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export var EditAction;
9
+ (function (EditAction) {
10
+ EditAction["Undo"] = "Undo";
11
+ EditAction["Redo"] = "Redo";
12
+ EditAction["Cut"] = "Cut";
13
+ EditAction["Copy"] = "Copy";
14
+ EditAction["Paste"] = "Paste";
15
+ EditAction["SelectAll"] = "SelectAll";
16
+ })(EditAction || (EditAction = {}));
17
+ //# sourceMappingURL=edit-action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edit-action.js","sourceRoot":"","sources":["../../../../src/noldova.desktop.protocol/src/enums/edit-action.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,CAAN,IAAY,UAOX;AAPD,WAAY,UAAU;IACpB,2BAAa,CAAA;IACb,2BAAa,CAAA;IACb,yBAAW,CAAA;IACX,2BAAa,CAAA;IACb,6BAAe,CAAA;IACf,qCAAuB,CAAA;AACzB,CAAC,EAPW,UAAU,KAAV,UAAU,QAOrB"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export var FailureCode;
9
+ (function (FailureCode) {
10
+ FailureCode["InvalidMessage"] = "InvalidMessage";
11
+ FailureCode["FrameTooLarge"] = "FrameTooLarge";
12
+ FailureCode["UnsupportedVersion"] = "UnsupportedVersion";
13
+ FailureCode["BuildMismatch"] = "BuildMismatch";
14
+ FailureCode["PreShellData"] = "PreShellData";
15
+ FailureCode["Unauthorized"] = "Unauthorized";
16
+ FailureCode["UnknownMethod"] = "UnknownMethod";
17
+ FailureCode["InvalidParams"] = "InvalidParams";
18
+ FailureCode["NotFound"] = "NotFound";
19
+ FailureCode["Conflict"] = "Conflict";
20
+ FailureCode["Cancelled"] = "Cancelled";
21
+ FailureCode["DeadlineExceeded"] = "DeadlineExceeded";
22
+ FailureCode["Unavailable"] = "Unavailable";
23
+ FailureCode["Disconnected"] = "Disconnected";
24
+ FailureCode["Updating"] = "Updating";
25
+ FailureCode["Internal"] = "Internal";
26
+ })(FailureCode || (FailureCode = {}));
27
+ //# sourceMappingURL=failure-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure-code.js","sourceRoot":"","sources":["../../../../src/noldova.desktop.protocol/src/enums/failure-code.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,CAAN,IAAY,WAiBX;AAjBD,WAAY,WAAW;IACrB,gDAAiC,CAAA;IACjC,8CAA+B,CAAA;IAC/B,wDAAyC,CAAA;IACzC,8CAA+B,CAAA;IAC/B,4CAA6B,CAAA;IAC7B,4CAA6B,CAAA;IAC7B,8CAA+B,CAAA;IAC/B,8CAA+B,CAAA;IAC/B,oCAAqB,CAAA;IACrB,oCAAqB,CAAA;IACrB,sCAAuB,CAAA;IACvB,oDAAqC,CAAA;IACrC,0CAA2B,CAAA;IAC3B,4CAA6B,CAAA;IAC7B,oCAAqB,CAAA;IACrB,oCAAqB,CAAA;AACvB,CAAC,EAjBW,WAAW,KAAX,WAAW,QAiBtB"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export var ModuleState;
9
+ (function (ModuleState) {
10
+ ModuleState["Active"] = "Active";
11
+ ModuleState["Failed"] = "Failed";
12
+ ModuleState["Blocked"] = "Blocked";
13
+ ModuleState["Off"] = "Off";
14
+ ModuleState["Unavailable"] = "Unavailable";
15
+ })(ModuleState || (ModuleState = {}));
16
+ //# sourceMappingURL=module-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-state.js","sourceRoot":"","sources":["../../../../src/noldova.desktop.protocol/src/enums/module-state.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,MAAM,CAAN,IAAY,WAMX;AAND,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,gCAAiB,CAAA;IACjB,kCAAmB,CAAA;IACnB,0BAAW,CAAA;IACX,0CAA2B,CAAA;AAC7B,CAAC,EANW,WAAW,KAAX,WAAW,QAMtB"}