@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.
- package/dist/client/query/dataset/datasetDescriptorEndpoint.cjs +2 -0
- package/dist/client/query/dataset/datasetDescriptorEndpoint.cjs.map +1 -0
- package/dist/client/query/dataset/datasetDescriptorEndpoint.d.cts +8 -0
- package/dist/client/query/dataset/datasetDescriptorEndpoint.d.ts +8 -0
- package/dist/client/query/dataset/datasetDescriptorEndpoint.es.js +34 -0
- package/dist/client/query/dataset/datasetDescriptorEndpoint.es.js.map +1 -0
- package/dist/client/query/dataset/datasetDirectoryClient.cjs +2 -0
- package/dist/client/query/dataset/datasetDirectoryClient.cjs.map +1 -0
- package/dist/client/query/dataset/datasetDirectoryClient.d.cts +29 -0
- package/dist/client/query/dataset/datasetDirectoryClient.d.ts +29 -0
- package/dist/client/query/dataset/datasetDirectoryClient.es.js +25 -0
- package/dist/client/query/dataset/datasetDirectoryClient.es.js.map +1 -0
- package/dist/client/query/dataset/datasetQueryApi.d.cts +40 -0
- package/dist/client/query/dataset/datasetQueryApi.d.ts +40 -0
- package/dist/client/query/dataset/datasetQueryClient.cjs +2 -0
- package/dist/client/query/dataset/datasetQueryClient.cjs.map +1 -0
- package/dist/client/query/dataset/datasetQueryClient.d.cts +57 -0
- package/dist/client/query/dataset/datasetQueryClient.d.ts +57 -0
- package/dist/client/query/dataset/datasetQueryClient.es.js +154 -0
- package/dist/client/query/dataset/datasetQueryClient.es.js.map +1 -0
- package/dist/client/query/dataset/endpointPaths.cjs +2 -0
- package/dist/client/query/dataset/endpointPaths.cjs.map +1 -0
- package/dist/client/query/dataset/endpointPaths.d.cts +9 -0
- package/dist/client/query/dataset/endpointPaths.d.ts +9 -0
- package/dist/client/query/dataset/endpointPaths.es.js +14 -0
- package/dist/client/query/dataset/endpointPaths.es.js.map +1 -0
- package/dist/client/query/dataset/index.d.cts +3 -0
- package/dist/client/query/dataset/index.d.ts +3 -0
- package/dist/client/query/event/eventStreamQueryApi.d.cts +1 -1
- package/dist/client/query/event/eventStreamQueryApi.d.ts +1 -1
- package/dist/client/query/event/eventStreamQueryClient.cjs.map +1 -1
- package/dist/client/query/event/eventStreamQueryClient.d.cts +4 -1
- package/dist/client/query/event/eventStreamQueryClient.d.ts +4 -1
- package/dist/client/query/event/eventStreamQueryClient.es.js.map +1 -1
- package/dist/client/query/event/index.d.cts +0 -1
- package/dist/client/query/event/index.d.ts +0 -1
- package/dist/client/query/index.d.cts +1 -0
- package/dist/client/query/index.d.ts +1 -0
- package/dist/client/query/snapshot/index.d.cts +0 -1
- package/dist/client/query/snapshot/index.d.ts +0 -1
- package/dist/client/query/snapshot/snapshotQueryApi.d.cts +1 -1
- package/dist/client/query/snapshot/snapshotQueryApi.d.ts +1 -1
- package/dist/client/query/snapshot/snapshotQueryClient.cjs.map +1 -1
- package/dist/client/query/snapshot/snapshotQueryClient.d.cts +4 -1
- package/dist/client/query/snapshot/snapshotQueryClient.d.ts +4 -1
- package/dist/client/query/snapshot/snapshotQueryClient.es.js.map +1 -1
- package/dist/client/routing.cjs.map +1 -1
- package/dist/client/routing.d.cts +2 -2
- package/dist/client/routing.d.ts +2 -2
- package/dist/client/routing.es.js.map +1 -1
- package/dist/dsl/aggregation/admit.cjs +1 -1
- package/dist/dsl/aggregation/admit.cjs.map +1 -1
- package/dist/dsl/aggregation/admit.es.js +84 -65
- package/dist/dsl/aggregation/admit.es.js.map +1 -1
- package/dist/dsl/aggregation/builders.cjs +1 -1
- package/dist/dsl/aggregation/builders.cjs.map +1 -1
- package/dist/dsl/aggregation/builders.d.cts +16 -4
- package/dist/dsl/aggregation/builders.d.ts +16 -4
- package/dist/dsl/aggregation/builders.es.js +89 -78
- package/dist/dsl/aggregation/builders.es.js.map +1 -1
- package/dist/dsl/aggregation/derived.cjs +1 -1
- package/dist/dsl/aggregation/derived.cjs.map +1 -1
- package/dist/dsl/aggregation/derived.d.cts +32 -1
- package/dist/dsl/aggregation/derived.d.ts +32 -1
- package/dist/dsl/aggregation/derived.es.js +23 -1
- package/dist/dsl/aggregation/derived.es.js.map +1 -1
- package/dist/dsl/aggregation/types.cjs +1 -1
- package/dist/dsl/aggregation/types.cjs.map +1 -1
- package/dist/dsl/aggregation/types.d.cts +112 -7
- package/dist/dsl/aggregation/types.d.ts +112 -7
- package/dist/dsl/aggregation/types.es.js +19 -12
- package/dist/dsl/aggregation/types.es.js.map +1 -1
- package/dist/dsl/descriptor.cjs +1 -1
- package/dist/dsl/descriptor.cjs.map +1 -1
- package/dist/dsl/descriptor.d.cts +23 -1
- package/dist/dsl/descriptor.d.ts +23 -1
- package/dist/dsl/descriptor.es.js +2 -1
- package/dist/dsl/descriptor.es.js.map +1 -1
- package/dist/dsl.cjs +1 -1
- package/dist/dsl.d.cts +2 -2
- package/dist/dsl.d.ts +2 -2
- package/dist/dsl.es.js +13 -13
- package/dist/error/headers.cjs.map +1 -1
- package/dist/error/headers.d.cts +3 -2
- package/dist/error/headers.d.ts +3 -2
- package/dist/error/headers.es.js.map +1 -1
- package/dist/error/queryErrorCodes.cjs +1 -1
- package/dist/error/queryErrorCodes.cjs.map +1 -1
- package/dist/error/queryErrorCodes.d.cts +7 -0
- package/dist/error/queryErrorCodes.d.ts +7 -0
- package/dist/error/queryErrorCodes.es.js +2 -1
- package/dist/error/queryErrorCodes.es.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.es.js +35 -33
- package/dist/model/domainEventStream.cjs.map +1 -0
- package/dist/{client/query/event → model}/domainEventStream.d.cts +5 -1
- package/dist/{client/query/event → model}/domainEventStream.d.ts +5 -1
- package/dist/{client/query/event → model}/domainEventStream.es.js +1 -1
- package/dist/model/domainEventStream.es.js.map +1 -0
- package/dist/model/index.d.cts +2 -0
- package/dist/model/index.d.ts +2 -0
- package/dist/model/snapshot.cjs.map +1 -0
- package/dist/{client/query/snapshot → model}/snapshot.d.cts +3 -1
- package/dist/{client/query/snapshot → model}/snapshot.d.ts +3 -1
- package/dist/{client/query/snapshot → model}/snapshot.es.js +1 -1
- package/dist/model/snapshot.es.js.map +1 -0
- package/dist/transport/eventStreams.cjs +1 -1
- package/dist/transport/eventStreams.cjs.map +1 -1
- package/dist/transport/eventStreams.d.cts +3 -1
- package/dist/transport/eventStreams.d.ts +3 -1
- package/dist/transport/eventStreams.es.js +7 -4
- package/dist/transport/eventStreams.es.js.map +1 -1
- package/dist/v10/commands.cjs +2 -0
- package/dist/v10/commands.cjs.map +1 -0
- package/dist/v10/commands.d.cts +105 -0
- package/dist/v10/commands.d.ts +105 -0
- package/dist/v10/commands.es.js +68 -0
- package/dist/v10/commands.es.js.map +1 -0
- package/dist/v10/http.cjs +2 -0
- package/dist/v10/http.cjs.map +1 -0
- package/dist/v10/http.d.cts +87 -0
- package/dist/v10/http.d.ts +87 -0
- package/dist/v10/http.es.js +73 -0
- package/dist/v10/http.es.js.map +1 -0
- package/dist/v10/index.d.cts +19 -0
- package/dist/v10/index.d.ts +19 -0
- package/dist/v10/manifest.cjs +2 -0
- package/dist/v10/manifest.cjs.map +1 -0
- package/dist/v10/manifest.d.cts +109 -0
- package/dist/v10/manifest.d.ts +109 -0
- package/dist/v10/manifest.es.js +14 -0
- package/dist/v10/manifest.es.js.map +1 -0
- package/dist/v10/problem.cjs +2 -0
- package/dist/v10/problem.cjs.map +1 -0
- package/dist/v10/problem.d.cts +164 -0
- package/dist/v10/problem.d.ts +164 -0
- package/dist/v10/problem.es.js +119 -0
- package/dist/v10/problem.es.js.map +1 -0
- package/dist/v10/queries.cjs +2 -0
- package/dist/v10/queries.cjs.map +1 -0
- package/dist/v10/queries.d.cts +136 -0
- package/dist/v10/queries.d.ts +136 -0
- package/dist/v10/queries.es.js +88 -0
- package/dist/v10/queries.es.js.map +1 -0
- package/dist/v10/state.cjs +2 -0
- package/dist/v10/state.cjs.map +1 -0
- package/dist/v10/state.d.cts +53 -0
- package/dist/v10/state.d.ts +53 -0
- package/dist/v10/state.es.js +51 -0
- package/dist/v10/state.es.js.map +1 -0
- package/dist/v10/streams.cjs +2 -0
- package/dist/v10/streams.cjs.map +1 -0
- package/dist/v10/streams.d.cts +14 -0
- package/dist/v10/streams.d.ts +14 -0
- package/dist/v10/streams.es.js +22 -0
- package/dist/v10/streams.es.js.map +1 -0
- package/dist/v10/wait.cjs +2 -0
- package/dist/v10/wait.cjs.map +1 -0
- package/dist/v10/wait.d.cts +61 -0
- package/dist/v10/wait.d.ts +61 -0
- package/dist/v10/wait.es.js +44 -0
- package/dist/v10/wait.es.js.map +1 -0
- package/dist/v10/wire.cjs +2 -0
- package/dist/v10/wire.cjs.map +1 -0
- package/dist/v10/wire.d.cts +301 -0
- package/dist/v10/wire.d.ts +301 -0
- package/dist/v10/wire.es.js +10 -0
- package/dist/v10/wire.es.js.map +1 -0
- package/dist/v10.cjs +1 -0
- package/dist/v10.es.js +9 -0
- package/package.json +12 -2
- package/dist/client/query/event/domainEventStream.cjs.map +0 -1
- package/dist/client/query/event/domainEventStream.es.js.map +0 -1
- package/dist/client/query/snapshot/snapshot.cjs.map +0 -1
- package/dist/client/query/snapshot/snapshot.es.js.map +0 -1
- /package/dist/{client/query/event → model}/domainEventStream.cjs +0 -0
- /package/dist/{client/query/snapshot → model}/snapshot.cjs +0 -0
|
@@ -16,7 +16,9 @@ export declare const QueryEventStreamResultExtractor: ResultExtractor<ReadableSt
|
|
|
16
16
|
* stage the command reached, which errors with a {@link WowError} when the
|
|
17
17
|
* server sends an error event. A command result whose own `errorCode` is not
|
|
18
18
|
* `Ok` is still a result — the command failed in its processing — and is
|
|
19
|
-
* passed on as one.
|
|
19
|
+
* passed on as one. So is a result from a stage this version does not know:
|
|
20
|
+
* a command result names its stage in `stage`, the error event's `ErrorInfo`
|
|
21
|
+
* does not, so a newer server's stage is not read as an error.
|
|
20
22
|
*
|
|
21
23
|
* Generated command clients take it through `COMMAND_STREAM_ENDPOINT`.
|
|
22
24
|
*/
|
|
@@ -16,7 +16,9 @@ export declare const QueryEventStreamResultExtractor: ResultExtractor<ReadableSt
|
|
|
16
16
|
* stage the command reached, which errors with a {@link WowError} when the
|
|
17
17
|
* server sends an error event. A command result whose own `errorCode` is not
|
|
18
18
|
* `Ok` is still a result — the command failed in its processing — and is
|
|
19
|
-
* passed on as one.
|
|
19
|
+
* passed on as one. So is a result from a stage this version does not know:
|
|
20
|
+
* a command result names its stage in `stage`, the error event's `ErrorInfo`
|
|
21
|
+
* does not, so a newer server's stage is not read as an error.
|
|
20
22
|
*
|
|
21
23
|
* Generated command clients take it through `COMMAND_STREAM_ENDPOINT`.
|
|
22
24
|
*/
|
|
@@ -3,16 +3,19 @@ import { CommandStage as n } from "../model/command.es.js";
|
|
|
3
3
|
import { JsonEventStreamResultExtractor as r } from "@ahoo-wang/fetcher-eventstream";
|
|
4
4
|
//#region src/transport/eventStreams.ts
|
|
5
5
|
var i = "message", a = new Set(Object.values(n));
|
|
6
|
-
function o(
|
|
6
|
+
function o(e) {
|
|
7
|
+
return typeof e == "object" && !!e && typeof e.stage == "string";
|
|
8
|
+
}
|
|
9
|
+
function s(n) {
|
|
7
10
|
return new TransformStream({ transform(r, i) {
|
|
8
|
-
n(r
|
|
11
|
+
n(r) ? i.enqueue(r.data) : i.error(new e(t(r.data) ? r.data : {
|
|
9
12
|
errorCode: r.event,
|
|
10
13
|
errorMsg: ""
|
|
11
14
|
}));
|
|
12
15
|
} });
|
|
13
16
|
}
|
|
14
|
-
var
|
|
17
|
+
var c = async (e) => (await r(e)).pipeThrough(s((e) => e.event === i)), l = async (e) => (await r(e)).pipeThrough(s((e) => a.has(e.event) || o(e.data)));
|
|
15
18
|
//#endregion
|
|
16
|
-
export {
|
|
19
|
+
export { l as CommandResultEventStreamResultExtractor, c as QueryEventStreamResultExtractor };
|
|
17
20
|
|
|
18
21
|
//# sourceMappingURL=eventStreams.es.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eventStreams.es.js","names":["ROW_EVENT","COMMAND_STAGES","CommandStage","rowsUntilErrorEvent","isData","event","controller","WowError","isErrorInfo","QueryEventStreamResultExtractor","JsonEventStreamResultExtractor","exchange","
|
|
1
|
+
{"version":3,"file":"eventStreams.es.js","names":["ROW_EVENT","COMMAND_STAGES","CommandStage","namesStage","data","rowsUntilErrorEvent","isData","event","controller","WowError","isErrorInfo","QueryEventStreamResultExtractor","JsonEventStreamResultExtractor","exchange","CommandResultEventStreamResultExtractor"],"sources":["../../src/transport/eventStreams.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 { ResultExtractor } from '@ahoo-wang/fetcher';\nimport {\n JsonEventStreamResultExtractor,\n type JsonServerSentEvent,\n} from '@ahoo-wang/fetcher-eventstream';\nimport { isErrorInfo, WowError } from '../error/wowError.js';\nimport { type CommandResult, CommandStage } from '../model/command.js';\n\n/**\n * The event name the server gives the rows of a query stream. Wow sends them\n * without an `event:` field, which the event-stream parser reads as\n * `message`.\n */\nconst ROW_EVENT = 'message';\n\nconst COMMAND_STAGES: ReadonlySet<string> = new Set(\n Object.values(CommandStage),\n);\n\n/** True when the data is a command result: it names the stage it reports. */\nfunction namesStage(data: unknown): boolean {\n return (\n typeof data === 'object' &&\n data !== null &&\n typeof (data as { stage?: unknown }).stage === 'string'\n );\n}\n\n/**\n * Unwraps the events `isData` accepts to their data, and errors the stream\n * with a `WowError` at the first one it does not.\n *\n * Wow's `event`, `id` and `retry` fields carry nothing an application reads:\n * a query row always arrives as `message`, a command result names its stage\n * in `stage`, and Wow does not resume a stream. So the stream a client\n * answers is the rows themselves.\n *\n * When a server-sent event stream fails midway, Wow still answers HTTP 200\n * and sends one last event whose name is the error code and whose data is\n * the `ErrorInfo`, then closes the stream (`WebFluxResponseStrategy`,\n * `errorResume`). Read as data it would pass for a row or a command result;\n * here it ends the stream the way a failed request ends a call.\n */\nfunction rowsUntilErrorEvent<T>(\n isData: (event: JsonServerSentEvent<unknown>) => boolean,\n): TransformStream<JsonServerSentEvent<unknown>, T> {\n return new TransformStream({\n transform(event, controller) {\n if (isData(event)) {\n controller.enqueue(event.data as T);\n return;\n }\n controller.error(\n new WowError(\n isErrorInfo(event.data)\n ? event.data\n : { errorCode: event.event, errorMsg: '' },\n ),\n );\n },\n });\n}\n\n/**\n * Internal: applications and generated code take the two extractors below\n * through the endpoint presets `QUERY_STREAM_ENDPOINT` and\n * `COMMAND_STREAM_ENDPOINT` (`endpoints.ts`); this file is not re-exported.\n *\n * The result extractor of the query streams (`listStream`,\n * `listStateStream`, `aggregateStream`, `loadStream`): the response as a\n * stream of rows, one per server-sent event, which errors with a\n * {@link WowError} when the server sends an error event.\n */\nexport const QueryEventStreamResultExtractor: ResultExtractor<\n ReadableStream<unknown>\n> = async exchange =>\n (await JsonEventStreamResultExtractor(exchange)).pipeThrough(\n rowsUntilErrorEvent(event => event.event === ROW_EVENT),\n );\n\n/**\n * The result extractor of `sendAndWaitStream`: the command results, one per\n * stage the command reached, which errors with a {@link WowError} when the\n * server sends an error event. A command result whose own `errorCode` is not\n * `Ok` is still a result — the command failed in its processing — and is\n * passed on as one. So is a result from a stage this version does not know:\n * a command result names its stage in `stage`, the error event's `ErrorInfo`\n * does not, so a newer server's stage is not read as an error.\n *\n * Generated command clients take it through `COMMAND_STREAM_ENDPOINT`.\n */\nexport const CommandResultEventStreamResultExtractor: ResultExtractor<\n ReadableStream<CommandResult>\n> = async exchange =>\n (await JsonEventStreamResultExtractor(exchange)).pipeThrough(\n rowsUntilErrorEvent<CommandResult>(\n event => COMMAND_STAGES.has(event.event) || namesStage(event.data),\n ),\n );\n"],"mappings":";;;;AA0BA,IAAMA,IAAY,WAEZC,IAAsC,IAAI,IAC9C,OAAO,OAAOC,CAAY,CAC5B;AAGA,SAASC,EAAW,GAAwB;CAC1C,OACE,OAAOC,KAAS,cAChBA,KACA,OAAQA,EAA6B,SAAU;AAEnD;AAiBA,SAASC,EACP,GACkD;CAClD,OAAO,IAAI,gBAAgB,EACzB,UAAU,GAAO,GAAY;EAC3B,AAAIC,EAAOC,CAAK,IACdC,EAAW,QAAQD,EAAM,IAAS,IAGpCC,EAAW,MACT,IAAIC,EACFC,EAAYH,EAAM,IAAI,IAClBA,EAAM,OACN;GAAE,WAAWA,EAAM;GAAO,UAAU;EAAG,CAC7C,CACF;CACF,EACF,CAAC;AACH;AAYA,IAAaI,IAET,OAAM,OACP,MAAMC,EAA+BC,CAAQ,EAAA,CAAG,YAC/CR,GAAoB,MAASE,EAAM,UAAUP,CAAS,CACxD,GAaWc,IAET,OAAM,OACP,MAAMF,EAA+BC,CAAQ,EAAA,CAAG,YAC/CR,GACE,MAASJ,EAAe,IAAIM,EAAM,KAAK,KAAKJ,EAAWI,EAAM,IAAI,CACnE,CACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./problem.cjs"),t=require("./http.cjs"),n=require("./streams.cjs"),r=require("./wait.cjs");var i={DELETE_AGGREGATE:`wow.lifecycle.DeleteAggregate`,RESTORE_AGGREGATE:`wow.lifecycle.RestoreAggregate`,TRANSFER_OWNER:`wow.lifecycle.TransferOwner`,TRANSFER_SPACE:`wow.lifecycle.TransferSpace`,APPLY_TAGS:`wow.lifecycle.ApplyTags`};function a(e){return e.replace(/([A-Z]+)([A-Z][a-z])/g,`$1-$2`).replace(/([a-z0-9])([A-Z])/g,`$1-$2`).replace(/[_\s]+/g,`-`).toLowerCase()}function o(e,n){let i=e.wait;return{[t.WowV10Headers.REQUEST_ID]:e.requestId,[t.WowV10Headers.WAIT]:i?.plan===void 0?void 0:r.formatWaitPlan(i.plan),[t.WowV10Headers.WAIT_TIMEOUT]:i?.timeout===void 0?void 0:r.formatWaitTimeout(i.timeout),[t.WowV10Headers.IF_MATCH]:e.expectedVersion===void 0?void 0:`"${e.expectedVersion}"`,Accept:n}}var s=class{constructor(e={}){this.client=e}async send(n,r,i={}){try{let e=await this.post(n,r,i);return await t.json(e)}catch(t){if(i.resolveRejected&&t instanceof e.WowProblemError&&t.result!==void 0)return t.result;throw t}}async stream(e,t,r={}){return n.commandResults(await this.post(e,t,r,`text/event-stream`))}async lifecycle(e,n,r,s,c={}){let l=`${e}/${encodeURIComponent(n)}`;if(r===i.DELETE_AGGREGATE){let e=await t.send(this.client,{method:`DELETE`,path:l,headers:o(c),options:c});return t.json(e)}return this.send(`${l}/${a(r)}`,s??{},c)}post(e,n,r,i){return t.send(this.client,{method:`POST`,path:e.includes(`{id}`)?t.expandPath(e,{id:r.id??``}):e,headers:o(r,i),body:n??{},options:r})}};exports.CommandGateway=s,exports.LifecycleCommands=i,exports.commandSegment=a;
|
|
2
|
+
//# sourceMappingURL=commands.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.cjs","names":["WowV10Headers","formatWaitPlan","formatWaitTimeout","json","WowProblemError","commandResults","send","expandPath","require_problem","require_http","require_streams","require_wait","LifecycleCommands","commandSegment","name","commandHeaders","wait","options","accept","CommandGateway","client","response","path","body","error","base","aggregatePath","id","command"],"sources":["../../src/v10/commands.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 expandPath,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowV10Headers,\n} from './http.js';\nimport type { CommandResult } from './wire.js';\nimport { WowProblemError } from './problem.js';\nimport { commandResults, type CommandResultStream } from './streams.js';\nimport { formatWaitPlan, formatWaitTimeout, type WaitOptions } from './wait.js';\n\n/** What a command request carries beside its body (decisions D95–D99). */\nexport interface CommandOptions extends RequestOptions {\n /**\n * The request id (`Wow-Request-Id`): a retry with the same one is\n * deduplicated, answered as the first commit's duplicate.\n */\n readonly requestId?: string;\n /** What to wait for, and for how long. */\n readonly wait?: WaitOptions;\n /** The version the aggregate must be at (`If-Match`). */\n readonly expectedVersion?: number;\n /**\n * Resolve a result that did not succeed instead of rejecting with its\n * {@link WowProblemError}; `false` by default.\n */\n readonly resolveRejected?: boolean;\n}\n\n/** The options of a command whose route may name the aggregate id or not. */\nexport interface CreateCommandOptions extends CommandOptions {\n /**\n * The id of the aggregate to create (decision D176); the service generates\n * one when absent.\n */\n readonly id?: string;\n}\n\n/** The lifecycle commands an aggregate may list (decision D113). */\nexport const LifecycleCommands = {\n DELETE_AGGREGATE: 'wow.lifecycle.DeleteAggregate',\n RESTORE_AGGREGATE: 'wow.lifecycle.RestoreAggregate',\n TRANSFER_OWNER: 'wow.lifecycle.TransferOwner',\n TRANSFER_SPACE: 'wow.lifecycle.TransferSpace',\n APPLY_TAGS: 'wow.lifecycle.ApplyTags',\n} as const;\n\n/** A {@link LifecycleCommands} value. */\nexport type LifecycleCommand =\n (typeof LifecycleCommands)[keyof typeof LifecycleCommands];\n\n/** The body of `wow.lifecycle.TransferOwner`. */\nexport interface TransferOwner {\n readonly ownerId: string;\n}\n\n/** The body of `wow.lifecycle.TransferSpace`. */\nexport interface TransferSpace {\n readonly spaceId: string;\n}\n\n/** The body of `wow.lifecycle.ApplyTags`: the tags, names to values. */\nexport interface ApplyTags {\n readonly tags: Readonly<Record<string, readonly string[]>>;\n}\n\n/**\n * The route segment of a command name, as the server derives it: kebab case,\n * dots kept (`AddCartItem` → `add-cart-item`,\n * `wow.lifecycle.RestoreAggregate` → `wow.lifecycle.restore-aggregate`).\n *\n * @param name - The command's name\n */\nexport function commandSegment(name: string): string {\n return name\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')\n .replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n .replace(/[_\\s]+/g, '-')\n .toLowerCase();\n}\n\nfunction commandHeaders(\n options: CommandOptions,\n accept?: string,\n): Record<string, string | undefined> {\n const wait = options.wait;\n return {\n [WowV10Headers.REQUEST_ID]: options.requestId,\n [WowV10Headers.WAIT]:\n wait?.plan === undefined ? undefined : formatWaitPlan(wait.plan),\n [WowV10Headers.WAIT_TIMEOUT]:\n wait?.timeout === undefined ? undefined : formatWaitTimeout(wait.timeout),\n [WowV10Headers.IF_MATCH]:\n options.expectedVersion === undefined\n ? undefined\n : `\"${options.expectedVersion}\"`,\n Accept: accept,\n };\n}\n\n/**\n * Sends commands to the command routes of a Wow V10 service\n * (`POST /{context}/{aggregate}/{id}/{command}`, and without `{id}` for a\n * command that may create its aggregate). Generated aggregate clients build\n * on it; it serves any route too.\n *\n * A command that did not succeed rejects with a {@link WowProblemError}\n * holding its result, unless the options resolve it.\n */\nexport class CommandGateway {\n /** @param client - How the service is reached */\n constructor(readonly client: WowClientOptions = {}) {}\n\n /**\n * Sends a command and answers the result its wait ends with: 200, or 202\n * for a plan that ends at `accepted`.\n *\n * @param path - The route, `{id}` filled from `id`\n * @param body - The command's body; `{}` when absent\n * @param options - Headers, wait and the aggregate id\n */\n async send<R = Record<string, unknown>>(\n path: string,\n body?: object,\n options: CreateCommandOptions = {},\n ): Promise<CommandResult<R>> {\n try {\n const response = await this.post(path, body, options);\n return await json<CommandResult<R>>(response);\n } catch (error) {\n if (\n options.resolveRejected &&\n error instanceof WowProblemError &&\n error.result !== undefined\n ) {\n return error.result as CommandResult<R>;\n }\n throw error;\n }\n }\n\n /**\n * Sends a command with `Accept: text/event-stream` and answers one result\n * per hop as the wait advances. An admission refusal rejects with its\n * problem; a rejection after admission is the stream's last result.\n *\n * @param path - The route, `{id}` filled from `id`\n * @param body - The command's body; `{}` when absent\n * @param options - Headers, wait and the aggregate id\n */\n async stream<R = Record<string, unknown>>(\n path: string,\n body?: object,\n options: CreateCommandOptions = {},\n ): Promise<CommandResultStream<R>> {\n return commandResults<R>(\n await this.post(path, body, options, 'text/event-stream'),\n );\n }\n\n /**\n * Sends a lifecycle command an aggregate lists: `DELETE\n * /{context}/{aggregate}/{id}` for `DeleteAggregate`, `POST\n * …/{id}/wow.lifecycle.<kebab>` for the others.\n *\n * @param aggregatePath - `/{context}/{aggregate}`\n * @param id - The aggregate's id\n * @param command - The lifecycle command\n * @param body - Its body, for the commands that have one\n * @param options - Headers and wait\n */\n async lifecycle<R = Record<string, unknown>>(\n aggregatePath: string,\n id: string,\n command: LifecycleCommand,\n body?: TransferOwner | TransferSpace | ApplyTags,\n options: CommandOptions = {},\n ): Promise<CommandResult<R>> {\n const base = `${aggregatePath}/${encodeURIComponent(id)}`;\n if (command === LifecycleCommands.DELETE_AGGREGATE) {\n const response = await send(this.client, {\n method: 'DELETE',\n path: base,\n headers: commandHeaders(options),\n options,\n });\n return json<CommandResult<R>>(response);\n }\n return this.send<R>(\n `${base}/${commandSegment(command)}`,\n body ?? {},\n options,\n );\n }\n\n private post(\n path: string,\n body: object | undefined,\n options: CreateCommandOptions,\n accept?: string,\n ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: path.includes('{id}')\n ? expandPath(path, { id: options.id ?? '' })\n : path,\n headers: commandHeaders(options, accept),\n body: body ?? {},\n options,\n });\n }\n}\n"],"mappings":"4GAsDA,IAAaY,EAAoB,CAC/B,iBAAkB,gCAClB,kBAAmB,iCACnB,eAAgB,8BAChB,eAAgB,8BAChB,WAAY,yBACd,EA4BA,SAAgBC,EAAe,EAAsB,CACnD,OAAOC,EACJ,QAAQ,wBAAyB,OAAO,CAAC,CACzC,QAAQ,qBAAsB,OAAO,CAAC,CACtC,QAAQ,UAAW,GAAG,CAAC,CACvB,YAAY,CACjB,CAEA,SAASC,EACP,EACA,EACoC,CACpC,IAAMC,EAAOC,EAAQ,KACrB,MAAO,EACJjB,EAAAA,cAAc,YAAaiB,EAAQ,WACnCjB,EAAAA,cAAc,MACbgB,GAAM,OAAS,IAAA,GAAY,IAAA,GAAYf,EAAAA,eAAee,EAAK,IAAI,GAChEhB,EAAAA,cAAc,cACbgB,GAAM,UAAY,IAAA,GAAY,IAAA,GAAYd,EAAAA,kBAAkBc,EAAK,OAAO,GACzEhB,EAAAA,cAAc,UACbiB,EAAQ,kBAAoB,IAAA,GACxB,IAAA,GACA,IAAIA,EAAQ,gBAAgB,GAClC,OAAQC,CACV,CACF,CAWA,IAAaC,EAAb,KAA4B,CAE1B,YAAY,EAAoC,CAAC,EAAG,CAA/B,KAAA,OAAAC,CAAgC,CAUrD,MAAM,KACJ,EACA,EACA,EAAgC,CAAC,EACN,CAC3B,GAAI,CACF,IAAMC,EAAW,MAAM,KAAK,KAAKC,EAAMC,EAAMN,CAAO,EACpD,OAAO,MAAMd,EAAAA,KAAuBkB,CAAQ,CAC9C,OAASG,EAAO,CACd,GACEP,EAAQ,iBACRO,aAAiBpB,EAAAA,iBACjBoB,EAAM,SAAW,IAAA,GAEjB,OAAOA,EAAM,OAEf,MAAMA,CACR,CACF,CAWA,MAAM,OACJ,EACA,EACA,EAAgC,CAAC,EACA,CACjC,OAAOnB,EAAAA,eACL,MAAM,KAAK,KAAKiB,EAAMC,EAAMN,EAAS,mBAAmB,CAC1D,CACF,CAaA,MAAM,UACJ,EACA,EACA,EACA,EACA,EAA0B,CAAC,EACA,CAC3B,IAAMQ,EAAO,GAAGC,EAAc,GAAG,mBAAmBC,CAAE,IACtD,GAAIC,IAAYhB,EAAkB,iBAAkB,CAClD,IAAMS,EAAW,MAAMf,EAAAA,KAAK,KAAK,OAAQ,CACvC,OAAQ,SACR,KAAMmB,EACN,QAASV,EAAeE,CAAO,EAC/B,SACF,CAAC,EACD,OAAOd,EAAAA,KAAuBkB,CAAQ,CACxC,CACA,OAAO,KAAK,KACV,GAAGI,EAAK,GAAGZ,EAAee,CAAO,IACjCL,GAAQ,CAAC,EACTN,CACF,CACF,CAEA,KACE,EACA,EACA,EACA,EACmB,CACnB,OAAOX,EAAAA,KAAK,KAAK,OAAQ,CACvB,OAAQ,OACR,KAAMgB,EAAK,SAAS,MAAM,EACtBf,EAAAA,WAAWe,EAAM,CAAE,GAAIL,EAAQ,IAAM,EAAG,CAAC,EACzCK,EACJ,QAASP,EAAeE,EAASC,CAAM,EACvC,KAAMK,GAAQ,CAAC,EACf,SACF,CAAC,CACH,CACF"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { RequestOptions, WowClientOptions } from './http.cjs';
|
|
2
|
+
import { CommandResult } from './wire.cjs';
|
|
3
|
+
import { CommandResultStream } from './streams.cjs';
|
|
4
|
+
import { WaitOptions } from './wait.cjs';
|
|
5
|
+
/** What a command request carries beside its body (decisions D95–D99). */
|
|
6
|
+
export interface CommandOptions extends RequestOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The request id (`Wow-Request-Id`): a retry with the same one is
|
|
9
|
+
* deduplicated, answered as the first commit's duplicate.
|
|
10
|
+
*/
|
|
11
|
+
readonly requestId?: string;
|
|
12
|
+
/** What to wait for, and for how long. */
|
|
13
|
+
readonly wait?: WaitOptions;
|
|
14
|
+
/** The version the aggregate must be at (`If-Match`). */
|
|
15
|
+
readonly expectedVersion?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a result that did not succeed instead of rejecting with its
|
|
18
|
+
* {@link WowProblemError}; `false` by default.
|
|
19
|
+
*/
|
|
20
|
+
readonly resolveRejected?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** The options of a command whose route may name the aggregate id or not. */
|
|
23
|
+
export interface CreateCommandOptions extends CommandOptions {
|
|
24
|
+
/**
|
|
25
|
+
* The id of the aggregate to create (decision D176); the service generates
|
|
26
|
+
* one when absent.
|
|
27
|
+
*/
|
|
28
|
+
readonly id?: string;
|
|
29
|
+
}
|
|
30
|
+
/** The lifecycle commands an aggregate may list (decision D113). */
|
|
31
|
+
export declare const LifecycleCommands: {
|
|
32
|
+
readonly DELETE_AGGREGATE: "wow.lifecycle.DeleteAggregate";
|
|
33
|
+
readonly RESTORE_AGGREGATE: "wow.lifecycle.RestoreAggregate";
|
|
34
|
+
readonly TRANSFER_OWNER: "wow.lifecycle.TransferOwner";
|
|
35
|
+
readonly TRANSFER_SPACE: "wow.lifecycle.TransferSpace";
|
|
36
|
+
readonly APPLY_TAGS: "wow.lifecycle.ApplyTags";
|
|
37
|
+
};
|
|
38
|
+
/** A {@link LifecycleCommands} value. */
|
|
39
|
+
export type LifecycleCommand = (typeof LifecycleCommands)[keyof typeof LifecycleCommands];
|
|
40
|
+
/** The body of `wow.lifecycle.TransferOwner`. */
|
|
41
|
+
export interface TransferOwner {
|
|
42
|
+
readonly ownerId: string;
|
|
43
|
+
}
|
|
44
|
+
/** The body of `wow.lifecycle.TransferSpace`. */
|
|
45
|
+
export interface TransferSpace {
|
|
46
|
+
readonly spaceId: string;
|
|
47
|
+
}
|
|
48
|
+
/** The body of `wow.lifecycle.ApplyTags`: the tags, names to values. */
|
|
49
|
+
export interface ApplyTags {
|
|
50
|
+
readonly tags: Readonly<Record<string, readonly string[]>>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The route segment of a command name, as the server derives it: kebab case,
|
|
54
|
+
* dots kept (`AddCartItem` → `add-cart-item`,
|
|
55
|
+
* `wow.lifecycle.RestoreAggregate` → `wow.lifecycle.restore-aggregate`).
|
|
56
|
+
*
|
|
57
|
+
* @param name - The command's name
|
|
58
|
+
*/
|
|
59
|
+
export declare function commandSegment(name: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Sends commands to the command routes of a Wow V10 service
|
|
62
|
+
* (`POST /{context}/{aggregate}/{id}/{command}`, and without `{id}` for a
|
|
63
|
+
* command that may create its aggregate). Generated aggregate clients build
|
|
64
|
+
* on it; it serves any route too.
|
|
65
|
+
*
|
|
66
|
+
* A command that did not succeed rejects with a {@link WowProblemError}
|
|
67
|
+
* holding its result, unless the options resolve it.
|
|
68
|
+
*/
|
|
69
|
+
export declare class CommandGateway {
|
|
70
|
+
readonly client: WowClientOptions;
|
|
71
|
+
/** @param client - How the service is reached */
|
|
72
|
+
constructor(client?: WowClientOptions);
|
|
73
|
+
/**
|
|
74
|
+
* Sends a command and answers the result its wait ends with: 200, or 202
|
|
75
|
+
* for a plan that ends at `accepted`.
|
|
76
|
+
*
|
|
77
|
+
* @param path - The route, `{id}` filled from `id`
|
|
78
|
+
* @param body - The command's body; `{}` when absent
|
|
79
|
+
* @param options - Headers, wait and the aggregate id
|
|
80
|
+
*/
|
|
81
|
+
send<R = Record<string, unknown>>(path: string, body?: object, options?: CreateCommandOptions): Promise<CommandResult<R>>;
|
|
82
|
+
/**
|
|
83
|
+
* Sends a command with `Accept: text/event-stream` and answers one result
|
|
84
|
+
* per hop as the wait advances. An admission refusal rejects with its
|
|
85
|
+
* problem; a rejection after admission is the stream's last result.
|
|
86
|
+
*
|
|
87
|
+
* @param path - The route, `{id}` filled from `id`
|
|
88
|
+
* @param body - The command's body; `{}` when absent
|
|
89
|
+
* @param options - Headers, wait and the aggregate id
|
|
90
|
+
*/
|
|
91
|
+
stream<R = Record<string, unknown>>(path: string, body?: object, options?: CreateCommandOptions): Promise<CommandResultStream<R>>;
|
|
92
|
+
/**
|
|
93
|
+
* Sends a lifecycle command an aggregate lists: `DELETE
|
|
94
|
+
* /{context}/{aggregate}/{id}` for `DeleteAggregate`, `POST
|
|
95
|
+
* …/{id}/wow.lifecycle.<kebab>` for the others.
|
|
96
|
+
*
|
|
97
|
+
* @param aggregatePath - `/{context}/{aggregate}`
|
|
98
|
+
* @param id - The aggregate's id
|
|
99
|
+
* @param command - The lifecycle command
|
|
100
|
+
* @param body - Its body, for the commands that have one
|
|
101
|
+
* @param options - Headers and wait
|
|
102
|
+
*/
|
|
103
|
+
lifecycle<R = Record<string, unknown>>(aggregatePath: string, id: string, command: LifecycleCommand, body?: TransferOwner | TransferSpace | ApplyTags, options?: CommandOptions): Promise<CommandResult<R>>;
|
|
104
|
+
private post;
|
|
105
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { RequestOptions, WowClientOptions } from './http.js';
|
|
2
|
+
import { CommandResult } from './wire.js';
|
|
3
|
+
import { CommandResultStream } from './streams.js';
|
|
4
|
+
import { WaitOptions } from './wait.js';
|
|
5
|
+
/** What a command request carries beside its body (decisions D95–D99). */
|
|
6
|
+
export interface CommandOptions extends RequestOptions {
|
|
7
|
+
/**
|
|
8
|
+
* The request id (`Wow-Request-Id`): a retry with the same one is
|
|
9
|
+
* deduplicated, answered as the first commit's duplicate.
|
|
10
|
+
*/
|
|
11
|
+
readonly requestId?: string;
|
|
12
|
+
/** What to wait for, and for how long. */
|
|
13
|
+
readonly wait?: WaitOptions;
|
|
14
|
+
/** The version the aggregate must be at (`If-Match`). */
|
|
15
|
+
readonly expectedVersion?: number;
|
|
16
|
+
/**
|
|
17
|
+
* Resolve a result that did not succeed instead of rejecting with its
|
|
18
|
+
* {@link WowProblemError}; `false` by default.
|
|
19
|
+
*/
|
|
20
|
+
readonly resolveRejected?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** The options of a command whose route may name the aggregate id or not. */
|
|
23
|
+
export interface CreateCommandOptions extends CommandOptions {
|
|
24
|
+
/**
|
|
25
|
+
* The id of the aggregate to create (decision D176); the service generates
|
|
26
|
+
* one when absent.
|
|
27
|
+
*/
|
|
28
|
+
readonly id?: string;
|
|
29
|
+
}
|
|
30
|
+
/** The lifecycle commands an aggregate may list (decision D113). */
|
|
31
|
+
export declare const LifecycleCommands: {
|
|
32
|
+
readonly DELETE_AGGREGATE: "wow.lifecycle.DeleteAggregate";
|
|
33
|
+
readonly RESTORE_AGGREGATE: "wow.lifecycle.RestoreAggregate";
|
|
34
|
+
readonly TRANSFER_OWNER: "wow.lifecycle.TransferOwner";
|
|
35
|
+
readonly TRANSFER_SPACE: "wow.lifecycle.TransferSpace";
|
|
36
|
+
readonly APPLY_TAGS: "wow.lifecycle.ApplyTags";
|
|
37
|
+
};
|
|
38
|
+
/** A {@link LifecycleCommands} value. */
|
|
39
|
+
export type LifecycleCommand = (typeof LifecycleCommands)[keyof typeof LifecycleCommands];
|
|
40
|
+
/** The body of `wow.lifecycle.TransferOwner`. */
|
|
41
|
+
export interface TransferOwner {
|
|
42
|
+
readonly ownerId: string;
|
|
43
|
+
}
|
|
44
|
+
/** The body of `wow.lifecycle.TransferSpace`. */
|
|
45
|
+
export interface TransferSpace {
|
|
46
|
+
readonly spaceId: string;
|
|
47
|
+
}
|
|
48
|
+
/** The body of `wow.lifecycle.ApplyTags`: the tags, names to values. */
|
|
49
|
+
export interface ApplyTags {
|
|
50
|
+
readonly tags: Readonly<Record<string, readonly string[]>>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* The route segment of a command name, as the server derives it: kebab case,
|
|
54
|
+
* dots kept (`AddCartItem` → `add-cart-item`,
|
|
55
|
+
* `wow.lifecycle.RestoreAggregate` → `wow.lifecycle.restore-aggregate`).
|
|
56
|
+
*
|
|
57
|
+
* @param name - The command's name
|
|
58
|
+
*/
|
|
59
|
+
export declare function commandSegment(name: string): string;
|
|
60
|
+
/**
|
|
61
|
+
* Sends commands to the command routes of a Wow V10 service
|
|
62
|
+
* (`POST /{context}/{aggregate}/{id}/{command}`, and without `{id}` for a
|
|
63
|
+
* command that may create its aggregate). Generated aggregate clients build
|
|
64
|
+
* on it; it serves any route too.
|
|
65
|
+
*
|
|
66
|
+
* A command that did not succeed rejects with a {@link WowProblemError}
|
|
67
|
+
* holding its result, unless the options resolve it.
|
|
68
|
+
*/
|
|
69
|
+
export declare class CommandGateway {
|
|
70
|
+
readonly client: WowClientOptions;
|
|
71
|
+
/** @param client - How the service is reached */
|
|
72
|
+
constructor(client?: WowClientOptions);
|
|
73
|
+
/**
|
|
74
|
+
* Sends a command and answers the result its wait ends with: 200, or 202
|
|
75
|
+
* for a plan that ends at `accepted`.
|
|
76
|
+
*
|
|
77
|
+
* @param path - The route, `{id}` filled from `id`
|
|
78
|
+
* @param body - The command's body; `{}` when absent
|
|
79
|
+
* @param options - Headers, wait and the aggregate id
|
|
80
|
+
*/
|
|
81
|
+
send<R = Record<string, unknown>>(path: string, body?: object, options?: CreateCommandOptions): Promise<CommandResult<R>>;
|
|
82
|
+
/**
|
|
83
|
+
* Sends a command with `Accept: text/event-stream` and answers one result
|
|
84
|
+
* per hop as the wait advances. An admission refusal rejects with its
|
|
85
|
+
* problem; a rejection after admission is the stream's last result.
|
|
86
|
+
*
|
|
87
|
+
* @param path - The route, `{id}` filled from `id`
|
|
88
|
+
* @param body - The command's body; `{}` when absent
|
|
89
|
+
* @param options - Headers, wait and the aggregate id
|
|
90
|
+
*/
|
|
91
|
+
stream<R = Record<string, unknown>>(path: string, body?: object, options?: CreateCommandOptions): Promise<CommandResultStream<R>>;
|
|
92
|
+
/**
|
|
93
|
+
* Sends a lifecycle command an aggregate lists: `DELETE
|
|
94
|
+
* /{context}/{aggregate}/{id}` for `DeleteAggregate`, `POST
|
|
95
|
+
* …/{id}/wow.lifecycle.<kebab>` for the others.
|
|
96
|
+
*
|
|
97
|
+
* @param aggregatePath - `/{context}/{aggregate}`
|
|
98
|
+
* @param id - The aggregate's id
|
|
99
|
+
* @param command - The lifecycle command
|
|
100
|
+
* @param body - Its body, for the commands that have one
|
|
101
|
+
* @param options - Headers and wait
|
|
102
|
+
*/
|
|
103
|
+
lifecycle<R = Record<string, unknown>>(aggregatePath: string, id: string, command: LifecycleCommand, body?: TransferOwner | TransferSpace | ApplyTags, options?: CommandOptions): Promise<CommandResult<R>>;
|
|
104
|
+
private post;
|
|
105
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { WowProblemError as e } from "./problem.es.js";
|
|
2
|
+
import { WowV10Headers as t, expandPath as n, json as r, send as i } from "./http.es.js";
|
|
3
|
+
import { commandResults as a } from "./streams.es.js";
|
|
4
|
+
import { formatWaitPlan as o, formatWaitTimeout as s } from "./wait.es.js";
|
|
5
|
+
//#region src/v10/commands.ts
|
|
6
|
+
var c = {
|
|
7
|
+
DELETE_AGGREGATE: "wow.lifecycle.DeleteAggregate",
|
|
8
|
+
RESTORE_AGGREGATE: "wow.lifecycle.RestoreAggregate",
|
|
9
|
+
TRANSFER_OWNER: "wow.lifecycle.TransferOwner",
|
|
10
|
+
TRANSFER_SPACE: "wow.lifecycle.TransferSpace",
|
|
11
|
+
APPLY_TAGS: "wow.lifecycle.ApplyTags"
|
|
12
|
+
};
|
|
13
|
+
function l(e) {
|
|
14
|
+
return e.replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2").replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/[_\s]+/g, "-").toLowerCase();
|
|
15
|
+
}
|
|
16
|
+
function u(e, n) {
|
|
17
|
+
let r = e.wait;
|
|
18
|
+
return {
|
|
19
|
+
[t.REQUEST_ID]: e.requestId,
|
|
20
|
+
[t.WAIT]: r?.plan === void 0 ? void 0 : o(r.plan),
|
|
21
|
+
[t.WAIT_TIMEOUT]: r?.timeout === void 0 ? void 0 : s(r.timeout),
|
|
22
|
+
[t.IF_MATCH]: e.expectedVersion === void 0 ? void 0 : `"${e.expectedVersion}"`,
|
|
23
|
+
Accept: n
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
var d = class {
|
|
27
|
+
constructor(e = {}) {
|
|
28
|
+
this.client = e;
|
|
29
|
+
}
|
|
30
|
+
async send(t, n, i = {}) {
|
|
31
|
+
try {
|
|
32
|
+
let e = await this.post(t, n, i);
|
|
33
|
+
return await r(e);
|
|
34
|
+
} catch (t) {
|
|
35
|
+
if (i.resolveRejected && t instanceof e && t.result !== void 0) return t.result;
|
|
36
|
+
throw t;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
async stream(e, t, n = {}) {
|
|
40
|
+
return a(await this.post(e, t, n, "text/event-stream"));
|
|
41
|
+
}
|
|
42
|
+
async lifecycle(e, t, n, a, o = {}) {
|
|
43
|
+
let s = `${e}/${encodeURIComponent(t)}`;
|
|
44
|
+
if (n === c.DELETE_AGGREGATE) {
|
|
45
|
+
let e = await i(this.client, {
|
|
46
|
+
method: "DELETE",
|
|
47
|
+
path: s,
|
|
48
|
+
headers: u(o),
|
|
49
|
+
options: o
|
|
50
|
+
});
|
|
51
|
+
return r(e);
|
|
52
|
+
}
|
|
53
|
+
return this.send(`${s}/${l(n)}`, a ?? {}, o);
|
|
54
|
+
}
|
|
55
|
+
post(e, t, r, a) {
|
|
56
|
+
return i(this.client, {
|
|
57
|
+
method: "POST",
|
|
58
|
+
path: e.includes("{id}") ? n(e, { id: r.id ?? "" }) : e,
|
|
59
|
+
headers: u(r, a),
|
|
60
|
+
body: t ?? {},
|
|
61
|
+
options: r
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
//#endregion
|
|
66
|
+
export { d as CommandGateway, c as LifecycleCommands, l as commandSegment };
|
|
67
|
+
|
|
68
|
+
//# sourceMappingURL=commands.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commands.es.js","names":["LifecycleCommands","commandSegment","name","commandHeaders","wait","options","WowV10Headers","formatWaitPlan","formatWaitTimeout","accept","CommandGateway","client","response","path","body","json","error","WowProblemError","commandResults","base","aggregatePath","id","command","send","expandPath"],"sources":["../../src/v10/commands.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 expandPath,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowV10Headers,\n} from './http.js';\nimport type { CommandResult } from './wire.js';\nimport { WowProblemError } from './problem.js';\nimport { commandResults, type CommandResultStream } from './streams.js';\nimport { formatWaitPlan, formatWaitTimeout, type WaitOptions } from './wait.js';\n\n/** What a command request carries beside its body (decisions D95–D99). */\nexport interface CommandOptions extends RequestOptions {\n /**\n * The request id (`Wow-Request-Id`): a retry with the same one is\n * deduplicated, answered as the first commit's duplicate.\n */\n readonly requestId?: string;\n /** What to wait for, and for how long. */\n readonly wait?: WaitOptions;\n /** The version the aggregate must be at (`If-Match`). */\n readonly expectedVersion?: number;\n /**\n * Resolve a result that did not succeed instead of rejecting with its\n * {@link WowProblemError}; `false` by default.\n */\n readonly resolveRejected?: boolean;\n}\n\n/** The options of a command whose route may name the aggregate id or not. */\nexport interface CreateCommandOptions extends CommandOptions {\n /**\n * The id of the aggregate to create (decision D176); the service generates\n * one when absent.\n */\n readonly id?: string;\n}\n\n/** The lifecycle commands an aggregate may list (decision D113). */\nexport const LifecycleCommands = {\n DELETE_AGGREGATE: 'wow.lifecycle.DeleteAggregate',\n RESTORE_AGGREGATE: 'wow.lifecycle.RestoreAggregate',\n TRANSFER_OWNER: 'wow.lifecycle.TransferOwner',\n TRANSFER_SPACE: 'wow.lifecycle.TransferSpace',\n APPLY_TAGS: 'wow.lifecycle.ApplyTags',\n} as const;\n\n/** A {@link LifecycleCommands} value. */\nexport type LifecycleCommand =\n (typeof LifecycleCommands)[keyof typeof LifecycleCommands];\n\n/** The body of `wow.lifecycle.TransferOwner`. */\nexport interface TransferOwner {\n readonly ownerId: string;\n}\n\n/** The body of `wow.lifecycle.TransferSpace`. */\nexport interface TransferSpace {\n readonly spaceId: string;\n}\n\n/** The body of `wow.lifecycle.ApplyTags`: the tags, names to values. */\nexport interface ApplyTags {\n readonly tags: Readonly<Record<string, readonly string[]>>;\n}\n\n/**\n * The route segment of a command name, as the server derives it: kebab case,\n * dots kept (`AddCartItem` → `add-cart-item`,\n * `wow.lifecycle.RestoreAggregate` → `wow.lifecycle.restore-aggregate`).\n *\n * @param name - The command's name\n */\nexport function commandSegment(name: string): string {\n return name\n .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')\n .replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n .replace(/[_\\s]+/g, '-')\n .toLowerCase();\n}\n\nfunction commandHeaders(\n options: CommandOptions,\n accept?: string,\n): Record<string, string | undefined> {\n const wait = options.wait;\n return {\n [WowV10Headers.REQUEST_ID]: options.requestId,\n [WowV10Headers.WAIT]:\n wait?.plan === undefined ? undefined : formatWaitPlan(wait.plan),\n [WowV10Headers.WAIT_TIMEOUT]:\n wait?.timeout === undefined ? undefined : formatWaitTimeout(wait.timeout),\n [WowV10Headers.IF_MATCH]:\n options.expectedVersion === undefined\n ? undefined\n : `\"${options.expectedVersion}\"`,\n Accept: accept,\n };\n}\n\n/**\n * Sends commands to the command routes of a Wow V10 service\n * (`POST /{context}/{aggregate}/{id}/{command}`, and without `{id}` for a\n * command that may create its aggregate). Generated aggregate clients build\n * on it; it serves any route too.\n *\n * A command that did not succeed rejects with a {@link WowProblemError}\n * holding its result, unless the options resolve it.\n */\nexport class CommandGateway {\n /** @param client - How the service is reached */\n constructor(readonly client: WowClientOptions = {}) {}\n\n /**\n * Sends a command and answers the result its wait ends with: 200, or 202\n * for a plan that ends at `accepted`.\n *\n * @param path - The route, `{id}` filled from `id`\n * @param body - The command's body; `{}` when absent\n * @param options - Headers, wait and the aggregate id\n */\n async send<R = Record<string, unknown>>(\n path: string,\n body?: object,\n options: CreateCommandOptions = {},\n ): Promise<CommandResult<R>> {\n try {\n const response = await this.post(path, body, options);\n return await json<CommandResult<R>>(response);\n } catch (error) {\n if (\n options.resolveRejected &&\n error instanceof WowProblemError &&\n error.result !== undefined\n ) {\n return error.result as CommandResult<R>;\n }\n throw error;\n }\n }\n\n /**\n * Sends a command with `Accept: text/event-stream` and answers one result\n * per hop as the wait advances. An admission refusal rejects with its\n * problem; a rejection after admission is the stream's last result.\n *\n * @param path - The route, `{id}` filled from `id`\n * @param body - The command's body; `{}` when absent\n * @param options - Headers, wait and the aggregate id\n */\n async stream<R = Record<string, unknown>>(\n path: string,\n body?: object,\n options: CreateCommandOptions = {},\n ): Promise<CommandResultStream<R>> {\n return commandResults<R>(\n await this.post(path, body, options, 'text/event-stream'),\n );\n }\n\n /**\n * Sends a lifecycle command an aggregate lists: `DELETE\n * /{context}/{aggregate}/{id}` for `DeleteAggregate`, `POST\n * …/{id}/wow.lifecycle.<kebab>` for the others.\n *\n * @param aggregatePath - `/{context}/{aggregate}`\n * @param id - The aggregate's id\n * @param command - The lifecycle command\n * @param body - Its body, for the commands that have one\n * @param options - Headers and wait\n */\n async lifecycle<R = Record<string, unknown>>(\n aggregatePath: string,\n id: string,\n command: LifecycleCommand,\n body?: TransferOwner | TransferSpace | ApplyTags,\n options: CommandOptions = {},\n ): Promise<CommandResult<R>> {\n const base = `${aggregatePath}/${encodeURIComponent(id)}`;\n if (command === LifecycleCommands.DELETE_AGGREGATE) {\n const response = await send(this.client, {\n method: 'DELETE',\n path: base,\n headers: commandHeaders(options),\n options,\n });\n return json<CommandResult<R>>(response);\n }\n return this.send<R>(\n `${base}/${commandSegment(command)}`,\n body ?? {},\n options,\n );\n }\n\n private post(\n path: string,\n body: object | undefined,\n options: CreateCommandOptions,\n accept?: string,\n ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: path.includes('{id}')\n ? expandPath(path, { id: options.id ?? '' })\n : path,\n headers: commandHeaders(options, accept),\n body: body ?? {},\n options,\n });\n }\n}\n"],"mappings":";;;;;AAsDA,IAAaA,IAAoB;CAC/B,kBAAkB;CAClB,mBAAmB;CACnB,gBAAgB;CAChB,gBAAgB;CAChB,YAAY;AACd;AA4BA,SAAgBC,EAAe,GAAsB;CACnD,OAAOC,EACJ,QAAQ,yBAAyB,OAAO,CAAC,CACzC,QAAQ,sBAAsB,OAAO,CAAC,CACtC,QAAQ,WAAW,GAAG,CAAC,CACvB,YAAY;AACjB;AAEA,SAASC,EACP,GACA,GACoC;CACpC,IAAMC,IAAOC,EAAQ;CACrB,OAAO;GACJC,EAAc,aAAaD,EAAQ;GACnCC,EAAc,OACbF,GAAM,SAAS,KAAA,IAAY,KAAA,IAAYG,EAAeH,EAAK,IAAI;GAChEE,EAAc,eACbF,GAAM,YAAY,KAAA,IAAY,KAAA,IAAYI,EAAkBJ,EAAK,OAAO;GACzEE,EAAc,WACbD,EAAQ,oBAAoB,KAAA,IACxB,KAAA,IACA,IAAIA,EAAQ,gBAAgB;EAClC,QAAQI;CACV;AACF;AAWA,IAAaC,IAAb,MAA4B;CAE1B,YAAY,IAAoC,CAAC,GAAG;EAA/B,KAAA,SAAAC;CAAgC;CAUrD,MAAM,KACJ,GACA,GACA,IAAgC,CAAC,GACN;EAC3B,IAAI;GACF,IAAMC,IAAW,MAAM,KAAK,KAAKC,GAAMC,GAAMT,CAAO;GACpD,OAAO,MAAMU,EAAuBH,CAAQ;EAC9C,SAASI,GAAO;GACd,IACEX,EAAQ,mBACRW,aAAiBC,KACjBD,EAAM,WAAW,KAAA,GAEjB,OAAOA,EAAM;GAEf,MAAMA;EACR;CACF;CAWA,MAAM,OACJ,GACA,GACA,IAAgC,CAAC,GACA;EACjC,OAAOE,EACL,MAAM,KAAK,KAAKL,GAAMC,GAAMT,GAAS,mBAAmB,CAC1D;CACF;CAaA,MAAM,UACJ,GACA,GACA,GACA,GACA,IAA0B,CAAC,GACA;EAC3B,IAAMc,IAAO,GAAGC,EAAc,GAAG,mBAAmBC,CAAE;EACtD,IAAIC,MAAYtB,EAAkB,kBAAkB;GAClD,IAAMY,IAAW,MAAMW,EAAK,KAAK,QAAQ;IACvC,QAAQ;IACR,MAAMJ;IACN,SAAShB,EAAeE,CAAO;IAC/B;GACF,CAAC;GACD,OAAOU,EAAuBH,CAAQ;EACxC;EACA,OAAO,KAAK,KACV,GAAGO,EAAK,GAAGlB,EAAeqB,CAAO,KACjCR,KAAQ,CAAC,GACTT,CACF;CACF;CAEA,KACE,GACA,GACA,GACA,GACmB;EACnB,OAAOkB,EAAK,KAAK,QAAQ;GACvB,QAAQ;GACR,MAAMV,EAAK,SAAS,MAAM,IACtBW,EAAWX,GAAM,EAAE,IAAIR,EAAQ,MAAM,GAAG,CAAC,IACzCQ;GACJ,SAASV,EAAeE,GAASI,CAAM;GACvC,MAAMK,KAAQ,CAAC;GACf;EACF,CAAC;CACH;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./problem.cjs");let t=require("@ahoo-wang/fetcher");var n={REQUEST_ID:`Wow-Request-Id`,WAIT:`Wow-Wait`,WAIT_TIMEOUT:`Wow-Wait-Timeout`,SCOPE:`Wow-Scope`,SPACE:`Wow-Space`,IF_MATCH:`If-Match`,IF_NONE_MATCH:`If-None-Match`,ETAG:`ETag`,RETRY_AFTER:`Retry-After`};function r(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`}function i(e){let t=[e.tenantId===void 0?void 0:`tenant=${r(e.tenantId)}`,e.ownerId===void 0?void 0:`owner=${r(e.ownerId)}`,e.spaceId===void 0?void 0:`space=${r(e.spaceId)}`].filter(e=>e!==void 0);if(t.length===0)throw TypeError(`Wow-Scope names a tenant, an owner or a space.`);return t.join(`, `)}function a(e,t){return e.replace(/\{([^}]+)\}/g,(n,r)=>{let i=t[r];if(i===void 0||i===``)throw TypeError(`The path ${e} needs ${r}.`);return encodeURIComponent(i)})}function o(e){if(!e)return``;let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!==void 0&&t.append(n,String(r));let n=t.toString();return n?`?${n}`:``}async function s(r,a){let s=a.options??{},c={};for(let[e,t]of Object.entries({...a.headers,...s.scope===void 0?{}:{[n.SCOPE]:i(s.scope)},...s.space===void 0?{}:{[n.SPACE]:s.space},...s.headers}))t!==void 0&&(c[e]=t);let l=`${r.basePath??``}${a.path}${o(a.query)}`;try{return await(r.fetcher??t.fetcher).fetch(l,{method:a.method,headers:c,...a.body===void 0?{}:{body:a.body},...s.signal===void 0?{}:{signal:s.signal}})}catch(t){let n=t?.exchange?.response;if(a.notModified&&n?.status===304)return n;throw await e.toWowProblemError(t)??t}}async function c(e){return await e.json()}function l(e){let t=e.headers.get(n.ETAG);return t===null?void 0:t.replace(/^W\//,``).replace(/"/g,``)}exports.WowV10Headers=n,exports.entityTag=l,exports.expandPath=a,exports.formatScope=i,exports.json=c,exports.send=s;
|
|
2
|
+
//# sourceMappingURL=http.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.cjs","names":["defaultFetcher","toWowProblemError","require_problem","_ahoo_wang_fetcher","WowV10Headers","quote","value","formatScope","members","scope","member","expandPath","path","params","name","queryString","query","text","send","options","call","headers","url","client","error","response","json","entityTag","tag"],"sources":["../../src/v10/http.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 Fetcher, fetcher as defaultFetcher } from '@ahoo-wang/fetcher';\nimport { toWowProblemError } from './problem.js';\n\n/**\n * The request headers of a Wow V10 service's public port (decisions D95,\n * D96, D98, D99).\n */\nexport const WowV10Headers = {\n /** The caller's id of the request: a retry with the same one is deduplicated. */\n REQUEST_ID: 'Wow-Request-Id',\n /** The wait plan (decision D99). */\n WAIT: 'Wow-Wait',\n /** How long to wait: `500ms`, `10s` or an ISO-8601 duration. */\n WAIT_TIMEOUT: 'Wow-Wait-Timeout',\n /** The scope to act in, for a caller allowed to act across scopes (decision D95). */\n SCOPE: 'Wow-Scope',\n /** The space, among the caller's own, to act in (decision D96). */\n SPACE: 'Wow-Space',\n /** The expected version of the aggregate, as an entity tag. */\n IF_MATCH: 'If-Match',\n /** The version, or descriptor version, a read already holds. */\n IF_NONE_MATCH: 'If-None-Match',\n /** The version of a state read, or of a query descriptor. */\n ETAG: 'ETag',\n /** The seconds after which a failed request may be retried. */\n RETRY_AFTER: 'Retry-After',\n} as const;\n\n/** How a V10 client reaches its service. */\nexport interface WowClientOptions {\n /**\n * The fetcher requests go through, with its base URL and interceptors\n * (authentication, say); the default fetcher when absent.\n */\n readonly fetcher?: Fetcher;\n /** A path put before every route, such as a gateway's prefix. */\n readonly basePath?: string;\n}\n\n/**\n * The scope a caller allowed to act across scopes acts in: the `Wow-Scope`\n * header (decision D95).\n */\nexport interface TargetScope {\n readonly tenantId?: string;\n readonly ownerId?: string;\n readonly spaceId?: string;\n}\n\nfunction quote(value: string): string {\n return `\"${value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')}\"`;\n}\n\n/**\n * A target scope as the `Wow-Scope` header spells it, an RFC 8941\n * dictionary: `tenant=\"t1\", owner=\"u1\", space=\"s1\"`.\n *\n * @param scope - The scope; at least one of its members is set\n */\nexport function formatScope(scope: TargetScope): string {\n const members = [\n scope.tenantId === undefined\n ? undefined\n : `tenant=${quote(scope.tenantId)}`,\n scope.ownerId === undefined ? undefined : `owner=${quote(scope.ownerId)}`,\n scope.spaceId === undefined ? undefined : `space=${quote(scope.spaceId)}`,\n ].filter(member => member !== undefined);\n if (members.length === 0) {\n throw new TypeError('Wow-Scope names a tenant, an owner or a space.');\n }\n return members.join(', ');\n}\n\n/** What every V10 request may carry beside its own parameters. */\nexport interface RequestOptions {\n /** The scope to act in (`Wow-Scope`), for a caller allowed to. */\n readonly scope?: TargetScope;\n /** The space to act in (`Wow-Space`), among the caller's own. */\n readonly space?: string;\n /** More headers: the request facts the service records, say. */\n readonly headers?: Readonly<Record<string, string>>;\n /** Cancels the request. */\n readonly signal?: AbortSignal;\n}\n\n/** One request of a V10 client. */\nexport interface Call {\n readonly method: 'GET' | 'POST' | 'DELETE';\n readonly path: string;\n readonly query?: Readonly<Record<string, string | number | undefined>>;\n readonly headers?: Readonly<Record<string, string | undefined>>;\n readonly body?: unknown;\n readonly options?: RequestOptions;\n /** Answers a 304 rather than rejecting with it. */\n readonly notModified?: boolean;\n}\n\n/** `{name}` segments of `path` filled from `params`, each encoded. */\nexport function expandPath(\n path: string,\n params: Readonly<Record<string, string>>,\n): string {\n return path.replace(/\\{([^}]+)\\}/g, (segment, name: string) => {\n const value = params[name];\n if (value === undefined || value === '') {\n throw new TypeError(`The path ${path} needs ${name}.`);\n }\n return encodeURIComponent(value);\n });\n}\n\nfunction queryString(\n query: Readonly<Record<string, string | number | undefined>> | undefined,\n): string {\n if (!query) return '';\n const params = new URLSearchParams();\n for (const [name, value] of Object.entries(query)) {\n if (value !== undefined) params.append(name, String(value));\n }\n const text = params.toString();\n return text ? `?${text}` : '';\n}\n\n/**\n * Sends one request through the client's fetcher and answers its response;\n * a response that is not 2xx rejects with a {@link WowProblemError}.\n *\n * @param client - The client's options\n * @param call - The request\n */\nexport async function send(\n client: WowClientOptions,\n call: Call,\n): Promise<Response> {\n const options = call.options ?? {};\n const headers: Record<string, string> = {};\n for (const [name, value] of Object.entries({\n ...call.headers,\n ...(options.scope === undefined\n ? {}\n : { [WowV10Headers.SCOPE]: formatScope(options.scope) }),\n ...(options.space === undefined\n ? {}\n : { [WowV10Headers.SPACE]: options.space }),\n ...options.headers,\n })) {\n if (value !== undefined) headers[name] = value;\n }\n const url = `${client.basePath ?? ''}${call.path}${queryString(call.query)}`;\n try {\n return await (client.fetcher ?? defaultFetcher).fetch(url, {\n method: call.method,\n headers,\n ...(call.body === undefined ? {} : { body: call.body as object }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n });\n } catch (error) {\n const response = (error as { exchange?: { response?: Response } })?.exchange\n ?.response;\n if (call.notModified && response?.status === 304) return response;\n throw (await toWowProblemError(error)) ?? error;\n }\n}\n\n/** The JSON body of a 2xx response. */\nexport async function json<T>(response: Response): Promise<T> {\n return (await response.json()) as T;\n}\n\n/** The entity tag of a response without its quotes or weak marker. */\nexport function entityTag(response: Response): string | undefined {\n const tag = response.headers.get(WowV10Headers.ETAG);\n return tag === null ? undefined : tag.replace(/^W\\//, '').replace(/\"/g, '');\n}\n"],"mappings":"qEAoBA,IAAaI,EAAgB,CAE3B,WAAY,iBAEZ,KAAM,WAEN,aAAc,mBAEd,MAAO,YAEP,MAAO,YAEP,SAAU,WAEV,cAAe,gBAEf,KAAM,OAEN,YAAa,aACf,EAuBA,SAASC,EAAM,EAAuB,CACpC,MAAO,IAAIC,EAAM,QAAQ,MAAO,MAAM,CAAC,CAAC,QAAQ,KAAM,KAAK,EAAE,EAC/D,CAQA,SAAgBC,EAAY,EAA4B,CACtD,IAAMC,EAAU,CACdC,EAAM,WAAa,IAAA,GACf,IAAA,GACA,UAAUJ,EAAMI,EAAM,QAAQ,IAClCA,EAAM,UAAY,IAAA,GAAY,IAAA,GAAY,SAASJ,EAAMI,EAAM,OAAO,IACtEA,EAAM,UAAY,IAAA,GAAY,IAAA,GAAY,SAASJ,EAAMI,EAAM,OAAO,GACxE,CAAC,CAAC,OAAO,GAAUC,IAAW,IAAA,EAAS,EACvC,GAAIF,EAAQ,SAAW,EACrB,MAAU,UAAU,gDAAgD,EAEtE,OAAOA,EAAQ,KAAK,IAAI,CAC1B,CA2BA,SAAgBG,EACd,EACA,EACQ,CACR,OAAOC,EAAK,QAAQ,gBAAiB,EAAS,IAAiB,CAC7D,IAAMN,EAAQO,EAAOC,GACrB,GAAIR,IAAU,IAAA,IAAaA,IAAU,GACnC,MAAU,UAAU,YAAYM,EAAK,SAASE,EAAK,EAAE,EAEvD,OAAO,mBAAmBR,CAAK,CACjC,CAAC,CACH,CAEA,SAASS,EACP,EACQ,CACR,GAAI,CAACC,EAAO,MAAO,GACnB,IAAMH,EAAS,IAAI,gBACnB,IAAK,GAAM,CAACC,EAAMR,KAAU,OAAO,QAAQU,CAAK,EAC1CV,IAAU,IAAA,IAAWO,EAAO,OAAOC,EAAM,OAAOR,CAAK,CAAC,EAE5D,IAAMW,EAAOJ,EAAO,SAAS,EAC7B,OAAOI,EAAO,IAAIA,IAAS,EAC7B,CASA,eAAsBC,EACpB,EACA,EACmB,CACnB,IAAMC,EAAUC,EAAK,SAAW,CAAC,EAC3BC,EAAkC,CAAC,EACzC,IAAK,GAAM,CAACP,EAAMR,KAAU,OAAO,QAAQ,CACzC,GAAGc,EAAK,QACR,GAAID,EAAQ,QAAU,IAAA,GAClB,CAAC,EACD,EAAGf,EAAc,OAAQG,EAAYY,EAAQ,KAAK,CAAE,EACxD,GAAIA,EAAQ,QAAU,IAAA,GAClB,CAAC,EACD,EAAGf,EAAc,OAAQe,EAAQ,KAAM,EAC3C,GAAGA,EAAQ,OACb,CAAC,EACKb,IAAU,IAAA,KAAW,EAAQQ,GAAQR,GAE3C,IAAMgB,EAAM,GAAGC,EAAO,UAAY,KAAKH,EAAK,OAAOL,EAAYK,EAAK,KAAK,IACzE,GAAI,CACF,OAAO,MAAOG,EAAO,SAAWvB,EAAAA,QAAAA,CAAgB,MAAMsB,EAAK,CACzD,OAAQF,EAAK,OACb,UACA,GAAIA,EAAK,OAAS,IAAA,GAAY,CAAC,EAAI,CAAE,KAAMA,EAAK,IAAe,EAC/D,GAAID,EAAQ,SAAW,IAAA,GAAY,CAAC,EAAI,CAAE,OAAQA,EAAQ,MAAO,CACnE,CAAC,CACH,OAASK,EAAO,CACd,IAAMC,EAAYD,GAAkD,UAChE,SACJ,GAAIJ,EAAK,aAAeK,GAAU,SAAW,IAAK,OAAOA,EACzD,MAAO,MAAMxB,EAAAA,kBAAkBuB,CAAK,GAAMA,CAC5C,CACF,CAGA,eAAsBE,EAAQ,EAAgC,CAC5D,OAAQ,MAAMD,EAAS,KAAK,CAC9B,CAGA,SAAgBE,EAAU,EAAwC,CAChE,IAAMC,EAAMH,EAAS,QAAQ,IAAIrB,EAAc,IAAI,EACnD,OAAOwB,IAAQ,KAAO,IAAA,GAAYA,EAAI,QAAQ,OAAQ,EAAE,CAAC,CAAC,QAAQ,KAAM,EAAE,CAC5E"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
2
|
+
/**
|
|
3
|
+
* The request headers of a Wow V10 service's public port (decisions D95,
|
|
4
|
+
* D96, D98, D99).
|
|
5
|
+
*/
|
|
6
|
+
export declare const WowV10Headers: {
|
|
7
|
+
/** The caller's id of the request: a retry with the same one is deduplicated. */
|
|
8
|
+
readonly REQUEST_ID: "Wow-Request-Id";
|
|
9
|
+
/** The wait plan (decision D99). */
|
|
10
|
+
readonly WAIT: "Wow-Wait";
|
|
11
|
+
/** How long to wait: `500ms`, `10s` or an ISO-8601 duration. */
|
|
12
|
+
readonly WAIT_TIMEOUT: "Wow-Wait-Timeout";
|
|
13
|
+
/** The scope to act in, for a caller allowed to act across scopes (decision D95). */
|
|
14
|
+
readonly SCOPE: "Wow-Scope";
|
|
15
|
+
/** The space, among the caller's own, to act in (decision D96). */
|
|
16
|
+
readonly SPACE: "Wow-Space";
|
|
17
|
+
/** The expected version of the aggregate, as an entity tag. */
|
|
18
|
+
readonly IF_MATCH: "If-Match";
|
|
19
|
+
/** The version, or descriptor version, a read already holds. */
|
|
20
|
+
readonly IF_NONE_MATCH: "If-None-Match";
|
|
21
|
+
/** The version of a state read, or of a query descriptor. */
|
|
22
|
+
readonly ETAG: "ETag";
|
|
23
|
+
/** The seconds after which a failed request may be retried. */
|
|
24
|
+
readonly RETRY_AFTER: "Retry-After";
|
|
25
|
+
};
|
|
26
|
+
/** How a V10 client reaches its service. */
|
|
27
|
+
export interface WowClientOptions {
|
|
28
|
+
/**
|
|
29
|
+
* The fetcher requests go through, with its base URL and interceptors
|
|
30
|
+
* (authentication, say); the default fetcher when absent.
|
|
31
|
+
*/
|
|
32
|
+
readonly fetcher?: Fetcher;
|
|
33
|
+
/** A path put before every route, such as a gateway's prefix. */
|
|
34
|
+
readonly basePath?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The scope a caller allowed to act across scopes acts in: the `Wow-Scope`
|
|
38
|
+
* header (decision D95).
|
|
39
|
+
*/
|
|
40
|
+
export interface TargetScope {
|
|
41
|
+
readonly tenantId?: string;
|
|
42
|
+
readonly ownerId?: string;
|
|
43
|
+
readonly spaceId?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A target scope as the `Wow-Scope` header spells it, an RFC 8941
|
|
47
|
+
* dictionary: `tenant="t1", owner="u1", space="s1"`.
|
|
48
|
+
*
|
|
49
|
+
* @param scope - The scope; at least one of its members is set
|
|
50
|
+
*/
|
|
51
|
+
export declare function formatScope(scope: TargetScope): string;
|
|
52
|
+
/** What every V10 request may carry beside its own parameters. */
|
|
53
|
+
export interface RequestOptions {
|
|
54
|
+
/** The scope to act in (`Wow-Scope`), for a caller allowed to. */
|
|
55
|
+
readonly scope?: TargetScope;
|
|
56
|
+
/** The space to act in (`Wow-Space`), among the caller's own. */
|
|
57
|
+
readonly space?: string;
|
|
58
|
+
/** More headers: the request facts the service records, say. */
|
|
59
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
60
|
+
/** Cancels the request. */
|
|
61
|
+
readonly signal?: AbortSignal;
|
|
62
|
+
}
|
|
63
|
+
/** One request of a V10 client. */
|
|
64
|
+
export interface Call {
|
|
65
|
+
readonly method: 'GET' | 'POST' | 'DELETE';
|
|
66
|
+
readonly path: string;
|
|
67
|
+
readonly query?: Readonly<Record<string, string | number | undefined>>;
|
|
68
|
+
readonly headers?: Readonly<Record<string, string | undefined>>;
|
|
69
|
+
readonly body?: unknown;
|
|
70
|
+
readonly options?: RequestOptions;
|
|
71
|
+
/** Answers a 304 rather than rejecting with it. */
|
|
72
|
+
readonly notModified?: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** `{name}` segments of `path` filled from `params`, each encoded. */
|
|
75
|
+
export declare function expandPath(path: string, params: Readonly<Record<string, string>>): string;
|
|
76
|
+
/**
|
|
77
|
+
* Sends one request through the client's fetcher and answers its response;
|
|
78
|
+
* a response that is not 2xx rejects with a {@link WowProblemError}.
|
|
79
|
+
*
|
|
80
|
+
* @param client - The client's options
|
|
81
|
+
* @param call - The request
|
|
82
|
+
*/
|
|
83
|
+
export declare function send(client: WowClientOptions, call: Call): Promise<Response>;
|
|
84
|
+
/** The JSON body of a 2xx response. */
|
|
85
|
+
export declare function json<T>(response: Response): Promise<T>;
|
|
86
|
+
/** The entity tag of a response without its quotes or weak marker. */
|
|
87
|
+
export declare function entityTag(response: Response): string | undefined;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Fetcher } from '@ahoo-wang/fetcher';
|
|
2
|
+
/**
|
|
3
|
+
* The request headers of a Wow V10 service's public port (decisions D95,
|
|
4
|
+
* D96, D98, D99).
|
|
5
|
+
*/
|
|
6
|
+
export declare const WowV10Headers: {
|
|
7
|
+
/** The caller's id of the request: a retry with the same one is deduplicated. */
|
|
8
|
+
readonly REQUEST_ID: "Wow-Request-Id";
|
|
9
|
+
/** The wait plan (decision D99). */
|
|
10
|
+
readonly WAIT: "Wow-Wait";
|
|
11
|
+
/** How long to wait: `500ms`, `10s` or an ISO-8601 duration. */
|
|
12
|
+
readonly WAIT_TIMEOUT: "Wow-Wait-Timeout";
|
|
13
|
+
/** The scope to act in, for a caller allowed to act across scopes (decision D95). */
|
|
14
|
+
readonly SCOPE: "Wow-Scope";
|
|
15
|
+
/** The space, among the caller's own, to act in (decision D96). */
|
|
16
|
+
readonly SPACE: "Wow-Space";
|
|
17
|
+
/** The expected version of the aggregate, as an entity tag. */
|
|
18
|
+
readonly IF_MATCH: "If-Match";
|
|
19
|
+
/** The version, or descriptor version, a read already holds. */
|
|
20
|
+
readonly IF_NONE_MATCH: "If-None-Match";
|
|
21
|
+
/** The version of a state read, or of a query descriptor. */
|
|
22
|
+
readonly ETAG: "ETag";
|
|
23
|
+
/** The seconds after which a failed request may be retried. */
|
|
24
|
+
readonly RETRY_AFTER: "Retry-After";
|
|
25
|
+
};
|
|
26
|
+
/** How a V10 client reaches its service. */
|
|
27
|
+
export interface WowClientOptions {
|
|
28
|
+
/**
|
|
29
|
+
* The fetcher requests go through, with its base URL and interceptors
|
|
30
|
+
* (authentication, say); the default fetcher when absent.
|
|
31
|
+
*/
|
|
32
|
+
readonly fetcher?: Fetcher;
|
|
33
|
+
/** A path put before every route, such as a gateway's prefix. */
|
|
34
|
+
readonly basePath?: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The scope a caller allowed to act across scopes acts in: the `Wow-Scope`
|
|
38
|
+
* header (decision D95).
|
|
39
|
+
*/
|
|
40
|
+
export interface TargetScope {
|
|
41
|
+
readonly tenantId?: string;
|
|
42
|
+
readonly ownerId?: string;
|
|
43
|
+
readonly spaceId?: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A target scope as the `Wow-Scope` header spells it, an RFC 8941
|
|
47
|
+
* dictionary: `tenant="t1", owner="u1", space="s1"`.
|
|
48
|
+
*
|
|
49
|
+
* @param scope - The scope; at least one of its members is set
|
|
50
|
+
*/
|
|
51
|
+
export declare function formatScope(scope: TargetScope): string;
|
|
52
|
+
/** What every V10 request may carry beside its own parameters. */
|
|
53
|
+
export interface RequestOptions {
|
|
54
|
+
/** The scope to act in (`Wow-Scope`), for a caller allowed to. */
|
|
55
|
+
readonly scope?: TargetScope;
|
|
56
|
+
/** The space to act in (`Wow-Space`), among the caller's own. */
|
|
57
|
+
readonly space?: string;
|
|
58
|
+
/** More headers: the request facts the service records, say. */
|
|
59
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
60
|
+
/** Cancels the request. */
|
|
61
|
+
readonly signal?: AbortSignal;
|
|
62
|
+
}
|
|
63
|
+
/** One request of a V10 client. */
|
|
64
|
+
export interface Call {
|
|
65
|
+
readonly method: 'GET' | 'POST' | 'DELETE';
|
|
66
|
+
readonly path: string;
|
|
67
|
+
readonly query?: Readonly<Record<string, string | number | undefined>>;
|
|
68
|
+
readonly headers?: Readonly<Record<string, string | undefined>>;
|
|
69
|
+
readonly body?: unknown;
|
|
70
|
+
readonly options?: RequestOptions;
|
|
71
|
+
/** Answers a 304 rather than rejecting with it. */
|
|
72
|
+
readonly notModified?: boolean;
|
|
73
|
+
}
|
|
74
|
+
/** `{name}` segments of `path` filled from `params`, each encoded. */
|
|
75
|
+
export declare function expandPath(path: string, params: Readonly<Record<string, string>>): string;
|
|
76
|
+
/**
|
|
77
|
+
* Sends one request through the client's fetcher and answers its response;
|
|
78
|
+
* a response that is not 2xx rejects with a {@link WowProblemError}.
|
|
79
|
+
*
|
|
80
|
+
* @param client - The client's options
|
|
81
|
+
* @param call - The request
|
|
82
|
+
*/
|
|
83
|
+
export declare function send(client: WowClientOptions, call: Call): Promise<Response>;
|
|
84
|
+
/** The JSON body of a 2xx response. */
|
|
85
|
+
export declare function json<T>(response: Response): Promise<T>;
|
|
86
|
+
/** The entity tag of a response without its quotes or weak marker. */
|
|
87
|
+
export declare function entityTag(response: Response): string | undefined;
|