@substrat-run/kernel 0.159.0 → 0.161.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/billing-retention.d.ts +46 -0
- package/dist/billing-retention.d.ts.map +1 -0
- package/dist/billing-retention.js +78 -0
- package/dist/billing-retention.js.map +1 -0
- package/dist/byte-stream.d.ts +142 -0
- package/dist/byte-stream.d.ts.map +1 -0
- package/dist/byte-stream.js +274 -0
- package/dist/byte-stream.js.map +1 -0
- package/dist/connection-landings.d.ts +15 -3
- package/dist/connection-landings.d.ts.map +1 -1
- package/dist/connection-landings.js +10 -2
- package/dist/connection-landings.js.map +1 -1
- package/dist/deadline-fetch.d.ts +34 -0
- package/dist/deadline-fetch.d.ts.map +1 -0
- package/dist/deadline-fetch.js +231 -0
- package/dist/deadline-fetch.js.map +1 -0
- package/dist/deployment-wire-auth.d.ts +125 -0
- package/dist/deployment-wire-auth.d.ts.map +1 -0
- package/dist/deployment-wire-auth.js +161 -0
- package/dist/deployment-wire-auth.js.map +1 -0
- package/dist/entity-trash.d.ts +65 -8
- package/dist/entity-trash.d.ts.map +1 -1
- package/dist/entity-trash.js +80 -12
- package/dist/entity-trash.js.map +1 -1
- package/dist/export-break.d.ts +6 -0
- package/dist/export-break.d.ts.map +1 -1
- package/dist/export-break.js +11 -0
- package/dist/export-break.js.map +1 -1
- package/dist/index.d.ts +19 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/dist/meter-days.d.ts +107 -0
- package/dist/meter-days.d.ts.map +1 -0
- package/dist/meter-days.js +230 -0
- package/dist/meter-days.js.map +1 -0
- package/dist/meters.d.ts +19 -1
- package/dist/meters.d.ts.map +1 -1
- package/dist/meters.js +0 -0
- package/dist/meters.js.map +1 -1
- package/dist/ops-failure-reference.d.ts +43 -0
- package/dist/ops-failure-reference.d.ts.map +1 -0
- package/dist/ops-failure-reference.js +42 -0
- package/dist/ops-failure-reference.js.map +1 -0
- package/dist/platform-request-cap.d.ts +9 -0
- package/dist/platform-request-cap.d.ts.map +1 -0
- package/dist/platform-request-cap.js +42 -0
- package/dist/platform-request-cap.js.map +1 -0
- package/dist/platform-sweep.d.ts +187 -7
- package/dist/platform-sweep.d.ts.map +1 -1
- package/dist/platform-sweep.js +388 -45
- package/dist/platform-sweep.js.map +1 -1
- package/dist/promote-review.d.ts +6 -0
- package/dist/promote-review.d.ts.map +1 -1
- package/dist/promote-review.js +9 -0
- package/dist/promote-review.js.map +1 -1
- package/dist/request-rollup.d.ts +161 -0
- package/dist/request-rollup.d.ts.map +1 -0
- package/dist/request-rollup.js +273 -0
- package/dist/request-rollup.js.map +1 -0
- package/dist/reserved-roles.d.ts +192 -4
- package/dist/reserved-roles.d.ts.map +1 -1
- package/dist/reserved-roles.js +314 -2
- package/dist/reserved-roles.js.map +1 -1
- package/dist/schedule-state.d.ts +5 -0
- package/dist/schedule-state.d.ts.map +1 -1
- package/dist/scope-host.d.ts +317 -15
- package/dist/scope-host.d.ts.map +1 -1
- package/dist/scope-host.js +93 -2
- package/dist/scope-host.js.map +1 -1
- package/dist/scope-lifecycle.d.ts +7 -0
- package/dist/scope-lifecycle.d.ts.map +1 -1
- package/dist/scope-lifecycle.js +7 -0
- package/dist/scope-lifecycle.js.map +1 -1
- package/dist/scope-record.d.ts +16 -5
- package/dist/scope-record.d.ts.map +1 -1
- package/dist/scope-record.js +72 -7
- package/dist/scope-record.js.map +1 -1
- package/dist/spine-restore.d.ts +7 -3
- package/dist/spine-restore.d.ts.map +1 -1
- package/dist/spine-restore.js +14 -3
- package/dist/spine-restore.js.map +1 -1
- package/dist/storage-gauge.d.ts +47 -13
- package/dist/storage-gauge.d.ts.map +1 -1
- package/dist/storage-gauge.js +84 -27
- package/dist/storage-gauge.js.map +1 -1
- package/dist/subject-redaction.d.ts +9 -3
- package/dist/subject-redaction.d.ts.map +1 -1
- package/dist/subject-redaction.js +23 -12
- package/dist/subject-redaction.js.map +1 -1
- package/dist/vertical-owners.d.ts +69 -0
- package/dist/vertical-owners.d.ts.map +1 -0
- package/dist/vertical-owners.js +108 -0
- package/dist/vertical-owners.js.map +1 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection-landings.js","sourceRoot":"","sources":["../src/connection-landings.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAmFjC;;;;GAIG;AACH,MAAM,OAAO,WAAW;IAKH,IAAI;IACJ,KAAK;IACL,KAAK;IACL,WAAW;
|
|
1
|
+
{"version":3,"file":"connection-landings.js","sourceRoot":"","sources":["../src/connection-landings.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAmFjC;;;;GAIG;AACH,MAAM,OAAO,WAAW;IAKH,IAAI;IACJ,KAAK;IACL,KAAK;IACL,WAAW;IAMX,UAAU;IAbZ,OAAO,GAAG,IAAI,GAAG,EAA6B,CAAC;IAC/C,IAAI,GAAG,IAAI,GAAG,EAA+C,CAAC;IAE/E,YACmB,IAAe,EACf,KAAsB,EACtB,KAAoC,EACpC,WAAmB;IACpC;;;;OAIG;IACc,UAAqD;oBATrD,IAAI;qBACJ,KAAK;qBACL,KAAK;2BACL,WAAW;0BAMX,UAAU;IAC1B,CAAC;IAEJ,mGAAmG;IACnG,KAAK,CAAC,KAAK,CAAC,UAAsB;QAChC,MAAM,GAAG,GAAmB,EAAE,OAAO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AC/B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC7D,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;CACF;AAED,+FAA+F;AAC/F,SAAS,WAAW,CAClB,OAAkD,EAClD,SAAiB,EACjB,UAAkB,EAClB,OAAgC;IAEhC,IAAI,OAAO,CAAC,SAAS,KAAK,SAAS,IAAI,OAAO,CAAC,UAAU,KAAK,UAAU;QAAE,OAAO,KAAK,CAAC;IACvF,MAAM,IAAI,GAAG,OAA4C,CAAC;IAC1D,OAAO,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC;AAClH,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { ExtractionTimers } from './attachment-extractor.js';
|
|
2
|
+
import type { FetchLike } from './scope-host.js';
|
|
3
|
+
/**
|
|
4
|
+
* How long a streamed response body may go without a byte before it errors. 30 s, the default
|
|
5
|
+
* `timeoutMs` of a connector call: a provider that has been silent for as long as a whole call
|
|
6
|
+
* may take has stalled, and a slower link than that is still delivering within it. The window
|
|
7
|
+
* runs only while the stream waits on the provider: a consumer that is slow to take the next
|
|
8
|
+
* chunk (a store writing the last one) does not spend it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const STREAM_IDLE_TIMEOUT_MS = 30000;
|
|
11
|
+
/**
|
|
12
|
+
* The most a streamed body may take from its first read to its end, however steadily it flows:
|
|
13
|
+
* 10 minutes. Finite because a hosted run lives under the platform's wall limits and a trickle
|
|
14
|
+
* that never stops would otherwise hold a connection (and a run) for ever; generous because the
|
|
15
|
+
* idle window, not this, is what cuts a stalled transfer. At the 10 minutes a steady 1 MB/s
|
|
16
|
+
* link still moves about 600 MB.
|
|
17
|
+
*/
|
|
18
|
+
export declare const STREAM_MAX_DURATION_MS: number;
|
|
19
|
+
export interface DeadlineOptions {
|
|
20
|
+
/** The idle window of a streamed body. Default {@link STREAM_IDLE_TIMEOUT_MS}. */
|
|
21
|
+
idleMs?: number;
|
|
22
|
+
/** The absolute cap on a streamed body's duration. Default {@link STREAM_MAX_DURATION_MS}. */
|
|
23
|
+
maxStreamMs?: number;
|
|
24
|
+
/** The timers every bound runs on: the runtime's by default, a test's on a clock it moves itself. */
|
|
25
|
+
timers?: ExtractionTimers;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* `fetchImpl`, with `timeoutMs` on the call and an idle window plus an absolute cap on a streamed
|
|
29
|
+
* body (see the module header). The signal it hands the runtime is its own; a `signal` in `init`
|
|
30
|
+
* aborts it, so wrapping a `fetch` that is itself wrapped (a connector's timeout around a host's)
|
|
31
|
+
* lets the outer bound reach the runtime.
|
|
32
|
+
*/
|
|
33
|
+
export declare function deadlineFetch(fetchImpl: FetchLike, timeoutMs: number, options?: DeadlineOptions): FetchLike;
|
|
34
|
+
//# sourceMappingURL=deadline-fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadline-fetch.d.ts","sourceRoot":"","sources":["../src/deadline-fetch.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,KAAK,EAAqB,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEpE;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAE7C;;;;;;GAMG;AACH,eAAO,MAAM,sBAAsB,QAAc,CAAC;AA4BlD,MAAM,WAAW,eAAe;IAC9B,kFAAkF;IAClF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8FAA8F;IAC9F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,qGAAqG;IACrG,MAAM,CAAC,EAAE,gBAAgB,CAAC;CAC3B;AAgBD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,eAAoB,GAAG,SAAS,CAmF/G"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long a streamed response body may go without a byte before it errors. 30 s, the default
|
|
3
|
+
* `timeoutMs` of a connector call: a provider that has been silent for as long as a whole call
|
|
4
|
+
* may take has stalled, and a slower link than that is still delivering within it. The window
|
|
5
|
+
* runs only while the stream waits on the provider: a consumer that is slow to take the next
|
|
6
|
+
* chunk (a store writing the last one) does not spend it.
|
|
7
|
+
*/
|
|
8
|
+
export const STREAM_IDLE_TIMEOUT_MS = 30_000;
|
|
9
|
+
/**
|
|
10
|
+
* The most a streamed body may take from its first read to its end, however steadily it flows:
|
|
11
|
+
* 10 minutes. Finite because a hosted run lives under the platform's wall limits and a trickle
|
|
12
|
+
* that never stops would otherwise hold a connection (and a run) for ever; generous because the
|
|
13
|
+
* idle window, not this, is what cuts a stalled transfer. At the 10 minutes a steady 1 MB/s
|
|
14
|
+
* link still moves about 600 MB.
|
|
15
|
+
*/
|
|
16
|
+
export const STREAM_MAX_DURATION_MS = 10 * 60_000;
|
|
17
|
+
/**
|
|
18
|
+
* How many empty chunks in a row a stream may deliver before it is treated as making no progress.
|
|
19
|
+
* Generous: a real source sends a few at most. It is a count, not a time, because a source that
|
|
20
|
+
* answers only with empty chunks answers in microtasks and no timer would ever get to run.
|
|
21
|
+
*/
|
|
22
|
+
const MAX_CONSECUTIVE_EMPTY_READS = 1_000;
|
|
23
|
+
/** The runtime's timers, called bare — workerd throws `Illegal invocation` on `obj.setTimeout(…)`. */
|
|
24
|
+
const RUNTIME_TIMERS = {
|
|
25
|
+
setTimeout: (fn, ms) => setTimeout(fn, ms),
|
|
26
|
+
clearTimeout: (handle) => clearTimeout(handle),
|
|
27
|
+
};
|
|
28
|
+
/** The error every bound ends in. Neutral: it names neither the provider nor the URL. */
|
|
29
|
+
const timeoutError = (message) => new DOMException(message, 'TimeoutError');
|
|
30
|
+
/** The three reads that buffer the whole body; the call's total deadline covers them. */
|
|
31
|
+
const BUFFERED_READS = new Set(['text', 'json', 'arrayBuffer']);
|
|
32
|
+
/**
|
|
33
|
+
* `fetchImpl`, with `timeoutMs` on the call and an idle window plus an absolute cap on a streamed
|
|
34
|
+
* body (see the module header). The signal it hands the runtime is its own; a `signal` in `init`
|
|
35
|
+
* aborts it, so wrapping a `fetch` that is itself wrapped (a connector's timeout around a host's)
|
|
36
|
+
* lets the outer bound reach the runtime.
|
|
37
|
+
*/
|
|
38
|
+
export function deadlineFetch(fetchImpl, timeoutMs, options = {}) {
|
|
39
|
+
const idleMs = options.idleMs ?? STREAM_IDLE_TIMEOUT_MS;
|
|
40
|
+
const maxStreamMs = options.maxStreamMs ?? STREAM_MAX_DURATION_MS;
|
|
41
|
+
const timers = options.timers ?? RUNTIME_TIMERS;
|
|
42
|
+
return async (input, init) => {
|
|
43
|
+
const controller = new AbortController();
|
|
44
|
+
let timedOut;
|
|
45
|
+
const upstream = init?.signal;
|
|
46
|
+
// The caller's own abort ends the call: its deadline is released, so it cannot fire later and
|
|
47
|
+
// pass a cancel off as a timeout.
|
|
48
|
+
const onUpstreamAbort = () => {
|
|
49
|
+
releaseTotal();
|
|
50
|
+
controller.abort(upstream?.reason);
|
|
51
|
+
};
|
|
52
|
+
if (upstream?.aborted)
|
|
53
|
+
controller.abort(upstream.reason);
|
|
54
|
+
else
|
|
55
|
+
upstream?.addEventListener?.('abort', onUpstreamAbort, { once: true });
|
|
56
|
+
const total = timers.setTimeout(() => {
|
|
57
|
+
timedOut ??= timeoutError('The operation was aborted due to timeout');
|
|
58
|
+
controller.abort(timedOut);
|
|
59
|
+
finish();
|
|
60
|
+
}, timeoutMs);
|
|
61
|
+
// Not held against the process: `AbortSignal.timeout`'s timer was not either.
|
|
62
|
+
unref(total);
|
|
63
|
+
const releaseTotal = () => timers.clearTimeout(total);
|
|
64
|
+
/** The call is over: its deadline and its hold on the caller's signal go. Idempotent. */
|
|
65
|
+
function finish() {
|
|
66
|
+
releaseTotal();
|
|
67
|
+
upstream?.removeEventListener?.('abort', onUpstreamAbort);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* What a failed read reports. A runtime may fail a read the call's deadline aborted with a
|
|
71
|
+
* generic abort rather than the reason; that one is the deadline's `TimeoutError`. Any other
|
|
72
|
+
* failure (a caller's cancel, a network error) keeps its own class.
|
|
73
|
+
*/
|
|
74
|
+
const reported = (err) => timedOut && err?.name === 'AbortError' ? timedOut : err;
|
|
75
|
+
let res;
|
|
76
|
+
try {
|
|
77
|
+
res = await fetchImpl(input, { ...init, signal: controller.signal });
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
finish();
|
|
81
|
+
throw reported(err);
|
|
82
|
+
}
|
|
83
|
+
// A response that has no body at all (`null`, as on a web `Response`) has nothing to bound.
|
|
84
|
+
// A stand-in with no `body` field (`undefined`) may still be read buffered, so it keeps the deadline.
|
|
85
|
+
if (res.body === null)
|
|
86
|
+
finish();
|
|
87
|
+
let guarded;
|
|
88
|
+
return new Proxy(res, {
|
|
89
|
+
get(target, prop) {
|
|
90
|
+
const value = Reflect.get(target, prop, target);
|
|
91
|
+
if (prop === 'body') {
|
|
92
|
+
if (!value)
|
|
93
|
+
return value;
|
|
94
|
+
// Looking at the body takes nothing: the native stream stays unlocked and the call's
|
|
95
|
+
// deadline stays armed until the first read of the stream handed out here.
|
|
96
|
+
guarded ??= guardedBody(value, {
|
|
97
|
+
idleMs,
|
|
98
|
+
maxStreamMs,
|
|
99
|
+
timers,
|
|
100
|
+
releaseTotal,
|
|
101
|
+
finish,
|
|
102
|
+
abortCall: (reason) => controller.abort(reason),
|
|
103
|
+
reported,
|
|
104
|
+
});
|
|
105
|
+
return guarded;
|
|
106
|
+
}
|
|
107
|
+
if (typeof value !== 'function')
|
|
108
|
+
return value;
|
|
109
|
+
// Called on the response itself, never the proxy: a native method refuses any other receiver.
|
|
110
|
+
if (BUFFERED_READS.has(prop)) {
|
|
111
|
+
return async (...args) => {
|
|
112
|
+
try {
|
|
113
|
+
return await value.apply(target, args);
|
|
114
|
+
}
|
|
115
|
+
catch (err) {
|
|
116
|
+
// A runtime may fail a read the call's deadline aborted with a generic abort.
|
|
117
|
+
throw reported(err);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
finish();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
return value.bind(target);
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
/** A timer that does not hold a Node process open, where the runtime lets it say so. */
|
|
130
|
+
function unref(handle) {
|
|
131
|
+
handle?.unref?.();
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* `body`, passed through chunk by chunk. The native reader is taken on the FIRST pull, not here,
|
|
135
|
+
* so a stream that is only looked at, or taken and never read, leaves the native body unlocked
|
|
136
|
+
* and the call's deadline in force. From the first read: the stream errors when the provider is
|
|
137
|
+
* silent for `idleMs` (empty chunks are not bytes and do not reset the window) or when `maxStreamMs`
|
|
138
|
+
* has passed in all. Pull-driven with no queue of its own, so the idle window runs only while a
|
|
139
|
+
* read waits on the provider. Whichever bound ends it cancels the source reader, aborts the call
|
|
140
|
+
* (which releases the connection) and errors the stream: nothing is left reading, nothing buffered.
|
|
141
|
+
*
|
|
142
|
+
* The bounds are TIMERS that end the stream, never promises raced against each read: a promise
|
|
143
|
+
* that outlives a read keeps a reaction for every race it was in, and through it the chunk the
|
|
144
|
+
* race resolved with. Nothing long-lived here holds a chunk once it has been delivered.
|
|
145
|
+
*/
|
|
146
|
+
function guardedBody(body, o) {
|
|
147
|
+
let reader;
|
|
148
|
+
let ctl;
|
|
149
|
+
let capHandle;
|
|
150
|
+
let over = false;
|
|
151
|
+
/** End the stream with `err`, once: error it, let go of the call, cancel the source. */
|
|
152
|
+
const stop = async (err) => {
|
|
153
|
+
if (over)
|
|
154
|
+
return;
|
|
155
|
+
over = true;
|
|
156
|
+
o.timers.clearTimeout(capHandle);
|
|
157
|
+
try {
|
|
158
|
+
ctl?.error(err);
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// already closed or errored
|
|
162
|
+
}
|
|
163
|
+
o.abortCall(err);
|
|
164
|
+
o.finish();
|
|
165
|
+
await reader?.cancel(err).catch(() => { });
|
|
166
|
+
try {
|
|
167
|
+
reader?.releaseLock();
|
|
168
|
+
}
|
|
169
|
+
catch {
|
|
170
|
+
// a read the cancel has not yet settled: the lock goes with the stream
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
/** The first read: the call's deadline hands over to the idle window and the absolute cap. */
|
|
174
|
+
const begin = () => {
|
|
175
|
+
o.releaseTotal();
|
|
176
|
+
capHandle = o.timers.setTimeout(() => void stop(timeoutError('The transfer exceeded its maximum duration')), o.maxStreamMs);
|
|
177
|
+
unref(capHandle);
|
|
178
|
+
return body.getReader();
|
|
179
|
+
};
|
|
180
|
+
return new ReadableStream({
|
|
181
|
+
start(controller) {
|
|
182
|
+
ctl = controller;
|
|
183
|
+
},
|
|
184
|
+
async pull(controller) {
|
|
185
|
+
if (over)
|
|
186
|
+
return;
|
|
187
|
+
let idle;
|
|
188
|
+
let empties = 0;
|
|
189
|
+
try {
|
|
190
|
+
reader ??= begin();
|
|
191
|
+
idle = o.timers.setTimeout(() => void stop(timeoutError(`The response body stalled: no bytes for ${o.idleMs} ms`)), o.idleMs);
|
|
192
|
+
unref(idle);
|
|
193
|
+
for (;;) {
|
|
194
|
+
const { done, value } = await reader.read();
|
|
195
|
+
// A bound (or the consumer) ended the stream while this read waited: it has answered.
|
|
196
|
+
if (over)
|
|
197
|
+
return;
|
|
198
|
+
if (done) {
|
|
199
|
+
over = true;
|
|
200
|
+
o.timers.clearTimeout(capHandle);
|
|
201
|
+
o.finish();
|
|
202
|
+
controller.close();
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (!value)
|
|
206
|
+
throw new Error('the byte stream yielded a read with neither a chunk nor its end');
|
|
207
|
+
// An empty chunk carries nothing: it is read past under the same window, not counted as progress.
|
|
208
|
+
// A source that answers only with empty chunks, all in microtasks, would never let a timer
|
|
209
|
+
// run, so the run of them is itself bounded.
|
|
210
|
+
if (value.byteLength === 0) {
|
|
211
|
+
if (++empties > MAX_CONSECUTIVE_EMPTY_READS) {
|
|
212
|
+
throw timeoutError('The response body made no progress');
|
|
213
|
+
}
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
controller.enqueue(value);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
// A runtime may end a read the call's deadline aborted with a generic abort.
|
|
222
|
+
await stop(o.reported(err));
|
|
223
|
+
}
|
|
224
|
+
finally {
|
|
225
|
+
o.timers.clearTimeout(idle);
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
cancel: (reason) => stop(reason),
|
|
229
|
+
}, { highWaterMark: 0 });
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=deadline-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deadline-fetch.js","sourceRoot":"","sources":["../src/deadline-fetch.ts"],"names":[],"mappings":"AA0BA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE7C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,EAAE,GAAG,MAAM,CAAC;AAElD;;;;GAIG;AACH,MAAM,2BAA2B,GAAG,KAAK,CAAC;AAe1C,sGAAsG;AACtG,MAAM,cA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,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QACD,MAAM,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC;KACjC,EACD,EAAE,aAAa,EAAE,CAAC,EAAE,CACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The capability record (RFC wire-signing §7, Q8), as statements both adapters run against their
|
|
3
|
+
* directory: one row per deployment, the script an upload went to (a version's archive script or a
|
|
4
|
+
* vertical's serving script), holding what that upload gave it. Every upload of the script replaces
|
|
5
|
+
* its row, so the row is the last upload's: the one the running script was built from. Written once
|
|
6
|
+
* so the two adapters cannot keep different records of the same fleet.
|
|
7
|
+
*
|
|
8
|
+
* The uploader writes it from what it built and injected; a vertical never declares it, since a
|
|
9
|
+
* claim a version makes about itself proves nothing. The readiness report (follow-on 4) reads it.
|
|
10
|
+
* A vertical's rows go with the vertical (`forgetVerticalWireAuth`), so none outlives what it
|
|
11
|
+
* describes.
|
|
12
|
+
*/
|
|
13
|
+
import { type DeploymentWireAuth, type TenantId } from '@substrat-run/contracts';
|
|
14
|
+
import type { SwitchSql } from './system-switch.js';
|
|
15
|
+
export type { DeploymentWireAuthInput } from '@substrat-run/contracts';
|
|
16
|
+
/** Interpolated into both adapters' directory DDL, so the two spell one table. */
|
|
17
|
+
export declare const DEPLOYMENT_WIRE_AUTH_DDL = "\n CREATE TABLE IF NOT EXISTS vertical_wire_auth (\n deployment_ref TEXT PRIMARY KEY,\n vertical_slug TEXT NOT NULL,\n version_id TEXT,\n record TEXT NOT NULL,\n recorded_at TEXT NOT NULL\n );\n CREATE INDEX IF NOT EXISTS vertical_wire_auth_slug ON vertical_wire_auth (vertical_slug);\n";
|
|
18
|
+
/**
|
|
19
|
+
* Whose records a read may return: the verticals one tenant owns now (`verticals.owner_tenant`), or
|
|
20
|
+
* the whole fleet, said in so many words. There is no default, so a reader that forgets to confine
|
|
21
|
+
* itself is refused rather than handed every tenant's deployments: a record names scripts, versions
|
|
22
|
+
* and key ids, and a tenant reads only its own. A record of a platform-owned vertical (no owning
|
|
23
|
+
* tenant) is reached only by the fleet.
|
|
24
|
+
*
|
|
25
|
+
* A tenant reach follows the vertical's current owner: it is resolved at read time, so whoever owns
|
|
26
|
+
* the slug then reads every record the table holds for it, and a tenant that no longer owns it reads
|
|
27
|
+
* none. Apart from a whole-directory restore (`restoreDirectory`), which replaces the owners and the
|
|
28
|
+
* records together from one dump, no host path moves the owner of a registered vertical today: an
|
|
29
|
+
* owner changes by deleting the vertical, which removes its records, and registering the slug again.
|
|
30
|
+
* A record is written only beside its vertical's registration (`writeDeploymentWireAuth`), so a new
|
|
31
|
+
* registrant of a slug reads only what was recorded since it registered. Key ids are not secrets.
|
|
32
|
+
*/
|
|
33
|
+
export type DeploymentWireAuthReach = {
|
|
34
|
+
readonly tenantId: TenantId;
|
|
35
|
+
} | {
|
|
36
|
+
readonly fleet: true;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Which records a read returns, one page of them: the keyset convention by script name, `cursor` the
|
|
40
|
+
* last name of the page before. A version's script keeps its record for as long as its vertical
|
|
41
|
+
* exists, so a read is always a page: `limit` is required, at most `LIST_PAGE_MAX`.
|
|
42
|
+
*/
|
|
43
|
+
export interface DeploymentWireAuthFilter {
|
|
44
|
+
readonly reach: DeploymentWireAuthReach;
|
|
45
|
+
readonly verticalSlug?: string;
|
|
46
|
+
readonly limit: number;
|
|
47
|
+
readonly cursor?: string;
|
|
48
|
+
readonly order?: 'asc' | 'desc';
|
|
49
|
+
}
|
|
50
|
+
/** The longest `verticalSlug` or `cursor` a read takes. A script name is far shorter. */
|
|
51
|
+
export declare const WIRE_AUTH_FILTER_TEXT_MAX = 256;
|
|
52
|
+
/**
|
|
53
|
+
* The filter a read is allowed to run, or a `validation_failed` refusal: only the filter's own keys;
|
|
54
|
+
* a reach that is exactly one tenant (a tenant id) or exactly the fleet; a limit from 1 to
|
|
55
|
+
* `LIST_PAGE_MAX`; a vertical and a cursor of 1 to `WIRE_AUTH_FILTER_TEXT_MAX` characters; an order
|
|
56
|
+
* of `asc` or `desc`. Both adapters judge it before the read, and the Cloudflare host before the call
|
|
57
|
+
* into the directory's object, so the refusal keeps its code across the RPC.
|
|
58
|
+
*
|
|
59
|
+
* Answers a NEW object built from the judged fields alone, never the caller's, so nothing else crosses
|
|
60
|
+
* the RPC or reaches the access log. `reach` is its first key: the log keeps a read's params cut to a
|
|
61
|
+
* bounded length, and nothing after the reach can push it out of what is kept.
|
|
62
|
+
*/
|
|
63
|
+
export declare function assertWireAuthFilter(filter: unknown): DeploymentWireAuthFilter;
|
|
64
|
+
/** The access-log target of a read: the tenant a tenant reach names, none for the fleet. */
|
|
65
|
+
export declare function wireAuthAccessTarget(filter: DeploymentWireAuthFilter): {
|
|
66
|
+
tenantId: TenantId | null;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Record an upload's capability for its script, replacing the script's earlier record, and answer
|
|
70
|
+
* whether it did. Takes the row the adapter parsed (`deploymentWireAuth`) before it reached here: on
|
|
71
|
+
* Cloudflare that parse runs before the call into the directory's object, so a refusal keeps its code
|
|
72
|
+
* across the RPC.
|
|
73
|
+
*
|
|
74
|
+
* Writes nothing, and answers `false`, for a vertical the registry does not hold: a record exists only
|
|
75
|
+
* beside its vertical's registration, so no later registrant of a slug can read a record of an upload
|
|
76
|
+
* made before it held it. Every upload records after its vertical is registered (a push registers,
|
|
77
|
+
* then publishes, then records; a serve runs for a registered vertical), so this refuses only a write
|
|
78
|
+
* that raced the vertical's delete. Judged in the caller's transaction, beside the write it guards; the
|
|
79
|
+
* adapter turns `false` into `not_found`.
|
|
80
|
+
*/
|
|
81
|
+
export declare function writeDeploymentWireAuth(db: SwitchSql, row: DeploymentWireAuth): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* One page of the stored records the filter reaches, by script name. The filter is judged here too
|
|
84
|
+
* (`assertWireAuthFilter`), so no caller reaches the table unconfined or unbounded. A row that does
|
|
85
|
+
* not parse throws: it is a corrupt directory, not a fact.
|
|
86
|
+
*/
|
|
87
|
+
export declare function deploymentWireAuthOf(db: SwitchSql, input: DeploymentWireAuthFilter): DeploymentWireAuth[];
|
|
88
|
+
/**
|
|
89
|
+
* One pass of the fleet walk (RFC wire-signing follow-on 4), as its `walkWireAuth` admin row: whether
|
|
90
|
+
* it applied or only reported, the cursor it started from and the one it ended at, how many scripts it
|
|
91
|
+
* walked, and by name the scripts it updated, held, released and failed on. Script names and reasons
|
|
92
|
+
* only, never a key or a binding's value.
|
|
93
|
+
*/
|
|
94
|
+
export interface WireWalkAudit {
|
|
95
|
+
readonly apply: boolean;
|
|
96
|
+
/** A confirming pass, which read every recorded script rather than trusting its record. */
|
|
97
|
+
readonly confirm: boolean;
|
|
98
|
+
readonly from: string | null;
|
|
99
|
+
/** Where the next pass starts; `null` at the end of the fleet, or when the pass ended in an error. */
|
|
100
|
+
readonly next: string | null;
|
|
101
|
+
/** Scripts walked, counted to where the pass ended, an error included. */
|
|
102
|
+
readonly walked: number;
|
|
103
|
+
readonly updated: readonly string[];
|
|
104
|
+
readonly held: readonly string[];
|
|
105
|
+
readonly released: readonly string[];
|
|
106
|
+
readonly skipped: readonly {
|
|
107
|
+
readonly deploymentRef: string;
|
|
108
|
+
readonly reason: string;
|
|
109
|
+
}[];
|
|
110
|
+
readonly failed: readonly {
|
|
111
|
+
readonly deploymentRef: string;
|
|
112
|
+
readonly reason: string;
|
|
113
|
+
}[];
|
|
114
|
+
/** Set when the pass ended in an error: the fixed text a person reads, never an upstream message. */
|
|
115
|
+
readonly error?: string;
|
|
116
|
+
/**
|
|
117
|
+
* Set when the pass was refused before it walked anything, because the settings it would give are
|
|
118
|
+
* refused (the rollout setting does not parse, or the lists do not load): the setting and the
|
|
119
|
+
* problem, never a key.
|
|
120
|
+
*/
|
|
121
|
+
readonly refused?: string;
|
|
122
|
+
}
|
|
123
|
+
/** Forget a vertical's records, with the vertical. */
|
|
124
|
+
export declare function forgetVerticalWireAuth(db: SwitchSql, verticalSlug: string): void;
|
|
125
|
+
//# sourceMappingURL=deployment-wire-auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deployment-wire-auth.d.ts","sourceRoot":"","sources":["../src/deployment-wire-auth.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAA8D,KAAK,kBAAkB,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC7I,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAEpD,YAAY,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,kFAAkF;AAClF,eAAO,MAAM,wBAAwB,qUASpC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,uBAAuB,GAAG;IAAE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAA;CAAE,CAAC;AAEjG;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,KAAK,EAAE,uBAAuB,CAAC;IACxC,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;CACjC;AAID,yFAAyF;AACzF,eAAO,MAAM,yBAAyB,MAAM,CAAC;AAS7C;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,OAAO,GAAG,wBAAwB,CA0C9E;AAED,4FAA4F;AAC5F,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,wBAAwB,GAAG;IAAE,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAA;CA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AAE,MAAM,GAAG,IAAI,CAEhF"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The capability record (RFC wire-signing §7, Q8), as statements both adapters run against their
|
|
3
|
+
* directory: one row per deployment, the script an upload went to (a version's archive script or a
|
|
4
|
+
* vertical's serving script), holding what that upload gave it. Every upload of the script replaces
|
|
5
|
+
* its row, so the row is the last upload's: the one the running script was built from. Written once
|
|
6
|
+
* so the two adapters cannot keep different records of the same fleet.
|
|
7
|
+
*
|
|
8
|
+
* The uploader writes it from what it built and injected; a vertical never declares it, since a
|
|
9
|
+
* claim a version makes about itself proves nothing. The readiness report (follow-on 4) reads it.
|
|
10
|
+
* A vertical's rows go with the vertical (`forgetVerticalWireAuth`), so none outlives what it
|
|
11
|
+
* describes.
|
|
12
|
+
*/
|
|
13
|
+
import { deploymentWireAuth, LIST_PAGE_MAX, substratError, tenantId } from '@substrat-run/contracts';
|
|
14
|
+
/** Interpolated into both adapters' directory DDL, so the two spell one table. */
|
|
15
|
+
export const DEPLOYMENT_WIRE_AUTH_DDL = `
|
|
16
|
+
CREATE TABLE IF NOT EXISTS vertical_wire_auth (
|
|
17
|
+
deployment_ref TEXT PRIMARY KEY,
|
|
18
|
+
vertical_slug TEXT NOT NULL,
|
|
19
|
+
version_id TEXT,
|
|
20
|
+
record TEXT NOT NULL,
|
|
21
|
+
recorded_at TEXT NOT NULL
|
|
22
|
+
);
|
|
23
|
+
CREATE INDEX IF NOT EXISTS vertical_wire_auth_slug ON vertical_wire_auth (vertical_slug);
|
|
24
|
+
`;
|
|
25
|
+
const refused = (message) => substratError('validation_failed', message);
|
|
26
|
+
/** The longest `verticalSlug` or `cursor` a read takes. A script name is far shorter. */
|
|
27
|
+
export const WIRE_AUTH_FILTER_TEXT_MAX = 256;
|
|
28
|
+
const FILTER_KEYS = new Set(['reach', 'verticalSlug', 'limit', 'cursor', 'order']);
|
|
29
|
+
/** The longest caller-supplied key name a refusal echoes, so its text stays bounded. */
|
|
30
|
+
const ECHOED_KEY_MAX = 64;
|
|
31
|
+
const echoedKey = (key) => (key.length > ECHOED_KEY_MAX ? `${key.slice(0, ECHOED_KEY_MAX)}…` : key);
|
|
32
|
+
const REACH_REFUSAL = 'a capability-record read names its reach: one tenant ({ tenantId }) or the fleet ({ fleet: true }), exactly one';
|
|
33
|
+
/**
|
|
34
|
+
* The filter a read is allowed to run, or a `validation_failed` refusal: only the filter's own keys;
|
|
35
|
+
* a reach that is exactly one tenant (a tenant id) or exactly the fleet; a limit from 1 to
|
|
36
|
+
* `LIST_PAGE_MAX`; a vertical and a cursor of 1 to `WIRE_AUTH_FILTER_TEXT_MAX` characters; an order
|
|
37
|
+
* of `asc` or `desc`. Both adapters judge it before the read, and the Cloudflare host before the call
|
|
38
|
+
* into the directory's object, so the refusal keeps its code across the RPC.
|
|
39
|
+
*
|
|
40
|
+
* Answers a NEW object built from the judged fields alone, never the caller's, so nothing else crosses
|
|
41
|
+
* the RPC or reaches the access log. `reach` is its first key: the log keeps a read's params cut to a
|
|
42
|
+
* bounded length, and nothing after the reach can push it out of what is kept.
|
|
43
|
+
*/
|
|
44
|
+
export function assertWireAuthFilter(filter) {
|
|
45
|
+
if (typeof filter !== 'object' || filter === null || Array.isArray(filter)) {
|
|
46
|
+
throw refused('a capability-record read needs a filter naming its reach and its limit');
|
|
47
|
+
}
|
|
48
|
+
// Own properties only: a field inherited from a prototype, a polluted one included, is not the caller's.
|
|
49
|
+
const own = (o, key) => (Object.hasOwn(o, key) ? o[key] : undefined);
|
|
50
|
+
const extra = Object.keys(filter).filter((key) => !FILTER_KEYS.has(key));
|
|
51
|
+
if (extra.length > 0) {
|
|
52
|
+
throw refused(`a capability-record read takes reach, verticalSlug, limit, cursor and order; not ${extra.slice(0, 3).map(echoedKey).join(', ')}`);
|
|
53
|
+
}
|
|
54
|
+
const r = own(filter, 'reach');
|
|
55
|
+
if (typeof r !== 'object' || r === null || Array.isArray(r))
|
|
56
|
+
throw refused(REACH_REFUSAL);
|
|
57
|
+
const keys = Object.keys(r);
|
|
58
|
+
if (keys.length !== 1)
|
|
59
|
+
throw refused(REACH_REFUSAL);
|
|
60
|
+
const value = own(r, keys[0]);
|
|
61
|
+
let reach;
|
|
62
|
+
if (keys[0] === 'fleet' && value === true)
|
|
63
|
+
reach = { fleet: true };
|
|
64
|
+
else if (keys[0] === 'tenantId' && tenantId.safeParse(value).success)
|
|
65
|
+
reach = { tenantId: tenantId.parse(value) };
|
|
66
|
+
else
|
|
67
|
+
throw refused(REACH_REFUSAL);
|
|
68
|
+
const limit = own(filter, 'limit');
|
|
69
|
+
if (typeof limit !== 'number' || !Number.isInteger(limit) || limit < 1 || limit > LIST_PAGE_MAX) {
|
|
70
|
+
throw refused(`limit must be an integer from 1 to ${LIST_PAGE_MAX}, got ${typeof limit === 'number' ? String(limit) : typeof limit}`);
|
|
71
|
+
}
|
|
72
|
+
const text = (name) => {
|
|
73
|
+
const v = own(filter, name);
|
|
74
|
+
if (v === undefined)
|
|
75
|
+
return undefined;
|
|
76
|
+
if (typeof v !== 'string' || v.length === 0 || v.length > WIRE_AUTH_FILTER_TEXT_MAX) {
|
|
77
|
+
throw refused(`${name} must be a string of 1 to ${WIRE_AUTH_FILTER_TEXT_MAX} characters`);
|
|
78
|
+
}
|
|
79
|
+
return v;
|
|
80
|
+
};
|
|
81
|
+
const verticalSlug = text('verticalSlug');
|
|
82
|
+
const cursor = text('cursor');
|
|
83
|
+
const order = own(filter, 'order');
|
|
84
|
+
if (order !== undefined && order !== 'asc' && order !== 'desc')
|
|
85
|
+
throw refused('order must be asc or desc');
|
|
86
|
+
return {
|
|
87
|
+
reach,
|
|
88
|
+
...(verticalSlug !== undefined ? { verticalSlug } : {}),
|
|
89
|
+
limit,
|
|
90
|
+
...(cursor !== undefined ? { cursor } : {}),
|
|
91
|
+
...(order !== undefined ? { order } : {}),
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** The access-log target of a read: the tenant a tenant reach names, none for the fleet. */
|
|
95
|
+
export function wireAuthAccessTarget(filter) {
|
|
96
|
+
return { tenantId: 'tenantId' in filter.reach ? filter.reach.tenantId : null };
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Record an upload's capability for its script, replacing the script's earlier record, and answer
|
|
100
|
+
* whether it did. Takes the row the adapter parsed (`deploymentWireAuth`) before it reached here: on
|
|
101
|
+
* Cloudflare that parse runs before the call into the directory's object, so a refusal keeps its code
|
|
102
|
+
* across the RPC.
|
|
103
|
+
*
|
|
104
|
+
* Writes nothing, and answers `false`, for a vertical the registry does not hold: a record exists only
|
|
105
|
+
* beside its vertical's registration, so no later registrant of a slug can read a record of an upload
|
|
106
|
+
* made before it held it. Every upload records after its vertical is registered (a push registers,
|
|
107
|
+
* then publishes, then records; a serve runs for a registered vertical), so this refuses only a write
|
|
108
|
+
* that raced the vertical's delete. Judged in the caller's transaction, beside the write it guards; the
|
|
109
|
+
* adapter turns `false` into `not_found`.
|
|
110
|
+
*/
|
|
111
|
+
export function writeDeploymentWireAuth(db, row) {
|
|
112
|
+
if (db.all('SELECT 1 FROM verticals WHERE slug = ?', row.verticalSlug).length === 0)
|
|
113
|
+
return false;
|
|
114
|
+
db.run(`INSERT INTO vertical_wire_auth (deployment_ref, vertical_slug, version_id, record, recorded_at)
|
|
115
|
+
VALUES (?, ?, ?, ?, ?)
|
|
116
|
+
ON CONFLICT (deployment_ref) DO UPDATE SET
|
|
117
|
+
vertical_slug = excluded.vertical_slug,
|
|
118
|
+
version_id = excluded.version_id,
|
|
119
|
+
record = excluded.record,
|
|
120
|
+
recorded_at = excluded.recorded_at`, row.deploymentRef, row.verticalSlug, row.versionId, JSON.stringify(row.record), row.recordedAt);
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* One page of the stored records the filter reaches, by script name. The filter is judged here too
|
|
125
|
+
* (`assertWireAuthFilter`), so no caller reaches the table unconfined or unbounded. A row that does
|
|
126
|
+
* not parse throws: it is a corrupt directory, not a fact.
|
|
127
|
+
*/
|
|
128
|
+
export function deploymentWireAuthOf(db, input) {
|
|
129
|
+
const filter = assertWireAuthFilter(input);
|
|
130
|
+
const desc = filter.order === 'desc';
|
|
131
|
+
const where = [];
|
|
132
|
+
const params = [];
|
|
133
|
+
if ('tenantId' in filter.reach) {
|
|
134
|
+
where.push('vertical_slug IN (SELECT slug FROM verticals WHERE owner_tenant = ?)');
|
|
135
|
+
params.push(filter.reach.tenantId);
|
|
136
|
+
}
|
|
137
|
+
if (filter.verticalSlug !== undefined) {
|
|
138
|
+
where.push('vertical_slug = ?');
|
|
139
|
+
params.push(filter.verticalSlug);
|
|
140
|
+
}
|
|
141
|
+
if (filter.cursor) {
|
|
142
|
+
where.push(desc ? 'deployment_ref < ?' : 'deployment_ref > ?');
|
|
143
|
+
params.push(filter.cursor);
|
|
144
|
+
}
|
|
145
|
+
params.push(filter.limit);
|
|
146
|
+
const rows = db.all('SELECT deployment_ref, vertical_slug, version_id, record, recorded_at FROM vertical_wire_auth' +
|
|
147
|
+
(where.length ? ` WHERE ${where.join(' AND ')}` : '') +
|
|
148
|
+
` ORDER BY deployment_ref ${desc ? 'DESC' : 'ASC'} LIMIT ?`, ...params);
|
|
149
|
+
return rows.map((r) => deploymentWireAuth.parse({
|
|
150
|
+
deploymentRef: r['deployment_ref'],
|
|
151
|
+
verticalSlug: r['vertical_slug'],
|
|
152
|
+
versionId: r['version_id'],
|
|
153
|
+
record: JSON.parse(String(r['record'])),
|
|
154
|
+
recordedAt: r['recorded_at'],
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
/** Forget a vertical's records, with the vertical. */
|
|
158
|
+
export function forgetVerticalWireAuth(db, verticalSlug) {
|
|
159
|
+
db.run('DELETE FROM vertical_wire_auth WHERE vertical_slug = ?', verticalSlug);
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=deployment-wire-auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deployment-wire-auth.js","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