@ahoo-wang/wow-client 9.8.0 → 10.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (177) hide show
  1. package/dist/client/query/dataset/datasetDescriptorEndpoint.cjs +2 -0
  2. package/dist/client/query/dataset/datasetDescriptorEndpoint.cjs.map +1 -0
  3. package/dist/client/query/dataset/datasetDescriptorEndpoint.d.cts +8 -0
  4. package/dist/client/query/dataset/datasetDescriptorEndpoint.d.ts +8 -0
  5. package/dist/client/query/dataset/datasetDescriptorEndpoint.es.js +34 -0
  6. package/dist/client/query/dataset/datasetDescriptorEndpoint.es.js.map +1 -0
  7. package/dist/client/query/dataset/datasetDirectoryClient.cjs +2 -0
  8. package/dist/client/query/dataset/datasetDirectoryClient.cjs.map +1 -0
  9. package/dist/client/query/dataset/datasetDirectoryClient.d.cts +29 -0
  10. package/dist/client/query/dataset/datasetDirectoryClient.d.ts +29 -0
  11. package/dist/client/query/dataset/datasetDirectoryClient.es.js +25 -0
  12. package/dist/client/query/dataset/datasetDirectoryClient.es.js.map +1 -0
  13. package/dist/client/query/dataset/datasetQueryApi.d.cts +40 -0
  14. package/dist/client/query/dataset/datasetQueryApi.d.ts +40 -0
  15. package/dist/client/query/dataset/datasetQueryClient.cjs +2 -0
  16. package/dist/client/query/dataset/datasetQueryClient.cjs.map +1 -0
  17. package/dist/client/query/dataset/datasetQueryClient.d.cts +57 -0
  18. package/dist/client/query/dataset/datasetQueryClient.d.ts +57 -0
  19. package/dist/client/query/dataset/datasetQueryClient.es.js +154 -0
  20. package/dist/client/query/dataset/datasetQueryClient.es.js.map +1 -0
  21. package/dist/client/query/dataset/endpointPaths.cjs +2 -0
  22. package/dist/client/query/dataset/endpointPaths.cjs.map +1 -0
  23. package/dist/client/query/dataset/endpointPaths.d.cts +9 -0
  24. package/dist/client/query/dataset/endpointPaths.d.ts +9 -0
  25. package/dist/client/query/dataset/endpointPaths.es.js +14 -0
  26. package/dist/client/query/dataset/endpointPaths.es.js.map +1 -0
  27. package/dist/client/query/dataset/index.d.cts +3 -0
  28. package/dist/client/query/dataset/index.d.ts +3 -0
  29. package/dist/client/query/event/eventStreamQueryApi.d.cts +1 -1
  30. package/dist/client/query/event/eventStreamQueryApi.d.ts +1 -1
  31. package/dist/client/query/event/eventStreamQueryClient.cjs.map +1 -1
  32. package/dist/client/query/event/eventStreamQueryClient.d.cts +4 -1
  33. package/dist/client/query/event/eventStreamQueryClient.d.ts +4 -1
  34. package/dist/client/query/event/eventStreamQueryClient.es.js.map +1 -1
  35. package/dist/client/query/event/index.d.cts +0 -1
  36. package/dist/client/query/event/index.d.ts +0 -1
  37. package/dist/client/query/index.d.cts +1 -0
  38. package/dist/client/query/index.d.ts +1 -0
  39. package/dist/client/query/snapshot/index.d.cts +0 -1
  40. package/dist/client/query/snapshot/index.d.ts +0 -1
  41. package/dist/client/query/snapshot/snapshotQueryApi.d.cts +1 -1
  42. package/dist/client/query/snapshot/snapshotQueryApi.d.ts +1 -1
  43. package/dist/client/query/snapshot/snapshotQueryClient.cjs.map +1 -1
  44. package/dist/client/query/snapshot/snapshotQueryClient.d.cts +4 -1
  45. package/dist/client/query/snapshot/snapshotQueryClient.d.ts +4 -1
  46. package/dist/client/query/snapshot/snapshotQueryClient.es.js.map +1 -1
  47. package/dist/client/routing.cjs.map +1 -1
  48. package/dist/client/routing.d.cts +2 -2
  49. package/dist/client/routing.d.ts +2 -2
  50. package/dist/client/routing.es.js.map +1 -1
  51. package/dist/dsl/aggregation/admit.cjs +1 -1
  52. package/dist/dsl/aggregation/admit.cjs.map +1 -1
  53. package/dist/dsl/aggregation/admit.es.js +84 -65
  54. package/dist/dsl/aggregation/admit.es.js.map +1 -1
  55. package/dist/dsl/aggregation/builders.cjs +1 -1
  56. package/dist/dsl/aggregation/builders.cjs.map +1 -1
  57. package/dist/dsl/aggregation/builders.d.cts +16 -4
  58. package/dist/dsl/aggregation/builders.d.ts +16 -4
  59. package/dist/dsl/aggregation/builders.es.js +89 -78
  60. package/dist/dsl/aggregation/builders.es.js.map +1 -1
  61. package/dist/dsl/aggregation/derived.cjs +1 -1
  62. package/dist/dsl/aggregation/derived.cjs.map +1 -1
  63. package/dist/dsl/aggregation/derived.d.cts +32 -1
  64. package/dist/dsl/aggregation/derived.d.ts +32 -1
  65. package/dist/dsl/aggregation/derived.es.js +23 -1
  66. package/dist/dsl/aggregation/derived.es.js.map +1 -1
  67. package/dist/dsl/aggregation/types.cjs +1 -1
  68. package/dist/dsl/aggregation/types.cjs.map +1 -1
  69. package/dist/dsl/aggregation/types.d.cts +112 -7
  70. package/dist/dsl/aggregation/types.d.ts +112 -7
  71. package/dist/dsl/aggregation/types.es.js +19 -12
  72. package/dist/dsl/aggregation/types.es.js.map +1 -1
  73. package/dist/dsl/descriptor.cjs +1 -1
  74. package/dist/dsl/descriptor.cjs.map +1 -1
  75. package/dist/dsl/descriptor.d.cts +23 -1
  76. package/dist/dsl/descriptor.d.ts +23 -1
  77. package/dist/dsl/descriptor.es.js +2 -1
  78. package/dist/dsl/descriptor.es.js.map +1 -1
  79. package/dist/dsl.cjs +1 -1
  80. package/dist/dsl.d.cts +2 -2
  81. package/dist/dsl.d.ts +2 -2
  82. package/dist/dsl.es.js +13 -13
  83. package/dist/error/headers.cjs.map +1 -1
  84. package/dist/error/headers.d.cts +3 -2
  85. package/dist/error/headers.d.ts +3 -2
  86. package/dist/error/headers.es.js.map +1 -1
  87. package/dist/error/queryErrorCodes.cjs +1 -1
  88. package/dist/error/queryErrorCodes.cjs.map +1 -1
  89. package/dist/error/queryErrorCodes.d.cts +7 -0
  90. package/dist/error/queryErrorCodes.d.ts +7 -0
  91. package/dist/error/queryErrorCodes.es.js +2 -1
  92. package/dist/error/queryErrorCodes.es.js.map +1 -1
  93. package/dist/index.cjs +1 -1
  94. package/dist/index.es.js +35 -33
  95. package/dist/model/domainEventStream.cjs.map +1 -0
  96. package/dist/{client/query/event → model}/domainEventStream.d.cts +5 -1
  97. package/dist/{client/query/event → model}/domainEventStream.d.ts +5 -1
  98. package/dist/{client/query/event → model}/domainEventStream.es.js +1 -1
  99. package/dist/model/domainEventStream.es.js.map +1 -0
  100. package/dist/model/index.d.cts +2 -0
  101. package/dist/model/index.d.ts +2 -0
  102. package/dist/model/snapshot.cjs.map +1 -0
  103. package/dist/{client/query/snapshot → model}/snapshot.d.cts +3 -1
  104. package/dist/{client/query/snapshot → model}/snapshot.d.ts +3 -1
  105. package/dist/{client/query/snapshot → model}/snapshot.es.js +1 -1
  106. package/dist/model/snapshot.es.js.map +1 -0
  107. package/dist/transport/eventStreams.cjs +1 -1
  108. package/dist/transport/eventStreams.cjs.map +1 -1
  109. package/dist/transport/eventStreams.d.cts +3 -1
  110. package/dist/transport/eventStreams.d.ts +3 -1
  111. package/dist/transport/eventStreams.es.js +7 -4
  112. package/dist/transport/eventStreams.es.js.map +1 -1
  113. package/dist/v10/commands.cjs +2 -0
  114. package/dist/v10/commands.cjs.map +1 -0
  115. package/dist/v10/commands.d.cts +105 -0
  116. package/dist/v10/commands.d.ts +105 -0
  117. package/dist/v10/commands.es.js +68 -0
  118. package/dist/v10/commands.es.js.map +1 -0
  119. package/dist/v10/http.cjs +2 -0
  120. package/dist/v10/http.cjs.map +1 -0
  121. package/dist/v10/http.d.cts +87 -0
  122. package/dist/v10/http.d.ts +87 -0
  123. package/dist/v10/http.es.js +73 -0
  124. package/dist/v10/http.es.js.map +1 -0
  125. package/dist/v10/index.d.cts +19 -0
  126. package/dist/v10/index.d.ts +19 -0
  127. package/dist/v10/manifest.cjs +2 -0
  128. package/dist/v10/manifest.cjs.map +1 -0
  129. package/dist/v10/manifest.d.cts +109 -0
  130. package/dist/v10/manifest.d.ts +109 -0
  131. package/dist/v10/manifest.es.js +14 -0
  132. package/dist/v10/manifest.es.js.map +1 -0
  133. package/dist/v10/problem.cjs +2 -0
  134. package/dist/v10/problem.cjs.map +1 -0
  135. package/dist/v10/problem.d.cts +164 -0
  136. package/dist/v10/problem.d.ts +164 -0
  137. package/dist/v10/problem.es.js +119 -0
  138. package/dist/v10/problem.es.js.map +1 -0
  139. package/dist/v10/queries.cjs +2 -0
  140. package/dist/v10/queries.cjs.map +1 -0
  141. package/dist/v10/queries.d.cts +136 -0
  142. package/dist/v10/queries.d.ts +136 -0
  143. package/dist/v10/queries.es.js +88 -0
  144. package/dist/v10/queries.es.js.map +1 -0
  145. package/dist/v10/state.cjs +2 -0
  146. package/dist/v10/state.cjs.map +1 -0
  147. package/dist/v10/state.d.cts +53 -0
  148. package/dist/v10/state.d.ts +53 -0
  149. package/dist/v10/state.es.js +51 -0
  150. package/dist/v10/state.es.js.map +1 -0
  151. package/dist/v10/streams.cjs +2 -0
  152. package/dist/v10/streams.cjs.map +1 -0
  153. package/dist/v10/streams.d.cts +14 -0
  154. package/dist/v10/streams.d.ts +14 -0
  155. package/dist/v10/streams.es.js +22 -0
  156. package/dist/v10/streams.es.js.map +1 -0
  157. package/dist/v10/wait.cjs +2 -0
  158. package/dist/v10/wait.cjs.map +1 -0
  159. package/dist/v10/wait.d.cts +61 -0
  160. package/dist/v10/wait.d.ts +61 -0
  161. package/dist/v10/wait.es.js +44 -0
  162. package/dist/v10/wait.es.js.map +1 -0
  163. package/dist/v10/wire.cjs +2 -0
  164. package/dist/v10/wire.cjs.map +1 -0
  165. package/dist/v10/wire.d.cts +301 -0
  166. package/dist/v10/wire.d.ts +301 -0
  167. package/dist/v10/wire.es.js +10 -0
  168. package/dist/v10/wire.es.js.map +1 -0
  169. package/dist/v10.cjs +1 -0
  170. package/dist/v10.es.js +9 -0
  171. package/package.json +12 -2
  172. package/dist/client/query/event/domainEventStream.cjs.map +0 -1
  173. package/dist/client/query/event/domainEventStream.es.js.map +0 -1
  174. package/dist/client/query/snapshot/snapshot.cjs.map +0 -1
  175. package/dist/client/query/snapshot/snapshot.es.js.map +0 -1
  176. /package/dist/{client/query/event → model}/domainEventStream.cjs +0 -0
  177. /package/dist/{client/query/snapshot → model}/snapshot.cjs +0 -0
