@substrat-run/kernel 0.146.0 → 0.148.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/audit-outcome.d.ts +1 -1
- package/dist/audit-outcome.d.ts.map +1 -1
- package/dist/audit-outcome.js +4 -2
- package/dist/audit-outcome.js.map +1 -1
- package/dist/export-break.d.ts +137 -0
- package/dist/export-break.d.ts.map +1 -0
- package/dist/export-break.js +219 -0
- package/dist/export-break.js.map +1 -0
- package/dist/index.d.ts +17 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -5
- package/dist/index.js.map +1 -1
- package/dist/install-receipts.d.ts +116 -0
- package/dist/install-receipts.d.ts.map +1 -0
- package/dist/install-receipts.js +162 -0
- package/dist/install-receipts.js.map +1 -0
- package/dist/invocation-line.d.ts +63 -0
- package/dist/invocation-line.d.ts.map +1 -1
- package/dist/invocation-line.js +44 -0
- package/dist/invocation-line.js.map +1 -1
- package/dist/map-bounded.d.ts +8 -0
- package/dist/map-bounded.d.ts.map +1 -0
- package/dist/map-bounded.js +16 -0
- package/dist/map-bounded.js.map +1 -0
- package/dist/meters.d.ts +5 -0
- package/dist/meters.d.ts.map +1 -1
- package/dist/meters.js +0 -0
- package/dist/meters.js.map +1 -1
- package/dist/peer.js +1 -1
- package/dist/platform-sweep.d.ts +52 -363
- package/dist/platform-sweep.d.ts.map +1 -1
- package/dist/platform-sweep.js +49 -564
- package/dist/platform-sweep.js.map +1 -1
- package/dist/schedule-state.d.ts +91 -0
- package/dist/schedule-state.d.ts.map +1 -0
- package/dist/schedule-state.js +118 -0
- package/dist/schedule-state.js.map +1 -0
- package/dist/scope-copy-ledger.d.ts +29 -0
- package/dist/scope-copy-ledger.d.ts.map +1 -1
- package/dist/scope-copy-ledger.js +23 -0
- package/dist/scope-copy-ledger.js.map +1 -1
- package/dist/scope-copy.d.ts.map +1 -1
- package/dist/scope-copy.js +3 -2
- package/dist/scope-copy.js.map +1 -1
- package/dist/scope-host.d.ts +199 -14
- package/dist/scope-host.d.ts.map +1 -1
- package/dist/scope-host.js.map +1 -1
- package/dist/scope-identity.d.ts +68 -0
- package/dist/scope-identity.d.ts.map +1 -0
- package/dist/scope-identity.js +75 -0
- package/dist/scope-identity.js.map +1 -0
- package/dist/scope-store.d.ts +139 -0
- package/dist/scope-store.d.ts.map +1 -0
- package/dist/scope-store.js +237 -0
- package/dist/scope-store.js.map +1 -0
- package/dist/spine-restore.js +1 -1
- package/dist/sql-limits.d.ts.map +1 -1
- package/dist/sql-limits.js +10 -1
- package/dist/sql-limits.js.map +1 -1
- package/dist/storage-gauge.d.ts +21 -2
- package/dist/storage-gauge.d.ts.map +1 -1
- package/dist/storage-gauge.js +73 -6
- package/dist/storage-gauge.js.map +1 -1
- package/dist/store-kind-releases.d.ts +137 -0
- package/dist/store-kind-releases.d.ts.map +1 -0
- package/dist/store-kind-releases.js +252 -0
- package/dist/store-kind-releases.js.map +1 -0
- package/dist/upload-link.d.ts +89 -0
- package/dist/upload-link.d.ts.map +1 -0
- package/dist/upload-link.js +277 -0
- package/dist/upload-link.js.map +1 -0
- package/dist/vertical-scope-stores.d.ts +43 -0
- package/dist/vertical-scope-stores.d.ts.map +1 -0
- package/dist/vertical-scope-stores.js +195 -0
- package/dist/vertical-scope-stores.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { type CheckSubject, type PlatformActorId, type ReservedStoreOperation, type ReservedStoreResults, type ScopeId, type StoreOperationCatalog, type StoreRequest, type StoreResponse, type TenantId } from '@substrat-run/contracts';
|
|
2
|
+
import { type StoreCallLine } from './invocation-line.js';
|
|
3
|
+
import type { HostAdmin } from './scope-host.js';
|
|
4
|
+
/** Who a scope-store object belongs to. The host builds it. The runner keys on it. */
|
|
5
|
+
export interface ScopeStoreAddress {
|
|
6
|
+
readonly tenantId: string;
|
|
7
|
+
readonly vertical: string;
|
|
8
|
+
readonly scopeId: string;
|
|
9
|
+
readonly binding: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* What a kind ships for the pure adapter and for tests (#2213). One runner per
|
|
13
|
+
* kind. `invoke` speaks the envelope. `start` runs on the first store call.
|
|
14
|
+
* `stop` runs from `close`, including when `start` never ran, so it tolerates that.
|
|
15
|
+
*/
|
|
16
|
+
export interface ScopeStoreRunner {
|
|
17
|
+
readonly kind: string;
|
|
18
|
+
start(): Promise<void>;
|
|
19
|
+
stop(): Promise<void>;
|
|
20
|
+
invoke(address: ScopeStoreAddress, request: StoreRequest): Promise<StoreResponse>;
|
|
21
|
+
}
|
|
22
|
+
/** The runners a host was given, by binding. A binding named twice is refused. */
|
|
23
|
+
export interface ScopeStoreHostOptions {
|
|
24
|
+
/** When set, a scope running any other vertical is refused. */
|
|
25
|
+
readonly vertical?: string;
|
|
26
|
+
readonly runners?: readonly {
|
|
27
|
+
readonly binding: string;
|
|
28
|
+
readonly runner: ScopeStoreRunner;
|
|
29
|
+
}[];
|
|
30
|
+
readonly kinds?: Readonly<Record<string, string>>;
|
|
31
|
+
/**
|
|
32
|
+
* `platform` fetches `store.substrat.internal`. The router signs and addresses
|
|
33
|
+
* the object. `binding` is the direct namespace, for local development and
|
|
34
|
+
* tests, and is not an isolation boundary. On the Cloudflare host the omitted
|
|
35
|
+
* value is `platform` unless a non-empty `runners` list was given, control plane or
|
|
36
|
+
* not; `'platform'` beside runners is refused. On the platform hop the host's local
|
|
37
|
+
* size, export and erase reads refuse (`unavailable`) rather than answer "no stores".
|
|
38
|
+
*/
|
|
39
|
+
readonly transport?: 'platform' | 'binding';
|
|
40
|
+
}
|
|
41
|
+
export declare function scopeStoreRunnersOf(options: ScopeStoreHostOptions | undefined): Map<string, ScopeStoreRunner>;
|
|
42
|
+
/** Starts and stops one host's runners (#2213). */
|
|
43
|
+
export interface ScopeStoreLifecycle {
|
|
44
|
+
start(): Promise<void>;
|
|
45
|
+
stop(): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The lifecycle both adapters run their runners through. `start` starts each distinct
|
|
49
|
+
* runner once, and concurrent callers share the pass. A runner that started stays
|
|
50
|
+
* started when a later one throws, so the retry starts only the rest.
|
|
51
|
+
*
|
|
52
|
+
* `stop` first waits for a pass in flight, which starts no further runner once a stop
|
|
53
|
+
* has begun (it rejects instead), so no runner is started after the stops are asked.
|
|
54
|
+
* It then asks every runner, started or not, since a runner tolerates a stop without a
|
|
55
|
+
* start. One that throws does not leave the others running. One failure is rethrown as
|
|
56
|
+
* it is, and several as an `AggregateError` carrying each.
|
|
57
|
+
*/
|
|
58
|
+
export declare function scopeStoreLifecycleOf(runners: ReadonlyMap<string, ScopeStoreRunner>): ScopeStoreLifecycle;
|
|
59
|
+
/**
|
|
60
|
+
* The capability a `getScopeStore` door returns (#2207).
|
|
61
|
+
*
|
|
62
|
+
* `invoke` takes an operation and its input. It does not take `InvokeOptions`:
|
|
63
|
+
* those belong to a scope operation (idempotency, observers), and a store call
|
|
64
|
+
* is not one. A third argument is refused at runtime as well as by this type.
|
|
65
|
+
* The catalog parameter narrows `operation` for a caller who knows the kind.
|
|
66
|
+
*/
|
|
67
|
+
export interface StoreStub<C extends StoreOperationCatalog = StoreOperationCatalog> {
|
|
68
|
+
readonly tenantId: TenantId;
|
|
69
|
+
readonly scopeId: ScopeId;
|
|
70
|
+
readonly subjectKind?: CheckSubject['kind'];
|
|
71
|
+
invoke(operation: C['operations'][number], input?: unknown): Promise<unknown>;
|
|
72
|
+
}
|
|
73
|
+
/** What one store call leaves on an invocation line (#2245). Never the input. */
|
|
74
|
+
export type StoreCallReport = StoreCallLine;
|
|
75
|
+
/**
|
|
76
|
+
* Observers on a store stub (#2245). They carry no authority, the same way
|
|
77
|
+
* {@link ScopeStubOptions} does not. With none passed, the call is recorded on the
|
|
78
|
+
* request now running (RFC §6); `onStoreCall`, when passed, is heard instead.
|
|
79
|
+
* A throw from either is swallowed: the call's result is the store's, not the log's.
|
|
80
|
+
*/
|
|
81
|
+
export interface ScopeStoreStubOptions {
|
|
82
|
+
readonly onStoreCall?: (report: StoreCallReport) => void;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Time one store call and report it. The report names the binding, the
|
|
86
|
+
* operation, the outcome and the duration. It is built here, from those four
|
|
87
|
+
* facts, so a caller cannot put the input on it. A passed observer wins; with
|
|
88
|
+
* none, the call goes to the request now running, and outside one it is not
|
|
89
|
+
* logged.
|
|
90
|
+
*/
|
|
91
|
+
export declare function observeStoreCall<T>(binding: string, operation: string, run: () => Promise<T>, onStoreCall?: (report: StoreCallReport) => void): Promise<T>;
|
|
92
|
+
/**
|
|
93
|
+
* Send one envelope and read the answer (#2207). Reserved names are refused
|
|
94
|
+
* here, before `send`, so the store never sees a `substrat.*` call from a
|
|
95
|
+
* vertical. The platform's own caller does not come through this function.
|
|
96
|
+
*/
|
|
97
|
+
export declare function callScopeStore(send: (request: StoreRequest) => Promise<unknown>, operation: string, input?: unknown, ...extra: unknown[]): Promise<unknown>;
|
|
98
|
+
/** What a reserved operation answers, parsed (#2239). */
|
|
99
|
+
export type ReservedStoreResult<O extends ReservedStoreOperation> = ReservedStoreResults[O];
|
|
100
|
+
/**
|
|
101
|
+
* The platform's caller (#2207). A name that is not reserved is refused before
|
|
102
|
+
* `send`, the mirror of {@link callScopeStore}. The result is parsed against the
|
|
103
|
+
* operation's schema, so a store that answers the wrong shape fails here, and the
|
|
104
|
+
* caller gets that parsed type back rather than parsing again.
|
|
105
|
+
*/
|
|
106
|
+
export declare function callReservedStoreOperation<O extends ReservedStoreOperation>(send: (request: StoreRequest) => Promise<unknown>, operation: O, input?: unknown): Promise<ReservedStoreResult<O>>;
|
|
107
|
+
/**
|
|
108
|
+
* What a restore's erasure replay did (#2207). Present only when there is something to report:
|
|
109
|
+
* `storeErasuresReplayed > 0` or `storeErasureIncomplete`. Absent means no erasure had to be
|
|
110
|
+
* replayed and none is missing (no store for the target scope on this host, or no tombstone
|
|
111
|
+
* that applies).
|
|
112
|
+
*
|
|
113
|
+
* `storeErasureIncomplete` means some tombstone that applies to the restored data was not
|
|
114
|
+
* re-erased here. Either a store call failed, which the same restore again converges, or
|
|
115
|
+
* `storeErasureSourceUnknown`: the dump's source scope is not a scope of this tenant on this
|
|
116
|
+
* host (another host's backup, another tenant's, a deleted snapshot), so its marks cannot
|
|
117
|
+
* be read and running the restore again does not change that.
|
|
118
|
+
*/
|
|
119
|
+
export interface StoreErasureReplay {
|
|
120
|
+
storeErasuresReplayed: number;
|
|
121
|
+
storeErasureIncomplete: boolean;
|
|
122
|
+
storeErasureSourceUnknown?: true;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* `substrat.erase` again for every subject tombstoned in the target or in the dump's source
|
|
126
|
+
* (#2207). The target's marks always apply: the data now lives there. The source's apply
|
|
127
|
+
* when this host knows the source; a reaped scope keeps its directory row and its marks, so
|
|
128
|
+
* it is known. An unknown source never refuses the restore: it is reported. Each subject is
|
|
129
|
+
* erased once, and `erase` returns how many bindings it called.
|
|
130
|
+
*/
|
|
131
|
+
export declare function replayStoreErasures(input: {
|
|
132
|
+
admin: Pick<HostAdmin, 'listShreddedSubjects'>;
|
|
133
|
+
actor: PlatformActorId;
|
|
134
|
+
tenantId: TenantId;
|
|
135
|
+
target: ScopeId;
|
|
136
|
+
source: ScopeId;
|
|
137
|
+
erase: (subjectId: string) => Promise<number>;
|
|
138
|
+
}): Promise<StoreErasureReplay | undefined>;
|
|
139
|
+
//# sourceMappingURL=scope-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-store.d.ts","sourceRoot":"","sources":["../src/scope-store.ts"],"names":[],"mappings":"AAAA,OAAO,EAgBL,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,oBAAoB,EACzB,KAAK,OAAO,EACZ,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,QAAQ,EACd,MAAM,yBAAyB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EAAE,GAClB,OAAO,CAAC,OAAO,CAAC,CAelB;AAUD,yDAAyD;AACzD,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,sBAAsB,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAAC;AAqB5F;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAAC,CAAC,SAAS,sBAAsB,EAC/E,IAAI,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,OAAO,CAAC,OAAO,CAAC,EACjD,SAAS,EAAE,CAAC,EACZ,KAAK,CAAC,EAAE,OAAO,GACd,OAAO,CAAC,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAejC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,kBAAkB;IACjC,qBAAqB,EAAE,MAAM,CAAC;IAC9B,sBAAsB,EAAE,OAAO,CAAC;IAChC,yBAAyB,CAAC,EAAE,IAAI,CAAC;CAClC;AAED;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CAAC,KAAK,EAAE;IAC/C,KAAK,EAAE,IAAI,CAAC,SAAS,EAAE,sBAAsB,CAAC,CAAC;IAC/C,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;IAChB,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/C,GAAG,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAqC1C"}
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { errorCodeOf, RESERVED_STORE_OPERATIONS, STORE_OPERATION_NAME_MAX, StoreError, storeEraseInput, storeEraseResult, storeExportResult, storeImportInput, storeImportResult, storeOperationName, storeRequest, storeResponse, storeSizeResult, storeWipeResult, substratError, } from '@substrat-run/contracts';
|
|
2
|
+
import { currentStoreCallSink } from './invocation-line.js';
|
|
3
|
+
export function scopeStoreRunnersOf(options) {
|
|
4
|
+
const runners = new Map();
|
|
5
|
+
for (const entry of options?.runners ?? []) {
|
|
6
|
+
if (runners.has(entry.binding)) {
|
|
7
|
+
throw new Error(`scope store binding '${entry.binding}' is configured twice`);
|
|
8
|
+
}
|
|
9
|
+
runners.set(entry.binding, entry.runner);
|
|
10
|
+
}
|
|
11
|
+
return runners;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The lifecycle both adapters run their runners through. `start` starts each distinct
|
|
15
|
+
* runner once, and concurrent callers share the pass. A runner that started stays
|
|
16
|
+
* started when a later one throws, so the retry starts only the rest.
|
|
17
|
+
*
|
|
18
|
+
* `stop` first waits for a pass in flight, which starts no further runner once a stop
|
|
19
|
+
* has begun (it rejects instead), so no runner is started after the stops are asked.
|
|
20
|
+
* It then asks every runner, started or not, since a runner tolerates a stop without a
|
|
21
|
+
* start. One that throws does not leave the others running. One failure is rethrown as
|
|
22
|
+
* it is, and several as an `AggregateError` carrying each.
|
|
23
|
+
*/
|
|
24
|
+
export function scopeStoreLifecycleOf(runners) {
|
|
25
|
+
const started = new Set();
|
|
26
|
+
let pending = null;
|
|
27
|
+
let stopping = false;
|
|
28
|
+
return {
|
|
29
|
+
start() {
|
|
30
|
+
if (pending)
|
|
31
|
+
return pending;
|
|
32
|
+
const pass = (async () => {
|
|
33
|
+
for (const runner of new Set(runners.values())) {
|
|
34
|
+
if (started.has(runner))
|
|
35
|
+
continue;
|
|
36
|
+
if (stopping)
|
|
37
|
+
throw new Error('scope-store runners are stopping; this start is abandoned');
|
|
38
|
+
await runner.start();
|
|
39
|
+
started.add(runner);
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
42
|
+
pending = pass;
|
|
43
|
+
pass.catch(() => {
|
|
44
|
+
if (pending === pass)
|
|
45
|
+
pending = null;
|
|
46
|
+
});
|
|
47
|
+
return pass;
|
|
48
|
+
},
|
|
49
|
+
async stop() {
|
|
50
|
+
stopping = true;
|
|
51
|
+
try {
|
|
52
|
+
await pending?.catch(() => undefined);
|
|
53
|
+
const failures = [];
|
|
54
|
+
for (const runner of new Set(runners.values())) {
|
|
55
|
+
try {
|
|
56
|
+
await runner.stop();
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
failures.push(err);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (failures.length === 1)
|
|
63
|
+
throw failures[0];
|
|
64
|
+
if (failures.length > 1)
|
|
65
|
+
throw new AggregateError(failures, `${failures.length} scope-store runners failed to stop`);
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
started.clear();
|
|
69
|
+
pending = null;
|
|
70
|
+
stopping = false;
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Refuse an operation name that is not a fixed label (RFC §6): no `@`, no
|
|
77
|
+
* whitespace, no `:`, at most 64 characters. Checked before the call and before
|
|
78
|
+
* any report, so a name built from input never reaches a line.
|
|
79
|
+
*/
|
|
80
|
+
function assertStoreOperationName(operation) {
|
|
81
|
+
if (!storeOperationName.safeParse(operation).success) {
|
|
82
|
+
throw substratError('validation_failed', `a store operation name is a fixed label: no @, no whitespace, no :, at most ${STORE_OPERATION_NAME_MAX} characters`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Time one store call and report it. The report names the binding, the
|
|
87
|
+
* operation, the outcome and the duration. It is built here, from those four
|
|
88
|
+
* facts, so a caller cannot put the input on it. A passed observer wins; with
|
|
89
|
+
* none, the call goes to the request now running, and outside one it is not
|
|
90
|
+
* logged.
|
|
91
|
+
*/
|
|
92
|
+
export async function observeStoreCall(binding, operation, run, onStoreCall) {
|
|
93
|
+
assertStoreOperationName(operation);
|
|
94
|
+
// Resolved before the call: the record is the one of the request that made it.
|
|
95
|
+
const sink = onStoreCall ?? currentStoreCallSink();
|
|
96
|
+
const started = Date.now();
|
|
97
|
+
try {
|
|
98
|
+
const result = await run();
|
|
99
|
+
noteStoreCall({ binding, operation, outcome: 'ok', durationMs: Date.now() - started }, sink);
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
catch (err) {
|
|
103
|
+
noteStoreCall({ binding, operation, outcome: 'error', durationMs: Date.now() - started }, sink);
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function noteStoreCall(report, sink) {
|
|
108
|
+
try {
|
|
109
|
+
sink?.(report);
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
// Advisory. A broken observer must not replace the store's answer.
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Send one envelope and read the answer (#2207). Reserved names are refused
|
|
117
|
+
* here, before `send`, so the store never sees a `substrat.*` call from a
|
|
118
|
+
* vertical. The platform's own caller does not come through this function.
|
|
119
|
+
*/
|
|
120
|
+
export async function callScopeStore(send, operation, input, ...extra) {
|
|
121
|
+
if (extra.length > 0) {
|
|
122
|
+
throw substratError('forbidden', 'a scope store invoke takes an operation and an input, and nothing else');
|
|
123
|
+
}
|
|
124
|
+
assertStoreOperationName(operation);
|
|
125
|
+
if (operation.startsWith('substrat.')) {
|
|
126
|
+
throw substratError('forbidden', `store operation '${operation}' is reserved for the platform`);
|
|
127
|
+
}
|
|
128
|
+
const request = storeRequest.parse({ operation, input });
|
|
129
|
+
const parsed = storeResponse.safeParse(await send(request));
|
|
130
|
+
if (!parsed.success) {
|
|
131
|
+
throw new StoreError({ code: 'bad_envelope', status: 502, body: parsed.error.issues });
|
|
132
|
+
}
|
|
133
|
+
if ('error' in parsed.data)
|
|
134
|
+
throw new StoreError(parsed.data.error);
|
|
135
|
+
return parsed.data.result;
|
|
136
|
+
}
|
|
137
|
+
const RESERVED_RESULT = {
|
|
138
|
+
'substrat.export': storeExportResult,
|
|
139
|
+
'substrat.import': storeImportResult,
|
|
140
|
+
'substrat.size': storeSizeResult,
|
|
141
|
+
'substrat.wipe': storeWipeResult,
|
|
142
|
+
'substrat.erase': storeEraseResult,
|
|
143
|
+
};
|
|
144
|
+
const reservedNames = RESERVED_STORE_OPERATIONS;
|
|
145
|
+
function reservedInput(operation, input) {
|
|
146
|
+
if (operation === 'substrat.import') {
|
|
147
|
+
const parsed = storeImportInput.safeParse(input);
|
|
148
|
+
if (!parsed.success)
|
|
149
|
+
throw substratError('validation_failed', 'substrat.import takes { tables }');
|
|
150
|
+
return parsed.data;
|
|
151
|
+
}
|
|
152
|
+
if (operation === 'substrat.erase') {
|
|
153
|
+
const parsed = storeEraseInput.safeParse(input);
|
|
154
|
+
if (!parsed.success)
|
|
155
|
+
throw substratError('validation_failed', 'substrat.erase takes { subjectId }');
|
|
156
|
+
return parsed.data;
|
|
157
|
+
}
|
|
158
|
+
if (input !== undefined) {
|
|
159
|
+
throw substratError('validation_failed', `store operation '${operation}' takes no input`);
|
|
160
|
+
}
|
|
161
|
+
return undefined;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The platform's caller (#2207). A name that is not reserved is refused before
|
|
165
|
+
* `send`, the mirror of {@link callScopeStore}. The result is parsed against the
|
|
166
|
+
* operation's schema, so a store that answers the wrong shape fails here, and the
|
|
167
|
+
* caller gets that parsed type back rather than parsing again.
|
|
168
|
+
*/
|
|
169
|
+
export async function callReservedStoreOperation(send, operation, input) {
|
|
170
|
+
if (!reservedNames.includes(operation)) {
|
|
171
|
+
throw substratError('forbidden', `store operation '${operation}' is not reserved for the platform`);
|
|
172
|
+
}
|
|
173
|
+
const request = storeRequest.parse({ operation, input: reservedInput(operation, input) });
|
|
174
|
+
const parsed = storeResponse.safeParse(await send(request));
|
|
175
|
+
if (!parsed.success) {
|
|
176
|
+
throw new StoreError({ code: 'bad_envelope', status: 502, body: parsed.error.issues });
|
|
177
|
+
}
|
|
178
|
+
if ('error' in parsed.data)
|
|
179
|
+
throw new StoreError(parsed.data.error);
|
|
180
|
+
const result = RESERVED_RESULT[operation].safeParse(parsed.data.result);
|
|
181
|
+
if (!result.success) {
|
|
182
|
+
throw new StoreError({ code: 'bad_envelope', status: 502, body: result.error.issues });
|
|
183
|
+
}
|
|
184
|
+
return result.data;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* `substrat.erase` again for every subject tombstoned in the target or in the dump's source
|
|
188
|
+
* (#2207). The target's marks always apply: the data now lives there. The source's apply
|
|
189
|
+
* when this host knows the source; a reaped scope keeps its directory row and its marks, so
|
|
190
|
+
* it is known. An unknown source never refuses the restore: it is reported. Each subject is
|
|
191
|
+
* erased once, and `erase` returns how many bindings it called.
|
|
192
|
+
*/
|
|
193
|
+
export async function replayStoreErasures(input) {
|
|
194
|
+
const { admin, actor, tenantId } = input;
|
|
195
|
+
const subjects = new Set();
|
|
196
|
+
const collect = async (scope) => {
|
|
197
|
+
let cursor;
|
|
198
|
+
for (;;) {
|
|
199
|
+
const page = await admin.listShreddedSubjects(actor, tenantId, scope, cursor);
|
|
200
|
+
for (const subject of page.subjects)
|
|
201
|
+
subjects.add(subject);
|
|
202
|
+
if (!page.nextCursor)
|
|
203
|
+
return;
|
|
204
|
+
cursor = page.nextCursor;
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
await collect(input.target);
|
|
208
|
+
let sourceUnknown = false;
|
|
209
|
+
if (input.source !== input.target) {
|
|
210
|
+
try {
|
|
211
|
+
await collect(input.source);
|
|
212
|
+
}
|
|
213
|
+
catch (e) {
|
|
214
|
+
if (errorCodeOf(e) !== 'not_found')
|
|
215
|
+
throw e;
|
|
216
|
+
sourceUnknown = true;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
let replayed = 0;
|
|
220
|
+
let failed = false;
|
|
221
|
+
for (const subject of subjects) {
|
|
222
|
+
try {
|
|
223
|
+
replayed += await input.erase(subject);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
failed = true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (replayed === 0 && !failed && !sourceUnknown)
|
|
230
|
+
return undefined;
|
|
231
|
+
return {
|
|
232
|
+
storeErasuresReplayed: replayed,
|
|
233
|
+
storeErasureIncomplete: failed || sourceUnknown,
|
|
234
|
+
...(sourceUnknown ? { storeErasureSourceUnknown: true } : {}),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
//# sourceMappingURL=scope-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scope-store.js","sourceRoot":"","sources":["../src/scope-store.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,yBAAyB,EACzB,wBAAwB,EACxB,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,eAAe,EACf,aAAa,GAUd,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAsB,MAAM,sBAAsB,CAAC;AAwChF,MAAM,UAAU,mBAAmB,CACjC,OAA0C;IAE1C,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;IACpD,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,OAAO,IAAI,EAAE,EAAE,CAAC;QAC3C,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YAC/B,MAAM,IAAI,KAAK,CAAC,wBAAwB,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;QAChF,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAQD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA8C;IAClF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IAC5C,IAAI,OAAO,GAAyB,IAAI,CAAC;IACzC,IAAI,QAAQ,GAAG,KAAK,CAAC;IACrB,OAAO;QAC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substratError } from '@substrat-run/contracts';
|
|
2
2
|
import { MIGRATION_DIGEST_LEGACY } from './migration-digest.js';
|
|
3
|
-
import { SCHEDULE_STATE_KIND_OF_OP } from './
|
|
3
|
+
import { SCHEDULE_STATE_KIND_OF_OP } from './schedule-state.js';
|
|
4
4
|
import { isSearchIndexTable } from './search-index.js';
|
|
5
5
|
import { SWITCH_KINDS, dumpCarriesSwitches, switchesBackfillSqlOf } from './system-switch-record.js';
|
|
6
6
|
import { dumpCarriesMembershipFences, membershipFencesBackfillSql } from './membership-fence.js';
|
package/dist/sql-limits.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-limits.d.ts","sourceRoot":"","sources":["../src/sql-limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,iBAAiB,CAAC;AAE3D,qFAAqF;AACrF,eAAO,MAAM,aAAa;IACxB,iDAAiD;aACjD,aAAa,EAAE,CAAC;IAChB,0EAA0E;aAC1E,eAAe,EAAE,GAAG;IACpB,kFAAkF;aAClF,cAAc,EAAE,MAAO;IACvB,uGAAuG;aACvG,gBAAgB,EAAE,EAAE;IACpB,0GAA0G;aAC1G,OAAO,EAAE,GAAG;CACJ,CAAC;AA8CX;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAuJvD;
|
|
1
|
+
{"version":3,"file":"sql-limits.d.ts","sourceRoot":"","sources":["../src/sql-limits.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyDG;AACH,OAAO,KAAK,EAAE,SAAS,EAAY,MAAM,iBAAiB,CAAC;AAE3D,qFAAqF;AACrF,eAAO,MAAM,aAAa;IACxB,iDAAiD;aACjD,aAAa,EAAE,CAAC;IAChB,0EAA0E;aAC1E,eAAe,EAAE,GAAG;IACpB,kFAAkF;aAClF,cAAc,EAAE,MAAO;IACvB,uGAAuG;aACvG,gBAAgB,EAAE,EAAE;IACpB,0GAA0G;aAC1G,OAAO,EAAE,GAAG;CACJ,CAAC;AA8CX;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAuJvD;AAaD;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,UAAW,MAAM,KAAG,MAC8C,CAAC;AAEpG,2FAA2F;AAC3F,eAAO,MAAM,mBAAmB,UAAW,MAAM,SAAS,MAAM,KAAG,MAC8B,CAAC;AAElG;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAW1D"}
|
package/dist/sql-limits.js
CHANGED
|
@@ -89,7 +89,7 @@ export function assertWithinSqlLimits(sql) {
|
|
|
89
89
|
};
|
|
90
90
|
let nVar = 0;
|
|
91
91
|
const named = new Map();
|
|
92
|
-
const tooManyVariables = (at) => new Error(`too many SQL variables at offset ${byteOffset(sql, at)}: SQLITE_ERROR`);
|
|
92
|
+
const tooManyVariables = (at) => new Error(`too many SQL variables at offset ${byteOffset(sql, at)}: SQLITE_ERROR (${TOO_MANY_VARIABLES_HINT})`);
|
|
93
93
|
const bindOne = (at, number_) => {
|
|
94
94
|
if (number_ > DO_SQL_LIMITS.boundParameters)
|
|
95
95
|
throw tooManyVariables(at);
|
|
@@ -222,6 +222,15 @@ export function assertWithinSqlLimits(sql) {
|
|
|
222
222
|
}
|
|
223
223
|
endAllLists();
|
|
224
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* What the node adapter adds to the DO's own words when a statement binds over the limit
|
|
227
|
+
* (#2248): almost always a placeholder list that grew with the data, and the way round it.
|
|
228
|
+
* Named, not imported: this module imports only types, which is what lets
|
|
229
|
+
* `tools/vitest/sql-limits.cjs` require it into every node process without loading contracts.
|
|
230
|
+
*/
|
|
231
|
+
const TOO_MANY_VARIABLES_HINT = `limit ${DO_SQL_LIMITS.boundParameters}; bind a list of any length as ONE JSON array: ` +
|
|
232
|
+
`\`id IN \${list.sql}\` with \`list = inList(values)\` from @substrat-run/contracts, ` +
|
|
233
|
+
`which is \`IN (SELECT value FROM json_each(?))\``;
|
|
225
234
|
/**
|
|
226
235
|
* The refusal of a result set wider than `DO_SQL_LIMITS.columns`: the DO's own words, then what
|
|
227
236
|
* the DO does not say. (A DO names a table it refuses `sqlite_altertab_<t>` for an `ADD COLUMN`,
|
package/dist/sql-limits.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sql-limits.js","sourceRoot":"","sources":["../src/sql-limits.ts"],"names":[],"mappings":"AA4DA,qFAAqF;AACrF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,iDAAiD;IACjD,aAAa,EAAE,CAAC;IAChB,0EAA0E;IAC1E,eAAe,EAAE,GAAG;IACpB,kFAAkF;IAClF,cAAc,EAAE,OAAO;IACvB,uGAAuG;IACvG,gBAAgB,EAAE,EAAE;IACpB,0GAA0G;IAC1G,OAAO,EAAE,GAAG;CACJ,CAAC;AAIX,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC;AAC/B,MAAM,UAAU,GAAG,CAAC,CAAS,EAAU,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;AAEhE,6EAA6E;AAC7E,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,KAAa,EAAU,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AAE3F,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,OAAO,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC,CAAC;AACrE,uFAAuF;AACvF,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE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,KAAK,EAAE,CAA+B,GAAW,EAAE,MAA4B,EAAO,EAAE;YACtF,qBAAqB,CAAC,GAAG,CAAC,CAAC;YAC3B,OAAO,KAAK,CAAC,KAAK,CAAI,GAAG,EAAE,MAAM,CAAC,CAAC;QACrC,CAAC;QACD,IAAI,EAAE,CAAC,GAAW,EAAE,MAA4B,EAAE,EAAE;YAClD,qBAAqB,CAAC,GAAG,CAAC,CAAC;YAC3B,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/storage-gauge.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ import type { RedactionSql } from './subject-redaction.js';
|
|
|
21
21
|
* failure digest. With it, a failing scope is tried once a day like any other, while its last
|
|
22
22
|
* good sample stands.
|
|
23
23
|
*/
|
|
24
|
-
export declare const SCOPE_STORAGE_DDL = "\n CREATE TABLE IF NOT EXISTS _substrat_scope_storage (\n scope_id TEXT NOT NULL,\n day TEXT NOT NULL,\n tenant_id TEXT NOT NULL,\n bytes INTEGER NOT NULL,\n read_at TEXT NOT NULL,\n PRIMARY KEY (scope_id, day)\n );\n CREATE INDEX IF NOT EXISTS _substrat_scope_storage_tenant ON _substrat_scope_storage (tenant_id, day);\n CREATE INDEX IF NOT EXISTS _substrat_scope_storage_day ON _substrat_scope_storage (day);\n CREATE TABLE IF NOT EXISTS _substrat_scope_storage_attempts (\n scope_id TEXT PRIMARY KEY,\n tenant_id TEXT NOT NULL,\n attempted_at TEXT NOT NULL,\n error TEXT\n );\n";
|
|
24
|
+
export declare const SCOPE_STORAGE_DDL = "\n CREATE TABLE IF NOT EXISTS _substrat_scope_storage (\n scope_id TEXT NOT NULL,\n day TEXT NOT NULL,\n tenant_id TEXT NOT NULL,\n bytes INTEGER NOT NULL,\n read_at TEXT NOT NULL,\n PRIMARY KEY (scope_id, day)\n );\n CREATE INDEX IF NOT EXISTS _substrat_scope_storage_tenant ON _substrat_scope_storage (tenant_id, day);\n CREATE INDEX IF NOT EXISTS _substrat_scope_storage_day ON _substrat_scope_storage (day);\n CREATE TABLE IF NOT EXISTS _substrat_scope_storage_attempts (\n scope_id TEXT PRIMARY KEY,\n tenant_id TEXT NOT NULL,\n attempted_at TEXT NOT NULL,\n error TEXT\n );\n CREATE TABLE IF NOT EXISTS _substrat_scope_store_storage (\n scope_id TEXT NOT NULL,\n binding TEXT NOT NULL,\n day TEXT NOT NULL,\n tenant_id TEXT NOT NULL,\n bytes INTEGER NOT NULL,\n read_at TEXT NOT NULL,\n PRIMARY KEY (scope_id, binding, day)\n );\n CREATE INDEX IF NOT EXISTS _substrat_scope_store_storage_tenant ON _substrat_scope_store_storage (tenant_id, day);\n";
|
|
25
25
|
/**
|
|
26
26
|
* The statuses a scope that holds a store can be in: every status but `provisioning` (no
|
|
27
27
|
* store yet) and `reaped` (its store is gone). A non-serving scope (suspended, archiving,
|
|
@@ -57,6 +57,14 @@ export interface ScopeStorageReadingInput {
|
|
|
57
57
|
error?: string;
|
|
58
58
|
/** When the read was made. Its UTC date is the sample's day. */
|
|
59
59
|
readAt: string;
|
|
60
|
+
/**
|
|
61
|
+
* Scope stores read in the same attempt (#2212). Present means this attempt measured
|
|
62
|
+
* them: an empty list replaces the day's store rows with nothing. Absent leaves them.
|
|
63
|
+
*/
|
|
64
|
+
stores?: readonly {
|
|
65
|
+
binding: string;
|
|
66
|
+
bytes: number;
|
|
67
|
+
}[];
|
|
60
68
|
}
|
|
61
69
|
/** When the phase last tried a scope (#1524), and why it failed if it did. */
|
|
62
70
|
export interface ScopeStorageAttempt {
|
|
@@ -105,8 +113,17 @@ export declare function listScopeStorageRows(sql: RedactionSql, filter?: ScopeSt
|
|
|
105
113
|
* what a meter reading names failing scopes from. `tenantId` narrows to one tenant.
|
|
106
114
|
*/
|
|
107
115
|
export declare function listScopeStorageAttemptRows(sql: RedactionSql, tenantId?: TenantId): ScopeStorageAttempt[];
|
|
108
|
-
/** Delete at most `limit` samples older than retention, oldest first. Returns how many went. */
|
|
116
|
+
/** Delete at most `limit` samples older than retention, oldest first, across both tables. Returns how many went. */
|
|
109
117
|
export declare function pruneScopeStorageRows(sql: RedactionSql, nowMs: number, limit: number): number;
|
|
118
|
+
/**
|
|
119
|
+
* Bindings on the latest day that measured stores for the scope. A binding absent that day has
|
|
120
|
+
* stopped, and a day that measured none leaves only its marker, which is not a binding.
|
|
121
|
+
*/
|
|
122
|
+
export declare function listScopeStoreStorageRows(sql: RedactionSql, tenantId?: TenantId): {
|
|
123
|
+
tenantId: TenantId;
|
|
124
|
+
bytes: number;
|
|
125
|
+
readAt: string;
|
|
126
|
+
}[];
|
|
110
127
|
/** Drop a scope's samples and attempt: its storage is gone, so its history describes nothing billable. */
|
|
111
128
|
export declare function forgetScopeStorage(sql: RedactionSql, scopeId: string): void;
|
|
112
129
|
/**
|
|
@@ -121,5 +138,7 @@ export declare function foldStorageGauge(samples: readonly {
|
|
|
121
138
|
}[], total: number, attempts?: readonly {
|
|
122
139
|
attemptedAt: string;
|
|
123
140
|
error: string | null;
|
|
141
|
+
}[], stores?: readonly {
|
|
142
|
+
bytes: number;
|
|
124
143
|
}[]): StorageGauge;
|
|
125
144
|
//# sourceMappingURL=storage-gauge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-gauge.d.ts","sourceRoot":"","sources":["../src/storage-gauge.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,QAAQ,EACd,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG3D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,iBAAiB,
|
|
1
|
+
{"version":3,"file":"storage-gauge.d.ts","sourceRoot":"","sources":["../src/storage-gauge.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,OAAO,EACZ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