@ahoo-wang/wow-client 9.9.0 → 10.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dsl/descriptor.cjs.map +1 -1
- package/dist/dsl/descriptor.d.cts +7 -0
- package/dist/dsl/descriptor.d.ts +7 -0
- package/dist/dsl/descriptor.es.js.map +1 -1
- package/dist/v10/commands.cjs +2 -0
- package/dist/v10/commands.cjs.map +1 -0
- package/dist/v10/commands.d.cts +105 -0
- package/dist/v10/commands.d.ts +105 -0
- package/dist/v10/commands.es.js +68 -0
- package/dist/v10/commands.es.js.map +1 -0
- package/dist/v10/http.cjs +2 -0
- package/dist/v10/http.cjs.map +1 -0
- package/dist/v10/http.d.cts +87 -0
- package/dist/v10/http.d.ts +87 -0
- package/dist/v10/http.es.js +73 -0
- package/dist/v10/http.es.js.map +1 -0
- package/dist/v10/index.d.cts +19 -0
- package/dist/v10/index.d.ts +19 -0
- package/dist/v10/manifest.cjs +2 -0
- package/dist/v10/manifest.cjs.map +1 -0
- package/dist/v10/manifest.d.cts +109 -0
- package/dist/v10/manifest.d.ts +109 -0
- package/dist/v10/manifest.es.js +14 -0
- package/dist/v10/manifest.es.js.map +1 -0
- package/dist/v10/problem.cjs +2 -0
- package/dist/v10/problem.cjs.map +1 -0
- package/dist/v10/problem.d.cts +164 -0
- package/dist/v10/problem.d.ts +164 -0
- package/dist/v10/problem.es.js +119 -0
- package/dist/v10/problem.es.js.map +1 -0
- package/dist/v10/queries.cjs +2 -0
- package/dist/v10/queries.cjs.map +1 -0
- package/dist/v10/queries.d.cts +136 -0
- package/dist/v10/queries.d.ts +136 -0
- package/dist/v10/queries.es.js +88 -0
- package/dist/v10/queries.es.js.map +1 -0
- package/dist/v10/state.cjs +2 -0
- package/dist/v10/state.cjs.map +1 -0
- package/dist/v10/state.d.cts +53 -0
- package/dist/v10/state.d.ts +53 -0
- package/dist/v10/state.es.js +51 -0
- package/dist/v10/state.es.js.map +1 -0
- package/dist/v10/streams.cjs +2 -0
- package/dist/v10/streams.cjs.map +1 -0
- package/dist/v10/streams.d.cts +14 -0
- package/dist/v10/streams.d.ts +14 -0
- package/dist/v10/streams.es.js +22 -0
- package/dist/v10/streams.es.js.map +1 -0
- package/dist/v10/wait.cjs +2 -0
- package/dist/v10/wait.cjs.map +1 -0
- package/dist/v10/wait.d.cts +61 -0
- package/dist/v10/wait.d.ts +61 -0
- package/dist/v10/wait.es.js +44 -0
- package/dist/v10/wait.es.js.map +1 -0
- package/dist/v10/wire.cjs +2 -0
- package/dist/v10/wire.cjs.map +1 -0
- package/dist/v10/wire.d.cts +301 -0
- package/dist/v10/wire.d.ts +301 -0
- package/dist/v10/wire.es.js +10 -0
- package/dist/v10/wire.es.js.map +1 -0
- package/dist/v10.cjs +1 -0
- package/dist/v10.es.js +9 -0
- package/package.json +11 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem.es.js","names":["FrameworkErrorCodes","FRAMEWORK_ERROR_PREFIX","PROBLEM_TYPE_PREFIX","PROBLEM_MEMBERS","withExtensions","problem","extensions","name","RETRYABLE","retryHintOf","sameRequestId","code","retryable","status","afterMs","WowProblemError","options","isProblem","value","parseRetryAfter","trimmed","date","now","readProblem","body","response","toWowProblemError","error","cause","exchange","retryAfterMs"],"sources":["../../src/v10/problem.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 { CommandResult, Violation } from './wire.js';\n\n/**\n * The framework's error codes (design 05 §3, decisions D102, D103, D130),\n * each answered with the status of the Manifest's `errors` table. A domain\n * rejection has a code of its own, answered with 422 unless the service\n * configures another status.\n */\nexport const FrameworkErrorCodes = {\n /** 401: the request carries no valid credentials. */\n AUTH_UNAUTHENTICATED: 'wow.auth.unauthenticated',\n /** 403: the caller may not send this command. */\n AUTH_FORBIDDEN: 'wow.auth.forbidden',\n /** 403: the aggregate is outside the caller's scope. */\n AGGREGATE_FORBIDDEN: 'wow.aggregate.forbidden',\n /** 400: the command body cannot be read as the command type. */\n COMMAND_MALFORMED: 'wow.command.malformed',\n /** 400: the command failed validation; the problem lists the violations. */\n COMMAND_INVALID: 'wow.command.invalid',\n /** 400: the wait is not a chain the runtime can follow. */\n WAIT_INVALID: 'wow.wait.invalid',\n /** 400: the aggregate does not handle this command. */\n COMMAND_UNHANDLED: 'wow.command.unhandled',\n /** 404: the aggregate does not exist. */\n AGGREGATE_NOT_FOUND: 'wow.aggregate.not-found',\n /** 409: the aggregate already exists. */\n AGGREGATE_EXISTS: 'wow.aggregate.exists',\n /** 409, or 412 with `If-Match`: the aggregate is not at the expected version. */\n AGGREGATE_VERSION_MISMATCH: 'wow.aggregate.version-mismatch',\n /** 409: the request id was used by another command. */\n COMMAND_REQUEST_ID_REUSED: 'wow.command.request-id-reused',\n /** 409: concurrent writers kept winning; retrying with the same request id is safe. */\n COMMAND_CONTENDED: 'wow.command.contended',\n /** 410: the aggregate is deleted; only RestoreAggregate applies. */\n AGGREGATE_DELETED: 'wow.aggregate.deleted',\n /** 429: the node has too many commands in flight; retry later. */\n COMMAND_BUSY: 'wow.command.busy',\n /** 503: whether the command committed is unknown; retrying with the same request id is safe. */\n COMMAND_UNKNOWN: 'wow.command.unknown',\n /** 503: the node is shutting down; retry on another node. */\n NODE_CLOSING: 'wow.node.closing',\n /** 503, with `Retry-After`: a store could not be reached in time; retry later. */\n STORAGE_UNAVAILABLE: 'wow.storage.unavailable',\n /** 503: a scheduled command arrived too long before its due time; it is sent again later. */\n SCHEDULE_NOT_DUE: 'wow.schedule.not-due',\n /** 400: the job command does not fit its job or instance (decision D198). */\n SCHEDULE_JOB_INVALID: 'wow.schedule.job-invalid',\n /** 500: a subscription on the wait chain parked the aggregate. */\n SUBSCRIPTION_PARKED: 'wow.subscription.parked',\n /** 504: the wait ran out of time; the command may have committed. */\n WAIT_TIMEOUT: 'wow.wait.timeout',\n /** 400: the query body cannot be read as a query. */\n QUERY_MALFORMED: 'wow.query.malformed',\n /** 400: the query failed admission; each violation has its code. */\n QUERY_INVALID: 'wow.query.invalid',\n /** 500: the query backend failed to run the query. */\n QUERY_FAILED: 'wow.query.failed',\n /** 503: the query ran longer than its budget allows. */\n QUERY_TIMEOUT: 'wow.query.timeout',\n} as const;\n\n/** A {@link FrameworkErrorCodes} value. */\nexport type FrameworkErrorCode =\n (typeof FrameworkErrorCodes)[keyof typeof FrameworkErrorCodes];\n\n/** The prefix of every framework code, and of no domain code. */\nexport const FRAMEWORK_ERROR_PREFIX = 'wow.';\n\n/** The prefix of a problem's `type` that carries a Wow code. */\nexport const PROBLEM_TYPE_PREFIX = 'urn:wow:error:';\n\n/**\n * An RFC 9457 problem as a Wow V10 service writes it (decisions D101, D102):\n * `type` is `urn:wow:error:<code>`, or `about:blank` for an error that is\n * only HTTP's (a missing route, 406, 415).\n */\nexport interface Problem {\n readonly type: string;\n readonly title: string;\n readonly status: number;\n readonly detail?: string;\n /** The Wow code; absent for an error that is only HTTP's. */\n readonly code?: string;\n readonly violations?: readonly Violation[];\n /** The whole result of a command that has a ref. */\n readonly result?: CommandResult;\n /**\n * The problem's extension members (RFC 9457): every member the server\n * wrote besides the ones above and `instance`, such as a rejection's\n * structured data (decision D211). Absent when it wrote none.\n */\n readonly extensions?: Readonly<Record<string, unknown>>;\n}\n\n/** The members of a problem that are not extension members. */\nconst PROBLEM_MEMBERS: ReadonlySet<string> = new Set([\n 'type',\n 'title',\n 'status',\n 'detail',\n 'instance',\n 'code',\n 'violations',\n 'result',\n 'extensions',\n]);\n\n/**\n * `problem` with its extension members gathered as `extensions` (internal):\n * a problem read from the wire carries them as top-level members.\n */\nfunction withExtensions(problem: Problem): Problem {\n if (problem.extensions !== undefined) return problem;\n const extensions = Object.fromEntries(\n Object.entries(problem).filter(([name]) => !PROBLEM_MEMBERS.has(name)),\n );\n return Object.keys(extensions).length === 0\n ? problem\n : { ...problem, extensions };\n}\n\n/**\n * What a client may do about a failed request: whether retrying can succeed,\n * whether to keep the request id (`Wow-Request-Id`) so the server\n * deduplicates a command that did commit, and how long to wait first.\n */\nexport interface RetryHint {\n readonly retryable: boolean;\n /** Retry with the same `Wow-Request-Id`: a commit is then answered as a duplicate. */\n readonly sameRequestId: boolean;\n /** The server's `Retry-After`, in milliseconds. */\n readonly afterMs?: number;\n}\n\n/**\n * The codes a retry may get past, each with whether to keep the request id:\n * the 503s (`wow.command.unknown`, `wow.node.closing`,\n * `wow.storage.unavailable`, `wow.schedule.not-due`, `wow.query.timeout`),\n * the 429 `wow.command.busy`, the 409 `wow.command.contended` and the 504\n * `wow.wait.timeout`, whose command may have committed.\n */\nconst RETRYABLE: ReadonlyMap<string, boolean> = new Map([\n [FrameworkErrorCodes.COMMAND_UNKNOWN, true],\n [FrameworkErrorCodes.NODE_CLOSING, true],\n [FrameworkErrorCodes.STORAGE_UNAVAILABLE, true],\n [FrameworkErrorCodes.SCHEDULE_NOT_DUE, true],\n [FrameworkErrorCodes.QUERY_TIMEOUT, false],\n [FrameworkErrorCodes.COMMAND_BUSY, true],\n [FrameworkErrorCodes.COMMAND_CONTENDED, true],\n [FrameworkErrorCodes.WAIT_TIMEOUT, true],\n]);\n\n/**\n * The retry hint of a problem with `code` and `status`: a code of the\n * retryable table, or a 503 without a code (a proxy's), may be retried.\n *\n * @param code - The problem's Wow code, if any\n * @param status - The HTTP status\n * @param afterMs - The `Retry-After` the response carried, in milliseconds\n */\nexport function retryHintOf(\n code: string | undefined,\n status: number,\n afterMs?: number,\n): RetryHint {\n const sameRequestId = code === undefined ? undefined : RETRYABLE.get(code);\n const retryable =\n sameRequestId !== undefined || (code === undefined && status === 503);\n return {\n retryable,\n sameRequestId: sameRequestId ?? retryable,\n ...(afterMs === undefined ? {} : { afterMs }),\n };\n}\n\n/**\n * A request a Wow V10 service answered with a problem: a non-2xx response, a\n * command result that did not succeed, or the `error` event that ends a\n * streamed query.\n */\nexport class WowProblemError extends Error {\n override readonly name = 'WowProblemError';\n /** The problem as the server wrote it. */\n readonly problem: Problem;\n /** The HTTP status. */\n readonly status: number;\n /** The Wow code; absent for an error that is only HTTP's. */\n readonly code?: string;\n readonly violations: readonly Violation[];\n /** The command's result, when the command had a ref. */\n readonly result?: CommandResult;\n /** What a client may do about it. */\n readonly retry: RetryHint;\n /** The error this one explains: the fetcher's, or the stream's. */\n readonly cause?: unknown;\n\n /**\n * @param problem - The problem the server answered with\n * @param options - The response's `Retry-After` in milliseconds, and the\n * error this one explains\n */\n constructor(\n problem: Problem,\n options: { retryAfterMs?: number; cause?: unknown } = {},\n ) {\n super(\n problem.code\n ? `[${problem.code}] ${problem.detail ?? problem.title}`\n : `${problem.status} ${problem.detail ?? problem.title}`,\n );\n this.problem = withExtensions(problem);\n this.status = problem.status;\n if (problem.code !== undefined) this.code = problem.code;\n this.violations = problem.violations ?? [];\n if (problem.result !== undefined) this.result = problem.result;\n this.retry = retryHintOf(\n problem.code,\n problem.status,\n options.retryAfterMs,\n );\n if (options.cause !== undefined) this.cause = options.cause;\n }\n\n /** Whether the code is a framework one (`wow.*`) rather than the domain's. */\n get isFramework(): boolean {\n return this.code?.startsWith(FRAMEWORK_ERROR_PREFIX) ?? false;\n }\n}\n\n/** Whether `value` reads as a problem: an object with a numeric `status`. */\nexport function isProblem(value: unknown): value is Problem {\n return (\n typeof value === 'object' &&\n value !== null &&\n typeof (value as { status?: unknown }).status === 'number'\n );\n}\n\n/**\n * The milliseconds of a `Retry-After` header: delay seconds or an HTTP date.\n *\n * @param value - The header's value\n * @param now - The current time, in epoch milliseconds\n */\nexport function parseRetryAfter(\n value: string | null | undefined,\n now: number = Date.now(),\n): number | undefined {\n if (!value) return undefined;\n const trimmed = value.trim();\n if (/^\\d+$/.test(trimmed)) return Number(trimmed) * 1000;\n const date = Date.parse(trimmed);\n return Number.isNaN(date) ? undefined : Math.max(0, date - now);\n}\n\n/**\n * The problem a response that did not succeed carries: its body when it is\n * a problem (or a code the `type` names), else one made of its status.\n *\n * @param response - A response that is not 2xx\n */\nexport async function readProblem(response: Response): Promise<Problem> {\n let body: unknown;\n try {\n body = await response.clone().json();\n } catch {\n // Not JSON, or already read: the status is all there is.\n }\n if (isProblem(body)) {\n const code =\n body.code ??\n (body.type?.startsWith(PROBLEM_TYPE_PREFIX)\n ? body.type.slice(PROBLEM_TYPE_PREFIX.length)\n : undefined);\n return withExtensions({\n ...body,\n type: body.type ?? 'about:blank',\n title: body.title ?? response.statusText,\n ...(code === undefined ? {} : { code }),\n });\n }\n return {\n type: 'about:blank',\n title: response.statusText,\n status: response.status,\n };\n}\n\ninterface ExchangeLike {\n exchange?: { response?: Response };\n cause?: unknown;\n}\n\n/**\n * The {@link WowProblemError} of an error a request rejected with: the\n * fetcher's `ExchangeError` of a response that is not 2xx, read as a problem.\n * Undefined for a failure no server answered (a network error, an abort).\n *\n * @param error - What the request rejected with\n */\nexport async function toWowProblemError(\n error: unknown,\n): Promise<WowProblemError | undefined> {\n if (error instanceof WowProblemError) return error;\n if (typeof error !== 'object' || error === null) return undefined;\n const { exchange, cause } = error as ExchangeLike;\n if (cause instanceof WowProblemError) return cause;\n const response = exchange?.response;\n if (!response || response.ok) return undefined;\n const problem = await readProblem(response);\n const retryAfterMs = parseRetryAfter(response.headers.get('Retry-After'));\n return new WowProblemError(problem, {\n cause: error,\n ...(retryAfterMs === undefined ? {} : { retryAfterMs }),\n });\n}\n"],"mappings":";AAqBA,IAAaA,IAAsB;CAEjC,sBAAsB;CAEtB,gBAAgB;CAEhB,qBAAqB;CAErB,mBAAmB;CAEnB,iBAAiB;CAEjB,cAAc;CAEd,mBAAmB;CAEn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BAA8B,IACtCA,EAAK,KAAK,MAAM,EAA0B,IAC1C,KAAA;EACN,OAAOpB,EAAe;GACpB,GAAGoB;GACH,MAAMA,EAAK,QAAQ;GACnB,OAAOA,EAAK,SAASC,EAAS;GAC9B,GAAId,MAAS,KAAA,IAAY,CAAC,IAAI,EAAE,QAAK;EACvC,CAAC;CACH;CACA,OAAO;EACL,MAAM;EACN,OAAOc,EAAS;EAChB,QAAQA,EAAS;CACnB;AACF;AAcA,eAAsBC,EACpB,GACsC;CACtC,IAAIC,aAAiBZ,GAAiB,OAAOY;CAC7C,IAAI,OAAOA,KAAU,aAAYA,GAAgB;CACjD,IAAM,EAAE,aAAU,aAAUA;CAC5B,IAAIC,aAAiBb,GAAiB,OAAOa;CAC7C,IAAMH,IAAWI,GAAU;CAC3B,IAAI,CAACJ,KAAYA,EAAS,IAAI;CAC9B,IAAMpB,IAAU,MAAMkB,EAAYE,CAAQ,GACpCK,IAAeX,EAAgBM,EAAS,QAAQ,IAAI,aAAa,CAAC;CACxE,OAAO,IAAIV,EAAgBV,GAAS;EAClC,OAAOsB;EACP,GAAIG,MAAiB,KAAA,IAAY,CAAC,IAAI,EAAE,gBAAa;CACvD,CAAC;AACH"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./http.cjs"),t=require("./streams.cjs");var n=class{constructor(e,t={}){this.path=e,this.client=t}async list(t,n){return e.json(await this.post(`list`,t,n))}async listStream(e,n){return t.queryRows(await this.post(`list`,e,n,`text/event-stream`))}async paged(t,n){return e.json(await this.post(`paged`,t,n))}async cursor(t,n){return e.json(await this.post(`cursor`,t,n))}async single(t,n){return e.json(await this.post(`single`,t,n))}async count(t,n){return e.json(await this.post(`count`,t,n))}async aggregate(t,n){return e.json(await this.post(`aggregate`,t,n))}async describe(t,n){let r=await e.send(this.client,{method:`GET`,path:this.path,headers:{[e.WowV10Headers.IF_NONE_MATCH]:t===void 0?void 0:`"${t}"`},options:n,notModified:!0}),i=e.entityTag(r);return r.status===304?{notModified:!0,version:i??t??``}:{notModified:!1,...i===void 0?{}:{version:i},descriptor:await e.json(r)}}post(t,n,r,i){return e.send(this.client,{method:`POST`,path:this.path,headers:{Accept:i},body:{...n,kind:t},options:r})}};function r(e,t){return`/${e.context}/${e.name}/${t}/query`}var i=class extends n{constructor(e,t){super(r(e,`snapshot`),t),this.type=e}},a=class extends n{constructor(e,t){super(r(e,`events`),t),this.type=e}},o=class{constructor(e={}){this.client=e}async list(t){return e.json(await e.send(this.client,{method:`GET`,path:`/wow/dataset`,options:t}))}dataset(e,t){return new n(`/wow/dataset/${encodeURIComponent(e)}/${encodeURIComponent(t)}/query`,this.client)}};exports.DatasetClient=o,exports.EventQueryClient=a,exports.QueryModelClient=n,exports.SnapshotQueryClient=i,exports.queryPath=r;
|
|
2
|
+
//# sourceMappingURL=queries.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.cjs","names":["json","queryRows","send","WowV10Headers","entityTag","require_http","require_streams","QueryModelClient","path","client","query","options","response","version","tag","accept","queryPath","type","model","SnapshotQueryClient","EventQueryClient","DatasetClient","context","dataset"],"sources":["../../src/v10/queries.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AggregationQuery } from '../dsl/aggregation/index.js';\nimport type { CursorPage, CursorQuery } from '../dsl/cursorQuery.js';\nimport type { QueryModelDescriptor } from '../dsl/descriptor.js';\nimport type { FilterCapable } from '../dsl/filter/index.js';\nimport type {\n FilterListQuery,\n FilterPagedQuery,\n FilterSingleQuery,\n} from '../dsl/queryable.js';\nimport {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowV10Headers,\n} from './http.js';\nimport type {\n AggregateType,\n DatasetEntry,\n EventStreamField,\n EventStreamRecord,\n EventView,\n SnapshotRecord,\n SnapshotSystemField,\n} from './wire.js';\nimport { queryRows } from './streams.js';\n\n/** How a paged query counts its total (`TotalMode`, decision D150). */\nexport type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';\n\n/** A paged query of a V10 query route: a page, and how its total is counted. */\nexport interface PagedQuery<\n FIELDS extends string = string,\n> extends FilterPagedQuery<FIELDS> {\n /** `BOUNDED` (the server's default) counts up to the budget's limit. */\n total?: TotalMode;\n}\n\n/** A count of a V10 query route (decision D150). */\nexport interface CountQuery<\n FIELDS extends string = string,\n> extends FilterCapable<FIELDS> {\n /** The most matches to count; the budget's default when absent. */\n limit?: number;\n}\n\n/** What a count answers: exact below its limit, else the limit itself. */\nexport interface CountResult {\n readonly count: number;\n readonly exact: boolean;\n}\n\n/**\n * A page of a paged query: `total` is exact when `exact`, a lower bound\n * otherwise, and null for `TotalMode.NONE`.\n */\nexport interface PagedResult<T> {\n readonly total: number | null;\n readonly exact: boolean;\n readonly list: readonly T[];\n}\n\n/**\n * A query model's capability descriptor and its version, the `ETag` of\n * `GET …/query`; `notModified` when the version given is still current.\n */\nexport type DescriptorResult =\n | {\n readonly notModified: false;\n readonly version?: string;\n readonly descriptor: QueryModelDescriptor;\n }\n | { readonly notModified: true; readonly version: string };\n\n/**\n * Queries one query model of a Wow V10 service: `POST {path}` with a body\n * whose `kind` names the operation, `GET {path}` for the capability\n * descriptor (decisions D127, D145).\n *\n * @typeParam R - The record's type.\n * @typeParam FIELDS - The field paths a filter, sort or projection takes.\n */\nexport class QueryModelClient<R, FIELDS extends string = string> {\n /**\n * @param path - The query route, `/{context}/{aggregate}/{model}/query`\n * @param client - How the service is reached\n */\n constructor(\n readonly path: string,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The records that match, at most `limit` (the server's default when absent). */\n async list(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R[]> {\n return json<R[]>(await this.post('list', query, options));\n }\n\n /**\n * The records that match, as server-sent events read one at a time; a\n * failure after the first record errors the stream with its problem.\n */\n async listStream(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<ReadableStream<R>> {\n return queryRows<R>(\n await this.post('list', query, options, 'text/event-stream'),\n );\n }\n\n /** One page of the records that match, and their total. */\n async paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<PagedResult<R>> {\n return json<PagedResult<R>>(await this.post('paged', query, options));\n }\n\n /** One page of a forward-only cursor over the records that match. */\n async cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CursorPage<R>> {\n return json<CursorPage<R>>(await this.post('cursor', query, options));\n }\n\n /** The first record that matches; rejects with 404 when none does. */\n async single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R> {\n return json<R>(await this.post('single', query, options));\n }\n\n /** How many records match, bounded by the count's limit. */\n async count(\n query: CountQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CountResult> {\n return json<CountResult>(await this.post('count', query, options));\n }\n\n /** The groups and metrics of an aggregation, one row per group. */\n async aggregate<ROW = Record<string, unknown>>(\n query: AggregationQuery<FIELDS, string>,\n options?: RequestOptions,\n ): Promise<ROW[]> {\n return json<ROW[]>(await this.post('aggregate', query, options));\n }\n\n /**\n * The model's capability descriptor; with the `version` already held, a\n * 304 answers `notModified`.\n */\n async describe(\n version?: string,\n options?: RequestOptions,\n ): Promise<DescriptorResult> {\n const response = await send(this.client, {\n method: 'GET',\n path: this.path,\n headers: {\n [WowV10Headers.IF_NONE_MATCH]:\n version === undefined ? undefined : `\"${version}\"`,\n },\n options,\n notModified: true,\n });\n const tag = entityTag(response);\n if (response.status === 304) {\n return { notModified: true, version: tag ?? version ?? '' };\n }\n return {\n notModified: false,\n ...(tag === undefined ? {} : { version: tag }),\n descriptor: await json<QueryModelDescriptor>(response),\n };\n }\n\n private post(\n kind: string,\n query: object,\n options?: RequestOptions,\n accept?: string,\n ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: this.path,\n headers: { Accept: accept },\n body: { ...query, kind },\n options,\n });\n }\n}\n\n/** The query route of a model of an aggregate type. */\nexport function queryPath(type: AggregateType, model: string): string {\n return `/${type.context}/${type.name}/${model}/query`;\n}\n\n/**\n * Queries an aggregate type's snapshots (decision D128), the default read\n * model; only where the aggregate keeps them.\n *\n * @typeParam S - The state's type.\n * @typeParam STATE_FIELDS - The `state.*` paths of the state.\n */\nexport class SnapshotQueryClient<\n S = unknown,\n STATE_FIELDS extends string = `state.${string}`,\n> extends QueryModelClient<\n SnapshotRecord<S>,\n SnapshotSystemField | STATE_FIELDS\n> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n super(queryPath(type, 'snapshot'), client);\n }\n}\n\n/**\n * Queries an aggregate type's event streams (decision D131), one aggregate\n * at a time: a filter names its `aggregateId`, and may bound `version` or\n * `commitTime`.\n *\n * @typeParam E - The events' type.\n */\nexport class EventQueryClient<\n E extends EventView = EventView,\n> extends QueryModelClient<EventStreamRecord<E>, EventStreamField> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n super(queryPath(type, 'events'), client);\n }\n}\n\n/**\n * The datasets of a Wow V10 service (decisions D75, D145): registered at run\n * time, so not in the Manifest. Lists those the caller sees and queries\n * each as a snapshot model is queried.\n */\nexport class DatasetClient {\n /** @param client - How the service is reached */\n constructor(readonly client: WowClientOptions = {}) {}\n\n /** The datasets the caller sees, by name. */\n async list(options?: RequestOptions): Promise<DatasetEntry[]> {\n return json<DatasetEntry[]>(\n await send(this.client, { method: 'GET', path: '/wow/dataset', options }),\n );\n }\n\n /**\n * The query client of the dataset `context.dataset`.\n *\n * @typeParam R - The row's type.\n * @typeParam FIELDS - The dataset's field paths.\n */\n dataset<R = Record<string, unknown>, FIELDS extends string = string>(\n context: string,\n dataset: string,\n ): QueryModelClient<R, FIELDS> {\n return new QueryModelClient<R, FIELDS>(\n `/wow/dataset/${encodeURIComponent(context)}/${encodeURIComponent(dataset)}/query`,\n this.client,\n );\n }\n}\n"],"mappings":"yDAgGA,IAAaO,EAAb,KAAiE,CAK/D,YACE,EACA,EAAoC,CAAC,EACrC,CAFS,KAAA,KAAAC,EACA,KAAA,OAAAC,CACR,CAGH,MAAM,KACJ,EACA,EACc,CACd,OAAOT,EAAAA,KAAU,MAAM,KAAK,KAAK,OAAQU,EAAOC,CAAO,CAAC,CAC1D,CAMA,MAAM,WACJ,EACA,EAC4B,CAC5B,OAAOV,EAAAA,UACL,MAAM,KAAK,KAAK,OAAQS,EAAOC,EAAS,mBAAmB,CAC7D,CACF,CAGA,MAAM,MACJ,EACA,EACyB,CACzB,OAAOX,EAAAA,KAAqB,MAAM,KAAK,KAAK,QAASU,EAAOC,CAAO,CAAC,CACtE,CAGA,MAAM,OACJ,EACA,EACwB,CACxB,OAAOX,EAAAA,KAAoB,MAAM,KAAK,KAAK,SAAUU,EAAOC,CAAO,CAAC,CACtE,CAGA,MAAM,OACJ,EACA,EACY,CACZ,OAAOX,EAAAA,KAAQ,MAAM,KAAK,KAAK,SAAUU,EAAOC,CAAO,CAAC,CAC1D,CAGA,MAAM,MACJ,EACA,EACsB,CACtB,OAAOX,EAAAA,KAAkB,MAAM,KAAK,KAAK,QAASU,EAAOC,CAAO,CAAC,CACnE,CAGA,MAAM,UACJ,EACA,EACgB,CAChB,OAAOX,EAAAA,KAAY,MAAM,KAAK,KAAK,YAAaU,EAAOC,CAAO,CAAC,CACjE,CAMA,MAAM,SACJ,EACA,EAC2B,CAC3B,IAAMC,EAAW,MAAMV,EAAAA,KAAK,KAAK,OAAQ,CACvC,OAAQ,MACR,KA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,mBAAmBC,CAAO,EAAE,QAC3E,KAAK,MACP,CACF,CACF"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { AggregationQuery } from '../dsl/aggregation/index.cjs';
|
|
2
|
+
import { CursorPage, CursorQuery } from '../dsl/cursorQuery.cjs';
|
|
3
|
+
import { QueryModelDescriptor } from '../dsl/descriptor.cjs';
|
|
4
|
+
import { FilterCapable } from '../dsl/filter/index.cjs';
|
|
5
|
+
import { FilterListQuery, FilterPagedQuery, FilterSingleQuery } from '../dsl/queryable.cjs';
|
|
6
|
+
import { RequestOptions, WowClientOptions } from './http.cjs';
|
|
7
|
+
import { AggregateType, DatasetEntry, EventStreamField, EventStreamRecord, EventView, SnapshotRecord, SnapshotSystemField } from './wire.cjs';
|
|
8
|
+
/** How a paged query counts its total (`TotalMode`, decision D150). */
|
|
9
|
+
export type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';
|
|
10
|
+
/** A paged query of a V10 query route: a page, and how its total is counted. */
|
|
11
|
+
export interface PagedQuery<FIELDS extends string = string> extends FilterPagedQuery<FIELDS> {
|
|
12
|
+
/** `BOUNDED` (the server's default) counts up to the budget's limit. */
|
|
13
|
+
total?: TotalMode;
|
|
14
|
+
}
|
|
15
|
+
/** A count of a V10 query route (decision D150). */
|
|
16
|
+
export interface CountQuery<FIELDS extends string = string> extends FilterCapable<FIELDS> {
|
|
17
|
+
/** The most matches to count; the budget's default when absent. */
|
|
18
|
+
limit?: number;
|
|
19
|
+
}
|
|
20
|
+
/** What a count answers: exact below its limit, else the limit itself. */
|
|
21
|
+
export interface CountResult {
|
|
22
|
+
readonly count: number;
|
|
23
|
+
readonly exact: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A page of a paged query: `total` is exact when `exact`, a lower bound
|
|
27
|
+
* otherwise, and null for `TotalMode.NONE`.
|
|
28
|
+
*/
|
|
29
|
+
export interface PagedResult<T> {
|
|
30
|
+
readonly total: number | null;
|
|
31
|
+
readonly exact: boolean;
|
|
32
|
+
readonly list: readonly T[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A query model's capability descriptor and its version, the `ETag` of
|
|
36
|
+
* `GET …/query`; `notModified` when the version given is still current.
|
|
37
|
+
*/
|
|
38
|
+
export type DescriptorResult = {
|
|
39
|
+
readonly notModified: false;
|
|
40
|
+
readonly version?: string;
|
|
41
|
+
readonly descriptor: QueryModelDescriptor;
|
|
42
|
+
} | {
|
|
43
|
+
readonly notModified: true;
|
|
44
|
+
readonly version: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Queries one query model of a Wow V10 service: `POST {path}` with a body
|
|
48
|
+
* whose `kind` names the operation, `GET {path}` for the capability
|
|
49
|
+
* descriptor (decisions D127, D145).
|
|
50
|
+
*
|
|
51
|
+
* @typeParam R - The record's type.
|
|
52
|
+
* @typeParam FIELDS - The field paths a filter, sort or projection takes.
|
|
53
|
+
*/
|
|
54
|
+
export declare class QueryModelClient<R, FIELDS extends string = string> {
|
|
55
|
+
readonly path: string;
|
|
56
|
+
readonly client: WowClientOptions;
|
|
57
|
+
/**
|
|
58
|
+
* @param path - The query route, `/{context}/{aggregate}/{model}/query`
|
|
59
|
+
* @param client - How the service is reached
|
|
60
|
+
*/
|
|
61
|
+
constructor(path: string, client?: WowClientOptions);
|
|
62
|
+
/** The records that match, at most `limit` (the server's default when absent). */
|
|
63
|
+
list(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<R[]>;
|
|
64
|
+
/**
|
|
65
|
+
* The records that match, as server-sent events read one at a time; a
|
|
66
|
+
* failure after the first record errors the stream with its problem.
|
|
67
|
+
*/
|
|
68
|
+
listStream(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<ReadableStream<R>>;
|
|
69
|
+
/** One page of the records that match, and their total. */
|
|
70
|
+
paged(query: PagedQuery<FIELDS>, options?: RequestOptions): Promise<PagedResult<R>>;
|
|
71
|
+
/** One page of a forward-only cursor over the records that match. */
|
|
72
|
+
cursor(query: CursorQuery<FIELDS>, options?: RequestOptions): Promise<CursorPage<R>>;
|
|
73
|
+
/** The first record that matches; rejects with 404 when none does. */
|
|
74
|
+
single(query: FilterSingleQuery<FIELDS>, options?: RequestOptions): Promise<R>;
|
|
75
|
+
/** How many records match, bounded by the count's limit. */
|
|
76
|
+
count(query: CountQuery<FIELDS>, options?: RequestOptions): Promise<CountResult>;
|
|
77
|
+
/** The groups and metrics of an aggregation, one row per group. */
|
|
78
|
+
aggregate<ROW = Record<string, unknown>>(query: AggregationQuery<FIELDS, string>, options?: RequestOptions): Promise<ROW[]>;
|
|
79
|
+
/**
|
|
80
|
+
* The model's capability descriptor; with the `version` already held, a
|
|
81
|
+
* 304 answers `notModified`.
|
|
82
|
+
*/
|
|
83
|
+
describe(version?: string, options?: RequestOptions): Promise<DescriptorResult>;
|
|
84
|
+
private post;
|
|
85
|
+
}
|
|
86
|
+
/** The query route of a model of an aggregate type. */
|
|
87
|
+
export declare function queryPath(type: AggregateType, model: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Queries an aggregate type's snapshots (decision D128), the default read
|
|
90
|
+
* model; only where the aggregate keeps them.
|
|
91
|
+
*
|
|
92
|
+
* @typeParam S - The state's type.
|
|
93
|
+
* @typeParam STATE_FIELDS - The `state.*` paths of the state.
|
|
94
|
+
*/
|
|
95
|
+
export declare class SnapshotQueryClient<S = unknown, STATE_FIELDS extends string = `state.${string}`> extends QueryModelClient<SnapshotRecord<S>, SnapshotSystemField | STATE_FIELDS> {
|
|
96
|
+
readonly type: AggregateType;
|
|
97
|
+
/**
|
|
98
|
+
* @param type - The aggregate type
|
|
99
|
+
* @param client - How the service is reached
|
|
100
|
+
*/
|
|
101
|
+
constructor(type: AggregateType, client?: WowClientOptions);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Queries an aggregate type's event streams (decision D131), one aggregate
|
|
105
|
+
* at a time: a filter names its `aggregateId`, and may bound `version` or
|
|
106
|
+
* `commitTime`.
|
|
107
|
+
*
|
|
108
|
+
* @typeParam E - The events' type.
|
|
109
|
+
*/
|
|
110
|
+
export declare class EventQueryClient<E extends EventView = EventView> extends QueryModelClient<EventStreamRecord<E>, EventStreamField> {
|
|
111
|
+
readonly type: AggregateType;
|
|
112
|
+
/**
|
|
113
|
+
* @param type - The aggregate type
|
|
114
|
+
* @param client - How the service is reached
|
|
115
|
+
*/
|
|
116
|
+
constructor(type: AggregateType, client?: WowClientOptions);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The datasets of a Wow V10 service (decisions D75, D145): registered at run
|
|
120
|
+
* time, so not in the Manifest. Lists those the caller sees and queries
|
|
121
|
+
* each as a snapshot model is queried.
|
|
122
|
+
*/
|
|
123
|
+
export declare class DatasetClient {
|
|
124
|
+
readonly client: WowClientOptions;
|
|
125
|
+
/** @param client - How the service is reached */
|
|
126
|
+
constructor(client?: WowClientOptions);
|
|
127
|
+
/** The datasets the caller sees, by name. */
|
|
128
|
+
list(options?: RequestOptions): Promise<DatasetEntry[]>;
|
|
129
|
+
/**
|
|
130
|
+
* The query client of the dataset `context.dataset`.
|
|
131
|
+
*
|
|
132
|
+
* @typeParam R - The row's type.
|
|
133
|
+
* @typeParam FIELDS - The dataset's field paths.
|
|
134
|
+
*/
|
|
135
|
+
dataset<R = Record<string, unknown>, FIELDS extends string = string>(context: string, dataset: string): QueryModelClient<R, FIELDS>;
|
|
136
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { AggregationQuery } from '../dsl/aggregation/index.js';
|
|
2
|
+
import { CursorPage, CursorQuery } from '../dsl/cursorQuery.js';
|
|
3
|
+
import { QueryModelDescriptor } from '../dsl/descriptor.js';
|
|
4
|
+
import { FilterCapable } from '../dsl/filter/index.js';
|
|
5
|
+
import { FilterListQuery, FilterPagedQuery, FilterSingleQuery } from '../dsl/queryable.js';
|
|
6
|
+
import { RequestOptions, WowClientOptions } from './http.js';
|
|
7
|
+
import { AggregateType, DatasetEntry, EventStreamField, EventStreamRecord, EventView, SnapshotRecord, SnapshotSystemField } from './wire.js';
|
|
8
|
+
/** How a paged query counts its total (`TotalMode`, decision D150). */
|
|
9
|
+
export type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';
|
|
10
|
+
/** A paged query of a V10 query route: a page, and how its total is counted. */
|
|
11
|
+
export interface PagedQuery<FIELDS extends string = string> extends FilterPagedQuery<FIELDS> {
|
|
12
|
+
/** `BOUNDED` (the server's default) counts up to the budget's limit. */
|
|
13
|
+
total?: TotalMode;
|
|
14
|
+
}
|
|
15
|
+
/** A count of a V10 query route (decision D150). */
|
|
16
|
+
export interface CountQuery<FIELDS extends string = string> extends FilterCapable<FIELDS> {
|
|
17
|
+
/** The most matches to count; the budget's default when absent. */
|
|
18
|
+
limit?: number;
|
|
19
|
+
}
|
|
20
|
+
/** What a count answers: exact below its limit, else the limit itself. */
|
|
21
|
+
export interface CountResult {
|
|
22
|
+
readonly count: number;
|
|
23
|
+
readonly exact: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A page of a paged query: `total` is exact when `exact`, a lower bound
|
|
27
|
+
* otherwise, and null for `TotalMode.NONE`.
|
|
28
|
+
*/
|
|
29
|
+
export interface PagedResult<T> {
|
|
30
|
+
readonly total: number | null;
|
|
31
|
+
readonly exact: boolean;
|
|
32
|
+
readonly list: readonly T[];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A query model's capability descriptor and its version, the `ETag` of
|
|
36
|
+
* `GET …/query`; `notModified` when the version given is still current.
|
|
37
|
+
*/
|
|
38
|
+
export type DescriptorResult = {
|
|
39
|
+
readonly notModified: false;
|
|
40
|
+
readonly version?: string;
|
|
41
|
+
readonly descriptor: QueryModelDescriptor;
|
|
42
|
+
} | {
|
|
43
|
+
readonly notModified: true;
|
|
44
|
+
readonly version: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Queries one query model of a Wow V10 service: `POST {path}` with a body
|
|
48
|
+
* whose `kind` names the operation, `GET {path}` for the capability
|
|
49
|
+
* descriptor (decisions D127, D145).
|
|
50
|
+
*
|
|
51
|
+
* @typeParam R - The record's type.
|
|
52
|
+
* @typeParam FIELDS - The field paths a filter, sort or projection takes.
|
|
53
|
+
*/
|
|
54
|
+
export declare class QueryModelClient<R, FIELDS extends string = string> {
|
|
55
|
+
readonly path: string;
|
|
56
|
+
readonly client: WowClientOptions;
|
|
57
|
+
/**
|
|
58
|
+
* @param path - The query route, `/{context}/{aggregate}/{model}/query`
|
|
59
|
+
* @param client - How the service is reached
|
|
60
|
+
*/
|
|
61
|
+
constructor(path: string, client?: WowClientOptions);
|
|
62
|
+
/** The records that match, at most `limit` (the server's default when absent). */
|
|
63
|
+
list(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<R[]>;
|
|
64
|
+
/**
|
|
65
|
+
* The records that match, as server-sent events read one at a time; a
|
|
66
|
+
* failure after the first record errors the stream with its problem.
|
|
67
|
+
*/
|
|
68
|
+
listStream(query: FilterListQuery<FIELDS>, options?: RequestOptions): Promise<ReadableStream<R>>;
|
|
69
|
+
/** One page of the records that match, and their total. */
|
|
70
|
+
paged(query: PagedQuery<FIELDS>, options?: RequestOptions): Promise<PagedResult<R>>;
|
|
71
|
+
/** One page of a forward-only cursor over the records that match. */
|
|
72
|
+
cursor(query: CursorQuery<FIELDS>, options?: RequestOptions): Promise<CursorPage<R>>;
|
|
73
|
+
/** The first record that matches; rejects with 404 when none does. */
|
|
74
|
+
single(query: FilterSingleQuery<FIELDS>, options?: RequestOptions): Promise<R>;
|
|
75
|
+
/** How many records match, bounded by the count's limit. */
|
|
76
|
+
count(query: CountQuery<FIELDS>, options?: RequestOptions): Promise<CountResult>;
|
|
77
|
+
/** The groups and metrics of an aggregation, one row per group. */
|
|
78
|
+
aggregate<ROW = Record<string, unknown>>(query: AggregationQuery<FIELDS, string>, options?: RequestOptions): Promise<ROW[]>;
|
|
79
|
+
/**
|
|
80
|
+
* The model's capability descriptor; with the `version` already held, a
|
|
81
|
+
* 304 answers `notModified`.
|
|
82
|
+
*/
|
|
83
|
+
describe(version?: string, options?: RequestOptions): Promise<DescriptorResult>;
|
|
84
|
+
private post;
|
|
85
|
+
}
|
|
86
|
+
/** The query route of a model of an aggregate type. */
|
|
87
|
+
export declare function queryPath(type: AggregateType, model: string): string;
|
|
88
|
+
/**
|
|
89
|
+
* Queries an aggregate type's snapshots (decision D128), the default read
|
|
90
|
+
* model; only where the aggregate keeps them.
|
|
91
|
+
*
|
|
92
|
+
* @typeParam S - The state's type.
|
|
93
|
+
* @typeParam STATE_FIELDS - The `state.*` paths of the state.
|
|
94
|
+
*/
|
|
95
|
+
export declare class SnapshotQueryClient<S = unknown, STATE_FIELDS extends string = `state.${string}`> extends QueryModelClient<SnapshotRecord<S>, SnapshotSystemField | STATE_FIELDS> {
|
|
96
|
+
readonly type: AggregateType;
|
|
97
|
+
/**
|
|
98
|
+
* @param type - The aggregate type
|
|
99
|
+
* @param client - How the service is reached
|
|
100
|
+
*/
|
|
101
|
+
constructor(type: AggregateType, client?: WowClientOptions);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Queries an aggregate type's event streams (decision D131), one aggregate
|
|
105
|
+
* at a time: a filter names its `aggregateId`, and may bound `version` or
|
|
106
|
+
* `commitTime`.
|
|
107
|
+
*
|
|
108
|
+
* @typeParam E - The events' type.
|
|
109
|
+
*/
|
|
110
|
+
export declare class EventQueryClient<E extends EventView = EventView> extends QueryModelClient<EventStreamRecord<E>, EventStreamField> {
|
|
111
|
+
readonly type: AggregateType;
|
|
112
|
+
/**
|
|
113
|
+
* @param type - The aggregate type
|
|
114
|
+
* @param client - How the service is reached
|
|
115
|
+
*/
|
|
116
|
+
constructor(type: AggregateType, client?: WowClientOptions);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* The datasets of a Wow V10 service (decisions D75, D145): registered at run
|
|
120
|
+
* time, so not in the Manifest. Lists those the caller sees and queries
|
|
121
|
+
* each as a snapshot model is queried.
|
|
122
|
+
*/
|
|
123
|
+
export declare class DatasetClient {
|
|
124
|
+
readonly client: WowClientOptions;
|
|
125
|
+
/** @param client - How the service is reached */
|
|
126
|
+
constructor(client?: WowClientOptions);
|
|
127
|
+
/** The datasets the caller sees, by name. */
|
|
128
|
+
list(options?: RequestOptions): Promise<DatasetEntry[]>;
|
|
129
|
+
/**
|
|
130
|
+
* The query client of the dataset `context.dataset`.
|
|
131
|
+
*
|
|
132
|
+
* @typeParam R - The row's type.
|
|
133
|
+
* @typeParam FIELDS - The dataset's field paths.
|
|
134
|
+
*/
|
|
135
|
+
dataset<R = Record<string, unknown>, FIELDS extends string = string>(context: string, dataset: string): QueryModelClient<R, FIELDS>;
|
|
136
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { WowV10Headers as e, entityTag as t, json as n, send as r } from "./http.es.js";
|
|
2
|
+
import { queryRows as i } from "./streams.es.js";
|
|
3
|
+
//#region src/v10/queries.ts
|
|
4
|
+
var a = class {
|
|
5
|
+
constructor(e, t = {}) {
|
|
6
|
+
this.path = e, this.client = t;
|
|
7
|
+
}
|
|
8
|
+
async list(e, t) {
|
|
9
|
+
return n(await this.post("list", e, t));
|
|
10
|
+
}
|
|
11
|
+
async listStream(e, t) {
|
|
12
|
+
return i(await this.post("list", e, t, "text/event-stream"));
|
|
13
|
+
}
|
|
14
|
+
async paged(e, t) {
|
|
15
|
+
return n(await this.post("paged", e, t));
|
|
16
|
+
}
|
|
17
|
+
async cursor(e, t) {
|
|
18
|
+
return n(await this.post("cursor", e, t));
|
|
19
|
+
}
|
|
20
|
+
async single(e, t) {
|
|
21
|
+
return n(await this.post("single", e, t));
|
|
22
|
+
}
|
|
23
|
+
async count(e, t) {
|
|
24
|
+
return n(await this.post("count", e, t));
|
|
25
|
+
}
|
|
26
|
+
async aggregate(e, t) {
|
|
27
|
+
return n(await this.post("aggregate", e, t));
|
|
28
|
+
}
|
|
29
|
+
async describe(i, a) {
|
|
30
|
+
let o = await r(this.client, {
|
|
31
|
+
method: "GET",
|
|
32
|
+
path: this.path,
|
|
33
|
+
headers: { [e.IF_NONE_MATCH]: i === void 0 ? void 0 : `"${i}"` },
|
|
34
|
+
options: a,
|
|
35
|
+
notModified: !0
|
|
36
|
+
}), s = t(o);
|
|
37
|
+
return o.status === 304 ? {
|
|
38
|
+
notModified: !0,
|
|
39
|
+
version: s ?? i ?? ""
|
|
40
|
+
} : {
|
|
41
|
+
notModified: !1,
|
|
42
|
+
...s === void 0 ? {} : { version: s },
|
|
43
|
+
descriptor: await n(o)
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
post(e, t, n, i) {
|
|
47
|
+
return r(this.client, {
|
|
48
|
+
method: "POST",
|
|
49
|
+
path: this.path,
|
|
50
|
+
headers: { Accept: i },
|
|
51
|
+
body: {
|
|
52
|
+
...t,
|
|
53
|
+
kind: e
|
|
54
|
+
},
|
|
55
|
+
options: n
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
function o(e, t) {
|
|
60
|
+
return `/${e.context}/${e.name}/${t}/query`;
|
|
61
|
+
}
|
|
62
|
+
var s = class extends a {
|
|
63
|
+
constructor(e, t) {
|
|
64
|
+
super(o(e, "snapshot"), t), this.type = e;
|
|
65
|
+
}
|
|
66
|
+
}, c = class extends a {
|
|
67
|
+
constructor(e, t) {
|
|
68
|
+
super(o(e, "events"), t), this.type = e;
|
|
69
|
+
}
|
|
70
|
+
}, l = class {
|
|
71
|
+
constructor(e = {}) {
|
|
72
|
+
this.client = e;
|
|
73
|
+
}
|
|
74
|
+
async list(e) {
|
|
75
|
+
return n(await r(this.client, {
|
|
76
|
+
method: "GET",
|
|
77
|
+
path: "/wow/dataset",
|
|
78
|
+
options: e
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
81
|
+
dataset(e, t) {
|
|
82
|
+
return new a(`/wow/dataset/${encodeURIComponent(e)}/${encodeURIComponent(t)}/query`, this.client);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
//#endregion
|
|
86
|
+
export { l as DatasetClient, c as EventQueryClient, a as QueryModelClient, s as SnapshotQueryClient, o as queryPath };
|
|
87
|
+
|
|
88
|
+
//# sourceMappingURL=queries.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.es.js","names":["QueryModelClient","path","client","json","query","options","queryRows","response","send","WowV10Headers","version","tag","entityTag","accept","queryPath","type","model","SnapshotQueryClient","EventQueryClient","DatasetClient","context","dataset"],"sources":["../../src/v10/queries.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AggregationQuery } from '../dsl/aggregation/index.js';\nimport type { CursorPage, CursorQuery } from '../dsl/cursorQuery.js';\nimport type { QueryModelDescriptor } from '../dsl/descriptor.js';\nimport type { FilterCapable } from '../dsl/filter/index.js';\nimport type {\n FilterListQuery,\n FilterPagedQuery,\n FilterSingleQuery,\n} from '../dsl/queryable.js';\nimport {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowV10Headers,\n} from './http.js';\nimport type {\n AggregateType,\n DatasetEntry,\n EventStreamField,\n EventStreamRecord,\n EventView,\n SnapshotRecord,\n SnapshotSystemField,\n} from './wire.js';\nimport { queryRows } from './streams.js';\n\n/** How a paged query counts its total (`TotalMode`, decision D150). */\nexport type TotalMode = 'EXACT' | 'BOUNDED' | 'NONE';\n\n/** A paged query of a V10 query route: a page, and how its total is counted. */\nexport interface PagedQuery<\n FIELDS extends string = string,\n> extends FilterPagedQuery<FIELDS> {\n /** `BOUNDED` (the server's default) counts up to the budget's limit. */\n total?: TotalMode;\n}\n\n/** A count of a V10 query route (decision D150). */\nexport interface CountQuery<\n FIELDS extends string = string,\n> extends FilterCapable<FIELDS> {\n /** The most matches to count; the budget's default when absent. */\n limit?: number;\n}\n\n/** What a count answers: exact below its limit, else the limit itself. */\nexport interface CountResult {\n readonly count: number;\n readonly exact: boolean;\n}\n\n/**\n * A page of a paged query: `total` is exact when `exact`, a lower bound\n * otherwise, and null for `TotalMode.NONE`.\n */\nexport interface PagedResult<T> {\n readonly total: number | null;\n readonly exact: boolean;\n readonly list: readonly T[];\n}\n\n/**\n * A query model's capability descriptor and its version, the `ETag` of\n * `GET …/query`; `notModified` when the version given is still current.\n */\nexport type DescriptorResult =\n | {\n readonly notModified: false;\n readonly version?: string;\n readonly descriptor: QueryModelDescriptor;\n }\n | { readonly notModified: true; readonly version: string };\n\n/**\n * Queries one query model of a Wow V10 service: `POST {path}` with a body\n * whose `kind` names the operation, `GET {path}` for the capability\n * descriptor (decisions D127, D145).\n *\n * @typeParam R - The record's type.\n * @typeParam FIELDS - The field paths a filter, sort or projection takes.\n */\nexport class QueryModelClient<R, FIELDS extends string = string> {\n /**\n * @param path - The query route, `/{context}/{aggregate}/{model}/query`\n * @param client - How the service is reached\n */\n constructor(\n readonly path: string,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The records that match, at most `limit` (the server's default when absent). */\n async list(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R[]> {\n return json<R[]>(await this.post('list', query, options));\n }\n\n /**\n * The records that match, as server-sent events read one at a time; a\n * failure after the first record errors the stream with its problem.\n */\n async listStream(\n query: FilterListQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<ReadableStream<R>> {\n return queryRows<R>(\n await this.post('list', query, options, 'text/event-stream'),\n );\n }\n\n /** One page of the records that match, and their total. */\n async paged(\n query: PagedQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<PagedResult<R>> {\n return json<PagedResult<R>>(await this.post('paged', query, options));\n }\n\n /** One page of a forward-only cursor over the records that match. */\n async cursor(\n query: CursorQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CursorPage<R>> {\n return json<CursorPage<R>>(await this.post('cursor', query, options));\n }\n\n /** The first record that matches; rejects with 404 when none does. */\n async single(\n query: FilterSingleQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<R> {\n return json<R>(await this.post('single', query, options));\n }\n\n /** How many records match, bounded by the count's limit. */\n async count(\n query: CountQuery<FIELDS>,\n options?: RequestOptions,\n ): Promise<CountResult> {\n return json<CountResult>(await this.post('count', query, options));\n }\n\n /** The groups and metrics of an aggregation, one row per group. */\n async aggregate<ROW = Record<string, unknown>>(\n query: AggregationQuery<FIELDS, string>,\n options?: RequestOptions,\n ): Promise<ROW[]> {\n return json<ROW[]>(await this.post('aggregate', query, options));\n }\n\n /**\n * The model's capability descriptor; with the `version` already held, a\n * 304 answers `notModified`.\n */\n async describe(\n version?: string,\n options?: RequestOptions,\n ): Promise<DescriptorResult> {\n const response = await send(this.client, {\n method: 'GET',\n path: this.path,\n headers: {\n [WowV10Headers.IF_NONE_MATCH]:\n version === undefined ? undefined : `\"${version}\"`,\n },\n options,\n notModified: true,\n });\n const tag = entityTag(response);\n if (response.status === 304) {\n return { notModified: true, version: tag ?? version ?? '' };\n }\n return {\n notModified: false,\n ...(tag === undefined ? {} : { version: tag }),\n descriptor: await json<QueryModelDescriptor>(response),\n };\n }\n\n private post(\n kind: string,\n query: object,\n options?: RequestOptions,\n accept?: string,\n ): Promise<Response> {\n return send(this.client, {\n method: 'POST',\n path: this.path,\n headers: { Accept: accept },\n body: { ...query, kind },\n options,\n });\n }\n}\n\n/** The query route of a model of an aggregate type. */\nexport function queryPath(type: AggregateType, model: string): string {\n return `/${type.context}/${type.name}/${model}/query`;\n}\n\n/**\n * Queries an aggregate type's snapshots (decision D128), the default read\n * model; only where the aggregate keeps them.\n *\n * @typeParam S - The state's type.\n * @typeParam STATE_FIELDS - The `state.*` paths of the state.\n */\nexport class SnapshotQueryClient<\n S = unknown,\n STATE_FIELDS extends string = `state.${string}`,\n> extends QueryModelClient<\n SnapshotRecord<S>,\n SnapshotSystemField | STATE_FIELDS\n> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n super(queryPath(type, 'snapshot'), client);\n }\n}\n\n/**\n * Queries an aggregate type's event streams (decision D131), one aggregate\n * at a time: a filter names its `aggregateId`, and may bound `version` or\n * `commitTime`.\n *\n * @typeParam E - The events' type.\n */\nexport class EventQueryClient<\n E extends EventView = EventView,\n> extends QueryModelClient<EventStreamRecord<E>, EventStreamField> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n client?: WowClientOptions,\n ) {\n super(queryPath(type, 'events'), client);\n }\n}\n\n/**\n * The datasets of a Wow V10 service (decisions D75, D145): registered at run\n * time, so not in the Manifest. Lists those the caller sees and queries\n * each as a snapshot model is queried.\n */\nexport class DatasetClient {\n /** @param client - How the service is reached */\n constructor(readonly client: WowClientOptions = {}) {}\n\n /** The datasets the caller sees, by name. */\n async list(options?: RequestOptions): Promise<DatasetEntry[]> {\n return json<DatasetEntry[]>(\n await send(this.client, { method: 'GET', path: '/wow/dataset', options }),\n );\n }\n\n /**\n * The query client of the dataset `context.dataset`.\n *\n * @typeParam R - The row's type.\n * @typeParam FIELDS - The dataset's field paths.\n */\n dataset<R = Record<string, unknown>, FIELDS extends string = string>(\n context: string,\n dataset: string,\n ): QueryModelClient<R, FIELDS> {\n return new QueryModelClient<R, FIELDS>(\n `/wow/dataset/${encodeURIComponent(context)}/${encodeURIComponent(dataset)}/query`,\n this.client,\n );\n }\n}\n"],"mappings":";;;AAgGA,IAAaA,IAAb,MAAiE;CAK/D,YACE,GACA,IAAoC,CAAC,GACrC;EADS,AADA,KAAA,OAAAC,GACA,KAAA,SAAAC;C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,KAAK;GACX,SAAS,EAAE,QAAQK,EAAO;GAC1B,MAAM;IAAE,GAAGT;IAAO;GAAK;GACvB;EACF,CAAC;CACH;AACF;AAGA,SAAgBU,EAAU,GAAqB,GAAuB;CACpE,OAAO,IAAIC,EAAK,QAAQ,GAAGA,EAAK,KAAK,GAAGC,EAAM;AAChD;AASA,IAAaC,IAAb,cAGUjB,EAGR;CAKA,YACE,GACA,GACA;EAFS,AAGT,MAAMc,EAAUC,GAAM,UAAU,GAAGb,CAAM,GAHhC,KAAA,OAAAa;CAIX;AACF,GASaG,IAAb,cAEUlB,EAAyD;CAKjE,YACE,GACA,GACA;EAFS,AAGT,MAAMc,EAAUC,GAAM,QAAQ,GAAGb,CAAM,GAH9B,KAAA,OAAAa;CAIX;AACF,GAOaI,IAAb,MAA2B;CAEzB,YAAY,IAAoC,CAAC,GAAG;EAA/B,KAAA,SAAAjB;CAAgC;CAGrD,MAAM,KAAK,GAAmD;EAC5D,OAAOC,EACL,MAAMK,EAAK,KAAK,QAAQ;GAAE,QAAQ;GAAO,MAAM;GAAgB;EAAQ,CAAC,CAC1E;CACF;CAQA,QACE,GACA,GAC6B;EAC7B,OAAO,IAAIR,EACT,gBAAgB,mBAAmBoB,CAAO,EAAE,GAAG,mBAAmBC,CAAO,EAAE,SAC3E,KAAK,MACP;CACF;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./http.cjs");var t=class{constructor(e,t={}){this.type=e,this.client=t}async read(t,n={}){let r=n.at instanceof Date?n.at.toISOString():n.at,i=await e.send(this.client,{method:`GET`,path:this.statePath(t),query:{version:n.version,at:r},headers:{[e.WowV10Headers.IF_NONE_MATCH]:n.ifNoneMatch===void 0?void 0:`"${n.ifNoneMatch}"`},options:n,notModified:!0});return i.status===304?{notModified:!0,version:Number(e.entityTag(i)??n.ifNoneMatch)}:{notModified:!1,view:await e.json(i)}}async get(e,t={}){let n=await this.read(e,t);if(n.notModified)throw Error(`A read without If-None-Match was answered 304.`);return n.view}async trace(t,n={}){return e.json(await e.send(this.client,{method:`GET`,path:`${this.statePath(t)}/trace`,query:{from:n.from,to:n.to,limit:n.limit},options:n}))}statePath(e){return`/${this.type.context}/${this.type.name}/${encodeURIComponent(e)}/state`}};exports.StateClient=t;
|
|
2
|
+
//# sourceMappingURL=state.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.cjs","names":["send","WowV10Headers","entityTag","json","require_http","StateClient","type","client","at","options","response","id","result"],"sources":["../../src/v10/state.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n entityTag,\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n WowV10Headers,\n} from './http.js';\nimport type {\n AggregateType,\n EventView,\n StateTrace,\n StateView,\n} from './wire.js';\n\n/** Which state a read asks for: the latest, at a version or as of a time. */\nexport interface StateReadOptions extends RequestOptions {\n /** The committed state at this version. */\n readonly version?: number;\n /** The committed state as of this instant (ISO-8601, or a `Date`). */\n readonly at?: string | Date;\n /** The version already held: a 304 then answers `notModified`. */\n readonly ifNoneMatch?: number;\n}\n\n/** A state read: the view, or `notModified` when the version held is current. */\nexport type StateReadResult<S> =\n | { readonly notModified: false; readonly view: StateView<S> }\n | { readonly notModified: true; readonly version: number };\n\n/** Which commits a trace reads (decision D40). */\nexport interface StateTraceOptions extends RequestOptions {\n /** The first version; 1 when absent. */\n readonly from?: number;\n /** The last version; the latest when absent. */\n readonly to?: number;\n /** The most commits, at most 1000; 100 when absent. */\n readonly limit?: number;\n}\n\n/**\n * Reads an aggregate type's states (decisions D40, D112):\n * `GET /{context}/{aggregate}/{id}/state` with `?version=` or `?at=`, and\n * its trace, `…/state/trace`. A state that does not exist rejects with 404\n * `wow.aggregate.not-found`.\n *\n * @typeParam S - The state's type.\n * @typeParam E - The events' type of a trace.\n */\nexport class StateClient<S = unknown, E extends EventView = EventView> {\n /**\n * @param type - The aggregate type\n * @param client - How the service is reached\n */\n constructor(\n readonly type: AggregateType,\n readonly client: WowClientOptions = {},\n ) {}\n\n /** The state the options ask for. */\n async read(\n id: string,\n options: StateReadOptions = {},\n ): Promise<StateReadResult<S>> {\n const at =\n options.at instanceof Date ? options.at.toISOString() : options.at;\n const response = await send(this.client, {\n method: 'GET',\n path: this.statePath(id),\n query: { version: options.version, at },\n headers: {\n [WowV10Headers.IF_NONE_MATCH]:\n options.ifNoneMatch === undefined\n ? undefined\n : `\"${options.ifNoneMatch}\"`,\n },\n options,\n notModified: true,\n });\n if (response.status === 304) {\n return {\n notModified: true,\n version: Number(entityTag(response) ?? options.ifNoneMatch),\n };\n }\n return { notModified: false, view: await json<StateView<S>>(response) };\n }\n\n /** The latest state, or the one the options ask for, without a cache. */\n async get(\n id: string,\n options: Omit<StateReadOptions, 'ifNoneMatch'> = {},\n ): Promise<StateView<S>> {\n const result = await this.read(id, options);\n if (result.notModified) {\n throw new Error('A read without If-None-Match was answered 304.');\n }\n return result.view;\n }\n\n /** The commits from `from` to `to`, each with its events and the state after it. */\n async trace(\n id: string,\n options: StateTraceOptions = {},\n ): Promise<StateTrace<S, E>> {\n return json<StateTrace<S, E>>(\n await send(this.client, {\n method: 'GET',\n path: `${this.statePath(id)}/trace`,\n query: { from: options.from, to: options.to, limit: options.limit },\n options,\n }),\n );\n }\n\n private statePath(id: string): string {\n return `/${this.type.context}/${this.type.name}/${encodeURIComponent(id)}/state`;\n }\n}\n"],"mappings":"8BA8DA,IAAaK,EAAb,KAAuE,CAKrE,YACE,EACA,EAAoC,CAAC,EACrC,CAFS,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AggregateType, EventView, StateTrace, StateView } from './wire.cjs';
|
|
3
|
+
/** Which state a read asks for: the latest, at a version or as of a time. */
|
|
4
|
+
export interface StateReadOptions extends RequestOptions {
|
|
5
|
+
/** The committed state at this version. */
|
|
6
|
+
readonly version?: number;
|
|
7
|
+
/** The committed state as of this instant (ISO-8601, or a `Date`). */
|
|
8
|
+
readonly at?: string | Date;
|
|
9
|
+
/** The version already held: a 304 then answers `notModified`. */
|
|
10
|
+
readonly ifNoneMatch?: number;
|
|
11
|
+
}
|
|
12
|
+
/** A state read: the view, or `notModified` when the version held is current. */
|
|
13
|
+
export type StateReadResult<S> = {
|
|
14
|
+
readonly notModified: false;
|
|
15
|
+
readonly view: StateView<S>;
|
|
16
|
+
} | {
|
|
17
|
+
readonly notModified: true;
|
|
18
|
+
readonly version: number;
|
|
19
|
+
};
|
|
20
|
+
/** Which commits a trace reads (decision D40). */
|
|
21
|
+
export interface StateTraceOptions extends RequestOptions {
|
|
22
|
+
/** The first version; 1 when absent. */
|
|
23
|
+
readonly from?: number;
|
|
24
|
+
/** The last version; the latest when absent. */
|
|
25
|
+
readonly to?: number;
|
|
26
|
+
/** The most commits, at most 1000; 100 when absent. */
|
|
27
|
+
readonly limit?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reads an aggregate type's states (decisions D40, D112):
|
|
31
|
+
* `GET /{context}/{aggregate}/{id}/state` with `?version=` or `?at=`, and
|
|
32
|
+
* its trace, `…/state/trace`. A state that does not exist rejects with 404
|
|
33
|
+
* `wow.aggregate.not-found`.
|
|
34
|
+
*
|
|
35
|
+
* @typeParam S - The state's type.
|
|
36
|
+
* @typeParam E - The events' type of a trace.
|
|
37
|
+
*/
|
|
38
|
+
export declare class StateClient<S = unknown, E extends EventView = EventView> {
|
|
39
|
+
readonly type: AggregateType;
|
|
40
|
+
readonly client: WowClientOptions;
|
|
41
|
+
/**
|
|
42
|
+
* @param type - The aggregate type
|
|
43
|
+
* @param client - How the service is reached
|
|
44
|
+
*/
|
|
45
|
+
constructor(type: AggregateType, client?: WowClientOptions);
|
|
46
|
+
/** The state the options ask for. */
|
|
47
|
+
read(id: string, options?: StateReadOptions): Promise<StateReadResult<S>>;
|
|
48
|
+
/** The latest state, or the one the options ask for, without a cache. */
|
|
49
|
+
get(id: string, options?: Omit<StateReadOptions, 'ifNoneMatch'>): Promise<StateView<S>>;
|
|
50
|
+
/** The commits from `from` to `to`, each with its events and the state after it. */
|
|
51
|
+
trace(id: string, options?: StateTraceOptions): Promise<StateTrace<S, E>>;
|
|
52
|
+
private statePath;
|
|
53
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { RequestOptions, WowClientOptions } from './http.js';
|
|
2
|
+
import { AggregateType, EventView, StateTrace, StateView } from './wire.js';
|
|
3
|
+
/** Which state a read asks for: the latest, at a version or as of a time. */
|
|
4
|
+
export interface StateReadOptions extends RequestOptions {
|
|
5
|
+
/** The committed state at this version. */
|
|
6
|
+
readonly version?: number;
|
|
7
|
+
/** The committed state as of this instant (ISO-8601, or a `Date`). */
|
|
8
|
+
readonly at?: string | Date;
|
|
9
|
+
/** The version already held: a 304 then answers `notModified`. */
|
|
10
|
+
readonly ifNoneMatch?: number;
|
|
11
|
+
}
|
|
12
|
+
/** A state read: the view, or `notModified` when the version held is current. */
|
|
13
|
+
export type StateReadResult<S> = {
|
|
14
|
+
readonly notModified: false;
|
|
15
|
+
readonly view: StateView<S>;
|
|
16
|
+
} | {
|
|
17
|
+
readonly notModified: true;
|
|
18
|
+
readonly version: number;
|
|
19
|
+
};
|
|
20
|
+
/** Which commits a trace reads (decision D40). */
|
|
21
|
+
export interface StateTraceOptions extends RequestOptions {
|
|
22
|
+
/** The first version; 1 when absent. */
|
|
23
|
+
readonly from?: number;
|
|
24
|
+
/** The last version; the latest when absent. */
|
|
25
|
+
readonly to?: number;
|
|
26
|
+
/** The most commits, at most 1000; 100 when absent. */
|
|
27
|
+
readonly limit?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Reads an aggregate type's states (decisions D40, D112):
|
|
31
|
+
* `GET /{context}/{aggregate}/{id}/state` with `?version=` or `?at=`, and
|
|
32
|
+
* its trace, `…/state/trace`. A state that does not exist rejects with 404
|
|
33
|
+
* `wow.aggregate.not-found`.
|
|
34
|
+
*
|
|
35
|
+
* @typeParam S - The state's type.
|
|
36
|
+
* @typeParam E - The events' type of a trace.
|
|
37
|
+
*/
|
|
38
|
+
export declare class StateClient<S = unknown, E extends EventView = EventView> {
|
|
39
|
+
readonly type: AggregateType;
|
|
40
|
+
readonly client: WowClientOptions;
|
|
41
|
+
/**
|
|
42
|
+
* @param type - The aggregate type
|
|
43
|
+
* @param client - How the service is reached
|
|
44
|
+
*/
|
|
45
|
+
constructor(type: AggregateType, client?: WowClientOptions);
|
|
46
|
+
/** The state the options ask for. */
|
|
47
|
+
read(id: string, options?: StateReadOptions): Promise<StateReadResult<S>>;
|
|
48
|
+
/** The latest state, or the one the options ask for, without a cache. */
|
|
49
|
+
get(id: string, options?: Omit<StateReadOptions, 'ifNoneMatch'>): Promise<StateView<S>>;
|
|
50
|
+
/** The commits from `from` to `to`, each with its events and the state after it. */
|
|
51
|
+
trace(id: string, options?: StateTraceOptions): Promise<StateTrace<S, E>>;
|
|
52
|
+
private statePath;
|
|
53
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { WowV10Headers as e, entityTag as t, json as n, send as r } from "./http.es.js";
|
|
2
|
+
//#region src/v10/state.ts
|
|
3
|
+
var i = class {
|
|
4
|
+
constructor(e, t = {}) {
|
|
5
|
+
this.type = e, this.client = t;
|
|
6
|
+
}
|
|
7
|
+
async read(i, a = {}) {
|
|
8
|
+
let o = a.at instanceof Date ? a.at.toISOString() : a.at, s = await r(this.client, {
|
|
9
|
+
method: "GET",
|
|
10
|
+
path: this.statePath(i),
|
|
11
|
+
query: {
|
|
12
|
+
version: a.version,
|
|
13
|
+
at: o
|
|
14
|
+
},
|
|
15
|
+
headers: { [e.IF_NONE_MATCH]: a.ifNoneMatch === void 0 ? void 0 : `"${a.ifNoneMatch}"` },
|
|
16
|
+
options: a,
|
|
17
|
+
notModified: !0
|
|
18
|
+
});
|
|
19
|
+
return s.status === 304 ? {
|
|
20
|
+
notModified: !0,
|
|
21
|
+
version: Number(t(s) ?? a.ifNoneMatch)
|
|
22
|
+
} : {
|
|
23
|
+
notModified: !1,
|
|
24
|
+
view: await n(s)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
async get(e, t = {}) {
|
|
28
|
+
let n = await this.read(e, t);
|
|
29
|
+
if (n.notModified) throw Error("A read without If-None-Match was answered 304.");
|
|
30
|
+
return n.view;
|
|
31
|
+
}
|
|
32
|
+
async trace(e, t = {}) {
|
|
33
|
+
return n(await r(this.client, {
|
|
34
|
+
method: "GET",
|
|
35
|
+
path: `${this.statePath(e)}/trace`,
|
|
36
|
+
query: {
|
|
37
|
+
from: t.from,
|
|
38
|
+
to: t.to,
|
|
39
|
+
limit: t.limit
|
|
40
|
+
},
|
|
41
|
+
options: t
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
statePath(e) {
|
|
45
|
+
return `/${this.type.context}/${this.type.name}/${encodeURIComponent(e)}/state`;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { i as StateClient };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=state.es.js.map
|