@ahoo-wang/wow-client 10.0.0-alpha.6 → 10.0.0-beta.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 (198) hide show
  1. package/README.md +77 -23
  2. package/README.zh-CN.md +67 -19
  3. package/dist/commands.cjs +1 -1
  4. package/dist/commands.cjs.map +1 -1
  5. package/dist/commands.d.cts +134 -61
  6. package/dist/commands.d.ts +134 -61
  7. package/dist/commands.es.js +129 -59
  8. package/dist/commands.es.js.map +1 -1
  9. package/dist/developmentCaller.cjs +2 -0
  10. package/dist/developmentCaller.cjs.map +1 -0
  11. package/dist/developmentCaller.d.cts +61 -0
  12. package/dist/developmentCaller.d.ts +61 -0
  13. package/dist/developmentCaller.es.js +26 -0
  14. package/dist/developmentCaller.es.js.map +1 -0
  15. package/dist/dsl/aggregation/admit.cjs +1 -1
  16. package/dist/dsl/aggregation/admit.cjs.map +1 -1
  17. package/dist/dsl/aggregation/admit.es.js +93 -93
  18. package/dist/dsl/aggregation/admit.es.js.map +1 -1
  19. package/dist/dsl/aggregation/builders.cjs +1 -1
  20. package/dist/dsl/aggregation/builders.cjs.map +1 -1
  21. package/dist/dsl/aggregation/builders.d.cts +20 -20
  22. package/dist/dsl/aggregation/builders.d.ts +20 -20
  23. package/dist/dsl/aggregation/builders.es.js +88 -88
  24. package/dist/dsl/aggregation/builders.es.js.map +1 -1
  25. package/dist/dsl/aggregation/derived.cjs.map +1 -1
  26. package/dist/dsl/aggregation/derived.d.cts +8 -8
  27. package/dist/dsl/aggregation/derived.d.ts +8 -8
  28. package/dist/dsl/aggregation/derived.es.js +1 -2
  29. package/dist/dsl/aggregation/derived.es.js.map +1 -1
  30. package/dist/dsl/aggregation/expressionTrees.cjs.map +1 -1
  31. package/dist/dsl/aggregation/expressionTrees.es.js +1 -2
  32. package/dist/dsl/aggregation/having.cjs +1 -1
  33. package/dist/dsl/aggregation/having.cjs.map +1 -1
  34. package/dist/dsl/aggregation/having.d.cts +12 -12
  35. package/dist/dsl/aggregation/having.d.ts +12 -12
  36. package/dist/dsl/aggregation/having.es.js +33 -33
  37. package/dist/dsl/aggregation/having.es.js.map +1 -1
  38. package/dist/dsl/aggregation/sort.cjs.map +1 -1
  39. package/dist/dsl/aggregation/sort.es.js +1 -2
  40. package/dist/dsl/aggregation/types.cjs +1 -1
  41. package/dist/dsl/aggregation/types.cjs.map +1 -1
  42. package/dist/dsl/aggregation/types.d.cts +69 -69
  43. package/dist/dsl/aggregation/types.d.ts +69 -69
  44. package/dist/dsl/aggregation/types.es.js +15 -16
  45. package/dist/dsl/aggregation/types.es.js.map +1 -1
  46. package/dist/dsl/constantName.cjs +2 -0
  47. package/dist/dsl/constantName.cjs.map +1 -0
  48. package/dist/dsl/constantName.d.cts +9 -0
  49. package/dist/dsl/constantName.d.ts +9 -0
  50. package/dist/dsl/constantName.es.js +7 -0
  51. package/dist/dsl/constantName.es.js.map +1 -0
  52. package/dist/dsl/cursorQuery.cjs.map +1 -1
  53. package/dist/dsl/cursorQuery.es.js +1 -2
  54. package/dist/dsl/deletionState.cjs +1 -1
  55. package/dist/dsl/deletionState.cjs.map +1 -1
  56. package/dist/dsl/deletionState.d.cts +3 -3
  57. package/dist/dsl/deletionState.d.ts +3 -3
  58. package/dist/dsl/deletionState.es.js +2 -3
  59. package/dist/dsl/deletionState.es.js.map +1 -1
  60. package/dist/dsl/descriptor.cjs +1 -1
  61. package/dist/dsl/descriptor.cjs.map +1 -1
  62. package/dist/dsl/descriptor.d.cts +99 -42
  63. package/dist/dsl/descriptor.d.ts +99 -42
  64. package/dist/dsl/descriptor.es.js +37 -29
  65. package/dist/dsl/descriptor.es.js.map +1 -1
  66. package/dist/dsl/field.cjs.map +1 -1
  67. package/dist/dsl/field.es.js +1 -2
  68. package/dist/dsl/filter/builders.cjs +1 -1
  69. package/dist/dsl/filter/builders.cjs.map +1 -1
  70. package/dist/dsl/filter/builders.d.cts +53 -53
  71. package/dist/dsl/filter/builders.d.ts +53 -53
  72. package/dist/dsl/filter/builders.es.js +111 -111
  73. package/dist/dsl/filter/builders.es.js.map +1 -1
  74. package/dist/dsl/filter/datePattern.cjs.map +1 -1
  75. package/dist/dsl/filter/datePattern.es.js +1 -2
  76. package/dist/dsl/filter/operator.cjs +1 -1
  77. package/dist/dsl/filter/operator.cjs.map +1 -1
  78. package/dist/dsl/filter/operator.d.cts +57 -57
  79. package/dist/dsl/filter/operator.d.ts +57 -57
  80. package/dist/dsl/filter/operator.es.js +4 -5
  81. package/dist/dsl/filter/operator.es.js.map +1 -1
  82. package/dist/dsl/filter/scope.cjs +1 -1
  83. package/dist/dsl/filter/scope.cjs.map +1 -1
  84. package/dist/dsl/filter/scope.es.js +12 -12
  85. package/dist/dsl/filter/scope.es.js.map +1 -1
  86. package/dist/dsl/filter/validate.cjs +1 -1
  87. package/dist/dsl/filter/validate.cjs.map +1 -1
  88. package/dist/dsl/filter/validate.es.js +23 -23
  89. package/dist/dsl/filter/validate.es.js.map +1 -1
  90. package/dist/dsl/pagination.cjs.map +1 -1
  91. package/dist/dsl/pagination.es.js +1 -2
  92. package/dist/dsl/projection.cjs.map +1 -1
  93. package/dist/dsl/projection.d.cts +1 -1
  94. package/dist/dsl/projection.d.ts +1 -1
  95. package/dist/dsl/projection.es.js +1 -2
  96. package/dist/dsl/projection.es.js.map +1 -1
  97. package/dist/dsl/queryErrorCodes.cjs +1 -1
  98. package/dist/dsl/queryErrorCodes.cjs.map +1 -1
  99. package/dist/dsl/queryErrorCodes.d.cts +59 -48
  100. package/dist/dsl/queryErrorCodes.d.ts +59 -48
  101. package/dist/dsl/queryErrorCodes.es.js +51 -50
  102. package/dist/dsl/queryErrorCodes.es.js.map +1 -1
  103. package/dist/dsl/queryable.cjs +1 -1
  104. package/dist/dsl/queryable.cjs.map +1 -1
  105. package/dist/dsl/queryable.d.cts +25 -21
  106. package/dist/dsl/queryable.d.ts +25 -21
  107. package/dist/dsl/queryable.es.js +5 -5
  108. package/dist/dsl/queryable.es.js.map +1 -1
  109. package/dist/dsl/sort.cjs +1 -1
  110. package/dist/dsl/sort.cjs.map +1 -1
  111. package/dist/dsl/sort.d.cts +2 -2
  112. package/dist/dsl/sort.d.ts +2 -2
  113. package/dist/dsl/sort.es.js +4 -5
  114. package/dist/dsl/sort.es.js.map +1 -1
  115. package/dist/dsl.cjs +1 -1
  116. package/dist/dsl.es.js +3 -3
  117. package/dist/exactJson.cjs.map +1 -1
  118. package/dist/exactJson.d.cts +4 -4
  119. package/dist/exactJson.d.ts +4 -4
  120. package/dist/exactJson.es.js +1 -2
  121. package/dist/exactJson.es.js.map +1 -1
  122. package/dist/frameworkErrors.cjs +2 -0
  123. package/dist/frameworkErrors.cjs.map +1 -0
  124. package/dist/frameworkErrors.d.cts +121 -0
  125. package/dist/frameworkErrors.d.ts +121 -0
  126. package/dist/frameworkErrors.es.js +95 -0
  127. package/dist/frameworkErrors.es.js.map +1 -0
  128. package/dist/http.cjs +1 -1
  129. package/dist/http.cjs.map +1 -1
  130. package/dist/http.d.cts +4 -7
  131. package/dist/http.d.ts +4 -7
  132. package/dist/http.es.js +12 -20
  133. package/dist/http.es.js.map +1 -1
  134. package/dist/index.cjs +1 -1
  135. package/dist/index.d.cts +9 -7
  136. package/dist/index.d.ts +9 -7
  137. package/dist/index.es.js +11 -9
  138. package/dist/manifest.cjs +1 -1
  139. package/dist/manifest.cjs.map +1 -1
  140. package/dist/manifest.d.cts +37 -95
  141. package/dist/manifest.d.ts +37 -95
  142. package/dist/manifest.es.js +12 -7
  143. package/dist/manifest.es.js.map +1 -1
  144. package/dist/manifestTypes.d.cts +195 -0
  145. package/dist/manifestTypes.d.ts +195 -0
  146. package/dist/problem.cjs +1 -1
  147. package/dist/problem.cjs.map +1 -1
  148. package/dist/problem.d.cts +76 -115
  149. package/dist/problem.d.ts +76 -115
  150. package/dist/problem.es.js +45 -80
  151. package/dist/problem.es.js.map +1 -1
  152. package/dist/queries.cjs +1 -1
  153. package/dist/queries.cjs.map +1 -1
  154. package/dist/queries.d.cts +28 -51
  155. package/dist/queries.d.ts +28 -51
  156. package/dist/queries.es.js +49 -40
  157. package/dist/queries.es.js.map +1 -1
  158. package/dist/routes.cjs +2 -0
  159. package/dist/routes.cjs.map +1 -0
  160. package/dist/routes.d.cts +49 -0
  161. package/dist/routes.d.ts +49 -0
  162. package/dist/routes.es.js +33 -0
  163. package/dist/routes.es.js.map +1 -0
  164. package/dist/state.cjs +1 -1
  165. package/dist/state.cjs.map +1 -1
  166. package/dist/state.d.cts +56 -11
  167. package/dist/state.d.ts +56 -11
  168. package/dist/state.es.js +56 -21
  169. package/dist/state.es.js.map +1 -1
  170. package/dist/streams.cjs +1 -1
  171. package/dist/streams.cjs.map +1 -1
  172. package/dist/streams.d.cts +17 -13
  173. package/dist/streams.d.ts +17 -13
  174. package/dist/streams.es.js +50 -50
  175. package/dist/streams.es.js.map +1 -1
  176. package/dist/testing/wire.cjs +2 -0
  177. package/dist/testing/wire.cjs.map +1 -0
  178. package/dist/testing/wire.d.cts +29 -0
  179. package/dist/testing/wire.d.ts +29 -0
  180. package/dist/testing/wire.es.js +88 -0
  181. package/dist/testing/wire.es.js.map +1 -0
  182. package/dist/testing.cjs +1 -0
  183. package/dist/testing.d.cts +12 -0
  184. package/dist/testing.d.ts +12 -0
  185. package/dist/testing.es.js +3 -0
  186. package/dist/wait.cjs +1 -1
  187. package/dist/wait.cjs.map +1 -1
  188. package/dist/wait.d.cts +68 -19
  189. package/dist/wait.d.ts +68 -19
  190. package/dist/wait.es.js +61 -14
  191. package/dist/wait.es.js.map +1 -1
  192. package/dist/wire.cjs +1 -1
  193. package/dist/wire.cjs.map +1 -1
  194. package/dist/wire.d.cts +101 -50
  195. package/dist/wire.d.ts +101 -50
  196. package/dist/wire.es.js +17 -6
  197. package/dist/wire.es.js.map +1 -1
  198. package/package.json +23 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.cjs","names":["CommandResultStatus","Stage","FunctionKind","FrameworkErrorCodes","require_frameworkErrors","require_wire","commandResultOf","ref","status","overrides","commandId","name","TITLES","problemOf","code","problemResponse","members","problem","headers","init","extensions","snapshotOf"],"sources":["../../src/testing/wire.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { FrameworkErrorCodes, type Problem } from '../problem.js';\nimport {\n type AggregateRef,\n type CommandResult,\n CommandResultStatus,\n FunctionKind,\n Stage,\n type Snapshot,\n} from '../wire.js';\n\n/**\n * A command's result as a service answers it, for a test's fake: the command\n * `ref` names, committed (`succeeded` at `committed`, version 1) unless\n * `overrides` says otherwise. A `rejected` or `failed` one without an `error`\n * carries `wow.command.refused` or `wow.command.failed`.\n */\nexport function commandResultOf<R = Record<string, unknown>>(\n ref: AggregateRef,\n overrides: Partial<CommandResult<R>> = {},\n): CommandResult<R> {\n const { context, name } = ref.type;\n const status = overrides.status ?? CommandResultStatus.SUCCEEDED;\n const commandId = overrides.commandId ?? 'command-1';\n return {\n format: 1,\n commandId,\n requestId: 'request-1',\n correlationId: commandId,\n ref,\n hop: { stage: Stage.COMMITTED, context },\n function: {\n kind: FunctionKind.COMMAND,\n context,\n processor: name,\n name: 'Command',\n },\n status,\n version: 1,\n duplicate: false,\n error:\n status === CommandResultStatus.SUCCEEDED\n ? null\n : {\n code:\n status === CommandResultStatus.REJECTED\n ? FrameworkErrorCodes.COMMAND_REFUSED\n : FrameworkErrorCodes.COMMAND_FAILED,\n message: `The command was ${status.toLowerCase()}.`,\n },\n results: {} as R,\n derived: [],\n signalTime: 0,\n ...overrides,\n };\n}\n\n/** The reason phrases of the statuses a Wow service answers a problem with. */\nconst TITLES: Readonly<Record<number, string>> = {\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 403: 'Forbidden',\n 404: 'Not Found',\n 409: 'Conflict',\n 410: 'Gone',\n 412: 'Precondition Failed',\n 429: 'Too Many Requests',\n 500: 'Internal Server Error',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n};\n\n/**\n * An RFC 9457 problem as a service answers it, of `status` and the Wow `code`\n * (`urn:wow:error:<code>`; `about:blank` without one), for a test's fake or\n * an expected error. Its title is the status's reason phrase unless\n * `overrides` says otherwise.\n */\nexport function problemOf(\n status: number,\n code?: string,\n overrides: Partial<Problem> = {},\n): Problem {\n return {\n type: code === undefined ? 'about:blank' : `urn:wow:error:${code}`,\n title: TITLES[status] ?? `HTTP ${status}`,\n status,\n ...(code === undefined ? {} : { code }),\n ...overrides,\n };\n}\n\n/**\n * The response a service answers `problem` with: `application/problem+json`,\n * its extension members written as members of their own, as the wire carries\n * them.\n */\nexport function problemResponse(\n problem: Problem,\n init: ResponseInit = {},\n): Response {\n const { extensions, ...members } = problem;\n const headers = new Headers(init.headers);\n headers.set('Content-Type', 'application/problem+json');\n return new Response(JSON.stringify({ ...extensions, ...members }), {\n ...init,\n status: problem.status,\n headers,\n });\n}\n\n/**\n * An aggregate's snapshot as a state read and a snapshot query answer it, for\n * a test's fake: `ref`'s `state` at version 1, committed at 0 by an anonymous\n * caller, of no owner or space, not deleted, untagged and keeping no\n * schedules unless `overrides` says otherwise.\n */\nexport function snapshotOf<S>(\n ref: AggregateRef,\n state: S,\n overrides: Partial<\n Omit<Snapshot<S>, 'tenantId' | 'aggregateId' | 'state'>\n > = {},\n): Snapshot<S> {\n return {\n tenantId: ref.tenantId,\n aggregateId: ref.id,\n version: 1,\n ownerId: null,\n spaceId: null,\n deleted: false,\n tags: {},\n firstEventTime: 0,\n lastEventTime: 0,\n operator: null,\n firstOperator: null,\n schedules: {},\n state,\n ...overrides,\n };\n}\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E,GAAGG,EACH,OAAQF,EAAQ,OAChB,SACF,CAAC,CACH,CAQA,SAAgBI,EACd,EACA,EACA,EAEI,CAAC,EACQ,CACb,MAAO,CACL,SAAUd,EAAI,SACd,YAAaA,EAAI,GACjB,QAAS,EACT,QAAS,KACT,QAAS,KACT,QAAS,GACT,KAAM,CAAC,EACP,eAAgB,EAChB,cAAe,EACf,SAAU,KACV,cAAe,KACf,UAAW,CAAC,EACZ,QACA,GAAGE,CACL,CACF,C"}