@@ -0,0 +1,88 @@
1
+ import { WowV10Headers as e, entityTag as t, json as n, send as r } from "./http.es.js";
2
+ import { queryRows as i } from "./streams.es.js";
3
+ //#region src/v10/queries.ts
4
+ var a = class {
5
+ constructor(e, t = {}) {
6
+ this.path = e, this.client = t;
7
+ }
8
+ async list(e, t) {
9
+ return n(await this.post("list", e, t));
10
+ }
11
+ async listStream(e, t) {
12
+ return i(await this.post("list", e, t, "text/event-stream"));
13
+ }
14
+ async paged(e, t) {
15
+ return n(await this.post("paged", e, t));
16
+ }
17
+ async cursor(e, t) {
18
+ return n(await this.post("cursor", e, t));
19
+ }
20
+ async single(e, t) {
21
+ return n(await this.post("single", e, t));
22
+ }
23
+ async count(e, t) {
24
+ return n(await this.post("count", e, t));
25
+ }
26
+ async aggregate(e, t) {
27
+ return n(await this.post("aggregate", e, t));
28
+ }
29
+ async describe(i, a) {
30
+ let o = await r(this.client, {
31
+ method: "GET",
32
+ path: this.path,
33
+ headers: { [e.IF_NONE_MATCH]: i === void 0 ? void 0 : `"${i}"` },
34
+ options: a,
35
+ notModified: !0
36
+ }), s = t(o);
37
+ return o.status === 304 ? {
38
+ notModified: !0,
39
+ version: s ?? i ?? ""
40
+ } : {
41
+ notModified: !1,
42
+ ...s === void 0 ? {} : { version: s },
43
+ descriptor: await n(o)
44
+ };
45
+ }
46
+ post(e, t, n, i) {
47
+ return r(this.client, {
48
+ method: "POST",
49
+ path: this.path,
50
+ headers: { Accept: i },
51
+ body: {
52
+ ...t,
53
+ kind: e
54
+ },
55
+ options: n
56
+ });
57
+ }
58
+ };
59
+ function o(e, t) {
60
+ return `/${e.context}/${e.name}/${t}/query`;
61
+ }
62
+ var s = class extends a {
63
+ constructor(e, t) {
64
+ super(o(e, "snapshot"), t), this.type = e;
65
+ }
66
+ }, c = class extends a {
67
+ constructor(e, t) {
68
+ super(o(e, "events"), t), this.type = e;
69
+ }
70
+ }, l = class {
71
+ constructor(e = {}) {
72
+ this.client = e;
73
+ }
74
+ async list(e) {
75
+ return n(await r(this.client, {
76
+ method: "GET",
77
+ path: "/wow/dataset",
78
+ options: e
79
+ }));
80
+ }
81
+ dataset(e, t) {
82
+ return new a(`/wow/dataset/${encodeURIComponent(e)}/${encodeURIComponent(t)}/query`, this.client);
83
+ }
84
+ };
85
+ //#endregion
86
+ export { l as DatasetClient, c as EventQueryClient, a as QueryModelClient, s as SnapshotQueryClient, o as queryPath };
87
+
88
+ //# sourceMappingURL=queries.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.es.js","names":["QueryModelClient","path","client","json","query","options","queryRows","response","send","WowV10Headers","version","tag","entityTag","accept","queryPath","type","model","SnapshotQueryClient","EventQueryClient","DatasetClient","context","dataset"],"sources":["../../src/v10/queries.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 { AggregationQuery } from '../dsl/aggregation/index.js';\nimport type { CursorPage, CursorQuery } from '../dsl/cursorQuery.js';\nimport type { QueryModelDescriptor } from '../dsl/descriptor.js';\nimport type { FilterCapable } from '../dsl/filter/index.js';\nimport type {\n FilterListQuery,\n FilterPagedQuery,\n FilterSingleQuery,\n} from '../dsl/queryable.js';\nimport {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowV10Headers,\n} from './http.js';\nimport type {\n AggregateType,\n DatasetEntry,\n EventStreamField,\n EventStreamRecord,\n EventView,\n SnapshotRecord,\n SnapshotSystemField,\n} from './wire.js';\nimport { queryRows } from './streams.js';\n\n/** How a paged query counts its total (`TotalMode`, decision D150). */\nexport type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';\n\n/** A paged query of a V10 query route: a page, and how its total is counted. */\nexport interface PagedQuery<\n FIELDS extends string = string,\n> extends FilterPagedQuery<FIELDS> {\n /** `BOUNDED` (the server's default) counts up to the budget's limit. */\n total?: TotalMode;\n}\n\n/** A count of a V10 query route (decision D150). */\nexport interface CountQuery<\n FIELDS extends string = string,\n> extends FilterCapable<FIELDS> {\n /** The most matches to count; the budget's default when absent. */\n limit?: number;\n}\n\n/** What a count answers: exact below its limit, else the limit itself. */\nexport interface CountResult {\n readonly count: number;\n readonly exact: boolean;\n}\n\n/**\n * A page of a paged query: `total` is exact when `exact`, a lower bound\n * otherwise, and null for `TotalMode.NONE`.\n */\nexport interface PagedResult<T> {\n readonly total: number | null;\n readonly exact: boolean;\n readonly list: readonly T[];\n}\n\n/**\n * A query model's capability descriptor and its version, the `ETag` of\n * `GET …/query`; `notModified` when the version given is still current.\n */\nexport type DescriptorResult =\n | {\n readonly notModified: false;\n readonly version?: string;\n readonly descriptor: QueryModelDescriptor;\n }\n | { readonly notModified: true; readonly version: string };\n\n/**\n * Queries one query model of a Wow V10 service: `POST {path}` with a body\n * whose `kind` names the operation, `GET {path}` for the capability\n * descriptor (decisions D127, D145).\n *\n * @typeParam R - The record's type.\n * @typeParam FIELDS - The field paths a filter, sort or projection takes.\n */\nexport class QueryModelClient<R, FIELDS extends string = string> {\n /**\n * @param path - The query route, `/{context}/{aggregate}/{model}/query`\n * @param client - How the service is reached\n */\n constructor(\n readonly path: string,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The records that match, at most `limit` (the server's default when absent). */\n async list(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R[]> {\n return json<R[]>(await this.post('list', query, options));\n }\n\n /**\n * The records that match, as server-sent events read one at a time; a\n * failure after the first record errors the stream with its problem.\n */\n async listStream(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<ReadableStream<R>> {\n return queryRows<R>(\n await this.post('list', query, options, 'text/event-stream'),\n );\n }\n\n /** One page of the records that match, and their total. */\n async paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<PagedResult<R>> {\n return json<PagedResult<R>>(await this.post('paged', query, options));\n }\n\n /** One page of a forward-only cursor over the records that match. */\n async cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CursorPage<R>> {\n return json<CursorPage<R>>(await this.post('cursor', query, options));\n }\n\n /** The first record that matches; rejects with 404 when none does. */\n async single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R> {\n return json<R>(await this.post('single', query, options));\n }\n\n /** How many records match, bounded by the count's limit. */\n async count(\n query: CountQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CountResult> {\n return json<CountResult>(await this.post('count', query, options));\n }\n\n /** The groups and metrics of an aggregation, one row per group. */\n async aggregate<ROW = Record<string, unknown>>(\n query: AggregationQuery<FIELDS, string>,\n options?: RequestOptions,\n ): Promise<ROW[]> {\n return json<ROW[]>(await this.post('aggregate', query, options));\n }\n\n /**\n * The model's capability descriptor; with the `version` already held, a\n * 304 answers `notModified`.\n */\n async describe(\n version?: string,\n options?: RequestOptions,\n ): Promise<DescriptorResult> {\n const response = await send(this.client, {\n method: 'GET',\n path: this.path,\n headers: {\n [WowV10Headers.IF_NONE_MATCH]:\n version === undefined ? undefined : `\"${version}\"`,\n },\n options,\n notModified: true,\n });\n const tag = entityTag(response);\n if (response.status === 304) {\n return { notModified: true, version: tag ?? version ?? '' };\n }\n return {\n notModified: false,\n ...(tag === undefined ? {} : { version: tag }),\n descriptor: await json<QueryModelDescriptor>(response),\n };\n }\n\n private post(\n kind: string,\n query: object,\n options?: RequestOptions,\n accept?: string,\n ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: this.path,\n headers: { Accept: accept },\n body: { ...query, kind },\n options,\n });\n }\n}\n\n/** The query route of a model of an aggregate type. */\nexport function queryPath(type: AggregateType, model: string): string {\n return `/${type.context}/${type.name}/${model}/query`;\n}\n\n/**\n * Queries an aggregate type's snapshots (decision D128), the default read\n * model; only where the aggregate keeps them.\n *\n * @typeParam S - The state's type.\n * @typeParam STATE_FIELDS - The `state.*` paths of the state.\n */\nexport class SnapshotQueryClient<\n S = unknown,\n STATE_FIELDS extends string = `state.${string}`,\n> extends QueryModelClient<\n SnapshotRecord<S>,\n SnapshotSystemField | STATE_FIELDS\n> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n super(queryPath(type, 'snapshot'), client);\n }\n}\n\n/**\n * Queries an aggregate type's event streams (decision D131), one aggregate\n * at a time: a filter names its `aggregateId`, and may bound `version` or\n * `commitTime`.\n *\n * @typeParam E - The events' type.\n */\nexport class EventQueryClient<\n E extends EventView = EventView,\n> extends QueryModelClient<EventStreamRecord<E>, EventStreamField> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n super(queryPath(type, 'events'), client);\n }\n}\n\n/**\n * The datasets of a Wow V10 service (decisions D75, D145): registered at run\n * time, so not in the Manifest. Lists those the caller sees and queries\n * each as a snapshot model is queried.\n */\nexport class DatasetClient {\n /** @param client - How the service is reached */\n constructor(readonly client: WowClientOptions = {}) {}\n\n /** The datasets the caller sees, by name. */\n async list(options?: RequestOptions): Promise<DatasetEntry[]> {\n return json<DatasetEntry[]>(\n await send(this.client, { method: 'GET', path: '/wow/dataset', options }),\n );\n }\n\n /**\n * The query client of the dataset `context.dataset`.\n *\n * @typeParam R - The row's type.\n * @typeParam FIELDS - The dataset's field paths.\n */\n dataset<R = Record<string, unknown>, FIELDS extends string = string>(\n context: string,\n dataset: string,\n ): QueryModelClient<R, FIELDS> {\n return new QueryModelClient<R, FIELDS>(\n `/wow/dataset/${encodeURIComponent(context)}/${encodeURIComponent(dataset)}/query`,\n this.client,\n );\n }\n}\n"],"mappings":";;;AAgGA,IAAaA,IAAb,MAAiE;CAK/D,YACE,GACA,IAAoC,CAAC,GACrC;EADS,AADA,KAAA,OAAAC,GACA,KAAA,SAAAC;CACR;CAGH,MAAM,KACJ,GACA,GACc;EACd,OAAOC,EAAU,MAAM,KAAK,KAAK,QAAQC,GAAOC,CAAO,CAAC;CAC1D;CAMA,MAAM,WACJ,GACA,GAC4B;EAC5B,OAAOC,EACL,MAAM,KAAK,KAAK,QAAQF,GAAOC,GAAS,mBAAmB,CAC7D;CACF;CAGA,MAAM,MACJ,GACA,GACyB;EACzB,OAAOF,EAAqB,MAAM,KAAK,KAAK,SAASC,GAAOC,CAAO,CAAC;CACtE;CAGA,MAAM,OACJ,GACA,GACwB;EACxB,OAAOF,EAAoB,MAAM,KAAK,KAAK,UAAUC,GAAOC,CAAO,CAAC;CACtE;CAGA,MAAM,OACJ,GACA,GACY;EACZ,OAAOF,EAAQ,MAAM,KAAK,KAAK,UAAUC,GAAOC,CAAO,CAAC;CAC1D;CAGA,MAAM,MACJ,GACA,GACsB;EACtB,OAAOF,EAAkB,MAAM,KAAK,KAAK,SAASC,GAAOC,CAAO,CAAC;CACnE;CAGA,MAAM,UACJ,GACA,GACgB;EAChB,OAAOF,EAAY,MAAM,KAAK,KAAK,aAAaC,GAAOC,CAAO,CAAC;CACjE;CAMA,MAAM,SACJ,GACA,GAC2B;EAC3B,IAAME,IAAW,MAAMC,EAAK,KAAK,QAAQ;GACvC,QAAQ;GACR,MAAM,KAAK;GACX,SAAS,GACNC,EAAc,gBACbC,MAAY,KAAA,IAAY,KAAA,IAAY,IAAIA,EAAQ,GACpD;GACA;GACA,aAAa;EACf,CAAC,GACKC,IAAMC,EAAUL,CAAQ;EAI9B,OAHIA,EAAS,WAAW,MACf;GAAE,aAAa;GAAM,SAASI,KAAOD,KAAW;EAAG,IAErD;GACL,aAAa;GACb,GAAIC,MAAQ,KAAA,IAAY,CAAC,IAAI,EAAE,SAASA,EAAI;GAC5C,YAAY,MAAMR,EAA2BI,CAAQ;EACvD;CACF;CAEA,KACE,GACA,GACA,GACA,GACmB;EACnB,OAAOC,EAAK,KAAK,QAAQ;GACvB,QAAQ;GACR,MAAM,KAAK;GACX,SAAS,EAAE,QAAQK,EAAO;GAC1B,MAAM;IAAE,GAAGT;IAAO;GAAK;GACvB;EACF,CAAC;CACH;AACF;AAGA,SAAgBU,EAAU,GAAqB,GAAuB;CACpE,OAAO,IAAIC,EAAK,QAAQ,GAAGA,EAAK,KAAK,GAAGC,EAAM;AAChD;AASA,IAAaC,IAAb,cAGUjB,EAGR;CAKA,YACE,GACA,GACA;EAFS,AAGT,MAAMc,EAAUC,GAAM,UAAU,GAAGb,CAAM,GAHhC,KAAA,OAAAa;CAIX;AACF,GASaG,IAAb,cAEUlB,EAAyD;CAKjE,YACE,GACA,GACA;EAFS,AAGT,MAAMc,EAAUC,GAAM,QAAQ,GAAGb,CAAM,GAH9B,KAAA,OAAAa;CAIX;AACF,GAOaI,IAAb,MAA2B;CAEzB,YAAY,IAAoC,CAAC,GAAG;EAA/B,KAAA,SAAAjB;CAAgC;CAGrD,MAAM,KAAK,GAAmD;EAC5D,OAAOC,EACL,MAAMK,EAAK,KAAK,QAAQ;GAAE,QAAQ;GAAO,MAAM;GAAgB;EAAQ,CAAC,CAC1E;CACF;CAQA,QACE,GACA,GAC6B;EAC7B,OAAO,IAAIR,EACT,gBAAgB,mBAAmBoB,CAAO,EAAE,GAAG,mBAAmBC,CAAO,EAAE,SAC3E,KAAK,MACP;CACF;AACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("./http.cjs");var t=class{constructor(e,t={}){this.type=e,this.client=t}async read(t,n={}){let r=n.at instanceof Date?n.at.toISOString():n.at,i=await e.send(this.client,{method:`GET`,path:this.statePath(t),query:{version:n.version,at:r},headers:{[e.WowV10Headers.IF_NONE_MATCH]:n.ifNoneMatch===void 0?void 0:`"${n.ifNoneMatch}"`},options:n,notModified:!0});return i.status===304?{notModified:!0,version:Number(e.entityTag(i)??n.ifNoneMatch)}:{notModified:!1,view:await e.json(i)}}async get(e,t={}){let n=await this.read(e,t);if(n.notModified)throw Error(`A read without If-None-Match was answered 304.`);return n.view}async trace(t,n={}){return e.json(await e.send(this.client,{method:`GET`,path:`${this.statePath(t)}/trace`,query:{from:n.from,to:n.to,limit:n.limit},options:n}))}statePath(e){return`/${this.type.context}/${this.type.name}/${encodeURIComponent(e)}/state`}};exports.StateClient=t;
2
+ //# sourceMappingURL=state.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.cjs","names":["send","WowV10Headers","entityTag","json","require_http","StateClient","type","client","at","options","response","id","result"],"sources":["../../src/v10/state.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 {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowV10Headers,\n} from './http.js';\nimport type {\n AggregateType,\n EventView,\n StateTrace,\n StateView,\n} from './wire.js';\n\n/** Which state a read asks for: the latest, at a version or as of a time. */\nexport interface StateReadOptions extends RequestOptions {\n /** The committed state at this version. */\n readonly version?: number;\n /** The committed state as of this instant (ISO-8601, or a `Date`). */\n readonly at?: string | Date;\n /** The version already held: a 304 then answers `notModified`. */\n readonly ifNoneMatch?: number;\n}\n\n/** A state read: the view, or `notModified` when the version held is current. */\nexport type StateReadResult<S> =\n | { readonly notModified: false; readonly view: StateView<S> }\n | { readonly notModified: true; readonly version: number };\n\n/** Which commits a trace reads (decision D40). */\nexport interface StateTraceOptions extends RequestOptions {\n /** The first version; 1 when absent. */\n readonly from?: number;\n /** The last version; the latest when absent. */\n readonly to?: number;\n /** The most commits, at most 1000; 100 when absent. */\n readonly limit?: number;\n}\n\n/**\n * Reads an aggregate type's states (decisions D40, D112):\n * `GET /{context}/{aggregate}/{id}/state` with `?version=` or `?at=`, and\n * its trace, `…/state/trace`. A state that does not exist rejects with 404\n * `wow.aggregate.not-found`.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type of a trace.\n */\nexport class StateClient<S = unknown, E extends EventView = EventView> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The state the options ask for. */\n async read(\n id: string,\n options: StateReadOptions = {},\n ): Promise<StateReadResult<S>> {\n const at =\n options.at instanceof Date ? options.at.toISOString() : options.at;\n const response = await send(this.client, {\n method: 'GET',\n path: this.statePath(id),\n query: { version: options.version, at },\n headers: {\n [WowV10Headers.IF_NONE_MATCH]:\n options.ifNoneMatch === undefined\n ? undefined\n : `\"${options.ifNoneMatch}\"`,\n },\n options,\n notModified: true,\n });\n if (response.status === 304) {\n return {\n notModified: true,\n version: Number(entityTag(response) ?? options.ifNoneMatch),\n };\n }\n return { notModified: false, view: await json<StateView<S>>(response) };\n }\n\n /** The latest state, or the one the options ask for, without a cache. */\n async get(\n id: string,\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<StateView<S>> {\n const result = await this.read(id, options);\n if (result.notModified) {\n throw new Error('A read without If-None-Match was answered 304.');\n }\n return result.view;\n }\n\n /** The commits from `from` to `to`, each with its events and the state after it. */\n async trace(\n id: string,\n options: StateTraceOptions = {},\n ): Promise<StateTrace<S, E>> {\n return json<StateTrace<S, E>>(\n await send(this.client, {\n method: 'GET',\n path: `${this.statePath(id)}/trace`,\n query: { from: options.from, to: options.to, limit: options.limit },\n options,\n }),\n );\n }\n\n private statePath(id: string): string {\n return `/${this.type.context}/${this.type.name}/${encodeURIComponent(id)}/state`;\n }\n}\n"],"mappings":"8BA8DA,IAAaK,EAAb,KAAuE,CAKrE,YACE,EACA,EAAoC,CAAC,EACrC,CAFS,KAAA,KAAAC,EACA,KAAA,OAAAC,CACR,CAGH,MAAM,KACJ,EACA,EAA4B,CAAC,EACA,CAC7B,IAAMC,EACJC,EAAQ,cAAc,KAAOA,EAAQ,GAAG,YAAY,EAAIA,EAAQ,GAC5DC,EAAW,MAAMV,EAAAA,KAAK,KAAK,OAAQ,CACvC,OAAQ,MACR,KAAM,KAAK,UAAUW,CAAE,EACvB,MAAO,CAAE,QAASF,EAAQ,QAAS,IAAG,EACtC,QAAS,EACNR,EAAAA,cAAc,eACbQ,EAAQ,cAAgB,IAAA,GACpB,IAAA,GACA,IAAIA,EAAQ,YAAY,EAChC,EACA,UACA,YAAa,EACf,CAAC,EAOD,OANIC,EAAS,SAAW,IACf,CACL,YAAa,GACb,QAAS,OAAOR,EAAAA,UAAUQ,CAAQ,GAAKD,EAAQ,WAAW,CAC5D,EAEK,CAAE,YAAa,GAAO,KAAM,MAAMN,EAAAA,KAAmBO,CAAQ,CAAE,CACxE,CAGA,MAAM,IACJ,EACA,EAAiD,CAAC,EAC3B,CACvB,IAAME,EAAS,MAAM,KAAK,KAAKD,EAAIF,CAAO,EAC1C,GAAIG,EAAO,YACT,MAAU,MAAM,gDAAgD,EAElE,OAAOA,EAAO,IAChB,CAGA,MAAM,MACJ,EACA,EAA6B,CAAC,EACH,CAC3B,OAAOT,EAAAA,KACL,MAAMH,EAAAA,KAAK,KAAK,OAAQ,CACtB,OAAQ,MACR,KAAM,GAAG,KAAK,UAAUW,CAAE,EAAE,QAC5B,MAAO,CAAE,KAAMF,EAAQ,KAAM,GAAIA,EAAQ,GAAI,MAAOA,EAAQ,KAAM,EAClE,SACF,CAAC,CACH,CACF,CAEA,UAAkB,EAAoB,CACpC,MAAO,IAAI,KAAK,KAAK,QAAQ,GAAG,KAAK,KAAK,KAAK,GAAG,mBAAmBE,CAAE,EAAE,OAC3E,CACF"}
@@ -0,0 +1,53 @@
1
+ import { RequestOptions, WowClientOptions } from './http.cjs';
2
+ import { AggregateType, EventView, StateTrace, StateView } from './wire.cjs';
3
+ /** Which state a read asks for: the latest, at a version or as of a time. */
4
+ export interface StateReadOptions extends RequestOptions {
5
+ /** The committed state at this version. */
6
+ readonly version?: number;
7
+ /** The committed state as of this instant (ISO-8601, or a `Date`). */
8
+ readonly at?: string | Date;
9
+ /** The version already held: a 304 then answers `notModified`. */
10
+ readonly ifNoneMatch?: number;
11
+ }
12
+ /** A state read: the view, or `notModified` when the version held is current. */
13
+ export type StateReadResult<S> = {
14
+ readonly notModified: false;
15
+ readonly view: StateView<S>;
16
+ } | {
17
+ readonly notModified: true;
18
+ readonly version: number;
19
+ };
20
+ /** Which commits a trace reads (decision D40). */
21
+ export interface StateTraceOptions extends RequestOptions {
22
+ /** The first version; 1 when absent. */
23
+ readonly from?: number;
24
+ /** The last version; the latest when absent. */
25
+ readonly to?: number;
26
+ /** The most commits, at most 1000; 100 when absent. */
27
+ readonly limit?: number;
28
+ }
29
+ /**
30
+ * Reads an aggregate type's states (decisions D40, D112):
31
+ * `GET /{context}/{aggregate}/{id}/state` with `?version=` or `?at=`, and
32
+ * its trace, `…/state/trace`. A state that does not exist rejects with 404
33
+ * `wow.aggregate.not-found`.
34
+ *
35
+ * @typeParam S - The state's type.
36
+ * @typeParam E - The events' type of a trace.
37
+ */
38
+ export declare class StateClient<S = unknown, E extends EventView = EventView> {
39
+ readonly type: AggregateType;
40
+ readonly client: WowClientOptions;
41
+ /**
42
+ * @param type - The aggregate type
43
+ * @param client - How the service is reached
44
+ */
45
+ constructor(type: AggregateType, client?: WowClientOptions);
46
+ /** The state the options ask for. */
47
+ read(id: string, options?: StateReadOptions): Promise<StateReadResult<S>>;
48
+ /** The latest state, or the one the options ask for, without a cache. */
49
+ get(id: string, options?: Omit<StateReadOptions, 'ifNoneMatch'>): Promise<StateView<S>>;
50
+ /** The commits from `from` to `to`, each with its events and the state after it. */
51
+ trace(id: string, options?: StateTraceOptions): Promise<StateTrace<S, E>>;
52
+ private statePath;
53
+ }
@@ -0,0 +1,53 @@
1
+ import { RequestOptions, WowClientOptions } from './http.js';
2
+ import { AggregateType, EventView, StateTrace, StateView } from './wire.js';
3
+ /** Which state a read asks for: the latest, at a version or as of a time. */
4
+ export interface StateReadOptions extends RequestOptions {
5
+ /** The committed state at this version. */
6
+ readonly version?: number;
7
+ /** The committed state as of this instant (ISO-8601, or a `Date`). */
8
+ readonly at?: string | Date;
9
+ /** The version already held: a 304 then answers `notModified`. */
10
+ readonly ifNoneMatch?: number;
11
+ }
12
+ /** A state read: the view, or `notModified` when the version held is current. */
13
+ export type StateReadResult<S> = {
14
+ readonly notModified: false;
15
+ readonly view: StateView<S>;
16
+ } | {
17
+ readonly notModified: true;
18
+ readonly version: number;
19
+ };
20
+ /** Which commits a trace reads (decision D40). */
21
+ export interface StateTraceOptions extends RequestOptions {
22
+ /** The first version; 1 when absent. */
23
+ readonly from?: number;
24
+ /** The last version; the latest when absent. */
25
+ readonly to?: number;
26
+ /** The most commits, at most 1000; 100 when absent. */
27
+ readonly limit?: number;
28
+ }
29
+ /**
30
+ * Reads an aggregate type's states (decisions D40, D112):
31
+ * `GET /{context}/{aggregate}/{id}/state` with `?version=` or `?at=`, and
32
+ * its trace, `…/state/trace`. A state that does not exist rejects with 404
33
+ * `wow.aggregate.not-found`.
34
+ *
35
+ * @typeParam S - The state's type.
36
+ * @typeParam E - The events' type of a trace.
37
+ */
38
+ export declare class StateClient<S = unknown, E extends EventView = EventView> {
39
+ readonly type: AggregateType;
40
+ readonly client: WowClientOptions;
41
+ /**
42
+ * @param type - The aggregate type
43
+ * @param client - How the service is reached
44
+ */
45
+ constructor(type: AggregateType, client?: WowClientOptions);
46
+ /** The state the options ask for. */
47
+ read(id: string, options?: StateReadOptions): Promise<StateReadResult<S>>;
48
+ /** The latest state, or the one the options ask for, without a cache. */
49
+ get(id: string, options?: Omit<StateReadOptions, 'ifNoneMatch'>): Promise<StateView<S>>;
50
+ /** The commits from `from` to `to`, each with its events and the state after it. */
51
+ trace(id: string, options?: StateTraceOptions): Promise<StateTrace<S, E>>;
52
+ private statePath;
53
+ }
@@ -0,0 +1,51 @@
1
+ import { WowV10Headers as e, entityTag as t, json as n, send as r } from "./http.es.js";
2
+ //#region src/v10/state.ts
3
+ var i = class {
4
+ constructor(e, t = {}) {
5
+ this.type = e, this.client = t;
6
+ }
7
+ async read(i, a = {}) {
8
+ let o = a.at instanceof Date ? a.at.toISOString() : a.at, s = await r(this.client, {
9
+ method: "GET",
10
+ path: this.statePath(i),
11
+ query: {
12
+ version: a.version,
13
+ at: o
14
+ },
15
+ headers: { [e.IF_NONE_MATCH]: a.ifNoneMatch === void 0 ? void 0 : `"${a.ifNoneMatch}"` },
16
+ options: a,
17
+ notModified: !0
18
+ });
19
+ return s.status === 304 ? {
20
+ notModified: !0,
21
+ version: Number(t(s) ?? a.ifNoneMatch)
22
+ } : {
23
+ notModified: !1,
24
+ view: await n(s)
25
+ };
26
+ }
27
+ async get(e, t = {}) {
28
+ let n = await this.read(e, t);
29
+ if (n.notModified) throw Error("A read without If-None-Match was answered 304.");
30
+ return n.view;
31
+ }
32
+ async trace(e, t = {}) {
33
+ return n(await r(this.client, {
34
+ method: "GET",
35
+ path: `${this.statePath(e)}/trace`,
36
+ query: {
37
+ from: t.from,
38
+ to: t.to,
39
+ limit: t.limit
40
+ },
41
+ options: t
42
+ }));
43
+ }
44
+ statePath(e) {
45
+ return `/${this.type.context}/${this.type.name}/${encodeURIComponent(e)}/state`;
46
+ }
47
+ };
48
+ //#endregion
49
+ export { i as StateClient };
50
+
51
+ //# sourceMappingURL=state.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"state.es.js","names":["StateClient","type","client","at","options","response","send","id","WowV10Headers","entityTag","json","result"],"sources":["../../src/v10/state.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 {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowV10Headers,\n} from './http.js';\nimport type {\n AggregateType,\n EventView,\n StateTrace,\n StateView,\n} from './wire.js';\n\n/** Which state a read asks for: the latest, at a version or as of a time. */\nexport interface StateReadOptions extends RequestOptions {\n /** The committed state at this version. */\n readonly version?: number;\n /** The committed state as of this instant (ISO-8601, or a `Date`). */\n readonly at?: string | Date;\n /** The version already held: a 304 then answers `notModified`. */\n readonly ifNoneMatch?: number;\n}\n\n/** A state read: the view, or `notModified` when the version held is current. */\nexport type StateReadResult<S> =\n | { readonly notModified: false; readonly view: StateView<S> }\n | { readonly notModified: true; readonly version: number };\n\n/** Which commits a trace reads (decision D40). */\nexport interface StateTraceOptions extends RequestOptions {\n /** The first version; 1 when absent. */\n readonly from?: number;\n /** The last version; the latest when absent. */\n readonly to?: number;\n /** The most commits, at most 1000; 100 when absent. */\n readonly limit?: number;\n}\n\n/**\n * Reads an aggregate type's states (decisions D40, D112):\n * `GET /{context}/{aggregate}/{id}/state` with `?version=` or `?at=`, and\n * its trace, `…/state/trace`. A state that does not exist rejects with 404\n * `wow.aggregate.not-found`.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type of a trace.\n */\nexport class StateClient<S = unknown, E extends EventView = EventView> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The state the options ask for. */\n async read(\n id: string,\n options: StateReadOptions = {},\n ): Promise<StateReadResult<S>> {\n const at =\n options.at instanceof Date ? options.at.toISOString() : options.at;\n const response = await send(this.client, {\n method: 'GET',\n path: this.statePath(id),\n query: { version: options.version, at },\n headers: {\n [WowV10Headers.IF_NONE_MATCH]:\n options.ifNoneMatch === undefined\n ? undefined\n : `\"${options.ifNoneMatch}\"`,\n },\n options,\n notModified: true,\n });\n if (response.status === 304) {\n return {\n notModified: true,\n version: Number(entityTag(response) ?? options.ifNoneMatch),\n };\n }\n return { notModified: false, view: await json<StateView<S>>(response) };\n }\n\n /** The latest state, or the one the options ask for, without a cache. */\n async get(\n id: string,\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<StateView<S>> {\n const result = await this.read(id, options);\n if (result.notModified) {\n throw new Error('A read without If-None-Match was answered 304.');\n }\n return result.view;\n }\n\n /** The commits from `from` to `to`, each with its events and the state after it. */\n async trace(\n id: string,\n options: StateTraceOptions = {},\n ): Promise<StateTrace<S, E>> {\n return json<StateTrace<S, E>>(\n await send(this.client, {\n method: 'GET',\n path: `${this.statePath(id)}/trace`,\n query: { from: options.from, to: options.to, limit: options.limit },\n options,\n }),\n );\n }\n\n private statePath(id: string): string {\n return `/${this.type.context}/${this.type.name}/${encodeURIComponent(id)}/state`;\n }\n}\n"],"mappings":";;AA8DA,IAAaA,IAAb,MAAuE;CAKrE,YACE,GACA,IAAoC,CAAC,GACrC;EADS,AADA,KAAA,OAAAC,GACA,KAAA,SAAAC;CACR;CAGH,MAAM,KACJ,GACA,IAA4B,CAAC,GACA;EAC7B,IAAMC,IACJC,EAAQ,cAAc,OAAOA,EAAQ,GAAG,YAAY,IAAIA,EAAQ,IAC5DC,IAAW,MAAMC,EAAK,KAAK,QAAQ;GACvC,QAAQ;GACR,MAAM,KAAK,UAAUC,CAAE;GACvB,OAAO;IAAE,SAASH,EAAQ;IAAS;GAAG;GACtC,SAAS,GACNI,EAAc,gBACbJ,EAAQ,gBAAgB,KAAA,IACpB,KAAA,IACA,IAAIA,EAAQ,YAAY,GAChC;GACA;GACA,aAAa;EACf,CAAC;EAOD,OANIC,EAAS,WAAW,MACf;GACL,aAAa;GACb,SAAS,OAAOI,EAAUJ,CAAQ,KAAKD,EAAQ,WAAW;EAC5D,IAEK;GAAE,aAAa;GAAO,MAAM,MAAMM,EAAmBL,CAAQ;EAAE;CACxE;CAGA,MAAM,IACJ,GACA,IAAiD,CAAC,GAC3B;EACvB,IAAMM,IAAS,MAAM,KAAK,KAAKJ,GAAIH,CAAO;EAC1C,IAAIO,EAAO,aACT,MAAU,MAAM,gDAAgD;EAElE,OAAOA,EAAO;CAChB;CAGA,MAAM,MACJ,GACA,IAA6B,CAAC,GACH;EAC3B,OAAOD,EACL,MAAMJ,EAAK,KAAK,QAAQ;GACtB,QAAQ;GACR,MAAM,GAAG,KAAK,UAAUC,CAAE,EAAE;GAC5B,OAAO;IAAE,MAAMH,EAAQ;IAAM,IAAIA,EAAQ;IAAI,OAAOA,EAAQ;GAAM;GAClE;EACF,CAAC,CACH;CACF;CAEA,UAAkB,GAAoB;EACpC,OAAO,IAAI,KAAK,KAAK,QAAQ,GAAG,KAAK,KAAK,KAAK,GAAG,mBAAmBG,CAAE,EAAE;CAC3E;AACF"}
@@ -0,0 +1,2 @@
1
+ const e=require("./problem.cjs");let t=require("@ahoo-wang/fetcher-eventstream");var n=`row`,r=`error`,i=`message`;function a(e){return(0,t.toJsonServerSentEventStream)((0,t.toServerSentEventStream)(e)).pipeThrough(new TransformStream({transform(e,t){t.enqueue(e.data)}}))}function o(a){return(0,t.toJsonServerSentEventStream)((0,t.toServerSentEventStream)(a)).pipeThrough(new TransformStream({transform(t,a){t.event===r?a.error(new e.WowProblemError(e.isProblem(t.data)?t.data:{type:`about:blank`,title:`Query failed`,status:500})):(t.event===n||t.event===i)&&a.enqueue(t.data)}}))}exports.commandResults=a,exports.queryRows=o;
2
+ //# sourceMappingURL=streams.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streams.cjs","names":["toJsonServerSentEventStream","toServerSentEventStream","WowProblemError","isProblem","require_problem","_ahoo_wang_fetcher_eventstream","ROW_EVENT","ERROR_EVENT","UNNAMED_EVENT","commandResults","response","controller","event","queryRows"],"sources":["../../src/v10/streams.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 {\n type JsonServerSentEvent,\n toJsonServerSentEventStream,\n toServerSentEventStream,\n} from '@ahoo-wang/fetcher-eventstream';\nimport type { CommandResult } from './wire.js';\nimport { isProblem, WowProblemError } from './problem.js';\n\n/** The event of each record of a streamed query list. */\nconst ROW_EVENT = 'row';\n\n/** The event that ends a streamed query list that failed: the problem. */\nconst ERROR_EVENT = 'error';\n\n/** The name an event without one is read under. */\nconst UNNAMED_EVENT = 'message';\n\n/**\n * The results of a command's event stream (`Accept: text/event-stream`), one\n * per hop, each event named by its stage. A rejection or a failure after\n * admission is the stream's last result, not an error.\n */\nexport type CommandResultStream<R = Record<string, unknown>> = ReadableStream<\n CommandResult<R>\n>;\n\n/** The data of each event of `response`'s server-sent event stream. */\nexport function commandResults<R>(response: Response): CommandResultStream<R> {\n return toJsonServerSentEventStream<CommandResult<R>>(\n toServerSentEventStream(response),\n ).pipeThrough(\n new TransformStream<\n JsonServerSentEvent<CommandResult<R>>,\n CommandResult<R>\n >({\n transform(event, controller) {\n controller.enqueue(event.data);\n },\n }),\n );\n}\n\n/**\n * The records of a streamed query list: each `row` event's data, until an\n * `error` event, which errors the stream with its {@link WowProblemError}.\n */\nexport function queryRows<T>(response: Response): ReadableStream<T> {\n return toJsonServerSentEventStream<unknown>(\n toServerSentEventStream(response),\n ).pipeThrough(\n new TransformStream<JsonServerSentEvent<unknown>, T>({\n transform(event, controller) {\n if (event.event === ERROR_EVENT) {\n controller.error(\n new WowProblemError(\n isProblem(event.data)\n ? event.data\n : { type: 'about:blank', title: 'Query failed', status: 500 },\n ),\n );\n return;\n }\n if (event.event === ROW_EVENT || event.event === UNNAMED_EVENT) {\n controller.enqueue(event.data as T);\n }\n },\n }),\n );\n}\n"],"mappings":"iFAsBA,IAAMM,EAAY,MAGZC,EAAc,QAGdC,EAAgB,UAYtB,SAAgBC,EAAkB,EAA4C,CAC5E,OAAA,EAAOT,EAAAA,4BAAAA,EAAAA,EACLC,EAAAA,wBAAAA,CAAwBS,CAAQ,CAClC,CAAC,CAAC,YACA,IAAI,gBAGF,CACA,UAAU,EAAO,EAAY,CAC3BC,EAAW,QAAQC,EAAM,IAAI,CAC/B,CACF,CAAC,CACH,CACF,CAMA,SAAgBC,EAAa,EAAuC,CAClE,OAAA,EAAOb,EAAAA,4BAAAA,EAAAA,EACLC,EAAAA,wBAAAA,CAAwBS,CAAQ,CAClC,CAAC,CAAC,YACA,IAAI,gBAAiD,CACnD,UAAU,EAAO,EAAY,CACvBE,EAAM,QAAUL,EAClBI,EAAW,MACT,IAAIT,EAAAA,gBACFC,EAAAA,UAAUS,EAAM,IAAI,EAChBA,EAAM,KACN,CAAE,KAAM,cAAe,MAAO,eAAgB,OAAQ,GAAI,CAChE,CACF,GAGEA,EAAM,QAAUN,GAAaM,EAAM,QAAUJ,IAC/CG,EAAW,QAAQC,EAAM,IAAS,CAEtC,CACF,CAAC,CACH,CACF"}
@@ -0,0 +1,14 @@
1
+ import { CommandResult } from './wire.cjs';
2
+ /**
3
+ * The results of a command's event stream (`Accept: text/event-stream`), one
4
+ * per hop, each event named by its stage. A rejection or a failure after
5
+ * admission is the stream's last result, not an error.
6
+ */
7
+ export type CommandResultStream<R = Record<string, unknown>> = ReadableStream<CommandResult<R>>;
8
+ /** The data of each event of `response`'s server-sent event stream. */
9
+ export declare function commandResults<R>(response: Response): CommandResultStream<R>;
10
+ /**
11
+ * The records of a streamed query list: each `row` event's data, until an
12
+ * `error` event, which errors the stream with its {@link WowProblemError}.
13
+ */
14
+ export declare function queryRows<T>(response: Response): ReadableStream<T>;
@@ -0,0 +1,14 @@
1
+ import { CommandResult } from './wire.js';
2
+ /**
3
+ * The results of a command's event stream (`Accept: text/event-stream`), one
4
+ * per hop, each event named by its stage. A rejection or a failure after
5
+ * admission is the stream's last result, not an error.
6
+ */
7
+ export type CommandResultStream<R = Record<string, unknown>> = ReadableStream<CommandResult<R>>;
8
+ /** The data of each event of `response`'s server-sent event stream. */
9
+ export declare function commandResults<R>(response: Response): CommandResultStream<R>;
10
+ /**
11
+ * The records of a streamed query list: each `row` event's data, until an
12
+ * `error` event, which errors the stream with its {@link WowProblemError}.
13
+ */
14
+ export declare function queryRows<T>(response: Response): ReadableStream<T>;
@@ -0,0 +1,22 @@
1
+ import { WowProblemError as e, isProblem as t } from "./problem.es.js";
2
+ import { toJsonServerSentEventStream as n, toServerSentEventStream as r } from "@ahoo-wang/fetcher-eventstream";
3
+ //#region src/v10/streams.ts
4
+ var i = "row", a = "error", o = "message";
5
+ function s(e) {
6
+ return n(r(e)).pipeThrough(new TransformStream({ transform(e, t) {
7
+ t.enqueue(e.data);
8
+ } }));
9
+ }
10
+ function c(s) {
11
+ return n(r(s)).pipeThrough(new TransformStream({ transform(n, r) {
12
+ n.event === a ? r.error(new e(t(n.data) ? n.data : {
13
+ type: "about:blank",
14
+ title: "Query failed",
15
+ status: 500
16
+ })) : (n.event === i || n.event === o) && r.enqueue(n.data);
17
+ } }));
18
+ }
19
+ //#endregion
20
+ export { s as commandResults, c as queryRows };
21
+
22
+ //# sourceMappingURL=streams.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"streams.es.js","names":["ROW_EVENT","ERROR_EVENT","UNNAMED_EVENT","commandResults","toJsonServerSentEventStream","toServerSentEventStream","response","event","queryRows","controller","WowProblemError","isProblem"],"sources":["../../src/v10/streams.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 {\n type JsonServerSentEvent,\n toJsonServerSentEventStream,\n toServerSentEventStream,\n} from '@ahoo-wang/fetcher-eventstream';\nimport type { CommandResult } from './wire.js';\nimport { isProblem, WowProblemError } from './problem.js';\n\n/** The event of each record of a streamed query list. */\nconst ROW_EVENT = 'row';\n\n/** The event that ends a streamed query list that failed: the problem. */\nconst ERROR_EVENT = 'error';\n\n/** The name an event without one is read under. */\nconst UNNAMED_EVENT = 'message';\n\n/**\n * The results of a command's event stream (`Accept: text/event-stream`), one\n * per hop, each event named by its stage. A rejection or a failure after\n * admission is the stream's last result, not an error.\n */\nexport type CommandResultStream<R = Record<string, unknown>> = ReadableStream<\n CommandResult<R>\n>;\n\n/** The data of each event of `response`'s server-sent event stream. */\nexport function commandResults<R>(response: Response): CommandResultStream<R> {\n return toJsonServerSentEventStream<CommandResult<R>>(\n toServerSentEventStream(response),\n ).pipeThrough(\n new TransformStream<\n JsonServerSentEvent<CommandResult<R>>,\n CommandResult<R>\n >({\n transform(event, controller) {\n controller.enqueue(event.data);\n },\n }),\n );\n}\n\n/**\n * The records of a streamed query list: each `row` event's data, until an\n * `error` event, which errors the stream with its {@link WowProblemError}.\n */\nexport function queryRows<T>(response: Response): ReadableStream<T> {\n return toJsonServerSentEventStream<unknown>(\n toServerSentEventStream(response),\n ).pipeThrough(\n new TransformStream<JsonServerSentEvent<unknown>, T>({\n transform(event, controller) {\n if (event.event === ERROR_EVENT) {\n controller.error(\n new WowProblemError(\n isProblem(event.data)\n ? event.data\n : { type: 'about:blank', title: 'Query failed', status: 500 },\n ),\n );\n return;\n }\n if (event.event === ROW_EVENT || event.event === UNNAMED_EVENT) {\n controller.enqueue(event.data as T);\n }\n },\n }),\n );\n}\n"],"mappings":";;;AAsBA,IAAMA,IAAY,OAGZC,IAAc,SAGdC,IAAgB;AAYtB,SAAgBC,EAAkB,GAA4C;CAC5E,OAAOC,EACLC,EAAwBC,CAAQ,CAClC,CAAC,CAAC,YACA,IAAI,gBAGF,EACA,UAAU,GAAO,GAAY;EAC3B,EAAW,QAAQC,EAAM,IAAI;CAC/B,EACF,CAAC,CACH;AACF;AAMA,SAAgBC,EAAa,GAAuC;CAClE,OAAOJ,EACLC,EAAwBC,CAAQ,CAClC,CAAC,CAAC,YACA,IAAI,gBAAiD,EACnD,UAAU,GAAO,GAAY;EAC3B,AAAIC,EAAM,UAAUN,IAClBQ,EAAW,MACT,IAAIC,EACFC,EAAUJ,EAAM,IAAI,IAChBA,EAAM,OACN;GAAE,MAAM;GAAe,OAAO;GAAgB,QAAQ;EAAI,CAChE,CACF,KAGEA,EAAM,UAAUP,KAAaO,EAAM,UAAUL,MAC/CO,EAAW,QAAQF,EAAM,IAAS;CAEtC,EACF,CAAC,CACH;AACF"}
@@ -0,0 +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;
2
+ //# sourceMappingURL=wait.cjs.map
@@ -0,0 +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/v10/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,CAC9D,CACF,CAgBA,IAAaC,EAAO,CAElB,SAAW,GAA0BH,EAAIP,EAAAA,MAAM,SAAUQ,CAAO,EAEhE,UAAY,GAA0BD,EAAIP,EAAAA,MAAM,UAAWQ,CAAO,EAElE,SAAW,GACTD,EAAIP,EAAAA,MAAM,QAASQ,EAASN,CAAqB,EAEnD,SAAU,EAAsB,IAC9BK,EAAIP,EAAAA,MAAM,QAASQ,EAASC,CAAY,CAC5C,EASA,SAAgBE,EAAU,EAAoB,CAC5C,IAAMH,EAAUH,EAAM,SAAW,IAAA,GAC3BI,EAAeJ,EAAM,cAAgB,IAAA,GAC3C,GAAIA,EAAM,QAAUL,EAAAA,MAAM,QAAS,CACjC,GAAIS,IAAiB,IAAA,GACnB,MAAU,UAAU,uCAAuC,EAK7D,OAHIA,IAAA,WACKD,IAAY,IAAA,GAAY,WAAa,YAAYA,EAAQ,GAE3DA,IAAY,IAAA,GACf,WAAWC,EAAa,GACxB,WAAWD,EAAQ,GAAGC,EAAa,EACzC,CACA,GAAIA,IAAiB,IAAA,GACnB,MAAU,UAAU,0CAA0C,EAEhE,IAAMG,EAAUP,EAAM,MAAM,YAAY,EACxC,OAAOG,IAAY,IAAA,GAAYI,EAAU,GAAGA,EAAQ,GAAGJ,EAAQ,EACjE,CAQA,SAAgBK,EAAe,EAAuC,CACpE,GAAI,OAAOC,GAAS,SAAU,OAAOA,EACrC,GAAIA,EAAK,SAAW,EAClB,MAAU,UAAU,mCAAmC,EAEzD,OAAOA,EAAK,IAAIH,CAAS,CAAC,CAAC,KAAK,KAAK,CACvC,CASA,SAAgBI,EAAkB,EAAkC,CAClE,GAAI,OAAOC,GAAY,SAAU,OAAOA,EACxC,GAAI,CAAC,OAAO,UAAUA,CAAO,GAAKA,GAAW,EAC3C,MAAU,UACR,8DAA8DA,EAAQ,EACxE,EAEF,OAAOA,EAAU,KAAS,EAAI,GAAGA,EAAU,IAAK,GAAK,GAAGA,EAAQ,GAClE"}
@@ -0,0 +1,61 @@
1
+ import { Hop } from './wire.cjs';
2
+ /** The name of the built-in subscription that writes snapshots. */
3
+ export declare const SNAPSHOT_SUBSCRIPTION = "snapshot";
4
+ /**
5
+ * Builds the hops of a wait chain (decisions D62, D99). A context left out is
6
+ * the command's own. A saga's `handled` hop may be followed by hops of the
7
+ * commands it derived, in their contexts:
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const plan = [
12
+ * wait.committed(),
13
+ * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),
14
+ * wait.committed('eshop-ordering'),
15
+ * ];
16
+ * ```
17
+ */
18
+ export declare const wait: {
19
+ /** Until the command passed admission; the route answers 202. */
20
+ readonly accepted: (context?: string) => Hop;
21
+ /** Until the command's events are appended to the log. */
22
+ readonly committed: (context?: string) => Hop;
23
+ /** Until the snapshot holds the commit: the caller reads its own write. */
24
+ readonly snapshot: (context?: string) => Hop;
25
+ /** Until the subscription named `processor.function` handled the commit. */
26
+ readonly handled: (subscription: string, context?: string) => Hop;
27
+ };
28
+ /**
29
+ * A hop as `Wow-Wait` spells it: `accepted`, `committed`, `snapshot` and
30
+ * `handled(subscription)`, each with its context when it has one:
31
+ * `committed(ctx)`, `snapshot(ctx)`, `handled(ctx/subscription)`.
32
+ *
33
+ * @param value - The hop
34
+ */
35
+ export declare function formatHop(value: Hop): string;
36
+ /**
37
+ * A wait plan as the `Wow-Wait` header spells it: its hops, in order,
38
+ * separated by `>`. A string is taken as already spelled.
39
+ *
40
+ * @param plan - The hops, or the header's value
41
+ */
42
+ export declare function formatWaitPlan(plan: readonly Hop[] | string): string;
43
+ /**
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.
47
+ *
48
+ * @param timeout - Milliseconds, or the header's value
49
+ */
50
+ export declare function formatWaitTimeout(timeout: number | string): string;
51
+ /**
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.
55
+ */
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
+ }
@@ -0,0 +1,61 @@
1
+ import { Hop } from './wire.js';
2
+ /** The name of the built-in subscription that writes snapshots. */
3
+ export declare const SNAPSHOT_SUBSCRIPTION = "snapshot";
4
+ /**
5
+ * Builds the hops of a wait chain (decisions D62, D99). A context left out is
6
+ * the command's own. A saga's `handled` hop may be followed by hops of the
7
+ * commands it derived, in their contexts:
8
+ *
9
+ * @example
10
+ * ```typescript
11
+ * const plan = [
12
+ * wait.committed(),
13
+ * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),
14
+ * wait.committed('eshop-ordering'),
15
+ * ];
16
+ * ```
17
+ */
18
+ export declare const wait: {
19
+ /** Until the command passed admission; the route answers 202. */
20
+ readonly accepted: (context?: string) => Hop;
21
+ /** Until the command's events are appended to the log. */
22
+ readonly committed: (context?: string) => Hop;
23
+ /** Until the snapshot holds the commit: the caller reads its own write. */
24
+ readonly snapshot: (context?: string) => Hop;
25
+ /** Until the subscription named `processor.function` handled the commit. */
26
+ readonly handled: (subscription: string, context?: string) => Hop;
27
+ };
28
+ /**
29
+ * A hop as `Wow-Wait` spells it: `accepted`, `committed`, `snapshot` and
30
+ * `handled(subscription)`, each with its context when it has one:
31
+ * `committed(ctx)`, `snapshot(ctx)`, `handled(ctx/subscription)`.
32
+ *
33
+ * @param value - The hop
34
+ */
35
+ export declare function formatHop(value: Hop): string;
36
+ /**
37
+ * A wait plan as the `Wow-Wait` header spells it: its hops, in order,
38
+ * separated by `>`. A string is taken as already spelled.
39
+ *
40
+ * @param plan - The hops, or the header's value
41
+ */
42
+ export declare function formatWaitPlan(plan: readonly Hop[] | string): string;
43
+ /**
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.
47
+ *
48
+ * @param timeout - Milliseconds, or the header's value
49
+ */
50
+ export declare function formatWaitTimeout(timeout: number | string): string;
51
+ /**
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.
55
+ */
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
+ }
@@ -0,0 +1,44 @@
1
+ import { Stage as e } from "./wire.es.js";
2
+ //#region src/v10/wait.ts
3
+ var t = "snapshot", n = /^[A-Za-z0-9_.-]+$/;
4
+ function r(e, t) {
5
+ if (!n.test(t)) throw TypeError(`Not a ${e} name: '${t}'.`);
6
+ return t;
7
+ }
8
+ function i(e, t, n) {
9
+ return {
10
+ stage: e,
11
+ ...t === void 0 ? {} : { context: r("context", t) },
12
+ ...n === void 0 ? {} : { subscription: r("subscription", n) }
13
+ };
14
+ }
15
+ var a = {
16
+ accepted: (t) => i(e.ACCEPTED, t),
17
+ committed: (t) => i(e.COMMITTED, t),
18
+ snapshot: (n) => i(e.HANDLED, n, t),
19
+ handled: (t, n) => i(e.HANDLED, n, t)
20
+ };
21
+ function o(t) {
22
+ let n = t.context ?? void 0, r = t.subscription ?? void 0;
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})`;
26
+ }
27
+ if (r !== void 0) throw TypeError("Only a HANDLED hop names a subscription.");
28
+ let i = t.stage.toLowerCase();
29
+ return n === void 0 ? i : `${i}(${n})`;
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
+ }
36
+ function c(e) {
37
+ if (typeof e == "string") return e;
38
+ 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
+ }
41
+ //#endregion
42
+ export { t as SNAPSHOT_SUBSCRIPTION, o as formatHop, s as formatWaitPlan, c as formatWaitTimeout, a as wait };
43
+
44
+ //# sourceMappingURL=wait.es.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wait.es.js","names":["SNAPSHOT_SUBSCRIPTION","NAME","checkName","value","kind","hop","context","subscription","wait","Stage","formatHop","keyword","formatWaitPlan","plan","formatWaitTimeout","timeout"],"sources":["../../src/v10/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":";;AAgBA,IAAaA,IAAwB,YAE/BC,IAAO;AAEb,SAASC,EAAU,GAAc,GAAuB;CACtD,IAAI,CAACD,EAAK,KAAKE,CAAK,GAClB,MAAU,UAAU,SAASC,EAAK,UAAUD,EAAM,GAAG;CAEvD,OAAOA;AACT;AAEA,SAASE,EAAI,GAAc,GAAkB,GAA4B;CACvE,OAAO;EACL;EACA,GAAIC,MAAY,KAAA,IACZ,CAAC,IACD,EAAE,SAASJ,EAAU,WAAWI,CAAO,EAAE;EAC7C,GAAIC,MAAiB,KAAA,IACjB,CAAC,IACD,EAAE,cAAcL,EAAU,gBAAgBK,CAAY,EAAE;CAC9D;AACF;AAgBA,IAAaC,IAAO;CAElB,WAAW,MAA0BH,EAAII,EAAM,UAAUH,CAAO;CAEhE,YAAY,MAA0BD,EAAII,EAAM,WAAWH,CAAO;CAElE,WAAW,MACTD,EAAII,EAAM,SAASH,GAASN,CAAqB;CAEnD,UAAU,GAAsB,MAC9BK,EAAII,EAAM,SAASH,GAASC,CAAY;AAC5C;AASA,SAAgBG,EAAU,GAAoB;CAC5C,IAAMJ,IAAUH,EAAM,WAAW,KAAA,GAC3BI,IAAeJ,EAAM,gBAAgB,KAAA;CAC3C,IAAIA,EAAM,UAAUM,EAAM,SAAS;EACjC,IAAIF,MAAiB,KAAA,GACnB,MAAU,UAAU,uCAAuC;EAK7D,OAHIA,MAAA,aACKD,MAAY,KAAA,IAAY,aAAa,YAAYA,EAAQ,KAE3DA,MAAY,KAAA,IACf,WAAWC,EAAa,KACxB,WAAWD,EAAQ,GAAGC,EAAa;CACzC;CACA,IAAIA,MAAiB,KAAA,GACnB,MAAU,UAAU,0CAA0C;CAEhE,IAAMI,IAAUR,EAAM,MAAM,YAAY;CACxC,OAAOG,MAAY,KAAA,IAAYK,IAAU,GAAGA,EAAQ,GAAGL,EAAQ;AACjE;AAQA,SAAgBM,EAAe,GAAuC;CACpE,IAAI,OAAOC,KAAS,UAAU,OAAOA;CACrC,IAAIA,EAAK,WAAW,GAClB,MAAU,UAAU,mCAAmC;CAEzD,OAAOA,EAAK,IAAIH,CAAS,CAAC,CAAC,KAAK,KAAK;AACvC;AASA,SAAgBI,EAAkB,GAAkC;CAClE,IAAI,OAAOC,KAAY,UAAU,OAAOA;CACxC,IAAI,CAAC,OAAO,UAAUA,CAAO,KAAKA,KAAW,GAC3C,MAAU,UACR,8DAA8DA,EAAQ,EACxE;CAEF,OAAOA,IAAU,OAAS,IAAI,GAAGA,IAAU,IAAK,KAAK,GAAGA,EAAQ;AAClE"}
@@ -0,0 +1,2 @@
1
+ var e={ACCEPTED:`ACCEPTED`,COMMITTED:`COMMITTED`,HANDLED:`HANDLED`};exports.Stage=e;
2
+ //# sourceMappingURL=wire.cjs.map