@ahoo-wang/wow-client 10.0.0-beta.3 → 10.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commands.cjs +1 -1
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +15 -3
- package/dist/commands.d.ts +15 -3
- package/dist/commands.es.js +46 -46
- package/dist/commands.es.js.map +1 -1
- package/dist/dsl/aggregation/admit.cjs +1 -1
- package/dist/dsl/aggregation/admit.cjs.map +1 -1
- package/dist/dsl/aggregation/admit.es.js +96 -96
- package/dist/dsl/aggregation/builders.cjs +1 -1
- package/dist/dsl/aggregation/builders.cjs.map +1 -1
- package/dist/dsl/aggregation/builders.es.js +32 -32
- package/dist/dsl/aggregation/derived.cjs +1 -1
- package/dist/dsl/aggregation/derived.cjs.map +1 -1
- package/dist/dsl/aggregation/derived.es.js +11 -11
- package/dist/dsl/aggregation/groups.cjs +1 -1
- package/dist/dsl/aggregation/groups.cjs.map +1 -1
- package/dist/dsl/aggregation/groups.es.js +22 -22
- package/dist/dsl/aggregation/having.cjs +1 -1
- package/dist/dsl/aggregation/having.cjs.map +1 -1
- package/dist/dsl/aggregation/having.es.js +11 -11
- package/dist/dsl/filter/expressionFilter.cjs +1 -1
- package/dist/dsl/filter/expressionFilter.cjs.map +1 -1
- package/dist/dsl/filter/expressionFilter.es.js +7 -7
- package/dist/dsl/filter/fieldFilters.cjs +1 -1
- package/dist/dsl/filter/fieldFilters.cjs.map +1 -1
- package/dist/dsl/filter/fieldFilters.es.js +61 -61
- package/dist/dsl/filter/logicalFilters.cjs +1 -1
- package/dist/dsl/filter/logicalFilters.cjs.map +1 -1
- package/dist/dsl/filter/logicalFilters.es.js +19 -19
- package/dist/dsl/filter/metadataFilters.cjs +1 -1
- package/dist/dsl/filter/metadataFilters.cjs.map +1 -1
- package/dist/dsl/filter/metadataFilters.es.js +31 -31
- package/dist/dsl/filter/scope.cjs +1 -1
- package/dist/dsl/filter/scope.cjs.map +1 -1
- package/dist/dsl/filter/scope.es.js +18 -18
- package/dist/dsl/filter/searchFilter.cjs +1 -1
- package/dist/dsl/filter/searchFilter.cjs.map +1 -1
- package/dist/dsl/filter/searchFilter.es.js +6 -6
- package/dist/dsl/filter/timeFilters.cjs +1 -1
- package/dist/dsl/filter/timeFilters.cjs.map +1 -1
- package/dist/dsl/filter/timeFilters.es.js +47 -47
- package/dist/dsl/filter/validate.cjs +1 -1
- package/dist/dsl/filter/validate.cjs.map +1 -1
- package/dist/dsl/filter/validate.es.js +8 -8
- package/dist/dsl/queryable.cjs +1 -1
- package/dist/dsl/queryable.cjs.map +1 -1
- package/dist/dsl/queryable.es.js +8 -8
- package/dist/dsl.cjs +1 -1
- package/dist/dsl.es.js +12 -12
- package/dist/index.cjs +1 -1
- package/dist/index.es.js +12 -12
- package/dist/manifest.cjs +1 -1
- package/dist/manifest.cjs.map +1 -1
- package/dist/manifest.es.js +11 -11
- package/dist/state.cjs +1 -1
- package/dist/state.cjs.map +1 -1
- package/dist/state.es.js +22 -22
- package/package.json +4 -4
package/dist/manifest.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manifest.cjs","names":["send","WowProblemError","
|
|
1
|
+
{"version":3,"file":"manifest.cjs","names":["send","WowProblemError","require_http","require_problem","MANIFEST_FORMAT","MANIFEST_FEATURES","checkManifest","manifest","unknown","marker","fetchManifest","client","ManifestSource","signal","shared","error","abort","reject","resolve","ownFailure","failed"],"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 { type RequestOptions, send, type WowClientOptions } from './http.js';\nimport { WowProblemError } from './problem.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 const answer = await send(client, {\n method: 'GET',\n path: '/wow/manifest',\n numbers: {},\n options,\n });\n return checkManifest(await answer.json<Manifest>());\n}\n\n/**\n * The Manifest a client routes by (internal): the one it was given, or the\n * service's, read once for every caller and read again by the next caller\n * after a read that failed.\n */\nexport class ManifestSource {\n private manifest: Promise<RoutingManifest> | undefined;\n\n /**\n * @param client - How the service is reached\n * @param manifest - The Manifest given; without it the service's is read\n */\n constructor(\n private readonly client: WowClientOptions,\n manifest?: RoutingManifest,\n ) {\n this.manifest =\n manifest === undefined\n ? undefined\n : Promise.resolve(checkManifest(manifest));\n }\n\n /**\n * The Manifest, for one caller. The read is shared, but each caller's wait\n * is its own: it ends with the caller's `signal`, rejecting with its reason\n * while the read goes on for the others, and a read that fails rejects each\n * caller with an error of its own, so each carries the request id of its\n * own command.\n *\n * @param signal - Cancels this caller's wait\n */\n read(signal?: AbortSignal): Promise<RoutingManifest> {\n if (signal?.aborted) return Promise.reject(signal.reason);\n const shared = (this.manifest ??= fetchManifest(this.client).catch(\n (error: unknown) => {\n this.manifest = undefined;\n throw error;\n },\n ));\n return new Promise((resolve, reject) => {\n const abort = () => reject(signal!.reason);\n signal?.addEventListener('abort', abort, { once: true });\n shared\n .then(resolve, (error: unknown) => reject(ownFailure(error)))\n .finally(() => signal?.removeEventListener('abort', abort));\n });\n }\n}\n\n/**\n * A caller's own error for a shared Manifest read that failed with `error`:\n * the same problem when the service answered one, else an error that names\n * the read, under the name and with the cause of what it failed with.\n */\nfunction ownFailure(error: unknown): Error {\n if (error instanceof WowProblemError) {\n return new WowProblemError(error.problem, {\n cause: error,\n ...(error.retryAfterMs === undefined\n ? {}\n : { retryAfterMs: error.retryAfterMs }),\n });\n }\n // It reads as the read's own error: its name, and its cause where it has\n // one (a fetcher's timeout or abort), so a caller's check written for a\n // request that failed alike (`error.cause?.name === 'FetchTimeoutError'`)\n // holds. `{ cause }` of an `Error` is ES2022; this package targets ES2020.\n const failed = error instanceof Error ? error : undefined;\n return Object.assign(\n new Error(\n `The service's Manifest (GET /wow/manifest) could not be read: ${\n failed?.message ?? String(error)\n }`,\n ),\n {\n name: failed?.name ?? 'Error',\n cause: (failed as { cause?: unknown } | undefined)?.cause ?? error,\n },\n );\n}\n"],"mappings":"A,yDAyDA,IAAaI,EAAkB,EAMlBC,EAAyC,IAAI,IAS1D,SAAgBC,EAAyC,EAAgB,CACvE,GAAIC,EAAS,SAAA,EACX,MAAU,UACR,6BAA6BA,EAAS,OAAO,8BAC/C,EAEF,IAAMC,GAAWD,EAAS,UAAY,CAAC,EAAA,CAAG,OACxC,GAAU,CAACF,EAAkB,IAAII,CAAM,CACzC,EACA,GAAID,EAAQ,OAAS,EACnB,MAAU,UACR,yBAAyBA,EAAQ,KAAK,IAAI,EAAE,4EAC9C,EAEF,OAAOD,CACT,CAQA,eAAsBG,EACpB,EAA2B,CAAC,EAC5B,EACmB,CAOnB,OAAOJ,EAAc,MAAM,MANNN,EAAAA,KAAKW,EAAQ,CAChC,OAAQ,MACR,KAAM,gBACN,QAAS,CAAC,EACV,SACF,CAAC,EAAA,CACiC,KAAe,CAAC,CACpD,CAOA,IAAaC,EAAb,KAA4B,CAO1B,YACE,EACA,EACA,CAFiB,KAAA,OAAAD,EAGjB,KAAK,SACHJ,IAAa,IAAA,GACT,IAAA,GACA,QAAQ,QAAQD,EAAcC,CAAQ,CAAC,CAC/C,CAWA,KAAK,EAAgD,CACnD,GAAIM,GAAQ,QAAS,OAAO,QAAQ,OAAOA,EAAO,MAAM,EACxD,IAAMC,EAAU,KAAK,WAAaJ,EAAc,KAAK,MAAM,CAAC,CAAC,MAC1D,GAAmB,CAElB,KADA,MAAK,SAAW,IAAA,GACVK,CACR,CACF,EACA,OAAO,IAAI,SAAS,EAAS,IAAW,CACtC,IAAMC,MAAcC,EAAOJ,EAAQ,MAAM,EACzCA,GAAQ,iBAAiB,QAASG,EAAO,CAAE,KAAM,EAAK,CAAC,EACvDF,EACG,KAAKI,EAAU,GAAmBD,EAAOE,EAAWJ,CAAK,CAAC,CAAC,CAAC,CAC5D,YAAcF,GAAQ,oBAAoB,QAASG,CAAK,CAAC,CAC9D,CAAC,CACH,CACF,EAOA,SAASG,EAAW,EAAuB,CACzC,GAAIJ,aAAiBd,EAAAA,gBACnB,OAAO,IAAIA,EAAAA,gBAAgBc,EAAM,QAAS,CACxC,MAAOA,EACP,GAAIA,EAAM,eAAiB,IAAA,GACvB,CAAC,EACD,CAAE,aAAcA,EAAM,YAAa,CACzC,CAAC,EAMH,IAAMK,EAASL,aAAiB,MAAQA,EAAQ,IAAA,GAChD,OAAO,OAAO,OACR,MACF,iEACEK,GAAQ,SAAW,OAAOL,CAAK,GAEnC,EACA,CACE,KAAMK,GAAQ,MAAQ,QACtB,MAAQA,GAA4C,OAASL,CAC/D,CACF,CACF,C"}
|
package/dist/manifest.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { send as e } from "./http.es.js";
|
|
2
|
+
import { WowProblemError as t } from "./problem.es.js";
|
|
3
3
|
// src/manifest.ts
|
|
4
4
|
var n = 1, r = /* @__PURE__ */ new Set();
|
|
5
5
|
function i(e) {
|
|
@@ -8,8 +8,8 @@ function i(e) {
|
|
|
8
8
|
if (t.length > 0) throw TypeError(`The Manifest requires ${t.join(", ")}, which this client does not understand: use a newer @ahoo-wang/wow-client.`);
|
|
9
9
|
return e;
|
|
10
10
|
}
|
|
11
|
-
async function a(
|
|
12
|
-
return i(await (await t
|
|
11
|
+
async function a(t = {}, n) {
|
|
12
|
+
return i(await (await e(t, {
|
|
13
13
|
method: "GET",
|
|
14
14
|
path: "/wow/manifest",
|
|
15
15
|
numbers: {},
|
|
@@ -31,15 +31,15 @@ var o = class {
|
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
|
-
function s(
|
|
35
|
-
if (
|
|
36
|
-
cause:
|
|
37
|
-
...
|
|
34
|
+
function s(e) {
|
|
35
|
+
if (e instanceof t) return new t(e.problem, {
|
|
36
|
+
cause: e,
|
|
37
|
+
...e.retryAfterMs === void 0 ? {} : { retryAfterMs: e.retryAfterMs }
|
|
38
38
|
});
|
|
39
|
-
let n =
|
|
40
|
-
return Object.assign(/* @__PURE__ */ Error(`The service's Manifest (GET /wow/manifest) could not be read: ${n?.message ?? String(
|
|
39
|
+
let n = e instanceof Error ? e : void 0;
|
|
40
|
+
return Object.assign(/* @__PURE__ */ Error(`The service's Manifest (GET /wow/manifest) could not be read: ${n?.message ?? String(e)}`), {
|
|
41
41
|
name: n?.name ?? "Error",
|
|
42
|
-
cause: n?.cause ??
|
|
42
|
+
cause: n?.cause ?? e
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
45
|
export { r as MANIFEST_FEATURES, n as MANIFEST_FORMAT, o as ManifestSource, i as checkManifest, a as fetchManifest };
|
package/dist/state.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./
|
|
1
|
+
const e=require("./http.cjs"),t=require("./frameworkErrors.cjs"),n=require("./exactJson.cjs"),r=require("./problem.cjs");var i=class{constructor(e,t={}){this.type=e,this.client=t}read(e,t={}){return this.readAt(e,t)}get(e,t={}){return this.getAt(e,t)}find(e,t={}){return this.findAt(e,t)}trace(e,t={}){return this.traceAt(e,t)}async readAt(t,n){let r=n.at instanceof Date?n.at.toISOString():n.at,i=await e.send(this.client,{method:`GET`,path:this.statePath(t),query:{version:n.version,at:r,minVersion:n.minVersion},headers:{[e.WowHeaders.IF_NONE_MATCH]:n.ifNoneMatch===void 0?void 0:`"${n.ifNoneMatch}"`},numbers:{answer:this.stateNumbers},options:n,notModified:!0}),a=i.response;if(a.status===304){let t=e.entityTag(a)??n.ifNoneMatch??``;return{notModified:!0,version:Number.parseInt(t,10),etag:t}}return{notModified:!1,snapshot:await i.json(),etag:e.entityTag(a)}}async getAt(e,t){let n=await this.readAt(e,t);if(n.notModified)throw Error(`A read without If-None-Match was answered 304.`);return n.snapshot}async findAt(e,n){try{return await this.getAt(e,n)}catch(e){if(e instanceof r.WowProblemError&&e.status===404&&e.code===t.FrameworkErrorCodes.AGGREGATE_NOT_FOUND)return;throw e}}async traceAt(t,n){return(await e.send(this.client,{method:`GET`,path:`${this.statePath(t)}/trace`,query:{from:n.from,to:n.to,limit:n.limit},numbers:{answer:this.traceNumbers},options:n})).json()}get stateNumbers(){return n.recordNumbers({state:this.type.textNumbers?.state,access:this.type.textNumbers?.access})}get traceNumbers(){let e=n.eventNumbers(this.type),t=n.recordNumbers({state:this.type.textNumbers?.state,events:e===void 0?void 0:{"*":e},access:this.type.textNumbers?.access});return t===void 0?void 0:{commits:{"*":t}}}statePath(e){let t=`/${this.type.context}/${this.type.name}`;return e===void 0?`${t}/state`:`${t}/${encodeURIComponent(e)}/state`}},a=class extends i{readOwn(e={}){return this.readAt(void 0,e)}getOwn(e={}){return this.getAt(void 0,e)}findOwn(e={}){return this.findAt(void 0,e)}traceOwn(e={}){return this.traceAt(void 0,e)}};exports.OwnStateClient=a,exports.StateClient=i;
|
|
2
2
|
//# sourceMappingURL=state.cjs.map
|
package/dist/state.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.cjs","names":["send","WowHeaders","entityTag","WowProblemError","FrameworkErrorCodes","recordNumbers","eventNumbers","require_exactJson","require_frameworkErrors","require_problem","require_http","StateClient","type","client","id","options","at","answer","response","etag","result","error","events","commit","base","OwnStateClient"],"sources":["../src/state.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n entityTag,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowHeaders,\n} from './http.js';\nimport { eventNumbers, recordNumbers, type TextNumbers } from './exactJson.js';\nimport { FrameworkErrorCodes, WowProblemError } from './problem.js';\nimport type {\n AccessValues,\n AggregateType,\n CommittedEvent,\n StateTrace,\n Snapshot,\n} from './wire.js';\n\n/** Which state a read asks for: the latest, at a version or as of a time. */\nexport interface StateReadOptions extends RequestOptions {\n /** The committed state at this version. */\n readonly version?: number;\n /** The committed state as of this instant (ISO-8601, or a `Date`). */\n readonly at?: string | Date;\n /**\n * The latest state at this version or later (review R4-Q, Q-13: read your\n * writes), such as the `version` of a command's result: a lagging snapshot is\n * caught up with the log. Not with `version` or `at`. One not reached within\n * the server's wait rejects with 409 `wow.query.min-version-not-reached`,\n * whose `version` is the current one.\n */\n readonly minVersion?: number;\n /**\n * The entity tag of the state already held, as a read answered it\n * (`etag`): a 304 then answers `notModified`. The tag is the version and a\n * digest of the body (`3-<digest>`), so it changes whenever what is read\n * does, not only with the version.\n */\n readonly ifNoneMatch?: string;\n}\n\n/**\n * A state read: the snapshot and its entity tag, or `notModified` when the\n * state held is current, with its tag and the version the tag names.\n */\nexport type StateReadResult<S, A = AccessValues> =\n | {\n readonly notModified: false;\n readonly snapshot: Snapshot<S, A>;\n readonly etag?: string;\n }\n | {\n readonly notModified: true;\n readonly version: number;\n readonly etag: string;\n };\n\n/** Which commits a trace reads. */\nexport interface StateTraceOptions extends RequestOptions {\n /** The first version; 1 when absent. */\n readonly from?: number;\n /** The last version; the latest when absent. */\n readonly to?: number;\n /** The most commits, at most 1000; 100 when absent. */\n readonly limit?: number;\n}\n\n/**\n * Reads an aggregate type's states:\n * `GET /{context}/{aggregate}/{id}/state` with `?version=`, `?at=` or `?minVersion=`, and\n * its trace, `…/state/trace`; {@link OwnStateClient} reads the caller's own\n * of a type whose id is its owner's. A state that does not exist rejects with 404\n * `wow.aggregate.not-found`, except through {@link StateClient.find}, which\n * answers `undefined`.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type of a trace.\n * @typeParam A - The aggregate's access attributes.\n */\nexport class StateClient<\n S = unknown,\n E extends CommittedEvent = CommittedEvent,\n A = AccessValues,\n> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The state the options ask for. */\n read(\n id: string,\n options: StateReadOptions = {},\n ): Promise<StateReadResult<S, A>> {\n return this.readAt(id, options);\n }\n\n /** The latest state, or the one the options ask for, without a cache. */\n get(\n id: string,\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<Snapshot<S, A>> {\n return this.getAt(id, options);\n }\n\n /**\n * The latest state, or the one the options ask for, or `undefined` when the\n * aggregate does not exist (404 `wow.aggregate.not-found`), as Kotlin's\n * `SnapshotQueries.state` answers null. Any other 404, such as a route that\n * does not exist, rejects.\n */\n find(\n id: string,\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<Snapshot<S, A> | undefined> {\n return this.findAt(id, options);\n }\n\n /** The commits from `from` to `to`, each with its events and the state after it. */\n trace(\n id: string,\n options: StateTraceOptions = {},\n ): Promise<StateTrace<S, E, A>> {\n return this.traceAt(id, options);\n }\n\n /**\n * {@link StateClient.read} of the aggregate `id`, or by no id of the\n * caller's own ({@link OwnStateClient}).\n */\n protected async readAt(\n id: string | undefined,\n options: StateReadOptions,\n ): Promise<StateReadResult<S, A>> {\n const at =\n options.at instanceof Date ? options.at.toISOString() : options.at;\n const answer = await send(this.client, {\n method: 'GET',\n path: this.statePath(id),\n query: { version: options.version, at, minVersion: options.minVersion },\n headers: {\n [WowHeaders.IF_NONE_MATCH]:\n options.ifNoneMatch === undefined\n ? undefined\n : `\"${options.ifNoneMatch}\"`,\n },\n numbers: { answer: this.stateNumbers },\n options,\n notModified: true,\n });\n const response = answer.response;\n if (response.status === 304) {\n const etag = entityTag(response) ?? options.ifNoneMatch ?? '';\n return {\n notModified: true,\n version: Number.parseInt(etag, 10),\n etag,\n };\n }\n return {\n notModified: false,\n snapshot: await answer.json<Snapshot<S, A>>(),\n etag: entityTag(response),\n };\n }\n\n /** {@link StateClient.get} of the aggregate `id`, or of the caller's own. */\n protected async getAt(\n id: string | undefined,\n options: Omit<StateReadOptions, 'ifNoneMatch'>,\n ): Promise<Snapshot<S, A>> {\n const result = await this.readAt(id, options);\n if (result.notModified) {\n throw new Error('A read without If-None-Match was answered 304.');\n }\n return result.snapshot;\n }\n\n /** {@link StateClient.find} of the aggregate `id`, or of the caller's own. */\n protected async findAt(\n id: string | undefined,\n options: Omit<StateReadOptions, 'ifNoneMatch'>,\n ): Promise<Snapshot<S, A> | undefined> {\n try {\n return await this.getAt(id, options);\n } catch (error) {\n if (\n error instanceof WowProblemError &&\n error.status === 404 &&\n error.code === FrameworkErrorCodes.AGGREGATE_NOT_FOUND\n ) {\n return undefined;\n }\n throw error;\n }\n }\n\n /** {@link StateClient.trace} of the aggregate `id`, or of the caller's own. */\n protected async traceAt(\n id: string | undefined,\n options: StateTraceOptions,\n ): Promise<StateTrace<S, E, A>> {\n const answer = await send(this.client, {\n method: 'GET',\n path: `${this.statePath(id)}/trace`,\n query: { from: options.from, to: options.to, limit: options.limit },\n numbers: { answer: this.traceNumbers },\n options,\n });\n return answer.json<StateTrace<S, E, A>>();\n }\n\n /** The exact numbers of a state read: its state's and its access attributes'. */\n private get stateNumbers(): TextNumbers | undefined {\n return recordNumbers({\n state: this.type.textNumbers?.state,\n access: this.type.textNumbers?.access,\n });\n }\n\n /** The exact numbers of a trace: each commit's state, events and access attributes. */\n private get traceNumbers(): TextNumbers | undefined {\n const events = eventNumbers(this.type);\n const commit = recordNumbers({\n state: this.type.textNumbers?.state,\n events: events === undefined ? undefined : { '*': events },\n access: this.type.textNumbers?.access,\n });\n return commit === undefined ? undefined : { commits: { '*': commit } };\n }\n\n private statePath(id: string | undefined): string {\n const base = `/${this.type.context}/${this.type.name}`;\n return id === undefined\n ? `${base}/state`\n : `${base}/${encodeURIComponent(id)}/state`;\n }\n}\n\n/**\n * Reads the states of an aggregate type whose id is its owner's\n * (`@AggregateRoot(idSource = OWNER)`, the Manifest's `idSource: \"owner\"`):\n * by id as {@link StateClient} does, for a caller with no owner, and the\n * caller's own by no id, `GET /{context}/{aggregate}/state` and\n * `…/state/trace`, its id the owner the caller reads as. An unauthenticated\n * caller is refused with 401 `wow.auth.unauthenticated`, one with no owner\n * with 400 `wow.query.malformed`.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type of a trace.\n * @typeParam A - The aggregate's access attributes.\n */\nexport class OwnStateClient<\n S = unknown,\n E extends CommittedEvent = CommittedEvent,\n A = AccessValues,\n> extends StateClient<S, E, A> {\n /** {@link StateClient.read} of the caller's own aggregate. */\n readOwn(options: StateReadOptions = {}): Promise<StateReadResult<S, A>> {\n return this.readAt(undefined, options);\n }\n\n /** {@link StateClient.get} of the caller's own aggregate. */\n getOwn(\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<Snapshot<S, A>> {\n return this.getAt(undefined, options);\n }\n\n /**\n * {@link StateClient.find} of the caller's own aggregate: `undefined` until\n * the caller's first command creates it.\n */\n findOwn(\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<Snapshot<S, A> | undefined> {\n return this.findAt(undefined, options);\n }\n\n /** {@link StateClient.trace} of the caller's own aggregate. */\n traceOwn(options: StateTraceOptions = {}): Promise<StateTrace<S, E, A>> {\n return this.traceAt(undefined, options);\n }\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"state.cjs","names":["send","WowHeaders","entityTag","WowProblemError","FrameworkErrorCodes","recordNumbers","eventNumbers","require_http","require_frameworkErrors","require_exactJson","require_problem","StateClient","type","client","id","options","at","answer","response","etag","result","error","events","commit","base","OwnStateClient"],"sources":["../src/state.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n entityTag,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowHeaders,\n} from './http.js';\nimport { eventNumbers, recordNumbers, type TextNumbers } from './exactJson.js';\nimport { FrameworkErrorCodes, WowProblemError } from './problem.js';\nimport type {\n AccessValues,\n AggregateType,\n CommittedEvent,\n StateTrace,\n Snapshot,\n} from './wire.js';\n\n/** Which state a read asks for: the latest, at a version or as of a time. */\nexport interface StateReadOptions extends RequestOptions {\n /** The committed state at this version. */\n readonly version?: number;\n /** The committed state as of this instant (ISO-8601, or a `Date`). */\n readonly at?: string | Date;\n /**\n * The latest state at this version or later (review R4-Q, Q-13: read your\n * writes), such as the `version` of a command's result: a lagging snapshot is\n * caught up with the log. Not with `version` or `at`. One not reached within\n * the server's wait rejects with 409 `wow.query.min-version-not-reached`,\n * whose `version` is the current one.\n */\n readonly minVersion?: number;\n /**\n * The entity tag of the state already held, as a read answered it\n * (`etag`): a 304 then answers `notModified`. The tag is the version and a\n * digest of the body (`3-<digest>`), so it changes whenever what is read\n * does, not only with the version.\n */\n readonly ifNoneMatch?: string;\n}\n\n/**\n * A state read: the snapshot and its entity tag, or `notModified` when the\n * state held is current, with its tag and the version the tag names.\n */\nexport type StateReadResult<S, A = AccessValues> =\n | {\n readonly notModified: false;\n readonly snapshot: Snapshot<S, A>;\n readonly etag?: string;\n }\n | {\n readonly notModified: true;\n readonly version: number;\n readonly etag: string;\n };\n\n/** Which commits a trace reads. */\nexport interface StateTraceOptions extends RequestOptions {\n /** The first version; 1 when absent. */\n readonly from?: number;\n /** The last version; the latest when absent. */\n readonly to?: number;\n /** The most commits, at most 1000; 100 when absent. */\n readonly limit?: number;\n}\n\n/**\n * Reads an aggregate type's states:\n * `GET /{context}/{aggregate}/{id}/state` with `?version=`, `?at=` or `?minVersion=`, and\n * its trace, `…/state/trace`; {@link OwnStateClient} reads the caller's own\n * of a type whose id is its owner's. A state that does not exist rejects with 404\n * `wow.aggregate.not-found`, except through {@link StateClient.find}, which\n * answers `undefined`.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type of a trace.\n * @typeParam A - The aggregate's access attributes.\n */\nexport class StateClient<\n S = unknown,\n E extends CommittedEvent = CommittedEvent,\n A = AccessValues,\n> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The state the options ask for. */\n read(\n id: string,\n options: StateReadOptions = {},\n ): Promise<StateReadResult<S, A>> {\n return this.readAt(id, options);\n }\n\n /** The latest state, or the one the options ask for, without a cache. */\n get(\n id: string,\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<Snapshot<S, A>> {\n return this.getAt(id, options);\n }\n\n /**\n * The latest state, or the one the options ask for, or `undefined` when the\n * aggregate does not exist (404 `wow.aggregate.not-found`), as Kotlin's\n * `SnapshotQueries.state` answers null. Any other 404, such as a route that\n * does not exist, rejects.\n */\n find(\n id: string,\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<Snapshot<S, A> | undefined> {\n return this.findAt(id, options);\n }\n\n /** The commits from `from` to `to`, each with its events and the state after it. */\n trace(\n id: string,\n options: StateTraceOptions = {},\n ): Promise<StateTrace<S, E, A>> {\n return this.traceAt(id, options);\n }\n\n /**\n * {@link StateClient.read} of the aggregate `id`, or by no id of the\n * caller's own ({@link OwnStateClient}).\n */\n protected async readAt(\n id: string | undefined,\n options: StateReadOptions,\n ): Promise<StateReadResult<S, A>> {\n const at =\n options.at instanceof Date ? options.at.toISOString() : options.at;\n const answer = await send(this.client, {\n method: 'GET',\n path: this.statePath(id),\n query: { version: options.version, at, minVersion: options.minVersion },\n headers: {\n [WowHeaders.IF_NONE_MATCH]:\n options.ifNoneMatch === undefined\n ? undefined\n : `\"${options.ifNoneMatch}\"`,\n },\n numbers: { answer: this.stateNumbers },\n options,\n notModified: true,\n });\n const response = answer.response;\n if (response.status === 304) {\n const etag = entityTag(response) ?? options.ifNoneMatch ?? '';\n return {\n notModified: true,\n version: Number.parseInt(etag, 10),\n etag,\n };\n }\n return {\n notModified: false,\n snapshot: await answer.json<Snapshot<S, A>>(),\n etag: entityTag(response),\n };\n }\n\n /** {@link StateClient.get} of the aggregate `id`, or of the caller's own. */\n protected async getAt(\n id: string | undefined,\n options: Omit<StateReadOptions, 'ifNoneMatch'>,\n ): Promise<Snapshot<S, A>> {\n const result = await this.readAt(id, options);\n if (result.notModified) {\n throw new Error('A read without If-None-Match was answered 304.');\n }\n return result.snapshot;\n }\n\n /** {@link StateClient.find} of the aggregate `id`, or of the caller's own. */\n protected async findAt(\n id: string | undefined,\n options: Omit<StateReadOptions, 'ifNoneMatch'>,\n ): Promise<Snapshot<S, A> | undefined> {\n try {\n return await this.getAt(id, options);\n } catch (error) {\n if (\n error instanceof WowProblemError &&\n error.status === 404 &&\n error.code === FrameworkErrorCodes.AGGREGATE_NOT_FOUND\n ) {\n return undefined;\n }\n throw error;\n }\n }\n\n /** {@link StateClient.trace} of the aggregate `id`, or of the caller's own. */\n protected async traceAt(\n id: string | undefined,\n options: StateTraceOptions,\n ): Promise<StateTrace<S, E, A>> {\n const answer = await send(this.client, {\n method: 'GET',\n path: `${this.statePath(id)}/trace`,\n query: { from: options.from, to: options.to, limit: options.limit },\n numbers: { answer: this.traceNumbers },\n options,\n });\n return answer.json<StateTrace<S, E, A>>();\n }\n\n /** The exact numbers of a state read: its state's and its access attributes'. */\n private get stateNumbers(): TextNumbers | undefined {\n return recordNumbers({\n state: this.type.textNumbers?.state,\n access: this.type.textNumbers?.access,\n });\n }\n\n /** The exact numbers of a trace: each commit's state, events and access attributes. */\n private get traceNumbers(): TextNumbers | undefined {\n const events = eventNumbers(this.type);\n const commit = recordNumbers({\n state: this.type.textNumbers?.state,\n events: events === undefined ? undefined : { '*': events },\n access: this.type.textNumbers?.access,\n });\n return commit === undefined ? undefined : { commits: { '*': commit } };\n }\n\n private statePath(id: string | undefined): string {\n const base = `/${this.type.context}/${this.type.name}`;\n return id === undefined\n ? `${base}/state`\n : `${base}/${encodeURIComponent(id)}/state`;\n }\n}\n\n/**\n * Reads the states of an aggregate type whose id is its owner's\n * (`@AggregateRoot(idSource = OWNER)`, the Manifest's `idSource: \"owner\"`):\n * by id as {@link StateClient} does, for a caller with no owner, and the\n * caller's own by no id, `GET /{context}/{aggregate}/state` and\n * `…/state/trace`, its id the owner the caller reads as. An unauthenticated\n * caller is refused with 401 `wow.auth.unauthenticated`, one with no owner\n * with 400 `wow.query.malformed`.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type of a trace.\n * @typeParam A - The aggregate's access attributes.\n */\nexport class OwnStateClient<\n S = unknown,\n E extends CommittedEvent = CommittedEvent,\n A = AccessValues,\n> extends StateClient<S, E, A> {\n /** {@link StateClient.read} of the caller's own aggregate. */\n readOwn(options: StateReadOptions = {}): Promise<StateReadResult<S, A>> {\n return this.readAt(undefined, options);\n }\n\n /** {@link StateClient.get} of the caller's own aggregate. */\n getOwn(\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<Snapshot<S, A>> {\n return this.getAt(undefined, options);\n }\n\n /**\n * {@link StateClient.find} of the caller's own aggregate: `undefined` until\n * the caller's first command creates it.\n */\n findOwn(\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<Snapshot<S, A> | undefined> {\n return this.findAt(undefined, options);\n }\n\n /** {@link StateClient.trace} of the caller's own aggregate. */\n traceOwn(options: StateTraceOptions = {}): Promise<StateTrace<S, E, A>> {\n return this.traceAt(undefined, options);\n }\n}\n"],"mappings":"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"}
|
package/dist/state.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { FrameworkErrorCodes as
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { WowHeaders as e, entityTag as t, send as n } from "./http.es.js";
|
|
2
|
+
import { FrameworkErrorCodes as r } from "./frameworkErrors.es.js";
|
|
3
|
+
import { eventNumbers as i, recordNumbers as a } from "./exactJson.es.js";
|
|
4
|
+
import { WowProblemError as o } from "./problem.es.js";
|
|
5
5
|
// src/state.ts
|
|
6
6
|
var s = class {
|
|
7
7
|
constructor(e, t = {}) {
|
|
@@ -19,22 +19,22 @@ var s = class {
|
|
|
19
19
|
trace(e, t = {}) {
|
|
20
20
|
return this.traceAt(e, t);
|
|
21
21
|
}
|
|
22
|
-
async readAt(
|
|
23
|
-
let
|
|
22
|
+
async readAt(r, i) {
|
|
23
|
+
let a = i.at instanceof Date ? i.at.toISOString() : i.at, o = await n(this.client, {
|
|
24
24
|
method: "GET",
|
|
25
|
-
path: this.statePath(
|
|
25
|
+
path: this.statePath(r),
|
|
26
26
|
query: {
|
|
27
|
-
version:
|
|
28
|
-
at:
|
|
29
|
-
minVersion:
|
|
27
|
+
version: i.version,
|
|
28
|
+
at: a,
|
|
29
|
+
minVersion: i.minVersion
|
|
30
30
|
},
|
|
31
|
-
headers: { [
|
|
31
|
+
headers: { [e.IF_NONE_MATCH]: i.ifNoneMatch === void 0 ? void 0 : `"${i.ifNoneMatch}"` },
|
|
32
32
|
numbers: { answer: this.stateNumbers },
|
|
33
|
-
options:
|
|
33
|
+
options: i,
|
|
34
34
|
notModified: !0
|
|
35
|
-
}), s =
|
|
35
|
+
}), s = o.response;
|
|
36
36
|
if (s.status === 304) {
|
|
37
|
-
let e =
|
|
37
|
+
let e = t(s) ?? i.ifNoneMatch ?? "";
|
|
38
38
|
return {
|
|
39
39
|
notModified: !0,
|
|
40
40
|
version: Number.parseInt(e, 10),
|
|
@@ -43,8 +43,8 @@ var s = class {
|
|
|
43
43
|
}
|
|
44
44
|
return {
|
|
45
45
|
notModified: !1,
|
|
46
|
-
snapshot: await
|
|
47
|
-
etag:
|
|
46
|
+
snapshot: await o.json(),
|
|
47
|
+
etag: t(s)
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
async getAt(e, t) {
|
|
@@ -56,12 +56,12 @@ var s = class {
|
|
|
56
56
|
try {
|
|
57
57
|
return await this.getAt(e, t);
|
|
58
58
|
} catch (e) {
|
|
59
|
-
if (e instanceof
|
|
59
|
+
if (e instanceof o && e.status === 404 && e.code === r.AGGREGATE_NOT_FOUND) return;
|
|
60
60
|
throw e;
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
async traceAt(e, t) {
|
|
64
|
-
return (await
|
|
64
|
+
return (await n(this.client, {
|
|
65
65
|
method: "GET",
|
|
66
66
|
path: `${this.statePath(e)}/trace`,
|
|
67
67
|
query: {
|
|
@@ -74,18 +74,18 @@ var s = class {
|
|
|
74
74
|
})).json();
|
|
75
75
|
}
|
|
76
76
|
get stateNumbers() {
|
|
77
|
-
return
|
|
77
|
+
return a({
|
|
78
78
|
state: this.type.textNumbers?.state,
|
|
79
79
|
access: this.type.textNumbers?.access
|
|
80
80
|
});
|
|
81
81
|
}
|
|
82
82
|
get traceNumbers() {
|
|
83
|
-
let
|
|
83
|
+
let e = i(this.type), t = a({
|
|
84
84
|
state: this.type.textNumbers?.state,
|
|
85
|
-
events:
|
|
85
|
+
events: e === void 0 ? void 0 : { "*": e },
|
|
86
86
|
access: this.type.textNumbers?.access
|
|
87
87
|
});
|
|
88
|
-
return
|
|
88
|
+
return t === void 0 ? void 0 : { commits: { "*": t } };
|
|
89
89
|
}
|
|
90
90
|
statePath(e) {
|
|
91
91
|
let t = `/${this.type.context}/${this.type.name}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahoo-wang/wow-client",
|
|
3
|
-
"version": "10.0.0-beta.
|
|
3
|
+
"version": "10.0.0-beta.4",
|
|
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",
|
|
@@ -94,11 +94,11 @@
|
|
|
94
94
|
"@vitest/coverage-v8": "4.1.12",
|
|
95
95
|
"@vitest/ui": "^4.1.12",
|
|
96
96
|
"eslint": "^10.14.0",
|
|
97
|
-
"globals": "^17.
|
|
97
|
+
"globals": "^17.14.0",
|
|
98
98
|
"typescript": "~6.0.3",
|
|
99
|
-
"typescript-eslint": "^8.72.
|
|
99
|
+
"typescript-eslint": "^8.72.2",
|
|
100
100
|
"unplugin-dts": "1.1.2",
|
|
101
|
-
"vite": "8.3.
|
|
101
|
+
"vite": "8.3.8",
|
|
102
102
|
"vite-bundle-analyzer": "^1.3.9",
|
|
103
103
|
"vitest": "^4.1.12"
|
|
104
104
|
},
|