@@ -0,0 +1,29 @@
1
+ import { Problem } from '../problem.cjs';
2
+ import { AggregateRef, CommandResult, Snapshot } from '../wire.cjs';
3
+ /**
4
+ * A command's result as a service answers it, for a test's fake: the command
5
+ * `ref` names, committed (`succeeded` at `committed`, version 1) unless
6
+ * `overrides` says otherwise. A `rejected` or `failed` one without an `error`
7
+ * carries `wow.command.refused` or `wow.command.failed`.
8
+ */
9
+ export declare function commandResultOf<R = Record<string, unknown>>(ref: AggregateRef, overrides?: Partial<CommandResult<R>>): CommandResult<R>;
10
+ /**
11
+ * An RFC 9457 problem as a service answers it, of `status` and the Wow `code`
12
+ * (`urn:wow:error:<code>`; `about:blank` without one), for a test's fake or
13
+ * an expected error. Its title is the status's reason phrase unless
14
+ * `overrides` says otherwise.
15
+ */
16
+ export declare function problemOf(status: number, code?: string, overrides?: Partial<Problem>): Problem;
17
+ /**
18
+ * The response a service answers `problem` with: `application/problem+json`,
19
+ * its extension members written as members of their own, as the wire carries
20
+ * them.
21
+ */
22
+ export declare function problemResponse(problem: Problem, init?: ResponseInit): Response;
23
+ /**
24
+ * An aggregate's snapshot as a state read and a snapshot query answer it, for
25
+ * a test's fake: `ref`'s `state` at version 1, committed at 0 by an anonymous
26
+ * caller, of no owner or space, not deleted, untagged and keeping no
27
+ * schedules unless `overrides` says otherwise.
28
+ */
29
+ export declare function snapshotOf<S>(ref: AggregateRef, state: S, overrides?: Partial<Omit<Snapshot<S>, 'tenantId' | 'aggregateId' | 'state'>>): Snapshot<S>;
@@ -0,0 +1,29 @@
1
+ import { Problem } from '../problem.js';
2
+ import { AggregateRef, CommandResult, Snapshot } from '../wire.js';
3
+ /**
4
+ * A command's result as a service answers it, for a test's fake: the command
5
+ * `ref` names, committed (`succeeded` at `committed`, version 1) unless
6
+ * `overrides` says otherwise. A `rejected` or `failed` one without an `error`
7
+ * carries `wow.command.refused` or `wow.command.failed`.
8
+ */
9
+ export declare function commandResultOf<R = Record<string, unknown>>(ref: AggregateRef, overrides?: Partial<CommandResult<R>>): CommandResult<R>;
10
+ /**
11
+ * An RFC 9457 problem as a service answers it, of `status` and the Wow `code`
12
+ * (`urn:wow:error:<code>`; `about:blank` without one), for a test's fake or
13
+ * an expected error. Its title is the status's reason phrase unless
14
+ * `overrides` says otherwise.
15
+ */
16
+ export declare function problemOf(status: number, code?: string, overrides?: Partial<Problem>): Problem;
17
+ /**
18
+ * The response a service answers `problem` with: `application/problem+json`,
19
+ * its extension members written as members of their own, as the wire carries
20
+ * them.
21
+ */
22
+ export declare function problemResponse(problem: Problem, init?: ResponseInit): Response;
23
+ /**
24
+ * An aggregate's snapshot as a state read and a snapshot query answer it, for
25
+ * a test's fake: `ref`'s `state` at version 1, committed at 0 by an anonymous
26
+ * caller, of no owner or space, not deleted, untagged and keeping no
27
+ * schedules unless `overrides` says otherwise.
28
+ */
29
+ export declare function snapshotOf<S>(ref: AggregateRef, state: S, overrides?: Partial<Omit<Snapshot<S>, 'tenantId' | 'aggregateId' | 'state'>>): Snapshot<S>;
@@ -0,0 +1,88 @@
1
+ import { FrameworkErrorCodes as e } from "../frameworkErrors.es.js";
2
+ import { CommandResultStatus as t, FunctionKind as n, Stage as r } from "../wire.es.js";
3
+ // src/testing/wire.ts
4
+ function i(i, a = {}) {
5
+ let { context: o, name: s } = i.type, c = a.status ?? t.SUCCEEDED, l = a.commandId ?? "command-1";
6
+ return {
7
+ format: 1,
8
+ commandId: l,
9
+ requestId: "request-1",
10
+ correlationId: l,
11
+ ref: i,
12
+ hop: {
13
+ stage: r.COMMITTED,
14
+ context: o
15
+ },
16
+ function: {
17
+ kind: n.COMMAND,
18
+ context: o,
19
+ processor: s,
20
+ name: "Command"
21
+ },
22
+ status: c,
23
+ version: 1,
24
+ duplicate: !1,
25
+ error: c === t.SUCCEEDED ? null : {
26
+ code: c === t.REJECTED ? e.COMMAND_REFUSED : e.COMMAND_FAILED,
27
+ message: `The command was ${c.toLowerCase()}.`
28
+ },
29
+ results: {},
30
+ derived: [],
31
+ signalTime: 0,
32
+ ...a
33
+ };
34
+ }
35
+ var a = {
36
+ 400: "Bad Request",
37
+ 401: "Unauthorized",
38
+ 403: "Forbidden",
39
+ 404: "Not Found",
40
+ 409: "Conflict",
41
+ 410: "Gone",
42
+ 412: "Precondition Failed",
43
+ 429: "Too Many Requests",
44
+ 500: "Internal Server Error",
45
+ 503: "Service Unavailable",
46
+ 504: "Gateway Timeout"
47
+ };
48
+ function o(e, t, n = {}) {
49
+ return {
50
+ type: t === void 0 ? "about:blank" : `urn:wow:error:${t}`,
51
+ title: a[e] ?? `HTTP ${e}`,
52
+ status: e,
53
+ ...t === void 0 ? {} : { code: t },
54
+ ...n
55
+ };
56
+ }
57
+ function s(e, t = {}) {
58
+ let { extensions: n, ...r } = e, i = new Headers(t.headers);
59
+ return i.set("Content-Type", "application/problem+json"), new Response(JSON.stringify({
60
+ ...n,
61
+ ...r
62
+ }), {
63
+ ...t,
64
+ status: e.status,
65
+ headers: i
66
+ });
67
+ }
68
+ function c(e, t, n = {}) {
69
+ return {
70
+ tenantId: e.tenantId,
71
+ aggregateId: e.id,
72
+ version: 1,
73
+ ownerId: null,
74
+ spaceId: null,
75
+ deleted: !1,
76
+ tags: {},
77
+ firstEventTime: 0,
78
+ lastEventTime: 0,
79
+ operator: null,
80
+ firstOperator: null,
81
+ schedules: {},
82
+ state: t,
83
+ ...n
84
+ };
85
+ }
86
+ export { i as commandResultOf, o as problemOf, s as problemResponse, c as snapshotOf };
87
+
88
+ //# sourceMappingURL=wire.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.es.js","names":["commandResultOf","ref","status","overrides","CommandResultStatus","commandId","Stage","FunctionKind","name","FrameworkErrorCodes","TITLES","problemOf","code","problemResponse","members","problem","headers","init","extensions","snapshotOf"],"sources":["../../src/testing/wire.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { FrameworkErrorCodes, type Problem } from '../problem.js';\nimport {\n type AggregateRef,\n type CommandResult,\n CommandResultStatus,\n FunctionKind,\n Stage,\n type Snapshot,\n} from '../wire.js';\n\n/**\n * A command's result as a service answers it, for a test's fake: the command\n * `ref` names, committed (`succeeded` at `committed`, version 1) unless\n * `overrides` says otherwise. A `rejected` or `failed` one without an `error`\n * carries `wow.command.refused` or `wow.command.failed`.\n */\nexport function commandResultOf<R = Record<string, unknown>>(\n ref: AggregateRef,\n overrides: Partial<CommandResult<R>> = {},\n): CommandResult<R> {\n const { context, name } = ref.type;\n const status = overrides.status ?? CommandResultStatus.SUCCEEDED;\n const commandId = overrides.commandId ?? 'command-1';\n return {\n format: 1,\n commandId,\n requestId: 'request-1',\n correlationId: commandId,\n ref,\n hop: { stage: Stage.COMMITTED, context },\n function: {\n kind: FunctionKind.COMMAND,\n context,\n processor: name,\n name: 'Command',\n },\n status,\n version: 1,\n duplicate: false,\n error:\n status === CommandResultStatus.SUCCEEDED\n ? null\n : {\n code:\n status === CommandResultStatus.REJECTED\n ? FrameworkErrorCodes.COMMAND_REFUSED\n : FrameworkErrorCodes.COMMAND_FAILED,\n message: `The command was ${status.toLowerCase()}.`,\n },\n results: {} as R,\n derived: [],\n signalTime: 0,\n ...overrides,\n };\n}\n\n/** The reason phrases of the statuses a Wow service answers a problem with. */\nconst TITLES: Readonly<Record<number, string>> = {\n 400: 'Bad Request',\n 401: 'Unauthorized',\n 403: 'Forbidden',\n 404: 'Not Found',\n 409: 'Conflict',\n 410: 'Gone',\n 412: 'Precondition Failed',\n 429: 'Too Many Requests',\n 500: 'Internal Server Error',\n 503: 'Service Unavailable',\n 504: 'Gateway Timeout',\n};\n\n/**\n * An RFC 9457 problem as a service answers it, of `status` and the Wow `code`\n * (`urn:wow:error:<code>`; `about:blank` without one), for a test's fake or\n * an expected error. Its title is the status's reason phrase unless\n * `overrides` says otherwise.\n */\nexport function problemOf(\n status: number,\n code?: string,\n overrides: Partial<Problem> = {},\n): Problem {\n return {\n type: code === undefined ? 'about:blank' : `urn:wow:error:${code}`,\n title: TITLES[status] ?? `HTTP ${status}`,\n status,\n ...(code === undefined ? {} : { code }),\n ...overrides,\n };\n}\n\n/**\n * The response a service answers `problem` with: `application/problem+json`,\n * its extension members written as members of their own, as the wire carries\n * them.\n */\nexport function problemResponse(\n problem: Problem,\n init: ResponseInit = {},\n): Response {\n const { extensions, ...members } = problem;\n const headers = new Headers(init.headers);\n headers.set('Content-Type', 'application/problem+json');\n return new Response(JSON.stringify({ ...extensions, ...members }), {\n ...init,\n status: problem.status,\n headers,\n });\n}\n\n/**\n * An aggregate's snapshot as a state read and a snapshot query answer it, for\n * a test's fake: `ref`'s `state` at version 1, committed at 0 by an anonymous\n * caller, of no owner or space, not deleted, untagged and keeping no\n * schedules unless `overrides` says otherwise.\n */\nexport function snapshotOf<S>(\n ref: AggregateRef,\n state: S,\n overrides: Partial<\n Omit<Snapshot<S>, 'tenantId' | 'aggregateId' | 'state'>\n > = {},\n): Snapshot<S> {\n return {\n tenantId: ref.tenantId,\n aggregateId: ref.id,\n version: 1,\n ownerId: null,\n spaceId: null,\n deleted: false,\n tags: {},\n firstEventTime: 0,\n lastEventTime: 0,\n operator: null,\n firstOperator: null,\n schedules: {},\n state,\n ...overrides,\n };\n}\n"],"mappings":";;;AA6BA,SAAgBA,EACd,GACA,IAAuC,CAAC,GACtB;CAClB,IAAM,EAAE,YAAS,YAASC,EAAI,MACxBC,IAASC,EAAU,UAAUC,EAAoB,WACjDC,IAAYF,EAAU,aAAa;CACzC,OAAO;EACL,QAAQ;EACR;EACA,WAAW;EACX,eAAeE;EACf;EACA,KAAK;GAAE,OAAOC,EAAM;GAAW;EAAQ;EACvC,UAAU;GACR,MAAMC,EAAa;GACnB;GACA,WAAWC;GACX,MAAM;EACR;EACA;EACA,SAAS;EACT,WAAW;EACX,OACEN,MAAWE,EAAoB,YAC3B,OACA;GACE,MACEF,MAAWE,EAAoB,WAC3BK,EAAoB,kBACpBA,EAAoB;GAC1B,SAAS,mBAAmBP,EAAO,YAAY,EAAE;EACnD;EACN,SAAS,CAAC;EACV,SAAS,CAAC;EACV,YAAY;EACZ,GAAGC;CACL;AACF;AAGA,IAAMO,IAA2C;CAC/C,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;CACL,KAAK;AACP;AAQA,SAAgBC,EACd,GACA,GACA,IAA8B,CAAC,GACtB;CACT,OAAO;EACL,MAAMC,MAAS,KAAA,IAAY,gBAAgB,iBAAiBA;EAC5D,OAAOF,EAAOR,MAAW,QAAQA;EACjC;EACA,GAAIU,MAAS,KAAA,IAAY,CAAC,IAAI,EAAE,QAAK;EACrC,GAAGT;CACL;AACF;AAOA,SAAgBU,EACd,GACA,IAAqB,CAAC,GACZ;CACV,IAAM,EAAE,eAAY,GAAGC,MAAYC,GAC7BC,IAAU,IAAI,QAAQC,EAAK,OAAO;CAExC,OADAD,EAAQ,IAAI,gBAAgB,0BAA0B,GAC/C,IAAI,SAAS,KAAK,UAAU;EAAE,GAAGE;EAAY,GAAGJ;CAAQ,CAAC,GAAG;EACjE,GAAGG;EACH,QAAQF,EAAQ;EAChB;CACF,CAAC;AACH;AAQA,SAAgBI,EACd,GACA,GACA,IAEI,CAAC,GACQ;CACb,OAAO;EACL,UAAUlB,EAAI;EACd,aAAaA,EAAI;EACjB,SAAS;EACT,SAAS;EACT,SAAS;EACT,SAAS;EACT,MAAM,CAAC;EACP,gBAAgB;EAChB,eAAe;EACf,UAAU;EACV,eAAe;EACf,WAAW,CAAC;EACZ;EACA,GAAGE;CACL;AACF"}
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./developmentCaller.cjs"),t=require("./testing/wire.cjs");exports.DevelopmentCallerHeaders=e.DevelopmentCallerHeaders,exports.commandResultOf=t.commandResultOf,exports.developmentCaller=e.developmentCaller,exports.developmentCallerHeaders=e.developmentCallerHeaders,exports.problemOf=t.problemOf,exports.problemResponse=t.problemResponse,exports.snapshotOf=t.snapshotOf;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@ahoo-wang/wow-client/testing`: what a test of code that talks to a Wow
3
+ * service builds on — a caller of a development run
4
+ * ({@link developmentCaller}, the {@link DevelopmentCallerHeaders} it sends,
5
+ * both of the root entry too), and the service's answers for a fake: {@link commandResultOf},
6
+ * {@link problemOf} and {@link problemResponse}, {@link snapshotOf}.
7
+ *
8
+ * It loads no test framework, so any runner (or a story, or a local tool)
9
+ * imports it.
10
+ */
11
+ export { type DevelopmentCaller, developmentCaller, developmentCallerHeaders, DevelopmentCallerHeaders, } from './developmentCaller.cjs';
12
+ export { commandResultOf, problemOf, problemResponse, snapshotOf, } from './testing/wire.cjs';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * `@ahoo-wang/wow-client/testing`: what a test of code that talks to a Wow
3
+ * service builds on — a caller of a development run
4
+ * ({@link developmentCaller}, the {@link DevelopmentCallerHeaders} it sends,
5
+ * both of the root entry too), and the service's answers for a fake: {@link commandResultOf},
6
+ * {@link problemOf} and {@link problemResponse}, {@link snapshotOf}.
7
+ *
8
+ * It loads no test framework, so any runner (or a story, or a local tool)
9
+ * imports it.
10
+ */
11
+ export { type DevelopmentCaller, developmentCaller, developmentCallerHeaders, DevelopmentCallerHeaders, } from './developmentCaller.js';
12
+ export { commandResultOf, problemOf, problemResponse, snapshotOf, } from './testing/wire.js';
@@ -0,0 +1,3 @@
1
+ import { DevelopmentCallerHeaders as e, developmentCaller as t, developmentCallerHeaders as n } from "./developmentCaller.es.js";
2
+ import { commandResultOf as r, problemOf as i, problemResponse as a, snapshotOf as o } from "./testing/wire.es.js";
3
+ export { e as DevelopmentCallerHeaders, r as commandResultOf, t as developmentCaller, n as developmentCallerHeaders, i as problemOf, a as problemResponse, o as snapshotOf };
package/dist/wait.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./wire.cjs");var t=`snapshot`,n=/^[A-Za-z0-9_.-]+$/;function r(e,t){if(!n.test(t))throw TypeError(`Not a ${e} name: '${t}'.`);return t}function i(e,t,n){return{stage:e,...t===void 0?{}:{context:r(`context`,t)},...n===void 0?{}:{subscription:r(`subscription`,n)}}}var a={accepted:t=>i(e.Stage.ACCEPTED,t),committed:t=>i(e.Stage.COMMITTED,t),snapshot:n=>i(e.Stage.HANDLED,n,t),handled:(t,n)=>i(e.Stage.HANDLED,n,t)};function o(t){let n=t.context??void 0,r=t.subscription??void 0;if(t.stage===e.Stage.HANDLED){if(r===void 0)throw TypeError(`A HANDLED hop names its subscription.`);return r===`snapshot`?n===void 0?`snapshot`:`snapshot(${n})`:n===void 0?`handled(${r})`:`handled(${n}/${r})`}if(r!==void 0)throw TypeError(`Only a HANDLED hop names a subscription.`);let i=t.stage.toLowerCase();return n===void 0?i:`${i}(${n})`}function s(e){if(typeof e==`string`)return e;if(e.length===0)throw TypeError(`A wait plan has at least one hop.`);return e.map(o).join(` > `)}function c(e){if(typeof e==`string`)return e;if(!Number.isInteger(e)||e<=0)throw TypeError(`A wait timeout is a positive whole number of milliseconds: ${e}.`);return e%1e3==0?`${e/1e3}s`:`${e}ms`}exports.SNAPSHOT_SUBSCRIPTION=t,exports.formatHop=o,exports.formatWaitPlan=s,exports.formatWaitTimeout=c,exports.wait=a;
1
+ const e=require("./wire.cjs");var t=`wow.snapshot`,n=/^[A-Za-z0-9_.-]+$/;function r(e,t){if(!n.test(t))throw TypeError(`Not a ${e} name: '${t}'.`);return t}function i(e,t,n){return{stage:e,...t===void 0?{}:{context:r(`context`,t)},...n===void 0?{}:{subscription:r(`subscription`,n)}}}var a={accepted:t=>i(e.Stage.ACCEPTED,t),committed:t=>i(e.Stage.COMMITTED,t),snapshot:n=>i(e.Stage.HANDLED,n,t),handled:(t,n)=>i(e.Stage.HANDLED,n,t)};function o(t){let n=t.context??void 0,r=t.subscription??void 0;if(t.stage===e.Stage.HANDLED){if(r===void 0)throw TypeError(`A handled hop names its subscription.`);return r===`wow.snapshot`?n===void 0?`snapshot`:`snapshot(${n})`:n===void 0?`handled(${r})`:`handled(${n}/${r})`}if(r!==void 0)throw TypeError(`Only a handled hop names a subscription.`);let i=t.stage.toLowerCase();return n===void 0?i:`${i}(${n})`}var s=class e{static{this.DEFAULT_TIMEOUT=1e4}static{this.DEFAULT=new e([a.snapshot()],void 0,!0)}static{this.SNAPSHOT=new e([a.snapshot()])}static{this.COMMITTED=new e([a.committed()])}static{this.ACCEPTED=new e([a.accepted()])}static of(...t){return new e(t)}constructor(t,n=e.DEFAULT_TIMEOUT,r=!1){if(t.length===0)throw TypeError(`A wait plan has at least one hop.`);p(n),this.hops=Object.freeze([...t]),this.timeout=n,this.isDefault=r,Object.freeze(this)}within(t){return new e(this.hops,t,this.isDefault)}};function c(e){return e.hops.map(o).join(` > `)}var l=/^([A-Za-z]+)\s*(?:\(\s*([^()]*?)\s*\))?$/;function u(e){if(e.trim()===``)throw TypeError(`A wait plan has at least one hop.`);return s.of(...e.split(`>`).map(e=>d(e.trim())))}function d(e){let t=l.exec(e);if(t===null)throw TypeError(`Not a hop: '${e}'.`);let n=t[1].toLowerCase(),r=t[2];switch(n){case`accepted`:return a.accepted(r);case`committed`:return a.committed(r);case`snapshot`:return a.snapshot(r);case`handled`:{if(r===void 0)throw TypeError(`A handled hop names its subscription: '${e}'.`);let t=r.split(`/`);if(t.length>2)throw TypeError(`A handled hop is (subscription) or (context/subscription): '${r}'.`);return t.length===1?a.handled(t[0]):a.handled(t[1].trim(),t[0].trim())}default:throw TypeError(`Not a stage: '${n}'.`)}}function f(e){return p(e),e%1e3==0?`${e/1e3}s`:`${e}ms`}function p(e){if(!Number.isInteger(e)||e<=0)throw TypeError(`A wait timeout is a positive whole number of milliseconds: ${e}.`)}exports.SNAPSHOT_SUBSCRIPTION=t,exports.WaitPlan=s,exports.formatHop=o,exports.formatWaitPlan=c,exports.formatWaitTimeout=f,exports.parseHop=d,exports.parseWaitPlan=u,exports.wait=a;
2
2
  //# sourceMappingURL=wait.cjs.map
