@open-conduit/sdk 0.0.0-bootstrap.0 → 7.0.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.
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +1 -0
- package/dist/extension.d.ts +6 -2
- package/dist/extension.js +3 -3
- package/dist/host.d.ts +2 -0
- package/dist/host.js +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/jsonrpc.d.ts +8 -0
- package/dist/jsonrpc.js +39 -5
- package/dist/wire.d.ts +27 -1
- package/dist/wire.js +18 -1
- package/package.json +1 -1
package/dist/errors.d.ts
CHANGED
package/dist/errors.js
CHANGED
|
@@ -25,6 +25,7 @@ export const Code = {
|
|
|
25
25
|
ContainerRunning: "container_running",
|
|
26
26
|
ContainerUnconfirmed: "container_unconfirmed",
|
|
27
27
|
SiteUnavailable: "site_unavailable",
|
|
28
|
+
NoCapacity: "no_capacity",
|
|
28
29
|
RetryAfter: "retry_after",
|
|
29
30
|
Reentrant: "reentrant_call",
|
|
30
31
|
Overloaded: "overloaded",
|
package/dist/extension.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type Readable, Writable } from "node:stream";
|
|
2
2
|
import { type DeliveryInput, Host, type Put } from "./host.js";
|
|
3
3
|
import { type Infer, type Type } from "./schema.js";
|
|
4
|
-
import { type AcceptedEvent, type Authority, type CertificationFile, type ConfigEntry, type ConnectionEntry, type Dependency, type Emitted, type Event, type Family, type Manifest, type PushResult, type Route, type RouteDecision, type RouteInput, type RouteSample, RouteSamplesParams, type Scan, type Scope, type Snapshot, type WaitRequest } from "./wire.js";
|
|
4
|
+
import { type AcceptedEvent, type Authority, type CertificationFile, type ConfigEntry, type ConnectionEntry, type Dependency, type Emitted, type Event, type Family, type Manifest, type PushResult, type Route, type RouteDecision, type RouteInput, type RouteSample, RouteSamplesParams, type Scan, type Scope, type Snapshot, type TaskRunResult, type WaitRequest } from "./wire.js";
|
|
5
5
|
/** The protocol versions this SDK speaks. */
|
|
6
6
|
export declare const ProtocolVersions: number[];
|
|
7
7
|
/** What a handler can reach besides its input. */
|
|
@@ -221,7 +221,11 @@ export interface CheckContext extends Context {
|
|
|
221
221
|
}
|
|
222
222
|
/** A check returns its detail line, and throws to fail with the error's message as detail. */
|
|
223
223
|
export type CheckFn = (ctx: CheckContext) => string | Promise<string>;
|
|
224
|
-
|
|
224
|
+
/**
|
|
225
|
+
* A task may return when it next has something to do and what wakes it
|
|
226
|
+
* sooner (at most an hour off); returning nothing keeps its interval.
|
|
227
|
+
*/
|
|
228
|
+
export type TaskFn = (ctx: Context) => void | TaskRunResult | Promise<void | TaskRunResult>;
|
|
225
229
|
export type MigrateFn = (from: number, to: number, ctx: Context) => void | Promise<void>;
|
|
226
230
|
export interface Options {
|
|
227
231
|
/** The extension's own version (required). */
|
package/dist/extension.js
CHANGED
|
@@ -10,7 +10,7 @@ import { randomBytes } from "node:crypto";
|
|
|
10
10
|
import { Writable } from "node:stream";
|
|
11
11
|
import { Code, ConfigError, OperationError, ProtocolError } from "./errors.js";
|
|
12
12
|
import { Host, base64, toBytes } from "./host.js";
|
|
13
|
-
import { Conn } from "./jsonrpc.js";
|
|
13
|
+
import { Conn, laneOf } from "./jsonrpc.js";
|
|
14
14
|
import { check, diagnose, isRecord, matches, } from "./schema.js";
|
|
15
15
|
import { CheckRunParams, ConfigureParams, EmitCommitParams, IngressPushParams, IngressReconcileParams, InitializeParams, OperationParams, RouteMatchParams, RouteSamplesParams, TaskRunParams, ValidateParams, WebhookHandleParams, WorkKindTriggerParams, } from "./wire.js";
|
|
16
16
|
/** The protocol versions this SDK speaks. */
|
|
@@ -409,6 +409,7 @@ export class Server {
|
|
|
409
409
|
constructor(ext, input, output) {
|
|
410
410
|
this.#ext = ext;
|
|
411
411
|
this.#conn = new Conn(input, output, (method, raw, signal) => this.#handle(method, raw, signal), {
|
|
412
|
+
lane: laneOf,
|
|
412
413
|
onProtocolError: (reason) => process.stderr.write(`open-conduit sdk: ${reason}\n`),
|
|
413
414
|
});
|
|
414
415
|
this.host = new Host((method, p, signal) => this.#conn.call(method, p, signal));
|
|
@@ -540,8 +541,7 @@ export class Server {
|
|
|
540
541
|
const fn = served.tasks.get(params(TaskRunParams, raw).task);
|
|
541
542
|
if (fn === undefined)
|
|
542
543
|
throw notFound(method);
|
|
543
|
-
await fn({ host: this.host, signal });
|
|
544
|
-
return {};
|
|
544
|
+
return (await fn({ host: this.host, signal })) ?? {};
|
|
545
545
|
}
|
|
546
546
|
case "check.run": {
|
|
547
547
|
const p = params(CheckRunParams, raw);
|
package/dist/host.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export declare class Host {
|
|
|
60
60
|
constructor(call: Caller);
|
|
61
61
|
/** Makes any extension-to-host call, decoding its result through result. */
|
|
62
62
|
call<S extends Type<unknown>>(method: string, params: unknown, result: S, signal?: AbortSignal): Promise<Infer<S>>;
|
|
63
|
+
/** Runs one of the extension's own tasks on the host's next pass. */
|
|
64
|
+
wakeTask(task: string, signal?: AbortSignal): Promise<void>;
|
|
63
65
|
/** A KV value and its version, or undefined when the key is absent. */
|
|
64
66
|
get(namespace: string, key: string, signal?: AbortSignal): Promise<Entry | undefined>;
|
|
65
67
|
/** The entries under prefix, in lexical key order. */
|
package/dist/host.js
CHANGED
|
@@ -22,6 +22,10 @@ export class Host {
|
|
|
22
22
|
throw new ProtocolError(Code.Invalid, `malformed ${method} result`);
|
|
23
23
|
return out;
|
|
24
24
|
}
|
|
25
|
+
/** Runs one of the extension's own tasks on the host's next pass. */
|
|
26
|
+
async wakeTask(task, signal) {
|
|
27
|
+
await this.#call("task.wake", { task }, signal);
|
|
28
|
+
}
|
|
25
29
|
/** A KV value and its version, or undefined when the key is absent. */
|
|
26
30
|
async get(namespace, key, signal) {
|
|
27
31
|
const out = await this.call("kv.get", { namespace, key }, KVGetResult, signal);
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export { t, check, diagnose, matches, isRecord } from "./schema.js";
|
|
|
6
6
|
export type { Infer, Type } from "./schema.js";
|
|
7
7
|
export { Code, OperationError, ProtocolError, ConfigError, pointer, CancelledError, TransportError, isProtocolCode, } from "./errors.js";
|
|
8
8
|
export type { ConfigDiagnostic } from "./errors.js";
|
|
9
|
-
export { Conn, MaxMessageBytes, MaxChunkBytes, MaxInflight, } from "./jsonrpc.js";
|
|
9
|
+
export { Conn, MaxMessageBytes, MaxChunkBytes, MaxInflight, MaxControlInflight, laneOf, } from "./jsonrpc.js";
|
|
10
10
|
export * from "./wire.js";
|
package/dist/index.js
CHANGED
|
@@ -15,5 +15,5 @@ export { extension, Extension, Server, ProtocolVersions } from "./extension.js";
|
|
|
15
15
|
export { Host, MaxWorksPage, text } from "./host.js";
|
|
16
16
|
export { t, check, diagnose, matches, isRecord } from "./schema.js";
|
|
17
17
|
export { Code, OperationError, ProtocolError, ConfigError, pointer, CancelledError, TransportError, isProtocolCode, } from "./errors.js";
|
|
18
|
-
export { Conn, MaxMessageBytes, MaxChunkBytes, MaxInflight, } from "./jsonrpc.js";
|
|
18
|
+
export { Conn, MaxMessageBytes, MaxChunkBytes, MaxInflight, MaxControlInflight, laneOf, } from "./jsonrpc.js";
|
|
19
19
|
export * from "./wire.js";
|
package/dist/jsonrpc.d.ts
CHANGED
|
@@ -3,12 +3,20 @@ import type { Readable, Writable } from "node:stream";
|
|
|
3
3
|
export declare const MaxMessageBytes: number;
|
|
4
4
|
export declare const MaxChunkBytes: number;
|
|
5
5
|
export declare const MaxInflight = 64;
|
|
6
|
+
/** Capacity reserved for control methods on top of MaxInflight. */
|
|
7
|
+
export declare const MaxControlInflight = 16;
|
|
8
|
+
/** Which capacity an extension serves a host request from. */
|
|
9
|
+
export type Lane = "bounded" | "held" | "control";
|
|
10
|
+
/** The lane of a host-to-extension method (protocol.LaneOf). */
|
|
11
|
+
export declare function laneOf(method: string): Lane;
|
|
6
12
|
export declare const CancelMethod = "$/cancel";
|
|
7
13
|
/** Serves one inbound request. Its signal aborts when the peer cancels. */
|
|
8
14
|
export type Handler = (method: string, params: unknown, signal: AbortSignal) => Promise<unknown>;
|
|
9
15
|
export interface ConnOptions {
|
|
10
16
|
maxMessage?: number;
|
|
11
17
|
maxInflight?: number;
|
|
18
|
+
/** Classifies inbound requests; an extension sets it, a host does not. */
|
|
19
|
+
lane?: (method: string) => Lane;
|
|
12
20
|
/** Receives why a malformed stream closed the connection. */
|
|
13
21
|
onProtocolError?: (reason: string) => void;
|
|
14
22
|
}
|
package/dist/jsonrpc.js
CHANGED
|
@@ -18,6 +18,23 @@ import { isRecord, matches, t } from "./schema.js";
|
|
|
18
18
|
export const MaxMessageBytes = 16 << 20;
|
|
19
19
|
export const MaxChunkBytes = 256 << 10;
|
|
20
20
|
export const MaxInflight = 64;
|
|
21
|
+
/** Capacity reserved for control methods on top of MaxInflight. */
|
|
22
|
+
export const MaxControlInflight = 16;
|
|
23
|
+
const heldMethods = new Set(["executor.wait"]);
|
|
24
|
+
const controlMethods = new Set([
|
|
25
|
+
"executor.recover",
|
|
26
|
+
"executor.interrupt",
|
|
27
|
+
"executor.stop",
|
|
28
|
+
"executor.forget",
|
|
29
|
+
]);
|
|
30
|
+
/** The lane of a host-to-extension method (protocol.LaneOf). */
|
|
31
|
+
export function laneOf(method) {
|
|
32
|
+
if (heldMethods.has(method))
|
|
33
|
+
return "held";
|
|
34
|
+
if (controlMethods.has(method))
|
|
35
|
+
return "control";
|
|
36
|
+
return "bounded";
|
|
37
|
+
}
|
|
21
38
|
export const CancelMethod = "$/cancel";
|
|
22
39
|
const codeParse = -32700;
|
|
23
40
|
const codeInvalidRequest = -32600;
|
|
@@ -54,6 +71,8 @@ export class Conn {
|
|
|
54
71
|
#out;
|
|
55
72
|
#maxMessage;
|
|
56
73
|
#maxInflight;
|
|
74
|
+
#lane;
|
|
75
|
+
#controlInflight = 0;
|
|
57
76
|
#onProtocolError;
|
|
58
77
|
#pending = new Map();
|
|
59
78
|
#cancels = new Map();
|
|
@@ -69,6 +88,7 @@ export class Conn {
|
|
|
69
88
|
this.#out = output;
|
|
70
89
|
this.#maxMessage = o.maxMessage ?? MaxMessageBytes;
|
|
71
90
|
this.#maxInflight = o.maxInflight ?? MaxInflight;
|
|
91
|
+
this.#lane = o.lane ?? (() => "bounded");
|
|
72
92
|
this.#onProtocolError = o.onProtocolError;
|
|
73
93
|
this.done = new Promise((resolve) => {
|
|
74
94
|
this.#finish = resolve;
|
|
@@ -151,7 +171,8 @@ export class Conn {
|
|
|
151
171
|
else if (method !== undefined && method !== "" && isID(id)) {
|
|
152
172
|
// Refuse rather than queue: the reader also carries the responses
|
|
153
173
|
// in-flight handlers wait for, so blocking it would deadlock them.
|
|
154
|
-
|
|
174
|
+
const release = this.#admit(method);
|
|
175
|
+
if (release === undefined) {
|
|
155
176
|
this.#write({
|
|
156
177
|
jsonrpc: "2.0",
|
|
157
178
|
id,
|
|
@@ -163,7 +184,7 @@ export class Conn {
|
|
|
163
184
|
});
|
|
164
185
|
return;
|
|
165
186
|
}
|
|
166
|
-
void this.#serve(id, method, m.params);
|
|
187
|
+
void this.#serve(id, method, m.params, release);
|
|
167
188
|
}
|
|
168
189
|
else if (method !== undefined && method !== "") {
|
|
169
190
|
// Other notifications are served without a reply.
|
|
@@ -184,11 +205,24 @@ export class Conn {
|
|
|
184
205
|
this.#protocolError("message is neither request nor response");
|
|
185
206
|
}
|
|
186
207
|
}
|
|
187
|
-
|
|
208
|
+
/** Takes the capacity a method is served from, or undefined when full. */
|
|
209
|
+
#admit(method) {
|
|
210
|
+
const lane = this.#lane(method);
|
|
211
|
+
if (lane === "held")
|
|
212
|
+
return () => { };
|
|
213
|
+
if (lane === "control" && this.#controlInflight < MaxControlInflight) {
|
|
214
|
+
this.#controlInflight++;
|
|
215
|
+
return () => void this.#controlInflight--;
|
|
216
|
+
}
|
|
217
|
+
if (this.#inflight >= this.#maxInflight)
|
|
218
|
+
return undefined;
|
|
219
|
+
this.#inflight++;
|
|
220
|
+
return () => void this.#inflight--;
|
|
221
|
+
}
|
|
222
|
+
async #serve(id, method, params, release) {
|
|
188
223
|
const key = JSON.stringify(id);
|
|
189
224
|
const abort = new AbortController();
|
|
190
225
|
this.#cancels.set(key, abort);
|
|
191
|
-
this.#inflight++;
|
|
192
226
|
let reply;
|
|
193
227
|
try {
|
|
194
228
|
const result = await this.#handler(method, params, abort.signal);
|
|
@@ -204,7 +238,7 @@ export class Conn {
|
|
|
204
238
|
};
|
|
205
239
|
}
|
|
206
240
|
finally {
|
|
207
|
-
|
|
241
|
+
release();
|
|
208
242
|
this.#cancels.delete(key);
|
|
209
243
|
}
|
|
210
244
|
if (this.#closed)
|
package/dist/wire.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export declare const AcceptedEvent: import("./schema.js").Type<{
|
|
|
55
55
|
via?: string | undefined;
|
|
56
56
|
work_id?: string | undefined;
|
|
57
57
|
};
|
|
58
|
+
retired?: boolean | undefined;
|
|
58
59
|
routed: boolean;
|
|
59
60
|
routed_work_id?: string | undefined;
|
|
60
61
|
scope_id?: string | undefined;
|
|
@@ -287,6 +288,21 @@ export declare const TaskRunParams: import("./schema.js").Type<{
|
|
|
287
288
|
task: string;
|
|
288
289
|
}>;
|
|
289
290
|
export type TaskRunParams = Infer<typeof TaskRunParams>;
|
|
291
|
+
/** What runs a sleeping task before its time. */
|
|
292
|
+
export declare const TaskWake: import("./schema.js").Type<{
|
|
293
|
+
families?: string[] | undefined;
|
|
294
|
+
work?: boolean | undefined;
|
|
295
|
+
}>;
|
|
296
|
+
export type TaskWake = Infer<typeof TaskWake>;
|
|
297
|
+
/** What a task says about its next run; empty keeps its declared interval. */
|
|
298
|
+
export declare const TaskRunResult: import("./schema.js").Type<{
|
|
299
|
+
next_run_at?: string | undefined;
|
|
300
|
+
wake?: {
|
|
301
|
+
families?: string[] | undefined;
|
|
302
|
+
work?: boolean | undefined;
|
|
303
|
+
} | undefined;
|
|
304
|
+
}>;
|
|
305
|
+
export type TaskRunResult = Infer<typeof TaskRunResult>;
|
|
290
306
|
export declare const CheckRunParams: import("./schema.js").Type<{
|
|
291
307
|
check: string;
|
|
292
308
|
config: unknown;
|
|
@@ -467,6 +483,7 @@ export declare const EventAcceptResult: import("./schema.js").Type<{
|
|
|
467
483
|
via?: string | undefined;
|
|
468
484
|
work_id?: string | undefined;
|
|
469
485
|
};
|
|
486
|
+
retired?: boolean | undefined;
|
|
470
487
|
routed: boolean;
|
|
471
488
|
routed_work_id?: string | undefined;
|
|
472
489
|
scope_id?: string | undefined;
|
|
@@ -617,12 +634,16 @@ export type Scan = Infer<typeof Scan>;
|
|
|
617
634
|
/**
|
|
618
635
|
* One page of a reconcile. complete certifies the scan covered the whole
|
|
619
636
|
* source across its pages; false with no next_cursor is a partial scan,
|
|
620
|
-
* never proof that anything is gone.
|
|
637
|
+
* never proof that anything is gone. not_before (an RFC 3339 time) says the
|
|
638
|
+
* provider can't answer this page yet, a rate limit say: such a page has no
|
|
639
|
+
* observations, is not complete and repeats the scan's cursor as next_cursor,
|
|
640
|
+
* and the host asks for it again at that time without counting a failure.
|
|
621
641
|
*/
|
|
622
642
|
export declare const Snapshot: import("./schema.js").Type<{
|
|
623
643
|
checkpoint?: string | undefined;
|
|
624
644
|
complete: boolean;
|
|
625
645
|
next_cursor?: string | undefined;
|
|
646
|
+
not_before?: string | undefined;
|
|
626
647
|
observations?: {
|
|
627
648
|
event: {
|
|
628
649
|
actor?: string | undefined;
|
|
@@ -746,6 +767,7 @@ export declare const IngressDeliverResult: import("./schema.js").Type<{
|
|
|
746
767
|
via?: string | undefined;
|
|
747
768
|
work_id?: string | undefined;
|
|
748
769
|
};
|
|
770
|
+
retired?: boolean | undefined;
|
|
749
771
|
routed: boolean;
|
|
750
772
|
routed_work_id?: string | undefined;
|
|
751
773
|
scope_id?: string | undefined;
|
|
@@ -831,6 +853,7 @@ export declare const RouteInput: import("./schema.js").Type<{
|
|
|
831
853
|
via?: string | undefined;
|
|
832
854
|
work_id?: string | undefined;
|
|
833
855
|
};
|
|
856
|
+
retired?: boolean | undefined;
|
|
834
857
|
routed: boolean;
|
|
835
858
|
routed_work_id?: string | undefined;
|
|
836
859
|
scope_id?: string | undefined;
|
|
@@ -986,6 +1009,7 @@ export declare const RouteMatchParams: import("./schema.js").Type<{
|
|
|
986
1009
|
via?: string | undefined;
|
|
987
1010
|
work_id?: string | undefined;
|
|
988
1011
|
};
|
|
1012
|
+
retired?: boolean | undefined;
|
|
989
1013
|
routed: boolean;
|
|
990
1014
|
routed_work_id?: string | undefined;
|
|
991
1015
|
scope_id?: string | undefined;
|
|
@@ -1273,6 +1297,7 @@ export declare const Emitted: import("./schema.js").Type<{
|
|
|
1273
1297
|
via?: string | undefined;
|
|
1274
1298
|
work_id?: string | undefined;
|
|
1275
1299
|
};
|
|
1300
|
+
retired?: boolean | undefined;
|
|
1276
1301
|
routed: boolean;
|
|
1277
1302
|
routed_work_id?: string | undefined;
|
|
1278
1303
|
scope_id?: string | undefined;
|
|
@@ -1328,6 +1353,7 @@ export declare const EmitCommitParams: import("./schema.js").Type<{
|
|
|
1328
1353
|
via?: string | undefined;
|
|
1329
1354
|
work_id?: string | undefined;
|
|
1330
1355
|
};
|
|
1356
|
+
retired?: boolean | undefined;
|
|
1331
1357
|
routed: boolean;
|
|
1332
1358
|
routed_work_id?: string | undefined;
|
|
1333
1359
|
scope_id?: string | undefined;
|
package/dist/wire.js
CHANGED
|
@@ -47,6 +47,9 @@ export const AcceptedEvent = t.object({
|
|
|
47
47
|
routed_work_id: t.optional(t.string()),
|
|
48
48
|
disposition: t.optional(t.string()),
|
|
49
49
|
scope_id: t.optional(t.string()),
|
|
50
|
+
// A tombstone: the Event's payload has left the live log, so empty data
|
|
51
|
+
// says nothing about what it carried.
|
|
52
|
+
retired: t.optional(t.boolean()),
|
|
50
53
|
}, open);
|
|
51
54
|
export const DisplayLink = t.object({
|
|
52
55
|
label: t.string(),
|
|
@@ -162,6 +165,16 @@ export const OperationResult = t.object({
|
|
|
162
165
|
export const TaskRunParams = t.object({
|
|
163
166
|
task: t.string(),
|
|
164
167
|
}, open);
|
|
168
|
+
/** What runs a sleeping task before its time. */
|
|
169
|
+
export const TaskWake = t.object({
|
|
170
|
+
families: t.optional(t.array(t.string())),
|
|
171
|
+
work: t.optional(t.boolean()),
|
|
172
|
+
}, open);
|
|
173
|
+
/** What a task says about its next run; empty keeps its declared interval. */
|
|
174
|
+
export const TaskRunResult = t.object({
|
|
175
|
+
next_run_at: t.optional(t.string()),
|
|
176
|
+
wake: t.optional(TaskWake),
|
|
177
|
+
}, open);
|
|
165
178
|
export const CheckRunParams = t.object({
|
|
166
179
|
check: t.string(),
|
|
167
180
|
deep: t.optional(t.boolean()),
|
|
@@ -317,7 +330,10 @@ export const Scan = t.object({
|
|
|
317
330
|
/**
|
|
318
331
|
* One page of a reconcile. complete certifies the scan covered the whole
|
|
319
332
|
* source across its pages; false with no next_cursor is a partial scan,
|
|
320
|
-
* never proof that anything is gone.
|
|
333
|
+
* never proof that anything is gone. not_before (an RFC 3339 time) says the
|
|
334
|
+
* provider can't answer this page yet, a rate limit say: such a page has no
|
|
335
|
+
* observations, is not complete and repeats the scan's cursor as next_cursor,
|
|
336
|
+
* and the host asks for it again at that time without counting a failure.
|
|
321
337
|
*/
|
|
322
338
|
export const Snapshot = t.object({
|
|
323
339
|
scan_id: t.string(),
|
|
@@ -325,6 +341,7 @@ export const Snapshot = t.object({
|
|
|
325
341
|
next_cursor: t.optional(t.string()),
|
|
326
342
|
complete: t.boolean(),
|
|
327
343
|
checkpoint: t.optional(t.string()),
|
|
344
|
+
not_before: t.optional(t.string()),
|
|
328
345
|
}, open);
|
|
329
346
|
/** A source an entry registers at configure. */
|
|
330
347
|
export const SourceDecl = t.object({
|
package/package.json
CHANGED