@ahoo-wang/wow-client 10.0.0-alpha.7 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"manifest.es.js","names":["MANIFEST_FORMAT","MANIFEST_FEATURES","checkManifest","manifest","unknown","marker","fetchManifest","json","send","client"],"sources":["../src/manifest.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 json,\n type RequestOptions,\n send,\n type WowClientOptions,\n} from './http.js';\nimport type {\n AggregateManifest,\n CommandManifest,\n ContextManifest,\n Manifest,\n ServiceRouteManifest,\n} from './manifestTypes.js';\n\nexport type * from './manifestTypes.js';\n\n/** Whether a command creates its aggregate. */\nexport type Creation = CommandManifest['creation'];\n\n/** A command as a {@link RoutingManifest} lists it: its name, former names and routes. */\nexport type RoutingCommand = Pick<CommandManifest, 'name' | 'routes'> &\n Partial<Pick<CommandManifest, 'aliases'>>;\n\n/** A service route as a {@link RoutingManifest} lists it: its name and its route. */\nexport type RoutingServiceRoute = Pick<ServiceRouteManifest, 'name' | 'route'>;\n\n/**\n * What a `CommandClient` reads of a Manifest to send a command: each\n * context's aggregates and their commands with their routes, and the context's\n * own system commands; and what a `ServiceRoutes` reads to call a service\n * route: the context's routes. A whole {@link Manifest} is one; a generated\n * client carries its service's as data (`manifest.ts`), with no schema.\n */\nexport interface RoutingManifest extends Pick<Manifest, 'format' | 'requires'> {\n readonly contexts: readonly (Pick<ContextManifest, 'name'> & {\n readonly aggregates?: readonly (Pick<AggregateManifest, 'name'> & {\n readonly commands?: readonly RoutingCommand[];\n })[];\n readonly commands?: readonly RoutingCommand[];\n readonly routes?: readonly RoutingServiceRoute[];\n })[];\n}\n\n/** The format of the Manifest this client reads. */\nexport const MANIFEST_FORMAT = 1;\n\n/**\n * The markers of a Manifest's `requires` this client understands, as the\n * Kotlin reader's `ManifestFeatures`: none yet.\n */\nexport const MANIFEST_FEATURES: ReadonlySet<string> = new Set<string>();\n\n/**\n * Checks that this client can read `manifest`: its format, and every marker it\n * requires.\n *\n * @param manifest - The Manifest\n * @throws TypeError naming what this client does not understand\n */\nexport function checkManifest<M extends RoutingManifest>(manifest: M): M {\n if (manifest.format !== MANIFEST_FORMAT) {\n throw new TypeError(\n `The Manifest is of format ${manifest.format}; this client reads format ${MANIFEST_FORMAT}.`,\n );\n }\n const unknown = (manifest.requires ?? []).filter(\n marker => !MANIFEST_FEATURES.has(marker),\n );\n if (unknown.length > 0) {\n throw new TypeError(\n `The Manifest requires ${unknown.join(', ')}, which this client does not understand: use a newer @ahoo-wang/wow-client.`,\n );\n }\n return manifest;\n}\n\n/**\n * The service's Manifest, `GET /wow/manifest`, authorized as any API.\n *\n * @param client - How the service is reached\n * @param options - Headers and cancellation\n */\nexport async function fetchManifest(\n client: WowClientOptions = {},\n options?: RequestOptions,\n): Promise<Manifest> {\n return checkManifest(\n await json<Manifest>(\n await send(client, { method: 'GET', path: '/wow/manifest', options }),\n ),\n );\n}\n"],"mappings":";;AAyDA,IAAaA,IAAkB,GAMlBC,oBAAyC,IAAI,IAAY;AAStE,SAAgBC,EAAyC,GAAgB;CACvE,IAAIC,EAAS,WAAA,GACX,MAAU,UACR,6BAA6BA,EAAS,OAAO,8BAC/C;CAEF,IAAMC,KAAWD,EAAS,YAAY,CAAC,EAAA,CAAG,QACxC,MAAU,CAACF,EAAkB,IAAII,CAAM,CACzC;CACA,IAAID,EAAQ,SAAS,GACnB,MAAU,UACR,yBAAyBA,EAAQ,KAAK,IAAI,EAAE,4EAC9C;CAEF,OAAOD;AACT;AAQA,eAAsBG,EACpB,IAA2B,CAAC,GAC5B,GACmB;CACnB,OAAOJ,EACL,MAAMK,EACJ,MAAMC,EAAKC,GAAQ;EAAE,QAAQ;EAAO,MAAM;EAAiB;CAAQ,CAAC,CACtE,CACF;AACF"}
1
+ {"version":3,"file":"manifest.es.js","names":["MANIFEST_FORMAT","MANIFEST_FEATURES","checkManifest","manifest","unknown","marker","fetchManifest","json","send","client"],"sources":["../src/manifest.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 json,\n type RequestOptions,\n send,\n type WowClientOptions,\n} from './http.js';\nimport type {\n AggregateManifest,\n CommandManifest,\n ContextManifest,\n Manifest,\n ServiceRouteManifest,\n} from './manifestTypes.js';\n\nexport type * from './manifestTypes.js';\n\n/** Whether a command creates its aggregate. */\nexport type Creation = CommandManifest['creation'];\n\n/**\n * A command as a {@link RoutingManifest} lists it: its name, former names and\n * routes, and the property of its body that names its aggregate, for a command\n * whose body does (`idProperty`).\n */\nexport type RoutingCommand = Pick<CommandManifest, 'name' | 'routes'> &\n Partial<Pick<CommandManifest, 'aliases' | 'idProperty'>>;\n\n/** A service route as a {@link RoutingManifest} lists it: its name and its route. */\nexport type RoutingServiceRoute = Pick<ServiceRouteManifest, 'name' | 'route'>;\n\n/**\n * What a `CommandClient` reads of a Manifest to send a command: each\n * context's aggregates and their commands with their routes, and the context's\n * own system commands; and what a `ServiceRoutes` reads to call a service\n * route: the context's routes. A whole {@link Manifest} is one; a generated\n * client carries its service's as data (`manifest.ts`), with no schema.\n */\nexport interface RoutingManifest extends Pick<Manifest, 'format' | 'requires'> {\n readonly contexts: readonly (Pick<ContextManifest, 'name'> & {\n readonly aggregates?: readonly (Pick<AggregateManifest, 'name'> & {\n readonly commands?: readonly RoutingCommand[];\n })[];\n readonly commands?: readonly RoutingCommand[];\n readonly routes?: readonly RoutingServiceRoute[];\n })[];\n}\n\n/** The format of the Manifest this client reads. */\nexport const MANIFEST_FORMAT = 1;\n\n/**\n * The markers of a Manifest's `requires` this client understands, as the\n * Kotlin reader's `ManifestFeatures`: none yet.\n */\nexport const MANIFEST_FEATURES: ReadonlySet<string> = new Set<string>();\n\n/**\n * Checks that this client can read `manifest`: its format, and every marker it\n * requires.\n *\n * @param manifest - The Manifest\n * @throws TypeError naming what this client does not understand\n */\nexport function checkManifest<M extends RoutingManifest>(manifest: M): M {\n if (manifest.format !== MANIFEST_FORMAT) {\n throw new TypeError(\n `The Manifest is of format ${manifest.format}; this client reads format ${MANIFEST_FORMAT}.`,\n );\n }\n const unknown = (manifest.requires ?? []).filter(\n marker => !MANIFEST_FEATURES.has(marker),\n );\n if (unknown.length > 0) {\n throw new TypeError(\n `The Manifest requires ${unknown.join(', ')}, which this client does not understand: use a newer @ahoo-wang/wow-client.`,\n );\n }\n return manifest;\n}\n\n/**\n * The service's Manifest, `GET /wow/manifest`, authorized as any API.\n *\n * @param client - How the service is reached\n * @param options - Headers and cancellation\n */\nexport async function fetchManifest(\n client: WowClientOptions = {},\n options?: RequestOptions,\n): Promise<Manifest> {\n return checkManifest(\n await json<Manifest>(\n await send(client, { method: 'GET', path: '/wow/manifest', options }),\n ),\n );\n}\n"],"mappings":";;AA6DA,IAAaA,IAAkB,GAMlBC,oBAAyC,IAAI,IAAY;AAStE,SAAgBC,EAAyC,GAAgB;CACvE,IAAIC,EAAS,WAAA,GACX,MAAU,UACR,6BAA6BA,EAAS,OAAO,8BAC/C;CAEF,IAAMC,KAAWD,EAAS,YAAY,CAAC,EAAA,CAAG,QACxC,MAAU,CAACF,EAAkB,IAAII,CAAM,CACzC;CACA,IAAID,EAAQ,SAAS,GACnB,MAAU,UACR,yBAAyBA,EAAQ,KAAK,IAAI,EAAE,4EAC9C;CAEF,OAAOD;AACT;AAQA,eAAsBG,EACpB,IAA2B,CAAC,GAC5B,GACmB;CACnB,OAAOJ,EACL,MAAMK,EACJ,MAAMC,EAAKC,GAAQ;EAAE,QAAQ;EAAO,MAAM;EAAiB;CAAQ,CAAC,CACtE,CACF;AACF"}
@@ -106,6 +106,8 @@ export interface CommandManifest {
106
106
  /** A system command (wow.*): a lifecycle command, a rebuild or a job command. */
107
107
  readonly system?: boolean;
108
108
  readonly transformsTo?: readonly string[];
109
+ /** The property of the command's body that holds its aggregate's id. */
110
+ readonly idProperty?: string;
109
111
  readonly description?: string;
110
112
  }