package/dist/wait.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"wait.cjs","names":["Stage","require_wire","SNAPSHOT_SUBSCRIPTION","NAME","checkName","value","kind","hop","context","subscription","wait","formatHop","keyword","formatWaitPlan","plan","formatWaitTimeout","timeout"],"sources":["../src/wait.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { type Hop, Stage } from './wire.js';\n\n/** The name of the built-in subscription that writes snapshots. */\nexport const SNAPSHOT_SUBSCRIPTION = 'snapshot';\n\nconst NAME = /^[A-Za-z0-9_.-]+$/;\n\nfunction checkName(kind: string, value: string): string {\n if (!NAME.test(value)) {\n throw new TypeError(`Not a ${kind} name: '${value}'.`);\n }\n return value;\n}\n\nfunction hop(stage: Stage, context?: string, subscription?: string): Hop {\n return {\n stage,\n ...(context === undefined\n ? {}\n : { context: checkName('context', context) }),\n ...(subscription === undefined\n ? {}\n : { subscription: checkName('subscription', subscription) }),\n };\n}\n\n/**\n * Builds the hops of a wait chain (decisions D62, D99). A context left out is\n * the command's own. A saga's `handled` hop may be followed by hops of the\n * commands it derived, in their contexts:\n *\n * @example\n * ```typescript\n * const plan = [\n * wait.committed(),\n * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),\n * wait.committed('eshop-ordering'),\n * ];\n * ```\n */\nexport const wait = {\n /** Until the command passed admission; the route answers 202. */\n accepted: (context?: string): Hop => hop(Stage.ACCEPTED, context),\n /** Until the command's events are appended to the log. */\n committed: (context?: string): Hop => hop(Stage.COMMITTED, context),\n /** Until the snapshot holds the commit: the caller reads its own write. */\n snapshot: (context?: string): Hop =>\n hop(Stage.HANDLED, context, SNAPSHOT_SUBSCRIPTION),\n /** Until the subscription named `processor.function` handled the commit. */\n handled: (subscription: string, context?: string): Hop =>\n hop(Stage.HANDLED, context, subscription),\n} as const;\n\n/**\n * A hop as `Wow-Wait` spells it: `accepted`, `committed`, `snapshot` and\n * `handled(subscription)`, each with its context when it has one:\n * `committed(ctx)`, `snapshot(ctx)`, `handled(ctx/subscription)`.\n *\n * @param value - The hop\n */\nexport function formatHop(value: Hop): string {\n const context = value.context ?? undefined;\n const subscription = value.subscription ?? undefined;\n if (value.stage === Stage.HANDLED) {\n if (subscription === undefined) {\n throw new TypeError('A HANDLED hop names its subscription.');\n }\n if (subscription === SNAPSHOT_SUBSCRIPTION) {\n return context === undefined ? 'snapshot' : `snapshot(${context})`;\n }\n return context === undefined\n ? `handled(${subscription})`\n : `handled(${context}/${subscription})`;\n }\n if (subscription !== undefined) {\n throw new TypeError(`Only a HANDLED hop names a subscription.`);\n }\n const keyword = value.stage.toLowerCase();\n return context === undefined ? keyword : `${keyword}(${context})`;\n}\n\n/**\n * A wait plan as the `Wow-Wait` header spells it: its hops, in order,\n * separated by `>`. A string is taken as already spelled.\n *\n * @param plan - The hops, or the header's value\n */\nexport function formatWaitPlan(plan: readonly Hop[] | string): string {\n if (typeof plan === 'string') return plan;\n if (plan.length === 0) {\n throw new TypeError('A wait plan has at least one hop.');\n }\n return plan.map(formatHop).join(' > ');\n}\n\n/**\n * A wait timeout as the `Wow-Wait-Timeout` header spells it: milliseconds\n * as `<n>s` when whole seconds, else `<n>ms`. A string (`10s`, `PT10S`) is\n * taken as already spelled.\n *\n * @param timeout - Milliseconds, or the header's value\n */\nexport function formatWaitTimeout(timeout: number | string): string {\n if (typeof timeout === 'string') return timeout;\n if (!Number.isInteger(timeout) || timeout <= 0) {\n throw new TypeError(\n `A wait timeout is a positive whole number of milliseconds: ${timeout}.`,\n );\n }\n return timeout % 1000 === 0 ? `${timeout / 1000}s` : `${timeout}ms`;\n}\n\n/**\n * What a command waits for (`Wow-Wait`, `Wow-Wait-Timeout`). Without either,\n * the server waits for the snapshot, or for the commit where the aggregate\n * keeps no snapshot (decision D69), within its default timeout.\n */\nexport interface WaitOptions {\n /** The hops, or the `Wow-Wait` value. */\n readonly plan?: readonly Hop[] | string;\n /** Milliseconds, or the `Wow-Wait-Timeout` value. */\n readonly timeout?: number | string;\n}\n"],"mappings":"8BAgBA,IAAaE,EAAwB,WAE/BC,EAAO,oBAEb,SAASC,EAAU,EAAc,EAAuB,CACtD,GAAI,CAACD,EAAK,KAAKE,CAAK,EAClB,MAAU,UAAU,SAASC,EAAK,UAAUD,EAAM,GAAG,EAEvD,OAAOA,CACT,CAEA,SAASE,EAAI,EAAc,EAAkB,EAA4B,CACvE,MAAO,CACL,QACA,GAAIC,IAAY,IAAA,GACZ,CAAC,EACD,CAAE,QAASJ,EAAU,UAAWI,CAAO,CAAE,EAC7C,GAAIC,IAAiB,IAAA,GACjB,CAAC,EACD,CAAE,aAAcL,EAAU,eAAgBK,CAAY,CAAE,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s","names":["Stage","require_wire","SNAPSHOT_SUBSCRIPTION","NAME","checkName","value","kind","hop","context","subscription","wait","formatHop","keyword","WaitPlan","hops","checkTimeout","timeout","isDefault","formatWaitPlan","plan","HOP","parseWaitPlan","parseHop","part","match","argument","parts","formatWaitTimeout"],"sources":["../src/wait.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { type Hop, Stage } from './wire.js';\n\n/** The name of the built-in subscription that writes snapshots. */\nexport const SNAPSHOT_SUBSCRIPTION = 'wow.snapshot';\n\nconst NAME = /^[A-Za-z0-9_.-]+$/;\n\nfunction checkName(kind: string, value: string): string {\n if (!NAME.test(value)) {\n throw new TypeError(`Not a ${kind} name: '${value}'.`);\n }\n return value;\n}\n\nfunction hop(stage: Stage, context?: string, subscription?: string): Hop {\n return {\n stage,\n ...(context === undefined\n ? {}\n : { context: checkName('context', context) }),\n ...(subscription === undefined\n ? {}\n : { subscription: checkName('subscription', subscription) }),\n };\n}\n\n/**\n * Builds the hops of a wait chain. A context left out is\n * the command's own. A saga's `handled` hop may be followed by hops of the\n * commands it derived, in their contexts:\n *\n * @example\n * ```typescript\n * const plan = [\n * wait.committed(),\n * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),\n * wait.committed('eshop-ordering'),\n * ];\n * ```\n */\nexport const wait = {\n /** Until the command passed admission; the route answers 202. */\n accepted: (context?: string): Hop => hop(Stage.ACCEPTED, context),\n /** Until the command's events are appended to the log. */\n committed: (context?: string): Hop => hop(Stage.COMMITTED, context),\n /** Until the snapshot holds the commit: the caller reads its own write. */\n snapshot: (context?: string): Hop =>\n hop(Stage.HANDLED, context, SNAPSHOT_SUBSCRIPTION),\n /** Until the subscription named `processor.function` handled the commit. */\n handled: (subscription: string, context?: string): Hop =>\n hop(Stage.HANDLED, context, subscription),\n} as const;\n\n/**\n * A hop as `Wow-Wait` spells it: `accepted`, `committed`, `snapshot` and\n * `handled(subscription)`, each with its context when it has one:\n * `committed(ctx)`, `snapshot(ctx)`, `handled(ctx/subscription)`.\n *\n * @param value - The hop\n */\nexport function formatHop(value: Hop): string {\n const context = value.context ?? undefined;\n const subscription = value.subscription ?? undefined;\n if (value.stage === Stage.HANDLED) {\n if (subscription === undefined) {\n throw new TypeError('A handled hop names its subscription.');\n }\n if (subscription === SNAPSHOT_SUBSCRIPTION) {\n return context === undefined ? 'snapshot' : `snapshot(${context})`;\n }\n return context === undefined\n ? `handled(${subscription})`\n : `handled(${context}/${subscription})`;\n }\n if (subscription !== undefined) {\n throw new TypeError(`Only a handled hop names a subscription.`);\n }\n const keyword = value.stage.toLowerCase();\n return context === undefined ? keyword : `${keyword}(${context})`;\n}\n\n/**\n * How far a command is waited for, and for how long: the hops, in order, and\n * a timeout in milliseconds. Kotlin's `me.ahoo.wow.api.result.WaitPlan`,\n * with its constants and constructors: {@link WaitPlan.of} the hops a\n * {@link wait} builder makes, {@link WaitPlan.within} another timeout.\n *\n * @example\n * ```typescript\n * const plan = WaitPlan.of(\n * wait.committed(),\n * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),\n * ).within(30_000);\n * ```\n */\nexport class WaitPlan {\n /** The timeout of a wait whose caller gives none: 10 seconds. */\n static readonly DEFAULT_TIMEOUT = 10_000;\n\n /**\n * The plan of a caller that asked for none: until the snapshot holds the\n * commit, so the caller reads its own write; until `committed` for an\n * aggregate without a snapshot subscription. A request with it sends no\n * `Wow-Wait`, so the service picks.\n */\n static readonly DEFAULT = new WaitPlan([wait.snapshot()], undefined, true);\n\n /**\n * Until the snapshot holds the commit, asked for explicitly: rejected at\n * admission for an aggregate without a snapshot subscription.\n */\n static readonly SNAPSHOT = new WaitPlan([wait.snapshot()]);\n\n /** Until the events are appended. */\n static readonly COMMITTED = new WaitPlan([wait.committed()]);\n\n /** Until the command passed admission. */\n static readonly ACCEPTED = new WaitPlan([wait.accepted()]);\n\n /** Until `hops` are reached, in order. */\n static of(...hops: Hop[]): WaitPlan {\n return new WaitPlan(hops);\n }\n\n /** The hops to reach, in order; at least one. */\n readonly hops: readonly Hop[];\n /** How long to wait, in milliseconds. */\n readonly timeout: number;\n /** Whether this is {@link WaitPlan.DEFAULT}, the service's choice. */\n readonly isDefault: boolean;\n\n private constructor(\n hops: readonly Hop[],\n timeout: number = WaitPlan.DEFAULT_TIMEOUT,\n isDefault = false,\n ) {\n if (hops.length === 0) {\n throw new TypeError('A wait plan has at least one hop.');\n }\n checkTimeout(timeout);\n this.hops = Object.freeze([...hops]);\n this.timeout = timeout;\n this.isDefault = isDefault;\n Object.freeze(this);\n }\n\n /** This plan, waiting `timeout` milliseconds. */\n within(timeout: number): WaitPlan {\n return new WaitPlan(this.hops, timeout, this.isDefault);\n }\n}\n\n/**\n * A wait plan as the `Wow-Wait` header spells it: its hops, in order,\n * separated by `>`; the inverse of {@link parseWaitPlan}.\n *\n * @param plan - The plan\n */\nexport function formatWaitPlan(plan: WaitPlan): string {\n return plan.hops.map(formatHop).join(' > ');\n}\n\nconst HOP = /^([A-Za-z]+)\\s*(?:\\(\\s*([^()]*?)\\s*\\))?$/;\n\n/**\n * The plan a `Wow-Wait` value spells, as the service reads it: hops\n * separated by `>`, each `accepted`, `committed`, `snapshot` or\n * `handled(subscription)`, with its context in parentheses\n * (`committed(ctx)`, `handled(ctx/subscription)`); the inverse of\n * {@link formatWaitPlan}. Throws a `TypeError` for anything else.\n *\n * @param value - The header's value\n */\nexport function parseWaitPlan(value: string): WaitPlan {\n if (value.trim() === '') {\n throw new TypeError('A wait plan has at least one hop.');\n }\n return WaitPlan.of(...value.split('>').map(part => parseHop(part.trim())));\n}\n\n/**\n * The hop one part of a `Wow-Wait` value spells; see {@link parseWaitPlan}.\n *\n * @param value - The part, such as `committed(ctx)`\n */\nexport function parseHop(value: string): Hop {\n const match = HOP.exec(value);\n if (match === null) throw new TypeError(`Not a hop: '${value}'.`);\n const keyword = match[1].toLowerCase();\n const argument = match[2];\n switch (keyword) {\n case 'accepted':\n return wait.accepted(argument);\n case 'committed':\n return wait.committed(argument);\n case 'snapshot':\n return wait.snapshot(argument);\n case 'handled': {\n if (argument === undefined) {\n throw new TypeError(\n `A handled hop names its subscription: '${value}'.`,\n );\n }\n const parts = argument.split('/');\n if (parts.length > 2) {\n throw new TypeError(\n `A handled hop is (subscription) or (context/subscription): '${argument}'.`,\n );\n }\n return parts.length === 1\n ? wait.handled(parts[0])\n : wait.handled(parts[1].trim(), parts[0].trim());\n }\n default:\n throw new TypeError(`Not a stage: '${keyword}'.`);\n }\n}\n\n/**\n * A wait timeout as the `Wow-Wait-Timeout` header spells it: milliseconds\n * as `<n>s` when whole seconds, else `<n>ms`.\n *\n * @param timeout - Milliseconds\n */\nexport function formatWaitTimeout(timeout: number): string {\n checkTimeout(timeout);\n return timeout % 1000 === 0 ? `${timeout / 1000}s` : `${timeout}ms`;\n}\n\nfunction checkTimeout(timeout: number): void {\n if (!Number.isInteger(timeout) || timeout <= 0) {\n throw new TypeError(\n `A wait timeout is a positive whole number of milliseconds: ${timeout}.`,\n );\n }\n}\n"],"mappings":"A,8BAgBA,IAAaE,EAAwB,eAE/BC,EAAO,oBAEb,SAASC,EAAU,EAAc,EAAuB,CACtD,GAAI,CAACD,EAAK,KAAKE,CAAK,EAClB,MAAU,UAAU,SAASC,EAAK,UAAUD,EAAM,GAAG,EAEvD,OAAOA,CACT,CAEA,SAASE,EAAI,EAAc,EAAkB,EAA4B,CACvE,MAAO,CACL,QACA,GAAIC,IAAY,IAAA,GACZ,CAAC,EACD,CAAE,QAASJ,EAAU,UAAWI,CAAO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,EAAS,GAC1E,EAEF,OAAOC,EAAM,SAAW,EACpBhB,EAAK,QAAQgB,EAAM,EAAE,EACrBhB,EAAK,QAAQgB,EAAM,EAAE,CAAC,KAAK,EAAGA,EAAM,EAAE,CAAC,KAAK,CAAC,CACnD,CACA,QACE,MAAU,UAAU,iBAAiBd,EAAQ,GAAG,CACpD,CACF,CAQA,SAAgBe,EAAkB,EAAyB,CAEzD,OADAZ,EAAaC,CAAO,EACbA,EAAU,KAAS,EAAI,GAAGA,EAAU,IAAK,GAAK,GAAGA,EAAQ,GAClE,CAEA,SAASD,EAAa,EAAuB,CAC3C,GAAI,CAAC,OAAO,UAAUC,CAAO,GAAKA,GAAW,EAC3C,MAAU,UACR,8DAA8DA,EAAQ,EACxE,CAEJ,C"}
package/dist/wait.d.cts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Hop } from './wire.cjs';
2
2
  /** The name of the built-in subscription that writes snapshots. */
