@pipelex/sdk 0.52.0 → 0.53.0

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.
Files changed (88) hide show
  1. package/README.md +17 -17
  2. package/dist/answer-reading.d.ts +70 -0
  3. package/dist/answer-reading.js +106 -0
  4. package/dist/answer-reading.js.map +1 -0
  5. package/dist/artifacts.js +45 -32
  6. package/dist/artifacts.js.map +1 -1
  7. package/dist/cli/present.d.ts +11 -14
  8. package/dist/cli/present.js +41 -37
  9. package/dist/cli/present.js.map +1 -1
  10. package/dist/cli/run.js +8 -7
  11. package/dist/cli/run.js.map +1 -1
  12. package/dist/cli/script.d.ts +1 -1
  13. package/dist/cli/source.js +2 -2
  14. package/dist/cli/source.js.map +1 -1
  15. package/dist/client.d.ts +248 -218
  16. package/dist/client.js +538 -477
  17. package/dist/client.js.map +1 -1
  18. package/dist/codegen-check.d.ts +21 -15
  19. package/dist/codegen-check.js +54 -27
  20. package/dist/codegen-check.js.map +1 -1
  21. package/dist/errors.d.ts +298 -455
  22. package/dist/errors.js +426 -534
  23. package/dist/errors.js.map +1 -1
  24. package/dist/exact-json.d.ts +8 -12
  25. package/dist/exact-json.js +19 -12
  26. package/dist/exact-json.js.map +1 -1
  27. package/dist/hooks/check-core.d.ts +12 -7
  28. package/dist/hooks/check-core.js +20 -14
  29. package/dist/hooks/check-core.js.map +1 -1
  30. package/dist/hooks/validate-stage.js +12 -3
  31. package/dist/hooks/validate-stage.js.map +1 -1
  32. package/dist/index.d.ts +4 -5
  33. package/dist/index.js +7 -6
  34. package/dist/index.js.map +1 -1
  35. package/dist/method-selector.js +7 -5
  36. package/dist/method-selector.js.map +1 -1
  37. package/dist/method-trees.d.ts +6 -7
  38. package/dist/method-trees.js +31 -37
  39. package/dist/method-trees.js.map +1 -1
  40. package/dist/models.d.ts +33 -210
  41. package/dist/models.js +2 -1
  42. package/dist/models.js.map +1 -1
  43. package/dist/prepare-inputs.d.ts +2 -2
  44. package/dist/prepare-inputs.js +51 -54
  45. package/dist/prepare-inputs.js.map +1 -1
  46. package/dist/problem-items.d.ts +19 -0
  47. package/dist/problem-items.js +52 -0
  48. package/dist/problem-items.js.map +1 -0
  49. package/dist/product-models.d.ts +23 -21
  50. package/dist/records.d.ts +12 -0
  51. package/dist/records.js +23 -0
  52. package/dist/records.js.map +1 -0
  53. package/dist/runs.d.ts +49 -38
  54. package/dist/runs.js +45 -19
  55. package/dist/runs.js.map +1 -1
  56. package/dist/transport-reading.d.ts +18 -0
  57. package/dist/{run-may-have-started.js → transport-reading.js} +15 -44
  58. package/dist/transport-reading.js.map +1 -0
  59. package/dist/upload-grant.d.ts +9 -6
  60. package/dist/upload-grant.js +42 -29
  61. package/dist/upload-grant.js.map +1 -1
  62. package/dist/upload.js +53 -33
  63. package/dist/upload.js.map +1 -1
  64. package/dist/version.d.ts +1 -1
  65. package/dist/version.js +1 -1
  66. package/docs/architecture.md +19 -19
  67. package/docs/artifact-download.md +6 -6
  68. package/docs/cli.md +1 -1
  69. package/docs/crate-routes.md +13 -14
  70. package/docs/errors.md +154 -267
  71. package/docs/exact-integers.md +1 -1
  72. package/docs/files.md +13 -13
  73. package/docs/hook-bundle.md +15 -1
  74. package/docs/input-preparation.md +14 -14
  75. package/docs/method-copy.md +24 -24
  76. package/docs/method-examples.md +13 -14
  77. package/docs/method-trees.md +27 -28
  78. package/docs/organization-branding.md +14 -16
  79. package/docs/run-results.md +8 -8
  80. package/package.json +1 -1
  81. package/dist/error-models.d.ts +0 -302
  82. package/dist/error-models.js +0 -203
  83. package/dist/error-models.js.map +0 -1
  84. package/dist/error-verdicts.d.ts +0 -46
  85. package/dist/error-verdicts.js +0 -120
  86. package/dist/error-verdicts.js.map +0 -1
  87. package/dist/run-may-have-started.d.ts +0 -31
  88. package/dist/run-may-have-started.js.map +0 -1