111
113
  /** An event of an aggregate and its revision. */
@@ -150,7 +152,7 @@ export interface SubscriptionManifest {
150
152
  readonly rejected?: readonly string[];
151
153
  readonly committed?: readonly string[];
152
154
  readonly calls?: readonly string[];
153
- readonly start?: 'beginning' | 'end' | (string & {});
155
+ readonly start?: 'beginning' | 'end' | 'join' | (string & {});
154
156
  readonly schedules?: readonly string[];
155
157
  readonly retry?: RetryManifest;
156
158
  readonly job?: JobManifest;
@@ -178,6 +180,7 @@ export interface RetryManifest {
178
180
  readonly timeout?: string;
179
181
  readonly recoverable?: readonly string[];
180
182
  readonly unrecoverable?: readonly string[];
183
+ readonly systemic?: readonly string[];
181
184
  readonly multiplier?: number;
182
185
  }
183
186
  /** The scheduled job a subscription runs. */
@@ -186,8 +189,7 @@ export interface JobManifest {
186
189
  readonly cron: string;
187
190
  readonly zone: string;
188
191
  /** Who the job runs for. */
189
- readonly scope: 'system' | 'tenant' | (string & {});
190
- readonly sharded: boolean;
192
+ readonly scope: 'system' | 'tenant' | 'sharded' | (string & {});
191
193
  /** What the job does with the slots it missed. */
192
194
  readonly misfire: 'coalesce' | 'catch-up' | (string & {});
193
195
  }
@@ -106,6 +106,8 @@ export interface CommandManifest {
106
106
  /** A system command (wow.*): a lifecycle command, a rebuild or a job command. */
107
107
  readonly system?: boolean;
108
108
  readonly transformsTo?: readonly string[];
109
+ /** The property of the command's body that holds its aggregate's id. */
110
+ readonly idProperty?: string;
109
111
  readonly description?: string;
110
112
  }
111
113
  /** An event of an aggregate and its revision. */
@@ -150,7 +152,7 @@ export interface SubscriptionManifest {
150
152
  readonly rejected?: readonly string[];
151
153
  readonly committed?: readonly string[];
152
154
  readonly calls?: readonly string[];
153
- readonly start?: 'beginning' | 'end' | (string & {});
155
+ readonly start?: 'beginning' | 'end' | 'join' | (string & {});
154
156
  readonly schedules?: readonly string[];
155
157
  readonly retry?: RetryManifest;
156
158
  readonly job?: JobManifest;
@@ -178,6 +180,7 @@ export interface RetryManifest {
178
180
  readonly timeout?: string;
179
181
  readonly recoverable?: readonly string[];
180
182
  readonly unrecoverable?: readonly string[];
183
+ readonly systemic?: readonly string[];
181
184
  readonly multiplier?: number;
182
185
  }
183
186
  /** The scheduled job a subscription runs. */
@@ -186,8 +189,7 @@ export interface JobManifest {
186
189
  readonly cron: string;
187
190
  readonly zone: string;
188
191
  /** Who the job runs for. */
189
- readonly scope: 'system' | 'tenant' | (string & {});
190
- readonly sharded: boolean;
192
+ readonly scope: 'system' | 'tenant' | 'sharded' | (string & {});
191
193
  /** What the job does with the slots it missed. */
192
194
  readonly misfire: 'coalesce' | 'catch-up' | (string & {});
193
195
  }
package/dist/wait.cjs CHANGED
@@ -1,2 +1,2 @@
1
- const e=require("./wire.cjs");var t=`snapshot`,n=/^[A-Za-z0-9_.-]+$/;function r(e,t){if(!n.test(t))throw TypeError(`Not a ${e} name: '${t}'.`);return t}function i(e,t,n){return{stage:e,...t===void 0?{}:{context:r(`context`,t)},...n===void 0?{}:{subscription:r(`subscription`,n)}}}var a={accepted:t=>i(e.Stage.ACCEPTED,t),committed:t=>i(e.Stage.COMMITTED,t),snapshot:n=>i(e.Stage.HANDLED,n,t),handled:(t,n)=>i(e.Stage.HANDLED,n,t)};function o(t){let n=t.context??void 0,r=t.subscription??void 0;if(t.stage===e.Stage.HANDLED){if(r===void 0)throw TypeError(`A handled hop names its subscription.`);return r===`snapshot`?n===void 0?`snapshot`:`snapshot(${n})`:n===void 0?`handled(${r})`:`handled(${n}/${r})`}if(r!==void 0)throw TypeError(`Only a handled hop names a subscription.`);let i=t.stage.toLowerCase();return n===void 0?i:`${i}(${n})`}var s=class e{static{this.DEFAULT_TIMEOUT=1e4}static{this.DEFAULT=new e([a.snapshot()],void 0,!0)}static{this.SNAPSHOT=new e([a.snapshot()])}static{this.COMMITTED=new e([a.committed()])}static{this.ACCEPTED=new e([a.accepted()])}static of(...t){return new e(t)}constructor(t,n=e.DEFAULT_TIMEOUT,r=!1){if(t.length===0)throw TypeError(`A wait plan has at least one hop.`);p(n),this.hops=Object.freeze([...t]),this.timeout=n,this.isDefault=r,Object.freeze(this)}within(t){return new e(this.hops,t,this.isDefault)}};function c(e){return e.hops.map(o).join(` > `)}var l=/^([A-Za-z]+)\s*(?:\(\s*([^()]*?)\s*\))?$/;function u(e){if(e.trim()===``)throw TypeError(`A wait plan has at least one hop.`);return s.of(...e.split(`>`).map(e=>d(e.trim())))}function d(e){let t=l.exec(e);if(t===null)throw TypeError(`Not a hop: '${e}'.`);let n=t[1].toLowerCase(),r=t[2];switch(n){case`accepted`:return a.accepted(r);case`committed`:return a.committed(r);case`snapshot`:return a.snapshot(r);case`handled`:{if(r===void 0)throw TypeError(`A handled hop names its subscription: '${e}'.`);let t=r.split(`/`);if(t.length>2)throw TypeError(`A handled hop is (subscription) or (context/subscription): '${r}'.`);return t.length===1?a.handled(t[0]):a.handled(t[1].trim(),t[0].trim())}default:throw TypeError(`Not a stage: '${n}'.`)}}function f(e){return p(e),e%1e3==0?`${e/1e3}s`:`${e}ms`}function p(e){if(!Number.isInteger(e)||e<=0)throw TypeError(`A wait timeout is a positive whole number of milliseconds: ${e}.`)}exports.SNAPSHOT_SUBSCRIPTION=t,exports.WaitPlan=s,exports.formatHop=o,exports.formatWaitPlan=c,exports.formatWaitTimeout=f,exports.parseHop=d,exports.parseWaitPlan=u,exports.wait=a;
1
+ const e=require("./wire.cjs");var t=`wow.snapshot`,n=/^[A-Za-z0-9_.-]+$/;function r(e,t){if(!n.test(t))throw TypeError(`Not a ${e} name: '${t}'.`);return t}function i(e,t,n){return{stage:e,...t===void 0?{}:{context:r(`context`,t)},...n===void 0?{}:{subscription:r(`subscription`,n)}}}var a={accepted:t=>i(e.Stage.ACCEPTED,t),committed:t=>i(e.Stage.COMMITTED,t),snapshot:n=>i(e.Stage.HANDLED,n,t),handled:(t,n)=>i(e.Stage.HANDLED,n,t)};function o(t){let n=t.context??void 0,r=t.subscription??void 0;if(t.stage===e.Stage.HANDLED){if(r===void 0)throw TypeError(`A handled hop names its subscription.`);return r===`wow.snapshot`?n===void 0?`snapshot`:`snapshot(${n})`:n===void 0?`handled(${r})`:`handled(${n}/${r})`}if(r!==void 0)throw TypeError(`Only a handled hop names a subscription.`);let i=t.stage.toLowerCase();return n===void 0?i:`${i}(${n})`}var s=class e{static{this.DEFAULT_TIMEOUT=1e4}static{this.DEFAULT=new e([a.snapshot()],void 0,!0)}static{this.SNAPSHOT=new e([a.snapshot()])}static{this.COMMITTED=new e([a.committed()])}static{this.ACCEPTED=new e([a.accepted()])}static of(...t){return new e(t)}constructor(t,n=e.DEFAULT_TIMEOUT,r=!1){if(t.length===0)throw TypeError(`A wait plan has at least one hop.`);p(n),this.hops=Object.freeze([...t]),this.timeout=n,this.isDefault=r,Object.freeze(this)}within(t){return new e(this.hops,t,this.isDefault)}};function c(e){return e.hops.map(o).join(` > `)}var l=/^([A-Za-z]+)\s*(?:\(\s*([^()]*?)\s*\))?$/;function u(e){if(e.trim()===``)throw TypeError(`A wait plan has at least one hop.`);return s.of(...e.split(`>`).map(e=>d(e.trim())))}function d(e){let t=l.exec(e);if(t===null)throw TypeError(`Not a hop: '${e}'.`);let n=t[1].toLowerCase(),r=t[2];switch(n){case`accepted`:return a.accepted(r);case`committed`:return a.committed(r);case`snapshot`:return a.snapshot(r);case`handled`:{if(r===void 0)throw TypeError(`A handled hop names its subscription: '${e}'.`);let t=r.split(`/`);if(t.length>2)throw TypeError(`A handled hop is (subscription) or (context/subscription): '${r}'.`);return t.length===1?a.handled(t[0]):a.handled(t[1].trim(),t[0].trim())}default:throw TypeError(`Not a stage: '${n}'.`)}}function f(e){return p(e),e%1e3==0?`${e/1e3}s`:`${e}ms`}function p(e){if(!Number.isInteger(e)||e<=0)throw TypeError(`A wait timeout is a positive whole number of milliseconds: ${e}.`)}exports.SNAPSHOT_SUBSCRIPTION=t,exports.WaitPlan=s,exports.formatHop=o,exports.formatWaitPlan=c,exports.formatWaitTimeout=f,exports.parseHop=d,exports.parseWaitPlan=u,exports.wait=a;
2
2
  //# sourceMappingURL=wait.cjs.map
package/dist/wait.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"wait.cjs","names":["Stage","require_wire","SNAPSHOT_SUBSCRIPTION","NAME","checkName","value","kind","hop","context","subscription","wait","formatHop","keyword","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 = 'snapshot';\n\nconst NAME = /^[A-Za-z0-9_.-]+$/;\n\nfunction checkName(kind: string, value: string): string {\n if (!NAME.test(value)) {\n throw new TypeError(`Not a ${kind} name: '${value}'.`);\n }\n return value;\n}\n\nfunction hop(stage: Stage, context?: string, subscription?: string): Hop {\n return {\n stage,\n ...(context === undefined\n ? {}\n : { context: checkName('context', context) }),\n ...(subscription === undefined\n ? {}\n : { subscription: checkName('subscription', subscription) }),\n };\n}\n\n/**\n * Builds the hops of a wait chain. A context left out is\n * the command's own. A saga's `handled` hop may be followed by hops of the\n * commands it derived, in their contexts:\n *\n * @example\n * ```typescript\n * const plan = [\n * wait.committed(),\n * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),\n * wait.committed('eshop-ordering'),\n * ];\n * ```\n */\nexport const wait = {\n /** Until the command passed admission; the route answers 202. */\n accepted: (context?: string): Hop => hop(Stage.ACCEPTED, context),\n /** Until the command's events are appended to the log. */\n committed: (context?: string): Hop => hop(Stage.COMMITTED, context),\n /** Until the snapshot holds the commit: the caller reads its own write. */\n snapshot: (context?: string): Hop =>\n hop(Stage.HANDLED, context, SNAPSHOT_SUBSCRIPTION),\n /** Until the subscription named `processor.function` handled the commit. */\n handled: (subscription: string, context?: string): Hop =>\n hop(Stage.HANDLED, context, subscription),\n} as const;\n\n/**\n * A hop as `Wow-Wait` spells it: `accepted`, `committed`, `snapshot` and\n * `handled(subscription)`, each with its context when it has one:\n * `committed(ctx)`, `snapshot(ctx)`, `handled(ctx/subscription)`.\n *\n * @param value - The hop\n */\nexport function formatHop(value: Hop): string {\n const context = value.context ?? undefined;\n const subscription = value.subscription ?? undefined;\n if (value.stage === Stage.HANDLED) {\n if (subscription === undefined) {\n throw new TypeError('A handled hop names its subscription.');\n }\n if (subscription === SNAPSHOT_SUBSCRIPTION) {\n return context === undefined ? 'snapshot' : `snapshot(${context})`;\n }\n return context === undefined\n ? `handled(${subscription})`\n : `handled(${context}/${subscription})`;\n }\n if (subscription !== undefined) {\n throw new TypeError(`Only a handled hop names a subscription.`);\n }\n const keyword = value.stage.toLowerCase();\n return context === undefined ? keyword : `${keyword}(${context})`;\n}\n\n/**\n * How far a command is waited for, and for how long: the hops, in order, and\n * a timeout in milliseconds. Kotlin's `me.ahoo.wow.api.result.WaitPlan`,\n * with its constants and constructors: {@link WaitPlan.of} the hops a\n * {@link wait} builder makes, {@link WaitPlan.within} another timeout.\n *\n * @example\n * ```typescript\n * const plan = WaitPlan.of(\n * wait.committed(),\n * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),\n * ).within(30_000);\n * ```\n */\nexport class WaitPlan {\n /** The timeout of a wait whose caller gives none: 10 seconds. */\n static readonly DEFAULT_TIMEOUT = 10_000;\n\n /**\n * The plan of a caller that asked for none: until the snapshot holds the\n * commit, so the caller reads its own write; until `committed` for an\n * aggregate without a snapshot subscription. A request with it sends no\n * `Wow-Wait`, so the service picks.\n */\n static readonly DEFAULT = new WaitPlan([wait.snapshot()], undefined, true);\n\n /**\n * Until the snapshot holds the commit, asked for explicitly: rejected at\n * admission for an aggregate without a snapshot subscription.\n */\n static readonly SNAPSHOT = new WaitPlan([wait.snapshot()]);\n\n /** Until the events are appended. */\n static readonly COMMITTED = new WaitPlan([wait.committed()]);\n\n /** Until the command passed admission. */\n static readonly ACCEPTED = new WaitPlan([wait.accepted()]);\n\n /** Until `hops` are reached, in order. */\n static of(...hops: Hop[]): WaitPlan {\n return new WaitPlan(hops);\n }\n\n /** The hops to reach, in order; at least one. */\n readonly hops: readonly Hop[];\n /** How long to wait, in milliseconds. */\n readonly timeout: number;\n /** Whether this is {@link WaitPlan.DEFAULT}, the service's choice. */\n readonly isDefault: boolean;\n\n private constructor(\n hops: readonly Hop[],\n timeout: number = WaitPlan.DEFAULT_TIMEOUT,\n isDefault = false,\n ) {\n if (hops.length === 0) {\n throw new TypeError('A wait plan has at least one hop.');\n }\n checkTimeout(timeout);\n this.hops = Object.freeze([...hops]);\n this.timeout = timeout;\n this.isDefault = isDefault;\n Object.freeze(this);\n }\n\n /** This plan, waiting `timeout` milliseconds. */\n within(timeout: number): WaitPlan {\n return new WaitPlan(this.hops, timeout, this.isDefault);\n }\n}\n\n/**\n * A wait plan as the `Wow-Wait` header spells it: its hops, in order,\n * separated by `>`; the inverse of {@link parseWaitPlan}.\n *\n * @param plan - The plan\n */\nexport function formatWaitPlan(plan: WaitPlan): string {\n return plan.hops.map(formatHop).join(' > ');\n}\n\nconst HOP = /^([A-Za-z]+)\\s*(?:\\(\\s*([^()]*?)\\s*\\))?$/;\n\n/**\n * The plan a `Wow-Wait` value spells, as the service reads it: hops\n * separated by `>`, each `accepted`, `committed`, `snapshot` or\n * `handled(subscription)`, with its context in parentheses\n * (`committed(ctx)`, `handled(ctx/subscription)`); the inverse of\n * {@link formatWaitPlan}. Throws a `TypeError` for anything else.\n *\n * @param value - The header's value\n */\nexport function parseWaitPlan(value: string): WaitPlan {\n if (value.trim() === '') {\n throw new TypeError('A wait plan has at least one hop.');\n }\n return WaitPlan.of(...value.split('>').map(part => parseHop(part.trim())));\n}\n\n/**\n * The hop one part of a `Wow-Wait` value spells; see {@link parseWaitPlan}.\n *\n * @param value - The part, such as `committed(ctx)`\n */\nexport function parseHop(value: string): Hop {\n const match = HOP.exec(value);\n if (match === null) throw new TypeError(`Not a hop: '${value}'.`);\n const keyword = match[1].toLowerCase();\n const argument = match[2];\n switch (keyword) {\n case 'accepted':\n return wait.accepted(argument);\n case 'committed':\n return wait.committed(argument);\n case 'snapshot':\n return wait.snapshot(argument);\n case 'handled': {\n if (argument === undefined) {\n throw new TypeError(\n `A handled hop names its subscription: '${value}'.`,\n );\n }\n const parts = argument.split('/');\n if (parts.length > 2) {\n throw new TypeError(\n `A handled hop is (subscription) or (context/subscription): '${argument}'.`,\n );\n }\n return parts.length === 1\n ? wait.handled(parts[0])\n : wait.handled(parts[1].trim(), parts[0].trim());\n }\n default:\n throw new TypeError(`Not a stage: '${keyword}'.`);\n }\n}\n\n/**\n * A wait timeout as the `Wow-Wait-Timeout` header spells it: milliseconds\n * as `<n>s` when whole seconds, else `<n>ms`.\n *\n * @param timeout - Milliseconds\n */\nexport function formatWaitTimeout(timeout: number): string {\n checkTimeout(timeout);\n return timeout % 1000 === 0 ? `${timeout / 1000}s` : `${timeout}ms`;\n}\n\nfunction checkTimeout(timeout: number): void {\n if (!Number.isInteger(timeout) || timeout <= 0) {\n throw new TypeError(\n `A wait timeout is a positive whole number of milliseconds: ${timeout}.`,\n );\n }\n}\n"],"mappings":"A,8BAgBA,IAAaE,EAAwB,WAE/BC,EAAO,oBAEb,SAASC,EAAU,EAAc,EAAuB,CACtD,GAAI,CAACD,EAAK,KAAKE,CAAK,EAClB,MAAU,UAAU,SAASC,EAAK,UAAUD,EAAM,GAAG,EAEvD,OAAOA,CACT,CAEA,SAASE,EAAI,EAAc,EAAkB,EAA4B,CACvE,MAAO,CACL,QACA,GAAIC,IAAY,IAAA,GACZ,CAAC,EACD,CAAE,QAASJ,EAAU,UAAWI,CAAO,CAAE,EAC7C,GAAIC,IAAiB,IAAA,GACjB,CAAC,EACD,CAAE,aAAcL,EAAU,eAAgBK,CAAY,CAAE,CAC9D,CACF,CAgBA,IAAaC,EAAO,CAElB,SAAW,GAA0BH,EAAIP,EAAAA,MAAM,SAAUQ,CAAO,EAEhE,UAAY,GAA0BD,EAAIP,EAAAA,MAAM,UAAWQ,CAAO,EAElE,SAAW,GACTD,EAAIP,EAAAA,MAAM,QAASQ,EAASN,CAAqB,EAEnD,SAAU,EAAsB,IAC9BK,EAAIP,EAAAA,MAAM,QAASQ,EAASC,CAAY,CAC5C,EASA,SAAgBE,EAAU,EAAoB,CAC5C,IAAMH,EAAUH,EAAM,SAAW,IAAA,GAC3BI,EAAeJ,EAAM,cAAgB,IAAA,GAC3C,GAAIA,EAAM,QAAUL,EAAAA,MAAM,QAAS,CACjC,GAAIS,IAAiB,IAAA,GACnB,MAAU,UAAU,uCAAuC,EAK7D,OAHIA,IAAA,WACKD,IAAY,I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,EAAS,GAAG,GAAGR,EAAM,MAAM,GAAG,CAAC,CAAC,IAAI,GAAQiB,EAASC,EAAK,KAAK,CAAC,CAAC,CAAC,CAC3E,CAOA,SAAgBD,EAAS,EAAoB,CAC3C,IAAME,EAAQJ,EAAI,KAAKf,CAAK,EAC5B,GAAImB,IAAU,KAAM,MAAU,UAAU,eAAenB,EAAM,GAAG,EAChE,IAAMO,EAAUY,EAAM,EAAE,CAAC,YAAY,EAC/BC,EAAWD,EAAM,GACvB,OAAQZ,EAAR,CACE,IAAK,WACH,OAAOF,EAAK,SAASe,CAAQ,EAC/B,IAAK,YACH,OAAOf,EAAK,UAAUe,CAAQ,EAChC,IAAK,WACH,OAAOf,EAAK,SAASe,CAAQ,EAC/B,IAAK,UAAW,CACd,GAAIA,IAAa,IAAA,GACf,MAAU,UACR,0CAA0CpB,EAAM,GAClD,EAEF,IAAMqB,EAAQD,EAAS,MAAM,GAAG,EAChC,GAAIC,EAAM,OAAS,EACjB,MAAU,UACR,+DAA+DD,EAAS,GAC1E,EAEF,OAAOC,EAAM,SAAW,EACpBhB,EAAK,QAAQgB,EAAM,EAAE,EACrBhB,EAAK,QAAQgB,EAAM,EAAE,CAAC,KAAK,EAAGA,EAAM,EAAE,CAAC,KAAK,CAAC,CACnD,CACA,QACE,MAAU,UAAU,iBAAiBd,EAAQ,GAAG,CACpD,CACF,CAQA,SAAgBe,EAAkB,EAAyB,CAEzD,OADAZ,EAAaC,CAAO,EACbA,EAAU,KAAS,EAAI,GAAGA,EAAU,IAAK,GAAK,GAAGA,EAAQ,GAClE,CAEA,SAASD,EAAa,EAAuB,CAC3C,GAAI,CAAC,OAAO,UAAUC,CAAO,GAAKA,GAAW,EAC3C,MAAU,UACR,8DAA8DA,EAAQ,EACxE,CAEJ,C"}
1
+ {"version":3,"file":"wait.cjs","names":["Stage","require_wire","SNAPSHOT_SUBSCRIPTION","NAME","checkName","value","kind","hop","context","subscription","wait","formatHop","keyword","WaitPlan","hops","checkTimeout","timeout","isDefault","formatWaitPlan","plan","HOP","parseWaitPlan","parseHop","part","match","argument","parts","formatWaitTimeout"],"sources":["../src/wait.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { type Hop, Stage } from './wire.js';\n\n/** The name of the built-in subscription that writes snapshots. */\nexport const SNAPSHOT_SUBSCRIPTION = 'wow.snapshot';\n\nconst NAME = /^[A-Za-z0-9_.-]+$/;\n\nfunction checkName(kind: string, value: string): string {\n if (!NAME.test(value)) {\n throw new TypeError(`Not a ${kind} name: '${value}'.`);\n }\n return value;\n}\n\nfunction hop(stage: Stage, context?: string, subscription?: string): Hop {\n return {\n stage,\n ...(context === undefined\n ? {}\n : { context: checkName('context', context) }),\n ...(subscription === undefined\n ? {}\n : { subscription: checkName('subscription', subscription) }),\n };\n}\n\n/**\n * Builds the hops of a wait chain. A context left out is\n * the command's own. A saga's `handled` hop may be followed by hops of the\n * commands it derived, in their contexts:\n *\n * @example\n * ```typescript\n * const plan = [\n * wait.committed(),\n * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),\n * wait.committed('eshop-ordering'),\n * ];\n * ```\n */\nexport const wait = {\n /** Until the command passed admission; the route answers 202. */\n accepted: (context?: string): Hop => hop(Stage.ACCEPTED, context),\n /** Until the command's events are appended to the log. */\n committed: (context?: string): Hop => hop(Stage.COMMITTED, context),\n /** Until the snapshot holds the commit: the caller reads its own write. */\n snapshot: (context?: string): Hop =>\n hop(Stage.HANDLED, context, SNAPSHOT_SUBSCRIPTION),\n /** Until the subscription named `processor.function` handled the commit. */\n handled: (subscription: string, context?: string): Hop =>\n hop(Stage.HANDLED, context, subscription),\n} as const;\n\n/**\n * A hop as `Wow-Wait` spells it: `accepted`, `committed`, `snapshot` and\n * `handled(subscription)`, each with its context when it has one:\n * `committed(ctx)`, `snapshot(ctx)`, `handled(ctx/subscription)`.\n *\n * @param value - The hop\n */\nexport function formatHop(value: Hop): string {\n const context = value.context ?? undefined;\n const subscription = value.subscription ?? undefined;\n if (value.stage === Stage.HANDLED) {\n if (subscription === undefined) {\n throw new TypeError('A handled hop names its subscription.');\n }\n if (subscription === SNAPSHOT_SUBSCRIPTION) {\n return context === undefined ? 'snapshot' : `snapshot(${context})`;\n }\n return context === undefined\n ? `handled(${subscription})`\n : `handled(${context}/${subscription})`;\n }\n if (subscription !== undefined) {\n throw new TypeError(`Only a handled hop names a subscription.`);\n }\n const keyword = value.stage.toLowerCase();\n return context === undefined ? keyword : `${keyword}(${context})`;\n}\n\n/**\n * How far a command is waited for, and for how long: the hops, in order, and\n * a timeout in milliseconds. Kotlin's `me.ahoo.wow.api.result.WaitPlan`,\n * with its constants and constructors: {@link WaitPlan.of} the hops a\n * {@link wait} builder makes, {@link WaitPlan.within} another timeout.\n *\n * @example\n * ```typescript\n * const plan = WaitPlan.of(\n * wait.committed(),\n * wait.handled('BasketCheckoutSaga.onBasketCheckedOut', 'eshop-basket'),\n * ).within(30_000);\n * ```\n */\nexport class WaitPlan {\n /** The timeout of a wait whose caller gives none: 10 seconds. */\n static readonly DEFAULT_TIMEOUT = 10_000;\n\n /**\n * The plan of a caller that asked for none: until the snapshot holds the\n * commit, so the caller reads its own write; until `committed` for an\n * aggregate without a snapshot subscription. A request with it sends no\n * `Wow-Wait`, so the service picks.\n */\n static readonly DEFAULT = new WaitPlan([wait.snapshot()], undefined, true);\n\n /**\n * Until the snapshot holds the commit, asked for explicitly: rejected at\n * admission for an aggregate without a snapshot subscription.\n */\n static readonly SNAPSHOT = new WaitPlan([wait.snapshot()]);\n\n /** Until the events are appended. */\n static readonly COMMITTED = new WaitPlan([wait.committed()]);\n\n /** Until the command passed admission. */\n static readonly ACCEPTED = new WaitPlan([wait.accepted()]);\n\n /** Until `hops` are reached, in order. */\n static of(...hops: Hop[]): WaitPlan {\n return new WaitPlan(hops);\n }\n\n /** The hops to reach, in order; at least one. */\n readonly hops: readonly Hop[];\n /** How long to wait, in milliseconds. */\n readonly timeout: number;\n /** Whether this is {@link WaitPlan.DEFAULT}, the service's choice. */\n readonly isDefault: boolean;\n\n private constructor(\n hops: readonly Hop[],\n timeout: number = WaitPlan.DEFAULT_TIMEOUT,\n isDefault = false,\n ) {\n if (hops.length === 0) {\n throw new TypeError('A wait plan has at least one hop.');\n }\n checkTimeout(timeout);\n this.hops = Object.freeze([...hops]);\n this.timeout = timeout;\n this.isDefault = isDefault;\n Object.freeze(this);\n }\n\n /** This plan, waiting `timeout` milliseconds. */\n within(timeout: number): WaitPlan {\n return new WaitPlan(this.hops, timeout, this.isDefault);\n }\n}\n\n/**\n * A wait plan as the `Wow-Wait` header spells it: its hops, in order,\n * separated by `>`; the inverse of {@link parseWaitPlan}.\n *\n * @param plan - The plan\n */\nexport function formatWaitPlan(plan: WaitPlan): string {\n return plan.hops.map(formatHop).join(' > ');\n}\n\nconst HOP = /^([A-Za-z]+)\\s*(?:\\(\\s*([^()]*?)\\s*\\))?$/;\n\n/**\n * The plan a `Wow-Wait` value spells, as the service reads it: hops\n * separated by `>`, each `accepted`, `committed`, `snapshot` or\n * `handled(subscription)`, with its context in parentheses\n * (`committed(ctx)`, `handled(ctx/subscription)`); the inverse of\n * {@link formatWaitPlan}. Throws a `TypeError` for anything else.\n *\n * @param value - The header's value\n */\nexport function parseWaitPlan(value: string): WaitPlan {\n if (value.trim() === '') {\n throw new TypeError('A wait plan has at least one hop.');\n }\n return WaitPlan.of(...value.split('>').map(part => parseHop(part.trim())));\n}\n\n/**\n * The hop one part of a `Wow-Wait` value spells; see {@link parseWaitPlan}.\n *\n * @param value - The part, such as `committed(ctx)`\n */\nexport function parseHop(value: string): Hop {\n const match = HOP.exec(value);\n if (match === null) throw new TypeError(`Not a hop: '${value}'.`);\n const keyword = match[1].toLowerCase();\n const argument = match[2];\n switch (keyword) {\n case 'accepted':\n return wait.accepted(argument);\n case 'committed':\n return wait.committed(argument);\n case 'snapshot':\n return wait.snapshot(argument);\n case 'handled': {\n if (argument === undefined) {\n throw new TypeError(\n `A handled hop names its subscription: '${value}'.`,\n );\n }\n const parts = argument.split('/');\n if (parts.length > 2) {\n throw new TypeError(\n `A handled hop is (subscription) or (context/subscription): '${argument}'.`,\n );\n }\n return parts.length === 1\n ? wait.handled(parts[0])\n : wait.handled(parts[1].trim(), parts[0].trim());\n }\n default:\n throw new TypeError(`Not a stage: '${keyword}'.`);\n }\n}\n\n/**\n * A wait timeout as the `Wow-Wait-Timeout` header spells it: milliseconds\n * as `<n>s` when whole seconds, else `<n>ms`.\n *\n * @param timeout - Milliseconds\n */\nexport function formatWaitTimeout(timeout: number): string {\n checkTimeout(timeout);\n return timeout % 1000 === 0 ? `${timeout / 1000}s` : `${timeout}ms`;\n}\n\nfunction checkTimeout(timeout: number): void {\n if (!Number.isInteger(timeout) || timeout <= 0) {\n throw new TypeError(\n `A wait timeout is a positive whole number of milliseconds: ${timeout}.`,\n );\n }\n}\n"],"mappings":"A,8BAgBA,IAAaE,EAAwB,eAE/BC,EAAO,oBAEb,SAASC,EAAU,EAAc,EAAuB,CACtD,GAAI,CAACD,EAAK,KAAKE,CAAK,EAClB,MAAU,UAAU,SAASC,EAAK,UAAUD,EAAM,GAAG,EAEvD,OAAOA,CACT,CAEA,SAASE,EAAI,EAAc,EAAkB,EAA4B,CACvE,MAAO,CACL,QACA,GAAIC,IAAY,IAAA,GACZ,CAAC,EACD,CAAE,QAASJ,EAAU,UAAWI,CAAO,CAAE,EAC7C,GAAIC,IAAiB,IAAA,GACjB,CAAC,EACD,CAAE,aAAcL,EAAU,eAAgBK,CAAY,CAAE,CAC9D,CACF,CAg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E,CAAC,KAAK,EAAGA,EAAM,EAAE,CAAC,KAAK,CAAC,CACnD,CACA,QACE,MAAU,UAAU,iBAAiBd,EAAQ,GAAG,CACpD,CACF,CAQA,SAAgBe,EAAkB,EAAyB,CAEzD,OADAZ,EAAaC,CAAO,EACbA,EAAU,KAAS,EAAI,GAAGA,EAAU,IAAK,GAAK,GAAGA,EAAQ,GAClE,CAEA,SAASD,EAAa,EAAuB,CAC3C,GAAI,CAAC,OAAO,UAAUC,CAAO,GAAKA,GAAW,EAC3C,MAAU,UACR,8DAA8DA,EAAQ,EACxE,CAEJ,C"}
package/dist/wait.d.cts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Hop } from './wire.cjs';
2
2
  /** The name of the built-in subscription that writes snapshots. */