3
- export declare const SNAPSHOT_SUBSCRIPTION = "snapshot";
3
+ export declare const SNAPSHOT_SUBSCRIPTION = "wow.snapshot";
4
4
  /**
5
- * Builds the hops of a wait chain (decisions D62, D99). A context left out is
5
+ * Builds the hops of a wait chain. A context left out is
6
6
  * the command's own. A saga's `handled` hop may be followed by hops of the
7
7
  * commands it derived, in their contexts:
8
8
  *
@@ -33,29 +33,78 @@ export declare const wait: {
33
33
  * @param value - The hop
34
34
  */
35
35
  export declare function formatHop(value: Hop): string;
36
+ /**
37
+ * How far a command is waited for, and for how long: the hops, in order, and
38
+ * a timeout in milliseconds. Kotlin's `me.ahoo.wow.api.result.WaitPlan`,
39
+ * with its constants and constructors: {@link WaitPlan.of} the hops a
40
+ * {@link wait} builder makes, {@link WaitPlan.within} another timeout.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const plan = WaitPlan.of(
45
+ * wait.committed(),
46
+ * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),
47
+ * ).within(30_000);
48
+ * ```
49
+ */
50
+ export declare class WaitPlan {
51
+ /** The timeout of a wait whose caller gives none: 10 seconds. */
52
+ static readonly DEFAULT_TIMEOUT = 10000;
53
+ /**
54
+ * The plan of a caller that asked for none: until the snapshot holds the
55
+ * commit, so the caller reads its own write; until `committed` for an
56
+ * aggregate without a snapshot subscription. A request with it sends no
57
+ * `Wow-Wait`, so the service picks.
58
+ */
59
+ static readonly DEFAULT: WaitPlan;
60
+ /**
61
+ * Until the snapshot holds the commit, asked for explicitly: rejected at
62
+ * admission for an aggregate without a snapshot subscription.
63
+ */
64
+ static readonly SNAPSHOT: WaitPlan;
65
+ /** Until the events are appended. */
66
+ static readonly COMMITTED: WaitPlan;
67
+ /** Until the command passed admission. */
68
+ static readonly ACCEPTED: WaitPlan;
69
+ /** Until `hops` are reached, in order. */
70
+ static of(...hops: Hop[]): WaitPlan;
71
+ /** The hops to reach, in order; at least one. */
72
+ readonly hops: readonly Hop[];
73
+ /** How long to wait, in milliseconds. */
74
+ readonly timeout: number;
75
+ /** Whether this is {@link WaitPlan.DEFAULT}, the service's choice. */
76
+ readonly isDefault: boolean;
77
+ private constructor();
78
+ /** This plan, waiting `timeout` milliseconds. */
79
+ within(timeout: number): WaitPlan;
80
+ }
36
81
  /**
37
82
  * A wait plan as the `Wow-Wait` header spells it: its hops, in order,
38
- * separated by `>`. A string is taken as already spelled.
83
+ * separated by `>`; the inverse of {@link parseWaitPlan}.
39
84
  *
40
- * @param plan - The hops, or the header's value
85
+ * @param plan - The plan
41
86
  */
