@gaganref/confect-test 10.3.1-fork.91 → 10.3.1-fork.93
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/TestConfect.d.ts +26 -0
- package/dist/TestConfect.d.ts.map +1 -1
- package/dist/TestConfect.js +9 -1
- package/dist/TestConfect.js.map +1 -1
- package/dist/internal/Attempt.d.ts +14 -1
- package/dist/internal/Attempt.d.ts.map +1 -1
- package/dist/internal/Attempt.js +18 -1
- package/dist/internal/Attempt.js.map +1 -1
- package/dist/internal/ConvexTest.d.ts +26 -1
- package/dist/internal/ConvexTest.d.ts.map +1 -1
- package/dist/internal/ConvexTest.js +55 -27
- package/dist/internal/ConvexTest.js.map +1 -1
- package/dist/internal/Execution.d.ts +151 -1
- package/dist/internal/Execution.d.ts.map +1 -1
- package/dist/internal/Execution.js +731 -214
- package/dist/internal/Execution.js.map +1 -1
- package/dist/internal/KernelQuery.d.ts +8 -3
- package/dist/internal/KernelQuery.d.ts.map +1 -1
- package/dist/internal/KernelQuery.js +10 -3
- package/dist/internal/KernelQuery.js.map +1 -1
- package/dist/internal/KernelRefusal.d.ts +134 -0
- package/dist/internal/KernelRefusal.d.ts.map +1 -1
- package/dist/internal/KernelRefusal.js +134 -1
- package/dist/internal/KernelRefusal.js.map +1 -1
- package/dist/internal/Metering.d.ts +186 -0
- package/dist/internal/Metering.d.ts.map +1 -0
- package/dist/internal/Metering.js +401 -0
- package/dist/internal/Metering.js.map +1 -0
- package/dist/internal/Redaction.d.ts +142 -0
- package/dist/internal/Redaction.d.ts.map +1 -0
- package/dist/internal/Redaction.js +448 -0
- package/dist/internal/Redaction.js.map +1 -0
- package/dist/internal/Snapshot.d.ts +298 -0
- package/dist/internal/Snapshot.d.ts.map +1 -0
- package/dist/internal/Snapshot.js +532 -0
- package/dist/internal/Snapshot.js.map +1 -0
- package/dist/internal/Subscriptions.d.ts +13 -0
- package/dist/internal/Subscriptions.d.ts.map +1 -1
- package/dist/internal/Subscriptions.js +27 -3
- package/dist/internal/Subscriptions.js.map +1 -1
- package/package.json +3 -3
- package/src/TestConfect.ts +63 -4
- package/src/internal/Attempt.ts +24 -0
- package/src/internal/ConvexTest.ts +135 -38
- package/src/internal/Execution.ts +1141 -324
- package/src/internal/KernelQuery.ts +17 -6
- package/src/internal/KernelRefusal.ts +160 -0
- package/src/internal/Metering.ts +520 -0
- package/src/internal/Redaction.ts +730 -0
- package/src/internal/Snapshot.ts +945 -0
- package/src/internal/Subscriptions.ts +34 -4
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { TransactionMetrics } from "convex/server";
|
|
2
|
+
import { type Value } from "convex/values";
|
|
3
|
+
import * as Schema from "effect/Schema";
|
|
4
|
+
import type { SerializedRangeExpression } from "./KernelValues.js";
|
|
5
|
+
/**
|
|
6
|
+
* The ceilings one function execution runs under, the binary's
|
|
7
|
+
* `TransactionLimits` (`crates/database/src/execution_size.rs:62-95`).
|
|
8
|
+
*/
|
|
9
|
+
export type Limits = {
|
|
10
|
+
readonly [K in keyof TransactionMetrics]: number;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The binary's default ceilings (`crates/common/src/knobs.rs`).
|
|
14
|
+
*/
|
|
15
|
+
export declare const defaults: Limits;
|
|
16
|
+
/**
|
|
17
|
+
* What a nested call may use on top of what its transaction has used, as
|
|
18
|
+
* `ctx.runQuery` and `ctx.runMutation` take it in `transactionLimits`.
|
|
19
|
+
*/
|
|
20
|
+
export type Budget = Partial<Limits>;
|
|
21
|
+
/**
|
|
22
|
+
* A nested call's ceilings: each one what the transaction has used plus the
|
|
23
|
+
* call's budget, never above the caller's (`TransactionLimits::from_budget`,
|
|
24
|
+
* execution_size.rs:97-160). An unset field leaves the caller's ceiling.
|
|
25
|
+
*/
|
|
26
|
+
export declare const fromBudget: (budget: Budget, used: Limits, ceiling: Limits) => Limits;
|
|
27
|
+
declare const TransactionLimitExceeded_base: Schema.Class<TransactionLimitExceeded, Schema.TaggedStruct<"TransactionLimitExceeded", {
|
|
28
|
+
readonly code: Schema.Literals<readonly ["TooManyReads", "TooManyDocumentsRead", "TooManyBytesRead", "TooManyWrites", "TooManyBytesWritten", "TooManyFunctionsScheduled", "ScheduledFunctionsArgumentsTooLarge"]>;
|
|
29
|
+
readonly limit: Schema.Int;
|
|
30
|
+
readonly message: Schema.String;
|
|
31
|
+
}>, import("effect/Cause").YieldableError>;
|
|
32
|
+
/**
|
|
33
|
+
* A function execution crossed one of its ceilings. `code` is the binary's
|
|
34
|
+
* short message and `message` its text, which the function receives as a
|
|
35
|
+
* catchable error.
|
|
36
|
+
*/
|
|
37
|
+
export declare class TransactionLimitExceeded extends TransactionLimitExceeded_base {
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* `common::fmt::format_bytes` (`crates/common/src/fmt.rs:29-47`).
|
|
41
|
+
*/
|
|
42
|
+
export declare const formatBytes: (n: number) => string;
|
|
43
|
+
/**
|
|
44
|
+
* A position in an index's key space: just before, or just after, every key
|
|
45
|
+
* that starts with `key`.
|
|
46
|
+
*/
|
|
47
|
+
interface Bound {
|
|
48
|
+
readonly key: ReadonlyArray<Value | undefined>;
|
|
49
|
+
readonly side: -1 | 1;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The keys from `start` up to `end`.
|
|
53
|
+
*/
|
|
54
|
+
export interface KeyInterval {
|
|
55
|
+
readonly start: Bound;
|
|
56
|
+
readonly end: Bound;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The one key `key`, as a read or write of a document by ID records it.
|
|
60
|
+
*/
|
|
61
|
+
export declare const point: (key: ReadonlyArray<Value | undefined>) => KeyInterval;
|
|
62
|
+
/**
|
|
63
|
+
* Every key of an index.
|
|
64
|
+
*/
|
|
65
|
+
export declare const everything: KeyInterval;
|
|
66
|
+
/**
|
|
67
|
+
* The part of an index range a query has examined: from where it starts, past
|
|
68
|
+
* the cursor `after`, through `through` in its order. `null` when it has
|
|
69
|
+
* examined nothing.
|
|
70
|
+
*/
|
|
71
|
+
export declare const examined: (range: ReadonlyArray<SerializedRangeExpression>, order: "asc" | "desc", after: ReadonlyArray<Value | undefined> | null, through: ReadonlyArray<Value | undefined> | "end") => KeyInterval | null;
|
|
72
|
+
/**
|
|
73
|
+
* The intervals read from one index, overlapping and adjacent ones merged
|
|
74
|
+
* (`IntervalSet::add`, `crates/common/src/interval/interval_set.rs:150-230`).
|
|
75
|
+
* They stay sorted and disjoint, so an add touches only its neighbours.
|
|
76
|
+
*/
|
|
77
|
+
declare class IntervalSet {
|
|
78
|
+
private readonly intervals;
|
|
79
|
+
get size(): number;
|
|
80
|
+
add(interval: KeyInterval): void;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The counters every frame of one attempt shares: reads and schedules stay when
|
|
84
|
+
* a nested mutation fails, as the binary keeps them outside its subtransaction
|
|
85
|
+
* token (`crates/database/src/transaction.rs:418-454`).
|
|
86
|
+
*/
|
|
87
|
+
declare class Shared {
|
|
88
|
+
readonly indexes: Map<string, IntervalSet>;
|
|
89
|
+
intervals: number;
|
|
90
|
+
documentsRead: number;
|
|
91
|
+
bytesRead: number;
|
|
92
|
+
functionsScheduled: number;
|
|
93
|
+
scheduledFunctionArgsBytes: number;
|
|
94
|
+
readonly filesRead = 0;
|
|
95
|
+
readonly fileReadBytes = 0;
|
|
96
|
+
/**
|
|
97
|
+
* A stale-snapshot query's counters: the scheduling and file-read counters
|
|
98
|
+
* carried over, reads and intervals from zero (`clone_for_snapshot_query`,
|
|
99
|
+
* `crates/database/src/transaction.rs:1460-1485`).
|
|
100
|
+
*/
|
|
101
|
+
forStaleSnapshot(): Shared;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* One frame's share of an attempt's accounting. The outermost frame belongs to
|
|
105
|
+
* the top-level function and each nested mutation gets a child. A child's
|
|
106
|
+
* writes count toward its caller's once it merges and are forgotten when it
|
|
107
|
+
* fails, as the binary's nested write set rolls its sizes back
|
|
108
|
+
* (`crates/database/src/writes.rs:96-136`).
|
|
109
|
+
*/
|
|
110
|
+
export declare class Meter {
|
|
111
|
+
private readonly shared;
|
|
112
|
+
private readonly parent?;
|
|
113
|
+
private documentsWritten;
|
|
114
|
+
private bytesWritten;
|
|
115
|
+
private readonly filesWritten;
|
|
116
|
+
private readonly fileWriteBytes;
|
|
117
|
+
constructor(shared?: Shared, parent?: Meter | undefined);
|
|
118
|
+
child(): Meter;
|
|
119
|
+
/**
|
|
120
|
+
* The meter of a query run on a stale snapshot. The binary runs it on a clone
|
|
121
|
+
* of the transaction that keeps the scheduling counters and starts reads and
|
|
122
|
+
* writes from zero, then drops the clone, so nothing it counts reaches this
|
|
123
|
+
* meter (`clone_for_snapshot_query`,
|
|
124
|
+
* `crates/database/src/transaction.rs:1460-1485`; `run_udf`,
|
|
125
|
+
* `crates/isolate/src/environment/udf/async_syscall.rs:695-776`).
|
|
126
|
+
*/
|
|
127
|
+
forStaleSnapshot(): Meter;
|
|
128
|
+
/**
|
|
129
|
+
* The child's writes become its caller's.
|
|
130
|
+
*/
|
|
131
|
+
merge(): void;
|
|
132
|
+
private chain;
|
|
133
|
+
/**
|
|
134
|
+
* How much of each limit the execution has used.
|
|
135
|
+
*/
|
|
136
|
+
used(): Limits;
|
|
137
|
+
/**
|
|
138
|
+
* What `getTransactionMetrics` answers (`tx_metrics`,
|
|
139
|
+
* `crates/isolate/src/environment/udf/async_syscall.rs:947-993`).
|
|
140
|
+
*/
|
|
141
|
+
metrics(limits: Limits): TransactionMetrics;
|
|
142
|
+
private set;
|
|
143
|
+
/**
|
|
144
|
+
* A read the function made of `interval` in `index`, counted as the binary
|
|
145
|
+
* counts it: the total drops by the index's interval count before the read,
|
|
146
|
+
* saturating at zero, and rises by its count after
|
|
147
|
+
* (`record_indexed_directly`, `crates/database/src/reads.rs:447-480`). The
|
|
148
|
+
* index's count includes the intervals of IDs this execution inserted, which
|
|
149
|
+
* joined it without counting (`deriveInterval`), so a read that covers them
|
|
150
|
+
* can move the total by more than the read itself. The binary starts the
|
|
151
|
+
* total at the system-table intervals it reads to run the function, which the
|
|
152
|
+
* kernel does not simulate. While neither total saturates they differ by
|
|
153
|
+
* exactly that share. A read that saturates only the kernel's lower total
|
|
154
|
+
* narrows the gap, and it never widens or turns negative (see the
|
|
155
|
+
* `SystemTableReadIntervals` boundary).
|
|
156
|
+
*/
|
|
157
|
+
readInterval(index: string, interval: KeyInterval, limits: Limits): TransactionLimitExceeded | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* A read the binary takes for a write rather than for the function: a new
|
|
160
|
+
* document's ID (`register_new_id`, writes.rs:426-441). It joins the index's
|
|
161
|
+
* intervals and leaves the total as it was (`record_indexed_derived` calls
|
|
162
|
+
* `_record_indexed` and ignores its counts, reads.rs:333-344), so a later
|
|
163
|
+
* read of that index starts from a count that includes it.
|
|
164
|
+
*/
|
|
165
|
+
deriveInterval(index: string, interval: KeyInterval): void;
|
|
166
|
+
/**
|
|
167
|
+
* A document the function read. A system table's document counts toward no
|
|
168
|
+
* limit (`record_read_document`, reads.rs:365-445).
|
|
169
|
+
*/
|
|
170
|
+
readDocument(document: Value, system: boolean, limits: Limits): TransactionLimitExceeded | undefined;
|
|
171
|
+
/**
|
|
172
|
+
* A write to a user table: the new document, or `null` for a delete. Each
|
|
173
|
+
* write counts, even to a document this execution already wrote
|
|
174
|
+
* (`Writes::update`, writes.rs:241-310).
|
|
175
|
+
*/
|
|
176
|
+
write(document: Value | null, limits: Limits): TransactionLimitExceeded | undefined;
|
|
177
|
+
/**
|
|
178
|
+
* A function scheduled with `args`. The binary checks before it counts, so a
|
|
179
|
+
* refused schedule counts nothing (`check_scheduling_limits`,
|
|
180
|
+
* `crates/model/src/scheduled_jobs/mod.rs:162-196`). Its arguments are sized
|
|
181
|
+
* as the one-element array the scheduler stores.
|
|
182
|
+
*/
|
|
183
|
+
schedule(args: Value, limits: Limits): TransactionLimitExceeded | undefined;
|
|
184
|
+
}
|
|
185
|
+
export {};
|
|
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CAkBb;IAED;;;OAGG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,kBAAkB,CAQ1C;IAED,OAAO,CAAC,GAAG;IAMX;;;;;;;;;;;;;OAaG;IACH,YAAY,CACV,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,WAAW,EACrB,MAAM,EAAE,MAAM,GACb,wBAAwB,GAAG,SAAS,CAmBtC;IAED;;;;;;OAMG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,QAElD;IAED;;;OAGG;IACH,YAAY,CACV,QAAQ,EAAE,KAAK,EACf,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,GACb,wBAAwB,GAAG,SAAS,CAoBtC;IAED;;;;OAIG;IACH,KAAK,CACH,QAAQ,EAAE,KAAK,GAAG,IAAI,EACtB,MAAM,EAAE,MAAM,GACb,wBAAwB,GAAG,SAAS,CAmBtC;IAED;;;;;OAKG;IACH,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,wBAAwB,GAAG,SAAS,CAuB1E;CACF"}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
import { evaluateQueryValue } from "./KernelValues.js";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import { compareValues, getConvexSize } from "convex/values";
|
|
4
|
+
//#region src/internal/Metering.ts
|
|
5
|
+
/**
|
|
6
|
+
* The binary's default ceilings (`crates/common/src/knobs.rs`).
|
|
7
|
+
*/
|
|
8
|
+
const defaults = {
|
|
9
|
+
bytesRead: 1 << 24,
|
|
10
|
+
documentsRead: 32e3,
|
|
11
|
+
databaseQueries: 4096,
|
|
12
|
+
documentsWritten: 16e3,
|
|
13
|
+
bytesWritten: 1 << 24,
|
|
14
|
+
functionsScheduled: 1e3,
|
|
15
|
+
scheduledFunctionArgsBytes: 1 << 24,
|
|
16
|
+
filesWritten: 10,
|
|
17
|
+
fileWriteBytes: 1 << 24,
|
|
18
|
+
filesRead: 10,
|
|
19
|
+
fileReadBytes: 1 << 24
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A nested call's ceilings: each one what the transaction has used plus the
|
|
23
|
+
* call's budget, never above the caller's (`TransactionLimits::from_budget`,
|
|
24
|
+
* execution_size.rs:97-160). An unset field leaves the caller's ceiling.
|
|
25
|
+
*/
|
|
26
|
+
const fromBudget = (budget, used, ceiling) => Object.fromEntries(Object.keys(ceiling).map((metric) => [metric, Math.min(used[metric] + (budget[metric] ?? ceiling[metric]), ceiling[metric])]));
|
|
27
|
+
const overLimitHelp = "Consider using smaller limits in your queries, paginating your queries, or using indexed queries with a selective index range expressions.";
|
|
28
|
+
/**
|
|
29
|
+
* A function execution crossed one of its ceilings. `code` is the binary's
|
|
30
|
+
* short message and `message` its text, which the function receives as a
|
|
31
|
+
* catchable error.
|
|
32
|
+
*/
|
|
33
|
+
var TransactionLimitExceeded = class extends Schema.TaggedError()("TransactionLimitExceeded", {
|
|
34
|
+
code: Schema.Literals([
|
|
35
|
+
"TooManyReads",
|
|
36
|
+
"TooManyDocumentsRead",
|
|
37
|
+
"TooManyBytesRead",
|
|
38
|
+
"TooManyWrites",
|
|
39
|
+
"TooManyBytesWritten",
|
|
40
|
+
"TooManyFunctionsScheduled",
|
|
41
|
+
"ScheduledFunctionsArgumentsTooLarge"
|
|
42
|
+
]),
|
|
43
|
+
limit: Schema.Int,
|
|
44
|
+
message: Schema.String
|
|
45
|
+
}) {};
|
|
46
|
+
const byteUnits = [
|
|
47
|
+
[2 ** 30, "GiB"],
|
|
48
|
+
[1e9, "GB"],
|
|
49
|
+
[2 ** 20, "MiB"],
|
|
50
|
+
[1e6, "MB"],
|
|
51
|
+
[1024, "KiB"],
|
|
52
|
+
[1e3, "KB"]
|
|
53
|
+
];
|
|
54
|
+
/**
|
|
55
|
+
* `common::fmt::format_bytes` (`crates/common/src/fmt.rs:29-47`).
|
|
56
|
+
*/
|
|
57
|
+
const formatBytes = (n) => {
|
|
58
|
+
if (n === 0) return "0 bytes";
|
|
59
|
+
for (const [unit, name] of byteUnits) {
|
|
60
|
+
if (n < unit) continue;
|
|
61
|
+
if (n % unit === 0) return `${n / unit} ${name}`;
|
|
62
|
+
if (n * 10 % unit === 0) return `${Math.floor(n / unit)}.${Math.floor(n * 10 / unit) % 10} ${name}`;
|
|
63
|
+
}
|
|
64
|
+
return `${n} bytes`;
|
|
65
|
+
};
|
|
66
|
+
const compareBounds = (a, b) => {
|
|
67
|
+
const shared = Math.min(a.key.length, b.key.length);
|
|
68
|
+
for (let i = 0; i < shared; i++) {
|
|
69
|
+
const cmp = compareValues(a.key[i], b.key[i]);
|
|
70
|
+
if (cmp !== 0) return cmp;
|
|
71
|
+
}
|
|
72
|
+
if (a.key.length === b.key.length) return a.side - b.side;
|
|
73
|
+
return a.key.length < b.key.length ? a.side : -b.side;
|
|
74
|
+
};
|
|
75
|
+
const maxBound = (a, b) => compareBounds(a, b) >= 0 ? a : b;
|
|
76
|
+
const minBound = (a, b) => compareBounds(a, b) <= 0 ? a : b;
|
|
77
|
+
/**
|
|
78
|
+
* The one key `key`, as a read or write of a document by ID records it.
|
|
79
|
+
*/
|
|
80
|
+
const point = (key) => ({
|
|
81
|
+
start: {
|
|
82
|
+
key,
|
|
83
|
+
side: -1
|
|
84
|
+
},
|
|
85
|
+
end: {
|
|
86
|
+
key,
|
|
87
|
+
side: 1
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
/**
|
|
91
|
+
* Every key of an index.
|
|
92
|
+
*/
|
|
93
|
+
const everything = point([]);
|
|
94
|
+
/**
|
|
95
|
+
* The part of an index range a query has examined: from where it starts, past
|
|
96
|
+
* the cursor `after`, through `through` in its order. `null` when it has
|
|
97
|
+
* examined nothing.
|
|
98
|
+
*/
|
|
99
|
+
const examined = (range, order, after, through) => {
|
|
100
|
+
const equal = [];
|
|
101
|
+
let start;
|
|
102
|
+
let end;
|
|
103
|
+
for (const expression of range) {
|
|
104
|
+
const value = evaluateQueryValue(expression.value);
|
|
105
|
+
switch (expression.type) {
|
|
106
|
+
case "Eq":
|
|
107
|
+
equal.push(value);
|
|
108
|
+
break;
|
|
109
|
+
case "Gt":
|
|
110
|
+
case "Gte":
|
|
111
|
+
start = {
|
|
112
|
+
key: [...equal, value],
|
|
113
|
+
side: expression.type === "Gt" ? 1 : -1
|
|
114
|
+
};
|
|
115
|
+
break;
|
|
116
|
+
case "Lt":
|
|
117
|
+
case "Lte": end = {
|
|
118
|
+
key: [...equal, value],
|
|
119
|
+
side: expression.type === "Lt" ? -1 : 1
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
start ??= {
|
|
124
|
+
key: equal,
|
|
125
|
+
side: -1
|
|
126
|
+
};
|
|
127
|
+
end ??= {
|
|
128
|
+
key: equal,
|
|
129
|
+
side: 1
|
|
130
|
+
};
|
|
131
|
+
if (after !== null) {
|
|
132
|
+
if (order === "asc") start = maxBound(start, {
|
|
133
|
+
key: after,
|
|
134
|
+
side: 1
|
|
135
|
+
});
|
|
136
|
+
else end = minBound(end, {
|
|
137
|
+
key: after,
|
|
138
|
+
side: -1
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
if (through !== "end") {
|
|
142
|
+
if (order === "asc") end = minBound(end, {
|
|
143
|
+
key: through,
|
|
144
|
+
side: 1
|
|
145
|
+
});
|
|
146
|
+
else start = maxBound(start, {
|
|
147
|
+
key: through,
|
|
148
|
+
side: -1
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
return compareBounds(start, end) < 0 ? {
|
|
152
|
+
start,
|
|
153
|
+
end
|
|
154
|
+
} : null;
|
|
155
|
+
};
|
|
156
|
+
/**
|
|
157
|
+
* The intervals read from one index, overlapping and adjacent ones merged
|
|
158
|
+
* (`IntervalSet::add`, `crates/common/src/interval/interval_set.rs:150-230`).
|
|
159
|
+
* They stay sorted and disjoint, so an add touches only its neighbours.
|
|
160
|
+
*/
|
|
161
|
+
var IntervalSet = class {
|
|
162
|
+
intervals = [];
|
|
163
|
+
get size() {
|
|
164
|
+
return this.intervals.length;
|
|
165
|
+
}
|
|
166
|
+
add(interval) {
|
|
167
|
+
const intervals = this.intervals;
|
|
168
|
+
let low = 0;
|
|
169
|
+
let high = intervals.length;
|
|
170
|
+
while (low < high) {
|
|
171
|
+
const middle = low + high >> 1;
|
|
172
|
+
if (compareBounds(intervals[middle].end, interval.start) < 0) low = middle + 1;
|
|
173
|
+
else high = middle;
|
|
174
|
+
}
|
|
175
|
+
let last = low;
|
|
176
|
+
let merged = interval;
|
|
177
|
+
while (last < intervals.length && compareBounds(intervals[last].start, interval.end) <= 0) {
|
|
178
|
+
const other = intervals[last];
|
|
179
|
+
merged = {
|
|
180
|
+
start: minBound(merged.start, other.start),
|
|
181
|
+
end: maxBound(merged.end, other.end)
|
|
182
|
+
};
|
|
183
|
+
last++;
|
|
184
|
+
}
|
|
185
|
+
intervals.splice(low, last - low, merged);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
/**
|
|
189
|
+
* The counters every frame of one attempt shares: reads and schedules stay when
|
|
190
|
+
* a nested mutation fails, as the binary keeps them outside its subtransaction
|
|
191
|
+
* token (`crates/database/src/transaction.rs:418-454`).
|
|
192
|
+
*/
|
|
193
|
+
var Shared = class Shared {
|
|
194
|
+
indexes = /* @__PURE__ */ new Map();
|
|
195
|
+
intervals = 0;
|
|
196
|
+
documentsRead = 0;
|
|
197
|
+
bytesRead = 0;
|
|
198
|
+
functionsScheduled = 0;
|
|
199
|
+
scheduledFunctionArgsBytes = 0;
|
|
200
|
+
filesRead = 0;
|
|
201
|
+
fileReadBytes = 0;
|
|
202
|
+
/**
|
|
203
|
+
* A stale-snapshot query's counters: the scheduling and file-read counters
|
|
204
|
+
* carried over, reads and intervals from zero (`clone_for_snapshot_query`,
|
|
205
|
+
* `crates/database/src/transaction.rs:1460-1485`).
|
|
206
|
+
*/
|
|
207
|
+
forStaleSnapshot() {
|
|
208
|
+
const copy = new Shared();
|
|
209
|
+
copy.functionsScheduled = this.functionsScheduled;
|
|
210
|
+
copy.scheduledFunctionArgsBytes = this.scheduledFunctionArgsBytes;
|
|
211
|
+
return copy;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* `a - b`, or 0 when `b` is larger: Rust's `usize::saturating_sub`.
|
|
216
|
+
*/
|
|
217
|
+
const saturatingSub = (a, b) => a > b ? a - b : 0;
|
|
218
|
+
/**
|
|
219
|
+
* One frame's share of an attempt's accounting. The outermost frame belongs to
|
|
220
|
+
* the top-level function and each nested mutation gets a child. A child's
|
|
221
|
+
* writes count toward its caller's once it merges and are forgotten when it
|
|
222
|
+
* fails, as the binary's nested write set rolls its sizes back
|
|
223
|
+
* (`crates/database/src/writes.rs:96-136`).
|
|
224
|
+
*/
|
|
225
|
+
var Meter = class Meter {
|
|
226
|
+
shared;
|
|
227
|
+
parent;
|
|
228
|
+
documentsWritten = 0;
|
|
229
|
+
bytesWritten = 0;
|
|
230
|
+
filesWritten = 0;
|
|
231
|
+
fileWriteBytes = 0;
|
|
232
|
+
constructor(shared = new Shared(), parent) {
|
|
233
|
+
this.shared = shared;
|
|
234
|
+
this.parent = parent;
|
|
235
|
+
}
|
|
236
|
+
child() {
|
|
237
|
+
return new Meter(this.shared, this);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* The meter of a query run on a stale snapshot. The binary runs it on a clone
|
|
241
|
+
* of the transaction that keeps the scheduling counters and starts reads and
|
|
242
|
+
* writes from zero, then drops the clone, so nothing it counts reaches this
|
|
243
|
+
* meter (`clone_for_snapshot_query`,
|
|
244
|
+
* `crates/database/src/transaction.rs:1460-1485`; `run_udf`,
|
|
245
|
+
* `crates/isolate/src/environment/udf/async_syscall.rs:695-776`).
|
|
246
|
+
*/
|
|
247
|
+
forStaleSnapshot() {
|
|
248
|
+
return new Meter(this.shared.forStaleSnapshot());
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* The child's writes become its caller's.
|
|
252
|
+
*/
|
|
253
|
+
merge() {
|
|
254
|
+
if (this.parent === void 0) throw new Error("The outermost meter of an attempt has no caller.");
|
|
255
|
+
this.parent.documentsWritten += this.documentsWritten;
|
|
256
|
+
this.parent.bytesWritten += this.bytesWritten;
|
|
257
|
+
}
|
|
258
|
+
chain() {
|
|
259
|
+
return this.parent === void 0 ? [this] : [...this.parent.chain(), this];
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* How much of each limit the execution has used.
|
|
263
|
+
*/
|
|
264
|
+
used() {
|
|
265
|
+
const frames = this.chain();
|
|
266
|
+
const sum = (of) => frames.reduce((total, meter) => total + of(meter), 0);
|
|
267
|
+
const shared = this.shared;
|
|
268
|
+
return {
|
|
269
|
+
bytesRead: shared.bytesRead,
|
|
270
|
+
documentsRead: shared.documentsRead,
|
|
271
|
+
databaseQueries: shared.intervals,
|
|
272
|
+
documentsWritten: sum((meter) => meter.documentsWritten),
|
|
273
|
+
bytesWritten: sum((meter) => meter.bytesWritten),
|
|
274
|
+
functionsScheduled: shared.functionsScheduled,
|
|
275
|
+
scheduledFunctionArgsBytes: shared.scheduledFunctionArgsBytes,
|
|
276
|
+
filesWritten: sum((meter) => meter.filesWritten),
|
|
277
|
+
fileWriteBytes: sum((meter) => meter.fileWriteBytes),
|
|
278
|
+
filesRead: shared.filesRead,
|
|
279
|
+
fileReadBytes: shared.fileReadBytes
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* What `getTransactionMetrics` answers (`tx_metrics`,
|
|
284
|
+
* `crates/isolate/src/environment/udf/async_syscall.rs:947-993`).
|
|
285
|
+
*/
|
|
286
|
+
metrics(limits) {
|
|
287
|
+
const used = this.used();
|
|
288
|
+
return Object.fromEntries(Object.keys(limits).map((metric) => [metric, {
|
|
289
|
+
used: used[metric],
|
|
290
|
+
remaining: limits[metric] - used[metric]
|
|
291
|
+
}]));
|
|
292
|
+
}
|
|
293
|
+
set(index) {
|
|
294
|
+
const set = this.shared.indexes.get(index) ?? new IntervalSet();
|
|
295
|
+
this.shared.indexes.set(index, set);
|
|
296
|
+
return set;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* A read the function made of `interval` in `index`, counted as the binary
|
|
300
|
+
* counts it: the total drops by the index's interval count before the read,
|
|
301
|
+
* saturating at zero, and rises by its count after
|
|
302
|
+
* (`record_indexed_directly`, `crates/database/src/reads.rs:447-480`). The
|
|
303
|
+
* index's count includes the intervals of IDs this execution inserted, which
|
|
304
|
+
* joined it without counting (`deriveInterval`), so a read that covers them
|
|
305
|
+
* can move the total by more than the read itself. The binary starts the
|
|
306
|
+
* total at the system-table intervals it reads to run the function, which the
|
|
307
|
+
* kernel does not simulate. While neither total saturates they differ by
|
|
308
|
+
* exactly that share. A read that saturates only the kernel's lower total
|
|
309
|
+
* narrows the gap, and it never widens or turns negative (see the
|
|
310
|
+
* `SystemTableReadIntervals` boundary).
|
|
311
|
+
*/
|
|
312
|
+
readInterval(index, interval, limits) {
|
|
313
|
+
const set = this.set(index);
|
|
314
|
+
const before = set.size;
|
|
315
|
+
set.add(interval);
|
|
316
|
+
const shared = this.shared;
|
|
317
|
+
shared.intervals = saturatingSub(shared.intervals, before) + set.size;
|
|
318
|
+
if (!Number.isSafeInteger(shared.intervals) || shared.intervals < 0) throw new Error(`The kernel counted ${shared.intervals} intervals read, which is no count.`);
|
|
319
|
+
return shared.intervals > limits.databaseQueries ? new TransactionLimitExceeded({
|
|
320
|
+
code: "TooManyReads",
|
|
321
|
+
limit: limits.databaseQueries,
|
|
322
|
+
message: `Too many reads in a single function execution (limit: ${limits.databaseQueries}). ${overLimitHelp}`
|
|
323
|
+
}) : void 0;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* A read the binary takes for a write rather than for the function: a new
|
|
327
|
+
* document's ID (`register_new_id`, writes.rs:426-441). It joins the index's
|
|
328
|
+
* intervals and leaves the total as it was (`record_indexed_derived` calls
|
|
329
|
+
* `_record_indexed` and ignores its counts, reads.rs:333-344), so a later
|
|
330
|
+
* read of that index starts from a count that includes it.
|
|
331
|
+
*/
|
|
332
|
+
deriveInterval(index, interval) {
|
|
333
|
+
this.set(index).add(interval);
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* A document the function read. A system table's document counts toward no
|
|
337
|
+
* limit (`record_read_document`, reads.rs:365-445).
|
|
338
|
+
*/
|
|
339
|
+
readDocument(document, system, limits) {
|
|
340
|
+
if (system) return void 0;
|
|
341
|
+
const shared = this.shared;
|
|
342
|
+
shared.documentsRead += 1;
|
|
343
|
+
shared.bytesRead += getConvexSize(document);
|
|
344
|
+
if (shared.documentsRead > limits.documentsRead) return new TransactionLimitExceeded({
|
|
345
|
+
code: "TooManyDocumentsRead",
|
|
346
|
+
limit: limits.documentsRead,
|
|
347
|
+
message: `Too many documents read in a single function execution (limit: ${limits.documentsRead}). ${overLimitHelp}`
|
|
348
|
+
});
|
|
349
|
+
if (shared.bytesRead > limits.bytesRead) return new TransactionLimitExceeded({
|
|
350
|
+
code: "TooManyBytesRead",
|
|
351
|
+
limit: limits.bytesRead,
|
|
352
|
+
message: `Too many bytes read in a single function execution (limit: ${limits.bytesRead} bytes). ${overLimitHelp}`
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* A write to a user table: the new document, or `null` for a delete. Each
|
|
357
|
+
* write counts, even to a document this execution already wrote
|
|
358
|
+
* (`Writes::update`, writes.rs:241-310).
|
|
359
|
+
*/
|
|
360
|
+
write(document, limits) {
|
|
361
|
+
this.documentsWritten += 1;
|
|
362
|
+
this.bytesWritten += document === null ? 0 : getConvexSize(document);
|
|
363
|
+
const used = this.used();
|
|
364
|
+
if (used.documentsWritten > limits.documentsWritten) return new TransactionLimitExceeded({
|
|
365
|
+
code: "TooManyWrites",
|
|
366
|
+
limit: limits.documentsWritten,
|
|
367
|
+
message: `Too many writes in a single function execution (limit: ${limits.documentsWritten})`
|
|
368
|
+
});
|
|
369
|
+
if (used.bytesWritten > limits.bytesWritten) return new TransactionLimitExceeded({
|
|
370
|
+
code: "TooManyBytesWritten",
|
|
371
|
+
limit: limits.bytesWritten,
|
|
372
|
+
message: `Too many bytes written in a single function execution (limit: ${formatBytes(limits.bytesWritten)})`
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
/**
|
|
376
|
+
* A function scheduled with `args`. The binary checks before it counts, so a
|
|
377
|
+
* refused schedule counts nothing (`check_scheduling_limits`,
|
|
378
|
+
* `crates/model/src/scheduled_jobs/mod.rs:162-196`). Its arguments are sized
|
|
379
|
+
* as the one-element array the scheduler stores.
|
|
380
|
+
*/
|
|
381
|
+
schedule(args, limits) {
|
|
382
|
+
const shared = this.shared;
|
|
383
|
+
const size = getConvexSize([args]);
|
|
384
|
+
if (shared.functionsScheduled >= limits.functionsScheduled) return new TransactionLimitExceeded({
|
|
385
|
+
code: "TooManyFunctionsScheduled",
|
|
386
|
+
limit: limits.functionsScheduled,
|
|
387
|
+
message: `Too many functions scheduled by this mutation (limit: ${limits.functionsScheduled})`
|
|
388
|
+
});
|
|
389
|
+
if (shared.scheduledFunctionArgsBytes + size > limits.scheduledFunctionArgsBytes) return new TransactionLimitExceeded({
|
|
390
|
+
code: "ScheduledFunctionsArgumentsTooLarge",
|
|
391
|
+
limit: limits.scheduledFunctionArgsBytes,
|
|
392
|
+
message: `Too large total size of the arguments of scheduled functions from this mutation (limit: ${limits.scheduledFunctionArgsBytes} bytes)`
|
|
393
|
+
});
|
|
394
|
+
shared.functionsScheduled += 1;
|
|
395
|
+
shared.scheduledFunctionArgsBytes += size;
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
//#endregion
|
|
399
|
+
export { Meter, TransactionLimitExceeded, defaults, everything, examined, formatBytes, fromBudget, point };
|
|
400
|
+
|
|
401
|
+
//# sourceMappingURL=Metering.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Metering.js","names":[],"sources":["../../src/internal/Metering.ts"],"sourcesContent":["// The limits, counters and messages are convex-backend's, read at the commit\n// the fork's local backend runs (`precompiled-2026-10-28-cccbade`). Paths below\n// are in that repository.\n\nimport type { TransactionMetrics } from \"convex/server\";\nimport { compareValues, getConvexSize, type Value } from \"convex/values\";\nimport * as Schema from \"effect/Schema\";\nimport type { SerializedRangeExpression } from \"./KernelValues.js\";\nimport { evaluateQueryValue } from \"./KernelValues.js\";\n\n/**\n * The ceilings one function execution runs under, the binary's\n * `TransactionLimits` (`crates/database/src/execution_size.rs:62-95`).\n */\nexport type Limits = { readonly [K in keyof TransactionMetrics]: number };\n\n/**\n * The binary's default ceilings (`crates/common/src/knobs.rs`).\n */\nexport const defaults: Limits = {\n // `TRANSACTION_MAX_READ_SIZE_BYTES`, knobs.rs:645-647.\n bytesRead: 1 << 24,\n // `TRANSACTION_MAX_READ_SIZE_ROWS`, knobs.rs:641-642.\n documentsRead: 32000,\n // `TRANSACTION_MAX_READ_SET_INTERVALS`, knobs.rs:657-658.\n databaseQueries: 4096,\n // `TRANSACTION_MAX_NUM_USER_WRITES`, knobs.rs:406-407.\n documentsWritten: 16000,\n // `TRANSACTION_MAX_USER_WRITE_SIZE_BYTES`, knobs.rs:410-412.\n bytesWritten: 1 << 24,\n // `TRANSACTION_MAX_NUM_SCHEDULED`, knobs.rs:514-515.\n functionsScheduled: 1000,\n // `TRANSACTION_MAX_SCHEDULED_TOTAL_ARGUMENT_SIZE_BYTES`, knobs.rs:530-536.\n scheduledFunctionArgsBytes: 1 << 24,\n // `TRANSACTION_MAX_NUM_FILES_WRITTEN`, knobs.rs:539-540.\n filesWritten: 10,\n // `TRANSACTION_MAX_FILE_WRITE_SIZE_BYTES`, knobs.rs:544-546.\n fileWriteBytes: 1 << 24,\n // `TRANSACTION_MAX_NUM_FILES_READ`, knobs.rs:549-550.\n filesRead: 10,\n // `TRANSACTION_MAX_FILE_READ_SIZE_BYTES`, knobs.rs:554-556.\n fileReadBytes: 1 << 24,\n};\n\n/**\n * What a nested call may use on top of what its transaction has used, as\n * `ctx.runQuery` and `ctx.runMutation` take it in `transactionLimits`.\n */\nexport type Budget = Partial<Limits>;\n\n/**\n * A nested call's ceilings: each one what the transaction has used plus the\n * call's budget, never above the caller's (`TransactionLimits::from_budget`,\n * execution_size.rs:97-160). An unset field leaves the caller's ceiling.\n */\nexport const fromBudget = (\n budget: Budget,\n used: Limits,\n ceiling: Limits,\n): Limits =>\n Object.fromEntries(\n (Object.keys(ceiling) as Array<keyof Limits>).map((metric) => [\n metric,\n Math.min(\n used[metric] + (budget[metric] ?? ceiling[metric]),\n ceiling[metric],\n ),\n ]),\n ) as unknown as Limits;\n\nconst overLimitHelp =\n \"Consider using smaller limits in your queries, paginating your queries, or using indexed queries with a selective index range expressions.\";\n\n/**\n * A function execution crossed one of its ceilings. `code` is the binary's\n * short message and `message` its text, which the function receives as a\n * catchable error.\n */\nexport class TransactionLimitExceeded extends Schema.TaggedError<TransactionLimitExceeded>()(\n \"TransactionLimitExceeded\",\n {\n code: Schema.Literals([\n \"TooManyReads\",\n \"TooManyDocumentsRead\",\n \"TooManyBytesRead\",\n \"TooManyWrites\",\n \"TooManyBytesWritten\",\n \"TooManyFunctionsScheduled\",\n \"ScheduledFunctionsArgumentsTooLarge\",\n ]),\n limit: Schema.Int,\n message: Schema.String,\n },\n) {}\n\nconst byteUnits: ReadonlyArray<readonly [number, string]> = [\n [2 ** 30, \"GiB\"],\n [1_000_000_000, \"GB\"],\n [2 ** 20, \"MiB\"],\n [1_000_000, \"MB\"],\n [2 ** 10, \"KiB\"],\n [1_000, \"KB\"],\n];\n\n/**\n * `common::fmt::format_bytes` (`crates/common/src/fmt.rs:29-47`).\n */\nexport const formatBytes = (n: number): string => {\n if (n === 0) return \"0 bytes\";\n for (const [unit, name] of byteUnits) {\n if (n < unit) continue;\n if (n % unit === 0) return `${n / unit} ${name}`;\n if ((n * 10) % unit === 0) {\n return `${Math.floor(n / unit)}.${Math.floor((n * 10) / unit) % 10} ${name}`;\n }\n }\n return `${n} bytes`;\n};\n\n/**\n * A position in an index's key space: just before, or just after, every key\n * that starts with `key`.\n */\ninterface Bound {\n readonly key: ReadonlyArray<Value | undefined>;\n readonly side: -1 | 1;\n}\n\n/**\n * The keys from `start` up to `end`.\n */\nexport interface KeyInterval {\n readonly start: Bound;\n readonly end: Bound;\n}\n\nconst compareBounds = (a: Bound, b: Bound): number => {\n const shared = Math.min(a.key.length, b.key.length);\n for (let i = 0; i < shared; i++) {\n const cmp = compareValues(a.key[i] as Value, b.key[i] as Value);\n if (cmp !== 0) return cmp;\n }\n if (a.key.length === b.key.length) return a.side - b.side;\n return a.key.length < b.key.length ? a.side : -b.side;\n};\n\nconst maxBound = (a: Bound, b: Bound) => (compareBounds(a, b) >= 0 ? a : b);\nconst minBound = (a: Bound, b: Bound) => (compareBounds(a, b) <= 0 ? a : b);\n\n/**\n * The one key `key`, as a read or write of a document by ID records it.\n */\nexport const point = (key: ReadonlyArray<Value | undefined>): KeyInterval => ({\n start: { key, side: -1 },\n end: { key, side: 1 },\n});\n\n/**\n * Every key of an index.\n */\nexport const everything: KeyInterval = point([]);\n\n/**\n * The part of an index range a query has examined: from where it starts, past\n * the cursor `after`, through `through` in its order. `null` when it has\n * examined nothing.\n */\nexport const examined = (\n range: ReadonlyArray<SerializedRangeExpression>,\n order: \"asc\" | \"desc\",\n after: ReadonlyArray<Value | undefined> | null,\n through: ReadonlyArray<Value | undefined> | \"end\",\n): KeyInterval | null => {\n const equal: Array<Value | undefined> = [];\n let start: Bound | undefined;\n let end: Bound | undefined;\n for (const expression of range) {\n const value = evaluateQueryValue(expression.value);\n switch (expression.type) {\n case \"Eq\":\n equal.push(value);\n break;\n case \"Gt\":\n case \"Gte\":\n start = {\n key: [...equal, value],\n side: expression.type === \"Gt\" ? 1 : -1,\n };\n break;\n case \"Lt\":\n case \"Lte\":\n end = {\n key: [...equal, value],\n side: expression.type === \"Lt\" ? -1 : 1,\n };\n break;\n }\n }\n start ??= { key: equal, side: -1 };\n end ??= { key: equal, side: 1 };\n if (after !== null) {\n if (order === \"asc\") start = maxBound(start, { key: after, side: 1 });\n else end = minBound(end, { key: after, side: -1 });\n }\n if (through !== \"end\") {\n if (order === \"asc\") end = minBound(end, { key: through, side: 1 });\n else start = maxBound(start, { key: through, side: -1 });\n }\n return compareBounds(start, end) < 0 ? { start, end } : null;\n};\n\n/**\n * The intervals read from one index, overlapping and adjacent ones merged\n * (`IntervalSet::add`, `crates/common/src/interval/interval_set.rs:150-230`).\n * They stay sorted and disjoint, so an add touches only its neighbours.\n */\nclass IntervalSet {\n private readonly intervals: Array<KeyInterval> = [];\n\n get size(): number {\n return this.intervals.length;\n }\n\n add(interval: KeyInterval) {\n const intervals = this.intervals;\n // The first interval that ends at or after the new one's start.\n let low = 0;\n let high = intervals.length;\n while (low < high) {\n const middle = (low + high) >> 1;\n if (compareBounds(intervals[middle]!.end, interval.start) < 0) {\n low = middle + 1;\n } else {\n high = middle;\n }\n }\n let last = low;\n let merged = interval;\n while (\n last < intervals.length &&\n compareBounds(intervals[last]!.start, interval.end) <= 0\n ) {\n const other = intervals[last]!;\n merged = {\n start: minBound(merged.start, other.start),\n end: maxBound(merged.end, other.end),\n };\n last++;\n }\n intervals.splice(low, last - low, merged);\n }\n}\n\n/**\n * The counters every frame of one attempt shares: reads and schedules stay when\n * a nested mutation fails, as the binary keeps them outside its subtransaction\n * token (`crates/database/src/transaction.rs:418-454`).\n */\nclass Shared {\n readonly indexes = new Map<string, IntervalSet>();\n intervals = 0;\n documentsRead = 0;\n bytesRead = 0;\n functionsScheduled = 0;\n scheduledFunctionArgsBytes = 0;\n // File storage counters stay at zero until the kernel stores files.\n readonly filesRead = 0;\n readonly fileReadBytes = 0;\n\n /**\n * A stale-snapshot query's counters: the scheduling and file-read counters\n * carried over, reads and intervals from zero (`clone_for_snapshot_query`,\n * `crates/database/src/transaction.rs:1460-1485`).\n */\n forStaleSnapshot(): Shared {\n const copy = new Shared();\n copy.functionsScheduled = this.functionsScheduled;\n copy.scheduledFunctionArgsBytes = this.scheduledFunctionArgsBytes;\n return copy;\n }\n}\n\n/**\n * `a - b`, or 0 when `b` is larger: Rust's `usize::saturating_sub`.\n */\nconst saturatingSub = (a: number, b: number) => (a > b ? a - b : 0);\n\n/**\n * One frame's share of an attempt's accounting. The outermost frame belongs to\n * the top-level function and each nested mutation gets a child. A child's\n * writes count toward its caller's once it merges and are forgotten when it\n * fails, as the binary's nested write set rolls its sizes back\n * (`crates/database/src/writes.rs:96-136`).\n */\nexport class Meter {\n private documentsWritten = 0;\n private bytesWritten = 0;\n // File storage counters stay at zero until the kernel stores files.\n private readonly filesWritten = 0;\n private readonly fileWriteBytes = 0;\n\n constructor(\n private readonly shared: Shared = new Shared(),\n private readonly parent?: Meter,\n ) {}\n\n child(): Meter {\n return new Meter(this.shared, this);\n }\n\n /**\n * The meter of a query run on a stale snapshot. The binary runs it on a clone\n * of the transaction that keeps the scheduling counters and starts reads and\n * writes from zero, then drops the clone, so nothing it counts reaches this\n * meter (`clone_for_snapshot_query`,\n * `crates/database/src/transaction.rs:1460-1485`; `run_udf`,\n * `crates/isolate/src/environment/udf/async_syscall.rs:695-776`).\n */\n forStaleSnapshot(): Meter {\n return new Meter(this.shared.forStaleSnapshot());\n }\n\n /**\n * The child's writes become its caller's.\n */\n merge() {\n if (this.parent === undefined) {\n throw new Error(\"The outermost meter of an attempt has no caller.\");\n }\n this.parent.documentsWritten += this.documentsWritten;\n this.parent.bytesWritten += this.bytesWritten;\n }\n\n private chain(): Array<Meter> {\n return this.parent === undefined ? [this] : [...this.parent.chain(), this];\n }\n\n /**\n * How much of each limit the execution has used.\n */\n used(): Limits {\n const frames = this.chain();\n const sum = (of: (meter: Meter) => number) =>\n frames.reduce((total, meter) => total + of(meter), 0);\n const shared = this.shared;\n return {\n bytesRead: shared.bytesRead,\n documentsRead: shared.documentsRead,\n databaseQueries: shared.intervals,\n documentsWritten: sum((meter) => meter.documentsWritten),\n bytesWritten: sum((meter) => meter.bytesWritten),\n functionsScheduled: shared.functionsScheduled,\n scheduledFunctionArgsBytes: shared.scheduledFunctionArgsBytes,\n filesWritten: sum((meter) => meter.filesWritten),\n fileWriteBytes: sum((meter) => meter.fileWriteBytes),\n filesRead: shared.filesRead,\n fileReadBytes: shared.fileReadBytes,\n };\n }\n\n /**\n * What `getTransactionMetrics` answers (`tx_metrics`,\n * `crates/isolate/src/environment/udf/async_syscall.rs:947-993`).\n */\n metrics(limits: Limits): TransactionMetrics {\n const used = this.used();\n return Object.fromEntries(\n (Object.keys(limits) as Array<keyof Limits>).map((metric) => [\n metric,\n { used: used[metric], remaining: limits[metric] - used[metric] },\n ]),\n ) as unknown as TransactionMetrics;\n }\n\n private set(index: string): IntervalSet {\n const set = this.shared.indexes.get(index) ?? new IntervalSet();\n this.shared.indexes.set(index, set);\n return set;\n }\n\n /**\n * A read the function made of `interval` in `index`, counted as the binary\n * counts it: the total drops by the index's interval count before the read,\n * saturating at zero, and rises by its count after\n * (`record_indexed_directly`, `crates/database/src/reads.rs:447-480`). The\n * index's count includes the intervals of IDs this execution inserted, which\n * joined it without counting (`deriveInterval`), so a read that covers them\n * can move the total by more than the read itself. The binary starts the\n * total at the system-table intervals it reads to run the function, which the\n * kernel does not simulate. While neither total saturates they differ by\n * exactly that share. A read that saturates only the kernel's lower total\n * narrows the gap, and it never widens or turns negative (see the\n * `SystemTableReadIntervals` boundary).\n */\n readInterval(\n index: string,\n interval: KeyInterval,\n limits: Limits,\n ): TransactionLimitExceeded | undefined {\n const set = this.set(index);\n const before = set.size;\n set.add(interval);\n const shared = this.shared;\n shared.intervals = saturatingSub(shared.intervals, before) + set.size;\n // Both terms are counts, so the total never goes below zero.\n if (!Number.isSafeInteger(shared.intervals) || shared.intervals < 0) {\n throw new Error(\n `The kernel counted ${shared.intervals} intervals read, which is no count.`,\n );\n }\n return shared.intervals > limits.databaseQueries\n ? new TransactionLimitExceeded({\n code: \"TooManyReads\",\n limit: limits.databaseQueries,\n message: `Too many reads in a single function execution (limit: ${limits.databaseQueries}). ${overLimitHelp}`,\n })\n : undefined;\n }\n\n /**\n * A read the binary takes for a write rather than for the function: a new\n * document's ID (`register_new_id`, writes.rs:426-441). It joins the index's\n * intervals and leaves the total as it was (`record_indexed_derived` calls\n * `_record_indexed` and ignores its counts, reads.rs:333-344), so a later\n * read of that index starts from a count that includes it.\n */\n deriveInterval(index: string, interval: KeyInterval) {\n this.set(index).add(interval);\n }\n\n /**\n * A document the function read. A system table's document counts toward no\n * limit (`record_read_document`, reads.rs:365-445).\n */\n readDocument(\n document: Value,\n system: boolean,\n limits: Limits,\n ): TransactionLimitExceeded | undefined {\n if (system) return undefined;\n const shared = this.shared;\n shared.documentsRead += 1;\n shared.bytesRead += getConvexSize(document);\n if (shared.documentsRead > limits.documentsRead) {\n return new TransactionLimitExceeded({\n code: \"TooManyDocumentsRead\",\n limit: limits.documentsRead,\n message: `Too many documents read in a single function execution (limit: ${limits.documentsRead}). ${overLimitHelp}`,\n });\n }\n if (shared.bytesRead > limits.bytesRead) {\n return new TransactionLimitExceeded({\n code: \"TooManyBytesRead\",\n limit: limits.bytesRead,\n message: `Too many bytes read in a single function execution (limit: ${limits.bytesRead} bytes). ${overLimitHelp}`,\n });\n }\n return undefined;\n }\n\n /**\n * A write to a user table: the new document, or `null` for a delete. Each\n * write counts, even to a document this execution already wrote\n * (`Writes::update`, writes.rs:241-310).\n */\n write(\n document: Value | null,\n limits: Limits,\n ): TransactionLimitExceeded | undefined {\n this.documentsWritten += 1;\n this.bytesWritten += document === null ? 0 : getConvexSize(document);\n const used = this.used();\n if (used.documentsWritten > limits.documentsWritten) {\n return new TransactionLimitExceeded({\n code: \"TooManyWrites\",\n limit: limits.documentsWritten,\n message: `Too many writes in a single function execution (limit: ${limits.documentsWritten})`,\n });\n }\n if (used.bytesWritten > limits.bytesWritten) {\n return new TransactionLimitExceeded({\n code: \"TooManyBytesWritten\",\n limit: limits.bytesWritten,\n message: `Too many bytes written in a single function execution (limit: ${formatBytes(limits.bytesWritten)})`,\n });\n }\n return undefined;\n }\n\n /**\n * A function scheduled with `args`. The binary checks before it counts, so a\n * refused schedule counts nothing (`check_scheduling_limits`,\n * `crates/model/src/scheduled_jobs/mod.rs:162-196`). Its arguments are sized\n * as the one-element array the scheduler stores.\n */\n schedule(args: Value, limits: Limits): TransactionLimitExceeded | undefined {\n const shared = this.shared;\n const size = getConvexSize([args]);\n if (shared.functionsScheduled >= limits.functionsScheduled) {\n return new TransactionLimitExceeded({\n code: \"TooManyFunctionsScheduled\",\n limit: limits.functionsScheduled,\n message: `Too many functions scheduled by this mutation (limit: ${limits.functionsScheduled})`,\n });\n }\n if (\n shared.scheduledFunctionArgsBytes + size >\n limits.scheduledFunctionArgsBytes\n ) {\n return new TransactionLimitExceeded({\n code: \"ScheduledFunctionsArgumentsTooLarge\",\n limit: limits.scheduledFunctionArgsBytes,\n message: `Too large total size of the arguments of scheduled functions from this mutation (limit: ${limits.scheduledFunctionArgsBytes} bytes)`,\n });\n }\n shared.functionsScheduled += 1;\n shared.scheduledFunctionArgsBytes += size;\n return undefined;\n }\n}\n"],"mappings":";;;;;;;AAmBA,MAAa,WAAmB;CAE9B,WAAW,KAAK;CAEhB,eAAe;CAEf,iBAAiB;CAEjB,kBAAkB;CAElB,cAAc,KAAK;CAEnB,oBAAoB;CAEpB,4BAA4B,KAAK;CAEjC,cAAc;CAEd,gBAAgB,KAAK;CAErB,WAAW;CAEX,eAAe,KAAK;AACtB;;;;;;AAaA,MAAa,cACX,QACA,MACA,YAEA,OAAO,YACJ,OAAO,KAAK,OAAO,CAAC,CAAyB,KAAK,WAAW,CAC5D,QACA,KAAK,IACH,KAAK,WAAW,OAAO,WAAW,QAAQ,UAC1C,QAAQ,OACV,CACF,CAAC,CACH;AAEF,MAAM,gBACJ;;;;;;AAOF,IAAa,2BAAb,cAA8C,OAAO,YAAsC,CAAC,CAC1F,4BACA;CACE,MAAM,OAAO,SAAS;EACpB;EACA;EACA;EACA;EACA;EACA;EACA;CACF,CAAC;CACD,OAAO,OAAO;C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