3
- export declare const SNAPSHOT_SUBSCRIPTION = "snapshot";
3
+ export declare const SNAPSHOT_SUBSCRIPTION = "wow.snapshot";
4
4
  /**
5
5
  * Builds the hops of a wait chain. A context left out is
6
6
  * the command's own. A saga's `handled` hop may be followed by hops of the
package/dist/wait.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Hop } from './wire.js';
2
2
  /** The name of the built-in subscription that writes snapshots. */
3
- export declare const SNAPSHOT_SUBSCRIPTION = "snapshot";
3
+ export declare const SNAPSHOT_SUBSCRIPTION = "wow.snapshot";
4
4
  /**
5
5
  * Builds the hops of a wait chain. A context left out is
6
6
  * the command's own. A saga's `handled` hop may be followed by hops of the
package/dist/wait.es.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Stage as e } from "./wire.es.js";
2
2
  // src/wait.ts
3
- var t = "snapshot", n = /^[A-Za-z0-9_.-]+$/;
3
+ var t = "wow.snapshot", n = /^[A-Za-z0-9_.-]+$/;
4
4
  function r(e, t) {
5
5
  if (!n.test(t)) throw TypeError(`Not a ${e} name: '${t}'.`);
6
6
  return t;
@@ -22,7 +22,7 @@ function o(t) {
22
22
  let n = t.context ?? void 0, r = t.subscription ?? void 0;
23
23
  if (t.stage === e.HANDLED) {
24
24
  if (r === void 0) throw TypeError("A handled hop names its subscription.");
25
- return r === "snapshot" ? n === void 0 ? "snapshot" : `snapshot(${n})` : n === void 0 ? `handled(${r})` : `handled(${n}/${r})`;
25
+ return r === "wow.snapshot" ? n === void 0 ? "snapshot" : `snapshot(${n})` : n === void 0 ? `handled(${r})` : `handled(${n}/${r})`;
26
26
  }
27
27
  if (r !== void 0) throw TypeError("Only a handled hop names a subscription.");
28
28
  let i = t.stage.toLowerCase();
@@ -1 +1 @@
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 = '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 );\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H,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"}
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,EA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js.map CHANGED
@@ -1 +1 @@
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 `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,EAqBaC,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"}
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
@@ -70,7 +70,8 @@ export type Stage = (typeof Stage)[keyof typeof Stage];
70
70
  /**
71
71
  * One hop of a wait chain: a stage, in a context (the
72
72
  * command's own when absent), of a subscription when the stage is
73
- * `handled`. The snapshot is the subscription named `snapshot`.
73
+ * `handled`. The snapshot is the subscription named `wow.snapshot`
74
+ * (`SNAPSHOT_SUBSCRIPTION`), which a `Wow-Wait` header writes `snapshot`.
74
75
  */