42
- export declare function formatWaitPlan(plan: readonly Hop[] | string): string;
87
+ export declare function formatWaitPlan(plan: WaitPlan): string;
43
88
  /**
44
- * A wait timeout as the `Wow-Wait-Timeout` header spells it: milliseconds
45
- * as `<n>s` when whole seconds, else `<n>ms`. A string (`10s`, `PT10S`) is
46
- * taken as already spelled.
89
+ * The plan a `Wow-Wait` value spells, as the service reads it: hops
90
+ * separated by `>`, each `accepted`, `committed`, `snapshot` or
91
+ * `handled(subscription)`, with its context in parentheses
92
+ * (`committed(ctx)`, `handled(ctx/subscription)`); the inverse of
93
+ * {@link formatWaitPlan}. Throws a `TypeError` for anything else.
47
94
  *
48
- * @param timeout - Milliseconds, or the header's value
95
+ * @param value - The header's value
49
96
  */
50
- export declare function formatWaitTimeout(timeout: number | string): string;
97
+ export declare function parseWaitPlan(value: string): WaitPlan;
51
98
  /**
52
- * What a command waits for (`Wow-Wait`, `Wow-Wait-Timeout`). Without either,
53
- * the server waits for the snapshot, or for the commit where the aggregate
54
- * keeps no snapshot (decision D69), within its default timeout.
99
+ * The hop one part of a `Wow-Wait` value spells; see {@link parseWaitPlan}.
100
+ *
101
+ * @param value - The part, such as `committed(ctx)`
55
102
  */
