@xeonr/pipelines-sdk 0.0.0-stage → 0.2.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 (102) hide show
  1. package/README.md +334 -2
  2. package/dist/auth.d.ts +72 -0
  3. package/dist/auth.d.ts.map +1 -0
  4. package/dist/auth.js +139 -0
  5. package/dist/auth.js.map +1 -0
  6. package/dist/client.d.ts +129 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/client.js +106 -0
  9. package/dist/client.js.map +1 -0
  10. package/dist/errors.d.ts +113 -0
  11. package/dist/errors.d.ts.map +1 -0
  12. package/dist/errors.js +115 -0
  13. package/dist/errors.js.map +1 -0
  14. package/dist/gen/buf/validate/validate_pb.d.ts +4828 -0
  15. package/dist/gen/buf/validate/validate_pb.d.ts.map +1 -0
  16. package/dist/gen/buf/validate/validate_pb.js +357 -0
  17. package/dist/gen/buf/validate/validate_pb.js.map +1 -0
  18. package/dist/gen/gnostic/openapi/v3/annotations_pb.d.ts +24 -0
  19. package/dist/gen/gnostic/openapi/v3/annotations_pb.d.ts.map +1 -0
  20. package/dist/gen/gnostic/openapi/v3/annotations_pb.js +37 -0
  21. package/dist/gen/gnostic/openapi/v3/annotations_pb.js.map +1 -0
  22. package/dist/gen/gnostic/openapi/v3/openapiv3_pb.d.ts +2245 -0
  23. package/dist/gen/gnostic/openapi/v3/openapiv3_pb.d.ts.map +1 -0
  24. package/dist/gen/gnostic/openapi/v3/openapiv3_pb.js +410 -0
  25. package/dist/gen/gnostic/openapi/v3/openapiv3_pb.js.map +1 -0
  26. package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.d.ts +1031 -0
  27. package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.d.ts.map +1 -0
  28. package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.js +219 -0
  29. package/dist/gen/xeonr/pipelines/private/v1/attempt_pb.js.map +1 -0
  30. package/dist/gen/xeonr/pipelines/private/v1/runners_pb.d.ts +190 -0
  31. package/dist/gen/xeonr/pipelines/private/v1/runners_pb.d.ts.map +1 -0
  32. package/dist/gen/xeonr/pipelines/private/v1/runners_pb.js +53 -0
  33. package/dist/gen/xeonr/pipelines/private/v1/runners_pb.js.map +1 -0
  34. package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.d.ts +1161 -0
  35. package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.d.ts.map +1 -0
  36. package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.js +269 -0
  37. package/dist/gen/xeonr/pipelines/private/v1/step_local_pb.js.map +1 -0
  38. package/dist/gen/xeonr/pipelines/private/v1/worker_pb.d.ts +1061 -0
  39. package/dist/gen/xeonr/pipelines/private/v1/worker_pb.d.ts.map +1 -0
  40. package/dist/gen/xeonr/pipelines/private/v1/worker_pb.js +221 -0
  41. package/dist/gen/xeonr/pipelines/private/v1/worker_pb.js.map +1 -0
  42. package/dist/gen/xeonr/pipelines/v1/common_pb.d.ts +580 -0
  43. package/dist/gen/xeonr/pipelines/v1/common_pb.d.ts.map +1 -0
  44. package/dist/gen/xeonr/pipelines/v1/common_pb.js +483 -0
  45. package/dist/gen/xeonr/pipelines/v1/common_pb.js.map +1 -0
  46. package/dist/gen/xeonr/pipelines/v1/definition_pb.d.ts +762 -0
  47. package/dist/gen/xeonr/pipelines/v1/definition_pb.d.ts.map +1 -0
  48. package/dist/gen/xeonr/pipelines/v1/definition_pb.js +190 -0
  49. package/dist/gen/xeonr/pipelines/v1/definition_pb.js.map +1 -0
  50. package/dist/gen/xeonr/pipelines/v1/pools_pb.d.ts +919 -0
  51. package/dist/gen/xeonr/pipelines/v1/pools_pb.d.ts.map +1 -0
  52. package/dist/gen/xeonr/pipelines/v1/pools_pb.js +272 -0
  53. package/dist/gen/xeonr/pipelines/v1/pools_pb.js.map +1 -0
  54. package/dist/gen/xeonr/pipelines/v1/registry_pb.d.ts +895 -0
  55. package/dist/gen/xeonr/pipelines/v1/registry_pb.d.ts.map +1 -0
  56. package/dist/gen/xeonr/pipelines/v1/registry_pb.js +277 -0
  57. package/dist/gen/xeonr/pipelines/v1/registry_pb.js.map +1 -0
  58. package/dist/gen/xeonr/pipelines/v1/runs_pb.d.ts +1237 -0
  59. package/dist/gen/xeonr/pipelines/v1/runs_pb.d.ts.map +1 -0
  60. package/dist/gen/xeonr/pipelines/v1/runs_pb.js +204 -0
  61. package/dist/gen/xeonr/pipelines/v1/runs_pb.js.map +1 -0
  62. package/dist/gen/xeonr/pipelines/v1/secrets_pb.d.ts +647 -0
  63. package/dist/gen/xeonr/pipelines/v1/secrets_pb.d.ts.map +1 -0
  64. package/dist/gen/xeonr/pipelines/v1/secrets_pb.js +181 -0
  65. package/dist/gen/xeonr/pipelines/v1/secrets_pb.js.map +1 -0
  66. package/dist/gen/xeonr/pipelines/v1/sinks_pb.d.ts +381 -0
  67. package/dist/gen/xeonr/pipelines/v1/sinks_pb.d.ts.map +1 -0
  68. package/dist/gen/xeonr/pipelines/v1/sinks_pb.js +145 -0
  69. package/dist/gen/xeonr/pipelines/v1/sinks_pb.js.map +1 -0
  70. package/dist/gen/xeonr/platform/v1/options_pb.d.ts +313 -0
  71. package/dist/gen/xeonr/platform/v1/options_pb.d.ts.map +1 -0
  72. package/dist/gen/xeonr/platform/v1/options_pb.js +235 -0
  73. package/dist/gen/xeonr/platform/v1/options_pb.js.map +1 -0
  74. package/dist/handler.d.ts +94 -0
  75. package/dist/handler.d.ts.map +1 -0
  76. package/dist/handler.js +18 -0
  77. package/dist/handler.js.map +1 -0
  78. package/dist/index.d.ts +30 -0
  79. package/dist/index.d.ts.map +1 -0
  80. package/dist/index.js +24 -0
  81. package/dist/index.js.map +1 -0
  82. package/dist/internal/time.d.ts +8 -0
  83. package/dist/internal/time.d.ts.map +1 -0
  84. package/dist/internal/time.js +25 -0
  85. package/dist/internal/time.js.map +1 -0
  86. package/dist/logship.d.ts +117 -0
  87. package/dist/logship.d.ts.map +1 -0
  88. package/dist/logship.js +319 -0
  89. package/dist/logship.js.map +1 -0
  90. package/dist/testing/index.d.ts +215 -0
  91. package/dist/testing/index.d.ts.map +1 -0
  92. package/dist/testing/index.js +1015 -0
  93. package/dist/testing/index.js.map +1 -0
  94. package/dist/transport.d.ts +43 -0
  95. package/dist/transport.d.ts.map +1 -0
  96. package/dist/transport.js +44 -0
  97. package/dist/transport.js.map +1 -0
  98. package/dist/worker.d.ts +236 -0
  99. package/dist/worker.d.ts.map +1 -0
  100. package/dist/worker.js +733 -0
  101. package/dist/worker.js.map +1 -0
  102. package/package.json +70 -3
