@ahoo-wang/wow-client 10.0.0-beta.1 → 10.0.0-beta.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/README.md +4 -2
- package/README.zh-CN.md +1 -1
- package/dist/commands.cjs +1 -1
- package/dist/commands.cjs.map +1 -1
- package/dist/commands.d.cts +1 -8
- package/dist/commands.d.ts +1 -8
- package/dist/commands.es.js +45 -51
- package/dist/commands.es.js.map +1 -1
- package/dist/dsl/aggregation/admit.cjs +1 -1
- package/dist/dsl/aggregation/admit.cjs.map +1 -1
- package/dist/dsl/aggregation/admit.es.js +73 -69
- package/dist/dsl/aggregation/admit.es.js.map +1 -1
- package/dist/dsl/aggregation/aliases.cjs +2 -0
- package/dist/dsl/aggregation/aliases.cjs.map +1 -0
- package/dist/dsl/aggregation/aliases.d.cts +2 -0
- package/dist/dsl/aggregation/aliases.d.ts +2 -0
- package/dist/dsl/aggregation/aliases.es.js +13 -0
- package/dist/dsl/aggregation/aliases.es.js.map +1 -0
- package/dist/dsl/aggregation/builders.cjs +1 -1
- package/dist/dsl/aggregation/builders.cjs.map +1 -1
- package/dist/dsl/aggregation/builders.d.cts +17 -243
- package/dist/dsl/aggregation/builders.d.ts +17 -243
- package/dist/dsl/aggregation/builders.es.js +36 -171
- 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 +123 -1
- package/dist/dsl/aggregation/derived.d.ts +123 -1
- package/dist/dsl/aggregation/derived.es.js +43 -28
- package/dist/dsl/aggregation/derived.es.js.map +1 -1
- package/dist/dsl/aggregation/groups.cjs +2 -0
- package/dist/dsl/aggregation/groups.cjs.map +1 -0
- package/dist/dsl/aggregation/groups.d.cts +325 -0
- package/dist/dsl/aggregation/groups.d.ts +325 -0
- package/dist/dsl/aggregation/groups.es.js +80 -0
- package/dist/dsl/aggregation/groups.es.js.map +1 -0
- package/dist/dsl/aggregation/having.cjs +1 -1
- package/dist/dsl/aggregation/having.cjs.map +1 -1
- package/dist/dsl/aggregation/having.d.cts +63 -1
- package/dist/dsl/aggregation/having.d.ts +63 -1
- package/dist/dsl/aggregation/having.es.js +33 -30
- package/dist/dsl/aggregation/having.es.js.map +1 -1
- package/dist/dsl/aggregation/index.d.cts +4 -2
- package/dist/dsl/aggregation/index.d.ts +4 -2
- package/dist/dsl/aggregation/metrics.cjs +2 -0
- package/dist/dsl/aggregation/metrics.cjs.map +1 -0
- package/dist/dsl/aggregation/metrics.d.cts +279 -0
- package/dist/dsl/aggregation/metrics.d.ts +279 -0
- package/dist/dsl/aggregation/metrics.es.js +75 -0
- package/dist/dsl/aggregation/metrics.es.js.map +1 -0
- package/dist/dsl/aggregation/types.cjs +1 -1
- package/dist/dsl/aggregation/types.cjs.map +1 -1
- package/dist/dsl/aggregation/types.d.cts +4 -524
- package/dist/dsl/aggregation/types.d.ts +4 -524
- package/dist/dsl/aggregation/types.es.js +5 -25
- package/dist/dsl/aggregation/types.es.js.map +1 -1
- package/dist/dsl/cursorQuery.cjs +1 -1
- package/dist/dsl/cursorQuery.cjs.map +1 -1
- package/dist/dsl/cursorQuery.d.cts +18 -7
- package/dist/dsl/cursorQuery.d.ts +18 -7
- package/dist/dsl/cursorQuery.es.js +13 -12
- package/dist/dsl/cursorQuery.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 +17 -379
- package/dist/dsl/descriptor.d.ts +17 -379
- package/dist/dsl/descriptor.es.js +4 -31
- package/dist/dsl/descriptor.es.js.map +1 -1
- package/dist/dsl/fieldDescriptor.cjs +2 -0
- package/dist/dsl/fieldDescriptor.cjs.map +1 -0
- package/dist/dsl/fieldDescriptor.d.cts +246 -0
- package/dist/dsl/fieldDescriptor.d.ts +246 -0
- package/dist/dsl/fieldDescriptor.es.js +24 -0
- package/dist/dsl/fieldDescriptor.es.js.map +1 -0
- package/dist/dsl/filter/builders.cjs +1 -1
- package/dist/dsl/filter/builders.cjs.map +1 -1
- package/dist/dsl/filter/builders.d.cts +7 -949
- package/dist/dsl/filter/builders.d.ts +7 -949
- package/dist/dsl/filter/builders.es.js +14 -285
- package/dist/dsl/filter/builders.es.js.map +1 -1
- package/dist/dsl/filter/expressionFilter.cjs +2 -0
- package/dist/dsl/filter/expressionFilter.cjs.map +1 -0
- package/dist/dsl/filter/expressionFilter.d.cts +35 -0
- package/dist/dsl/filter/expressionFilter.d.ts +35 -0
- package/dist/dsl/filter/expressionFilter.es.js +18 -0
- package/dist/dsl/filter/expressionFilter.es.js.map +1 -0
- package/dist/dsl/filter/fieldFilters.cjs +2 -0
- package/dist/dsl/filter/fieldFilters.cjs.map +1 -0
- package/dist/dsl/filter/fieldFilters.d.cts +297 -0
- package/dist/dsl/filter/fieldFilters.d.ts +297 -0
- package/dist/dsl/filter/fieldFilters.es.js +110 -0
- package/dist/dsl/filter/fieldFilters.es.js.map +1 -0
- package/dist/dsl/filter/index.d.cts +2 -1
- package/dist/dsl/filter/index.d.ts +2 -1
- package/dist/dsl/filter/logicalFilters.cjs +2 -0
- package/dist/dsl/filter/logicalFilters.cjs.map +1 -0
- package/dist/dsl/filter/logicalFilters.d.cts +109 -0
- package/dist/dsl/filter/logicalFilters.d.ts +109 -0
- package/dist/dsl/filter/logicalFilters.es.js +36 -0
- package/dist/dsl/filter/logicalFilters.es.js.map +1 -0
- package/dist/dsl/filter/metadataFilters.cjs +2 -0
- package/dist/dsl/filter/metadataFilters.cjs.map +1 -0
- package/dist/dsl/filter/metadataFilters.d.cts +132 -0
- package/dist/dsl/filter/metadataFilters.d.ts +132 -0
- package/dist/dsl/filter/metadataFilters.es.js +56 -0
- package/dist/dsl/filter/metadataFilters.es.js.map +1 -0
- package/dist/dsl/filter/operator.cjs +1 -1
- package/dist/dsl/filter/operator.cjs.map +1 -1
- package/dist/dsl/filter/operator.d.cts +11 -9
- package/dist/dsl/filter/operator.d.ts +11 -9
- package/dist/dsl/filter/operator.es.js +1 -1
- package/dist/dsl/filter/operator.es.js.map +1 -1
- package/dist/dsl/filter/searchFilter.cjs +2 -0
- package/dist/dsl/filter/searchFilter.cjs.map +1 -0
- package/dist/dsl/filter/searchFilter.d.cts +39 -0
- package/dist/dsl/filter/searchFilter.d.ts +39 -0
- package/dist/dsl/filter/searchFilter.es.js +19 -0
- package/dist/dsl/filter/searchFilter.es.js.map +1 -0
- package/dist/dsl/filter/timeFilters.cjs +2 -0
- package/dist/dsl/filter/timeFilters.cjs.map +1 -0
- package/dist/dsl/filter/timeFilters.d.cts +290 -0
- package/dist/dsl/filter/timeFilters.d.ts +290 -0
- package/dist/dsl/filter/timeFilters.es.js +89 -0
- package/dist/dsl/filter/timeFilters.es.js.map +1 -0
- package/dist/dsl/filter/types.d.cts +4 -14
- package/dist/dsl/filter/types.d.ts +4 -14
- package/dist/dsl/filter/validate.cjs +1 -1
- package/dist/dsl/filter/validate.cjs.map +1 -1
- package/dist/dsl/filter/validate.d.cts +2 -4
- package/dist/dsl/filter/validate.d.ts +2 -4
- package/dist/dsl/filter/validate.es.js +25 -31
- package/dist/dsl/filter/validate.es.js.map +1 -1
- package/dist/dsl/queryErrorCodes.cjs +1 -1
- package/dist/dsl/queryErrorCodes.cjs.map +1 -1
- package/dist/dsl/queryErrorCodes.d.cts +0 -2
- package/dist/dsl/queryErrorCodes.d.ts +0 -2
- package/dist/dsl/queryErrorCodes.es.js +0 -1
- package/dist/dsl/queryErrorCodes.es.js.map +1 -1
- package/dist/dsl/queryFilter.cjs +2 -0
- package/dist/dsl/queryFilter.cjs.map +1 -0
- package/dist/dsl/queryFilter.d.cts +3 -0
- package/dist/dsl/queryFilter.d.ts +3 -0
- package/dist/dsl/queryFilter.es.js +9 -0
- package/dist/dsl/queryFilter.es.js.map +1 -0
- package/dist/dsl/queryable.cjs +1 -1
- package/dist/dsl/queryable.cjs.map +1 -1
- package/dist/dsl/queryable.es.js +12 -16
- package/dist/dsl/queryable.es.js.map +1 -1
- package/dist/dsl/semanticTypes.cjs +2 -0
- package/dist/dsl/semanticTypes.cjs.map +1 -0
- package/dist/dsl/semanticTypes.d.cts +128 -0
- package/dist/dsl/semanticTypes.d.ts +128 -0
- package/dist/dsl/semanticTypes.es.js +13 -0
- package/dist/dsl/semanticTypes.es.js.map +1 -0
- package/dist/dsl.cjs +1 -1
- package/dist/dsl.d.cts +2 -0
- package/dist/dsl.d.ts +2 -0
- package/dist/dsl.es.js +14 -8
- package/dist/exactJson.cjs +2 -2
- package/dist/exactJson.cjs.map +1 -1
- package/dist/exactJson.d.cts +41 -16
- package/dist/exactJson.d.ts +41 -16
- package/dist/exactJson.es.js +104 -102
- package/dist/exactJson.es.js.map +1 -1
- package/dist/frameworkErrors.cjs.map +1 -1
- package/dist/frameworkErrors.d.cts +4 -4
- package/dist/frameworkErrors.d.ts +4 -4
- package/dist/frameworkErrors.es.js.map +1 -1
- package/dist/http.cjs +1 -1
- package/dist/http.cjs.map +1 -1
- package/dist/http.d.cts +29 -9
- package/dist/http.d.ts +29 -9
- package/dist/http.es.js +24 -19
- package/dist/http.es.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.es.js +12 -12
- package/dist/manifest.cjs +1 -1
- package/dist/manifest.cjs.map +1 -1
- package/dist/manifest.d.cts +24 -0
- package/dist/manifest.d.ts +24 -0
- package/dist/manifest.es.js +34 -6
- package/dist/manifest.es.js.map +1 -1
- package/dist/manifestTypes.d.cts +16 -1
- package/dist/manifestTypes.d.ts +16 -1
- package/dist/queries.cjs +1 -1
- package/dist/queries.cjs.map +1 -1
- package/dist/queries.d.cts +18 -8
- package/dist/queries.d.ts +18 -8
- package/dist/queries.es.js +46 -35
- package/dist/queries.es.js.map +1 -1
- package/dist/routes.cjs +1 -1
- package/dist/routes.cjs.map +1 -1
- package/dist/routes.d.cts +16 -3
- package/dist/routes.d.ts +16 -3
- package/dist/routes.es.js +24 -25
- package/dist/routes.es.js.map +1 -1
- package/dist/state.cjs +1 -1
- package/dist/state.cjs.map +1 -1
- package/dist/state.d.cts +21 -19
- package/dist/state.d.ts +21 -19
- package/dist/state.es.js +27 -22
- package/dist/state.es.js.map +1 -1
- package/dist/streams.cjs +1 -1
- package/dist/streams.cjs.map +1 -1
- package/dist/streams.d.cts +14 -7
- package/dist/streams.d.ts +14 -7
- package/dist/streams.es.js +65 -50
- package/dist/streams.es.js.map +1 -1
- package/dist/testing/wire.cjs +1 -1
- package/dist/testing/wire.cjs.map +1 -1
- package/dist/testing/wire.es.js +1 -1
- package/dist/testing/wire.es.js.map +1 -1
- package/dist/wait.cjs +1 -1
- package/dist/wait.cjs.map +1 -1
- package/dist/wait.d.cts +17 -4
- package/dist/wait.d.ts +17 -4
- package/dist/wait.es.js +36 -34
- package/dist/wait.es.js.map +1 -1
- package/dist/wire.cjs +1 -1
- package/dist/wire.cjs.map +1 -1
- package/dist/wire.d.cts +75 -31
- package/dist/wire.d.ts +75 -31
- package/dist/wire.es.js +1 -3
- package/dist/wire.es.js.map +1 -1
- package/package.json +5 -5
- package/dist/dsl/filter/datePattern.cjs +0 -2
- package/dist/dsl/filter/datePattern.cjs.map +0 -1
- package/dist/dsl/filter/datePattern.d.cts +0 -8
- package/dist/dsl/filter/datePattern.d.ts +0 -8
- package/dist/dsl/filter/datePattern.es.js +0 -96
- package/dist/dsl/filter/datePattern.es.js.map +0 -1
package/dist/exactJson.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exactJson.es.js","names":["BY","textNumbersBy","marksNothing","marks","Captured","text","child","name","define","key","target","value","resolve","index","object","by","discriminant","marksOf","Code","ESCAPES","Parser","capture","next","array","items","start","code","escape","hex","unescaped","first","exponent","sign","word","at","parseJson","JSON_NUMBER","stringifyJson","numbers","prefix","replaced","replace","placeholder","item","copy","eventNumbers","events","type"],"sources":["../src/exactJson.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 { AggregateType } from './wire.js';\n\n/**\n * Which numbers of a JSON value a client reads and writes as their exact\n * text: an `int64`, `bigint` or `decimal`\n * field of a Manifest, which JavaScript's `number` would round. The wire\n * keeps JSON numbers (decision D122); such a field is a `string` in the\n * generated types, its digits exactly as the server wrote them.\n *\n * - `true`: this value is such a number.\n * - An object: the marks of its members by name, `'*'` for every item of an\n * array and every value of a map.\n * - {@link textNumbersBy}: the marks of one member chosen by a sibling's\n * value, such as an event's `body` by its `name`.\n */\nexport type TextNumbers =\n true | TextNumbersByName | { readonly [member: string]: TextNumbers };\n\n/** The key of a {@link TextNumbersByName}: a symbol, so no member name is mistaken for it. */\nconst BY: unique symbol = Symbol('wow.textNumbersBy');\n\n/** The marks of one member of an object chosen by the value of another. */\nexport interface TextNumbersByName {\n readonly [BY]: {\n readonly discriminant: string;\n readonly member: string;\n readonly cases: Readonly<Record<string, TextNumbers>>;\n };\n}\n\n/**\n * The marks of `member` chosen by the string value of `discriminant`, its\n * sibling: `textNumbersBy('name', 'body', { 'shop.cart.ItemAdded': { price:\n * true } })` reads an event's body by the event's name.\n */\nexport function textNumbersBy(\n discriminant: string,\n member: string,\n cases: Readonly<Record<string, TextNumbers>>,\n): TextNumbersByName {\n return { [BY]: { discriminant, member, cases } };\n}\n\n/** Whether `marks` marks nothing, so plain `JSON.parse` reads the value. */\nexport function marksNothing(marks: TextNumbers | undefined): boolean {\n if (marks === undefined) return true;\n if (marks === true) return false;\n if (BY in marks) {\n return Object.values(marks[BY].cases).every(marksNothing);\n }\n return Object.values(marks).every(marksNothing);\n}\n\n/** A number of a captured member, kept as its text until its marks are known. */\nclass Captured {\n constructor(readonly text: string) {}\n}\n\n/** The marks of a member or item of a value marked `marks`. */\nfunction child(\n marks: TextNumbers | undefined,\n name: string,\n): TextNumbers | undefined {\n if (marks === undefined || marks === true || BY in marks) return undefined;\n return Object.prototype.hasOwnProperty.call(marks, name)\n ? marks[name]\n : Object.prototype.hasOwnProperty.call(marks, '*')\n ? marks['*']\n : undefined;\n}\n\n/** Sets a member as `JSON.parse` does: an own data property, `__proto__` too. */\nfunction define(target: Record<string, unknown>, key: string, value: unknown) {\n if (key === '__proto__') {\n Object.defineProperty(target, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n } else {\n target[key] = value;\n }\n}\n\n/** Resolves the numbers of a captured value against its now known marks. */\nfunction resolve(value: unknown, marks: TextNumbers | undefined): unknown {\n if (value instanceof Captured) {\n return marks === true ? value.text : Number(value.text);\n }\n if (Array.isArray(value)) {\n for (let index = 0; index < value.length; index++) {\n value[index] = resolve(value[index], child(marks, String(index)));\n }\n return value;\n }\n if (value !== null && typeof value === 'object') {\n const object = value as Record<string, unknown>;\n const by =\n marks !== undefined && marks !== true && BY in marks\n ? marks[BY]\n : undefined;\n const discriminant = by === undefined ? undefined : object[by.discriminant];\n for (const key of Object.keys(object)) {\n const marksOf =\n by === undefined\n ? child(marks, key)\n : key === by.member && typeof discriminant === 'string'\n ? by.cases[discriminant]\n : undefined;\n define(object, key, resolve(object[key], marksOf));\n }\n }\n return value;\n}\n\nconst Code = {\n TAB: 0x09,\n LF: 0x0a,\n CR: 0x0d,\n SPACE: 0x20,\n QUOTE: 0x22,\n PLUS: 0x2b,\n COMMA: 0x2c,\n MINUS: 0x2d,\n DOT: 0x2e,\n ZERO: 0x30,\n NINE: 0x39,\n COLON: 0x3a,\n UPPER_E: 0x45,\n OPEN_BRACKET: 0x5b,\n BACKSLASH: 0x5c,\n CLOSE_BRACKET: 0x5d,\n LOWER_E: 0x65,\n OPEN_BRACE: 0x7b,\n CLOSE_BRACE: 0x7d,\n} as const;\n\nconst ESCAPES: Readonly<Record<string, string>> = {\n '\"': '\"',\n '\\\\': '\\\\',\n '/': '/',\n b: '\\b',\n f: '\\f',\n n: '\\n',\n r: '\\r',\n t: '\\t',\n};\n\n/** A JSON text read as `JSON.parse` reads it, but for the numbers `marks` marks. */\nclass Parser {\n private at = 0;\n\n constructor(private readonly text: string) {}\n\n parse(marks: TextNumbers | undefined): unknown {\n this.skipSpaces();\n const value = this.value(marks, false);\n this.skipSpaces();\n if (this.at < this.text.length) this.fail();\n return value;\n }\n\n /** A value; `capture` keeps its numbers as {@link Captured} text. */\n private value(marks: TextNumbers | undefined, capture: boolean): unknown {\n const code = this.text.charCodeAt(this.at);\n switch (code) {\n case Code.OPEN_BRACE:\n return this.object(marks, capture);\n case Code.OPEN_BRACKET:\n return this.array(marks, capture);\n case Code.QUOTE:\n return this.string();\n case 0x74: // t\n return this.literal('true', true);\n case 0x66: // f\n return this.literal('false', false);\n case 0x6e: // n\n return this.literal('null', null);\n default: {\n const text = this.number();\n if (capture) return new Captured(text);\n return marks === true ? text : Number(text);\n }\n }\n }\n\n private object(marks: TextNumbers | undefined, capture: boolean): unknown {\n this.at++;\n const object: Record<string, unknown> = {};\n const by =\n !capture && marks !== undefined && marks !== true && BY in marks\n ? marks[BY]\n : undefined;\n this.skipSpaces();\n if (this.text.charCodeAt(this.at) === Code.CLOSE_BRACE) {\n this.at++;\n return object;\n }\n for (;;) {\n if (this.text.charCodeAt(this.at) !== Code.QUOTE) this.fail();\n const key = this.string();\n this.skipSpaces();\n this.expect(Code.COLON);\n this.skipSpaces();\n const member =\n by !== undefined && key === by.member\n ? this.value(undefined, true)\n : this.value(capture ? undefined : child(marks, key), capture);\n define(object, key, member);\n this.skipSpaces();\n const next = this.text.charCodeAt(this.at++);\n if (next === Code.CLOSE_BRACE) break;\n if (next !== Code.COMMA) this.fail(this.at - 1);\n this.skipSpaces();\n }\n if (\n by !== undefined &&\n Object.prototype.hasOwnProperty.call(object, by.member)\n ) {\n const discriminant = object[by.discriminant];\n define(\n object,\n by.member,\n resolve(\n object[by.member],\n typeof discriminant === 'string' ? by.cases[discriminant] : undefined,\n ),\n );\n }\n return object;\n }\n\n private array(marks: TextNumbers | undefined, capture: boolean): unknown[] {\n this.at++;\n const array: unknown[] = [];\n this.skipSpaces();\n if (this.text.charCodeAt(this.at) === Code.CLOSE_BRACKET) {\n this.at++;\n return array;\n }\n const items = capture ? undefined : child(marks, '*');\n for (;;) {\n array.push(this.value(items, capture));\n this.skipSpaces();\n const next = this.text.charCodeAt(this.at++);\n if (next === Code.CLOSE_BRACKET) return array;\n if (next !== Code.COMMA) this.fail(this.at - 1);\n this.skipSpaces();\n }\n }\n\n private string(): string {\n const text = this.text;\n let start = ++this.at;\n let value = '';\n for (;;) {\n const code = text.charCodeAt(this.at);\n if (code === Code.QUOTE) {\n value += text.slice(start, this.at++);\n return value;\n }\n if (code === Code.BACKSLASH) {\n value += text.slice(start, this.at);\n const escape = text[this.at + 1];\n if (escape === 'u') {\n const hex = text.slice(this.at + 2, this.at + 6);\n if (!/^[0-9a-fA-F]{4}$/.test(hex)) this.fail(this.at);\n value += String.fromCharCode(Number.parseInt(hex, 16));\n this.at += 6;\n } else {\n const unescaped = escape === undefined ? undefined : ESCAPES[escape];\n if (unescaped === undefined) this.fail(this.at);\n value += unescaped;\n this.at += 2;\n }\n start = this.at;\n } else if (code < Code.SPACE || Number.isNaN(code)) {\n this.fail();\n } else {\n this.at++;\n }\n }\n }\n\n /** The text of a number, checked against JSON's grammar. */\n private number(): string {\n const text = this.text;\n const start = this.at;\n if (text.charCodeAt(this.at) === Code.MINUS) this.at++;\n const first = text.charCodeAt(this.at);\n if (first === Code.ZERO) {\n this.at++;\n } else if (first > Code.ZERO && first <= Code.NINE) {\n this.digits();\n } else {\n this.fail();\n }\n if (text.charCodeAt(this.at) === Code.DOT) {\n this.at++;\n if (!this.digits()) this.fail();\n }\n const exponent = text.charCodeAt(this.at);\n if (exponent === Code.LOWER_E || exponent === Code.UPPER_E) {\n this.at++;\n const sign = text.charCodeAt(this.at);\n if (sign === Code.PLUS || sign === Code.MINUS) this.at++;\n if (!this.digits()) this.fail();\n }\n return text.slice(start, this.at);\n }\n\n /** Skips digits; whether there was one. */\n private digits(): boolean {\n const start = this.at;\n let code = this.text.charCodeAt(this.at);\n while (code >= Code.ZERO && code <= Code.NINE) {\n code = this.text.charCodeAt(++this.at);\n }\n return this.at > start;\n }\n\n private literal<T>(word: string, value: T): T {\n if (!this.text.startsWith(word, this.at)) this.fail();\n this.at += word.length;\n return value;\n }\n\n private skipSpaces(): void {\n let code = this.text.charCodeAt(this.at);\n while (\n code === Code.SPACE ||\n code === Code.LF ||\n code === Code.CR ||\n code === Code.TAB\n ) {\n code = this.text.charCodeAt(++this.at);\n }\n }\n\n private expect(code: number): void {\n if (this.text.charCodeAt(this.at) !== code) this.fail();\n this.at++;\n }\n\n private fail(at: number = this.at): never {\n throw new SyntaxError(\n at >= this.text.length\n ? 'Unexpected end of JSON input'\n : `Unexpected token in JSON at position ${at}`,\n );\n }\n}\n\n/**\n * `text` read as `JSON.parse` reads it, but each number `marks` marks comes\n * back as its exact text, a string. Without marks it is\n * `JSON.parse` itself. Malformed text throws a `SyntaxError`.\n */\nexport function parseJson(text: string, marks?: TextNumbers): unknown {\n if (marksNothing(marks)) return JSON.parse(text);\n return new Parser(text).parse(marks);\n}\n\n/** JSON's number grammar. */\nconst JSON_NUMBER = /^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$/;\n\n/**\n * `value` written as `JSON.stringify` writes it, but each string `marks`\n * marks goes on the wire as the JSON number it spells, unquoted: `{\"price\":\n * \"19.99\"}` marked `{price: true}` is `{\"price\":19.99}`.\n * A marked string that is not a JSON number is a `TypeError`.\n */\nexport function stringifyJson(value: unknown, marks?: TextNumbers): string {\n if (marksNothing(marks)) return JSON.stringify(value);\n const numbers: string[] = [];\n // A NUL and a fresh nonce: no string of the value is the placeholder.\n const prefix = `\\u0000wow-number-${Math.random().toString(36).slice(2)}:`;\n const replaced = replace(value, marks, numbers, prefix);\n const text = JSON.stringify(replaced);\n if (numbers.length === 0) return text;\n const placeholder = new RegExp(\n `\"${JSON.stringify(prefix).slice(1, -1).replace(/\\\\/g, '\\\\\\\\')}(\\\\d+)\"`,\n 'g',\n );\n return text.replace(\n placeholder,\n (_, index: string) => numbers[Number(index)]!,\n );\n}\n\n/**\n * A copy of `value` along the marked paths, each marked string replaced by a\n * placeholder of its number; everything else shared.\n */\nfunction replace(\n value: unknown,\n marks: TextNumbers | undefined,\n numbers: string[],\n prefix: string,\n): unknown {\n if (marks === undefined || value === null || value === undefined) {\n return value;\n }\n if (marks === true) {\n if (typeof value !== 'string') return value;\n if (!JSON_NUMBER.test(value)) {\n throw new TypeError(`Not a JSON number: [${value}].`);\n }\n numbers.push(value);\n return `${prefix}${numbers.length - 1}`;\n }\n if (Array.isArray(value)) {\n return value.map((item, index) =>\n replace(item, child(marks, String(index)), numbers, prefix),\n );\n }\n if (typeof value !== 'object') return value;\n const object = value as Record<string, unknown>;\n // `JSON.stringify` writes what `toJSON` returns (a `Date`, say): not a path.\n if (typeof object.toJSON === 'function') return value;\n const by = BY in marks ? marks[BY] : undefined;\n const discriminant = by === undefined ? undefined : object[by.discriminant];\n const copy: Record<string, unknown> = {};\n for (const key of Object.keys(object)) {\n const marksOf =\n by === undefined\n ? child(marks, key)\n : key === by.member && typeof discriminant === 'string'\n ? by.cases[discriminant]\n : undefined;\n define(copy, key, replace(object[key], marksOf, numbers, prefix));\n }\n return copy;\n}\n\n/**\n * The exact numbers ({@link TextNumbers}) of an aggregate type's events: each\n * event's `body` by its `name`.\n */\nexport function eventNumbers(type: AggregateType): TextNumbers | undefined {\n const events = type.textNumbers?.events;\n return events === undefined\n ? undefined\n : textNumbersBy('name', 'body', events);\n}\n"],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IAAI,OAAOQ,KAAU,UAAU,OAAOA;EACtC,IAAI,CAACyB,EAAY,KAAKzB,CAAK,GACzB,MAAU,UAAU,uBAAuBA,EAAM,GAAG;EAGtD,OADA2B,EAAQ,KAAK3B,CAAK,GACX,GAAG4B,IAASD,EAAQ,SAAS;CACtC;CACA,IAAI,MAAM,QAAQ3B,CAAK,GACrB,OAAOA,EAAM,KAAK,GAAM,MACtB8B,EAAQE,GAAMrC,EAAMH,GAAO,OAAOU,CAAK,CAAC,GAAGyB,GAASC,CAAM,CAC5D;CAEF,IAAI,OAAO5B,KAAU,UAAU,OAAOA;CACtC,IAAMG,IAASH;CAEf,IAAI,OAAOG,EAAO,UAAW,YAAY,OAAOH;CAChD,IAAMI,IAAKf,KAAMG,IAAQA,EAAMH,KAAM,KAAA,GAC/BgB,IAAeD,MAAO,KAAA,IAAY,KAAA,IAAYD,EAAOC,EAAG,eACxD6B,IAAgC,CAAC;CACvC,KAAK,IAAMnC,KAAO,OAAO,KAAKK,CAAM,GAAG;EACrC,IAAMG,IACJF,MAAO,KAAA,IACHT,EAAMH,GAAOM,CAAG,IAChBA,MAAQM,EAAG,UAAU,OAAOC,KAAiB,WAC3CD,EAAG,MAAMC,KACT,KAAA;EACR,EAAO4B,GAAMnC,GAAKgC,EAAQ3B,EAAOL,IAAMQ,GAASqB,GAASC,CAAM,CAAC;CAClE;CACA,OAAOK;AACT;AAMA,SAAgBC,EAAa,GAA8C;CACzE,IAAMC,IAASC,EAAK,aAAa;CACjC,OAAOD,MAAW,KAAA,IACd,KAAA,IACA7C,EAAc,QAAQ,QAAQ6C,CAAM;AAC1C"}
|
|
1
|
+
{"version":3,"file":"exactJson.es.js","names":["OR","BY","textNumberOr","marks","textNumbersBy","marksNothing","Captured","text","kind","own","object","value","mine","name","discriminant","cases","child","members","define","key","target","resolve","index","Code","ESCAPES","Parser","code","capture","array","open","close","items","next","start","escape","hex","unescaped","first","exponent","sign","word","at","parseJson","JSON_NUMBER","stringifyJson","numbers","prefix","replaced","replace","placeholder","item","copy","recordNumbers","marked","entry","eventNumbers","events","type","body"],"sources":["../src/exactJson.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 { AggregateType } from './wire.js';\n\n/**\n * Which numbers of a JSON value a client reads and writes as their exact\n * text: an `int64`, `bigint` or `decimal` field of a Manifest, which\n * JavaScript's `number` would round. The wire keeps JSON numbers (decision\n * D122); such a field is a `string` in the generated types, its digits\n * exactly as the server wrote them. A generated client carries the marks of\n * its Manifest; a hand-written one writes them in these forms:\n *\n * - `true`: this value is such a number — `{ price: true }`.\n * - Members: the marks of an object's members by name, `'*'` for every item\n * of an array and every value of a map — `{ lines: { '*': { amount: true } } }`.\n * - Lazy, `() => marks`: marks read only when a value reaches them, for a\n * recursive type — `const tree: TextNumbers = { amount: true, children:\n * { '*': () => tree } }`.\n * - {@link textNumberOr}: a number read exactly, or an object or array\n * marked as given — `textNumberOr({ amount: true })` for a `decimal |\n * { amount: decimal }`.\n * - {@link textNumbersBy}: the marks of an object chosen by the string value\n * of one of its members — `textNumbersBy('kind', { decimal: { amount: true\n * } })` for a union its `kind` tells apart.\n */\nexport type TextNumbers =\n | true\n | (() => TextNumbers)\n | TextNumbersOr\n | TextNumbersByName\n | { readonly [member: string]: TextNumbers };\n\n/** The key of a {@link TextNumbersOr}: a symbol, so no member name is mistaken for it. */\nconst OR: unique symbol = Symbol('wow.textNumberOr');\n\n/** The key of a {@link TextNumbersByName}: a symbol, so no member name is mistaken for it. */\nconst BY: unique symbol = Symbol('wow.textNumbersBy');\n\n/** A number read exactly, or an object or array marked as given: {@link textNumberOr}. */\nexport interface TextNumbersOr {\n readonly [OR]: TextNumbers;\n}\n\n/** The marks of an object chosen by the value of one of its members: {@link textNumbersBy}. */\nexport interface TextNumbersByName {\n readonly [BY]: {\n readonly discriminant: string;\n readonly cases: Readonly<Record<string, TextNumbers>>;\n };\n}\n\n/**\n * The marks of a value that is either an exact number or an object or array\n * marked `marks`: `textNumberOr({ amount: true })` reads `12.50` and\n * `{ \"amount\": 12.50 }` both as their text.\n */\nexport function textNumberOr(marks: TextNumbers): TextNumbersOr {\n return { [OR]: marks };\n}\n\n/**\n * The marks of an object chosen by the string value of its member\n * `discriminant`: `textNumbersBy('name', { 'shop.cart.ItemAdded': { body:\n * { price: true } } })` reads an event by its name. An object whose\n * discriminant names no case has no exact numbers.\n */\nexport function textNumbersBy(\n discriminant: string,\n cases: Readonly<Record<string, TextNumbers>>,\n): TextNumbersByName {\n return { [BY]: { discriminant, cases } };\n}\n\n/** Whether `marks` marks nothing, so plain `JSON.parse` reads the value. */\nexport function marksNothing(marks: TextNumbers | undefined): boolean {\n if (marks === undefined) return true;\n // A lazy mark is a recursive type's, which the generator writes only for a\n // type that marks something: following it could go round forever.\n if (marks === true || typeof marks === 'function' || OR in marks) {\n return false;\n }\n return Object.values(BY in marks ? marks[BY].cases : marks).every(\n marksNothing,\n );\n}\n\n/** A number of a captured object, kept as its text until its marks are known. */\nclass Captured {\n constructor(readonly text: string) {}\n}\n\n/**\n * The marks of a value of one kind, a number or else an object or array:\n * lazy marks read, and the side of a {@link textNumberOr} that kind takes.\n */\nfunction kind(\n marks: TextNumbers | undefined,\n compound: boolean,\n): TextNumbers | undefined {\n while (typeof marks === 'function') marks = marks();\n return marks !== undefined && marks !== true && OR in marks\n ? compound\n ? kind(marks[OR], true)\n : true\n : marks;\n}\n\n/** The marks of `value` itself: of its kind, and of its case where a member chooses it. */\nfunction own(\n marks: TextNumbers | undefined,\n value: unknown,\n): TextNumbers | undefined {\n const object = typeof value === 'object' && value !== null;\n const mine = kind(marks, object);\n if (mine === undefined || mine === true || !(BY in mine)) return mine;\n const { discriminant, cases } = mine[BY];\n const name = object\n ? (value as Record<string, unknown>)[discriminant]\n : undefined;\n return typeof name === 'string' &&\n Object.prototype.hasOwnProperty.call(cases, name)\n ? own(cases[name], value)\n : undefined;\n}\n\n/** The marks of a member or item, by name, of a value whose own marks are `marks`. */\nfunction child(\n marks: TextNumbers | undefined,\n name: string,\n): TextNumbers | undefined {\n if (marks === undefined || marks === true || typeof marks === 'function') {\n return undefined;\n }\n const members = marks as Readonly<Record<string, TextNumbers>>;\n return Object.prototype.hasOwnProperty.call(members, name)\n ? members[name]\n : Object.prototype.hasOwnProperty.call(members, '*')\n ? members['*']\n : undefined;\n}\n\n/** Sets a member as `JSON.parse` does: an own data property, `__proto__` too. */\nfunction define(target: Record<string, unknown>, key: string, value: unknown) {\n if (key === '__proto__') {\n Object.defineProperty(target, key, {\n value,\n writable: true,\n enumerable: true,\n configurable: true,\n });\n } else {\n target[key] = value;\n }\n}\n\n/** Resolves the numbers of a captured value against its now known marks. */\nfunction resolve(value: unknown, marks: TextNumbers | undefined): unknown {\n if (value instanceof Captured) {\n return kind(marks, false) === true ? value.text : Number(value.text);\n }\n const mine = own(marks, value);\n if (Array.isArray(value)) {\n for (let index = 0; index < value.length; index++) {\n value[index] = resolve(value[index], child(mine, String(index)));\n }\n } else if (value !== null && typeof value === 'object') {\n const object = value as Record<string, unknown>;\n for (const key of Object.keys(object)) {\n define(object, key, resolve(object[key], child(mine, key)));\n }\n }\n return value;\n}\n\nconst Code = {\n TAB: 0x09,\n LF: 0x0a,\n CR: 0x0d,\n SPACE: 0x20,\n QUOTE: 0x22,\n PLUS: 0x2b,\n COMMA: 0x2c,\n MINUS: 0x2d,\n DOT: 0x2e,\n ZERO: 0x30,\n NINE: 0x39,\n COLON: 0x3a,\n UPPER_E: 0x45,\n OPEN_BRACKET: 0x5b,\n BACKSLASH: 0x5c,\n CLOSE_BRACKET: 0x5d,\n LOWER_E: 0x65,\n OPEN_BRACE: 0x7b,\n CLOSE_BRACE: 0x7d,\n} as const;\n\nconst ESCAPES: Readonly<Record<string, string>> = {\n '\"': '\"',\n '\\\\': '\\\\',\n '/': '/',\n b: '\\b',\n f: '\\f',\n n: '\\n',\n r: '\\r',\n t: '\\t',\n};\n\n/** A JSON text read as `JSON.parse` reads it, but for the numbers `marks` marks. */\nclass Parser {\n private at = 0;\n\n constructor(private readonly text: string) {}\n\n parse(marks: TextNumbers | undefined): unknown {\n this.skipSpaces();\n const value = this.value(marks, false);\n this.skipSpaces();\n if (this.at < this.text.length) this.fail();\n return value;\n }\n\n /** A value; `capture` keeps its numbers as {@link Captured} text. */\n private value(marks: TextNumbers | undefined, capture: boolean): unknown {\n const code = this.text.charCodeAt(this.at);\n switch (code) {\n case Code.OPEN_BRACE:\n case Code.OPEN_BRACKET: {\n if (capture) return this.compound(code, undefined, true);\n const mine = kind(marks, true);\n // An object marked by a member's value is read whole, then marked.\n return mine !== undefined && mine !== true && BY in mine\n ? resolve(this.compound(code, undefined, true), mine)\n : this.compound(code, mine, false);\n }\n case Code.QUOTE:\n return this.string();\n case 0x74: // t\n return this.literal('true', true);\n case 0x66: // f\n return this.literal('false', false);\n case 0x6e: // n\n return this.literal('null', null);\n default: {\n const text = this.number();\n if (capture) return new Captured(text);\n return kind(marks, false) === true ? text : Number(text);\n }\n }\n }\n\n /** An object or an array whose own marks are `marks`. */\n private compound(\n open: number,\n marks: TextNumbers | undefined,\n capture: boolean,\n ): unknown {\n const array = open === Code.OPEN_BRACKET;\n const close = array ? Code.CLOSE_BRACKET : Code.CLOSE_BRACE;\n const items: unknown[] = [];\n const object: Record<string, unknown> = {};\n this.at++;\n this.skipSpaces();\n if (this.text.charCodeAt(this.at) === close) {\n this.at++;\n return array ? items : object;\n }\n for (;;) {\n if (array) {\n items.push(this.value(child(marks, '*'), capture));\n } else {\n if (this.text.charCodeAt(this.at) !== Code.QUOTE) this.fail();\n const key = this.string();\n this.skipSpaces();\n this.expect(Code.COLON);\n this.skipSpaces();\n define(object, key, this.value(child(marks, key), capture));\n }\n this.skipSpaces();\n const next = this.text.charCodeAt(this.at++);\n if (next === close) return array ? items : object;\n if (next !== Code.COMMA) this.fail(this.at - 1);\n this.skipSpaces();\n }\n }\n\n private string(): string {\n const text = this.text;\n let start = ++this.at;\n let value = '';\n for (;;) {\n const code = text.charCodeAt(this.at);\n if (code === Code.QUOTE) {\n value += text.slice(start, this.at++);\n return value;\n }\n if (code === Code.BACKSLASH) {\n value += text.slice(start, this.at);\n const escape = text[this.at + 1];\n if (escape === 'u') {\n const hex = text.slice(this.at + 2, this.at + 6);\n if (!/^[0-9a-fA-F]{4}$/.test(hex)) this.fail(this.at);\n value += String.fromCharCode(Number.parseInt(hex, 16));\n this.at += 6;\n } else {\n const unescaped = escape === undefined ? undefined : ESCAPES[escape];\n if (unescaped === undefined) this.fail(this.at);\n value += unescaped;\n this.at += 2;\n }\n start = this.at;\n } else if (code < Code.SPACE || Number.isNaN(code)) {\n this.fail();\n } else {\n this.at++;\n }\n }\n }\n\n /** The text of a number, checked against JSON's grammar. */\n private number(): string {\n const text = this.text;\n const start = this.at;\n if (text.charCodeAt(this.at) === Code.MINUS) this.at++;\n const first = text.charCodeAt(this.at);\n if (first === Code.ZERO) {\n this.at++;\n } else if (first > Code.ZERO && first <= Code.NINE) {\n this.digits();\n } else {\n this.fail();\n }\n if (text.charCodeAt(this.at) === Code.DOT) {\n this.at++;\n if (!this.digits()) this.fail();\n }\n const exponent = text.charCodeAt(this.at);\n if (exponent === Code.LOWER_E || exponent === Code.UPPER_E) {\n this.at++;\n const sign = text.charCodeAt(this.at);\n if (sign === Code.PLUS || sign === Code.MINUS) this.at++;\n if (!this.digits()) this.fail();\n }\n return text.slice(start, this.at);\n }\n\n /** Skips digits; whether there was one. */\n private digits(): boolean {\n const start = this.at;\n let code = this.text.charCodeAt(this.at);\n while (code >= Code.ZERO && code <= Code.NINE) {\n code = this.text.charCodeAt(++this.at);\n }\n return this.at > start;\n }\n\n private literal<T>(word: string, value: T): T {\n if (!this.text.startsWith(word, this.at)) this.fail();\n this.at += word.length;\n return value;\n }\n\n private skipSpaces(): void {\n let code = this.text.charCodeAt(this.at);\n while (\n code === Code.SPACE ||\n code === Code.LF ||\n code === Code.CR ||\n code === Code.TAB\n ) {\n code = this.text.charCodeAt(++this.at);\n }\n }\n\n private expect(code: number): void {\n if (this.text.charCodeAt(this.at) !== code) this.fail();\n this.at++;\n }\n\n private fail(at: number = this.at): never {\n throw new SyntaxError(\n at >= this.text.length\n ? 'Unexpected end of JSON input'\n : `Unexpected token in JSON at position ${at}`,\n );\n }\n}\n\n/**\n * `text` read as `JSON.parse` reads it, but each number `marks` marks comes\n * back as its exact text, a string. Without marks it is\n * `JSON.parse` itself. Malformed text throws a `SyntaxError`.\n */\nexport function parseJson(text: string, marks?: TextNumbers): unknown {\n if (marksNothing(marks)) return JSON.parse(text);\n return new Parser(text).parse(marks);\n}\n\n/** JSON's number grammar. */\nconst JSON_NUMBER = /^-?(?:0|[1-9]\\d*)(?:\\.\\d+)?(?:[eE][+-]?\\d+)?$/;\n\n/**\n * `value` written as `JSON.stringify` writes it, but each string `marks`\n * marks goes on the wire as the JSON number it spells, unquoted: `{\"price\":\n * \"19.99\"}` marked `{price: true}` is `{\"price\":19.99}`.\n * A marked string that is not a JSON number is a `TypeError`.\n */\nexport function stringifyJson(value: unknown, marks?: TextNumbers): string {\n if (marksNothing(marks)) return JSON.stringify(value);\n const numbers: string[] = [];\n // A NUL and a fresh nonce: no string of the value is the placeholder.\n const prefix = `\\u0000wow-number-${Math.random().toString(36).slice(2)}:`;\n const replaced = replace(value, marks, numbers, prefix);\n const text = JSON.stringify(replaced);\n if (numbers.length === 0) return text;\n const placeholder = new RegExp(\n `\"${JSON.stringify(prefix).slice(1, -1).replace(/\\\\/g, '\\\\\\\\')}(\\\\d+)\"`,\n 'g',\n );\n return text.replace(\n placeholder,\n (_, index: string) => numbers[Number(index)]!,\n );\n}\n\n/**\n * A copy of `value` along the marked paths, each marked string replaced by a\n * placeholder of its number; everything else shared.\n */\nfunction replace(\n value: unknown,\n marks: TextNumbers | undefined,\n numbers: string[],\n prefix: string,\n): unknown {\n const mine = own(marks, value);\n if (mine === undefined || value === null || value === undefined) {\n return value;\n }\n if (mine === true) {\n if (typeof value !== 'string') return value;\n if (!JSON_NUMBER.test(value)) {\n throw new TypeError(`Not a JSON number: [${value}].`);\n }\n numbers.push(value);\n return `${prefix}${numbers.length - 1}`;\n }\n if (Array.isArray(value)) {\n return value.map((item, index) =>\n replace(item, child(mine, String(index)), numbers, prefix),\n );\n }\n if (typeof value !== 'object') return value;\n const object = value as Record<string, unknown>;\n // `JSON.stringify` writes what `toJSON` returns (a `Date`, say): not a path.\n if (typeof object.toJSON === 'function') return value;\n const copy: Record<string, unknown> = {};\n for (const key of Object.keys(object)) {\n define(copy, key, replace(object[key], child(mine, key), numbers, prefix));\n }\n return copy;\n}\n\n/**\n * The marks of a record's `members` that mark something, by member, or\n * `undefined` when none does.\n */\nexport function recordNumbers(\n members: Readonly<Record<string, TextNumbers | undefined>>,\n): TextNumbers | undefined {\n const marked = Object.entries(members).filter(\n (entry): entry is [string, TextNumbers] => entry[1] !== undefined,\n );\n return marked.length === 0 ? undefined : Object.fromEntries(marked);\n}\n\n/**\n * The exact numbers ({@link TextNumbers}) of an aggregate type's events: each\n * event's `body` by its `name`.\n */\nexport function eventNumbers(type: AggregateType): TextNumbers | undefined {\n const events = type.textNumbers?.events;\n return events === undefined\n ? undefined\n : textNumbersBy(\n 'name',\n Object.fromEntries(\n Object.entries(events).map(([name, body]) => [name, { body }]),\n ),\n );\n}\n"],"mappings":";AA4CA,IAAMA,IAAoB,OAAO,kBAAkB,GAG7CC,IAAoB,OAAO,mBAAmB;AAoBpD,SAAgBC,EAAa,GAAmC;CAC9D,OAAO,GAAGF,IAAKG,EAAM;AACvB;AAQA,SAAgBC,EACd,GACA,GACmB;CACnB,O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,KAAKlC,CAAK,GACX,GAAGmC,IAASD,EAAQ,SAAS;CACtC;CACA,IAAI,MAAM,QAAQlC,CAAK,GACrB,OAAOA,EAAM,KAAK,GAAM,MACtBqC,EAAQE,GAAMlC,EAAMJ,GAAM,OAAOU,CAAK,CAAC,GAAGuB,GAASC,CAAM,CAC3D;CAEF,IAAI,OAAOnC,KAAU,UAAU,OAAOA;CACtC,IAAMD,IAASC;CAEf,IAAI,OAAOD,EAAO,UAAW,YAAY,OAAOC;CAChD,IAAMwC,IAAgC,CAAC;CACvC,KAAK,IAAMhC,KAAO,OAAO,KAAKT,CAAM,GAClC,EAAOyC,GAAMhC,GAAK6B,EAAQtC,EAAOS,IAAMH,EAAMJ,GAAMO,CAAG,GAAG0B,GAASC,CAAM,CAAC;CAE3E,OAAOK;AACT;AAMA,SAAgBC,EACd,GACyB;CACzB,IAAMC,IAAS,OAAO,QAAQpC,CAAO,CAAC,CAAC,QACpC,MAA0CqC,EAAM,OAAO,KAAA,CAC1D;CACA,OAAOD,EAAO,WAAW,IAAI,KAAA,IAAY,OAAO,YAAYA,CAAM;AACpE;AAMA,SAAgBE,EAAa,GAA8C;CACzE,IAAMC,IAASC,EAAK,aAAa;CACjC,OAAOD,MAAW,KAAA,IACd,KAAA,IACApD,EACE,QACA,OAAO,YACL,OAAO,QAAQoD,CAAM,CAAC,CAAC,KAAK,CAAC3C,GAAM6C,OAAU,CAAC7C,GAAM,EAAE,QAAK,CAAC,CAAC,CAC/D,CACF;AACN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frameworkErrors.cjs","names":["FrameworkErrorCodes","FRAMEWORK_RETRIES","DEFAULT_RETRY"],"sources":["../src/frameworkErrors.ts"],"sourcesContent":["// Code generated by scripts/framework-errors.mjs from the error catalog\n// (FrameworkErrors of :manifest, api/manifest/src/test/resources/framework-errors.json).\n// DO NOT EDIT: change FrameworkErrors and run the script.\n\n/**\n * What a retry of a request answered with an error may do, as the error\n * catalog declares it for the error's code and every problem carries it\n * (`retry`): `none`, a retry fails alike; `same-request`, send it again\n * with the same request id (`Wow-Request-Id`), so a command that did commit\n * is answered as its duplicate; `new-request`, send it again as it is.\n */\nexport type Retry = 'none' | 'same-request' | 'new-request';\n\n/**\n * The framework's error codes, each answered with the status of the error\n * catalog. A domain rejection has a code of its own, answered with 422 unless\n * the service configures another status.\n */\nexport const FrameworkErrorCodes = {\n /** 401 Unauthenticated: The request carries no valid credentials. */\n AUTH_UNAUTHENTICATED: 'wow.auth.unauthenticated',\n /** 403 Command forbidden: The caller may not send this command. */\n AUTH_FORBIDDEN: 'wow.auth.forbidden',\n /** 403 Aggregate out of scope: The aggregate is outside the caller's scope. */\n AGGREGATE_FORBIDDEN: 'wow.aggregate.forbidden',\n /** 400 Malformed request: A request header or parameter does not parse, or names what Wow does not take. */\n REQUEST_MALFORMED: 'wow.request.malformed',\n /** 400 Malformed command: The command body cannot be read as the command type. */\n COMMAND_MALFORMED: 'wow.command.malformed',\n /** 400 Invalid command: The command failed validation; the problem lists the violations. */\n COMMAND_INVALID: 'wow.command.invalid',\n /** 400 Invalid wait: The wait is not a chain the runtime can follow; the command was not run. */\n WAIT_INVALID: 'wow.wait.invalid',\n /** 400 Command not handled: The aggregate does not handle this command. */\n COMMAND_UNHANDLED: 'wow.command.unhandled',\n /** 404 Aggregate not found: The aggregate does not exist. */\n AGGREGATE_NOT_FOUND: 'wow.aggregate.not-found',\n /** 409 Aggregate exists: The aggregate already exists. */\n AGGREGATE_EXISTS: 'wow.aggregate.exists',\n /** 409 Version mismatch: The aggregate is not at the expected version (412 when the request carried If-Match). */\n AGGREGATE_VERSION_MISMATCH: 'wow.aggregate.version-mismatch',\n /** 409 Request id reused: The request id was used by another command. */\n COMMAND_REQUEST_ID_REUSED: 'wow.command.request-id-reused',\n /** 409 Command contended: Concurrent writers kept winning the version; retrying with the same request id is safe. */\n COMMAND_CONTENDED: 'wow.command.contended',\n /** 410 Aggregate deleted: The aggregate is deleted; only RestoreAggregate applies. */\n AGGREGATE_DELETED: 'wow.aggregate.deleted',\n /** 429 Command busy: The command was not taken: its aggregate has too many commands waiting, or the node too many in flight; retry later. */\n COMMAND_BUSY: 'wow.command.busy',\n /** 503 Command outcome unknown: Whether the command committed is unknown; retrying with the same request id is safe. */\n COMMAND_UNKNOWN: 'wow.command.unknown',\n /** 500 Command failed: The command's handling failed with an unexpected error; it committed nothing, and a retry fails alike. */\n COMMAND_FAILED: 'wow.command.failed',\n /** 409 Command refused: The aggregate's current state refuses the command (a check of its decide function); the message says why. */\n COMMAND_REFUSED: 'wow.command.refused',\n /** 500 Undeclared event: The command's handling produced an event its decide function or after hooks do not declare: a bug in the model, which the message names; it committed nothing. */\n COMMAND_UNDECLARED_EVENT: 'wow.command.undeclared-event',\n /** 503 Node closing: The node is shutting down; retry on another node. */\n NODE_CLOSING: 'wow.node.closing',\n /** 503 Node on standby: The node is on standby until the cut-over: it serves reads only. */\n NODE_STANDBY: 'wow.node.standby',\n /** 503 Storage unavailable: A store could not be reached or did not answer in time; retry later, a command with the same request id. */\n STORAGE_UNAVAILABLE: 'wow.storage.unavailable',\n /** 503 Schedule not due: A scheduled command arrived too long before its due time on this node's clock; it is sent again later. */\n SCHEDULE_NOT_DUE: 'wow.schedule.not-due',\n /** 400 Invalid schedule job: The job command does not fit its job or instance: an unknown job, another scope, or an instance not enabled. */\n SCHEDULE_JOB_INVALID: 'wow.schedule.job-invalid',\n /** 409 Stale ledger action: The action names a parking the entry no longer is: the aggregate was resolved and parked again since; read the entry again before acting on it. */\n LEDGER_STALE: 'wow.ledger.stale',\n /** 500 Subscription parked: A subscription on the wait chain parked the aggregate; the wait cannot be reached until the aggregate is retried. */\n SUBSCRIPTION_PARKED: 'wow.subscription.parked',\n /** 504 Wait timed out: The wait ran out of time; the command may have committed. The problem carries the last stage reached. */\n WAIT_TIMEOUT: 'wow.wait.timeout',\n /** 400 Malformed route request: A service route's parameter or body cannot be read as its type; the violation names the parameter. */\n ROUTE_MALFORMED: 'wow.route.malformed',\n /** 400 Malformed query: The query body cannot be read as a query. */\n QUERY_MALFORMED: 'wow.query.malformed',\n /** 400 Invalid query: The query failed admission; the problem lists the violations, each with its code (UNKNOWN_FIELD, ...). */\n QUERY_INVALID: 'wow.query.invalid',\n /** 500 Query failed: The query backend failed to run the query. */\n QUERY_FAILED: 'wow.query.failed',\n /** 404 No matching record: A single query matched no record: a query result, not a statement that an aggregate does not exist. */\n QUERY_NOT_FOUND: 'wow.query.not-found',\n /** 404 Dataset not found: No dataset of that name is served to the caller. */\n QUERY_DATASET_NOT_FOUND: 'wow.query.dataset-not-found',\n /** 400 Too many groups: An aggregation that names no sort has more groups than its limit; add a sort for a top-N, or raise limit. */\n QUERY_TOO_MANY_GROUPS: 'wow.query.too-many-groups',\n /** 504 Query timed out: The query ran longer than its budget allows; narrow it rather than run it again. */\n QUERY_TIMEOUT: 'wow.query.timeout',\n /** 409 Version not reached: The state read asked for a version the aggregate has not reached within the wait; the problem carries its current version: retry later. */\n QUERY_MIN_VERSION_NOT_REACHED: 'wow.query.min-version-not-reached',\n /** 429 Query busy: The query was not run: its store has as many queries running as it allows; retry later. */\n QUERY_BUSY: 'wow.query.busy',\n /** 409 Dataset unavailable: The dataset is served but cannot be queried now, for the reason the problem names (it needs revision). */\n QUERY_DATASET_UNAVAILABLE: 'wow.query.dataset-unavailable',\n /** 403 Call forbidden: The calling service may not call this command: its wow.callers.<service>.commands do not list it. */\n CALL_COMMAND_FORBIDDEN: 'wow.call.command-forbidden',\n /** 503 Peer unavailable: A client reached no node of the peer, or lost the connection before a query's answer; nothing was changed, so the request may be sent again. */\n PEER_UNAVAILABLE: 'wow.peer.unavailable',\n} as const;\n\n/** A {@link FrameworkErrorCodes} value. */\nexport type FrameworkErrorCode =\n (typeof FrameworkErrorCodes)[keyof typeof FrameworkErrorCodes];\n\n/** What a retry of a framework code may do, as the error catalog declares it. */\nexport interface FrameworkRetry {\n /** What a retry may do: never `none` here. */\n readonly retry: Retry;\n /** Its `Retry-After`, in milliseconds. */\n readonly retryAfterMs: number;\n}\n\n/**\n * What a retry may do of each framework code a retry may get past, by code;\n * a retry of every other code, a domain's among them, is `none`.\n */\nexport const FRAMEWORK_RETRIES: ReadonlyMap<string, FrameworkRetry> = new Map<\n string,\n FrameworkRetry\n>([\n ['wow.command.contended', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.command.busy', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.command.unknown', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.node.closing', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.node.standby', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.storage.unavailable', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.schedule.not-due', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.wait.timeout', { retry: 'same-request', retryAfterMs: 1000 }],\n [\n 'wow.query.min-version-not-reached',\n { retry: 'new-request', retryAfterMs: 1000 },\n ],\n ['wow.query.busy', { retry: 'new-request', retryAfterMs: 1000 }],\n ['wow.peer.unavailable', { retry: 'new-request', retryAfterMs: 1000 }],\n]);\n\n/**\n * How often, and after how long, a client sends a request again by default\n * when a retry may get past its error, as the Kotlin client does\n * (`RetryPolicy.DEFAULT`): at most `attempts` attempts, the first included,\n * `backoffMs` before the first retry without a `Retry-After`, doubled at each\n * attempt up to `maxWaitMs`.\n */\nexport const DEFAULT_RETRY = {\n attempts: 5,\n backoffMs: 200,\n maxWaitMs: 5000,\n} as const;\n"],"mappings":"AAkBA,IAAaA,EAAsB,CAEjC,qBAAsB,2BAEtB,eAAgB,qBAEhB,oBAAqB,0BAErB,kBAAmB,wBAEnB,kBAAmB,wBAEnB,gBAAiB,sBAEjB,aAAc,mBAEd,kBAAmB,wBAEnB,oBAAqB,0BAErB,iBAAkB,uBAElB,2BAA4B,iCAE5B,0BAA2B,gCAE3B,kBAAmB,wBAEnB,kBAAmB,wBAEnB,aAAc,mBAEd,gBAAiB,sBAEjB,eAAgB,qBAEhB,gBAAiB,sBAEjB,yBAA0B,+BAE1B,aAAc,mBAEd,aAAc,mBAEd,oBAAqB,0BAErB,iBAAkB,uBAElB,qBAAsB,2BAEtB,aAAc,mBAEd,oBAAqB,0BAErB,aAAc,mBAEd,gBAAiB,sBAEjB,gBAAiB,sBAEjB,cAAe,oBAEf,aAAc,mBAEd,gBAAiB,sBAEjB,wBAAyB,8BAEzB,sBAAuB,4BAEvB,cAAe,oBAEf,8BAA+B,oCAE/B,WAAY,iBAEZ,0BAA2B,gCAE3B,uBAAwB,6BAExB,iBAAkB,sBACpB,EAkBaC,EAAyD,IAAI,IAGxE,CACA,CAAC,wBAAyB,CAAE,MAAO,eAAgB,aAAc,GAAK,CAAC,EACvE,CAAC,mBAAoB,CAAE,MAAO,eAAgB,aAAc,GAAK,CAAC,EAClE,CAAC,sBAAuB,CAAE,MAAO,eAAgB,aAAc,GAAK,CAAC,EACrE,CAAC,mBAAoB,CAAE,MAAO,eAAgB,aAAc,GAAK,CAAC,EAClE,CAAC,mBAAoB,CAAE,MAAO,eAAgB,aAAc,GAAK,CAAC,EAClE,CAAC,0BAA2B,CAAE,MAAO,eAAgB,aAAc,GAAK,CAAC,EACzE,CAAC,uBAAwB,CAAE,MAAO,eAAgB,aAAc,GAAK,CAAC,EACtE,CAAC,mBAAoB,CAAE,MAAO,eAAgB,aAAc,GAAK,CAAC,EAClE,CACE,oCACA,CAAE,MAAO,cAAe,aAAc,GAAK,CAC7C,EACA,CAAC,iBAAkB,CAAE,MAAO,cAAe,aAAc,GAAK,CAAC,EAC/D,CAAC,uBAAwB,CAAE,MAAO,cAAe,aAAc,GAAK,CAAC,CACvE,CAAC,EASYC,EAAgB,CAC3B,SAAU,EACV,UAAW,IACX,UAAW,GACb,E"}
|
|
1
|
+
{"version":3,"file":"frameworkErrors.cjs","names":["FrameworkErrorCodes","FRAMEWORK_RETRIES","DEFAULT_RETRY"],"sources":["../src/frameworkErrors.ts"],"sourcesContent":["// Code generated by scripts/framework-errors.mjs from the error catalog\n// (FrameworkErrors of :manifest, api/manifest/src/test/resources/framework-errors.json).\n// DO NOT EDIT: change FrameworkErrors and run the script.\n\n/**\n * What a retry of a request answered with an error may do, as the error\n * catalog declares it for the error's code and every problem carries it\n * (`retry`): `none`, a retry fails alike; `same-request`, send it again\n * with the same request id (`Wow-Request-Id`), so a command that did commit\n * is answered as its duplicate; `new-request`, send it again as it is.\n */\nexport type Retry = 'none' | 'same-request' | 'new-request';\n\n/**\n * The framework's error codes, each answered with the status of the error\n * catalog. A domain rejection has a code of its own, answered with 422 unless\n * the service configures another status.\n */\nexport const FrameworkErrorCodes = {\n /** 401 Unauthenticated: The request carries no valid credentials. */\n AUTH_UNAUTHENTICATED: 'wow.auth.unauthenticated',\n /** 403 Forbidden: The caller may not do what the request asks: send this command, call this route, or act or read across scopes. */\n AUTH_FORBIDDEN: 'wow.auth.forbidden',\n /** 403 Aggregate change forbidden: The caller may read the aggregate but may not change it, or the command would create one outside the caller's reach. */\n AGGREGATE_FORBIDDEN: 'wow.aggregate.forbidden',\n /** 400 Malformed request: A request header or parameter does not parse, or names what Wow does not take. */\n REQUEST_MALFORMED: 'wow.request.malformed',\n /** 400 Malformed command: The command body cannot be read as the command type. */\n COMMAND_MALFORMED: 'wow.command.malformed',\n /** 400 Invalid command: The command failed validation; the problem lists the violations. */\n COMMAND_INVALID: 'wow.command.invalid',\n /** 400 Invalid wait: The wait is not a chain the runtime can follow; the command was not run. */\n WAIT_INVALID: 'wow.wait.invalid',\n /** 400 Command not handled: The aggregate does not handle this command. */\n COMMAND_UNHANDLED: 'wow.command.unhandled',\n /** 404 Aggregate not found: The aggregate does not exist, or is outside the caller's reach. */\n AGGREGATE_NOT_FOUND: 'wow.aggregate.not-found',\n /** 409 Aggregate exists: The aggregate already exists. */\n AGGREGATE_EXISTS: 'wow.aggregate.exists',\n /** 409 Version mismatch: The aggregate is not at the expected version (412 when the request carried If-Match). */\n AGGREGATE_VERSION_MISMATCH: 'wow.aggregate.version-mismatch',\n /** 409 Request id reused: The request id was used by another command. */\n COMMAND_REQUEST_ID_REUSED: 'wow.command.request-id-reused',\n /** 409 Command contended: Concurrent writers kept winning the version; retrying with the same request id is safe. */\n COMMAND_CONTENDED: 'wow.command.contended',\n /** 410 Aggregate deleted: The aggregate is deleted; only RestoreAggregate applies. */\n AGGREGATE_DELETED: 'wow.aggregate.deleted',\n /** 429 Command busy: The command was not taken: its aggregate has too many commands waiting, or the node too many in flight; retry later. */\n COMMAND_BUSY: 'wow.command.busy',\n /** 503 Command outcome unknown: Whether the command committed is unknown; retrying with the same request id is safe. */\n COMMAND_UNKNOWN: 'wow.command.unknown',\n /** 500 Command failed: The command's handling failed with an unexpected error; it committed nothing, and a retry fails alike. */\n COMMAND_FAILED: 'wow.command.failed',\n /** 409 Command refused: The aggregate's current state refuses the command (a check of its decide function); the message says why. */\n COMMAND_REFUSED: 'wow.command.refused',\n /** 500 Undeclared event: The command's handling produced an event its decide function or after hooks do not declare: a bug in the model, which the message names; it committed nothing. */\n COMMAND_UNDECLARED_EVENT: 'wow.command.undeclared-event',\n /** 503 Node closing: The node is shutting down; retry on another node. */\n NODE_CLOSING: 'wow.node.closing',\n /** 503 Node on standby: The node is on standby until the cut-over: it serves reads only. */\n NODE_STANDBY: 'wow.node.standby',\n /** 503 Storage unavailable: A store could not be reached or did not answer in time; retry later, a command with the same request id. */\n STORAGE_UNAVAILABLE: 'wow.storage.unavailable',\n /** 503 Schedule not due: A scheduled command arrived too long before its due time on this node's clock; it is sent again later. */\n SCHEDULE_NOT_DUE: 'wow.schedule.not-due',\n /** 400 Invalid schedule job: The job command does not fit its job or instance: an unknown job, another scope, or an instance not enabled. */\n SCHEDULE_JOB_INVALID: 'wow.schedule.job-invalid',\n /** 409 Stale ledger action: The action names a parking the entry no longer is: the aggregate was resolved and parked again since; read the entry again before acting on it. */\n LEDGER_STALE: 'wow.ledger.stale',\n /** 500 Subscription parked: A subscription on the wait chain parked the aggregate; the wait cannot be reached until the aggregate is retried. */\n SUBSCRIPTION_PARKED: 'wow.subscription.parked',\n /** 504 Wait timed out: The wait ran out of time; the command may have committed. The problem carries the last stage reached. */\n WAIT_TIMEOUT: 'wow.wait.timeout',\n /** 400 Malformed route request: A service route's parameter or body cannot be read as its type; the violation names the parameter. */\n ROUTE_MALFORMED: 'wow.route.malformed',\n /** 400 Malformed query: The query body cannot be read as a query. */\n QUERY_MALFORMED: 'wow.query.malformed',\n /** 400 Invalid query: The query failed admission; the problem lists the violations, each with its code (unknown-field, ...). */\n QUERY_INVALID: 'wow.query.invalid',\n /** 500 Query failed: The query backend failed to run the query. */\n QUERY_FAILED: 'wow.query.failed',\n /** 404 No matching record: A single query matched no record: a query result, not a statement that an aggregate does not exist. */\n QUERY_NOT_FOUND: 'wow.query.not-found',\n /** 404 Dataset not found: No dataset of that name is served to the caller. */\n QUERY_DATASET_NOT_FOUND: 'wow.query.dataset-not-found',\n /** 400 Too many groups: An aggregation that names no sort has more groups than its limit; add a sort for a top-N, or raise limit. */\n QUERY_TOO_MANY_GROUPS: 'wow.query.too-many-groups',\n /** 504 Query timed out: The query ran longer than its budget allows; narrow it rather than run it again. */\n QUERY_TIMEOUT: 'wow.query.timeout',\n /** 409 Version not reached: The state read asked for a version the aggregate has not reached within the wait; the problem carries its current version: retry later. */\n QUERY_MIN_VERSION_NOT_REACHED: 'wow.query.min-version-not-reached',\n /** 429 Query busy: The query was not run: its store has as many queries running as it allows; retry later. */\n QUERY_BUSY: 'wow.query.busy',\n /** 409 Dataset unavailable: The dataset is served but cannot be queried now, for the reason the problem names (it needs revision). */\n QUERY_DATASET_UNAVAILABLE: 'wow.query.dataset-unavailable',\n /** 403 Call forbidden: The calling service may not call this command: its wow.callers.<service>.commands do not list it. */\n CALL_COMMAND_FORBIDDEN: 'wow.call.command-forbidden',\n /** 503 Peer unavailable: A client reached no node of the peer, or lost the connection before a query's answer; nothing was changed, so the request may be sent again. */\n PEER_UNAVAILABLE: 'wow.peer.unavailable',\n} as const;\n\n/** A {@link FrameworkErrorCodes} value. */\nexport type FrameworkErrorCode =\n (typeof FrameworkErrorCodes)[keyof typeof FrameworkErrorCodes];\n\n/** What a retry of a framework code may do, as the error catalog declares it. */\nexport interface FrameworkRetry {\n /** What a retry may do: never `none` here. */\n readonly retry: Retry;\n /** Its `Retry-After`, in milliseconds. */\n readonly retryAfterMs: number;\n}\n\n/**\n * What a retry may do of each framework code a retry may get past, by code;\n * a retry of every other code, a domain's among them, is `none`.\n */\nexport const FRAMEWORK_RETRIES: ReadonlyMap<string, FrameworkRetry> = new Map<\n string,\n FrameworkRetry\n>([\n ['wow.command.contended', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.command.busy', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.command.unknown', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.node.closing', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.node.standby', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.storage.unavailable', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.schedule.not-due', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.wait.timeout', { retry: 'same-request', retryAfterMs: 1000 }],\n [\n 'wow.query.min-version-not-reached',\n { retry: 'new-request', retryAfterMs: 1000 },\n ],\n ['wow.query.busy', { retry: 'new-request', retryAfterMs: 1000 }],\n ['wow.peer.unavailable', { retry: 'new-request', retryAfterMs: 1000 }],\n]);\n\n/**\n * How often, and after how long, a client sends a request again by default\n * when a retry may get past its error, as the Kotlin client does\n * (`RetryPolicy.DEFAULT`): at most `attempts` attempts, the first included,\n * `backoffMs` before the first retry without a `Retry-After`, doubled at each\n * attempt up to `maxWaitMs`.\n */\nexport const DEFAULT_RETRY = {\n attempts: 5,\n backoffMs: 200,\n maxWaitMs: 5000,\n} as const;\n"],"mappings":"AAkBA,IAAaA,EAAsB,CAEjC,qBAAsB,2BAEtB,eAAgB,qBAEhB,oBAAqB,0BAErB,kBAAmB,wBAEnB,kBAAmB,wBAEnB,gBAAiB,sB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V,UAAW,IACX,UAAW,GACb,E"}
|
|
@@ -14,9 +14,9 @@ export type Retry = 'none' | 'same-request' | 'new-request';
|
|
|
14
14
|
export declare const FrameworkErrorCodes: {
|
|
15
15
|
/** 401 Unauthenticated: The request carries no valid credentials. */
|
|
16
16
|
readonly AUTH_UNAUTHENTICATED: "wow.auth.unauthenticated";
|
|
17
|
-
/** 403
|
|
17
|
+
/** 403 Forbidden: The caller may not do what the request asks: send this command, call this route, or act or read across scopes. */
|
|
18
18
|
readonly AUTH_FORBIDDEN: "wow.auth.forbidden";
|
|
19
|
-
/** 403 Aggregate
|
|
19
|
+
/** 403 Aggregate change forbidden: The caller may read the aggregate but may not change it, or the command would create one outside the caller's reach. */
|
|
20
20
|
readonly AGGREGATE_FORBIDDEN: "wow.aggregate.forbidden";
|
|
21
21
|
/** 400 Malformed request: A request header or parameter does not parse, or names what Wow does not take. */
|
|
22
22
|
readonly REQUEST_MALFORMED: "wow.request.malformed";
|
|
@@ -28,7 +28,7 @@ export declare const FrameworkErrorCodes: {
|
|
|
28
28
|
readonly WAIT_INVALID: "wow.wait.invalid";
|
|
29
29
|
/** 400 Command not handled: The aggregate does not handle this command. */
|
|
30
30
|
readonly COMMAND_UNHANDLED: "wow.command.unhandled";
|
|
31
|
-
/** 404 Aggregate not found: The aggregate does not exist. */
|
|
31
|
+
/** 404 Aggregate not found: The aggregate does not exist, or is outside the caller's reach. */
|
|
32
32
|
readonly AGGREGATE_NOT_FOUND: "wow.aggregate.not-found";
|
|
33
33
|
/** 409 Aggregate exists: The aggregate already exists. */
|
|
34
34
|
readonly AGGREGATE_EXISTS: "wow.aggregate.exists";
|
|
@@ -70,7 +70,7 @@ export declare const FrameworkErrorCodes: {
|
|
|
70
70
|
readonly ROUTE_MALFORMED: "wow.route.malformed";
|
|
71
71
|
/** 400 Malformed query: The query body cannot be read as a query. */
|
|
72
72
|
readonly QUERY_MALFORMED: "wow.query.malformed";
|
|
73
|
-
/** 400 Invalid query: The query failed admission; the problem lists the violations, each with its code (
|
|
73
|
+
/** 400 Invalid query: The query failed admission; the problem lists the violations, each with its code (unknown-field, ...). */
|
|
74
74
|
readonly QUERY_INVALID: "wow.query.invalid";
|
|
75
75
|
/** 500 Query failed: The query backend failed to run the query. */
|
|
76
76
|
readonly QUERY_FAILED: "wow.query.failed";
|
|
@@ -14,9 +14,9 @@ export type Retry = 'none' | 'same-request' | 'new-request';
|
|
|
14
14
|
export declare const FrameworkErrorCodes: {
|
|
15
15
|
/** 401 Unauthenticated: The request carries no valid credentials. */
|
|
16
16
|
readonly AUTH_UNAUTHENTICATED: "wow.auth.unauthenticated";
|
|
17
|
-
/** 403
|
|
17
|
+
/** 403 Forbidden: The caller may not do what the request asks: send this command, call this route, or act or read across scopes. */
|
|
18
18
|
readonly AUTH_FORBIDDEN: "wow.auth.forbidden";
|
|
19
|
-
/** 403 Aggregate
|
|
19
|
+
/** 403 Aggregate change forbidden: The caller may read the aggregate but may not change it, or the command would create one outside the caller's reach. */
|
|
20
20
|
readonly AGGREGATE_FORBIDDEN: "wow.aggregate.forbidden";
|
|
21
21
|
/** 400 Malformed request: A request header or parameter does not parse, or names what Wow does not take. */
|
|
22
22
|
readonly REQUEST_MALFORMED: "wow.request.malformed";
|
|
@@ -28,7 +28,7 @@ export declare const FrameworkErrorCodes: {
|
|
|
28
28
|
readonly WAIT_INVALID: "wow.wait.invalid";
|
|
29
29
|
/** 400 Command not handled: The aggregate does not handle this command. */
|
|
30
30
|
readonly COMMAND_UNHANDLED: "wow.command.unhandled";
|
|
31
|
-
/** 404 Aggregate not found: The aggregate does not exist. */
|
|
31
|
+
/** 404 Aggregate not found: The aggregate does not exist, or is outside the caller's reach. */
|
|
32
32
|
readonly AGGREGATE_NOT_FOUND: "wow.aggregate.not-found";
|
|
33
33
|
/** 409 Aggregate exists: The aggregate already exists. */
|
|
34
34
|
readonly AGGREGATE_EXISTS: "wow.aggregate.exists";
|
|
@@ -70,7 +70,7 @@ export declare const FrameworkErrorCodes: {
|
|
|
70
70
|
readonly ROUTE_MALFORMED: "wow.route.malformed";
|
|
71
71
|
/** 400 Malformed query: The query body cannot be read as a query. */
|
|
72
72
|
readonly QUERY_MALFORMED: "wow.query.malformed";
|
|
73
|
-
/** 400 Invalid query: The query failed admission; the problem lists the violations, each with its code (
|
|
73
|
+
/** 400 Invalid query: The query failed admission; the problem lists the violations, each with its code (unknown-field, ...). */
|
|
74
74
|
readonly QUERY_INVALID: "wow.query.invalid";
|
|
75
75
|
/** 500 Query failed: The query backend failed to run the query. */
|
|
76
76
|
readonly QUERY_FAILED: "wow.query.failed";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"frameworkErrors.es.js","names":["FrameworkErrorCodes","FRAMEWORK_RETRIES","DEFAULT_RETRY"],"sources":["../src/frameworkErrors.ts"],"sourcesContent":["// Code generated by scripts/framework-errors.mjs from the error catalog\n// (FrameworkErrors of :manifest, api/manifest/src/test/resources/framework-errors.json).\n// DO NOT EDIT: change FrameworkErrors and run the script.\n\n/**\n * What a retry of a request answered with an error may do, as the error\n * catalog declares it for the error's code and every problem carries it\n * (`retry`): `none`, a retry fails alike; `same-request`, send it again\n * with the same request id (`Wow-Request-Id`), so a command that did commit\n * is answered as its duplicate; `new-request`, send it again as it is.\n */\nexport type Retry = 'none' | 'same-request' | 'new-request';\n\n/**\n * The framework's error codes, each answered with the status of the error\n * catalog. A domain rejection has a code of its own, answered with 422 unless\n * the service configures another status.\n */\nexport const FrameworkErrorCodes = {\n /** 401 Unauthenticated: The request carries no valid credentials. */\n AUTH_UNAUTHENTICATED: 'wow.auth.unauthenticated',\n /** 403 Command forbidden: The caller may not send this command. */\n AUTH_FORBIDDEN: 'wow.auth.forbidden',\n /** 403 Aggregate out of scope: The aggregate is outside the caller's scope. */\n AGGREGATE_FORBIDDEN: 'wow.aggregate.forbidden',\n /** 400 Malformed request: A request header or parameter does not parse, or names what Wow does not take. */\n REQUEST_MALFORMED: 'wow.request.malformed',\n /** 400 Malformed command: The command body cannot be read as the command type. */\n COMMAND_MALFORMED: 'wow.command.malformed',\n /** 400 Invalid command: The command failed validation; the problem lists the violations. */\n COMMAND_INVALID: 'wow.command.invalid',\n /** 400 Invalid wait: The wait is not a chain the runtime can follow; the command was not run. */\n WAIT_INVALID: 'wow.wait.invalid',\n /** 400 Command not handled: The aggregate does not handle this command. */\n COMMAND_UNHANDLED: 'wow.command.unhandled',\n /** 404 Aggregate not found: The aggregate does not exist. */\n AGGREGATE_NOT_FOUND: 'wow.aggregate.not-found',\n /** 409 Aggregate exists: The aggregate already exists. */\n AGGREGATE_EXISTS: 'wow.aggregate.exists',\n /** 409 Version mismatch: The aggregate is not at the expected version (412 when the request carried If-Match). */\n AGGREGATE_VERSION_MISMATCH: 'wow.aggregate.version-mismatch',\n /** 409 Request id reused: The request id was used by another command. */\n COMMAND_REQUEST_ID_REUSED: 'wow.command.request-id-reused',\n /** 409 Command contended: Concurrent writers kept winning the version; retrying with the same request id is safe. */\n COMMAND_CONTENDED: 'wow.command.contended',\n /** 410 Aggregate deleted: The aggregate is deleted; only RestoreAggregate applies. */\n AGGREGATE_DELETED: 'wow.aggregate.deleted',\n /** 429 Command busy: The command was not taken: its aggregate has too many commands waiting, or the node too many in flight; retry later. */\n COMMAND_BUSY: 'wow.command.busy',\n /** 503 Command outcome unknown: Whether the command committed is unknown; retrying with the same request id is safe. */\n COMMAND_UNKNOWN: 'wow.command.unknown',\n /** 500 Command failed: The command's handling failed with an unexpected error; it committed nothing, and a retry fails alike. */\n COMMAND_FAILED: 'wow.command.failed',\n /** 409 Command refused: The aggregate's current state refuses the command (a check of its decide function); the message says why. */\n COMMAND_REFUSED: 'wow.command.refused',\n /** 500 Undeclared event: The command's handling produced an event its decide function or after hooks do not declare: a bug in the model, which the message names; it committed nothing. */\n COMMAND_UNDECLARED_EVENT: 'wow.command.undeclared-event',\n /** 503 Node closing: The node is shutting down; retry on another node. */\n NODE_CLOSING: 'wow.node.closing',\n /** 503 Node on standby: The node is on standby until the cut-over: it serves reads only. */\n NODE_STANDBY: 'wow.node.standby',\n /** 503 Storage unavailable: A store could not be reached or did not answer in time; retry later, a command with the same request id. */\n STORAGE_UNAVAILABLE: 'wow.storage.unavailable',\n /** 503 Schedule not due: A scheduled command arrived too long before its due time on this node's clock; it is sent again later. */\n SCHEDULE_NOT_DUE: 'wow.schedule.not-due',\n /** 400 Invalid schedule job: The job command does not fit its job or instance: an unknown job, another scope, or an instance not enabled. */\n SCHEDULE_JOB_INVALID: 'wow.schedule.job-invalid',\n /** 409 Stale ledger action: The action names a parking the entry no longer is: the aggregate was resolved and parked again since; read the entry again before acting on it. */\n LEDGER_STALE: 'wow.ledger.stale',\n /** 500 Subscription parked: A subscription on the wait chain parked the aggregate; the wait cannot be reached until the aggregate is retried. */\n SUBSCRIPTION_PARKED: 'wow.subscription.parked',\n /** 504 Wait timed out: The wait ran out of time; the command may have committed. The problem carries the last stage reached. */\n WAIT_TIMEOUT: 'wow.wait.timeout',\n /** 400 Malformed route request: A service route's parameter or body cannot be read as its type; the violation names the parameter. */\n ROUTE_MALFORMED: 'wow.route.malformed',\n /** 400 Malformed query: The query body cannot be read as a query. */\n QUERY_MALFORMED: 'wow.query.malformed',\n /** 400 Invalid query: The query failed admission; the problem lists the violations, each with its code (UNKNOWN_FIELD, ...). */\n QUERY_INVALID: 'wow.query.invalid',\n /** 500 Query failed: The query backend failed to run the query. */\n QUERY_FAILED: 'wow.query.failed',\n /** 404 No matching record: A single query matched no record: a query result, not a statement that an aggregate does not exist. */\n QUERY_NOT_FOUND: 'wow.query.not-found',\n /** 404 Dataset not found: No dataset of that name is served to the caller. */\n QUERY_DATASET_NOT_FOUND: 'wow.query.dataset-not-found',\n /** 400 Too many groups: An aggregation that names no sort has more groups than its limit; add a sort for a top-N, or raise limit. */\n QUERY_TOO_MANY_GROUPS: 'wow.query.too-many-groups',\n /** 504 Query timed out: The query ran longer than its budget allows; narrow it rather than run it again. */\n QUERY_TIMEOUT: 'wow.query.timeout',\n /** 409 Version not reached: The state read asked for a version the aggregate has not reached within the wait; the problem carries its current version: retry later. */\n QUERY_MIN_VERSION_NOT_REACHED: 'wow.query.min-version-not-reached',\n /** 429 Query busy: The query was not run: its store has as many queries running as it allows; retry later. */\n QUERY_BUSY: 'wow.query.busy',\n /** 409 Dataset unavailable: The dataset is served but cannot be queried now, for the reason the problem names (it needs revision). */\n QUERY_DATASET_UNAVAILABLE: 'wow.query.dataset-unavailable',\n /** 403 Call forbidden: The calling service may not call this command: its wow.callers.<service>.commands do not list it. */\n CALL_COMMAND_FORBIDDEN: 'wow.call.command-forbidden',\n /** 503 Peer unavailable: A client reached no node of the peer, or lost the connection before a query's answer; nothing was changed, so the request may be sent again. */\n PEER_UNAVAILABLE: 'wow.peer.unavailable',\n} as const;\n\n/** A {@link FrameworkErrorCodes} value. */\nexport type FrameworkErrorCode =\n (typeof FrameworkErrorCodes)[keyof typeof FrameworkErrorCodes];\n\n/** What a retry of a framework code may do, as the error catalog declares it. */\nexport interface FrameworkRetry {\n /** What a retry may do: never `none` here. */\n readonly retry: Retry;\n /** Its `Retry-After`, in milliseconds. */\n readonly retryAfterMs: number;\n}\n\n/**\n * What a retry may do of each framework code a retry may get past, by code;\n * a retry of every other code, a domain's among them, is `none`.\n */\nexport const FRAMEWORK_RETRIES: ReadonlyMap<string, FrameworkRetry> = new Map<\n string,\n FrameworkRetry\n>([\n ['wow.command.contended', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.command.busy', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.command.unknown', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.node.closing', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.node.standby', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.storage.unavailable', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.schedule.not-due', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.wait.timeout', { retry: 'same-request', retryAfterMs: 1000 }],\n [\n 'wow.query.min-version-not-reached',\n { retry: 'new-request', retryAfterMs: 1000 },\n ],\n ['wow.query.busy', { retry: 'new-request', retryAfterMs: 1000 }],\n ['wow.peer.unavailable', { retry: 'new-request', retryAfterMs: 1000 }],\n]);\n\n/**\n * How often, and after how long, a client sends a request again by default\n * when a retry may get past its error, as the Kotlin client does\n * (`RetryPolicy.DEFAULT`): at most `attempts` attempts, the first included,\n * `backoffMs` before the first retry without a `Retry-After`, doubled at each\n * attempt up to `maxWaitMs`.\n */\nexport const DEFAULT_RETRY = {\n attempts: 5,\n backoffMs: 200,\n maxWaitMs: 5000,\n} as const;\n"],"mappings":";AAkBA,IAAaA,IAAsB;CAEjC,sBAAsB;CAEtB,gBAAgB;CAEhB,qBAAqB;CAErB,mBAAmB;CAEnB,mBAAmB;CAEnB,iBAAiB;CAEjB,cAAc;CAEd,mBAAmB;CAEnB,qBAAqB;CAErB,kBAAkB;CAElB,4BAA4B;CAE5B,2BAA2B;CAE3B,mBAAmB;CAEnB,mBAAmB;CAEnB,cAAc;CAEd,iBAAiB;CAEjB,gBAAgB;CAEhB,iBAAiB;CAEjB,0BAA0B;CAE1B,cAAc;CAEd,cAAc;CAEd,qBAAqB;CAErB,kBAAkB;CAElB,sBAAsB;CAEtB,cAAc;CAEd,qBAAqB;CAErB,cAAc;CAEd,iBAAiB;CAEjB,iBAAiB;CAEjB,eAAe;CAEf,cAAc;CAEd,iBAAiB;CAEjB,yBAAyB;CAEzB,uBAAuB;CAEvB,eAAe;CAEf,+BAA+B;CAE/B,YAAY;CAEZ,2BAA2B;CAE3B,wBAAwB;CAExB,kBAAkB;AACpB,GAkBaC,oBAAyD,IAAI,IAGxE;CACA,CAAC,yBAAyB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CACvE,CAAC,oBAAoB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CAClE,CAAC,uBAAuB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CACrE,CAAC,oBAAoB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CAClE,CAAC,oBAAoB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CAClE,CAAC,2BAA2B;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CACzE,CAAC,wBAAwB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CACtE,CAAC,oBAAoB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CAClE,CACE,qCACA;EAAE,OAAO;EAAe,cAAc;CAAK,CAC7C;CACA,CAAC,kBAAkB;EAAE,OAAO;EAAe,cAAc;CAAK,CAAC;CAC/D,CAAC,wBAAwB;EAAE,OAAO;EAAe,cAAc;CAAK,CAAC;AACvE,CAAC,GASYC,IAAgB;CAC3B,UAAU;CACV,WAAW;CACX,WAAW;AACb"}
|
|
1
|
+
{"version":3,"file":"frameworkErrors.es.js","names":["FrameworkErrorCodes","FRAMEWORK_RETRIES","DEFAULT_RETRY"],"sources":["../src/frameworkErrors.ts"],"sourcesContent":["// Code generated by scripts/framework-errors.mjs from the error catalog\n// (FrameworkErrors of :manifest, api/manifest/src/test/resources/framework-errors.json).\n// DO NOT EDIT: change FrameworkErrors and run the script.\n\n/**\n * What a retry of a request answered with an error may do, as the error\n * catalog declares it for the error's code and every problem carries it\n * (`retry`): `none`, a retry fails alike; `same-request`, send it again\n * with the same request id (`Wow-Request-Id`), so a command that did commit\n * is answered as its duplicate; `new-request`, send it again as it is.\n */\nexport type Retry = 'none' | 'same-request' | 'new-request';\n\n/**\n * The framework's error codes, each answered with the status of the error\n * catalog. A domain rejection has a code of its own, answered with 422 unless\n * the service configures another status.\n */\nexport const FrameworkErrorCodes = {\n /** 401 Unauthenticated: The request carries no valid credentials. */\n AUTH_UNAUTHENTICATED: 'wow.auth.unauthenticated',\n /** 403 Forbidden: The caller may not do what the request asks: send this command, call this route, or act or read across scopes. */\n AUTH_FORBIDDEN: 'wow.auth.forbidden',\n /** 403 Aggregate change forbidden: The caller may read the aggregate but may not change it, or the command would create one outside the caller's reach. */\n AGGREGATE_FORBIDDEN: 'wow.aggregate.forbidden',\n /** 400 Malformed request: A request header or parameter does not parse, or names what Wow does not take. */\n REQUEST_MALFORMED: 'wow.request.malformed',\n /** 400 Malformed command: The command body cannot be read as the command type. */\n COMMAND_MALFORMED: 'wow.command.malformed',\n /** 400 Invalid command: The command failed validation; the problem lists the violations. */\n COMMAND_INVALID: 'wow.command.invalid',\n /** 400 Invalid wait: The wait is not a chain the runtime can follow; the command was not run. */\n WAIT_INVALID: 'wow.wait.invalid',\n /** 400 Command not handled: The aggregate does not handle this command. */\n COMMAND_UNHANDLED: 'wow.command.unhandled',\n /** 404 Aggregate not found: The aggregate does not exist, or is outside the caller's reach. */\n AGGREGATE_NOT_FOUND: 'wow.aggregate.not-found',\n /** 409 Aggregate exists: The aggregate already exists. */\n AGGREGATE_EXISTS: 'wow.aggregate.exists',\n /** 409 Version mismatch: The aggregate is not at the expected version (412 when the request carried If-Match). */\n AGGREGATE_VERSION_MISMATCH: 'wow.aggregate.version-mismatch',\n /** 409 Request id reused: The request id was used by another command. */\n COMMAND_REQUEST_ID_REUSED: 'wow.command.request-id-reused',\n /** 409 Command contended: Concurrent writers kept winning the version; retrying with the same request id is safe. */\n COMMAND_CONTENDED: 'wow.command.contended',\n /** 410 Aggregate deleted: The aggregate is deleted; only RestoreAggregate applies. */\n AGGREGATE_DELETED: 'wow.aggregate.deleted',\n /** 429 Command busy: The command was not taken: its aggregate has too many commands waiting, or the node too many in flight; retry later. */\n COMMAND_BUSY: 'wow.command.busy',\n /** 503 Command outcome unknown: Whether the command committed is unknown; retrying with the same request id is safe. */\n COMMAND_UNKNOWN: 'wow.command.unknown',\n /** 500 Command failed: The command's handling failed with an unexpected error; it committed nothing, and a retry fails alike. */\n COMMAND_FAILED: 'wow.command.failed',\n /** 409 Command refused: The aggregate's current state refuses the command (a check of its decide function); the message says why. */\n COMMAND_REFUSED: 'wow.command.refused',\n /** 500 Undeclared event: The command's handling produced an event its decide function or after hooks do not declare: a bug in the model, which the message names; it committed nothing. */\n COMMAND_UNDECLARED_EVENT: 'wow.command.undeclared-event',\n /** 503 Node closing: The node is shutting down; retry on another node. */\n NODE_CLOSING: 'wow.node.closing',\n /** 503 Node on standby: The node is on standby until the cut-over: it serves reads only. */\n NODE_STANDBY: 'wow.node.standby',\n /** 503 Storage unavailable: A store could not be reached or did not answer in time; retry later, a command with the same request id. */\n STORAGE_UNAVAILABLE: 'wow.storage.unavailable',\n /** 503 Schedule not due: A scheduled command arrived too long before its due time on this node's clock; it is sent again later. */\n SCHEDULE_NOT_DUE: 'wow.schedule.not-due',\n /** 400 Invalid schedule job: The job command does not fit its job or instance: an unknown job, another scope, or an instance not enabled. */\n SCHEDULE_JOB_INVALID: 'wow.schedule.job-invalid',\n /** 409 Stale ledger action: The action names a parking the entry no longer is: the aggregate was resolved and parked again since; read the entry again before acting on it. */\n LEDGER_STALE: 'wow.ledger.stale',\n /** 500 Subscription parked: A subscription on the wait chain parked the aggregate; the wait cannot be reached until the aggregate is retried. */\n SUBSCRIPTION_PARKED: 'wow.subscription.parked',\n /** 504 Wait timed out: The wait ran out of time; the command may have committed. The problem carries the last stage reached. */\n WAIT_TIMEOUT: 'wow.wait.timeout',\n /** 400 Malformed route request: A service route's parameter or body cannot be read as its type; the violation names the parameter. */\n ROUTE_MALFORMED: 'wow.route.malformed',\n /** 400 Malformed query: The query body cannot be read as a query. */\n QUERY_MALFORMED: 'wow.query.malformed',\n /** 400 Invalid query: The query failed admission; the problem lists the violations, each with its code (unknown-field, ...). */\n QUERY_INVALID: 'wow.query.invalid',\n /** 500 Query failed: The query backend failed to run the query. */\n QUERY_FAILED: 'wow.query.failed',\n /** 404 No matching record: A single query matched no record: a query result, not a statement that an aggregate does not exist. */\n QUERY_NOT_FOUND: 'wow.query.not-found',\n /** 404 Dataset not found: No dataset of that name is served to the caller. */\n QUERY_DATASET_NOT_FOUND: 'wow.query.dataset-not-found',\n /** 400 Too many groups: An aggregation that names no sort has more groups than its limit; add a sort for a top-N, or raise limit. */\n QUERY_TOO_MANY_GROUPS: 'wow.query.too-many-groups',\n /** 504 Query timed out: The query ran longer than its budget allows; narrow it rather than run it again. */\n QUERY_TIMEOUT: 'wow.query.timeout',\n /** 409 Version not reached: The state read asked for a version the aggregate has not reached within the wait; the problem carries its current version: retry later. */\n QUERY_MIN_VERSION_NOT_REACHED: 'wow.query.min-version-not-reached',\n /** 429 Query busy: The query was not run: its store has as many queries running as it allows; retry later. */\n QUERY_BUSY: 'wow.query.busy',\n /** 409 Dataset unavailable: The dataset is served but cannot be queried now, for the reason the problem names (it needs revision). */\n QUERY_DATASET_UNAVAILABLE: 'wow.query.dataset-unavailable',\n /** 403 Call forbidden: The calling service may not call this command: its wow.callers.<service>.commands do not list it. */\n CALL_COMMAND_FORBIDDEN: 'wow.call.command-forbidden',\n /** 503 Peer unavailable: A client reached no node of the peer, or lost the connection before a query's answer; nothing was changed, so the request may be sent again. */\n PEER_UNAVAILABLE: 'wow.peer.unavailable',\n} as const;\n\n/** A {@link FrameworkErrorCodes} value. */\nexport type FrameworkErrorCode =\n (typeof FrameworkErrorCodes)[keyof typeof FrameworkErrorCodes];\n\n/** What a retry of a framework code may do, as the error catalog declares it. */\nexport interface FrameworkRetry {\n /** What a retry may do: never `none` here. */\n readonly retry: Retry;\n /** Its `Retry-After`, in milliseconds. */\n readonly retryAfterMs: number;\n}\n\n/**\n * What a retry may do of each framework code a retry may get past, by code;\n * a retry of every other code, a domain's among them, is `none`.\n */\nexport const FRAMEWORK_RETRIES: ReadonlyMap<string, FrameworkRetry> = new Map<\n string,\n FrameworkRetry\n>([\n ['wow.command.contended', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.command.busy', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.command.unknown', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.node.closing', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.node.standby', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.storage.unavailable', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.schedule.not-due', { retry: 'same-request', retryAfterMs: 1000 }],\n ['wow.wait.timeout', { retry: 'same-request', retryAfterMs: 1000 }],\n [\n 'wow.query.min-version-not-reached',\n { retry: 'new-request', retryAfterMs: 1000 },\n ],\n ['wow.query.busy', { retry: 'new-request', retryAfterMs: 1000 }],\n ['wow.peer.unavailable', { retry: 'new-request', retryAfterMs: 1000 }],\n]);\n\n/**\n * How often, and after how long, a client sends a request again by default\n * when a retry may get past its error, as the Kotlin client does\n * (`RetryPolicy.DEFAULT`): at most `attempts` attempts, the first included,\n * `backoffMs` before the first retry without a `Retry-After`, doubled at each\n * attempt up to `maxWaitMs`.\n */\nexport const DEFAULT_RETRY = {\n attempts: 5,\n backoffMs: 200,\n maxWaitMs: 5000,\n} as const;\n"],"mappings":";AAkBA,IAAaA,IAAsB;CAEjC,sBAAsB;CAEtB,gBAAgB;CAEhB,qBAAqB;CAErB,mBAAmB;CAEnB,mBAAmB;CAEnB,iBAAiB;CAEjB,cAAc;CAEd,mBAAmB;CAEnB,qBAAqB;CAErB,kBAAkB;CAElB,4BAA4B;CAE5B,2BAA2B;CAE3B,mBAAmB;CAEnB,mBAAmB;CAEnB,cAAc;CAEd,iBAAiB;CAEjB,gBAAgB;CAEhB,iBAAiB;CAEjB,0BAA0B;CAE1B,cAAc;CAEd,cAAc;CAEd,qBAAqB;CAErB,kBAAkB;CAElB,sBAAsB;CAEtB,cAAc;CAEd,qBAAqB;CAErB,cAAc;CAEd,iBAAiB;CAEjB,iBAAiB;CAEjB,eAAe;CAEf,cAAc;CAEd,iBAAiB;CAEjB,yBAAyB;CAEzB,uBAAuB;CAEvB,eAAe;CAEf,+BAA+B;CAE/B,YAAY;CAEZ,2BAA2B;CAE3B,wBAAwB;CAExB,kBAAkB;AACpB,GAkBaC,oBAAyD,IAAI,IAGxE;CACA,CAAC,yBAAyB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CACvE,CAAC,oBAAoB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CAClE,CAAC,uBAAuB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CACrE,CAAC,oBAAoB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CAClE,CAAC,oBAAoB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CAClE,CAAC,2BAA2B;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CACzE,CAAC,wBAAwB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CACtE,CAAC,oBAAoB;EAAE,OAAO;EAAgB,cAAc;CAAK,CAAC;CAClE,CACE,qCACA;EAAE,OAAO;EAAe,cAAc;CAAK,CAC7C;CACA,CAAC,kBAAkB;EAAE,OAAO;EAAe,cAAc;CAAK,CAAC;CAC/D,CAAC,wBAAwB;EAAE,OAAO;EAAe,cAAc;CAAK,CAAC;AACvE,CAAC,GASYC,IAAgB;CAC3B,UAAU;CACV,WAAW;CACX,WAAW;AACb"}
|
package/dist/http.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./exactJson.cjs"),t=require("./problem.cjs");let n=require("@ahoo-wang/fetcher");var r={REQUEST_ID:`Wow-Request-Id`,WAIT:`Wow-Wait`,WAIT_TIMEOUT:`Wow-Wait-Timeout`,SCOPE:`Wow-Scope`,SPACE:`Wow-Space`,IF_MATCH:`If-Match`,IF_NONE_MATCH:`If-None-Match`,ETAG:`ETag`,RETRY_AFTER:`Retry-After`,LAST_EVENT_ID:`Last-Event-ID`};function i(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`}function a(e){let t=[e.tenantId===void 0?void 0:`tenant=${i(e.tenantId)}`,e.ownerId===void 0?void 0:`owner=${i(e.ownerId)}`,e.spaceId===void 0?void 0:`space=${i(e.spaceId)}`].filter(e=>e!==void 0);if(t.length===0)throw TypeError(`Wow-Scope names a tenant, an owner or a space.`);return t.join(`, `)}function o(e){if(!e)return``;let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!==void 0&&t.append(n,String(r));let n=t.toString();return n?`?${n}`:``}async function
|
|
1
|
+
const e=require("./exactJson.cjs"),t=require("./problem.cjs");let n=require("@ahoo-wang/fetcher");var r={REQUEST_ID:`Wow-Request-Id`,WAIT:`Wow-Wait`,WAIT_TIMEOUT:`Wow-Wait-Timeout`,SCOPE:`Wow-Scope`,SPACE:`Wow-Space`,IF_MATCH:`If-Match`,IF_NONE_MATCH:`If-None-Match`,ETAG:`ETag`,RETRY_AFTER:`Retry-After`,LAST_EVENT_ID:`Last-Event-ID`};function i(e){return`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`)}"`}function a(e){let t=[e.tenantId===void 0?void 0:`tenant=${i(e.tenantId)}`,e.ownerId===void 0?void 0:`owner=${i(e.ownerId)}`,e.spaceId===void 0?void 0:`space=${i(e.spaceId)}`].filter(e=>e!==void 0);if(t.length===0)throw TypeError(`Wow-Scope names a tenant, an owner or a space.`);return t.join(`, `)}function o(e){if(!e)return``;let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r!==void 0&&t.append(n,String(r));let n=t.toString();return n?`?${n}`:``}var s=class{constructor(e,t){this.response=e,this.numbers=t}async json(){return e.marksNothing(this.numbers)?await this.response.json():e.parseJson(await this.response.text(),this.numbers)}};async function c(i,c){let l=c.options??{},u={};for(let[e,t]of Object.entries({...c.headers,...l.scope===void 0?{}:{[r.SCOPE]:a(l.scope)},...l.space===void 0?{}:{[r.SPACE]:l.space},...l.headers}))t!==void 0&&(u[e]=t);let d=c.body!==void 0&&!e.marksNothing(c.numbers.body);d&&(u[`Content-Type`]=`application/json`);let f=`${i.basePath??``}${c.path}${o(c.query)}`;try{return new s(await(i.fetcher??n.fetcher).fetch(f,{method:c.method,headers:u,...c.body===void 0?{}:{body:d?e.stringifyJson(c.body,c.numbers.body):c.body},...l.signal===void 0?{}:{signal:l.signal}}),c.numbers.answer)}catch(e){let n=e?.exchange?.response;if(c.notModified&&n?.status===304)return new s(n,void 0);throw await t.toWowProblemError(e)??e}}function l(e){let t=e.headers.get(r.ETAG);return t===null?void 0:t.replace(/^W\//,``).replace(/"/g,``)}exports.Answer=s,exports.WowHeaders=r,exports.entityTag=l,exports.formatScope=a,exports.send=c;
|
|
2
2
|
//# sourceMappingURL=http.cjs.map
|
package/dist/http.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.cjs","names":["marksNothing","defaultFetcher","stringifyJson","toWowProblemError","parseJson","require_exactJson","require_problem","_ahoo_wang_fetcher","WowHeaders","quote","value","formatScope","members","scope","member","queryString","query","params","name","text","send","options","call","headers","exact","url","client","error","response","json","numbers","entityTag","tag"],"sources":["../src/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 {\n marksNothing,\n parseJson,\n stringifyJson,\n type TextNumbers,\n} from './exactJson.js';\nimport { toWowProblemError } from './problem.js';\n\n/**\n * The request headers of a Wow service's public port.\n */\nexport const WowHeaders = {\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 /** The position a streamed list resumes after (decision D253). */\n LAST_EVENT_ID: 'Last-Event-ID',\n} as const;\n\n/** How a 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.\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 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 client. */\nexport interface Call {\n readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | '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 /** The body's numbers written as their exact text ({@link TextNumbers}). */\n readonly bodyNumbers?: TextNumbers;\n readonly options?: RequestOptions;\n /** Answers a 304 rather than rejecting with it. */\n readonly notModified?: boolean;\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 : { [WowHeaders.SCOPE]: formatScope(options.scope) }),\n ...(options.space === undefined\n ? {}\n : { [WowHeaders.SPACE]: options.space }),\n ...options.headers,\n })) {\n if (value !== undefined) headers[name] = value;\n }\n // A body with exact numbers goes as its own JSON text, those numbers unquoted.\n const exact = call.body !== undefined && !marksNothing(call.bodyNumbers);\n if (exact) headers['Content-Type'] = 'application/json';\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\n ? {}\n : {\n body: exact\n ? stringifyJson(call.body, call.bodyNumbers)\n : (call.body as object),\n }),\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/**\n * The JSON body of a 2xx response; the numbers `numbers` marks come back as\n * their exact text, and without marks it is\n * `response.json()` itself.\n */\nexport async function json<T>(\n response: Response,\n numbers?: TextNumbers,\n): Promise<T> {\n if (marksNothing(numbers)) return (await response.json()) as T;\n return parseJson(await response.text(), numbers) 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(WowHeaders.ETAG);\n return tag === null ? undefined : tag.replace(/^W\\//, '').replace(/\"/g, '');\n}\n"],"mappings":"A,kGAyBA,IAAaQ,EAAa,CAExB,WAAY,iBAEZ,KAAM,WAEN,aAAc,mBAEd,MAAO,YAEP,MAAO,YAEP,SAAU,WAEV,cAAe,gBAEf,KAAM,OAEN,YAAa,cAEb,cAAe,eACjB,EAuBA,SAASC,EAAM,EAAuB,CACpC,MAAO,IAAIC,EAAM,QAAQ,MAAO,MAAM,CAAC,CAAC,QAAQ,KAAM,KAAK,EAAE,EAC/D,CAQA,SAAgBC,EAAY,EAA4B,CACtD,IAAMC,EAAU,CACdC,EAAM,WAAa,IAAA,GACf,IAAA,GACA,UAAUJ,EAAMI,EAAM,QAAQ,IAClCA,EAAM,UAAY,IAAA,GAAY,IAAA,GAAY,SAASJ,EAAMI,EAAM,OAAO,IACtEA,EAAM,UAAY,IAAA,GAAY,IAAA,GAAY,SAASJ,EAAMI,EAAM,OAAO,GACxE,CAAC,CAAC,OAAO,GAAUC,IAAW,IAAA,EAAS,EACvC,GAAIF,EAAQ,SAAW,EACrB,MAAU,UAAU,gDAAgD,EAEtE,OAAOA,EAAQ,KAAK,IAAI,CAC1B,CA4BA,SAASG,EACP,EACQ,CACR,GAAI,CAACC,EAAO,MAAO,GACnB,IAAMC,EAAS,IAAI,gBACnB,IAAK,GAAM,CAACC,EAAMR,KAAU,OAAO,QAAQM,CAAK,EAC1CN,IAAU,IAAA,IAAWO,EAAO,OAAOC,EAAM,OAAOR,CAAK,CAAC,EAE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S,KAAK,EAChDxB,EAAAA,UAAU,MAAMwB,EAAS,KAAK,EAAGE,CAAO,CACjD,CAGA,SAAgBC,EAAU,EAAwC,CAChE,IAAMC,EAAMJ,EAAS,QAAQ,IAAIpB,EAAW,IAAI,EAChD,OAAOwB,IAAQ,KAAO,IAAA,GAAYA,EAAI,QAAQ,OAAQ,EAAE,CAAC,CAAC,QAAQ,KAAM,EAAE,CAC5E,C"}
|
|
1
|
+
{"version":3,"file":"http.cjs","names":["marksNothing","parseJson","defaultFetcher","stringifyJson","toWowProblemError","require_exactJson","require_problem","_ahoo_wang_fetcher","WowHeaders","quote","value","formatScope","members","scope","member","queryString","query","params","name","text","Answer","response","numbers","send","options","call","headers","exact","url","client","error","entityTag","tag"],"sources":["../src/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 {\n marksNothing,\n parseJson,\n stringifyJson,\n type TextNumbers,\n} from './exactJson.js';\nimport { toWowProblemError } from './problem.js';\n\n/**\n * The request headers of a Wow service's public port.\n */\nexport const WowHeaders = {\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 /** The position a streamed list resumes after (decision D253). */\n LAST_EVENT_ID: 'Last-Event-ID',\n} as const;\n\n/** How a 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.\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 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/**\n * The exact numbers ({@link TextNumbers}) of one call: of the body it writes\n * and of the JSON it reads back.\n */\nexport interface CallNumbers {\n readonly body?: TextNumbers;\n readonly answer?: TextNumbers;\n}\n\n/** One request of a client. */\nexport interface Call {\n readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | '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 /**\n * Its exact numbers, required of every call: a call with none says so\n * (`{}`), so no way of reading or writing JSON leaves them out.\n */\n readonly numbers: CallNumbers;\n readonly options?: RequestOptions;\n /** Answers a 304 rather than rejecting with it. */\n readonly notModified?: boolean;\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 * A call's response: its JSON is read only with the exact numbers the call\n * declared ({@link Call.numbers}), here or by a stream reader given it.\n */\nexport class Answer {\n /**\n * @param response - The response\n * @param numbers - The exact numbers of its JSON, or of each event's\n */\n constructor(\n readonly response: Response,\n readonly numbers: TextNumbers | undefined,\n ) {}\n\n /** The JSON body, its exact numbers as their text. */\n async json<T>(): Promise<T> {\n return (\n marksNothing(this.numbers)\n ? await this.response.json()\n : parseJson(await this.response.text(), this.numbers)\n ) as T;\n }\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<Answer> {\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 : { [WowHeaders.SCOPE]: formatScope(options.scope) }),\n ...(options.space === undefined\n ? {}\n : { [WowHeaders.SPACE]: options.space }),\n ...options.headers,\n })) {\n if (value !== undefined) headers[name] = value;\n }\n // A body with exact numbers goes as its own JSON text, those numbers unquoted.\n const exact = call.body !== undefined && !marksNothing(call.numbers.body);\n if (exact) headers['Content-Type'] = 'application/json';\n const url = `${client.basePath ?? ''}${call.path}${queryString(call.query)}`;\n try {\n const response = await (client.fetcher ?? defaultFetcher).fetch(url, {\n method: call.method,\n headers,\n ...(call.body === undefined\n ? {}\n : {\n body: exact\n ? stringifyJson(call.body, call.numbers.body)\n : (call.body as object),\n }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n });\n return new Answer(response, call.numbers.answer);\n } catch (error) {\n const response = (error as { exchange?: { response?: Response } })?.exchange\n ?.response;\n if (call.notModified && response?.status === 304) {\n return new Answer(response, undefined);\n }\n throw (await toWowProblemError(error)) ?? error;\n }\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(WowHeaders.ETAG);\n return tag === null ? undefined : tag.replace(/^W\\//, '').replace(/\"/g, '');\n}\n"],"mappings":"A,kGAyBA,IAAaQ,EAAa,CAExB,WAAY,iBAEZ,KAAM,WAEN,aAAc,mBAEd,MAAO,YAEP,MAAO,YAEP,SAAU,WAEV,cAAe,gBAEf,KAAM,OAEN,YAAa,cAEb,cAAe,eACjB,EAuBA,SAASC,EAAM,EAAuB,CACpC,MAAO,IAAIC,EAAM,QAAQ,MAAO,MAAM,CAAC,CAAC,QAAQ,KAAM,KAAK,EAAE,EAC/D,CAQA,SAAgBC,EAAY,EAA4B,CACtD,IAAMC,EAAU,CACdC,EAAM,WAAa,IAAA,GACf,IAAA,GACA,UAAUJ,EAAMI,EAAM,QAAQ,IAClCA,EAAM,UAAY,IAAA,GAAY,IAAA,GAAY,SAASJ,EAAMI,EAAM,OAAO,IACtEA,EAAM,UAAY,IAAA,GAAY,IAAA,GAAY,SAASJ,EAAMI,EAAM,OAAO,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AAO,UAAY,KAAKJ,EAAK,OAAOV,EAAYU,EAAK,KAAK,IACzE,GAAI,CAaF,OAAO,IAAIL,EAAO,MAZMS,EAAO,SAAW3B,EAAAA,QAAAA,CAAgB,MAAM0B,EAAK,CACnE,OAAQH,EAAK,OACb,UACA,GAAIA,EAAK,OAAS,IAAA,GACd,CAAC,EACD,CACE,KAAME,EACFxB,EAAAA,cAAcsB,EAAK,KAAMA,EAAK,QAAQ,IAAI,EACzCA,EAAK,IACZ,EACJ,GAAID,EAAQ,SAAW,IAAA,GAAY,CAAC,EAAI,CAAE,OAAQA,EAAQ,MAAO,CACnE,CAAC,EAC2BC,EAAK,QAAQ,MAAM,CACjD,OAASK,EAAO,CACd,IAAMT,EAAYS,GAAkD,UAChE,SACJ,GAAIL,EAAK,aAAeJ,GAAU,SAAW,IAC3C,OAAO,IAAID,EAAOC,EAAU,IAAA,EAAS,EAEvC,MAAO,MAAMjB,EAAAA,kBAAkB0B,CAAK,GAAMA,CAC5C,CACF,CAGA,SAAgBC,EAAU,EAAwC,CAChE,IAAMC,EAAMX,EAAS,QAAQ,IAAIb,EAAW,IAAI,EAChD,OAAOwB,IAAQ,KAAO,IAAA,GAAYA,EAAI,QAAQ,OAAQ,EAAE,CAAC,CAAC,QAAQ,KAAM,EAAE,CAC5E,C"}
|
package/dist/http.d.cts
CHANGED
|
@@ -62,6 +62,14 @@ export interface RequestOptions {
|
|
|
62
62
|
/** Cancels the request. */
|
|
63
63
|
readonly signal?: AbortSignal;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* The exact numbers ({@link TextNumbers}) of one call: of the body it writes
|
|
67
|
+
* and of the JSON it reads back.
|
|
68
|
+
*/
|
|
69
|
+
export interface CallNumbers {
|
|
70
|
+
readonly body?: TextNumbers;
|
|
71
|
+
readonly answer?: TextNumbers;
|
|
72
|
+
}
|
|
65
73
|
/** One request of a client. */
|
|
66
74
|
export interface Call {
|
|
67
75
|
readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
@@ -69,12 +77,30 @@ export interface Call {
|
|
|
69
77
|
readonly query?: Readonly<Record<string, string | number | undefined>>;
|
|
70
78
|
readonly headers?: Readonly<Record<string, string | undefined>>;
|
|
71
79
|
readonly body?: unknown;
|
|
72
|
-
/**
|
|
73
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Its exact numbers, required of every call: a call with none says so
|
|
82
|
+
* (`{}`), so no way of reading or writing JSON leaves them out.
|
|
83
|
+
*/
|
|
84
|
+
readonly numbers: CallNumbers;
|
|
74
85
|
readonly options?: RequestOptions;
|
|
75
86
|
/** Answers a 304 rather than rejecting with it. */
|
|
76
87
|
readonly notModified?: boolean;
|
|
77
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* A call's response: its JSON is read only with the exact numbers the call
|
|
91
|
+
* declared ({@link Call.numbers}), here or by a stream reader given it.
|
|
92
|
+
*/
|
|
93
|
+
export declare class Answer {
|
|
94
|
+
readonly response: Response;
|
|
95
|
+
readonly numbers: TextNumbers | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* @param response - The response
|
|
98
|
+
* @param numbers - The exact numbers of its JSON, or of each event's
|
|
99
|
+
*/
|
|
100
|
+
constructor(response: Response, numbers: TextNumbers | undefined);
|
|
101
|
+
/** The JSON body, its exact numbers as their text. */
|
|
102
|
+
json<T>(): Promise<T>;
|
|
103
|
+
}
|
|
78
104
|
/**
|
|
79
105
|
* Sends one request through the client's fetcher and answers its response;
|
|
80
106
|
* a response that is not 2xx rejects with a {@link WowProblemError}.
|
|
@@ -82,12 +108,6 @@ export interface Call {
|
|
|
82
108
|
* @param client - The client's options
|
|
83
109
|
* @param call - The request
|
|
84
110
|
*/
|
|
85
|
-
export declare function send(client: WowClientOptions, call: Call): Promise<
|
|
86
|
-
/**
|
|
87
|
-
* The JSON body of a 2xx response; the numbers `numbers` marks come back as
|
|
88
|
-
* their exact text, and without marks it is
|
|
89
|
-
* `response.json()` itself.
|
|
90
|
-
*/
|
|
91
|
-
export declare function json<T>(response: Response, numbers?: TextNumbers): Promise<T>;
|
|
111
|
+
export declare function send(client: WowClientOptions, call: Call): Promise<Answer>;
|
|
92
112
|
/** The entity tag of a response without its quotes or weak marker. */
|
|
93
113
|
export declare function entityTag(response: Response): string | undefined;
|
package/dist/http.d.ts
CHANGED
|
@@ -62,6 +62,14 @@ export interface RequestOptions {
|
|
|
62
62
|
/** Cancels the request. */
|
|
63
63
|
readonly signal?: AbortSignal;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* The exact numbers ({@link TextNumbers}) of one call: of the body it writes
|
|
67
|
+
* and of the JSON it reads back.
|
|
68
|
+
*/
|
|
69
|
+
export interface CallNumbers {
|
|
70
|
+
readonly body?: TextNumbers;
|
|
71
|
+
readonly answer?: TextNumbers;
|
|
72
|
+
}
|
|
65
73
|
/** One request of a client. */
|
|
66
74
|
export interface Call {
|
|
67
75
|
readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
|
|
@@ -69,12 +77,30 @@ export interface Call {
|
|
|
69
77
|
readonly query?: Readonly<Record<string, string | number | undefined>>;
|
|
70
78
|
readonly headers?: Readonly<Record<string, string | undefined>>;
|
|
71
79
|
readonly body?: unknown;
|
|
72
|
-
/**
|
|
73
|
-
|
|
80
|
+
/**
|
|
81
|
+
* Its exact numbers, required of every call: a call with none says so
|
|
82
|
+
* (`{}`), so no way of reading or writing JSON leaves them out.
|
|
83
|
+
*/
|
|
84
|
+
readonly numbers: CallNumbers;
|
|
74
85
|
readonly options?: RequestOptions;
|
|
75
86
|
/** Answers a 304 rather than rejecting with it. */
|
|
76
87
|
readonly notModified?: boolean;
|
|
77
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* A call's response: its JSON is read only with the exact numbers the call
|
|
91
|
+
* declared ({@link Call.numbers}), here or by a stream reader given it.
|
|
92
|
+
*/
|
|
93
|
+
export declare class Answer {
|
|
94
|
+
readonly response: Response;
|
|
95
|
+
readonly numbers: TextNumbers | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* @param response - The response
|
|
98
|
+
* @param numbers - The exact numbers of its JSON, or of each event's
|
|
99
|
+
*/
|
|
100
|
+
constructor(response: Response, numbers: TextNumbers | undefined);
|
|
101
|
+
/** The JSON body, its exact numbers as their text. */
|
|
102
|
+
json<T>(): Promise<T>;
|
|
103
|
+
}
|
|
78
104
|
/**
|
|
79
105
|
* Sends one request through the client's fetcher and answers its response;
|
|
80
106
|
* a response that is not 2xx rejects with a {@link WowProblemError}.
|
|
@@ -82,12 +108,6 @@ export interface Call {
|
|
|
82
108
|
* @param client - The client's options
|
|
83
109
|
* @param call - The request
|
|
84
110
|
*/
|
|
85
|
-
export declare function send(client: WowClientOptions, call: Call): Promise<
|
|
86
|
-
/**
|
|
87
|
-
* The JSON body of a 2xx response; the numbers `numbers` marks come back as
|
|
88
|
-
* their exact text, and without marks it is
|
|
89
|
-
* `response.json()` itself.
|
|
90
|
-
*/
|
|
91
|
-
export declare function json<T>(response: Response, numbers?: TextNumbers): Promise<T>;
|
|
111
|
+
export declare function send(client: WowClientOptions, call: Call): Promise<Answer>;
|
|
92
112
|
/** The entity tag of a response without its quotes or weak marker. */
|
|
93
113
|
export declare function entityTag(response: Response): string | undefined;
|
package/dist/http.es.js
CHANGED
|
@@ -33,37 +33,42 @@ function c(e) {
|
|
|
33
33
|
let n = t.toString();
|
|
34
34
|
return n ? `?${n}` : "";
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
var l = class {
|
|
37
|
+
constructor(e, t) {
|
|
38
|
+
this.response = e, this.numbers = t;
|
|
39
|
+
}
|
|
40
|
+
async json() {
|
|
41
|
+
return e(this.numbers) ? await this.response.json() : t(await this.response.text(), this.numbers);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
async function u(t, o) {
|
|
45
|
+
let u = o.options ?? {}, d = {};
|
|
38
46
|
for (let [e, t] of Object.entries({
|
|
39
47
|
...o.headers,
|
|
40
|
-
...
|
|
41
|
-
...
|
|
42
|
-
...
|
|
43
|
-
})) t !== void 0 && (
|
|
44
|
-
let
|
|
45
|
-
|
|
46
|
-
let
|
|
48
|
+
...u.scope === void 0 ? {} : { [a.SCOPE]: s(u.scope) },
|
|
49
|
+
...u.space === void 0 ? {} : { [a.SPACE]: u.space },
|
|
50
|
+
...u.headers
|
|
51
|
+
})) t !== void 0 && (d[e] = t);
|
|
52
|
+
let f = o.body !== void 0 && !e(o.numbers.body);
|
|
53
|
+
f && (d["Content-Type"] = "application/json");
|
|
54
|
+
let p = `${t.basePath ?? ""}${o.path}${c(o.query)}`;
|
|
47
55
|
try {
|
|
48
|
-
return await (t.fetcher ?? i).fetch(
|
|
56
|
+
return new l(await (t.fetcher ?? i).fetch(p, {
|
|
49
57
|
method: o.method,
|
|
50
|
-
headers:
|
|
51
|
-
...o.body === void 0 ? {} : { body:
|
|
52
|
-
...
|
|
53
|
-
});
|
|
58
|
+
headers: d,
|
|
59
|
+
...o.body === void 0 ? {} : { body: f ? n(o.body, o.numbers.body) : o.body },
|
|
60
|
+
...u.signal === void 0 ? {} : { signal: u.signal }
|
|
61
|
+
}), o.numbers.answer);
|
|
54
62
|
} catch (e) {
|
|
55
63
|
let t = e?.exchange?.response;
|
|
56
|
-
if (o.notModified && t?.status === 304) return t;
|
|
64
|
+
if (o.notModified && t?.status === 304) return new l(t, void 0);
|
|
57
65
|
throw await r(e) ?? e;
|
|
58
66
|
}
|
|
59
67
|
}
|
|
60
|
-
async function u(n, r) {
|
|
61
|
-
return e(r) ? await n.json() : t(await n.text(), r);
|
|
62
|
-
}
|
|
63
68
|
function d(e) {
|
|
64
69
|
let t = e.headers.get(a.ETAG);
|
|
65
70
|
return t === null ? void 0 : t.replace(/^W\//, "").replace(/"/g, "");
|
|
66
71
|
}
|
|
67
|
-
export { a as WowHeaders, d as entityTag, s as formatScope, u as
|
|
72
|
+
export { l as Answer, a as WowHeaders, d as entityTag, s as formatScope, u as send };
|
|
68
73
|
|
|
69
74
|
//# sourceMappingURL=http.es.js.map
|
package/dist/http.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.es.js","names":["defaultFetcher","WowHeaders","quote","value","formatScope","members","scope","member","queryString","query","params","name","text","send","options","call","headers","exact","marksNothing","url","client","fetcher","stringifyJson","error","response","toWowProblemError","json","numbers","parseJson","entityTag","tag"],"sources":["../src/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 {\n marksNothing,\n parseJson,\n stringifyJson,\n type TextNumbers,\n} from './exactJson.js';\nimport { toWowProblemError } from './problem.js';\n\n/**\n * The request headers of a Wow service's public port.\n */\nexport const WowHeaders = {\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 /** The position a streamed list resumes after (decision D253). */\n LAST_EVENT_ID: 'Last-Event-ID',\n} as const;\n\n/** How a 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.\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 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 client. */\nexport interface Call {\n readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | '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 /** The body's numbers written as their exact text ({@link TextNumbers}). */\n readonly bodyNumbers?: TextNumbers;\n readonly options?: RequestOptions;\n /** Answers a 304 rather than rejecting with it. */\n readonly notModified?: boolean;\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 : { [WowHeaders.SCOPE]: formatScope(options.scope) }),\n ...(options.space === undefined\n ? {}\n : { [WowHeaders.SPACE]: options.space }),\n ...options.headers,\n })) {\n if (value !== undefined) headers[name] = value;\n }\n // A body with exact numbers goes as its own JSON text, those numbers unquoted.\n const exact = call.body !== undefined && !marksNothing(call.bodyNumbers);\n if (exact) headers['Content-Type'] = 'application/json';\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\n ? {}\n : {\n body: exact\n ? stringifyJson(call.body, call.bodyNumbers)\n : (call.body as object),\n }),\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/**\n * The JSON body of a 2xx response; the numbers `numbers` marks come back as\n * their exact text, and without marks it is\n * `response.json()` itself.\n */\nexport async function json<T>(\n response: Response,\n numbers?: TextNumbers,\n): Promise<T> {\n if (marksNothing(numbers)) return (await response.json()) as T;\n return parseJson(await response.text(), numbers) 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(WowHeaders.ETAG);\n return tag === null ? undefined : tag.replace(/^W\\//, '').replace(/\"/g, '');\n}\n"],"mappings":";;;;AAyBA,IAAaC,IAAa;CAExB,YAAY;CAEZ,MAAM;CAEN,cAAc;CAEd,OAAO;CAEP,OAAO;CAEP,UAAU;CAEV,eAAe;CAEf,MAAM;CAEN,aAAa;CAEb,eAAe;AACjB;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;AA4BA,SAASG,EACP,GACQ;CACR,IAAI,CAACC,GAAO,OAAO;CACnB,IAAMC,IAAS,IAAI,gBAAgB;CACnC,KAAK,IAAM,CAACC,GAAMR,MAAU,OAAO,QAAQM,CAAK,GAC9C,AAAIN,MAAU,KAAA,KAAWO,EAAO,OAAOC,GAAM,OAAOR,CAAK,CAAC;CAE5D,IAAMS,IAAOF,EAAO,SAAS;CAC7B,OAAOE,IAAO,IAAIA,MAAS;AAC7B;AASA,eAAsBC,EACpB,GACA,GACmB;CACnB,IAAMC,IAAUC,EAAK,WAAW,CAAC,GAC3BC,IAAkC,CAAC;CACzC,KAAK,IAAM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C,CAAC,QAAQ,MAAM,EAAE;AAC5E"}
|
|
1
|
+
{"version":3,"file":"http.es.js","names":["defaultFetcher","WowHeaders","quote","value","formatScope","members","scope","member","queryString","query","params","name","text","Answer","response","numbers","marksNothing","parseJson","send","options","call","headers","exact","url","client","fetcher","stringifyJson","error","toWowProblemError","entityTag","tag"],"sources":["../src/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 {\n marksNothing,\n parseJson,\n stringifyJson,\n type TextNumbers,\n} from './exactJson.js';\nimport { toWowProblemError } from './problem.js';\n\n/**\n * The request headers of a Wow service's public port.\n */\nexport const WowHeaders = {\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 /** The position a streamed list resumes after (decision D253). */\n LAST_EVENT_ID: 'Last-Event-ID',\n} as const;\n\n/** How a 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.\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 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/**\n * The exact numbers ({@link TextNumbers}) of one call: of the body it writes\n * and of the JSON it reads back.\n */\nexport interface CallNumbers {\n readonly body?: TextNumbers;\n readonly answer?: TextNumbers;\n}\n\n/** One request of a client. */\nexport interface Call {\n readonly method: 'GET' | 'POST' | 'PUT' | 'PATCH' | '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 /**\n * Its exact numbers, required of every call: a call with none says so\n * (`{}`), so no way of reading or writing JSON leaves them out.\n */\n readonly numbers: CallNumbers;\n readonly options?: RequestOptions;\n /** Answers a 304 rather than rejecting with it. */\n readonly notModified?: boolean;\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 * A call's response: its JSON is read only with the exact numbers the call\n * declared ({@link Call.numbers}), here or by a stream reader given it.\n */\nexport class Answer {\n /**\n * @param response - The response\n * @param numbers - The exact numbers of its JSON, or of each event's\n */\n constructor(\n readonly response: Response,\n readonly numbers: TextNumbers | undefined,\n ) {}\n\n /** The JSON body, its exact numbers as their text. */\n async json<T>(): Promise<T> {\n return (\n marksNothing(this.numbers)\n ? await this.response.json()\n : parseJson(await this.response.text(), this.numbers)\n ) as T;\n }\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<Answer> {\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 : { [WowHeaders.SCOPE]: formatScope(options.scope) }),\n ...(options.space === undefined\n ? {}\n : { [WowHeaders.SPACE]: options.space }),\n ...options.headers,\n })) {\n if (value !== undefined) headers[name] = value;\n }\n // A body with exact numbers goes as its own JSON text, those numbers unquoted.\n const exact = call.body !== undefined && !marksNothing(call.numbers.body);\n if (exact) headers['Content-Type'] = 'application/json';\n const url = `${client.basePath ?? ''}${call.path}${queryString(call.query)}`;\n try {\n const response = await (client.fetcher ?? defaultFetcher).fetch(url, {\n method: call.method,\n headers,\n ...(call.body === undefined\n ? {}\n : {\n body: exact\n ? stringifyJson(call.body, call.numbers.body)\n : (call.body as object),\n }),\n ...(options.signal === undefined ? {} : { signal: options.signal }),\n });\n return new Answer(response, call.numbers.answer);\n } catch (error) {\n const response = (error as { exchange?: { response?: Response } })?.exchange\n ?.response;\n if (call.notModified && response?.status === 304) {\n return new Answer(response, undefined);\n }\n throw (await toWowProblemError(error)) ?? error;\n }\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(WowHeaders.ETAG);\n return tag === null ? undefined : tag.replace(/^W\\//, '').replace(/\"/g, '');\n}\n"],"mappings":";;;;AAyBA,IAAaC,IAAa;CAExB,YAAY;CAEZ,MAAM;CAEN,cAAc;CAEd,OAAO;CAEP,OAAO;CAEP,UAAU;CAEV,eAAe;CAEf,MAAM;CAEN,aAAa;CAEb,eAAe;AACjB;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;AAwCA,SAASG,EACP,GACQ;CACR,IAAI,CAACC,GAAO,OAAO;CACnB,IAAMC,IAAS,IAAI,gBAAgB;CACnC,KAAK,IAAM,CAACC,GA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