fatedb 0.0.0-stage → 0.10.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/LICENSE +21 -0
- package/README.md +264 -2
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +3 -0
- package/dist/cli.d.ts +15 -0
- package/dist/cli.js +256 -0
- package/dist/client.d.ts +152 -0
- package/dist/client.js +416 -0
- package/dist/cloudflare.d.ts +197 -0
- package/dist/cloudflare.js +159 -0
- package/dist/datalog/ast.d.ts +35 -0
- package/dist/datalog/ast.js +40 -0
- package/dist/datalog/evaluator.d.ts +14 -0
- package/dist/datalog/evaluator.js +395 -0
- package/dist/datalog/fact-source.d.ts +30 -0
- package/dist/datalog/fact-source.js +1 -0
- package/dist/datalog/fingerprint.d.ts +12 -0
- package/dist/datalog/fingerprint.js +50 -0
- package/dist/datalog/parser.d.ts +3 -0
- package/dist/datalog/parser.js +302 -0
- package/dist/datalog/value.d.ts +34 -0
- package/dist/datalog/value.js +104 -0
- package/dist/domain/date-validation.d.ts +2 -0
- package/dist/domain/date-validation.js +32 -0
- package/dist/domain/fact-value.d.ts +91 -0
- package/dist/domain/fact-value.js +167 -0
- package/dist/domain/fact.d.ts +14 -0
- package/dist/domain/fact.js +47 -0
- package/dist/domain/failure.d.ts +44 -0
- package/dist/domain/failure.js +30 -0
- package/dist/domain/graph-id.d.ts +7 -0
- package/dist/domain/graph-id.js +10 -0
- package/dist/domain/histogram.d.ts +29 -0
- package/dist/domain/histogram.js +48 -0
- package/dist/domain/identifiers.d.ts +26 -0
- package/dist/domain/identifiers.js +75 -0
- package/dist/domain/numbers.d.ts +12 -0
- package/dist/domain/numbers.js +77 -0
- package/dist/domain/projection.d.ts +252 -0
- package/dist/domain/projection.js +51 -0
- package/dist/domain/query-metrics.d.ts +31 -0
- package/dist/domain/query-metrics.js +35 -0
- package/dist/domain/read-token.d.ts +37 -0
- package/dist/domain/read-token.js +93 -0
- package/dist/domain/result.d.ts +22 -0
- package/dist/domain/result.js +16 -0
- package/dist/domain/schema-observation.d.ts +20 -0
- package/dist/domain/schema-observation.js +61 -0
- package/dist/domain/string-order.d.ts +2 -0
- package/dist/domain/string-order.js +15 -0
- package/dist/domain/vocabulary.d.ts +101 -0
- package/dist/domain/vocabulary.js +276 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +14 -0
- package/dist/projection-config.d.ts +3 -0
- package/dist/projection-config.js +212 -0
- package/dist/server/access.d.ts +32 -0
- package/dist/server/access.js +117 -0
- package/dist/server/admin.d.ts +233 -0
- package/dist/server/admin.js +483 -0
- package/dist/server/authorization.d.ts +35 -0
- package/dist/server/authorization.js +76 -0
- package/dist/server/console-assets.d.ts +6 -0
- package/dist/server/console-assets.js +2 -0
- package/dist/server/console.d.ts +8 -0
- package/dist/server/console.js +301 -0
- package/dist/server/index.d.ts +122 -0
- package/dist/server/index.js +487 -0
- package/dist/server/mcp.d.ts +31 -0
- package/dist/server/mcp.js +169 -0
- package/dist/server/telemetry-do.d.ts +31 -0
- package/dist/server/telemetry-do.js +342 -0
- package/dist/server/telemetry.d.ts +27 -0
- package/dist/server/telemetry.js +191 -0
- package/dist/storage/constants.d.ts +20 -0
- package/dist/storage/constants.js +21 -0
- package/dist/storage/environment.d.ts +438 -0
- package/dist/storage/environment.js +145 -0
- package/dist/storage/facts.d.ts +41 -0
- package/dist/storage/facts.js +73 -0
- package/dist/storage/http.d.ts +55 -0
- package/dist/storage/http.js +169 -0
- package/dist/storage/keys.d.ts +50 -0
- package/dist/storage/keys.js +84 -0
- package/dist/storage/layout.d.ts +67 -0
- package/dist/storage/layout.js +134 -0
- package/dist/storage/log.d.ts +41 -0
- package/dist/storage/log.js +137 -0
- package/dist/storage/manifest.d.ts +26 -0
- package/dist/storage/manifest.js +206 -0
- package/dist/storage/operations.d.ts +303 -0
- package/dist/storage/operations.js +719 -0
- package/dist/storage/partition.d.ts +125 -0
- package/dist/storage/partition.js +816 -0
- package/dist/storage/projection.d.ts +72 -0
- package/dist/storage/projection.js +1349 -0
- package/dist/storage/root.d.ts +120 -0
- package/dist/storage/root.js +596 -0
- package/dist/storage/segment.d.ts +145 -0
- package/dist/storage/segment.js +451 -0
- package/dist/storage/shard.d.ts +82 -0
- package/dist/storage/shard.js +710 -0
- package/dist/storage/source.d.ts +60 -0
- package/dist/storage/source.js +199 -0
- package/dist/telemetry/model.d.ts +123 -0
- package/dist/telemetry/model.js +292 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +6 -0
- package/package.json +82 -4
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import { type FactValue } from "../domain/fact-value.js";
|
|
2
|
+
import { type TransactionId } from "../domain/identifiers.js";
|
|
3
|
+
import type { QueryMetrics } from "../domain/query-metrics.js";
|
|
4
|
+
import { type Consistency, type ReadToken } from "../domain/read-token.js";
|
|
5
|
+
import { type StorageEnv } from "./environment.js";
|
|
6
|
+
import { type Key } from "./keys.js";
|
|
7
|
+
import { type Layout } from "./layout.js";
|
|
8
|
+
import { segmentCacheStats, type SegmentSchema, type ValueTag } from "./segment.js";
|
|
9
|
+
import { type ObservedField } from "../domain/schema-observation.js";
|
|
10
|
+
/** A refusal with its HTTP status; `retryable` says whether the same call may succeed later. */
|
|
11
|
+
export declare class GraphError extends Error {
|
|
12
|
+
readonly status: number;
|
|
13
|
+
readonly retryable: boolean;
|
|
14
|
+
constructor(status: number, message: string, retryable?: boolean);
|
|
15
|
+
}
|
|
16
|
+
export type TransactBody = Readonly<{
|
|
17
|
+
facts?: unknown;
|
|
18
|
+
clientRequestToken?: unknown;
|
|
19
|
+
readToken?: unknown;
|
|
20
|
+
}>;
|
|
21
|
+
/** `key`: the write's place in the graph's order. `replayed`: a retry with the same client request token, answered from the first write. */
|
|
22
|
+
export type TransactReceipt = Readonly<{
|
|
23
|
+
txId: TransactionId;
|
|
24
|
+
key: Key;
|
|
25
|
+
replayed: boolean;
|
|
26
|
+
readToken: ReadToken;
|
|
27
|
+
}>;
|
|
28
|
+
/** The graph's layout, as this isolate cached it: the root's, read at most LAYOUT_TTL_MS ago, or a partition's newer one. Reading it makes the graph's first. */
|
|
29
|
+
export declare function layoutFor(env: StorageEnv, graph: string, fresh?: boolean): Promise<Layout>;
|
|
30
|
+
/** Tests only: forget every cached layout, as a new isolate would. */
|
|
31
|
+
export declare function forgetLayouts(): void;
|
|
32
|
+
export declare function transact(env: StorageEnv, graphInput: string, body: TransactBody): Promise<TransactReceipt>;
|
|
33
|
+
export type ReadBody = Readonly<{
|
|
34
|
+
readToken?: unknown;
|
|
35
|
+
consistency?: unknown;
|
|
36
|
+
maxStalenessMs?: unknown;
|
|
37
|
+
}>;
|
|
38
|
+
export type QueryBody = ReadBody & Readonly<{
|
|
39
|
+
query?: unknown;
|
|
40
|
+
}>;
|
|
41
|
+
export type QueryManyBody = ReadBody & Readonly<{
|
|
42
|
+
queries?: unknown;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* A query's metrics as the graph serves them: the public ones, and the isolate that answered with
|
|
46
|
+
* its segment caches after the query, which a load generator needs to tell isolates apart.
|
|
47
|
+
*/
|
|
48
|
+
export type ServedQueryMetrics = QueryMetrics & Readonly<{
|
|
49
|
+
isolate: string;
|
|
50
|
+
cache: ReturnType<typeof segmentCacheStats>;
|
|
51
|
+
}>;
|
|
52
|
+
/** A query's row: each variable's value, as the fact value the first atom binding it matched; entities are references. */
|
|
53
|
+
export type QueryRow = Readonly<Record<string, FactValue>>;
|
|
54
|
+
export type QueryAnswer = Readonly<{
|
|
55
|
+
rows: readonly QueryRow[];
|
|
56
|
+
watermark: number;
|
|
57
|
+
consistency: Consistency;
|
|
58
|
+
readToken: ReadToken;
|
|
59
|
+
metrics: ServedQueryMetrics;
|
|
60
|
+
/** Only with a limit: there were more rows than it. */
|
|
61
|
+
truncated?: true;
|
|
62
|
+
}>;
|
|
63
|
+
export type QueryManyItem = Readonly<{
|
|
64
|
+
rows: readonly QueryRow[];
|
|
65
|
+
metrics: ServedQueryMetrics;
|
|
66
|
+
truncated?: true;
|
|
67
|
+
}>;
|
|
68
|
+
export type QueryManyAnswer = Readonly<{
|
|
69
|
+
answers: readonly QueryManyItem[];
|
|
70
|
+
watermark: number;
|
|
71
|
+
consistency: Consistency;
|
|
72
|
+
readToken: ReadToken;
|
|
73
|
+
metrics: ServedQueryMetrics;
|
|
74
|
+
}>;
|
|
75
|
+
/** Tests only: clear the per-isolate watermark query cache. */
|
|
76
|
+
export declare function clearQueryCache(): void;
|
|
77
|
+
/**
|
|
78
|
+
* An answer's JSON, `JSON.stringify(answer)` exactly, from its rows' JSON: the rows are the bulk of
|
|
79
|
+
* an answer, and are serialized at most once.
|
|
80
|
+
*/
|
|
81
|
+
export declare function answerJson(rowsJson: string, answer: QueryAnswer): string;
|
|
82
|
+
/** `answerJson(rowsJson, answer).length`, from the rows' JSON's length alone. */
|
|
83
|
+
export declare function answerLength(rowsLength: number, answer: QueryAnswer): number;
|
|
84
|
+
export type QueryRunOptions = Readonly<{
|
|
85
|
+
limit?: number;
|
|
86
|
+
}>;
|
|
87
|
+
/** An answer, and its rows' JSON when serving it made it: the HTTP route sends it, and makes it otherwise. */
|
|
88
|
+
export type ServedQuery = Readonly<{
|
|
89
|
+
answer: QueryAnswer;
|
|
90
|
+
rowsJson: string | null;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Runs a query. With `limit`, the answer is the first `limit` rows and says whether there were
|
|
94
|
+
* more (`truncated`), instead of failing past MAX_QUERY_RESULTS: the console and agents read so.
|
|
95
|
+
*/
|
|
96
|
+
export declare function query(env: StorageEnv, graphInput: string, body: QueryBody, options?: QueryRunOptions): Promise<QueryAnswer>;
|
|
97
|
+
/** `query`, with its rows' JSON when it made it. */
|
|
98
|
+
export declare function serveQuery(env: StorageEnv, graphInput: string, body: QueryBody, options?: QueryRunOptions): Promise<ServedQuery>;
|
|
99
|
+
/**
|
|
100
|
+
* Runs 1 to MAX_QUERY_MANY Datalog queries against one pinned watermark and read view, sharing a
|
|
101
|
+
* single manifest read, session tail read, and in-flight segment header/block reads.
|
|
102
|
+
*/
|
|
103
|
+
export declare function queryMany(env: StorageEnv, graphInput: string, body: QueryManyBody, options?: QueryRunOptions): Promise<QueryManyAnswer>;
|
|
104
|
+
export type SchemaAnswer = Readonly<{
|
|
105
|
+
fields: readonly ObservedField[];
|
|
106
|
+
watermark: number;
|
|
107
|
+
consistency: Consistency;
|
|
108
|
+
readToken: ReadToken;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* The graph's fields and the value tags of their active facts, at the watermark plus the caller's
|
|
112
|
+
* own writes: exactly the (field, tag) pairs some active fact holds (tests/storage/schema.test.ts
|
|
113
|
+
* checks the counting below on every short history, in every segmentation).
|
|
114
|
+
*
|
|
115
|
+
* It is read from the tag counts in segment headers. A bucket's segments cover disjoint epochs, so
|
|
116
|
+
* a tag is surely active if, in some segment, more of its tuples end asserted than all later
|
|
117
|
+
* segments retract. A segment reaching above the watermark is read, to count only what is below
|
|
118
|
+
* it. A tag the counts leave open, as many retractions as assertions, is decided by reading the
|
|
119
|
+
* field's active facts, within the query tuple budget.
|
|
120
|
+
*/
|
|
121
|
+
export declare function schema(env: StorageEnv, graphInput: string, body: ReadBody): Promise<SchemaAnswer>;
|
|
122
|
+
type FieldCounts = SegmentSchema[string];
|
|
123
|
+
/** The tags the counts show active, and those they leave open. `layers` are oldest first. */
|
|
124
|
+
export declare function tagsOf(layers: readonly FieldCounts[]): Readonly<{
|
|
125
|
+
active: Set<ValueTag>;
|
|
126
|
+
open: Set<ValueTag>;
|
|
127
|
+
}>;
|
|
128
|
+
export type GraphStatus = Awaited<ReturnType<typeof status>>;
|
|
129
|
+
export type CreateBody = Readonly<{
|
|
130
|
+
partitions?: unknown;
|
|
131
|
+
shards?: unknown;
|
|
132
|
+
}>;
|
|
133
|
+
export type CreatedGraph = Readonly<{
|
|
134
|
+
graph: string;
|
|
135
|
+
created: boolean;
|
|
136
|
+
partitions: number;
|
|
137
|
+
shards: number;
|
|
138
|
+
}>;
|
|
139
|
+
/**
|
|
140
|
+
* Makes a graph before its first write, so it is listed and has a layout: the instance's initial
|
|
141
|
+
* partitions and one index shard, or the counts asked for, for a graph whose load is known ahead.
|
|
142
|
+
* A graph that exists keeps its layout, and `created` is false.
|
|
143
|
+
*/
|
|
144
|
+
export declare function createGraph(env: StorageEnv, graphInput: string, body: CreateBody): Promise<CreatedGraph>;
|
|
145
|
+
/** The root, every index shard and every partition. A graph never written or created has no layout, and no shards or partitions here. */
|
|
146
|
+
export declare function status(env: StorageEnv, graphInput: string): Promise<{
|
|
147
|
+
graph: string;
|
|
148
|
+
now: number;
|
|
149
|
+
nowEpoch: number;
|
|
150
|
+
root: {
|
|
151
|
+
readonly graph: string | null;
|
|
152
|
+
readonly layout: {
|
|
153
|
+
readonly version: number;
|
|
154
|
+
readonly eras: readonly {
|
|
155
|
+
readonly version: number;
|
|
156
|
+
readonly from: number;
|
|
157
|
+
readonly count: number;
|
|
158
|
+
readonly since: number;
|
|
159
|
+
readonly at: number;
|
|
160
|
+
}[];
|
|
161
|
+
readonly shards: readonly {
|
|
162
|
+
readonly depth: number;
|
|
163
|
+
readonly prefix: number;
|
|
164
|
+
}[];
|
|
165
|
+
readonly firstDepth: number;
|
|
166
|
+
} | null;
|
|
167
|
+
readonly partitions: number;
|
|
168
|
+
readonly shards: number;
|
|
169
|
+
readonly watermark: number;
|
|
170
|
+
readonly stalenessMs: number;
|
|
171
|
+
readonly shardWatermarks: {
|
|
172
|
+
readonly [x: string]: number;
|
|
173
|
+
};
|
|
174
|
+
readonly indexed: {
|
|
175
|
+
readonly facts: number;
|
|
176
|
+
};
|
|
177
|
+
readonly manifests: number;
|
|
178
|
+
readonly lastManifestAt: number;
|
|
179
|
+
readonly growth: {
|
|
180
|
+
readonly installing: boolean;
|
|
181
|
+
readonly lastGrewAt: number;
|
|
182
|
+
readonly callsPerSecond: number | null;
|
|
183
|
+
readonly overloads: number;
|
|
184
|
+
};
|
|
185
|
+
readonly counters: {
|
|
186
|
+
readonly reports: number;
|
|
187
|
+
readonly alarms: number;
|
|
188
|
+
readonly lastAlarmMs: number;
|
|
189
|
+
readonly maxAlarmMs: number;
|
|
190
|
+
readonly notifyRounds: number;
|
|
191
|
+
readonly lastNotifyMs: number;
|
|
192
|
+
readonly skippedNotifies: number;
|
|
193
|
+
};
|
|
194
|
+
readonly errors: readonly string[];
|
|
195
|
+
} & Disposable;
|
|
196
|
+
shards: ({
|
|
197
|
+
readonly shard: number;
|
|
198
|
+
readonly depth: number;
|
|
199
|
+
readonly layoutVersion: number;
|
|
200
|
+
readonly watermark: number;
|
|
201
|
+
readonly graphWatermark: number;
|
|
202
|
+
readonly facts: number;
|
|
203
|
+
readonly segments: number;
|
|
204
|
+
readonly liveFacts: number;
|
|
205
|
+
readonly bytes: number;
|
|
206
|
+
readonly compactions: {
|
|
207
|
+
readonly runs: number;
|
|
208
|
+
readonly segmentsIn: number;
|
|
209
|
+
readonly bytesIn: number;
|
|
210
|
+
readonly lastMs: number;
|
|
211
|
+
readonly maxMs: number;
|
|
212
|
+
};
|
|
213
|
+
readonly flushes: readonly {
|
|
214
|
+
readonly at: number;
|
|
215
|
+
readonly watermark: number;
|
|
216
|
+
readonly stalenessMs: number;
|
|
217
|
+
readonly txs: number;
|
|
218
|
+
readonly facts: number;
|
|
219
|
+
readonly segments: number;
|
|
220
|
+
readonly compacted: number;
|
|
221
|
+
readonly handoffMs: number;
|
|
222
|
+
readonly r2Ms: number;
|
|
223
|
+
readonly reportMs: number;
|
|
224
|
+
readonly totalMs: number;
|
|
225
|
+
readonly behind: boolean;
|
|
226
|
+
}[];
|
|
227
|
+
readonly errors: readonly string[];
|
|
228
|
+
} & Disposable)[];
|
|
229
|
+
partitions: ({
|
|
230
|
+
readonly partition: number;
|
|
231
|
+
readonly commits: number;
|
|
232
|
+
readonly txs: number;
|
|
233
|
+
readonly replays: number;
|
|
234
|
+
readonly conflicts: number;
|
|
235
|
+
readonly maxBatch: number;
|
|
236
|
+
readonly rows: number;
|
|
237
|
+
readonly tokens: number;
|
|
238
|
+
readonly closed: number;
|
|
239
|
+
readonly floor: number;
|
|
240
|
+
readonly indexed: number;
|
|
241
|
+
readonly archived: number;
|
|
242
|
+
readonly lastEpoch: number;
|
|
243
|
+
readonly pending: number;
|
|
244
|
+
readonly startedAt: number;
|
|
245
|
+
readonly layoutVersion: number;
|
|
246
|
+
readonly calls: number;
|
|
247
|
+
readonly boots: number;
|
|
248
|
+
readonly isolate: string;
|
|
249
|
+
readonly colo: string | null;
|
|
250
|
+
readonly service: {
|
|
251
|
+
readonly buckets: readonly (readonly number[])[];
|
|
252
|
+
readonly maxMs: number;
|
|
253
|
+
};
|
|
254
|
+
} & Disposable)[];
|
|
255
|
+
}>;
|
|
256
|
+
/** The root's part of the status alone: cheap enough to poll during a load point. */
|
|
257
|
+
export declare function rootStatus(env: StorageEnv, graphInput: string): Promise<{
|
|
258
|
+
readonly graph: string | null;
|
|
259
|
+
readonly layout: {
|
|
260
|
+
readonly version: number;
|
|
261
|
+
readonly eras: readonly {
|
|
262
|
+
readonly version: number;
|
|
263
|
+
readonly from: number;
|
|
264
|
+
readonly count: number;
|
|
265
|
+
readonly since: number;
|
|
266
|
+
readonly at: number;
|
|
267
|
+
}[];
|
|
268
|
+
readonly shards: readonly {
|
|
269
|
+
readonly depth: number;
|
|
270
|
+
readonly prefix: number;
|
|
271
|
+
}[];
|
|
272
|
+
readonly firstDepth: number;
|
|
273
|
+
} | null;
|
|
274
|
+
readonly partitions: number;
|
|
275
|
+
readonly shards: number;
|
|
276
|
+
readonly watermark: number;
|
|
277
|
+
readonly stalenessMs: number;
|
|
278
|
+
readonly shardWatermarks: {
|
|
279
|
+
readonly [x: string]: number;
|
|
280
|
+
};
|
|
281
|
+
readonly indexed: {
|
|
282
|
+
readonly facts: number;
|
|
283
|
+
};
|
|
284
|
+
readonly manifests: number;
|
|
285
|
+
readonly lastManifestAt: number;
|
|
286
|
+
readonly growth: {
|
|
287
|
+
readonly installing: boolean;
|
|
288
|
+
readonly lastGrewAt: number;
|
|
289
|
+
readonly callsPerSecond: number | null;
|
|
290
|
+
readonly overloads: number;
|
|
291
|
+
};
|
|
292
|
+
readonly counters: {
|
|
293
|
+
readonly reports: number;
|
|
294
|
+
readonly alarms: number;
|
|
295
|
+
readonly lastAlarmMs: number;
|
|
296
|
+
readonly maxAlarmMs: number;
|
|
297
|
+
readonly notifyRounds: number;
|
|
298
|
+
readonly lastNotifyMs: number;
|
|
299
|
+
readonly skippedNotifies: number;
|
|
300
|
+
};
|
|
301
|
+
readonly errors: readonly string[];
|
|
302
|
+
} & Disposable>;
|
|
303
|
+
export type { FactValue };
|