@@ -1,203 +0,0 @@
1
- /**
2
- * Error-report wire models — a failed run's stored report, and the typed members of a
3
- * problem document.
4
- *
5
- * **The runner owns these shapes; this SDK follows them.** A run that fails reports why as
6
- * the runner's `ErrorReport` (`pipelex.base_exceptions`), which the hosted platform stores
7
- * whole on the run row as `error` and serves through the runner's STRICT disclosure: on the
8
- * status read (`RunRead.error`), on the run records (`PipelineRun.error`,
9
- * `RunHistoryItem.error`), and inside the problem document of the results read's `409`, where
10
- * the client lifts it onto the failed arm of
11
- * `RunResultState` and onto `RunFailedError.error`. The same classification fields
12
- * (`error_domain`, `user_action`, …) ride a runner-rendered problem document as extension
13
- * members, which is why `ApiResponseError` types its members with the models declared here.
14
- *
15
- * Every field is optional and every interface keeps an index signature, for the reason
16
- * `TokensUsageRecord` gives: the runner adds fields without asking this SDK, and a field this
17
- * version does not name still reaches the caller. The enum-ish fields (`error_domain`,
18
- * `error_category`, `user_action.kind`) are open sets on the wire and stay `string`, never
19
- * frozen unions, so a value the runner adds is not an SDK break; their known values are listed
20
- * where they are declared.
21
- *
22
- * **A stored report is checked, not cast.** Every read that hands one back runs it through
23
- * `readRunErrorReport`, which keeps each named field only when it has the type declared here and
24
- * reads it as absent otherwise, as the Python twin does: a report written by an older runner, or
25
- * stored by hand, cannot hand a consumer a number where a string is typed. The client checks the
26
- * nested members of a problem document with the same readers, so `ApiResponseError`'s
27
- * `providerMetadata`, `migration`, `validationErrors` and `errors` hold to their types as a stored
28
- * report's do.
29
- *
30
- * **The platform serves the STRICT projection; this SDK strips nothing further.** The run row
31
- * keeps the runner's VERBOSE report as the operators' record, and every read that hands it to a
32
- * caller serves the rule the hosted runner applies to an error on `execute`: `error_type`,
33
- * `title`, `type_uri`, `error_domain`, `error_category`, `retryable` and `validation_errors`
34
- * pass through; `message` and `user_action` pass through only when `caller_facing_message` is
35
- * `true`, which the served report then keeps, and otherwise `message` is the placeholder
36
- * `An internal error occurred.` while `user_action` and the flag are absent; `provider_metadata`
37
- * keeps only `status_code` and `retry_after_seconds`; `model`, `provider` and `migration` are
38
- * absent. The reports the platform writes itself are caller-facing copy, so they keep their
39
- * message and their next step. A platform run locally with `ERROR_DISCLOSURE=verbose` serves the
40
- * report whole, which is why the types still name every member the runner writes. Deciding what
41
- * a person should see is each consumer's presentation; the report arrives here as served,
42
- * members this SDK does not name included.
43
- */
44
- // ── Checking a stored report, and a problem document's nested members ─
45
- //
46
- // The readers below that are exported serve the client's problem-document parser as well; they
47
- // stay internal, out of the package entry.
48
- /** The string fields of a report, kept when they are a string (empty included) or `null`. */
49
- const REPORT_STRING_FIELDS = [
50
- "error_type",
51
- "message",
52
- "title",
53
- "type_uri",
54
- "error_domain",
55
- "error_category",
56
- "model",
57
- "provider",
58
- ];
59
- /** The boolean fields of a report, kept when they are a boolean or `null`. */
60
- const REPORT_BOOLEAN_FIELDS = ["retryable", "caller_facing_message"];
61
- /** The string fields of `provider_metadata`. */
62
- const PROVIDER_STRING_FIELDS = [
63
- "provider",
64
- "sdk_exception_type",
65
- "message",
66
- "request_id",
67
- "provider_error_code",
68
- ];
69
- /** The fields of `provider_metadata` the hosted store may serve as strings: a number or a string. */
70
- const PROVIDER_NUMERIC_FIELDS = ["status_code", "retry_after_seconds"];
71
- /** The string fields of an item of a platform problem document's `errors[]`. */
72
- const FIELD_ERROR_STRING_FIELDS = ["field", "code", "detail"];
73
- /** Whether a value is a plain object: an object that is neither `null` nor an array. */
74
- export function isPlainObject(value) {
75
- return typeof value === "object" && value !== null && !Array.isArray(value);
76
- }
77
- /**
78
- * Drop each of `fields` from `record` when it is present and fails `fits`. `null` always fits,
79
- * since every field of these shapes allows it. Internal: the run status read's degradation
80
- * (`readRunDegradation` in `runs.ts`) is checked with it too.
81
- */
82
- export function dropUnfit(record, fields, fits) {
83
- for (const field of fields) {
84
- if (!Object.hasOwn(record, field))
85
- continue;
86
- const value = record[field];
87
- if (value !== null && !fits(value))
88
- delete record[field];
89
- }
90
- }
91
- const isString = (value) => typeof value === "string";
92
- const isBoolean = (value) => typeof value === "boolean";
93
- const isNumberOrString = (value) => typeof value === "number" || typeof value === "string";
94
- /** `user_action` is kept whole or not at all: an object whose `kind` and `detail` are strings. */
95
- function readUserAction(value) {
96
- return typeof value.kind === "string" && typeof value.detail === "string"
97
- ? { ...value }
98
- : undefined;
99
- }
100
- /**
101
- * `provider_metadata`, its named string fields kept as strings and `status_code` and
102
- * `retry_after_seconds` as a number or a string; its other members are relayed as sent.
103
- */
104
- export function readProviderMetadata(value) {
105
- const metadata = { ...value };
106
- dropUnfit(metadata, PROVIDER_STRING_FIELDS, isString);
107
- dropUnfit(metadata, PROVIDER_NUMERIC_FIELDS, isNumberOrString);
108
- return metadata;
109
- }
110
- /**
111
- * `migration`, its `remedy` kept as a string, `would_write` and `needs_attention` as booleans, and
112
- * `plans` as an array keeping only its objects; its other members are relayed as sent.
113
- */
114
- export function readMigration(value) {
115
- const migration = { ...value };
116
- dropUnfit(migration, ["remedy"], isString);
117
- dropUnfit(migration, ["would_write", "needs_attention"], isBoolean);
118
- if (Object.hasOwn(migration, "plans") && migration.plans !== null) {
119
- if (Array.isArray(migration.plans))
120
- migration.plans = migration.plans.filter(isPlainObject);
121
- else
122
- delete migration.plans;
123
- }
124
- return migration;
125
- }
126
- /**
127
- * A validation item is kept when it is an object with a string `category` and `message`, its other
128
- * members relayed as sent. It checks a problem document's items and a stored report's only:
129
- * `validate()` and the crate routes hand their reports' items back unchecked.
130
- */
131
- export function isValidationItem(value) {
132
- return isPlainObject(value) && isString(value.category) && isString(value.message);
133
- }
134
- /**
135
- * An item of a platform problem document's `errors[]`, its `field`, `code` and `detail` kept when
136
- * they are strings and its other members relayed as sent.
137
- */
138
- export function readFieldError(value) {
139
- const item = { ...value };
140
- dropUnfit(item, FIELD_ERROR_STRING_FIELDS, isString);
141
- return item;
142
- }
143
- /**
144
- * A failed run's stored report, checked field by field — the one way every read in this SDK
145
- * hands a report back.
146
- *
147
- * - A value that is not a plain object reads as `null`, no report.
148
- * - Each string field (`error_type`, `message`, `title`, `type_uri`, `error_domain`,
149
- * `error_category`, `model`, `provider`) is kept when it is a string, an empty one included, and
150
- * is absent otherwise. Deciding that a blank field says nothing is presentation, left to each
151
- * consumer.
152
- * - `retryable` and `caller_facing_message` are kept when they are booleans.
153
- * - `user_action` is kept whole or not at all: an object whose `kind` and `detail` are both
154
- * strings, which is what `UserAction` promises. (The Python twin keeps a partial action, its
155
- * stored-report action being a lenient type of its own; this is the one place the two differ.)
156
- * - `provider_metadata` is kept when it is an object, with each named field checked: the strings
157
- * as strings, `status_code` and `retry_after_seconds` as a number or a string, since the hosted
158
- * store serves its numbers as strings.
159
- * - `migration` is kept when it is an object: `remedy` as a string, `would_write` and
160
- * `needs_attention` as booleans, and `plans` as an array keeping only its objects.
161
- * - `validation_errors` is kept when it is an array, keeping each item that is an object with a
162
- * string `category` and a string `message`.
163
- * - `null` is kept wherever the type allows it, which is every named field; and members this SDK
164
- * does not name, in the report and in each nested object, are relayed as sent.
165
- *
166
- * Internal: every report a consumer meets comes through one of the reads that apply it.
167
- */
168
- export function readRunErrorReport(value) {
169
- if (!isPlainObject(value))
170
- return null;
171
- const report = { ...value };
172
- dropUnfit(report, REPORT_STRING_FIELDS, isString);
173
- dropUnfit(report, REPORT_BOOLEAN_FIELDS, isBoolean);
174
- readNested(report, "user_action", readUserAction);
175
- readNested(report, "provider_metadata", readProviderMetadata);
176
- readNested(report, "migration", readMigration);
177
- if (Object.hasOwn(report, "validation_errors") && report.validation_errors !== null) {
178
- if (Array.isArray(report.validation_errors)) {
179
- report.validation_errors = report.validation_errors.filter(isValidationItem);
180
- }
181
- else {
182
- delete report.validation_errors;
183
- }
184
- }
185
- return report;
186
- }
187
- /**
188
- * Replace the object at `field` with what `read` keeps of it, or drop the field when it is not an
189
- * object or `read` keeps nothing. `null` is kept.
190
- */
191
- function readNested(record, field, read) {
192
- if (!Object.hasOwn(record, field))
193
- return;
194
- const value = record[field];
195
- if (value === null)
196
- return;
197
- const kept = isPlainObject(value) ? read(value) : undefined;
198
- if (kept === undefined)
199
- delete record[field];
200
- else
201
- record[field] = kept;
202
- }
203
- //# sourceMappingURL=error-models.js.map
@@ -1 +0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AK,IAAI,EAAE,CAAC;QACpF,IAAI,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,iBAAiB,GAAG,MAAM,CAAC,iBAAiB,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;QAC/E,CAAC;aAAM,CAAC;YACN,OAAO,MAAM,CAAC,iBAAiB,CAAC;QAClC,CAAC;IACH,CAAC;IACD,OAAO,MAAwB,CAAC;AAClC,CAAC;AAED;;;GAGG;AACH,SAAS,UAAU,CACjB,MAA+B,EAC/B,KAAa,EACb,IAAiD;IAEjD,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,OAAO;IAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO;IAC3B,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC5D,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;;QACxC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;AAC5B,CAAC"}
@@ -1,46 +0,0 @@
1
- /**
2
- * The verdict an `ApiResponseError` falls back to when the server sent no usable member.
3
- *
4
- * A problem document may carry `retryable` and `error_domain`, and the error reads the members
5
- * the server sent first (see `ApiResponseError`): the runner sends them on the problems it renders,
6
- * and the platform on those it renders itself once its deployment classifies them. Where one is
7
- * missing — a platform route that does not classify its refusals, as its Lambda-backed routes do
8
- * not yet, a gateway's HTML page, a bare runner's Starlette `{"detail": "Not Found"}` — that member
9
- * is read off this table instead, so a consumer never has to choose its own default. The one
10
- * exception is a `retryable` missing beside a sent `input` or `config` domain, which is not
11
- * retryable whatever the status. The table reads only the HTTP status, the platform's native
12
- * `code`, and whether the body names what it refused.
13
- *
14
- * It is also the platform's reference: the verdicts the platform sends on its own refusals are
15
- * decided against this table, so a refusal keeps its verdict whether the platform sent it or the
16
- * table supplied it. The Python twin, `pipelex-sdk`, applies the same table as its `fallback_verdict`.
17
- * The case file `tests/fixtures/error-verdicts.json` holds every row, and this package's suite
18
- * drives the table through it; the Python suite drives its own code through the copy that
19
- * `make shared-files` writes at the repository's root, byte for byte identical.
20
- */
21
- import type { Problem } from "mthds/protocol";
22
- import type { ErrorVerdict } from "./errors.js";
23
- /**
24
- * The verdict of a refused request whose problem document carried no usable member.
25
- *
26
- * - `status` is the HTTP status of the answer.
27
- * - `code` is the platform's native code, when the body carried one.
28
- * - `named` says whether the body names what it refused: a platform `code` or a runner
29
- * `error_type`. It decides a `404`: a named one is a resource the caller asked for that does not
30
- * exist (`input`), a bare one is a route the deployment does not serve (`config`).
31
- *
32
- * Every `4xx` the table does not list is the caller's request refused (`input`, not retryable),
33
- * every `5xx` it does not list is a fault in the service that may pass (`runtime`, retryable),
34
- * and any other status is one no refusal carries, such as the `2xx` of an answer the client could
35
- * not read, so nothing says a retry helps (`runtime`, not retryable).
36
- */
37
- export declare function fallbackVerdict(status: number, code: string | undefined, named: boolean): ErrorVerdict;
38
- /**
39
- * The verdict of a problem of the MTHDS standard, in this SDK's vocabulary, so that an error of
40
- * the standard's own client (`mthds`) reads with `errorVerdictOf` as this SDK's errors do. The
41
- * standard's domain and retry verdict are read by its own fallbacks (`problemDomain`,
42
- * `problemRetry`): a domain it does not know reads by the code's family, else as `runtime`, and
43
- * a retry verdict it does not know as `no`. The Python twin, `pipelex-sdk`, applies the same
44
- * mapping.
45
- */
46
- export declare function problemVerdict(problem: Pick<Problem, "code" | "domain" | "retry">): ErrorVerdict;
@@ -1,120 +0,0 @@
1
- /**
2
- * The verdict an `ApiResponseError` falls back to when the server sent no usable member.
3
- *
4
- * A problem document may carry `retryable` and `error_domain`, and the error reads the members
5
- * the server sent first (see `ApiResponseError`): the runner sends them on the problems it renders,
6
- * and the platform on those it renders itself once its deployment classifies them. Where one is
7
- * missing — a platform route that does not classify its refusals, as its Lambda-backed routes do
8
- * not yet, a gateway's HTML page, a bare runner's Starlette `{"detail": "Not Found"}` — that member
9
- * is read off this table instead, so a consumer never has to choose its own default. The one
10
- * exception is a `retryable` missing beside a sent `input` or `config` domain, which is not
11
- * retryable whatever the status. The table reads only the HTTP status, the platform's native
12
- * `code`, and whether the body names what it refused.
13
- *
14
- * It is also the platform's reference: the verdicts the platform sends on its own refusals are
15
- * decided against this table, so a refusal keeps its verdict whether the platform sent it or the
16
- * table supplied it. The Python twin, `pipelex-sdk`, applies the same table as its `fallback_verdict`.
17
- * The case file `tests/fixtures/error-verdicts.json` holds every row, and this package's suite
18
- * drives the table through it; the Python suite drives its own code through the copy that
19
- * `make shared-files` writes at the repository's root, byte for byte identical.
20
- */
21
- import { problemDomain, problemRetry } from "mthds/protocol";
22
- const INPUT = Object.freeze({ errorDomain: "input", retryable: false });
23
- const CONFIG = Object.freeze({ errorDomain: "config", retryable: false });
24
- const TRANSIENT = Object.freeze({ errorDomain: "runtime", retryable: true });
25
- const FAULT = Object.freeze({ errorDomain: "runtime", retryable: false });
26
- /** The platform code a `409` carries when the organization holds as many API keys as it may. */
27
- const API_KEY_LIMIT_CODE = "pipelex_api_key_limit_reached";
28
- /**
29
- * The platform code a `409` carries when an earlier request under the same `Idempotency-Key` is
30
- * still being handled: nothing ran for this one, and the same request under the same key is
31
- * answered with the earlier one's outcome once it is stored.
32
- */
33
- const IDEMPOTENCY_KEY_IN_USE_CODE = "idempotency_key_in_use";
34
- /**
35
- * The verdict of a refused request whose problem document carried no usable member.
36
- *
37
- * - `status` is the HTTP status of the answer.
38
- * - `code` is the platform's native code, when the body carried one.
39
- * - `named` says whether the body names what it refused: a platform `code` or a runner
40
- * `error_type`. It decides a `404`: a named one is a resource the caller asked for that does not
41
- * exist (`input`), a bare one is a route the deployment does not serve (`config`).
42
- *
43
- * Every `4xx` the table does not list is the caller's request refused (`input`, not retryable),
44
- * every `5xx` it does not list is a fault in the service that may pass (`runtime`, retryable),
45
- * and any other status is one no refusal carries, such as the `2xx` of an answer the client could
46
- * not read, so nothing says a retry helps (`runtime`, not retryable).
47
- */
48
- export function fallbackVerdict(status, code, named) {
49
- switch (status) {
50
- case 401:
51
- case 402:
52
- case 403:
53
- // The credential, the plan or the access must change.
54
- return CONFIG;
55
- case 404:
56
- return named ? INPUT : CONFIG;
57
- case 405:
58
- // The deployment does not serve this method on the route.
59
- return CONFIG;
60
- case 408:
61
- case 429:
62
- // Refused for its timing, not its content.
63
- return TRANSIENT;
64
- case 409:
65
- // The organization holds as many API keys as it may: someone lifts it by removing a key.
66
- if (code === API_KEY_LIMIT_CODE)
67
- return CONFIG;
68
- // An earlier request still holds the idempotency key, and releases it by finishing.
69
- if (code === IDEMPOTENCY_KEY_IN_USE_CODE)
70
- return TRANSIENT;
71
- // Any other conflict with the stored state is the caller's.
72
- return INPUT;
73
- case 501:
74
- // The deployment does not implement it, and asking again will not change that.
75
- return CONFIG;
76
- }
77
- if (status >= 400 && status < 500)
78
- return INPUT;
79
- if (status >= 500 && status < 600)
80
- return TRANSIENT;
81
- return FAULT;
82
- }
83
- /**
84
- * Who can fix a failure the MTHDS standard's problem says must be acted on by its `domain`, in
85
- * this SDK's vocabulary: the caller changes the request or the method it names (`input`, `method`),
86
- * someone changes the environment, the credential, the plan or the deployment (`account`,
87
- * `operator`), or nobody beforehand (`runtime`).
88
- */
89
- const ERROR_DOMAIN_OF = Object.freeze({
90
- input: "input",
91
- method: "input",
92
- account: "config",
93
- operator: "config",
94
- runtime: "runtime",
95
- });
96
- /**
97
- * Whether asking again can succeed, by the standard's `retry`: only `yes` is retryable, since an
98
- * operation whose outcome is unknown may already have taken effect, and a run that may have
99
- * started is never retryable.
100
- */
101
- const RETRYABLE_OF = Object.freeze({
102
- yes: true,
103
- no: false,
104
- outcome_unknown: false,
105
- });
106
- /**
107
- * The verdict of a problem of the MTHDS standard, in this SDK's vocabulary, so that an error of
108
- * the standard's own client (`mthds`) reads with `errorVerdictOf` as this SDK's errors do. The
109
- * standard's domain and retry verdict are read by its own fallbacks (`problemDomain`,
110
- * `problemRetry`): a domain it does not know reads by the code's family, else as `runtime`, and
111
- * a retry verdict it does not know as `no`. The Python twin, `pipelex-sdk`, applies the same
112
- * mapping.
113
- */
114
- export function problemVerdict(problem) {
115
- return {
116
- errorDomain: ERROR_DOMAIN_OF[problemDomain(problem)],
117
- retryable: RETRYABLE_OF[problemRetry(problem)],
118
- };
119
- }
120
- //# sourceMappingURL=error-verdicts.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"error-verdicts.js","sourceRoot":"","sources":["../src/error-verdicts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAK7D,MAAM,KAAK,GAAiB,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AACtF,MAAM,MAAM,GAAiB,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AACxF,MAAM,SAAS,GAAiB,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3F,MAAM,KAAK,GAAiB,MAAM,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;AAExF,gGAAgG;AAChG,MAAM,kBAAkB,GAAG,+BAA+B,CAAC;AAE3D;;;;GAIG;AACH,MAAM,2BAA2B,GAAG,wBAAwB,CAAC;AAE7D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAc,EACd,IAAwB,EACxB,KAAc;IAEd,QAAQ,MAAM,E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AAE,eAAe,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACpD,SAAS,EAAE,YAAY,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;KAC/C,CAAC;AACJ,CAAC"}
@@ -1,31 +0,0 @@
1
- /**
2
- * Whether a failed request that may create a run, a start or a blocking execute, may still have
3
- * started one whose id never reached the caller. `ApiUnreachableError` and `ApiResponseError` read
4
- * it when the client tells them their request may create a run, and carry the answer as
5
- * `runMayHaveStarted`; the Python twin, `pipelex-sdk`, reads the same failures the same way in
6
- * `pipelex_sdk.run_may_have_started`.
7
- *
8
- * The reading errs on the safe side. A false "may have started" costs the person a look at the run
9
- * history; a false "did not start" costs a second paid run. So every failure counts as one that
10
- * may have started a run unless it proves otherwise: a transport failure that proves nothing was
11
- * sent, and an answer that says the request was refused before anything ran.
12
- */
13
- /**
14
- * Whether an answer to a request that may create a run leaves one possibly started:
15
- *
16
- * - any `2xx`, which the client met only because it could not read it: the server accepted the
17
- * request, and only its acknowledgement was lost;
18
- * - a `408`, which a proxy in front of the platform may answer for a request it forwarded;
19
- * - every `5xx` but a `501`, which says the deployment does not serve the route, and a `503`
20
- * carrying the platform's code `pipeline_start_unavailable`, which says the runner was never
21
- * reached: the server or a gateway failed while handling the request.
22
- *
23
- * Any other status is the request refused before anything ran.
24
- */
25
- export declare function answerMayHaveStartedRun(status: number, code: string | undefined): boolean;
26
- /**
27
- * Whether a transport failure of a request that may create a run leaves one possibly started:
28
- * every failure but one that proves nothing was sent. `cause` is the failure fetch threw, which
29
- * `ApiUnreachableError` keeps as its own `cause`.
30
- */
31
- export declare function transportMayHaveStartedRun(cause: unknown): boolean;
@@ -1 +0,0 @@
1
- {"version":3,"file":"run-may-have-started.js","sourceRoot":"","sources":["../src/run-may-have-started.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH;;;;GAIG;AACH,MAAM,sBAAsB,GAAG,4BAA4B,CAAC;AAE5D;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,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