75
76
  export interface Hop {
76
77
  /**
package/dist/wire.d.ts CHANGED
@@ -70,7 +70,8 @@ export type Stage = (typeof Stage)[keyof typeof Stage];
70
70
  /**
71
71
  * One hop of a wait chain: a stage, in a context (the
72
72
  * command's own when absent), of a subscription when the stage is
73
- * `handled`. The snapshot is the subscription named `snapshot`.
73
+ * `handled`. The snapshot is the subscription named `wow.snapshot`
74
+ * (`SNAPSHOT_SUBSCRIPTION`), which a `Wow-Wait` header writes `snapshot`.
74
75
  */
75
76
  export interface Hop {
76
77
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"wire.es.js","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 `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,IAAQ;CAEnB,UAAU;CAEV,WAAW;CAEX,SAAS;AACX,GAqBaC,IAAe;CAE1B,SAAS;CAET,SAAS;CAET,OAAO;CAEP,MAAM;CAEN,UAAU;CAEV,aAAa;CAEb,QAAQ;AACV,GAyCaC,IAAsB;CAEjC,WAAW;CAEX,UAAU;CAEV,QAAQ;AACV"}
1
+ {"version":3,"file":"wire.es.js","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,IAAQ;CAEnB,UAAU;CAEV,WAAW;CAEX,SAAS;AACX,GAsBaC,IAAe;CAE1B,SAAS;CAET,SAAS;CAET,OAAO;CAEP,MAAM;CAEN,UAAU;CAEV,aAAa;CAEb,QAAQ;AACV,GAyCaC,IAAsB;CAEjC,WAAW;CAEX,UAAU;CAEV,QAAQ;AACV"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ahoo-wang/wow-client",
3
- "version": "10.0.0-alpha.7",
3
+ "version": "10.0.0-beta.1",
4
4
  "description": "TypeScript client for Wow (https://github.com/Ahoo-Wang/Wow): commands with their waits and event streams, state reads, snapshot, event and dataset queries, the Manifest and RFC 9457 problems, and the query DSL, built on Fetcher.",
5
5
  "keywords": [
6
6
  "wow",