56
- export interface WaitOptions {
57
- /** The hops, or the `Wow-Wait` value. */
58
- readonly plan?: readonly Hop[] | string;
59
- /** Milliseconds, or the `Wow-Wait-Timeout` value. */
60
- readonly timeout?: number | string;
61
- }
103
+ export declare function parseHop(value: string): Hop;
104
+ /**
105
+ * A wait timeout as the `Wow-Wait-Timeout` header spells it: milliseconds
106
+ * as `<n>s` when whole seconds, else `<n>ms`.
107
+ *
108
+ * @param timeout - Milliseconds
109
+ */
110
+ export declare function formatWaitTimeout(timeout: number): string;
package/dist/wait.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { Hop } from './wire.js';
2
2
  /** The name of the built-in subscription that writes snapshots. */
3
- export declare const SNAPSHOT_SUBSCRIPTION = "snapshot";
3
+ export declare const SNAPSHOT_SUBSCRIPTION = "wow.snapshot";
4
4
  /**
5
- * Builds the hops of a wait chain (decisions D62, D99). A context left out is
5
+ * Builds the hops of a wait chain. A context left out is
6
6
  * the command's own. A saga's `handled` hop may be followed by hops of the
7
7
  * commands it derived, in their contexts:
8
8
  *
@@ -33,29 +33,78 @@ export declare const wait: {
33
33
  * @param value - The hop
34
34
  */
