@ahoo-wang/wow-client 9.8.0 → 10.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/query/dataset/datasetDescriptorEndpoint.cjs +2 -0
- package/dist/client/query/dataset/datasetDescriptorEndpoint.cjs.map +1 -0
- package/dist/client/query/dataset/datasetDescriptorEndpoint.d.cts +8 -0
- package/dist/client/query/dataset/datasetDescriptorEndpoint.d.ts +8 -0
- package/dist/client/query/dataset/datasetDescriptorEndpoint.es.js +34 -0
- package/dist/client/query/dataset/datasetDescriptorEndpoint.es.js.map +1 -0
- package/dist/client/query/dataset/datasetDirectoryClient.cjs +2 -0
- package/dist/client/query/dataset/datasetDirectoryClient.cjs.map +1 -0
- package/dist/client/query/dataset/datasetDirectoryClient.d.cts +29 -0
- package/dist/client/query/dataset/datasetDirectoryClient.d.ts +29 -0
- package/dist/client/query/dataset/datasetDirectoryClient.es.js +25 -0
- package/dist/client/query/dataset/datasetDirectoryClient.es.js.map +1 -0
- package/dist/client/query/dataset/datasetQueryApi.d.cts +40 -0
- package/dist/client/query/dataset/datasetQueryApi.d.ts +40 -0
- package/dist/client/query/dataset/datasetQueryClient.cjs +2 -0
- package/dist/client/query/dataset/datasetQueryClient.cjs.map +1 -0
- package/dist/client/query/dataset/datasetQueryClient.d.cts +57 -0
- package/dist/client/query/dataset/datasetQueryClient.d.ts +57 -0
- package/dist/client/query/dataset/datasetQueryClient.es.js +154 -0
- package/dist/client/query/dataset/datasetQueryClient.es.js.map +1 -0
- package/dist/client/query/dataset/endpointPaths.cjs +2 -0
- package/dist/client/query/dataset/endpointPaths.cjs.map +1 -0
- package/dist/client/query/dataset/endpointPaths.d.cts +9 -0
- package/dist/client/query/dataset/endpointPaths.d.ts +9 -0
- package/dist/client/query/dataset/endpointPaths.es.js +14 -0
- package/dist/client/query/dataset/endpointPaths.es.js.map +1 -0
- package/dist/client/query/dataset/index.d.cts +3 -0
- package/dist/client/query/dataset/index.d.ts +3 -0
- package/dist/client/query/event/eventStreamQueryApi.d.cts +1 -1
- package/dist/client/query/event/eventStreamQueryApi.d.ts +1 -1
- package/dist/client/query/event/eventStreamQueryClient.cjs.map +1 -1
- package/dist/client/query/event/eventStreamQueryClient.d.cts +4 -1
- package/dist/client/query/event/eventStreamQueryClient.d.ts +4 -1
- package/dist/client/query/event/eventStreamQueryClient.es.js.map +1 -1
- package/dist/client/query/event/index.d.cts +0 -1
- package/dist/client/query/event/index.d.ts +0 -1
- package/dist/client/query/index.d.cts +1 -0
- package/dist/client/query/index.d.ts +1 -0
- package/dist/client/query/snapshot/index.d.cts +0 -1
- package/dist/client/query/snapshot/index.d.ts +0 -1
- package/dist/client/query/snapshot/snapshotQueryApi.d.cts +1 -1
- package/dist/client/query/snapshot/snapshotQueryApi.d.ts +1 -1
- package/dist/client/query/snapshot/snapshotQueryClient.cjs.map +1 -1
- package/dist/client/query/snapshot/snapshotQueryClient.d.cts +4 -1
- package/dist/client/query/snapshot/snapshotQueryClient.d.ts +4 -1
- package/dist/client/query/snapshot/snapshotQueryClient.es.js.map +1 -1
- package/dist/client/routing.cjs.map +1 -1
- package/dist/client/routing.d.cts +2 -2
- package/dist/client/routing.d.ts +2 -2
- package/dist/client/routing.es.js.map +1 -1
- package/dist/dsl/aggregation/admit.cjs +1 -1
- package/dist/dsl/aggregation/admit.cjs.map +1 -1
- package/dist/dsl/aggregation/admit.es.js +84 -65
- package/dist/dsl/aggregation/admit.es.js.map +1 -1
- package/dist/dsl/aggregation/builders.cjs +1 -1
- package/dist/dsl/aggregation/builders.cjs.map +1 -1
- package/dist/dsl/aggregation/builders.d.cts +16 -4
- package/dist/dsl/aggregation/builders.d.ts +16 -4
- package/dist/dsl/aggregation/builders.es.js +89 -78
- package/dist/dsl/aggregation/builders.es.js.map +1 -1
- package/dist/dsl/aggregation/derived.cjs +1 -1
- package/dist/dsl/aggregation/derived.cjs.map +1 -1
- package/dist/dsl/aggregation/derived.d.cts +32 -1
- package/dist/dsl/aggregation/derived.d.ts +32 -1
- package/dist/dsl/aggregation/derived.es.js +23 -1
- package/dist/dsl/aggregation/derived.es.js.map +1 -1
- package/dist/dsl/aggregation/types.cjs +1 -1
- package/dist/dsl/aggregation/types.cjs.map +1 -1
- package/dist/dsl/aggregation/types.d.cts +112 -7
- package/dist/dsl/aggregation/types.d.ts +112 -7
- package/dist/dsl/aggregation/types.es.js +19 -12
- package/dist/dsl/aggregation/types.es.js.map +1 -1
- package/dist/dsl/descriptor.cjs +1 -1
- package/dist/dsl/descriptor.cjs.map +1 -1
- package/dist/dsl/descriptor.d.cts +23 -1
- package/dist/dsl/descriptor.d.ts +23 -1
- package/dist/dsl/descriptor.es.js +2 -1
- package/dist/dsl/descriptor.es.js.map +1 -1
- package/dist/dsl.cjs +1 -1
- package/dist/dsl.d.cts +2 -2
- package/dist/dsl.d.ts +2 -2
- package/dist/dsl.es.js +13 -13
- package/dist/error/headers.cjs.map +1 -1
- package/dist/error/headers.d.cts +3 -2
- package/dist/error/headers.d.ts +3 -2
- package/dist/error/headers.es.js.map +1 -1
- package/dist/error/queryErrorCodes.cjs +1 -1
- package/dist/error/queryErrorCodes.cjs.map +1 -1
- package/dist/error/queryErrorCodes.d.cts +7 -0
- package/dist/error/queryErrorCodes.d.ts +7 -0
- package/dist/error/queryErrorCodes.es.js +2 -1
- package/dist/error/queryErrorCodes.es.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.es.js +35 -33
- package/dist/model/domainEventStream.cjs.map +1 -0
- package/dist/{client/query/event → model}/domainEventStream.d.cts +5 -1
- package/dist/{client/query/event → model}/domainEventStream.d.ts +5 -1
- package/dist/{client/query/event → model}/domainEventStream.es.js +1 -1
- package/dist/model/domainEventStream.es.js.map +1 -0
- package/dist/model/index.d.cts +2 -0
- package/dist/model/index.d.ts +2 -0
- package/dist/model/snapshot.cjs.map +1 -0
- package/dist/{client/query/snapshot → model}/snapshot.d.cts +3 -1
- package/dist/{client/query/snapshot → model}/snapshot.d.ts +3 -1
- package/dist/{client/query/snapshot → model}/snapshot.es.js +1 -1
- package/dist/model/snapshot.es.js.map +1 -0
- package/dist/transport/eventStreams.cjs +1 -1
- package/dist/transport/eventStreams.cjs.map +1 -1
- package/dist/transport/eventStreams.d.cts +3 -1
- package/dist/transport/eventStreams.d.ts +3 -1
- package/dist/transport/eventStreams.es.js +7 -4
- package/dist/transport/eventStreams.es.js.map +1 -1
- package/dist/v10/commands.cjs +2 -0
- package/dist/v10/commands.cjs.map +1 -0
- package/dist/v10/commands.d.cts +105 -0
- package/dist/v10/commands.d.ts +105 -0
- package/dist/v10/commands.es.js +68 -0
- package/dist/v10/commands.es.js.map +1 -0
- package/dist/v10/http.cjs +2 -0
- package/dist/v10/http.cjs.map +1 -0
- package/dist/v10/http.d.cts +87 -0
- package/dist/v10/http.d.ts +87 -0
- package/dist/v10/http.es.js +73 -0
- package/dist/v10/http.es.js.map +1 -0
- package/dist/v10/index.d.cts +19 -0
- package/dist/v10/index.d.ts +19 -0
- package/dist/v10/manifest.cjs +2 -0
- package/dist/v10/manifest.cjs.map +1 -0
- package/dist/v10/manifest.d.cts +109 -0
- package/dist/v10/manifest.d.ts +109 -0
- package/dist/v10/manifest.es.js +14 -0
- package/dist/v10/manifest.es.js.map +1 -0
- package/dist/v10/problem.cjs +2 -0
- package/dist/v10/problem.cjs.map +1 -0
- package/dist/v10/problem.d.cts +164 -0
- package/dist/v10/problem.d.ts +164 -0
- package/dist/v10/problem.es.js +119 -0
- package/dist/v10/problem.es.js.map +1 -0
- package/dist/v10/queries.cjs +2 -0
- package/dist/v10/queries.cjs.map +1 -0
- package/dist/v10/queries.d.cts +136 -0
- package/dist/v10/queries.d.ts +136 -0
- package/dist/v10/queries.es.js +88 -0
- package/dist/v10/queries.es.js.map +1 -0
- package/dist/v10/state.cjs +2 -0
- package/dist/v10/state.cjs.map +1 -0
- package/dist/v10/state.d.cts +53 -0
- package/dist/v10/state.d.ts +53 -0
- package/dist/v10/state.es.js +51 -0
- package/dist/v10/state.es.js.map +1 -0
- package/dist/v10/streams.cjs +2 -0
- package/dist/v10/streams.cjs.map +1 -0
- package/dist/v10/streams.d.cts +14 -0
- package/dist/v10/streams.d.ts +14 -0
- package/dist/v10/streams.es.js +22 -0
- package/dist/v10/streams.es.js.map +1 -0
- package/dist/v10/wait.cjs +2 -0
- package/dist/v10/wait.cjs.map +1 -0
- package/dist/v10/wait.d.cts +61 -0
- package/dist/v10/wait.d.ts +61 -0
- package/dist/v10/wait.es.js +44 -0
- package/dist/v10/wait.es.js.map +1 -0
- package/dist/v10/wire.cjs +2 -0
- package/dist/v10/wire.cjs.map +1 -0
- package/dist/v10/wire.d.cts +301 -0
- package/dist/v10/wire.d.ts +301 -0
- package/dist/v10/wire.es.js +10 -0
- package/dist/v10/wire.es.js.map +1 -0
- package/dist/v10.cjs +1 -0
- package/dist/v10.es.js +9 -0
- package/package.json +12 -2
- package/dist/client/query/event/domainEventStream.cjs.map +0 -1
- package/dist/client/query/event/domainEventStream.es.js.map +0 -1
- package/dist/client/query/snapshot/snapshot.cjs.map +0 -1
- package/dist/client/query/snapshot/snapshot.es.js.map +0 -1
- /package/dist/{client/query/event → model}/domainEventStream.cjs +0 -0
- /package/dist/{client/query/snapshot → model}/snapshot.cjs +0 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { toWowProblemError as e } from "./problem.es.js";
|
|
2
|
+
import { fetcher as t } from "@ahoo-wang/fetcher";
|
|
3
|
+
//#region src/v10/http.ts
|
|
4
|
+
var n = {
|
|
5
|
+
REQUEST_ID: "Wow-Request-Id",
|
|
6
|
+
WAIT: "Wow-Wait",
|
|
7
|
+
WAIT_TIMEOUT: "Wow-Wait-Timeout",
|
|
8
|
+
SCOPE: "Wow-Scope",
|
|
9
|
+
SPACE: "Wow-Space",
|
|
10
|
+
IF_MATCH: "If-Match",
|
|
11
|
+
IF_NONE_MATCH: "If-None-Match",
|
|
12
|
+
ETAG: "ETag",
|
|
13
|
+
RETRY_AFTER: "Retry-After"
|
|
14
|
+
};
|
|
15
|
+
function r(e) {
|
|
16
|
+
return `"${e.replace(/\\/g, "\\\\").replace(/"/g, "\\\"")}"`;
|
|
17
|
+
}
|
|
18
|
+
function i(e) {
|
|
19
|
+
let t = [
|
|
20
|
+
e.tenantId === void 0 ? void 0 : `tenant=${r(e.tenantId)}`,
|
|
21
|
+
e.ownerId === void 0 ? void 0 : `owner=${r(e.ownerId)}`,
|
|
22
|
+
e.spaceId === void 0 ? void 0 : `space=${r(e.spaceId)}`
|
|
23
|
+
].filter((e) => e !== void 0);
|
|
24
|
+
if (t.length === 0) throw TypeError("Wow-Scope names a tenant, an owner or a space.");
|
|
25
|
+
return t.join(", ");
|
|
26
|
+
}
|
|
27
|
+
function a(e, t) {
|
|
28
|
+
return e.replace(/\{([^}]+)\}/g, (n, r) => {
|
|
29
|
+
let i = t[r];
|
|
30
|
+
if (i === void 0 || i === "") throw TypeError(`The path ${e} needs ${r}.`);
|
|
31
|
+
return encodeURIComponent(i);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
function o(e) {
|
|
35
|
+
if (!e) return "";
|
|
36
|
+
let t = new URLSearchParams();
|
|
37
|
+
for (let [n, r] of Object.entries(e)) r !== void 0 && t.append(n, String(r));
|
|
38
|
+
let n = t.toString();
|
|
39
|
+
return n ? `?${n}` : "";
|
|
40
|
+
}
|
|
41
|
+
async function s(r, a) {
|
|
42
|
+
let s = a.options ?? {}, c = {};
|
|
43
|
+
for (let [e, t] of Object.entries({
|
|
44
|
+
...a.headers,
|
|
45
|
+
...s.scope === void 0 ? {} : { [n.SCOPE]: i(s.scope) },
|
|
46
|
+
...s.space === void 0 ? {} : { [n.SPACE]: s.space },
|
|
47
|
+
...s.headers
|
|
48
|
+
})) t !== void 0 && (c[e] = t);
|
|
49
|
+
let l = `${r.basePath ?? ""}${a.path}${o(a.query)}`;
|
|
50
|
+
try {
|
|
51
|
+
return await (r.fetcher ?? t).fetch(l, {
|
|
52
|
+
method: a.method,
|
|
53
|
+
headers: c,
|
|
54
|
+
...a.body === void 0 ? {} : { body: a.body },
|
|
55
|
+
...s.signal === void 0 ? {} : { signal: s.signal }
|
|
56
|
+
});
|
|
57
|
+
} catch (t) {
|
|
58
|
+
let n = t?.exchange?.response;
|
|
59
|
+
if (a.notModified && n?.status === 304) return n;
|
|
60
|
+
throw await e(t) ?? t;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function c(e) {
|
|
64
|
+
return await e.json();
|
|
65
|
+
}
|
|
66
|
+
function l(e) {
|
|
67
|
+
let t = e.headers.get(n.ETAG);
|
|
68
|
+
return t === null ? void 0 : t.replace(/^W\//, "").replace(/"/g, "");
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { n as WowV10Headers, l as entityTag, a as expandPath, i as formatScope, c as json, s as send };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=http.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.es.js","names":["defaultFetcher","WowV10Headers","quote","value","formatScope","members","scope","member","expandPath","path","params","name","queryString","query","text","send","options","call","headers","url","client","fetcher","error","response","toWowProblemError","json","entityTag","tag"],"sources":["../../src/v10/http.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { type Fetcher, fetcher as defaultFetcher } from '@ahoo-wang/fetcher';\nimport { toWowProblemError } from './problem.js';\n\n/**\n * The request headers of a Wow V10 service's public port (decisions D95,\n * D96, D98, D99).\n */\nexport const WowV10Headers = {\n /** The caller's id of the request: a retry with the same one is deduplicated. */\n REQUEST_ID: 'Wow-Request-Id',\n /** The wait plan (decision D99). */\n WAIT: 'Wow-Wait',\n /** How long to wait: `500ms`, `10s` or an ISO-8601 duration. */\n WAIT_TIMEOUT: 'Wow-Wait-Timeout',\n /** The scope to act in, for a caller allowed to act across scopes (decision D95). */\n SCOPE: 'Wow-Scope',\n /** The space, among the caller's own, to act in (decision D96). */\n SPACE: 'Wow-Space',\n /** The expected version of the aggregate, as an entity tag. */\n IF_MATCH: 'If-Match',\n /** The version, or descriptor version, a read already holds. */\n IF_NONE_MATCH: 'If-None-Match',\n /** The version of a state read, or of a query descriptor. */\n ETAG: 'ETag',\n /** The seconds after which a failed request may be retried. */\n RETRY_AFTER: 'Retry-After',\n} as const;\n\n/** How a V10 client reaches its service. */\nexport interface WowClientOptions {\n /**\n * The fetcher requests go through, with its base URL and interceptors\n * (authentication, say); the default fetcher when absent.\n */\n readonly fetcher?: Fetcher;\n /** A path put before every route, such as a gateway's prefix. */\n readonly basePath?: string;\n}\n\n/**\n * The scope a caller allowed to act across scopes acts in: the `Wow-Scope`\n * header (decision D95).\n */\nexport interface TargetScope {\n readonly tenantId?: string;\n readonly ownerId?: string;\n readonly spaceId?: string;\n}\n\nfunction quote(value: string): string {\n return `\"${value.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"')}\"`;\n}\n\n/**\n * A target scope as the `Wow-Scope` header spells it, an RFC 8941\n * dictionary: `tenant=\"t1\", owner=\"u1\", space=\"s1\"`.\n *\n * @param scope - The scope; at least one of its members is set\n */\nexport function formatScope(scope: TargetScope): string {\n const members = [\n scope.tenantId === undefined\n ? undefined\n : `tenant=${quote(scope.tenantId)}`,\n scope.ownerId === undefined ? undefined : `owner=${quote(scope.ownerId)}`,\n scope.spaceId === undefined ? undefined : `space=${quote(scope.spaceId)}`,\n ].filter(member => member !== undefined);\n if (members.length === 0) {\n throw new TypeError('Wow-Scope names a tenant, an owner or a space.');\n }\n return members.join(', ');\n}\n\n/** What every V10 request may carry beside its own parameters. */\nexport interface RequestOptions {\n /** The scope to act in (`Wow-Scope`), for a caller allowed to. */\n readonly scope?: TargetScope;\n /** The space to act in (`Wow-Space`), among the caller's own. */\n readonly space?: string;\n /** More headers: the request facts the service records, say. */\n readonly headers?: Readonly<Record<string, string>>;\n /** Cancels the request. */\n readonly signal?: AbortSignal;\n}\n\n/** One request of a V10 client. */\nexport interface Call {\n readonly method: 'GET' | 'POST' | 'DELETE';\n readonly path: string;\n readonly query?: Readonly<Record<string, string | number | undefined>>;\n readonly headers?: Readonly<Record<string, string | undefined>>;\n readonly body?: unknown;\n readonly options?: RequestOptions;\n /** Answers a 304 rather than rejecting with it. */\n readonly notModified?: boolean;\n}\n\n/** `{name}` segments of `path` filled from `params`, each encoded. */\nexport function expandPath(\n path: string,\n params: Readonly<Record<string, string>>,\n): string {\n return path.replace(/\\{([^}]+)\\}/g, (segment, name: string) => {\n const value = params[name];\n if (value === undefined || value === '') {\n throw new TypeError(`The path ${path} needs ${name}.`);\n }\n return encodeURIComponent(value);\n });\n}\n\nfunction queryString(\n query: Readonly<Record<string, string | number | undefined>> | undefined,\n): string {\n if (!query) return '';\n const params = new URLSearchParams();\n for (const [name, value] of Object.entries(query)) {\n if (value !== undefined) params.append(name, String(value));\n }\n const text = params.toString();\n return text ? `?${text}` : '';\n}\n\n/**\n * Sends one request through the client's fetcher and answers its response;\n * a response that is not 2xx rejects with a {@link WowProblemError}.\n *\n * @param client - The client's options\n * @param call - The request\n */\nexport async function send(\n client: WowClientOptions,\n call: Call,\n): Promise<Response> {\n const options = call.options ?? {};\n const headers: Record<string, string> = {};\n for (const [name, value] of Object.entries({\n ...call.headers,\n ...(options.scope === undefined\n ? {}\n : { [WowV10Headers.SCOPE]: formatScope(options.scope) }),\n ...(options.space === undefined\n ? {}\n : { [WowV10Headers.SPACE]: options.space }),\n ...options.headers,\n })) {\n if (value !== undefined) headers[name] = value;\n }\n const url = `${client.basePath ?? ''}${call.path}${queryString(call.query)}`;\n try {\n return await (client.fetcher ?? defaultFetcher).fetch(url, {\n method: call.method,\n headers,\n ...(call.body === undefined ? {} : { body: call.body as object }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n });\n } catch (error) {\n const response = (error as { exchange?: { response?: Response } })?.exchange\n ?.response;\n if (call.notModified && response?.status === 304) return response;\n throw (await toWowProblemError(error)) ?? error;\n }\n}\n\n/** The JSON body of a 2xx response. */\nexport async function json<T>(response: Response): Promise<T> {\n return (await response.json()) as T;\n}\n\n/** The entity tag of a response without its quotes or weak marker. */\nexport function entityTag(response: Response): string | undefined {\n const tag = response.headers.get(WowV10Headers.ETAG);\n return tag === null ? undefined : tag.replace(/^W\\//, '').replace(/\"/g, '');\n}\n"],"mappings":";;;AAoBA,IAAaC,IAAgB;CAE3B,YAAY;CAEZ,MAAM;CAEN,cAAc;CAEd,OAAO;CAEP,OAAO;CAEP,UAAU;CAEV,eAAe;CAEf,MAAM;CAEN,aAAa;AACf;AAuBA,SAASC,EAAM,GAAuB;CACpC,OAAO,IAAIC,EAAM,QAAQ,OAAO,MAAM,CAAC,CAAC,QAAQ,MAAM,MAAK,EAAE;AAC/D;AAQA,SAAgBC,EAAY,GAA4B;CACtD,IAAMC,IAAU;EACdC,EAAM,aAAa,KAAA,IACf,KAAA,IACA,UAAUJ,EAAMI,EAAM,QAAQ;EAClCA,EAAM,YAAY,KAAA,IAAY,KAAA,IAAY,SAASJ,EAAMI,EAAM,OAAO;EACtEA,EAAM,YAAY,KAAA,IAAY,KAAA,IAAY,SAASJ,EAAMI,EAAM,OAAO;CACxE,CAAC,CAAC,QAAO,MAAUC,MAAW,KAAA,CAAS;CACvC,IAAIF,EAAQ,WAAW,GACrB,MAAU,UAAU,gDAAgD;CAEtE,OAAOA,EAAQ,KAAK,IAAI;AAC1B;AA2BA,SAAgBG,EACd,GACA,GACQ;CACR,OAAOC,EAAK,QAAQ,iBAAiB,GAAS,MAAiB;EAC7D,IAAMN,IAAQO,EAAOC;EACrB,IAAIR,MAAU,KAAA,KAAaA,MAAU,IACnC,MAAU,UAAU,YAAYM,EAAK,SAASE,EAAK,EAAE;EAEvD,OAAO,mBAAmBR,CAAK;CACjC,CAAC;AACH;AAEA,SAASS,EACP,GACQ;CACR,IAAI,CAACC,GAAO,OAAO;CACnB,IAAMH,IAAS,IAAI,gBAAgB;CACnC,KAAK,IAAM,CAACC,GAAMR,MAAU,OAAO,QAAQU,CAAK,GAC9C,AAAIV,MAAU,KAAA,KAAWO,EAAO,OAAOC,GAAM,OAAOR,CAAK,CAAC;CAE5D,IAAMW,IAAOJ,EAAO,SAAS;CAC7B,OAAOI,IAAO,IAAIA,MAAS;AAC7B;AASA,eAAsBC,EACpB,GACA,GACmB;CACnB,IAAMC,IAAUC,EAAK,WAAW,CAAC,GAC3BC,IAAkC,CAAC;CACzC,KAAK,IAAM,CAACP,GAAMR,MAAU,OAAO,QAAQ;EACzC,GAAGc,EAAK;EACR,GAAID,EAAQ,UAAU,KAAA,IAClB,CAAC,IACD,GAAGf,EAAc,QAAQG,EAAYY,EAAQ,KAAK,EAAE;EACxD,GAAIA,EAAQ,UAAU,KAAA,IAClB,CAAC,IACD,GAAGf,EAAc,QAAQe,EAAQ,MAAM;EAC3C,GAAGA,EAAQ;CACb,CAAC,GACC,AAAIb,MAAU,KAAA,MAAW,EAAQQ,KAAQR;CAE3C,IAAMgB,IAAM,GAAGC,EAAO,YAAY,KAAKH,EAAK,OAAOL,EAAYK,EAAK,KAAK;CACzE,IAAI;EACF,OAAO,OAAOG,EAAO,WAAWpB,EAAAA,CAAgB,MAAMmB,GAAK;GACzD,QAAQF,EAAK;GACb;GACA,GAAIA,EAAK,SAAS,KAAA,IAAY,CAAC,IAAI,EAAE,MAAMA,EAAK,KAAe;GAC/D,GAAID,EAAQ,WAAW,KAAA,IAAY,CAAC,IAAI,EAAE,QAAQA,EAAQ,OAAO;EACnE,CAAC;CACH,SAASM,GAAO;EACd,IAAMC,IAAYD,GAAkD,UAChE;EACJ,IAAIL,EAAK,eAAeM,GAAU,WAAW,KAAK,OAAOA;EACzD,MAAO,MAAMC,EAAkBF,CAAK,KAAMA;CAC5C;AACF;AAGA,eAAsBG,EAAQ,GAAgC;CAC5D,OAAQ,MAAMF,EAAS,KAAK;AAC9B;AAGA,SAAgBG,EAAU,GAAwC;CAChE,IAAMC,IAAMJ,EAAS,QAAQ,IAAItB,EAAc,IAAI;CACnD,OAAO0B,MAAQ,OAAO,KAAA,IAAYA,EAAI,QAAQ,QAAQ,EAAE,CAAC,CAAC,QAAQ,MAAM,EAAE;AAC5E"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ahoo-wang/wow-client/v10`: the client of a Wow V10 service's public
|
|
3
|
+
* routes — commands with `Wow-Wait` and their event streams, state reads and
|
|
4
|
+
* traces, the snapshot, event and dataset query routes, the Manifest, and
|
|
5
|
+
* RFC 9457 problems as {@link WowProblemError}s with retry hints. Code
|
|
6
|
+
* `wow-generator` generates from a Manifest builds on it.
|
|
7
|
+
*
|
|
8
|
+
* It is additive: the root entry keeps serving Wow 9.x services. Build
|
|
9
|
+
* queries with the DSL of `@ahoo-wang/wow-client/dsl`.
|
|
10
|
+
*/
|
|
11
|
+
export { type ApplyTags, CommandGateway, type CommandOptions, commandSegment, type CreateCommandOptions, type LifecycleCommand, LifecycleCommands, type TransferOwner, type TransferSpace, } from './commands.cjs';
|
|
12
|
+
export { formatScope, type RequestOptions, type TargetScope, type WowClientOptions, WowV10Headers, } from './http.cjs';
|
|
13
|
+
export { type AggregateManifest, type CommandManifest, type ContextManifest, type Creation, type ErrorManifest, type EventManifest, fetchManifest, type Manifest, MANIFEST_FORMAT, type QueryManifest, type RouteManifest, type SubscriptionManifest, } from './manifest.cjs';
|
|
14
|
+
export * from './wire.cjs';
|
|
15
|
+
export { FRAMEWORK_ERROR_PREFIX, type FrameworkErrorCode, FrameworkErrorCodes, isProblem, parseRetryAfter, type Problem, PROBLEM_TYPE_PREFIX, readProblem, type RetryHint, retryHintOf, toWowProblemError, WowProblemError, } from './problem.cjs';
|
|
16
|
+
export { type CountQuery, type CountResult, DatasetClient, type DescriptorResult, EventQueryClient, type PagedQuery, type PagedResult, QueryModelClient, queryPath, SnapshotQueryClient, type TotalMode, } from './queries.cjs';
|
|
17
|
+
export { StateClient, type StateReadOptions, type StateReadResult, type StateTraceOptions, } from './state.cjs';
|
|
18
|
+
export { type CommandResultStream } from './streams.cjs';
|
|
19
|
+
export { formatHop, formatWaitPlan, formatWaitTimeout, SNAPSHOT_SUBSCRIPTION, wait, type WaitOptions, } from './wait.cjs';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@ahoo-wang/wow-client/v10`: the client of a Wow V10 service's public
|
|
3
|
+
* routes — commands with `Wow-Wait` and their event streams, state reads and
|
|
4
|
+
* traces, the snapshot, event and dataset query routes, the Manifest, and
|
|
5
|
+
* RFC 9457 problems as {@link WowProblemError}s with retry hints. Code
|
|
6
|
+
* `wow-generator` generates from a Manifest builds on it.
|
|
7
|
+
*
|
|
8
|
+
* It is additive: the root entry keeps serving Wow 9.x services. Build
|
|
9
|
+
* queries with the DSL of `@ahoo-wang/wow-client/dsl`.
|
|
10
|
+
*/
|
|
11
|
+
export { type ApplyTags, CommandGateway, type CommandOptions, commandSegment, type CreateCommandOptions, type LifecycleCommand, LifecycleCommands, type TransferOwner, type TransferSpace, } from './commands.js';
|
|
12
|
+
export { formatScope, type RequestOptions, type TargetScope, type WowClientOptions, WowV10Headers, } from './http.js';
|
|
13
|
+
export { type AggregateManifest, type CommandManifest, type ContextManifest, type Creation, type ErrorManifest, type EventManifest, fetchManifest, type Manifest, MANIFEST_FORMAT, type QueryManifest, type RouteManifest, type SubscriptionManifest, } from './manifest.js';
|
|
14
|
+
export * from './wire.js';
|
|
15
|
+
export { FRAMEWORK_ERROR_PREFIX, type FrameworkErrorCode, FrameworkErrorCodes, isProblem, parseRetryAfter, type Problem, PROBLEM_TYPE_PREFIX, readProblem, type RetryHint, retryHintOf, toWowProblemError, WowProblemError, } from './problem.js';
|
|
16
|
+
export { type CountQuery, type CountResult, DatasetClient, type DescriptorResult, EventQueryClient, type PagedQuery, type PagedResult, QueryModelClient, queryPath, SnapshotQueryClient, type TotalMode, } from './queries.js';
|
|
17
|
+
export { StateClient, type StateReadOptions, type StateReadResult, type StateTraceOptions, } from './state.js';
|
|
18
|
+
export { type CommandResultStream } from './streams.js';
|
|
19
|
+
export { formatHop, formatWaitPlan, formatWaitTimeout, SNAPSHOT_SUBSCRIPTION, wait, type WaitOptions, } from './wait.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.cjs","names":["json","send","require_http","MANIFEST_FORMAT","fetchManifest","client"],"sources":["../../src/v10/manifest.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n} from './http.js';\nimport type { Ownership } from './wire.js';\n\n/** A route of the Manifest: a method and a path, `{id}` the aggregate id. */\nexport interface RouteManifest {\n readonly method: string;\n readonly path: string;\n}\n\n/** Whether a command creates its aggregate. */\nexport type Creation = 'NONE' | 'REQUIRED' | 'ALLOWED';\n\n/** A command of an aggregate (decisions D104, D176, D182). */\nexport interface CommandManifest {\n readonly name: string;\n readonly aliases?: readonly string[];\n /** `#/$defs/<key>`. */\n readonly schema: string;\n readonly creation?: Creation;\n readonly produces?: readonly string[];\n readonly routes?: readonly RouteManifest[];\n readonly mounted?: boolean;\n readonly transformsTo?: readonly string[];\n}\n\n/** An event of an aggregate and its revision. */\nexport interface EventManifest {\n readonly name: string;\n readonly aliases?: readonly string[];\n readonly revision?: number;\n readonly schema: string;\n}\n\n/** A query model of an aggregate: `snapshot` or `events` (decision D128). */\nexport interface QueryManifest {\n readonly model: string;\n readonly routes?: readonly RouteManifest[];\n}\n\n/** An aggregate of a bounded context. */\nexport interface AggregateManifest {\n readonly name: string;\n readonly description?: string;\n readonly state: { readonly schema: string; readonly fingerprint?: string };\n readonly snapshot?: { readonly enabled?: boolean };\n readonly commands?: readonly CommandManifest[];\n readonly events?: readonly EventManifest[];\n readonly lifecycle?: readonly string[];\n readonly queries?: readonly QueryManifest[];\n readonly schedules?: readonly string[];\n readonly ownership?: Ownership;\n}\n\n/** A subscription of a bounded context (design 04 §1). */\nexport interface SubscriptionManifest {\n /** `processor.function`, as a `handled` hop names it. */\n readonly name: string;\n readonly kind: 'PROJECTION' | 'REACTOR' | 'SAGA';\n readonly source: {\n readonly context?: string;\n readonly aggregates?: readonly string[];\n readonly events?: readonly string[];\n };\n readonly derives?: readonly string[];\n readonly rejected?: readonly string[];\n readonly committed?: readonly string[];\n readonly [property: string]: unknown;\n}\n\n/** An error code and the HTTP status it is answered with. */\nexport interface ErrorManifest {\n readonly code: string;\n readonly status: number;\n readonly description?: string;\n}\n\n/** A bounded context of the Manifest. */\nexport interface ContextManifest {\n readonly name: string;\n readonly description?: string;\n readonly aggregates?: readonly AggregateManifest[];\n readonly subscriptions?: readonly SubscriptionManifest[];\n readonly published?: readonly {\n readonly aggregate: string;\n readonly topic: string;\n readonly includeState?: boolean;\n }[];\n readonly errors?: readonly ErrorManifest[];\n}\n\n/**\n * A service's Manifest (decisions D17, D73–D76): its contexts, aggregates,\n * commands, events, routes and error codes, and the JSON Schemas they refer\n * to under `$defs`. `wow-generator` generates typed clients from it.\n */\nexport interface Manifest {\n readonly format: number;\n readonly service?: { readonly name: string; readonly version?: string };\n readonly contexts: readonly ContextManifest[];\n readonly errors?: readonly ErrorManifest[];\n readonly $defs?: Readonly<Record<string, unknown>>;\n}\n\n/** The format of the Manifest this client reads. */\nexport const MANIFEST_FORMAT = 1;\n\n/**\n * The service's Manifest, `GET /wow/manifest`, authorized as any API.\n *\n * @param client - How the service is reached\n * @param options - Headers and cancellation\n */\nexport async function fetchManifest(\n client: WowClientOptions = {},\n options?: RequestOptions,\n): Promise<Manifest> {\n return json<Manifest>(\n await send(client, { method: 'GET', path: '/wow/manifest', options }),\n );\n}\n"],"mappings":"8BA0HA,IAAaG,EAAkB,EAQ/B,eAAsBC,EACpB,EAA2B,CAAC,EAC5B,EACmB,CACnB,OAAOJ,EAAAA,KACL,MAAMC,EAAAA,KAAKI,EAAQ,CAAE,OAAQ,MAAO,KAAM,gBAAiB,SAAQ,CAAC,CACtE,CACF"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { RequestOptions, WowClientOptions } from './http.cjs';
|
|
2
|
+
import { Ownership } from './wire.cjs';
|
|
3
|
+
/** A route of the Manifest: a method and a path, `{id}` the aggregate id. */
|
|
4
|
+
export interface RouteManifest {
|
|
5
|
+
readonly method: string;
|
|
6
|
+
readonly path: string;
|
|
7
|
+
}
|
|
8
|
+
/** Whether a command creates its aggregate. */
|
|
9
|
+
export type Creation = 'NONE' | 'REQUIRED' | 'ALLOWED';
|
|
10
|
+
/** A command of an aggregate (decisions D104, D176, D182). */
|
|
11
|
+
export interface CommandManifest {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly aliases?: readonly string[];
|
|
14
|
+
/** `#/$defs/<key>`. */
|
|
15
|
+
readonly schema: string;
|
|
16
|
+
readonly creation?: Creation;
|
|
17
|
+
readonly produces?: readonly string[];
|
|
18
|
+
readonly routes?: readonly RouteManifest[];
|
|
19
|
+
readonly mounted?: boolean;
|
|
20
|
+
readonly transformsTo?: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
/** An event of an aggregate and its revision. */
|
|
23
|
+
export interface EventManifest {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly aliases?: readonly string[];
|
|
26
|
+
readonly revision?: number;
|
|
27
|
+
readonly schema: string;
|
|
28
|
+
}
|
|
29
|
+
/** A query model of an aggregate: `snapshot` or `events` (decision D128). */
|
|
30
|
+
export interface QueryManifest {
|
|
31
|
+
readonly model: string;
|
|
32
|
+
readonly routes?: readonly RouteManifest[];
|
|
33
|
+
}
|
|
34
|
+
/** An aggregate of a bounded context. */
|
|
35
|
+
export interface AggregateManifest {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly description?: string;
|
|
38
|
+
readonly state: {
|
|
39
|
+
readonly schema: string;
|
|
40
|
+
readonly fingerprint?: string;
|
|
41
|
+
};
|
|
42
|
+
readonly snapshot?: {
|
|
43
|
+
readonly enabled?: boolean;
|
|
44
|
+
};
|
|
45
|
+
readonly commands?: readonly CommandManifest[];
|
|
46
|
+
readonly events?: readonly EventManifest[];
|
|
47
|
+
readonly lifecycle?: readonly string[];
|
|
48
|
+
readonly queries?: readonly QueryManifest[];
|
|
49
|
+
readonly schedules?: readonly string[];
|
|
50
|
+
readonly ownership?: Ownership;
|
|
51
|
+
}
|
|
52
|
+
/** A subscription of a bounded context (design 04 §1). */
|
|
53
|
+
export interface SubscriptionManifest {
|
|
54
|
+
/** `processor.function`, as a `handled` hop names it. */
|
|
55
|
+
readonly name: string;
|
|
56
|
+
readonly kind: 'PROJECTION' | 'REACTOR' | 'SAGA';
|
|
57
|
+
readonly source: {
|
|
58
|
+
readonly context?: string;
|
|
59
|
+
readonly aggregates?: readonly string[];
|
|
60
|
+
readonly events?: readonly string[];
|
|
61
|
+
};
|
|
62
|
+
readonly derives?: readonly string[];
|
|
63
|
+
readonly rejected?: readonly string[];
|
|
64
|
+
readonly committed?: readonly string[];
|
|
65
|
+
readonly [property: string]: unknown;
|
|
66
|
+
}
|
|
67
|
+
/** An error code and the HTTP status it is answered with. */
|
|
68
|
+
export interface ErrorManifest {
|
|
69
|
+
readonly code: string;
|
|
70
|
+
readonly status: number;
|
|
71
|
+
readonly description?: string;
|
|
72
|
+
}
|
|
73
|
+
/** A bounded context of the Manifest. */
|
|
74
|
+
export interface ContextManifest {
|
|
75
|
+
readonly name: string;
|
|
76
|
+
readonly description?: string;
|
|
77
|
+
readonly aggregates?: readonly AggregateManifest[];
|
|
78
|
+
readonly subscriptions?: readonly SubscriptionManifest[];
|
|
79
|
+
readonly published?: readonly {
|
|
80
|
+
readonly aggregate: string;
|
|
81
|
+
readonly topic: string;
|
|
82
|
+
readonly includeState?: boolean;
|
|
83
|
+
}[];
|
|
84
|
+
readonly errors?: readonly ErrorManifest[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A service's Manifest (decisions D17, D73–D76): its contexts, aggregates,
|
|
88
|
+
* commands, events, routes and error codes, and the JSON Schemas they refer
|
|
89
|
+
* to under `$defs`. `wow-generator` generates typed clients from it.
|
|
90
|
+
*/
|
|
91
|
+
export interface Manifest {
|
|
92
|
+
readonly format: number;
|
|
93
|
+
readonly service?: {
|
|
94
|
+
readonly name: string;
|
|
95
|
+
readonly version?: string;
|
|
96
|
+
};
|
|
97
|
+
readonly contexts: readonly ContextManifest[];
|
|
98
|
+
readonly errors?: readonly ErrorManifest[];
|
|
99
|
+
readonly $defs?: Readonly<Record<string, unknown>>;
|
|
100
|
+
}
|
|
101
|
+
/** The format of the Manifest this client reads. */
|
|
102
|
+
export declare const MANIFEST_FORMAT = 1;
|
|
103
|
+
/**
|
|
104
|
+
* The service's Manifest, `GET /wow/manifest`, authorized as any API.
|
|
105
|
+
*
|
|
106
|
+
* @param client - How the service is reached
|
|
107
|
+
* @param options - Headers and cancellation
|
|
108
|
+
*/
|
|
109
|
+
export declare function fetchManifest(client?: WowClientOptions, options?: RequestOptions): Promise<Manifest>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { RequestOptions, WowClientOptions } from './http.js';
|
|
2
|
+
import { Ownership } from './wire.js';
|
|
3
|
+
/** A route of the Manifest: a method and a path, `{id}` the aggregate id. */
|
|
4
|
+
export interface RouteManifest {
|
|
5
|
+
readonly method: string;
|
|
6
|
+
readonly path: string;
|
|
7
|
+
}
|
|
8
|
+
/** Whether a command creates its aggregate. */
|
|
9
|
+
export type Creation = 'NONE' | 'REQUIRED' | 'ALLOWED';
|
|
10
|
+
/** A command of an aggregate (decisions D104, D176, D182). */
|
|
11
|
+
export interface CommandManifest {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly aliases?: readonly string[];
|
|
14
|
+
/** `#/$defs/<key>`. */
|
|
15
|
+
readonly schema: string;
|
|
16
|
+
readonly creation?: Creation;
|
|
17
|
+
readonly produces?: readonly string[];
|
|
18
|
+
readonly routes?: readonly RouteManifest[];
|
|
19
|
+
readonly mounted?: boolean;
|
|
20
|
+
readonly transformsTo?: readonly string[];
|
|
21
|
+
}
|
|
22
|
+
/** An event of an aggregate and its revision. */
|
|
23
|
+
export interface EventManifest {
|
|
24
|
+
readonly name: string;
|
|
25
|
+
readonly aliases?: readonly string[];
|
|
26
|
+
readonly revision?: number;
|
|
27
|
+
readonly schema: string;
|
|
28
|
+
}
|
|
29
|
+
/** A query model of an aggregate: `snapshot` or `events` (decision D128). */
|
|
30
|
+
export interface QueryManifest {
|
|
31
|
+
readonly model: string;
|
|
32
|
+
readonly routes?: readonly RouteManifest[];
|
|
33
|
+
}
|
|
34
|
+
/** An aggregate of a bounded context. */
|
|
35
|
+
export interface AggregateManifest {
|
|
36
|
+
readonly name: string;
|
|
37
|
+
readonly description?: string;
|
|
38
|
+
readonly state: {
|
|
39
|
+
readonly schema: string;
|
|
40
|
+
readonly fingerprint?: string;
|
|
41
|
+
};
|
|
42
|
+
readonly snapshot?: {
|
|
43
|
+
readonly enabled?: boolean;
|
|
44
|
+
};
|
|
45
|
+
readonly commands?: readonly CommandManifest[];
|
|
46
|
+
readonly events?: readonly EventManifest[];
|
|
47
|
+
readonly lifecycle?: readonly string[];
|
|
48
|
+
readonly queries?: readonly QueryManifest[];
|
|
49
|
+
readonly schedules?: readonly string[];
|
|
50
|
+
readonly ownership?: Ownership;
|
|
51
|
+
}
|
|
52
|
+
/** A subscription of a bounded context (design 04 §1). */
|
|
53
|
+
export interface SubscriptionManifest {
|
|
54
|
+
/** `processor.function`, as a `handled` hop names it. */
|
|
55
|
+
readonly name: string;
|
|
56
|
+
readonly kind: 'PROJECTION' | 'REACTOR' | 'SAGA';
|
|
57
|
+
readonly source: {
|
|
58
|
+
readonly context?: string;
|
|
59
|
+
readonly aggregates?: readonly string[];
|
|
60
|
+
readonly events?: readonly string[];
|
|
61
|
+
};
|
|
62
|
+
readonly derives?: readonly string[];
|
|
63
|
+
readonly rejected?: readonly string[];
|
|
64
|
+
readonly committed?: readonly string[];
|
|
65
|
+
readonly [property: string]: unknown;
|
|
66
|
+
}
|
|
67
|
+
/** An error code and the HTTP status it is answered with. */
|
|
68
|
+
export interface ErrorManifest {
|
|
69
|
+
readonly code: string;
|
|
70
|
+
readonly status: number;
|
|
71
|
+
readonly description?: string;
|
|
72
|
+
}
|
|
73
|
+
/** A bounded context of the Manifest. */
|
|
74
|
+
export interface ContextManifest {
|
|
75
|
+
readonly name: string;
|
|
76
|
+
readonly description?: string;
|
|
77
|
+
readonly aggregates?: readonly AggregateManifest[];
|
|
78
|
+
readonly subscriptions?: readonly SubscriptionManifest[];
|
|
79
|
+
readonly published?: readonly {
|
|
80
|
+
readonly aggregate: string;
|
|
81
|
+
readonly topic: string;
|
|
82
|
+
readonly includeState?: boolean;
|
|
83
|
+
}[];
|
|
84
|
+
readonly errors?: readonly ErrorManifest[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* A service's Manifest (decisions D17, D73–D76): its contexts, aggregates,
|
|
88
|
+
* commands, events, routes and error codes, and the JSON Schemas they refer
|
|
89
|
+
* to under `$defs`. `wow-generator` generates typed clients from it.
|
|
90
|
+
*/
|
|
91
|
+
export interface Manifest {
|
|
92
|
+
readonly format: number;
|
|
93
|
+
readonly service?: {
|
|
94
|
+
readonly name: string;
|
|
95
|
+
readonly version?: string;
|
|
96
|
+
};
|
|
97
|
+
readonly contexts: readonly ContextManifest[];
|
|
98
|
+
readonly errors?: readonly ErrorManifest[];
|
|
99
|
+
readonly $defs?: Readonly<Record<string, unknown>>;
|
|
100
|
+
}
|
|
101
|
+
/** The format of the Manifest this client reads. */
|
|
102
|
+
export declare const MANIFEST_FORMAT = 1;
|
|
103
|
+
/**
|
|
104
|
+
* The service's Manifest, `GET /wow/manifest`, authorized as any API.
|
|
105
|
+
*
|
|
106
|
+
* @param client - How the service is reached
|
|
107
|
+
* @param options - Headers and cancellation
|
|
108
|
+
*/
|
|
109
|
+
export declare function fetchManifest(client?: WowClientOptions, options?: RequestOptions): Promise<Manifest>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { json as e, send as t } from "./http.es.js";
|
|
2
|
+
//#region src/v10/manifest.ts
|
|
3
|
+
var n = 1;
|
|
4
|
+
async function r(n = {}, r) {
|
|
5
|
+
return e(await t(n, {
|
|
6
|
+
method: "GET",
|
|
7
|
+
path: "/wow/manifest",
|
|
8
|
+
options: r
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { n as MANIFEST_FORMAT, r as fetchManifest };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=manifest.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.es.js","names":["MANIFEST_FORMAT","fetchManifest","json","send","client"],"sources":["../../src/v10/manifest.ts"],"sourcesContent":["/*\n * Copyright [2021-present] [ahoo wang <ahoowang@qq.com> (https://github.com/Ahoo-Wang)].\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n * http://www.apache.org/licenses/LICENSE-2.0\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n json,\n type RequestOptions,\n send,\n type WowClientOptions,\n} from './http.js';\nimport type { Ownership } from './wire.js';\n\n/** A route of the Manifest: a method and a path, `{id}` the aggregate id. */\nexport interface RouteManifest {\n readonly method: string;\n readonly path: string;\n}\n\n/** Whether a command creates its aggregate. */\nexport type Creation = 'NONE' | 'REQUIRED' | 'ALLOWED';\n\n/** A command of an aggregate (decisions D104, D176, D182). */\nexport interface CommandManifest {\n readonly name: string;\n readonly aliases?: readonly string[];\n /** `#/$defs/<key>`. */\n readonly schema: string;\n readonly creation?: Creation;\n readonly produces?: readonly string[];\n readonly routes?: readonly RouteManifest[];\n readonly mounted?: boolean;\n readonly transformsTo?: readonly string[];\n}\n\n/** An event of an aggregate and its revision. */\nexport interface EventManifest {\n readonly name: string;\n readonly aliases?: readonly string[];\n readonly revision?: number;\n readonly schema: string;\n}\n\n/** A query model of an aggregate: `snapshot` or `events` (decision D128). */\nexport interface QueryManifest {\n readonly model: string;\n readonly routes?: readonly RouteManifest[];\n}\n\n/** An aggregate of a bounded context. */\nexport interface AggregateManifest {\n readonly name: string;\n readonly description?: string;\n readonly state: { readonly schema: string; readonly fingerprint?: string };\n readonly snapshot?: { readonly enabled?: boolean };\n readonly commands?: readonly CommandManifest[];\n readonly events?: readonly EventManifest[];\n readonly lifecycle?: readonly string[];\n readonly queries?: readonly QueryManifest[];\n readonly schedules?: readonly string[];\n readonly ownership?: Ownership;\n}\n\n/** A subscription of a bounded context (design 04 §1). */\nexport interface SubscriptionManifest {\n /** `processor.function`, as a `handled` hop names it. */\n readonly name: string;\n readonly kind: 'PROJECTION' | 'REACTOR' | 'SAGA';\n readonly source: {\n readonly context?: string;\n readonly aggregates?: readonly string[];\n readonly events?: readonly string[];\n };\n readonly derives?: readonly string[];\n readonly rejected?: readonly string[];\n readonly committed?: readonly string[];\n readonly [property: string]: unknown;\n}\n\n/** An error code and the HTTP status it is answered with. */\nexport interface ErrorManifest {\n readonly code: string;\n readonly status: number;\n readonly description?: string;\n}\n\n/** A bounded context of the Manifest. */\nexport interface ContextManifest {\n readonly name: string;\n readonly description?: string;\n readonly aggregates?: readonly AggregateManifest[];\n readonly subscriptions?: readonly SubscriptionManifest[];\n readonly published?: readonly {\n readonly aggregate: string;\n readonly topic: string;\n readonly includeState?: boolean;\n }[];\n readonly errors?: readonly ErrorManifest[];\n}\n\n/**\n * A service's Manifest (decisions D17, D73–D76): its contexts, aggregates,\n * commands, events, routes and error codes, and the JSON Schemas they refer\n * to under `$defs`. `wow-generator` generates typed clients from it.\n */\nexport interface Manifest {\n readonly format: number;\n readonly service?: { readonly name: string; readonly version?: string };\n readonly contexts: readonly ContextManifest[];\n readonly errors?: readonly ErrorManifest[];\n readonly $defs?: Readonly<Record<string, unknown>>;\n}\n\n/** The format of the Manifest this client reads. */\nexport const MANIFEST_FORMAT = 1;\n\n/**\n * The service's Manifest, `GET /wow/manifest`, authorized as any API.\n *\n * @param client - How the service is reached\n * @param options - Headers and cancellation\n */\nexport async function fetchManifest(\n client: WowClientOptions = {},\n options?: RequestOptions,\n): Promise<Manifest> {\n return json<Manifest>(\n await send(client, { method: 'GET', path: '/wow/manifest', options }),\n );\n}\n"],"mappings":";;AA0HA,IAAaA,IAAkB;AAQ/B,eAAsBC,EACpB,IAA2B,CAAC,GAC5B,GACmB;CACnB,OAAOC,EACL,MAAMC,EAAKC,GAAQ;EAAE,QAAQ;EAAO,MAAM;EAAiB;CAAQ,CAAC,CACtE;AACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e={AUTH_UNAUTHENTICATED:`wow.auth.unauthenticated`,AUTH_FORBIDDEN:`wow.auth.forbidden`,AGGREGATE_FORBIDDEN:`wow.aggregate.forbidden`,COMMAND_MALFORMED:`wow.command.malformed`,COMMAND_INVALID:`wow.command.invalid`,WAIT_INVALID:`wow.wait.invalid`,COMMAND_UNHANDLED:`wow.command.unhandled`,AGGREGATE_NOT_FOUND:`wow.aggregate.not-found`,AGGREGATE_EXISTS:`wow.aggregate.exists`,AGGREGATE_VERSION_MISMATCH:`wow.aggregate.version-mismatch`,COMMAND_REQUEST_ID_REUSED:`wow.command.request-id-reused`,COMMAND_CONTENDED:`wow.command.contended`,AGGREGATE_DELETED:`wow.aggregate.deleted`,COMMAND_BUSY:`wow.command.busy`,COMMAND_UNKNOWN:`wow.command.unknown`,NODE_CLOSING:`wow.node.closing`,STORAGE_UNAVAILABLE:`wow.storage.unavailable`,SCHEDULE_NOT_DUE:`wow.schedule.not-due`,SCHEDULE_JOB_INVALID:`wow.schedule.job-invalid`,SUBSCRIPTION_PARKED:`wow.subscription.parked`,WAIT_TIMEOUT:`wow.wait.timeout`,QUERY_MALFORMED:`wow.query.malformed`,QUERY_INVALID:`wow.query.invalid`,QUERY_FAILED:`wow.query.failed`,QUERY_TIMEOUT:`wow.query.timeout`},t=`wow.`,n=`urn:wow:error:`,r=new Set([`type`,`title`,`status`,`detail`,`instance`,`code`,`violations`,`result`,`extensions`]);function i(e){if(e.extensions!==void 0)return e;let t=Object.fromEntries(Object.entries(e).filter(([e])=>!r.has(e)));return Object.keys(t).length===0?e:{...e,extensions:t}}var a=new Map([[e.COMMAND_UNKNOWN,!0],[e.NODE_CLOSING,!0],[e.STORAGE_UNAVAILABLE,!0],[e.SCHEDULE_NOT_DUE,!0],[e.QUERY_TIMEOUT,!1],[e.COMMAND_BUSY,!0],[e.COMMAND_CONTENDED,!0],[e.WAIT_TIMEOUT,!0]]);function o(e,t,n){let r=e===void 0?void 0:a.get(e),i=r!==void 0||e===void 0&&t===503;return{retryable:i,sameRequestId:r??i,...n===void 0?{}:{afterMs:n}}}var s=class extends Error{constructor(e,t={}){super(e.code?`[${e.code}] ${e.detail??e.title}`:`${e.status} ${e.detail??e.title}`),this.name=`WowProblemError`,this.problem=i(e),this.status=e.status,e.code!==void 0&&(this.code=e.code),this.violations=e.violations??[],e.result!==void 0&&(this.result=e.result),this.retry=o(e.code,e.status,t.retryAfterMs),t.cause!==void 0&&(this.cause=t.cause)}get isFramework(){return this.code?.startsWith(`wow.`)??!1}};function c(e){return typeof e==`object`&&!!e&&typeof e.status==`number`}function l(e,t=Date.now()){if(!e)return;let n=e.trim();if(/^\d+$/.test(n))return Number(n)*1e3;let r=Date.parse(n);return Number.isNaN(r)?void 0:Math.max(0,r-t)}async function u(e){let t;try{t=await e.clone().json()}catch{}if(c(t)){let n=t.code??(t.type?.startsWith(`urn:wow:error:`)?t.type.slice(14):void 0);return i({...t,type:t.type??`about:blank`,title:t.title??e.statusText,...n===void 0?{}:{code:n}})}return{type:`about:blank`,title:e.statusText,status:e.status}}async function d(e){if(e instanceof s)return e;if(typeof e!=`object`||!e)return;let{exchange:t,cause:n}=e;if(n instanceof s)return n;let r=t?.response;if(!r||r.ok)return;let i=await u(r),a=l(r.headers.get(`Retry-After`));return new s(i,{cause:e,...a===void 0?{}:{retryAfterMs:a}})}exports.FRAMEWORK_ERROR_PREFIX=t,exports.FrameworkErrorCodes=e,exports.PROBLEM_TYPE_PREFIX=n,exports.WowProblemError=s,exports.isProblem=c,exports.parseRetryAfter=l,exports.readProblem=u,exports.retryHintOf=o,exports.toWowProblemError=d;
|
|
2
|
+
//# sourceMappingURL=problem.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"problem.cjs","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,EAAsB,CAEjC,qBAAsB,2BAEtB,eAAgB,qBAEhB,oBAAqB,0BAErB,kBAAmB,wBAEnB,gBAAiB,sBAEjB,aAAc,mBAEd,kBAAmB,wBAEnB,oBAAqB,0BAErB,iBAAkB,uBAElB,2BAA4B,iCAE5B,0BAA2B,gCAE3B,kBAAmB,wBAEnB,kBAAmB,wBAEnB,aAAc,mBAEd,gBAAiB,sBAEjB,aAAc,mBAEd,oBAAqB,0BAErB,iBAAkB,uBAElB,qBAAsB,2BAEtB,oBAAqB,0BAErB,aAAc,mBAEd,gBAAiB,sBAEjB,cAAe,oBAEf,aAAc,mBAEd,cAAe,mBACjB,EAOaC,EAAyB,OAGzBC,EAAsB,iBA0B7BC,EAAuC,IAAI,IAAI,CACnD,OACA,QACA,SACA,SACA,WACA,OACA,aACA,SACA,YACF,CAAC,EAMD,SAASC,EAAe,EAA2B,CACjD,GAAIC,EAAQ,aAAe,IAAA,GAAW,OAAOA,EAC7C,IAAMC,EAAa,OAAO,YACxB,OAAO,QAAQD,CAAO,CAAC,CAAC,QAAQ,CAACE,KAAU,CAACJ,EAAgB,IAAII,CAAI,CAAC,CACvE,EACA,OAAO,OAAO,KAAKD,CAAU,CAAC,CAAC,SAAW,EACtCD,EACA,CAAE,GAAGA,EAAS,YAAW,CAC/B,CAsBA,IAAMG,EAA0C,IAAI,IAAI,CACtD,CAACR,EAAoB,gBAAiB,EAAI,EAC1C,CAACA,EAAoB,aAAc,EAAI,EACvC,CAACA,EAAoB,oBAAqB,EAAI,EAC9C,CAACA,EAAoB,iBAAkB,EAAI,EAC3C,CAACA,EAAoB,cAAe,EAAK,EACzC,CAACA,EAAoB,aAAc,EAAI,EACvC,CAACA,EAAoB,kBAAmB,EAAI,EAC5C,CAACA,EAAoB,aAAc,EAAI,CACzC,CAAC,EAUD,SAAgBS,EACd,EACA,EACA,EACW,CACX,IAAMC,EAAgBC,IAAS,IAAA,GAAY,IAAA,GAAYH,EAAU,IAAIG,CAAI,EACnEC,EACJF,IAAkB,IAAA,IAAcC,IAAS,IAAA,IAAaE,IAAW,IACnE,MAAO,CACL,YACA,cAAeH,GAAiBE,EAChC,GAAIE,IAAY,IAAA,GAAY,CAAC,EAAI,CAAE,SAAQ,CAC7C,CACF,CAOA,IAAaC,EAAb,cAAqC,KAAM,CAqBzC,YACE,EACA,EAAsD,CAAC,EACvD,CACA,MACEV,EAAQ,KACJ,IAAIA,EAAQ,KAAK,IAAIA,EAAQ,QAAUA,EAAQ,QAC/C,GAAGA,EAAQ,OAAO,GAAGA,EAAQ,QAAUA,EAAQ,OACrD,EA5BuB,KAAA,KAAA,kBA6BvB,KAAK,QAAUD,EAAeC,CAAO,EACrC,KAAK,OAASA,EAAQ,OAClBA,EAAQ,OAAS,IAAA,KAAW,KAAK,KAAOA,EAAQ,MACpD,KAAK,WAAaA,EAAQ,YAAc,CAAC,EACrCA,EAAQ,SAAW,IAAA,KAAW,KAAK,OAASA,EAAQ,QACxD,KAAK,MAAQI,EACXJ,EAAQ,KACRA,EAAQ,OACRW,EAAQ,YACV,EACIA,EAAQ,QAAU,IAAA,KAAW,KAAK,MAAQA,EAAQ,MACxD,CAGA,IAAI,aAAuB,CACzB,OAAO,KAAK,MAAM,WAAA,MAAiC,GAAK,EAC1D,CACF,EAGA,SAAgBC,EAAU,EAAkC,CAC1D,OACE,OAAOC,GAAU,YACjBA,GACA,OAAQA,EAA+B,QAAW,QAEtD,CAQA,SAAgBC,EACd,EACA,EAAc,KAAK,IAAI,EACH,CACpB,GAAI,CAACD,EAAO,OACZ,IAAME,EAAUF,EAAM,KAAK,EAC3B,GAAI,QAAQ,KAAKE,CAAO,EAAG,OAAO,OAAOA,CAAO,EAAI,IACpD,IAAMC,EAAO,KAAK,MAAMD,CAAO,EAC/B,OAAO,OAAO,MAAMC,CAAI,EAAI,IAAA,GAAY,KAAK,IAAI,EAAGA,EAAOC,CAAG,CAChE,CAQA,eAAsBC,EAAY,EAAsC,CACtE,IAAIC,EACJ,GAAI,CACF,EAAO,MAAMC,EAAS,MAAM,CAAC,CAAC,KAAK,CACrC,MAAQ,CAER,CACA,GAAIR,EAAUO,CAAI,EAAG,CACnB,IAAMb,EACJa,EAAK,OACJA,EAAK,MAAM,WAAA,gBAA8B,EACtCA,EAAK,KAAK,MAAM,EAA0B,EAC1C,IAAA,IACN,OAAOpB,EAAe,CACpB,GAAGoB,EACH,KAAMA,EAAK,MAAQ,cACnB,MAAOA,EAAK,OAASC,EAAS,WAC9B,GAAId,IAAS,IAAA,GAAY,CAAC,EAAI,CAAE,MAAK,CACvC,CAAC,CACH,CACA,MAAO,CACL,KAAM,cACN,MAAOc,EAAS,WAChB,OAAQA,EAAS,MACnB,CACF,CAcA,eAAsBC,EACpB,EACsC,CACtC,GAAIC,aAAiBZ,EAAiB,OAAOY,EAC7C,GAAI,OAAOA,GAAU,WAAYA,EAAgB,OACjD,GAAM,CAAE,WAAU,SAAUA,EAC5B,GAAIC,aAAiBb,EAAiB,OAAOa,EAC7C,IAAMH,EAAWI,GAAU,SAC3B,GAAI,CAACJ,GAAYA,EAAS,GAAI,OAC9B,IAAMpB,EAAU,MAAMkB,EAAYE,CAAQ,EACpCK,EAAeX,EAAgBM,EAAS,QAAQ,IAAI,aAAa,CAAC,EACxE,OAAO,IAAIV,EAAgBV,EAAS,CAClC,MAAOsB,EACP,GAAIG,IAAiB,IAAA,GAAY,CAAC,EAAI,CAAE,cAAa,CACvD,CAAC,CACH"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { CommandResult, Violation } from './wire.cjs';
|
|
2
|
+
/**
|
|
3
|
+
* The framework's error codes (design 05 §3, decisions D102, D103, D130),
|
|
4
|
+
* each answered with the status of the Manifest's `errors` table. A domain
|
|
5
|
+
* rejection has a code of its own, answered with 422 unless the service
|
|
6
|
+
* configures another status.
|
|
7
|
+
*/
|
|
8
|
+
export declare const FrameworkErrorCodes: {
|
|
9
|
+
/** 401: the request carries no valid credentials. */
|
|
10
|
+
readonly AUTH_UNAUTHENTICATED: "wow.auth.unauthenticated";
|
|
11
|
+
/** 403: the caller may not send this command. */
|
|
12
|
+
readonly AUTH_FORBIDDEN: "wow.auth.forbidden";
|
|
13
|
+
/** 403: the aggregate is outside the caller's scope. */
|
|
14
|
+
readonly AGGREGATE_FORBIDDEN: "wow.aggregate.forbidden";
|
|
15
|
+
/** 400: the command body cannot be read as the command type. */
|
|
16
|
+
readonly COMMAND_MALFORMED: "wow.command.malformed";
|
|
17
|
+
/** 400: the command failed validation; the problem lists the violations. */
|
|
18
|
+
readonly COMMAND_INVALID: "wow.command.invalid";
|
|
19
|
+
/** 400: the wait is not a chain the runtime can follow. */
|
|
20
|
+
readonly WAIT_INVALID: "wow.wait.invalid";
|
|
21
|
+
/** 400: the aggregate does not handle this command. */
|
|
22
|
+
readonly COMMAND_UNHANDLED: "wow.command.unhandled";
|
|
23
|
+
/** 404: the aggregate does not exist. */
|
|
24
|
+
readonly AGGREGATE_NOT_FOUND: "wow.aggregate.not-found";
|
|
25
|
+
/** 409: the aggregate already exists. */
|
|
26
|
+
readonly AGGREGATE_EXISTS: "wow.aggregate.exists";
|
|
27
|
+
/** 409, or 412 with `If-Match`: the aggregate is not at the expected version. */
|
|
28
|
+
readonly AGGREGATE_VERSION_MISMATCH: "wow.aggregate.version-mismatch";
|
|
29
|
+
/** 409: the request id was used by another command. */
|
|
30
|
+
readonly COMMAND_REQUEST_ID_REUSED: "wow.command.request-id-reused";
|
|
31
|
+
/** 409: concurrent writers kept winning; retrying with the same request id is safe. */
|
|
32
|
+
readonly COMMAND_CONTENDED: "wow.command.contended";
|
|
33
|
+
/** 410: the aggregate is deleted; only RestoreAggregate applies. */
|
|
34
|
+
readonly AGGREGATE_DELETED: "wow.aggregate.deleted";
|
|
35
|
+
/** 429: the node has too many commands in flight; retry later. */
|
|
36
|
+
readonly COMMAND_BUSY: "wow.command.busy";
|
|
37
|
+
/** 503: whether the command committed is unknown; retrying with the same request id is safe. */
|
|
38
|
+
readonly COMMAND_UNKNOWN: "wow.command.unknown";
|
|
39
|
+
/** 503: the node is shutting down; retry on another node. */
|
|
40
|
+
readonly NODE_CLOSING: "wow.node.closing";
|
|
41
|
+
/** 503, with `Retry-After`: a store could not be reached in time; retry later. */
|
|
42
|
+
readonly STORAGE_UNAVAILABLE: "wow.storage.unavailable";
|
|
43
|
+
/** 503: a scheduled command arrived too long before its due time; it is sent again later. */
|
|
44
|
+
readonly SCHEDULE_NOT_DUE: "wow.schedule.not-due";
|
|
45
|
+
/** 400: the job command does not fit its job or instance (decision D198). */
|
|
46
|
+
readonly SCHEDULE_JOB_INVALID: "wow.schedule.job-invalid";
|
|
47
|
+
/** 500: a subscription on the wait chain parked the aggregate. */
|
|
48
|
+
readonly SUBSCRIPTION_PARKED: "wow.subscription.parked";
|
|
49
|
+
/** 504: the wait ran out of time; the command may have committed. */
|
|
50
|
+
readonly WAIT_TIMEOUT: "wow.wait.timeout";
|
|
51
|
+
/** 400: the query body cannot be read as a query. */
|
|
52
|
+
readonly QUERY_MALFORMED: "wow.query.malformed";
|
|
53
|
+
/** 400: the query failed admission; each violation has its code. */
|
|
54
|
+
readonly QUERY_INVALID: "wow.query.invalid";
|
|
55
|
+
/** 500: the query backend failed to run the query. */
|
|
56
|
+
readonly QUERY_FAILED: "wow.query.failed";
|
|
57
|
+
/** 503: the query ran longer than its budget allows. */
|
|
58
|
+
readonly QUERY_TIMEOUT: "wow.query.timeout";
|
|
59
|
+
};
|
|
60
|
+
/** A {@link FrameworkErrorCodes} value. */
|
|
61
|
+
export type FrameworkErrorCode = (typeof FrameworkErrorCodes)[keyof typeof FrameworkErrorCodes];
|
|
62
|
+
/** The prefix of every framework code, and of no domain code. */
|
|
63
|
+
export declare const FRAMEWORK_ERROR_PREFIX = "wow.";
|
|
64
|
+
/** The prefix of a problem's `type` that carries a Wow code. */
|
|
65
|
+
export declare const PROBLEM_TYPE_PREFIX = "urn:wow:error:";
|
|
66
|
+
/**
|
|
67
|
+
* An RFC 9457 problem as a Wow V10 service writes it (decisions D101, D102):
|
|
68
|
+
* `type` is `urn:wow:error:<code>`, or `about:blank` for an error that is
|
|
69
|
+
* only HTTP's (a missing route, 406, 415).
|
|
70
|
+
*/
|
|
71
|
+
export interface Problem {
|
|
72
|
+
readonly type: string;
|
|
73
|
+
readonly title: string;
|
|
74
|
+
readonly status: number;
|
|
75
|
+
readonly detail?: string;
|
|
76
|
+
/** The Wow code; absent for an error that is only HTTP's. */
|
|
77
|
+
readonly code?: string;
|
|
78
|
+
readonly violations?: readonly Violation[];
|
|
79
|
+
/** The whole result of a command that has a ref. */
|
|
80
|
+
readonly result?: CommandResult;
|
|
81
|
+
/**
|
|
82
|
+
* The problem's extension members (RFC 9457): every member the server
|
|
83
|
+
* wrote besides the ones above and `instance`, such as a rejection's
|
|
84
|
+
* structured data (decision D211). Absent when it wrote none.
|
|
85
|
+
*/
|
|
86
|
+
readonly extensions?: Readonly<Record<string, unknown>>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* What a client may do about a failed request: whether retrying can succeed,
|
|
90
|
+
* whether to keep the request id (`Wow-Request-Id`) so the server
|
|
91
|
+
* deduplicates a command that did commit, and how long to wait first.
|
|
92
|
+
*/
|
|
93
|
+
export interface RetryHint {
|
|
94
|
+
readonly retryable: boolean;
|
|
95
|
+
/** Retry with the same `Wow-Request-Id`: a commit is then answered as a duplicate. */
|
|
96
|
+
readonly sameRequestId: boolean;
|
|
97
|
+
/** The server's `Retry-After`, in milliseconds. */
|
|
98
|
+
readonly afterMs?: number;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The retry hint of a problem with `code` and `status`: a code of the
|
|
102
|
+
* retryable table, or a 503 without a code (a proxy's), may be retried.
|
|
103
|
+
*
|
|
104
|
+
* @param code - The problem's Wow code, if any
|
|
105
|
+
* @param status - The HTTP status
|
|
106
|
+
* @param afterMs - The `Retry-After` the response carried, in milliseconds
|
|
107
|
+
*/
|
|
108
|
+
export declare function retryHintOf(code: string | undefined, status: number, afterMs?: number): RetryHint;
|
|
109
|
+
/**
|
|
110
|
+
* A request a Wow V10 service answered with a problem: a non-2xx response, a
|
|
111
|
+
* command result that did not succeed, or the `error` event that ends a
|
|
112
|
+
* streamed query.
|
|
113
|
+
*/
|
|
114
|
+
export declare class WowProblemError extends Error {
|
|
115
|
+
readonly name = "WowProblemError";
|
|
116
|
+
/** The problem as the server wrote it. */
|
|
117
|
+
readonly problem: Problem;
|
|
118
|
+
/** The HTTP status. */
|
|
119
|
+
readonly status: number;
|
|
120
|
+
/** The Wow code; absent for an error that is only HTTP's. */
|
|
121
|
+
readonly code?: string;
|
|
122
|
+
readonly violations: readonly Violation[];
|
|
123
|
+
/** The command's result, when the command had a ref. */
|
|
124
|
+
readonly result?: CommandResult;
|
|
125
|
+
/** What a client may do about it. */
|
|
126
|
+
readonly retry: RetryHint;
|
|
127
|
+
/** The error this one explains: the fetcher's, or the stream's. */
|
|
128
|
+
readonly cause?: unknown;
|
|
129
|
+
/**
|
|
130
|
+
* @param problem - The problem the server answered with
|
|
131
|
+
* @param options - The response's `Retry-After` in milliseconds, and the
|
|
132
|
+
* error this one explains
|
|
133
|
+
*/
|
|
134
|
+
constructor(problem: Problem, options?: {
|
|
135
|
+
retryAfterMs?: number;
|
|
136
|
+
cause?: unknown;
|
|
137
|
+
});
|
|
138
|
+
/** Whether the code is a framework one (`wow.*`) rather than the domain's. */
|
|
139
|
+
get isFramework(): boolean;
|
|
140
|
+
}
|
|
141
|
+
/** Whether `value` reads as a problem: an object with a numeric `status`. */
|
|
142
|
+
export declare function isProblem(value: unknown): value is Problem;
|
|
143
|
+
/**
|
|
144
|
+
* The milliseconds of a `Retry-After` header: delay seconds or an HTTP date.
|
|
145
|
+
*
|
|
146
|
+
* @param value - The header's value
|
|
147
|
+
* @param now - The current time, in epoch milliseconds
|
|
148
|
+
*/
|
|
149
|
+
export declare function parseRetryAfter(value: string | null | undefined, now?: number): number | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* The problem a response that did not succeed carries: its body when it is
|
|
152
|
+
* a problem (or a code the `type` names), else one made of its status.
|
|
153
|
+
*
|
|
154
|
+
* @param response - A response that is not 2xx
|
|
155
|
+
*/
|
|
156
|
+
export declare function readProblem(response: Response): Promise<Problem>;
|
|
157
|
+
/**
|
|
158
|
+
* The {@link WowProblemError} of an error a request rejected with: the
|
|
159
|
+
* fetcher's `ExchangeError` of a response that is not 2xx, read as a problem.
|
|
160
|
+
* Undefined for a failure no server answered (a network error, an abort).
|
|
161
|
+
*
|
|
162
|
+
* @param error - What the request rejected with
|
|
163
|
+
*/
|
|
164
|
+
export declare function toWowProblemError(error: unknown): Promise<WowProblemError | undefined>;
|