@ahoo-wang/wow-client 10.0.0-alpha.6 → 10.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +77 -23
- package/README.zh-CN.md +67 -19
- package/dist/commands.cjs +1 -1
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +134 -61
- package/dist/commands.d.ts +134 -61
- package/dist/commands.es.js +129 -59
- package/dist/commands.es.js.map +1 -1
- package/dist/developmentCaller.cjs +2 -0
- package/dist/developmentCaller.cjs.map +1 -0
- package/dist/developmentCaller.d.cts +61 -0
- package/dist/developmentCaller.d.ts +61 -0
- package/dist/developmentCaller.es.js +26 -0
- package/dist/developmentCaller.es.js.map +1 -0
- package/dist/dsl/aggregation/admit.cjs +1 -1
- package/dist/dsl/aggregation/admit.cjs.map +1 -1
- package/dist/dsl/aggregation/admit.es.js +93 -93
- 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 +20 -20
- package/dist/dsl/aggregation/builders.d.ts +20 -20
- package/dist/dsl/aggregation/builders.es.js +88 -88
- package/dist/dsl/aggregation/builders.es.js.map +1 -1
- package/dist/dsl/aggregation/derived.cjs.map +1 -1
- package/dist/dsl/aggregation/derived.d.cts +8 -8
- package/dist/dsl/aggregation/derived.d.ts +8 -8
- package/dist/dsl/aggregation/derived.es.js +1 -2
- package/dist/dsl/aggregation/derived.es.js.map +1 -1
- package/dist/dsl/aggregation/expressionTrees.cjs.map +1 -1
- package/dist/dsl/aggregation/expressionTrees.es.js +1 -2
- package/dist/dsl/aggregation/having.cjs +1 -1
- package/dist/dsl/aggregation/having.cjs.map +1 -1
- package/dist/dsl/aggregation/having.d.cts +12 -12
- package/dist/dsl/aggregation/having.d.ts +12 -12
- package/dist/dsl/aggregation/having.es.js +33 -33
- package/dist/dsl/aggregation/having.es.js.map +1 -1
- package/dist/dsl/aggregation/sort.cjs.map +1 -1
- package/dist/dsl/aggregation/sort.es.js +1 -2
- package/dist/dsl/aggregation/types.cjs +1 -1
- package/dist/dsl/aggregation/types.cjs.map +1 -1
- package/dist/dsl/aggregation/types.d.cts +69 -69
- package/dist/dsl/aggregation/types.d.ts +69 -69
- package/dist/dsl/aggregation/types.es.js +15 -16
- package/dist/dsl/aggregation/types.es.js.map +1 -1
- package/dist/dsl/constantName.cjs +2 -0
- package/dist/dsl/constantName.cjs.map +1 -0
- package/dist/dsl/constantName.d.cts +9 -0
- package/dist/dsl/constantName.d.ts +9 -0
- package/dist/dsl/constantName.es.js +7 -0
- package/dist/dsl/constantName.es.js.map +1 -0
- package/dist/dsl/cursorQuery.cjs.map +1 -1
- package/dist/dsl/cursorQuery.es.js +1 -2
- package/dist/dsl/deletionState.cjs +1 -1
- package/dist/dsl/deletionState.cjs.map +1 -1
- package/dist/dsl/deletionState.d.cts +3 -3
- package/dist/dsl/deletionState.d.ts +3 -3
- package/dist/dsl/deletionState.es.js +2 -3
- package/dist/dsl/deletionState.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 +99 -42
- package/dist/dsl/descriptor.d.ts +99 -42
- package/dist/dsl/descriptor.es.js +37 -29
- package/dist/dsl/descriptor.es.js.map +1 -1
- package/dist/dsl/field.cjs.map +1 -1
- package/dist/dsl/field.es.js +1 -2
- package/dist/dsl/filter/builders.cjs +1 -1
- package/dist/dsl/filter/builders.cjs.map +1 -1
- package/dist/dsl/filter/builders.d.cts +53 -53
- package/dist/dsl/filter/builders.d.ts +53 -53
- package/dist/dsl/filter/builders.es.js +111 -111
- package/dist/dsl/filter/builders.es.js.map +1 -1
- package/dist/dsl/filter/datePattern.cjs.map +1 -1
- package/dist/dsl/filter/datePattern.es.js +1 -2
- package/dist/dsl/filter/operator.cjs +1 -1
- package/dist/dsl/filter/operator.cjs.map +1 -1
- package/dist/dsl/filter/operator.d.cts +57 -57
- package/dist/dsl/filter/operator.d.ts +57 -57
- package/dist/dsl/filter/operator.es.js +4 -5
- package/dist/dsl/filter/operator.es.js.map +1 -1
- package/dist/dsl/filter/scope.cjs +1 -1
- package/dist/dsl/filter/scope.cjs.map +1 -1
- package/dist/dsl/filter/scope.es.js +12 -12
- package/dist/dsl/filter/scope.es.js.map +1 -1
- package/dist/dsl/filter/validate.cjs +1 -1
- package/dist/dsl/filter/validate.cjs.map +1 -1
- package/dist/dsl/filter/validate.es.js +23 -23
- package/dist/dsl/filter/validate.es.js.map +1 -1
- package/dist/dsl/pagination.cjs.map +1 -1
- package/dist/dsl/pagination.es.js +1 -2
- package/dist/dsl/projection.cjs.map +1 -1
- package/dist/dsl/projection.d.cts +1 -1
- package/dist/dsl/projection.d.ts +1 -1
- package/dist/dsl/projection.es.js +1 -2
- package/dist/dsl/projection.es.js.map +1 -1
- package/dist/dsl/queryErrorCodes.cjs +1 -1
- package/dist/dsl/queryErrorCodes.cjs.map +1 -1
- package/dist/dsl/queryErrorCodes.d.cts +59 -48
- package/dist/dsl/queryErrorCodes.d.ts +59 -48
- package/dist/dsl/queryErrorCodes.es.js +51 -50
- package/dist/dsl/queryErrorCodes.es.js.map +1 -1
- package/dist/dsl/queryable.cjs +1 -1
- package/dist/dsl/queryable.cjs.map +1 -1
- package/dist/dsl/queryable.d.cts +25 -21
- package/dist/dsl/queryable.d.ts +25 -21
- package/dist/dsl/queryable.es.js +5 -5
- package/dist/dsl/queryable.es.js.map +1 -1
- package/dist/dsl/sort.cjs +1 -1
- package/dist/dsl/sort.cjs.map +1 -1
- package/dist/dsl/sort.d.cts +2 -2
- package/dist/dsl/sort.d.ts +2 -2
- package/dist/dsl/sort.es.js +4 -5
- package/dist/dsl/sort.es.js.map +1 -1
- package/dist/dsl.cjs +1 -1
- package/dist/dsl.es.js +3 -3
- package/dist/exactJson.cjs.map +1 -1
- package/dist/exactJson.d.cts +4 -4
- package/dist/exactJson.d.ts +4 -4
- package/dist/exactJson.es.js +1 -2
- package/dist/exactJson.es.js.map +1 -1
- package/dist/frameworkErrors.cjs +2 -0
- package/dist/frameworkErrors.cjs.map +1 -0
- package/dist/frameworkErrors.d.cts +121 -0
- package/dist/frameworkErrors.d.ts +121 -0
- package/dist/frameworkErrors.es.js +95 -0
- package/dist/frameworkErrors.es.js.map +1 -0
- package/dist/http.cjs +1 -1
- package/dist/http.cjs.map +1 -1
- package/dist/http.d.cts +4 -7
- package/dist/http.d.ts +4 -7
- package/dist/http.es.js +12 -20
- package/dist/http.es.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +9 -7
- package/dist/index.d.ts +9 -7
- package/dist/index.es.js +11 -9
- package/dist/manifest.cjs +1 -1
- package/dist/manifest.cjs.map +1 -1
- package/dist/manifest.d.cts +37 -95
- package/dist/manifest.d.ts +37 -95
- package/dist/manifest.es.js +12 -7
- package/dist/manifest.es.js.map +1 -1
- package/dist/manifestTypes.d.cts +195 -0
- package/dist/manifestTypes.d.ts +195 -0
- package/dist/problem.cjs +1 -1
- package/dist/problem.cjs.map +1 -1
- package/dist/problem.d.cts +76 -115
- package/dist/problem.d.ts +76 -115
- package/dist/problem.es.js +45 -80
- package/dist/problem.es.js.map +1 -1
- package/dist/queries.cjs +1 -1
- package/dist/queries.cjs.map +1 -1
- package/dist/queries.d.cts +28 -51
- package/dist/queries.d.ts +28 -51
- package/dist/queries.es.js +49 -40
- package/dist/queries.es.js.map +1 -1
- package/dist/routes.cjs +2 -0
- package/dist/routes.cjs.map +1 -0
- package/dist/routes.d.cts +49 -0
- package/dist/routes.d.ts +49 -0
- package/dist/routes.es.js +33 -0
- package/dist/routes.es.js.map +1 -0
- package/dist/state.cjs +1 -1
- package/dist/state.cjs.map +1 -1
- package/dist/state.d.cts +56 -11
- package/dist/state.d.ts +56 -11
- package/dist/state.es.js +56 -21
- package/dist/state.es.js.map +1 -1
- package/dist/streams.cjs +1 -1
- package/dist/streams.cjs.map +1 -1
- package/dist/streams.d.cts +17 -13
- package/dist/streams.d.ts +17 -13
- package/dist/streams.es.js +50 -50
- package/dist/streams.es.js.map +1 -1
- package/dist/testing/wire.cjs +2 -0
- package/dist/testing/wire.cjs.map +1 -0
- package/dist/testing/wire.d.cts +29 -0
- package/dist/testing/wire.d.ts +29 -0
- package/dist/testing/wire.es.js +88 -0
- package/dist/testing/wire.es.js.map +1 -0
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +12 -0
- package/dist/testing.d.ts +12 -0
- package/dist/testing.es.js +3 -0
- package/dist/wait.cjs +1 -1
- package/dist/wait.cjs.map +1 -1
- package/dist/wait.d.cts +68 -19
- package/dist/wait.d.ts +68 -19
- package/dist/wait.es.js +61 -14
- package/dist/wait.es.js.map +1 -1
- package/dist/wire.cjs +1 -1
- package/dist/wire.cjs.map +1 -1
- package/dist/wire.d.cts +101 -50
- package/dist/wire.d.ts +101 -50
- package/dist/wire.es.js +17 -6
- package/dist/wire.es.js.map +1 -1
- package/package.json +23 -3
package/dist/wait.es.js.map
CHANGED
|
@@ -1 +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/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"}
|
|
1
|
+
{"version":3,"file":"wait.es.js","names":["SNAPSHOT_SUBSCRIPTION","NAME","checkName","value","kind","hop","context","subscription","wait","Stage","formatHop","keyword","WaitPlan","hops","checkTimeout","timeout","isDefault","formatWaitPlan","plan","HOP","parseWaitPlan","parseHop","part","match","argument","parts","formatWaitTimeout"],"sources":["../src/wait.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { type Hop, Stage } from './wire.js';\n\n/** The name of the built-in subscription that writes snapshots. */\nexport const SNAPSHOT_SUBSCRIPTION = 'wow.snapshot';\n\nconst NAME = /^[A-Za-z0-9_.-]+$/;\n\nfunction checkName(kind: string, value: string): string {\n if (!NAME.test(value)) {\n throw new TypeError(`Not a ${kind} name: '${value}'.`);\n }\n return value;\n}\n\nfunction hop(stage: Stage, context?: string, subscription?: string): Hop {\n return {\n stage,\n ...(context === undefined\n ? {}\n : { context: checkName('context', context) }),\n ...(subscription === undefined\n ? {}\n : { subscription: checkName('subscription', subscription) }),\n };\n}\n\n/**\n * Builds the hops of a wait chain. A context left out is\n * the command's own. A saga's `handled` hop may be followed by hops of the\n * commands it derived, in their contexts:\n *\n * @example\n * ```typescript\n * const plan = [\n * wait.committed(),\n * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),\n * wait.committed('eshop-ordering'),\n * ];\n * ```\n */\nexport const wait = {\n /** Until the command passed admission; the route answers 202. */\n accepted: (context?: string): Hop => hop(Stage.ACCEPTED, context),\n /** Until the command's events are appended to the log. */\n committed: (context?: string): Hop => hop(Stage.COMMITTED, context),\n /** Until the snapshot holds the commit: the caller reads its own write. */\n snapshot: (context?: string): Hop =>\n hop(Stage.HANDLED, context, SNAPSHOT_SUBSCRIPTION),\n /** Until the subscription named `processor.function` handled the commit. */\n handled: (subscription: string, context?: string): Hop =>\n hop(Stage.HANDLED, context, subscription),\n} as const;\n\n/**\n * A hop as `Wow-Wait` spells it: `accepted`, `committed`, `snapshot` and\n * `handled(subscription)`, each with its context when it has one:\n * `committed(ctx)`, `snapshot(ctx)`, `handled(ctx/subscription)`.\n *\n * @param value - The hop\n */\nexport function formatHop(value: Hop): string {\n const context = value.context ?? undefined;\n const subscription = value.subscription ?? undefined;\n if (value.stage === Stage.HANDLED) {\n if (subscription === undefined) {\n throw new TypeError('A handled hop names its subscription.');\n }\n if (subscription === SNAPSHOT_SUBSCRIPTION) {\n return context === undefined ? 'snapshot' : `snapshot(${context})`;\n }\n return context === undefined\n ? `handled(${subscription})`\n : `handled(${context}/${subscription})`;\n }\n if (subscription !== undefined) {\n throw new TypeError(`Only a handled hop names a subscription.`);\n }\n const keyword = value.stage.toLowerCase();\n return context === undefined ? keyword : `${keyword}(${context})`;\n}\n\n/**\n * How far a command is waited for, and for how long: the hops, in order, and\n * a timeout in milliseconds. Kotlin's `me.ahoo.wow.api.result.WaitPlan`,\n * with its constants and constructors: {@link WaitPlan.of} the hops a\n * {@link wait} builder makes, {@link WaitPlan.within} another timeout.\n *\n * @example\n * ```typescript\n * const plan = WaitPlan.of(\n * wait.committed(),\n * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),\n * ).within(30_000);\n * ```\n */\nexport class WaitPlan {\n /** The timeout of a wait whose caller gives none: 10 seconds. */\n static readonly DEFAULT_TIMEOUT = 10_000;\n\n /**\n * The plan of a caller that asked for none: until the snapshot holds the\n * commit, so the caller reads its own write; until `committed` for an\n * aggregate without a snapshot subscription. A request with it sends no\n * `Wow-Wait`, so the service picks.\n */\n static readonly DEFAULT = new WaitPlan([wait.snapshot()], undefined, true);\n\n /**\n * Until the snapshot holds the commit, asked for explicitly: rejected at\n * admission for an aggregate without a snapshot subscription.\n */\n static readonly SNAPSHOT = new WaitPlan([wait.snapshot()]);\n\n /** Until the events are appended. */\n static readonly COMMITTED = new WaitPlan([wait.committed()]);\n\n /** Until the command passed admission. */\n static readonly ACCEPTED = new WaitPlan([wait.accepted()]);\n\n /** Until `hops` are reached, in order. */\n static of(...hops: Hop[]): WaitPlan {\n return new WaitPlan(hops);\n }\n\n /** The hops to reach, in order; at least one. */\n readonly hops: readonly Hop[];\n /** How long to wait, in milliseconds. */\n readonly timeout: number;\n /** Whether this is {@link WaitPlan.DEFAULT}, the service's choice. */\n readonly isDefault: boolean;\n\n private constructor(\n hops: readonly Hop[],\n timeout: number = WaitPlan.DEFAULT_TIMEOUT,\n isDefault = false,\n ) {\n if (hops.length === 0) {\n throw new TypeError('A wait plan has at least one hop.');\n }\n checkTimeout(timeout);\n this.hops = Object.freeze([...hops]);\n this.timeout = timeout;\n this.isDefault = isDefault;\n Object.freeze(this);\n }\n\n /** This plan, waiting `timeout` milliseconds. */\n within(timeout: number): WaitPlan {\n return new WaitPlan(this.hops, timeout, this.isDefault);\n }\n}\n\n/**\n * A wait plan as the `Wow-Wait` header spells it: its hops, in order,\n * separated by `>`; the inverse of {@link parseWaitPlan}.\n *\n * @param plan - The plan\n */\nexport function formatWaitPlan(plan: WaitPlan): string {\n return plan.hops.map(formatHop).join(' > ');\n}\n\nconst HOP = /^([A-Za-z]+)\\s*(?:\\(\\s*([^()]*?)\\s*\\))?$/;\n\n/**\n * The plan a `Wow-Wait` value spells, as the service reads it: hops\n * separated by `>`, each `accepted`, `committed`, `snapshot` or\n * `handled(subscription)`, with its context in parentheses\n * (`committed(ctx)`, `handled(ctx/subscription)`); the inverse of\n * {@link formatWaitPlan}. Throws a `TypeError` for anything else.\n *\n * @param value - The header's value\n */\nexport function parseWaitPlan(value: string): WaitPlan {\n if (value.trim() === '') {\n throw new TypeError('A wait plan has at least one hop.');\n }\n return WaitPlan.of(...value.split('>').map(part => parseHop(part.trim())));\n}\n\n/**\n * The hop one part of a `Wow-Wait` value spells; see {@link parseWaitPlan}.\n *\n * @param value - The part, such as `committed(ctx)`\n */\nexport function parseHop(value: string): Hop {\n const match = HOP.exec(value);\n if (match === null) throw new TypeError(`Not a hop: '${value}'.`);\n const keyword = match[1].toLowerCase();\n const argument = match[2];\n switch (keyword) {\n case 'accepted':\n return wait.accepted(argument);\n case 'committed':\n return wait.committed(argument);\n case 'snapshot':\n return wait.snapshot(argument);\n case 'handled': {\n if (argument === undefined) {\n throw new TypeError(\n `A handled hop names its subscription: '${value}'.`,\n );\n }\n const parts = argument.split('/');\n if (parts.length > 2) {\n throw new TypeError(\n `A handled hop is (subscription) or (context/subscription): '${argument}'.`,\n );\n }\n return parts.length === 1\n ? wait.handled(parts[0])\n : wait.handled(parts[1].trim(), parts[0].trim());\n }\n default:\n throw new TypeError(`Not a stage: '${keyword}'.`);\n }\n}\n\n/**\n * A wait timeout as the `Wow-Wait-Timeout` header spells it: milliseconds\n * as `<n>s` when whole seconds, else `<n>ms`.\n *\n * @param timeout - Milliseconds\n */\nexport function formatWaitTimeout(timeout: number): string {\n checkTimeout(timeout);\n return timeout % 1000 === 0 ? `${timeout / 1000}s` : `${timeout}ms`;\n}\n\nfunction checkTimeout(timeout: number): void {\n if (!Number.isInteger(timeout) || timeout <= 0) {\n throw new TypeError(\n `A wait timeout is a positive whole number of milliseconds: ${timeout}.`,\n );\n }\n}\n"],"mappings":";;AAgBA,IAAaA,IAAwB,gBAE/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,iBACKD,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;AAgBA,IAAaM,IAAb,MAAaA,EAAS;;EAEc,KAAA,kBAAA;;;EAQR,KAAA,UAAA,IAAIA,EAAS,CAACJ,EAAK,SAAS,CAAC,GAAG,KAAA,GAAW,EAAI;;;EAM9C,KAAA,WAAA,IAAII,EAAS,CAACJ,EAAK,SAAS,CAAC,CAAC;;;EAG7B,KAAA,YAAA,IAAII,EAAS,CAACJ,EAAK,UAAU,CAAC,CAAC;;;EAGhC,KAAA,WAAA,IAAII,EAAS,CAACJ,EAAK,SAAS,CAAC,CAAC;;CAGzD,OAAO,GAAG,GAAGK,GAAuB;EAClC,OAAO,IAAID,EAASC,CAAI;CAC1B;CASA,YACE,GACA,IAAkBD,EAAS,iBAC3B,IAAY,IACZ;EACA,IAAIC,EAAK,WAAW,GAClB,MAAU,UAAU,mCAAmC;EAMzD,AAJAC,EAAaC,CAAO,GACpB,KAAK,OAAO,OAAO,OAAO,CAAC,GAAGF,CAAI,CAAC,GACnC,KAAK,UAAUE,GACf,KAAK,YAAYC,GACjB,OAAO,OAAO,IAAI;CACpB;CAGA,OAAO,GAA2B;EAChC,OAAO,IAAIJ,EAAS,KAAK,MAAMG,GAAS,KAAK,SAAS;CACxD;AACF;AAQA,SAAgBE,EAAe,GAAwB;CACrD,OAAOC,EAAK,KAAK,IAAIR,CAAS,CAAC,CAAC,KAAK,KAAK;AAC5C;AAEA,IAAMS,IAAM;AAWZ,SAAgBC,EAAc,GAAyB;CACrD,IAAIjB,EAAM,KAAK,MAAM,IACnB,MAAU,UAAU,mCAAmC;CAEzD,OAAOS,EAAS,GAAG,GAAGT,EAAM,MAAM,GAAG,CAAC,CAAC,KAAI,MAAQkB,EAASC,EAAK,KAAK,CAAC,CAAC,CAAC;AAC3E;AAOA,SAAgBD,EAAS,GAAoB;CAC3C,IAAME,IAAQJ,EAAI,KAAKhB,CAAK;CAC5B,IAAIoB,MAAU,MAAM,MAAU,UAAU,eAAepB,EAAM,GAAG;CAChE,IAAMQ,IAAUY,EAAM,EAAE,CAAC,YAAY,GAC/BC,IAAWD,EAAM;CACvB,QAAQZ,GAAR;EACE,KAAK,YACH,OAAOH,EAAK,SAASgB,CAAQ;EAC/B,KAAK,aACH,OAAOhB,EAAK,UAAUgB,CAAQ;EAChC,KAAK,YACH,OAAOhB,EAAK,SAASgB,CAAQ;EAC/B,KAAK,WAAW;GACd,IAAIA,MAAa,KAAA,GACf,MAAU,UACR,0CAA0CrB,EAAM,GAClD;GAEF,IAAMsB,IAAQD,EAAS,MAAM,GAAG;GAChC,IAAIC,EAAM,SAAS,GACjB,MAAU,UACR,+DAA+DD,EAAS,GAC1E;GAEF,OAAOC,EAAM,WAAW,IACpBjB,EAAK,QAAQiB,EAAM,EAAE,IACrBjB,EAAK,QAAQiB,EAAM,EAAE,CAAC,KAAK,GAAGA,EAAM,EAAE,CAAC,KAAK,CAAC;EACnD;EACA,SACE,MAAU,UAAU,iBAAiBd,EAAQ,GAAG;CACpD;AACF;AAQA,SAAgBe,EAAkB,GAAyB;CAEzD,OADAZ,EAAaC,CAAO,GACbA,IAAU,OAAS,IAAI,GAAGA,IAAU,IAAK,KAAK,GAAGA,EAAQ;AAClE;AAEA,SAASD,EAAa,GAAuB;CAC3C,IAAI,CAAC,OAAO,UAAUC,CAAO,KAAKA,KAAW,GAC3C,MAAU,UACR,8DAA8DA,EAAQ,EACxE;AAEJ"}
|
package/dist/wire.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e={ACCEPTED:`
|
|
1
|
+
var e={ACCEPTED:`accepted`,COMMITTED:`committed`,HANDLED:`handled`},t={COMMAND:`command`,PROJECT:`project`,REACT:`react`,SAGA:`saga`,SNAPSHOT:`snapshot`,RESERVATION:`reservation`,TIMERS:`timers`},n={SUCCEEDED:`succeeded`,REJECTED:`rejected`,FAILED:`failed`};exports.CommandResultStatus=n,exports.FunctionKind=t,exports.Stage=e;
|
|
2
2
|
//# sourceMappingURL=wire.cjs.map
|
package/dist/wire.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wire.cjs","names":["Stage"],"sources":["../src/wire.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { TextNumbers } from './exactJson.js';\n\n/**\n * The wire model of a Wow service: what its routes answer, as the server\n * writes it (`wow-api`'s `CommandResult`, the edge's state views, the query\n * records). Types and wire values only.\n */\n\n/** An aggregate type: its bounded context and its name. */\nexport interface AggregateType {\n readonly context: string;\n readonly name: string;\n /**\n * Which numbers of its states, events and commands are read and written\n * as their exact text (review R4-Q, Q-9): the `int64`, `bigint` and\n * `decimal` fields of its Manifest, as wow-generator writes them.\n */\n readonly textNumbers?: AggregateTextNumbers;\n}\n\n/** The numbers of an aggregate type kept as their exact text ({@link TextNumbers}). */\nexport interface AggregateTextNumbers {\n /** Those of its state. */\n readonly state?: TextNumbers;\n /** Those of each event's body, by the event's name as the server sends it. */\n readonly events?: Readonly<Record<string, TextNumbers>>;\n /** Those of each command's body, by the command's name. */\n readonly commands?: Readonly<Record<string, TextNumbers>>;\n}\n\n/** One aggregate: its type, its tenant and its id. */\nexport interface AggregateRef {\n readonly type: AggregateType;\n readonly tenantId: string;\n readonly id: string;\n}\n\n/** The owner and the space an aggregate belongs to, beside its tenant. */\nexport interface Scope {\n readonly ownerId?: string | null;\n readonly spaceId?: string | null;\n}\n\n/**\n * Who sent a command (decision D163): the opaque id of the authenticated\n * subject, its own tenant, and whether it acted in another tenant or scope.\n * Resolve the id to a display name in the application, never from Wow.\n */\nexport interface Operator {\n readonly id: string;\n readonly tenantId: string;\n readonly crossScope: boolean;\n}\n\n/** How far a command has come (decision D61). */\nexport const Stage = {\n /** The command passed admission. */\n ACCEPTED: 'ACCEPTED',\n /** The command's events are appended to the log. */\n COMMITTED: 'COMMITTED',\n /** A named subscription has handled the commit. */\n HANDLED: 'HANDLED',\n} as const;\n\n/** A {@link Stage} value. */\nexport type Stage = (typeof Stage)[keyof typeof Stage];\n\n/**\n * One hop of a wait chain (decision D62): a stage, in a context (the\n * command's own when absent), of a subscription when the stage is\n * `HANDLED`. The snapshot is the subscription named `snapshot`.\n */\nexport interface Hop {\n readonly stage: Stage;\n readonly context?: string | null;\n readonly subscription?: string | null;\n}\n\n/** The kind of function that produced a result. */\nexport type FunctionKind =\n | 'COMMAND'\n | 'PROJECT'\n | 'REACT'\n | 'SAGA'\n | 'SNAPSHOT'\n | 'RESERVATION'\n | 'TIMERS';\n\n/** Who produced a result: a function of `kind` in `context`. */\nexport interface FunctionInfo {\n readonly kind: FunctionKind;\n readonly context: string;\n readonly processor: string;\n readonly name: string;\n}\n\n/** A field-level validation error. */\nexport interface Violation {\n /** The path of the field, or the query part, that broke the rule. */\n readonly path: string;\n /** The rule's code, such as `NotBlank` or `UNKNOWN_FIELD`. */\n readonly code: string;\n /** A human-readable message. */\n readonly message: string;\n}\n\n/** Why a command was rejected or failed. */\nexport interface ErrorInfo {\n /** A framework code (`wow.*`) or the domain's own. */\n readonly code: string;\n readonly message: string;\n readonly violations?: readonly Violation[];\n /**\n * The rejection's structured data (decision D211), which a problem\n * writes as its extension members.\n */\n readonly extensions?: Readonly<Record<string, unknown>>;\n}\n\n/** How a command ended at a hop. */\nexport type CommandResultStatus = 'SUCCEEDED' | 'REJECTED' | 'FAILED';\n\n/**\n * The command a request named before a transformer turned it into the one\n * that ran (decision D182).\n */\nexport interface TransformedFrom {\n /** The full type name, `context.aggregate.Command`. */\n readonly command: string;\n readonly aggregateId?: string | null;\n}\n\n/**\n * The one outward result of a command (design 08 §7): what it reached at one\n * hop of its wait chain. A command route answers the last one; its event\n * stream sends one per hop.\n *\n * A chain can end before its plan does (decision D212): a hop, such as a\n * saga's that sent no command (a declined payment, say), leaves nothing to\n * reach the later hops. Its result is then the last one, at that hop with its\n * own status, `chainEnded` and the hops not reached in `pending`; a server\n * before D212 sends neither, so read them as `false` and empty when absent.\n *\n * @typeParam R - The shape of `results`, what the command's decide function\n * answered with.\n */\nexport interface CommandResult<R = Record<string, unknown>> {\n readonly format: number;\n readonly commandId: string;\n readonly requestId: string;\n readonly correlationId: string;\n readonly ref: AggregateRef;\n readonly hop: Hop;\n readonly function: FunctionInfo;\n readonly status: CommandResultStatus;\n /** The aggregate's version after the commit, or the unchanged one. */\n readonly version?: number | null;\n /** The request was already committed: it was not decided again. */\n readonly duplicate: boolean;\n /** Set when `status` is `REJECTED` or `FAILED`. */\n readonly error?: ErrorInfo | null;\n readonly results: R;\n /** On a saga's hop, the ids of the commands it derived. */\n readonly derived: readonly string[];\n /** When it was produced, in epoch milliseconds. */\n readonly signalTime: number;\n readonly transformedFrom?: TransformedFrom | null;\n /**\n * The chain ended at this hop before its plan did (decision D212): the\n * hops in `pending` will not come.\n */\n readonly chainEnded?: boolean;\n /** When `chainEnded`, the hops of the plan not reached, in order. */\n readonly pending?: readonly Hop[];\n}\n\n/** The tags of an aggregate: names to values. */\nexport type Tags = Readonly<Record<string, readonly string[]>>;\n\n/**\n * An aggregate's state at a version (decision D40), as\n * `GET /{context}/{aggregate}/{id}/state` answers it.\n *\n * @typeParam S - The state's type.\n */\nexport interface StateView<S = unknown> {\n readonly ref: AggregateRef;\n readonly version: number;\n readonly scope: Scope;\n readonly deleted: boolean;\n readonly tags: Tags;\n readonly state: S;\n}\n\n/**\n * An event as Wow reads it now: under its current name, upgraded to its latest revision. The `events` query gives\n * every stored event so, however old its record, and leaves out the events its aggregate retired, so a generated\n * `<Aggregate>Event` union, with {@link SystemEvent}, covers each event it returns.\n *\n * @typeParam N - The event's name.\n * @typeParam B - The event's body.\n */\nexport interface EventView<N extends string = string, B = unknown> {\n readonly name: N;\n readonly revision: number;\n readonly body: B;\n}\n\n/** The body of `wow.lifecycle.OwnerTransferred`: the aggregate's new owner. */\nexport interface OwnerTransferred {\n readonly ownerId: string;\n}\n\n/** The body of `wow.lifecycle.SpaceTransferred`: the aggregate's new space. */\nexport interface SpaceTransferred {\n readonly spaceId: string;\n}\n\n/** The body of `wow.lifecycle.TagsApplied`: the aggregate's tags now. */\nexport interface TagsApplied {\n readonly tags: Tags;\n}\n\n/**\n * The body of `wow.ScheduleSet` (decision D198): the aggregate set its\n * schedule `key`, to send `target` the command of type `commandType`\n * (`command` its JSON text) as `rule` says.\n */\nexport interface ScheduleSet {\n readonly key: string;\n readonly rule: ScheduleRule;\n readonly target: AggregateRef;\n readonly commandType: string;\n readonly command: string;\n}\n\n/** The body of `wow.ScheduleCancelled` (decision D198). */\nexport interface ScheduleCancelled {\n readonly key: string;\n}\n\n/**\n * The system events the kernel gives every aggregate (decisions D113, D198):\n * the lifecycle events and the schedule events. A state trace and an event\n * stream carry them beside the aggregate's own events, so the event union\n * `wow-generator` writes for an aggregate includes this one.\n */\nexport type SystemEvent =\n | EventView<'wow.lifecycle.AggregateDeleted', Readonly<Record<string, never>>>\n | EventView<\n 'wow.lifecycle.AggregateRestored',\n Readonly<Record<string, never>>\n >\n | EventView<'wow.lifecycle.OwnerTransferred', OwnerTransferred>\n | EventView<'wow.lifecycle.SpaceTransferred', SpaceTransferred>\n | EventView<'wow.lifecycle.TagsApplied', TagsApplied>\n | EventView<'wow.ScheduleSet', ScheduleSet>\n | EventView<'wow.ScheduleCancelled', ScheduleCancelled>;\n\n/**\n * One commit of a state trace (decision D40): the events of a version and the\n * aggregate after it.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type.\n */\nexport interface CommitView<S = unknown, E extends EventView = EventView> {\n readonly version: number;\n /** When it was committed, in epoch milliseconds. */\n readonly commitTime: number;\n readonly commandId: string;\n readonly requestId: string;\n readonly commandType: string;\n readonly events: readonly E[];\n readonly scope: Scope;\n readonly deleted: boolean;\n readonly tags: Tags;\n readonly state: S;\n readonly operator?: Operator | null;\n}\n\n/**\n * What `GET /{context}/{aggregate}/{id}/state/trace` answers: the aggregate\n * and its commits in version order.\n */\nexport interface StateTrace<S = unknown, E extends EventView = EventView> {\n readonly ref: AggregateRef;\n readonly commits: readonly CommitView<S, E>[];\n}\n\n/**\n * A record of the `snapshot` query model (decisions D128, D163): the\n * aggregate's system fields and its state.\n *\n * @typeParam S - The state's type.\n */\nexport interface SnapshotRecord<S = unknown> {\n readonly tenantId: string;\n readonly aggregateId: string;\n readonly version: number;\n readonly ownerId: string | null;\n readonly spaceId: string | null;\n readonly deleted: boolean;\n readonly tags: Tags;\n /** The first commit's time, in epoch milliseconds. */\n readonly firstEventTime: number;\n /** The last commit's time, in epoch milliseconds. */\n readonly lastEventTime: number;\n /** Who sent the last command; null for an anonymous caller. */\n readonly operator: Operator | null;\n /** Who created the aggregate; null for an anonymous caller. */\n readonly firstOperator: Operator | null;\n /**\n * The schedules the aggregate keeps (decision D198): each rule, `{type,\n * ...}`, by its key; absent from a server before 6.8c.\n */\n readonly schedules?: Readonly<Record<string, ScheduleRule>>;\n readonly state: S;\n}\n\n/**\n * The system fields of a snapshot record a query can filter, sort and\n * project on; a state field is `state.<path>`.\n */\nexport type SnapshotSystemField =\n | 'tenantId'\n | 'aggregateId'\n | 'version'\n | 'ownerId'\n | 'spaceId'\n | 'deleted'\n | 'tags'\n | 'firstEventTime'\n | 'lastEventTime'\n | 'operator'\n | 'operator.id'\n | 'operator.tenantId'\n | 'operator.crossScope'\n | 'firstOperator'\n | 'firstOperator.id'\n | 'firstOperator.tenantId'\n | 'firstOperator.crossScope'\n | 'schedules';\n\n/** A schedule rule of a snapshot's `schedules` (decision D198). */\nexport interface ScheduleRule {\n /** The rule's type: `at`, `after`, `cron`, … */\n readonly type: string;\n readonly [property: string]: unknown;\n}\n\n/**\n * A record of the `events` query model (decision D131): one commit of one\n * aggregate and its events.\n *\n * @typeParam E - The events' type.\n */\nexport interface EventStreamRecord<E extends EventView = EventView> {\n readonly aggregateId: string;\n readonly tenantId: string;\n readonly version: number;\n /** When it was committed, in epoch milliseconds. */\n readonly commitTime: number;\n readonly commandId: string;\n readonly requestId: string;\n readonly commandType: string;\n /** Null when the stream has none (`Scope.NONE`). */\n readonly ownerId?: string | null;\n readonly spaceId?: string | null;\n /** Null for an anonymous caller (decision D163). */\n readonly operator?: Operator | null;\n readonly events: readonly E[];\n}\n\n/**\n * The fields of an event stream record a query names (decision D235): its\n * system fields and `events`, the array an `elementMatch` filter and an\n * aggregation's `elements` reach an event through, by the event's own\n * `name`, `revision` and `body.*`.\n */\nexport type EventStreamField =\n | 'aggregateId'\n | 'tenantId'\n | 'version'\n | 'commitTime'\n | 'commandId'\n | 'requestId'\n | 'commandType'\n | 'ownerId'\n | 'spaceId'\n | 'operator'\n | 'operator.id'\n | 'operator.tenantId'\n | 'operator.crossScope'\n | 'events';\n\n/** How an aggregate belongs to its callers (decision D189). */\nexport type Ownership = 'OWNER' | 'TENANT';\n\n/** One dataset of `GET /wow/dataset` (decision D145). */\nexport interface DatasetEntry {\n /** `{context}.{dataset}`. */\n readonly name: string;\n readonly context: string;\n readonly dataset: string;\n readonly title?: string | null;\n /** The path of its query route. */\n readonly path: string;\n}\n"],"mappings":"AAoEA,IAAaA,EAAQ,CAEnB,SAAU,WAEV,UAAW,YAEX,QAAS,SACX"}
|
|
1
|
+
{"version":3,"file":"wire.cjs","names":["Stage","FunctionKind","CommandResultStatus"],"sources":["../src/wire.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { TextNumbers } from './exactJson.js';\n\n/**\n * The wire model of a Wow service: what its routes answer, as the server\n * writes it (`wow-api`'s `CommandResult`, the edge's state views, the query\n * records). Types and wire values only.\n */\n\n/** An aggregate type: its bounded context and its name. */\nexport interface AggregateType {\n readonly context: string;\n readonly name: string;\n /**\n * Which numbers of its states, events and commands are read and written\n * as their exact text (review R4-Q, Q-9): the `int64`, `bigint` and\n * `decimal` fields of its Manifest, as wow-generator writes them.\n */\n readonly textNumbers?: AggregateTextNumbers;\n}\n\n/** The numbers of an aggregate type kept as their exact text ({@link TextNumbers}). */\nexport interface AggregateTextNumbers {\n /** Those of its state. */\n readonly state?: TextNumbers;\n /** Those of each event's body, by the event's name as the server sends it. */\n readonly events?: Readonly<Record<string, TextNumbers>>;\n /** Those of each command's body, by the command's name. */\n readonly commands?: Readonly<Record<string, TextNumbers>>;\n}\n\n/** One aggregate: its type, its tenant and its id. */\nexport interface AggregateRef {\n readonly type: AggregateType;\n readonly tenantId: string;\n readonly id: string;\n}\n\n/**\n * The aggregate a command names: an {@link AggregateRef} whose `id` is null\n * while admission has not chosen it, as for a creation that leaves its id to\n * the server and was refused before one was chosen. The Kotlin client holds\n * such an id as `AggregateRef.UNASSIGNED`.\n */\nexport interface CommandRef {\n readonly type: AggregateType;\n readonly tenantId: string;\n readonly id: string | null;\n}\n\n/** The owner and the space an aggregate belongs to, beside its tenant. */\nexport interface Scope {\n readonly ownerId?: string | null;\n readonly spaceId?: string | null;\n}\n\n/**\n * Who sent a command: the opaque id of the authenticated\n * subject, its own tenant, and whether it acted in another tenant or scope.\n * Resolve the id to a display name in the application, never from Wow.\n */\nexport interface Operator {\n readonly id: string;\n readonly tenantId: string;\n readonly crossScope: boolean;\n}\n\n/** How far a command has come. */\nexport const Stage = {\n /** The command passed admission. */\n ACCEPTED: 'accepted',\n /** The command's events are appended to the log. */\n COMMITTED: 'committed',\n /** A named subscription has handled the commit. */\n HANDLED: 'handled',\n} as const;\n\n/** A {@link Stage} value. */\nexport type Stage = (typeof Stage)[keyof typeof Stage];\n\n/**\n * One hop of a wait chain: a stage, in a context (the\n * command's own when absent), of a subscription when the stage is\n * `handled`. The snapshot is the subscription named `wow.snapshot`\n * (`SNAPSHOT_SUBSCRIPTION`), which a `Wow-Wait` header writes `snapshot`.\n */\nexport interface Hop {\n /**\n * The stage; a server newer than this client may answer one it does not\n * list.\n */\n readonly stage: Stage | (string & {});\n readonly context?: string | null;\n readonly subscription?: string | null;\n}\n\n/** The kind of function that produced a result. */\nexport const FunctionKind = {\n /** The aggregate's command function. */\n COMMAND: 'command',\n /** A projection. */\n PROJECT: 'project',\n /** An event handler that reacts. */\n REACT: 'react',\n /** A saga. */\n SAGA: 'saga',\n /** The snapshot subscription. */\n SNAPSHOT: 'snapshot',\n /** A reservation. */\n RESERVATION: 'reservation',\n /** A timer. */\n TIMERS: 'timers',\n} as const;\n\n/** A {@link FunctionKind} value. */\nexport type FunctionKind = (typeof FunctionKind)[keyof typeof FunctionKind];\n\n/** Who produced a result: a function of `kind` in `context`. */\nexport interface FunctionInfo {\n /**\n * The kind; a server newer than this client may answer one it does not\n * list.\n */\n readonly kind: FunctionKind | (string & {});\n readonly context: string;\n readonly processor: string;\n readonly name: string;\n}\n\n/** A field-level validation error. */\nexport interface Violation {\n /** The path of the field, or the query part, that broke the rule. */\n readonly path: string;\n /** The rule's code, such as `NotBlank` or `UNKNOWN_FIELD`. */\n readonly code: string;\n /** A human-readable message. */\n readonly message: string;\n}\n\n/** Why a command was rejected or failed. */\nexport interface ErrorInfo {\n /** A framework code (`wow.*`) or the domain's own. */\n readonly code: string;\n readonly message: string;\n readonly violations?: readonly Violation[];\n /**\n * The rejection's structured data (decision D211), which a problem\n * writes as its extension members.\n */\n readonly extensions?: Readonly<Record<string, unknown>>;\n}\n\n/** How a command ended at a hop. */\nexport const CommandResultStatus = {\n /** The command reached the hop. */\n SUCCEEDED: 'succeeded',\n /** The domain or admission refused the command. */\n REJECTED: 'rejected',\n /** A technical failure stopped the command. */\n FAILED: 'failed',\n} as const;\n\n/** A {@link CommandResultStatus} value. */\nexport type CommandResultStatus =\n (typeof CommandResultStatus)[keyof typeof CommandResultStatus];\n\n/**\n * The command a request named before a transformer turned it into the one\n * that ran.\n */\nexport interface TransformedFrom {\n /** The full type name, `context.aggregate.Command`. */\n readonly command: string;\n readonly aggregateId?: string | null;\n}\n\n/**\n * The one outward result of a command: what it reached at one\n * hop of its wait chain. A command route answers the last one; its event\n * stream sends one per hop.\n *\n * A chain can end before its plan does (decision D212): a hop, such as a\n * saga's that sent no command (a declined payment, say), leaves nothing to\n * reach the later hops. Its result is then the last one, at that hop with its\n * own status, `chainEnded` and the hops not reached in `pending`; a server\n * before D212 sends neither, so read them as `false` and empty when absent.\n *\n * @typeParam R - The shape of `results`, what the command's decide function\n * answered with.\n */\nexport interface CommandResult<R = Record<string, unknown>> {\n readonly format: number;\n readonly commandId: string;\n readonly requestId: string;\n readonly correlationId: string;\n /** The aggregate: a result that succeeded always names its id. */\n readonly ref: AggregateRef;\n readonly hop: Hop;\n readonly function: FunctionInfo;\n /**\n * The status; a server newer than this client may answer one it does not\n * list, which did not succeed as far as this client knows.\n */\n readonly status: CommandResultStatus | (string & {});\n /** The aggregate's version after the commit, or the unchanged one. */\n readonly version?: number | null;\n /** The request was already committed: it was not decided again. */\n readonly duplicate: boolean;\n /** Set when `status` is `rejected` or `failed`. */\n readonly error?: ErrorInfo | null;\n readonly results: R;\n /** On a saga's hop, the ids of the commands it derived. */\n readonly derived: readonly string[];\n /** When it was produced, in epoch milliseconds. */\n readonly signalTime: number;\n readonly transformedFrom?: TransformedFrom | null;\n /**\n * The chain ended at this hop before its plan did (decision D212): the\n * hops in `pending` will not come.\n */\n readonly chainEnded?: boolean;\n /** When `chainEnded`, the hops of the plan not reached, in order. */\n readonly pending?: readonly Hop[];\n}\n\n/**\n * A result that may not have succeeded, as a rejection or a problem carries\n * it (`CommandRejectedError.result`, `WowProblemError.result`): a command\n * refused before an aggregate id was decided names none\n * ({@link CommandRef}). The Kotlin client has no type of its own\n * for it: its `CommandResult.ref` holds such an id as\n * `AggregateRef.UNASSIGNED`.\n *\n * @typeParam R - The results' type.\n */\nexport interface RefusedResult<R = Record<string, unknown>> extends Omit<\n CommandResult<R>,\n 'ref'\n> {\n readonly ref: CommandRef;\n}\n\n/** The tags of an aggregate: names to values. */\nexport type Tags = Readonly<Record<string, readonly string[]>>;\n\n/**\n * An event as Wow reads it now: under its current name, upgraded to its latest revision. Kotlin's `CommittedEvent`. The `events` query gives\n * every stored event so, however old its record, and leaves out the events its aggregate retired, so a generated\n * `<Aggregate>Event` union, with {@link SystemEvent}, covers each event it returns.\n *\n * @typeParam N - The event's name.\n * @typeParam B - The event's body.\n */\nexport interface CommittedEvent<N extends string = string, B = unknown> {\n readonly name: N;\n readonly revision: number;\n readonly body: B;\n}\n\n/** The body of `wow.lifecycle.OwnerTransferred`: the aggregate's new owner. */\nexport interface OwnerTransferred {\n readonly ownerId: string;\n}\n\n/** The body of `wow.lifecycle.SpaceTransferred`: the aggregate's new space. */\nexport interface SpaceTransferred {\n readonly spaceId: string;\n}\n\n/** The body of `wow.lifecycle.TagsApplied`: the aggregate's tags now. */\nexport interface TagsApplied {\n readonly tags: Tags;\n}\n\n/**\n * The body of `wow.ScheduleSet`: the aggregate set its\n * schedule `key`, to send `target` the command of type `commandType`\n * (`command` its JSON text) as `rule` says.\n */\nexport interface ScheduleSet {\n readonly key: string;\n readonly rule: ScheduleRule;\n readonly target: CommandRef;\n readonly commandType: string;\n readonly command: string;\n}\n\n/** The body of `wow.ScheduleCancelled`. */\nexport interface ScheduleCancelled {\n readonly key: string;\n}\n\n/**\n * The system events the kernel gives every aggregate:\n * the lifecycle events and the schedule events. A state trace and an event\n * stream carry them beside the aggregate's own events, so the event union\n * `wow-generator` writes for an aggregate includes this one.\n */\nexport type SystemEvent =\n | CommittedEvent<\n 'wow.lifecycle.AggregateDeleted',\n Readonly<Record<string, never>>\n >\n | CommittedEvent<\n 'wow.lifecycle.AggregateRestored',\n Readonly<Record<string, never>>\n >\n | CommittedEvent<'wow.lifecycle.OwnerTransferred', OwnerTransferred>\n | CommittedEvent<'wow.lifecycle.SpaceTransferred', SpaceTransferred>\n | CommittedEvent<'wow.lifecycle.TagsApplied', TagsApplied>\n | CommittedEvent<'wow.ScheduleSet', ScheduleSet>\n | CommittedEvent<'wow.ScheduleCancelled', ScheduleCancelled>;\n\n/**\n * One commit of a state trace: the events of a version and the\n * aggregate after it.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type.\n */\nexport interface CommitView<\n S = unknown,\n E extends CommittedEvent = CommittedEvent,\n> {\n readonly version: number;\n /** When it was committed, in epoch milliseconds. */\n readonly commitTime: number;\n readonly commandId: string;\n readonly requestId: string;\n readonly commandType: string;\n readonly events: readonly E[];\n readonly scope: Scope;\n readonly deleted: boolean;\n readonly tags: Tags;\n readonly state: S;\n readonly operator?: Operator | null;\n}\n\n/**\n * What `GET /{context}/{aggregate}/{id}/state/trace` answers: the aggregate\n * and its commits in version order.\n */\nexport interface StateTrace<\n S = unknown,\n E extends CommittedEvent = CommittedEvent,\n> {\n readonly ref: AggregateRef;\n readonly commits: readonly CommitView<S, E>[];\n}\n\n/**\n * An aggregate's latest committed state, as a record of the `snapshot` query\n * model and as `GET /{context}/{aggregate}/{id}/state` answer it: the\n * aggregate's system fields and its state. Kotlin's `Snapshot`.\n *\n * @typeParam S - The state's type.\n */\nexport interface Snapshot<S = unknown> {\n readonly tenantId: string;\n readonly aggregateId: string;\n readonly version: number;\n readonly ownerId: string | null;\n readonly spaceId: string | null;\n readonly deleted: boolean;\n readonly tags: Tags;\n /** The first commit's time, in epoch milliseconds. */\n readonly firstEventTime: number;\n /** The last commit's time, in epoch milliseconds. */\n readonly lastEventTime: number;\n /** Who sent the last command; null for an anonymous caller. */\n readonly operator: Operator | null;\n /** Who created the aggregate; null for an anonymous caller. */\n readonly firstOperator: Operator | null;\n /**\n * The schedules the aggregate keeps (decision D198): each rule, `{type,\n * ...}`, by its key.\n */\n readonly schedules: Readonly<Record<string, ScheduleRule>>;\n readonly state: S;\n}\n\n/**\n * The system fields of a snapshot record a query can filter, sort and\n * project on; a state field is `state.<path>`.\n */\nexport type SnapshotSystemField =\n | 'tenantId'\n | 'aggregateId'\n | 'version'\n | 'ownerId'\n | 'spaceId'\n | 'deleted'\n | 'tags'\n | 'firstEventTime'\n | 'lastEventTime'\n | 'operator'\n | 'operator.id'\n | 'operator.tenantId'\n | 'operator.crossScope'\n | 'firstOperator'\n | 'firstOperator.id'\n | 'firstOperator.tenantId'\n | 'firstOperator.crossScope'\n | 'schedules';\n\n/** A schedule rule of a snapshot's `schedules`. */\nexport interface ScheduleRule {\n /** The rule's type: `at`, `after`, `cron`, … */\n readonly type: string;\n readonly [property: string]: unknown;\n}\n\n/**\n * A record of the `events` query model: one commit of one\n * aggregate and its events. Kotlin's `EventStream`.\n *\n * @typeParam E - The events' type.\n */\nexport interface EventStream<E extends CommittedEvent = CommittedEvent> {\n readonly aggregateId: string;\n readonly tenantId: string;\n readonly version: number;\n /** When it was committed, in epoch milliseconds. */\n readonly commitTime: number;\n readonly commandId: string;\n readonly requestId: string;\n readonly commandType: string;\n /** Null when the stream has none (`Scope.NONE`). */\n readonly ownerId?: string | null;\n readonly spaceId?: string | null;\n /** Null for an anonymous caller (decision D163). */\n readonly operator?: Operator | null;\n readonly events: readonly E[];\n}\n\n/**\n * The fields of an event stream record a query names: its\n * system fields and `events`, the array an `elementMatch` filter and an\n * aggregation's `elements` reach an event through, by the event's own\n * `name`, `revision` and `body.*`.\n */\nexport type EventStreamField =\n | 'aggregateId'\n | 'tenantId'\n | 'version'\n | 'commitTime'\n | 'commandId'\n | 'requestId'\n | 'commandType'\n | 'ownerId'\n | 'spaceId'\n | 'operator'\n | 'operator.id'\n | 'operator.tenantId'\n | 'operator.crossScope'\n | 'events';\n\n/** How an aggregate belongs to its callers. */\nexport type Ownership = 'owner' | 'tenant';\n\n/** One dataset of `GET /wow/dataset`. */\nexport interface DatasetEntry {\n /** `{context}.{dataset}`. */\n readonly name: string;\n readonly context: string;\n readonly dataset: string;\n readonly title?: string | null;\n /** The path of its query route. */\n readonly path: string;\n}\n"],"mappings":"AAgFA,IAAaA,EAAQ,CAEnB,SAAU,WAEV,UAAW,YAEX,QAAS,SACX,EAsBaC,EAAe,CAE1B,QAAS,UAET,QAAS,UAET,MAAO,QAEP,KAAM,OAEN,SAAU,WAEV,YAAa,cAEb,OAAQ,QACV,EAyCaC,EAAsB,CAEjC,UAAW,YAEX,SAAU,WAEV,OAAQ,QACV,E"}
|
package/dist/wire.d.cts
CHANGED
|
@@ -30,13 +30,24 @@ export interface AggregateRef {
|
|
|
30
30
|
readonly tenantId: string;
|
|
31
31
|
readonly id: string;
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* The aggregate a command names: an {@link AggregateRef} whose `id` is null
|
|
35
|
+
* while admission has not chosen it, as for a creation that leaves its id to
|
|
36
|
+
* the server and was refused before one was chosen. The Kotlin client holds
|
|
37
|
+
* such an id as `AggregateRef.UNASSIGNED`.
|
|
38
|
+
*/
|
|
39
|
+
export interface CommandRef {
|
|
40
|
+
readonly type: AggregateType;
|
|
41
|
+
readonly tenantId: string;
|
|
42
|
+
readonly id: string | null;
|
|
43
|
+
}
|
|
33
44
|
/** The owner and the space an aggregate belongs to, beside its tenant. */
|
|
34
45
|
export interface Scope {
|
|
35
46
|
readonly ownerId?: string | null;
|
|
36
47
|
readonly spaceId?: string | null;
|
|
37
48
|
}
|
|
38
49
|
/**
|
|
39
|
-
* Who sent a command
|
|
50
|
+
* Who sent a command: the opaque id of the authenticated
|
|
40
51
|
* subject, its own tenant, and whether it acted in another tenant or scope.
|
|
41
52
|
* Resolve the id to a display name in the application, never from Wow.
|
|
42
53
|
*/
|
|
@@ -45,32 +56,58 @@ export interface Operator {
|
|
|
45
56
|
readonly tenantId: string;
|
|
46
57
|
readonly crossScope: boolean;
|
|
47
58
|
}
|
|
48
|
-
/** How far a command has come
|
|
59
|
+
/** How far a command has come. */
|
|
49
60
|
export declare const Stage: {
|
|
50
61
|
/** The command passed admission. */
|
|
51
|
-
readonly ACCEPTED: "
|
|
62
|
+
readonly ACCEPTED: "accepted";
|
|
52
63
|
/** The command's events are appended to the log. */
|
|
53
|
-
readonly COMMITTED: "
|
|
64
|
+
readonly COMMITTED: "committed";
|
|
54
65
|
/** A named subscription has handled the commit. */
|
|
55
|
-
readonly HANDLED: "
|
|
66
|
+
readonly HANDLED: "handled";
|
|
56
67
|
};
|
|
57
68
|
/** A {@link Stage} value. */
|
|
58
69
|
export type Stage = (typeof Stage)[keyof typeof Stage];
|
|
59
70
|
/**
|
|
60
|
-
* One hop of a wait chain
|
|
71
|
+
* One hop of a wait chain: a stage, in a context (the
|
|
61
72
|
* command's own when absent), of a subscription when the stage is
|
|
62
|
-
* `
|
|
73
|
+
* `handled`. The snapshot is the subscription named `wow.snapshot`
|
|
74
|
+
* (`SNAPSHOT_SUBSCRIPTION`), which a `Wow-Wait` header writes `snapshot`.
|
|
63
75
|
*/
|
|
64
76
|
export interface Hop {
|
|
65
|
-
|
|
77
|
+
/**
|
|
78
|
+
* The stage; a server newer than this client may answer one it does not
|
|
79
|
+
* list.
|
|
80
|
+
*/
|
|
81
|
+
readonly stage: Stage | (string & {});
|
|
66
82
|
readonly context?: string | null;
|
|
67
83
|
readonly subscription?: string | null;
|
|
68
84
|
}
|
|
69
85
|
/** The kind of function that produced a result. */
|
|
70
|
-
export
|
|
86
|
+
export declare const FunctionKind: {
|
|
87
|
+
/** The aggregate's command function. */
|
|
88
|
+
readonly COMMAND: "command";
|
|
89
|
+
/** A projection. */
|
|
90
|
+
readonly PROJECT: "project";
|
|
91
|
+
/** An event handler that reacts. */
|
|
92
|
+
readonly REACT: "react";
|
|
93
|
+
/** A saga. */
|
|
94
|
+
readonly SAGA: "saga";
|
|
95
|
+
/** The snapshot subscription. */
|
|
96
|
+
readonly SNAPSHOT: "snapshot";
|
|
97
|
+
/** A reservation. */
|
|
98
|
+
readonly RESERVATION: "reservation";
|
|
99
|
+
/** A timer. */
|
|
100
|
+
readonly TIMERS: "timers";
|
|
101
|
+
};
|
|
102
|
+
/** A {@link FunctionKind} value. */
|
|
103
|
+
export type FunctionKind = (typeof FunctionKind)[keyof typeof FunctionKind];
|
|
71
104
|
/** Who produced a result: a function of `kind` in `context`. */
|
|
72
105
|
export interface FunctionInfo {
|
|
73
|
-
|
|
106
|
+
/**
|
|
107
|
+
* The kind; a server newer than this client may answer one it does not
|
|
108
|
+
* list.
|
|
109
|
+
*/
|
|
110
|
+
readonly kind: FunctionKind | (string & {});
|
|
74
111
|
readonly context: string;
|
|
75
112
|
readonly processor: string;
|
|
76
113
|
readonly name: string;
|
|
@@ -97,10 +134,19 @@ export interface ErrorInfo {
|
|
|
97
134
|
readonly extensions?: Readonly<Record<string, unknown>>;
|
|
98
135
|
}
|
|
99
136
|
/** How a command ended at a hop. */
|
|
100
|
-
export
|
|
137
|
+
export declare const CommandResultStatus: {
|
|
138
|
+
/** The command reached the hop. */
|
|
139
|
+
readonly SUCCEEDED: "succeeded";
|
|
140
|
+
/** The domain or admission refused the command. */
|
|
141
|
+
readonly REJECTED: "rejected";
|
|
142
|
+
/** A technical failure stopped the command. */
|
|
143
|
+
readonly FAILED: "failed";
|
|
144
|
+
};
|
|
145
|
+
/** A {@link CommandResultStatus} value. */
|
|
146
|
+
export type CommandResultStatus = (typeof CommandResultStatus)[keyof typeof CommandResultStatus];
|
|
101
147
|
/**
|
|
102
148
|
* The command a request named before a transformer turned it into the one
|
|
103
|
-
* that ran
|
|
149
|
+
* that ran.
|
|
104
150
|
*/
|
|
105
151
|
export interface TransformedFrom {
|
|
106
152
|
/** The full type name, `context.aggregate.Command`. */
|
|
@@ -108,7 +154,7 @@ export interface TransformedFrom {
|
|
|
108
154
|
readonly aggregateId?: string | null;
|
|
109
155
|
}
|
|
110
156
|
/**
|
|
111
|
-
* The one outward result of a command
|
|
157
|
+
* The one outward result of a command: what it reached at one
|
|
112
158
|
* hop of its wait chain. A command route answers the last one; its event
|
|
113
159
|
* stream sends one per hop.
|
|
114
160
|
*
|
|
@@ -126,15 +172,20 @@ export interface CommandResult<R = Record<string, unknown>> {
|
|
|
126
172
|
readonly commandId: string;
|
|
127
173
|
readonly requestId: string;
|
|
128
174
|
readonly correlationId: string;
|
|
175
|
+
/** The aggregate: a result that succeeded always names its id. */
|
|
129
176
|
readonly ref: AggregateRef;
|
|
130
177
|
readonly hop: Hop;
|
|
131
178
|
readonly function: FunctionInfo;
|
|
132
|
-
|
|
179
|
+
/**
|
|
180
|
+
* The status; a server newer than this client may answer one it does not
|
|
181
|
+
* list, which did not succeed as far as this client knows.
|
|
182
|
+
*/
|
|
183
|
+
readonly status: CommandResultStatus | (string & {});
|
|
133
184
|
/** The aggregate's version after the commit, or the unchanged one. */
|
|
134
185
|
readonly version?: number | null;
|
|
135
186
|
/** The request was already committed: it was not decided again. */
|
|
136
187
|
readonly duplicate: boolean;
|
|
137
|
-
/** Set when `status` is `
|
|
188
|
+
/** Set when `status` is `rejected` or `failed`. */
|
|
138
189
|
readonly error?: ErrorInfo | null;
|
|
139
190
|
readonly results: R;
|
|
140
191
|
/** On a saga's hop, the ids of the commands it derived. */
|
|
@@ -150,31 +201,30 @@ export interface CommandResult<R = Record<string, unknown>> {
|
|
|
150
201
|
/** When `chainEnded`, the hops of the plan not reached, in order. */
|
|
151
202
|
readonly pending?: readonly Hop[];
|
|
152
203
|
}
|
|
153
|
-
/** The tags of an aggregate: names to values. */
|
|
154
|
-
export type Tags = Readonly<Record<string, readonly string[]>>;
|
|
155
204
|
/**
|
|
156
|
-
*
|
|
157
|
-
* `
|
|
205
|
+
* A result that may not have succeeded, as a rejection or a problem carries
|
|
206
|
+
* it (`CommandRejectedError.result`, `WowProblemError.result`): a command
|
|
207
|
+
* refused before an aggregate id was decided names none
|
|
208
|
+
* ({@link CommandRef}). The Kotlin client has no type of its own
|
|
209
|
+
* for it: its `CommandResult.ref` holds such an id as
|
|
210
|
+
* `AggregateRef.UNASSIGNED`.
|
|
158
211
|
*
|
|
159
|
-
* @typeParam
|
|
212
|
+
* @typeParam R - The results' type.
|
|
160
213
|
*/
|
|
161
|
-
export interface
|
|
162
|
-
readonly ref:
|
|
163
|
-
readonly version: number;
|
|
164
|
-
readonly scope: Scope;
|
|
165
|
-
readonly deleted: boolean;
|
|
166
|
-
readonly tags: Tags;
|
|
167
|
-
readonly state: S;
|
|
214
|
+
export interface RefusedResult<R = Record<string, unknown>> extends Omit<CommandResult<R>, 'ref'> {
|
|
215
|
+
readonly ref: CommandRef;
|
|
168
216
|
}
|
|
217
|
+
/** The tags of an aggregate: names to values. */
|
|
218
|
+
export type Tags = Readonly<Record<string, readonly string[]>>;
|
|
169
219
|
/**
|
|
170
|
-
* An event as Wow reads it now: under its current name, upgraded to its latest revision. The `events` query gives
|
|
220
|
+
* An event as Wow reads it now: under its current name, upgraded to its latest revision. Kotlin's `CommittedEvent`. The `events` query gives
|
|
171
221
|
* every stored event so, however old its record, and leaves out the events its aggregate retired, so a generated
|
|
172
222
|
* `<Aggregate>Event` union, with {@link SystemEvent}, covers each event it returns.
|
|
173
223
|
*
|
|
174
224
|
* @typeParam N - The event's name.
|
|
175
225
|
* @typeParam B - The event's body.
|
|
176
226
|
*/
|
|
177
|
-
export interface
|
|
227
|
+
export interface CommittedEvent<N extends string = string, B = unknown> {
|
|
178
228
|
readonly name: N;
|
|
179
229
|
readonly revision: number;
|
|
180
230
|
readonly body: B;
|
|
@@ -192,36 +242,36 @@ export interface TagsApplied {
|
|
|
192
242
|
readonly tags: Tags;
|
|
193
243
|
}
|
|
194
244
|
/**
|
|
195
|
-
* The body of `wow.ScheduleSet
|
|
245
|
+
* The body of `wow.ScheduleSet`: the aggregate set its
|
|
196
246
|
* schedule `key`, to send `target` the command of type `commandType`
|
|
197
247
|
* (`command` its JSON text) as `rule` says.
|
|
198
248
|
*/
|
|
199
249
|
export interface ScheduleSet {
|
|
200
250
|
readonly key: string;
|
|
201
251
|
readonly rule: ScheduleRule;
|
|
202
|
-
readonly target:
|
|
252
|
+
readonly target: CommandRef;
|
|
203
253
|
readonly commandType: string;
|
|
204
254
|
readonly command: string;
|
|
205
255
|
}
|
|
206
|
-
/** The body of `wow.ScheduleCancelled
|
|
256
|
+
/** The body of `wow.ScheduleCancelled`. */
|
|
207
257
|
export interface ScheduleCancelled {
|
|
208
258
|
readonly key: string;
|
|
209
259
|
}
|
|
210
260
|
/**
|
|
211
|
-
* The system events the kernel gives every aggregate
|
|
261
|
+
* The system events the kernel gives every aggregate:
|
|
212
262
|
* the lifecycle events and the schedule events. A state trace and an event
|
|
213
263
|
* stream carry them beside the aggregate's own events, so the event union
|
|
214
264
|
* `wow-generator` writes for an aggregate includes this one.
|
|
215
265
|
*/
|
|
216
|
-
export type SystemEvent =
|
|
266
|
+
export type SystemEvent = CommittedEvent<'wow.lifecycle.AggregateDeleted', Readonly<Record<string, never>>> | CommittedEvent<'wow.lifecycle.AggregateRestored', Readonly<Record<string, never>>> | CommittedEvent<'wow.lifecycle.OwnerTransferred', OwnerTransferred> | CommittedEvent<'wow.lifecycle.SpaceTransferred', SpaceTransferred> | CommittedEvent<'wow.lifecycle.TagsApplied', TagsApplied> | CommittedEvent<'wow.ScheduleSet', ScheduleSet> | CommittedEvent<'wow.ScheduleCancelled', ScheduleCancelled>;
|
|
217
267
|
/**
|
|
218
|
-
* One commit of a state trace
|
|
268
|
+
* One commit of a state trace: the events of a version and the
|
|
219
269
|
* aggregate after it.
|
|
220
270
|
*
|
|
221
271
|
* @typeParam S - The state's type.
|
|
222
272
|
* @typeParam E - The events' type.
|
|
223
273
|
*/
|
|
224
|
-
export interface CommitView<S = unknown, E extends
|
|
274
|
+
export interface CommitView<S = unknown, E extends CommittedEvent = CommittedEvent> {
|
|
225
275
|
readonly version: number;
|
|
226
276
|
/** When it was committed, in epoch milliseconds. */
|
|
227
277
|
readonly commitTime: number;
|
|
@@ -239,17 +289,18 @@ export interface CommitView<S = unknown, E extends EventView = EventView> {
|
|
|
239
289
|
* What `GET /{context}/{aggregate}/{id}/state/trace` answers: the aggregate
|
|
240
290
|
* and its commits in version order.
|
|
241
291
|
*/
|
|
242
|
-
export interface StateTrace<S = unknown, E extends
|
|
292
|
+
export interface StateTrace<S = unknown, E extends CommittedEvent = CommittedEvent> {
|
|
243
293
|
readonly ref: AggregateRef;
|
|
244
294
|
readonly commits: readonly CommitView<S, E>[];
|
|
245
295
|
}
|
|
246
296
|
/**
|
|
247
|
-
*
|
|
248
|
-
*
|
|
297
|
+
* An aggregate's latest committed state, as a record of the `snapshot` query
|
|
298
|
+
* model and as `GET /{context}/{aggregate}/{id}/state` answer it: the
|
|
299
|
+
* aggregate's system fields and its state. Kotlin's `Snapshot`.
|
|
249
300
|
*
|
|
250
301
|
* @typeParam S - The state's type.
|
|
251
302
|
*/
|
|
252
|
-
export interface
|
|
303
|
+
export interface Snapshot<S = unknown> {
|
|
253
304
|
readonly tenantId: string;
|
|
254
305
|
readonly aggregateId: string;
|
|
255
306
|
readonly version: number;
|
|
@@ -267,9 +318,9 @@ export interface SnapshotRecord<S = unknown> {
|
|
|
267
318
|
readonly firstOperator: Operator | null;
|
|
268
319
|
/**
|
|
269
320
|
* The schedules the aggregate keeps (decision D198): each rule, `{type,
|
|
270
|
-
* ...}`, by its key
|
|
321
|
+
* ...}`, by its key.
|
|
271
322
|
*/
|
|
272
|
-
readonly schedules
|
|
323
|
+
readonly schedules: Readonly<Record<string, ScheduleRule>>;
|
|
273
324
|
readonly state: S;
|
|
274
325
|
}
|
|
275
326
|
/**
|
|
@@ -277,19 +328,19 @@ export interface SnapshotRecord<S = unknown> {
|
|
|
277
328
|
* project on; a state field is `state.<path>`.
|
|
278
329
|
*/
|
|
279
330
|
export type SnapshotSystemField = 'tenantId' | 'aggregateId' | 'version' | 'ownerId' | 'spaceId' | 'deleted' | 'tags' | 'firstEventTime' | 'lastEventTime' | 'operator' | 'operator.id' | 'operator.tenantId' | 'operator.crossScope' | 'firstOperator' | 'firstOperator.id' | 'firstOperator.tenantId' | 'firstOperator.crossScope' | 'schedules';
|
|
280
|
-
/** A schedule rule of a snapshot's `schedules
|
|
331
|
+
/** A schedule rule of a snapshot's `schedules`. */
|
|
281
332
|
export interface ScheduleRule {
|
|
282
333
|
/** The rule's type: `at`, `after`, `cron`, … */
|
|
283
334
|
readonly type: string;
|
|
284
335
|
readonly [property: string]: unknown;
|
|
285
336
|
}
|
|
286
337
|
/**
|
|
287
|
-
* A record of the `events` query model
|
|
288
|
-
* aggregate and its events.
|
|
338
|
+
* A record of the `events` query model: one commit of one
|
|
339
|
+
* aggregate and its events. Kotlin's `EventStream`.
|
|
289
340
|
*
|
|
290
341
|
* @typeParam E - The events' type.
|
|
291
342
|
*/
|
|
292
|
-
export interface
|
|
343
|
+
export interface EventStream<E extends CommittedEvent = CommittedEvent> {
|
|
293
344
|
readonly aggregateId: string;
|
|
294
345
|
readonly tenantId: string;
|
|
295
346
|
readonly version: number;
|
|
@@ -306,15 +357,15 @@ export interface EventStreamRecord<E extends EventView = EventView> {
|
|
|
306
357
|
readonly events: readonly E[];
|
|
307
358
|
}
|
|
308
359
|
/**
|
|
309
|
-
* The fields of an event stream record a query names
|
|
360
|
+
* The fields of an event stream record a query names: its
|
|
310
361
|
* system fields and `events`, the array an `elementMatch` filter and an
|
|
311
362
|
* aggregation's `elements` reach an event through, by the event's own
|
|
312
363
|
* `name`, `revision` and `body.*`.
|
|
313
364
|
*/
|
|
314
365
|
export type EventStreamField = 'aggregateId' | 'tenantId' | 'version' | 'commitTime' | 'commandId' | 'requestId' | 'commandType' | 'ownerId' | 'spaceId' | 'operator' | 'operator.id' | 'operator.tenantId' | 'operator.crossScope' | 'events';
|
|
315
|
-
/** How an aggregate belongs to its callers
|
|
316
|
-
export type Ownership = '
|
|
317
|
-
/** One dataset of `GET /wow/dataset
|
|
366
|
+
/** How an aggregate belongs to its callers. */
|
|
367
|
+
export type Ownership = 'owner' | 'tenant';
|
|
368
|
+
/** One dataset of `GET /wow/dataset`. */
|
|
318
369
|
export interface DatasetEntry {
|
|
319
370
|
/** `{context}.{dataset}`. */
|
|
320
371
|
readonly name: string;
|