35
35
  export declare function formatHop(value: Hop): string;
36
+ /**
37
+ * How far a command is waited for, and for how long: the hops, in order, and
38
+ * a timeout in milliseconds. Kotlin's `me.ahoo.wow.api.result.WaitPlan`,
39
+ * with its constants and constructors: {@link WaitPlan.of} the hops a
40
+ * {@link wait} builder makes, {@link WaitPlan.within} another timeout.
41
+ *
42
+ * @example
43
+ * ```typescript
44
+ * const plan = WaitPlan.of(
45
+ * wait.committed(),
46
+ * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),
47
+ * ).within(30_000);
48
+ * ```
49
+ */
50
+ export declare class WaitPlan {
51
+ /** The timeout of a wait whose caller gives none: 10 seconds. */
52
+ static readonly DEFAULT_TIMEOUT = 10000;
53
+ /**
54
+ * The plan of a caller that asked for none: until the snapshot holds the
55
+ * commit, so the caller reads its own write; until `committed` for an
56
+ * aggregate without a snapshot subscription. A request with it sends no
57
+ * `Wow-Wait`, so the service picks.
58
+ */
59
+ static readonly DEFAULT: WaitPlan;
60
+ /**
61
+ * Until the snapshot holds the commit, asked for explicitly: rejected at
62
+ * admission for an aggregate without a snapshot subscription.
63
+ */
64
+ static readonly SNAPSHOT: WaitPlan;
65
+ /** Until the events are appended. */
66
+ static readonly COMMITTED: WaitPlan;
67
+ /** Until the command passed admission. */
68
+ static readonly ACCEPTED: WaitPlan;
69
+ /** Until `hops` are reached, in order. */
70
+ static of(...hops: Hop[]): WaitPlan;
71
+ /** The hops to reach, in order; at least one. */
72
+ readonly hops: readonly Hop[];
73
+ /** How long to wait, in milliseconds. */
74
+ readonly timeout: number;
75
+ /** Whether this is {@link WaitPlan.DEFAULT}, the service's choice. */
76
+ readonly isDefault: boolean;
77
+ private constructor();
78
+ /** This plan, waiting `timeout` milliseconds. */
79
+ within(timeout: number): WaitPlan;
80
+ }
36
81
  /**
37
82
  * A wait plan as the `Wow-Wait` header spells it: its hops, in order,
38
- * separated by `>`. A string is taken as already spelled.
83
+ * separated by `>`; the inverse of {@link parseWaitPlan}.
39
84
  *
40
- * @param plan - The hops, or the header's value
85
+ * @param plan - The plan
41
86
  */