@@ -0,0 +1,129 @@
1
+ import type { JsonObject, MessageInitShape } from "@bufbuild/protobuf";
2
+ import type { Client, Transport } from "@connectrpc/connect";
3
+ import type { RunState } from "./gen/xeonr/pipelines/v1/common_pb.js";
4
+ import type { Definition } from "./gen/xeonr/pipelines/v1/definition_pb.js";
5
+ import { DefinitionSchema } from "./gen/xeonr/pipelines/v1/definition_pb.js";
6
+ import type { RetrySchema } from "./gen/xeonr/pipelines/v1/definition_pb.js";
7
+ import { RunsService } from "./gen/xeonr/pipelines/v1/runs_pb.js";
8
+ import type { Exclusion, ExclusionSchema, GetRunGraphResponse, Run } from "./gen/xeonr/pipelines/v1/runs_pb.js";
9
+ import type { Connection } from "./transport.js";
10
+ /** Options for {@link PipelinesClient}: how to reach pipelines-api. */
11
+ export type PipelinesClientOptions = Connection & {
12
+ /** Bound on each call. Default 30 s. */
13
+ timeoutMs?: number;
14
+ };
15
+ /** What {@link PipelinesClient.createRun} takes. */
16
+ export interface CreateRunInput {
17
+ /**
18
+ * Makes the create safe to repeat, per calling product: a repeat returns
19
+ * the first run with `deduplicated` set.
20
+ */
21
+ idempotencyKey: string;
22
+ /** The team the run belongs to: `urn:xeonr:auth:team:<uuid>`. */
23
+ tenant: string;
24
+ /** What the run is about. */
25
+ resource: {
26
+ kind: string;
27
+ id: string;
28
+ json?: JsonObject;
29
+ };
30
+ /** The definition to run, as a message or its init shape. */
31
+ definition: Definition | MessageInitShape<typeof DefinitionSchema>;
32
+ /** Facts about the run the product vouches for (tiers and secret policies read them). */
33
+ attestedFacts?: JsonObject;
34
+ /** Per-run values, read as `${{ variables.<name> }}`. Never secrets. */
35
+ variables?: JsonObject;
36
+ /** Makes runs sharing a key mutually exclusive (milestone 2). */
37
+ exclusion?: Exclusion | MessageInitShape<typeof ExclusionSchema>;
38
+ }
39
+ /** What {@link PipelinesClient.createJob} takes. */
40
+ export interface CreateJobInput {
41
+ /** The team the job belongs to: `urn:xeonr:auth:team:<uuid>`. */
42
+ tenant: string;
43
+ /** The worker handler to run, `<namespace>/<name>`. */
44
+ handler: string;
45
+ /** The handler's inputs, by input name. At most 256 KiB encoded. */
46
+ payload?: JsonObject;
47
+ /** Holds the job back: it is not offered to a worker earlier. At most a year. */
48
+ delayMs?: number;
49
+ /** Makes the create safe to repeat, per calling product. */
50
+ idempotencyKey: string;
51
+ /** What the job is about, if anything. */
52
+ resource?: {
53
+ kind: string;
54
+ id: string;
55
+ json?: JsonObject;
56
+ };
57
+ /**
58
+ * The job's retry policy, as a node's `retry`. Unset is the platform's
59
+ * default: transient classes only, which retries a handler error only when
60
+ * the worker marked it transient (`TransientError`). List
61
+ * `FailureClass.HANDLER_ERROR` in `when` to retry every handler error; a
62
+ * `PermanentError` is still never retried. `max` is at most 10.
63
+ */
64
+ retry?: MessageInitShape<typeof RetrySchema>;
65
+ /** Bounds one attempt from its start. Unset is the platform's default. */
66
+ timeoutMs?: number;
67
+ }
68
+ /** A created run, and whether the idempotency key had been seen. */
69
+ export interface CreatedRun {
70
+ run: Run;
71
+ /** The key was seen before and `run` is the one the first call made. */
72
+ deduplicated: boolean;
73
+ }
74
+ /** What {@link PipelinesClient.listRuns} takes. */
75
+ export interface ListRunsInput {
76
+ tenant: string;
77
+ resource?: {
78
+ kind: string;
79
+ id: string;
80
+ };
81
+ states?: RunState[];
82
+ cursor?: string;
83
+ limit?: number;
84
+ }
85
+ /**
86
+ * The public-API client a product uses to start runs and jobs and to read
87
+ * what became of them (`RunsService`). It calls with the product's Auth
88
+ * service-account token (scopes `pipelines:run:edit` and
89
+ * `pipelines:run:read`).
90
+ *
91
+ * Every method is a single RPC; errors are the API's `ConnectError`s,
92
+ * classified by {@link errorKind}.
93
+ */
94
+ export declare class PipelinesClient {
95
+ /** The generated RunsService client, for anything not wrapped here. */
96
+ readonly runs: Client<typeof RunsService>;
97
+ /** The transport, to build other generated clients on. */
98
+ readonly transport: Transport;
99
+ private readonly timeoutMs;
100
+ constructor(opts: PipelinesClientOptions);
101
+ /**
102
+ * Creates a run of a definition (`CreateRun`). Worker nodes name a handler
103
+ * (`{ id, action: { case: "handler", value: "acme/resize" } }`); they mix
104
+ * freely with image nodes in one run.
105
+ */
106
+ createRun(input: CreateRunInput, signal?: AbortSignal): Promise<CreatedRun>;
107
+ /**
108
+ * Enqueues a job: one run of one worker handler (`CreateJob`, the plan's
109
+ * `EnqueueJob`). With `delayMs` it stays `QUEUED` and is not offered to a
110
+ * worker before the delay has passed.
111
+ */
112
+ createJob(input: CreateJobInput, signal?: AbortSignal): Promise<CreatedRun>;
113
+ /** Reads one run (`GetRun`). */
114
+ getRun(runId: string, signal?: AbortSignal): Promise<Run>;
115
+ /** Reads a run with its frozen definition and every node's attempts and outputs (`GetRunGraph`). */
116
+ getRunGraph(runId: string, signal?: AbortSignal): Promise<GetRunGraphResponse>;
117
+ /** Lists a tenant's runs, newest first (`ListRuns`). */
118
+ listRuns(input: ListRunsInput, signal?: AbortSignal): Promise<{
119
+ runs: Run[];
120
+ nextCursor: string;
121
+ }>;
122
+ /**
123
+ * Asks a run to stop (`CancelRun`). Running attempts are told on their next
124
+ * heartbeat; an SDK worker aborts the handler's signal. Idempotent.
125
+ */
126
+ cancelRun(runId: string, reason?: string, signal?: AbortSignal): Promise<Run>;
127
+ private opts;
128
+ }
129
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAC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B;IAMxC;;;;OAIG;IACG,SAAS,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAgBjF;;;;OAIG;IACG,SAAS,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;IAuBjF,gCAAgC;IAC1B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAI/D,oGAAoG;IAC9F,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAIpF,wDAAwD;IAClD,QAAQ,CAAC,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,EAAE,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAcxG;;;OAGG;IACG,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAInF,OAAO,CAAC,IAAI;CAGb"}
package/dist/client.js ADDED
@@ -0,0 +1,106 @@
1
+ import { create } from "@bufbuild/protobuf";
2
+ import { durationFromMs } from "@bufbuild/protobuf/wkt";
3
+ import { createClient } from "@connectrpc/connect";
4
+ import { DefinitionSchema } from "./gen/xeonr/pipelines/v1/definition_pb.js";
5
+ import { RunsService } from "./gen/xeonr/pipelines/v1/runs_pb.js";
6
+ import { transportOf } from "./transport.js";
7
+ /**
8
+ * The public-API client a product uses to start runs and jobs and to read
9
+ * what became of them (`RunsService`). It calls with the product's Auth
10
+ * service-account token (scopes `pipelines:run:edit` and
11
+ * `pipelines:run:read`).
12
+ *
13
+ * Every method is a single RPC; errors are the API's `ConnectError`s,
14
+ * classified by {@link errorKind}.
15
+ */
16
+ export class PipelinesClient {
17
+ /** The generated RunsService client, for anything not wrapped here. */
18
+ runs;
19
+ /** The transport, to build other generated clients on. */
20
+ transport;
21
+ timeoutMs;
22
+ constructor(opts) {
23
+ this.transport = transportOf(opts);
24
+ this.runs = createClient(RunsService, this.transport);
25
+ this.timeoutMs = opts.timeoutMs ?? 30_000;
26
+ }
27
+ /**
28
+ * Creates a run of a definition (`CreateRun`). Worker nodes name a handler
29
+ * (`{ id, action: { case: "handler", value: "acme/resize" } }`); they mix
30
+ * freely with image nodes in one run.
31
+ */
32
+ async createRun(input, signal) {
33
+ const res = await this.runs.createRun({
34
+ idempotencyKey: input.idempotencyKey,
35
+ tenant: input.tenant,
36
+ resource: resource(input.resource),
37
+ source: { case: "inlineDefinition", value: create(DefinitionSchema, input.definition) },
38
+ ...(input.attestedFacts ? { attestedFacts: input.attestedFacts } : {}),
39
+ ...(input.variables ? { variables: input.variables } : {}),
40
+ ...(input.exclusion ? { exclusion: input.exclusion } : {}),
41
+ }, this.opts(signal));
42
+ return { run: required(res.run), deduplicated: res.deduplicated };
43
+ }
44
+ /**
45
+ * Enqueues a job: one run of one worker handler (`CreateJob`, the plan's
46
+ * `EnqueueJob`). With `delayMs` it stays `QUEUED` and is not offered to a
47
+ * worker before the delay has passed.
48
+ */
49
+ async createJob(input, signal) {
50
+ if (input.delayMs !== undefined && (input.delayMs < 0 || !Number.isFinite(input.delayMs))) {
51
+ throw new RangeError("createJob: delayMs must be a finite, non-negative number");
52
+ }
53
+ if (input.timeoutMs !== undefined && (input.timeoutMs <= 0 || !Number.isFinite(input.timeoutMs))) {
54
+ throw new RangeError("createJob: timeoutMs must be a finite, positive number");
55
+ }
56
+ const res = await this.runs.createJob({
57
+ tenant: input.tenant,
58
+ handler: input.handler,
59
+ idempotencyKey: input.idempotencyKey,
60
+ ...(input.payload ? { payload: input.payload } : {}),
61
+ ...(input.delayMs ? { delay: durationFromMs(input.delayMs) } : {}),
62
+ ...(input.resource ? { resource: resource(input.resource) } : {}),
63
+ ...(input.retry ? { retry: input.retry } : {}),
64
+ ...(input.timeoutMs ? { timeout: durationFromMs(input.timeoutMs) } : {}),
65
+ }, this.opts(signal));
66
+ return { run: required(res.run), deduplicated: res.deduplicated };
67
+ }
68
+ /** Reads one run (`GetRun`). */
69
+ async getRun(runId, signal) {
70
+ return required((await this.runs.getRun({ runId }, this.opts(signal))).run);
71
+ }
72
+ /** Reads a run with its frozen definition and every node's attempts and outputs (`GetRunGraph`). */
73
+ async getRunGraph(runId, signal) {
74
+ return this.runs.getRunGraph({ runId }, this.opts(signal));
75
+ }
76
+ /** Lists a tenant's runs, newest first (`ListRuns`). */
77
+ async listRuns(input, signal) {
78
+ const res = await this.runs.listRuns({
79
+ tenant: input.tenant,
80
+ ...(input.resource ? { resource: input.resource } : {}),
81
+ ...(input.states ? { states: input.states } : {}),
82
+ ...(input.cursor ? { cursor: input.cursor } : {}),
83
+ ...(input.limit ? { limit: input.limit } : {}),
84
+ }, this.opts(signal));
85
+ return { runs: res.runs, nextCursor: res.nextCursor };
86
+ }
87
+ /**
88
+ * Asks a run to stop (`CancelRun`). Running attempts are told on their next
89
+ * heartbeat; an SDK worker aborts the handler's signal. Idempotent.
90
+ */
91
+ async cancelRun(runId, reason, signal) {
92
+ return required((await this.runs.cancelRun({ runId, ...(reason ? { reason } : {}) }, this.opts(signal))).run);
93
+ }
94
+ opts(signal) {
95
+ return { timeoutMs: this.timeoutMs, ...(signal ? { signal } : {}) };
96
+ }
97
+ }
98
+ function resource(r) {
99
+ return { kind: r.kind, id: r.id, ...(r.json ? { json: r.json } : {}) };
100
+ }
101
+ function required(run) {
102
+ if (!run)
103
+ throw new Error("pipelines-api answered without a run");
104
+ return run;
105
+ }
106
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,oBA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AAC,CAAC,EAAE,CAAC,EAAE,CAAC;IACtE,CAAC;CACF;AAED,SAAS,QAAQ,CAAC,CAAkD;IAClE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;AACzE,CAAC;AAED,SAAS,QAAQ,CAAC,GAAoB;IACpC,IAAI,CAAC,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAClE,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -0,0 +1,113 @@
1
+ import { HandlerFailureKind } from "./gen/xeonr/pipelines/private/v1/worker_pb.js";
2
+ /**
3
+ * How the SDK treats an error from pipelines-api, decided by its Connect
4
+ * code. The rules are the API's (WorkerService's comments, and what the api
5
+ * and runner sessions settled):
6
+ *
7
+ * - `lost`: `failed_precondition`. The attempt is no longer this worker's
8
+ * (abandoned, re-offered, completed, or cancelled before it started). Stop
9
+ * work on it and report nothing more.
10
+ * - `final`: `invalid_argument`, `not_found`, `already_exists`,
11
+ * `unimplemented`, `out_of_range`. Repeating the same request cannot
12
+ * succeed; the caller decides what that means for its operation. On
13
+ * AppendLogs, `out_of_range` names the seq the server expects and the log
14
+ * shipper resends or renumbers from it; it is never fatal to the attempt.
15
+ * - `auth`: `unauthenticated`, `permission_denied`. Not transient: the
16
+ * credential or its scopes are wrong. A worker stops claiming and surfaces
17
+ * it.
18
+ * - `aborted`: the caller's own signal ended the call.
19
+ * - `transient`: everything else (`unavailable`, `deadline_exceeded`,
20
+ * `internal`, `resource_exhausted`, `aborted` from the server, network
21
+ * failures). Retried with backoff.
22
+ */
23
+ export type ErrorKind = "lost" | "final" | "auth" | "aborted" | "transient";
24
+ /** Classifies an error thrown by a pipelines-api call. */
25
+ export declare function errorKind(err: unknown): ErrorKind;
26
+ /**
27
+ * Thrown by a token provider when Auth's token endpoint refuses or cannot be
28
+ * read. It carries the HTTP status and the OAuth error code only, never the
29
+ * response body (log.no-secrets).
30
+ */
31
+ export declare class PipelinesAuthError extends Error {
32
+ /** The HTTP status of the token endpoint, when it answered. */
33
+ readonly status?: number | undefined;
34
+ /** The OAuth `error` code (`invalid_grant`, ...), when one was given. */
35
+ readonly oauthError?: string | undefined;
36
+ readonly name = "PipelinesAuthError";
37
+ constructor(message: string,
38
+ /** The HTTP status of the token endpoint, when it answered. */
39
+ status?: number | undefined,
40
+ /** The OAuth `error` code (`invalid_grant`, ...), when one was given. */
41
+ oauthError?: string | undefined, options?: ErrorOptions);
42
+ }
43
+ /**
44
+ * The reason an attempt's `AbortSignal` fires. Read it from `signal.reason`
45
+ * in a handler to tell why it is being asked to stop.
46
+ */
47
+ export declare class AttemptAbortedError extends Error {
48
+ /**
49
+ * - `cancelled`: a heartbeat answered cancel (the run was cancelled or the
50
+ * attempt superseded). Return or throw promptly; the cancel grace
51
+ * applies.
52
+ * - `deadline`: the attempt's timeout passed.
53
+ * - `lost`: the attempt is no longer this worker's (lease lost). Nothing
54
+ * the handler returns is reported.
55
+ * - `shutdown`: the worker is stopping and its shutdown timeout passed.
56
+ * The attempt is completed with `TERMINATION_INTERRUPTED`, which the
57
+ * platform retries by default (and, on an `interruptible` node,
58
+ * without spending the retry budget).
59
+ */
60
+ readonly cause: "cancelled" | "deadline" | "lost" | "shutdown";
61
+ readonly name = "AttemptAbortedError";
62
+ constructor(
63
+ /**
64
+ * - `cancelled`: a heartbeat answered cancel (the run was cancelled or the
65
+ * attempt superseded). Return or throw promptly; the cancel grace
66
+ * applies.
67
+ * - `deadline`: the attempt's timeout passed.
68
+ * - `lost`: the attempt is no longer this worker's (lease lost). Nothing
69
+ * the handler returns is reported.
70
+ * - `shutdown`: the worker is stopping and its shutdown timeout passed.
71
+ * The attempt is completed with `TERMINATION_INTERRUPTED`, which the
72
+ * platform retries by default (and, on an `interruptible` node,
73
+ * without spending the retry budget).
74
+ */
75
+ cause: "cancelled" | "deadline" | "lost" | "shutdown", message: string);
76
+ }
77
+ /** Thrown by `Worker.start` when the worker cannot boot (registration failed). */
78
+ export declare class WorkerStartError extends Error {
79
+ readonly name = "WorkerStartError";
80
+ }
81
+ /** Brands a thrown value with a failure kind, across duplicate copies of this package. */
82
+ declare const FAILURE_KIND: unique symbol;
83
+ /**
84
+ * Throw from a handler when the failure will not pass on a retry: a payload
85
+ * that fails validation, a 4xx from a downstream service. The attempt is
86
+ * completed with `handler_failure_kind = PERMANENT` and is not retried,
87
+ * whatever the node's `Retry.when` lists (a worker can narrow the policy,
88
+ * never widen it). The class stays `FAILURE_CLASS_HANDLER_ERROR`.
89
+ */
90
+ export declare class PermanentError extends Error {
91
+ readonly name: string;
92
+ readonly [FAILURE_KIND]: "permanent";
93
+ }
94
+ /**
95
+ * Throw from a handler when the failure may pass on its own: a downstream
96
+ * timeout, a 503. The attempt is completed with
97
+ * `handler_failure_kind = TRANSIENT`, so the platform's default policy
98
+ * retries it; an explicit `Retry.when` applies as written, and `Retry.max`
99
+ * and backoff bound it as always.
100
+ */
101
+ export declare class TransientError extends Error {
102
+ readonly name: string;
103
+ readonly [FAILURE_KIND]: "transient";
104
+ }
105
+ /**
106
+ * The handler failure kind a thrown value carries: PERMANENT for a
107
+ * {@link PermanentError}, TRANSIENT for a {@link TransientError} (or any
108
+ * error branded by another copy of this package), UNSPECIFIED otherwise. An
109
+ * error wrapped as the `cause` of another counts too.
110
+ */
111
+ export declare function handlerFailureKind(err: unknown): HandlerFailureKind;
112
+ export {};
113
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AAEnF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM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;CAChD;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,OAAO,GAAG,kBAAkB,CAQnE"}
package/dist/errors.js ADDED
@@ -0,0 +1,115 @@
1
+ import { Code, ConnectError } from "@connectrpc/connect";
2
+ import { HandlerFailureKind } from "./gen/xeonr/pipelines/private/v1/worker_pb.js";
3
+ /** Classifies an error thrown by a pipelines-api call. */
4
+ export function errorKind(err) {
5
+ if (err instanceof PipelinesAuthError)
6
+ return "auth";
7
+ const ce = ConnectError.from(err);
8
+ switch (ce.code) {
9
+ case Code.FailedPrecondition:
10
+ return "lost";
11
+ case Code.InvalidArgument:
12
+ case Code.NotFound:
13
+ case Code.AlreadyExists:
14
+ case Code.Unimplemented:
15
+ case Code.OutOfRange:
16
+ return "final";
17
+ case Code.Unauthenticated:
18
+ case Code.PermissionDenied:
19
+ return "auth";
20
+ case Code.Canceled:
21
+ return "aborted";
22
+ default:
23
+ return "transient";
24
+ }
25
+ }
26
+ /**
27
+ * Thrown by a token provider when Auth's token endpoint refuses or cannot be
28
+ * read. It carries the HTTP status and the OAuth error code only, never the
29
+ * response body (log.no-secrets).
30
+ */
31
+ export class PipelinesAuthError extends Error {
32
+ status;
33
+ oauthError;
34
+ name = "PipelinesAuthError";
35
+ constructor(message,
36
+ /** The HTTP status of the token endpoint, when it answered. */
37
+ status,
38
+ /** The OAuth `error` code (`invalid_grant`, ...), when one was given. */
39
+ oauthError, options) {
40
+ super(message, options);
41
+ this.status = status;
42
+ this.oauthError = oauthError;
43
+ }
44
+ }
45
+ /**
46
+ * The reason an attempt's `AbortSignal` fires. Read it from `signal.reason`
47
+ * in a handler to tell why it is being asked to stop.
48
+ */
49
+ export class AttemptAbortedError extends Error {
50
+ cause;
51
+ name = "AttemptAbortedError";
52
+ constructor(
53
+ /**
54
+ * - `cancelled`: a heartbeat answered cancel (the run was cancelled or the
55
+ * attempt superseded). Return or throw promptly; the cancel grace
56
+ * applies.
57
+ * - `deadline`: the attempt's timeout passed.
58
+ * - `lost`: the attempt is no longer this worker's (lease lost). Nothing
59
+ * the handler returns is reported.
60
+ * - `shutdown`: the worker is stopping and its shutdown timeout passed.
61
+ * The attempt is completed with `TERMINATION_INTERRUPTED`, which the
62
+ * platform retries by default (and, on an `interruptible` node,
63
+ * without spending the retry budget).
64
+ */
65
+ cause, message) {
66
+ super(message);
67
+ this.cause = cause;
68
+ }
69
+ }
70
+ /** Thrown by `Worker.start` when the worker cannot boot (registration failed). */
71
+ export class WorkerStartError extends Error {
72
+ name = "WorkerStartError";
73
+ }
74
+ /** Brands a thrown value with a failure kind, across duplicate copies of this package. */
75
+ const FAILURE_KIND = Symbol.for("@xeonr/pipelines-sdk/handler-failure-kind");
76
+ /**
77
+ * Throw from a handler when the failure will not pass on a retry: a payload
78
+ * that fails validation, a 4xx from a downstream service. The attempt is
79
+ * completed with `handler_failure_kind = PERMANENT` and is not retried,
80
+ * whatever the node's `Retry.when` lists (a worker can narrow the policy,
81
+ * never widen it). The class stays `FAILURE_CLASS_HANDLER_ERROR`.
82
+ */
83
+ export class PermanentError extends Error {
84
+ name = "PermanentError";
85
+ [FAILURE_KIND] = "permanent";
86
+ }
87
+ /**
88
+ * Throw from a handler when the failure may pass on its own: a downstream
89
+ * timeout, a 503. The attempt is completed with
90
+ * `handler_failure_kind = TRANSIENT`, so the platform's default policy
91
+ * retries it; an explicit `Retry.when` applies as written, and `Retry.max`
92
+ * and backoff bound it as always.
93
+ */
94
+ export class TransientError extends Error {
95
+ name = "TransientError";
96
+ [FAILURE_KIND] = "transient";
97
+ }
98
+ /**
99
+ * The handler failure kind a thrown value carries: PERMANENT for a
100
+ * {@link PermanentError}, TRANSIENT for a {@link TransientError} (or any
101
+ * error branded by another copy of this package), UNSPECIFIED otherwise. An
102
+ * error wrapped as the `cause` of another counts too.
103
+ */
104
+ export function handlerFailureKind(err) {
105
+ for (let e = err, depth = 0; e !== null && typeof e === "object" && depth < 8; depth++) {
106
+ const kind = e[FAILURE_KIND];
107
+ if (kind === "permanent")
108
+ return HandlerFailureKind.PERMANENT;
109
+ if (kind === "transient")
110
+ return HandlerFailureKind.TRANSIENT;
111
+ e = e.cause;
112
+ }
113
+ return HandlerFailureKind.UNSPECIFIED;
114
+ }
115
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAE,kBAAkB,EAAE,MAAM,+CAA+C,CAAC;AAyBnF,0DAA0D;AAC1D,MAAM,UAAU,SAAS,CAAC,GAAY;IACpC,IAAI,GAAG,YAAY,kBAAkB;QAAE,OAAO,MAAM,CAAC;IACrD,MAAM,EAAE,GAAG,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAClC,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC;QAChB,KAAK,IAAI,CAAC,kBAAkB;YAC1B,OAAO,MAAM,CAAC;QAChB,KAAK,IAAI,CAAC,eAAe,CAAC;QAC1B,KAAK,IAAI,CAAC,QAAQ,CAAC;QACnB,KAAK,IAAI,CAAC,aAAa,CAAC;QACxB,KAAK,IAAI,CAAC,aAAa,CAAC;QACxB,KAAK,IAAI,CAAC,UAAU;YAClB,OAAO,OAAO,CAAC;QACjB,KAAK,IAAI,CAAC,eAAe,CAAC;QAC1B,KAAK,IAAI,CAAC,gBAAgB;YACxB,OAAO,MAAM,CAAC;QAChB,KAAK,IAAI,CAAC,QAAQ;YAChB,OAAO,SAAS,CAAC;QACnB;YACE,OAAO,WAAW,CAAC;IACvB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAKhC;IAEA;IANO,IAAI,GAAG,oBAAoB,CAAC;IAC9C,YACE,OAAe;IACf,+DAA+D;IACtD,MAAe;IACxB,yEAAyE;IAChE,UAAmB,EAC5B,OAAsB;QA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