42
- export declare function formatWaitPlan(plan: readonly Hop[] | string): string;
87
+ export declare function formatWaitPlan(plan: WaitPlan): string;
43
88
  /**
44
- * A wait timeout as the `Wow-Wait-Timeout` header spells it: milliseconds
45
- * as `<n>s` when whole seconds, else `<n>ms`. A string (`10s`, `PT10S`) is
46
- * taken as already spelled.
89
+ * The plan a `Wow-Wait` value spells, as the service reads it: hops
90
+ * separated by `>`, each `accepted`, `committed`, `snapshot` or
91
+ * `handled(subscription)`, with its context in parentheses
92
+ * (`committed(ctx)`, `handled(ctx/subscription)`); the inverse of
93
+ * {@link formatWaitPlan}. Throws a `TypeError` for anything else.
47
94
  *
48
- * @param timeout - Milliseconds, or the header's value
95
+ * @param value - The header's value
49
96
  */
50
- export declare function formatWaitTimeout(timeout: number | string): string;
97
+ export declare function parseWaitPlan(value: string): WaitPlan;
51
98
  /**
52
- * What a command waits for (`Wow-Wait`, `Wow-Wait-Timeout`). Without either,
53
- * the server waits for the snapshot, or for the commit where the aggregate
54
- * keeps no snapshot (decision D69), within its default timeout.
99
+ * The hop one part of a `Wow-Wait` value spells; see {@link parseWaitPlan}.
100
+ *
101
+ * @param value - The part, such as `committed(ctx)`
55
102
  */
56
- export interface WaitOptions {
57
- /** The hops, or the `Wow-Wait` value. */
58
- readonly plan?: readonly Hop[] | string;
59
- /** Milliseconds, or the `Wow-Wait-Timeout` value. */
60
- readonly timeout?: number | string;
61
- }
103
+ export declare function parseHop(value: string): Hop;
104
+ /**
105
+ * A wait timeout as the `Wow-Wait-Timeout` header spells it: milliseconds
106
+ * as `<n>s` when whole seconds, else `<n>ms`.
107
+ *
108
+ * @param timeout - Milliseconds
109
+ */
110
+ export declare function formatWaitTimeout(timeout: number): string;
package/dist/wait.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Stage as e } from "./wire.es.js";
2
- //#region src/wait.ts
3
- var t = "snapshot", n = /^[A-Za-z0-9_.-]+$/;
2
+ // src/wait.ts
3
+ var t = "wow.snapshot", n = /^[A-Za-z0-9_.-]+$/;
4
4
  function r(e, t) {
5
5
  if (!n.test(t)) throw TypeError(`Not a ${e} name: '${t}'.`);
6
6
  return t;
@@ -21,24 +21,71 @@ var a = {
21
21
  function o(t) {
22
22
  let n = t.context ?? void 0, r = t.subscription ?? void 0;
23
23
  if (t.stage === e.HANDLED) {
24
- if (r === void 0) throw TypeError("A HANDLED hop names its subscription.");
25
- return r === "snapshot" ? n === void 0 ? "snapshot" : `snapshot(${n})` : n === void 0 ? `handled(${r})` : `handled(${n}/${r})`;
24
+ if (r === void 0) throw TypeError("A handled hop names its subscription.");
25
+ return r === "wow.snapshot" ? n === void 0 ? "snapshot" : `snapshot(${n})` : n === void 0 ? `handled(${r})` : `handled(${n}/${r})`;
26
26
  }
27
- if (r !== void 0) throw TypeError("Only a HANDLED hop names a subscription.");
27
+ if (r !== void 0) throw TypeError("Only a handled hop names a subscription.");
28
28
  let i = t.stage.toLowerCase();
29
29
  return n === void 0 ? i : `${i}(${n})`;
30
30
  }
31
- function s(e) {
32
- if (typeof e == "string") return e;
33
- if (e.length === 0) throw TypeError("A wait plan has at least one hop.");
34
- return e.map(o).join(" > ");
35
- }
31
+ var s = class e {
32
+ static {
33
+ this.DEFAULT_TIMEOUT = 1e4;
34
+ }
35
+ static {
36
+ this.DEFAULT = new e([a.snapshot()], void 0, !0);
37
+ }
38
+ static {
39
+ this.SNAPSHOT = new e([a.snapshot()]);
40
+ }
41
+ static {
42
+ this.COMMITTED = new e([a.committed()]);
43
+ }
44
+ static {
45
+ this.ACCEPTED = new e([a.accepted()]);
46
+ }
47
+ static of(...t) {
48
+ return new e(t);
49
+ }
50
+ constructor(t, n = e.DEFAULT_TIMEOUT, r = !1) {
51
+ if (t.length === 0) throw TypeError("A wait plan has at least one hop.");
52
+ p(n), this.hops = Object.freeze([...t]), this.timeout = n, this.isDefault = r, Object.freeze(this);
53
+ }
54
+ within(t) {
55
+ return new e(this.hops, t, this.isDefault);
56
+ }
57
+ };
36
58
  function c(e) {
37
- if (typeof e == "string") return e;
59
+ return e.hops.map(o).join(" > ");
60
+ }
61
+ var l = /^([A-Za-z]+)\s*(?:\(\s*([^()]*?)\s*\))?$/;
62
+ function u(e) {
63
+ if (e.trim() === "") throw TypeError("A wait plan has at least one hop.");
64
+ return s.of(...e.split(">").map((e) => d(e.trim())));
65
+ }
66
+ function d(e) {
67
+ let t = l.exec(e);
68
+ if (t === null) throw TypeError(`Not a hop: '${e}'.`);
69
+ let n = t[1].toLowerCase(), r = t[2];
70
+ switch (n) {
71
+ case "accepted": return a.accepted(r);
72
+ case "committed": return a.committed(r);
73
+ case "snapshot": return a.snapshot(r);
74
+ case "handled": {
75
+ if (r === void 0) throw TypeError(`A handled hop names its subscription: '${e}'.`);
76
+ let t = r.split("/");
77
+ if (t.length > 2) throw TypeError(`A handled hop is (subscription) or (context/subscription): '${r}'.`);
78
+ return t.length === 1 ? a.handled(t[0]) : a.handled(t[1].trim(), t[0].trim());
79
+ }
80
+ default: throw TypeError(`Not a stage: '${n}'.`);
81
+ }
82
+ }
83
+ function f(e) {
84
+ return p(e), e % 1e3 == 0 ? `${e / 1e3}s` : `${e}ms`;
85
+ }
86
+ function p(e) {
38
87
  if (!Number.isInteger(e) || e <= 0) throw TypeError(`A wait timeout is a positive whole number of milliseconds: ${e}.`);
39
- return e % 1e3 == 0 ? `${e / 1e3}s` : `${e}ms`;
40
88
  }
41
- //#endregion
42
- export { t as SNAPSHOT_SUBSCRIPTION, o as formatHop, s as formatWaitPlan, c as formatWaitTimeout, a as wait };
89
+ export { t as SNAPSHOT_SUBSCRIPTION, s as WaitPlan, o as formatHop, c as formatWaitPlan, f as formatWaitTimeout, d as parseHop, u as parseWaitPlan, a as wait };
43
90
 
44
91
  //# sourceMappingURL=wait.es.js.map