@feltdb/core 0.6.8 → 0.6.10
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/cli/application.js +55 -88
- package/dist/cli/commands.js +206 -95
- package/dist/cli/index.js +1 -1
- package/dist/collection.d.ts +110 -2
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +228 -3
- package/dist/create/package-versions.js +1 -1
- package/dist/create/server-source/crates/feltdb/src/bin/feltdb_node.rs +408 -178
- package/dist/create/server-source/crates/feltdb/src/lib.rs +49 -5
- package/dist/create/server-source/crates/feltdb/src/multi_operation_transaction.rs +659 -0
- package/dist/create/server-source/crates/feltdb/src/p1_application_atomicity.rs +285 -0
- package/dist/create/server-source/crates/feltdb/src/p1_atomicity_acceptance.rs +582 -0
- package/dist/create/server-source/crates/feltdb-server/src/main.rs +141 -0
- package/dist/db.d.ts +59 -0
- package/dist/db.d.ts.map +1 -1
- package/dist/db.js +94 -2
- package/dist/embedded-transaction.d.ts +77 -0
- package/dist/embedded-transaction.d.ts.map +1 -0
- package/dist/embedded-transaction.js +102 -0
- package/dist/feltdb.d.ts +49 -1
- package/dist/feltdb.d.ts.map +1 -1
- package/dist/file-db.d.ts +33 -0
- package/dist/file-db.d.ts.map +1 -1
- package/dist/file-db.js +128 -4
- package/dist/freshness.d.ts +119 -0
- package/dist/freshness.d.ts.map +1 -0
- package/dist/freshness.js +115 -0
- package/dist/http-db.d.ts +48 -0
- package/dist/http-db.d.ts.map +1 -1
- package/dist/http-db.js +77 -1
- package/dist/index-backend.d.ts +8 -0
- package/dist/index-backend.d.ts.map +1 -1
- package/dist/index-backend.js +13 -0
- package/dist/index-core.d.ts +78 -0
- package/dist/index-core.d.ts.map +1 -0
- package/dist/index-core.js +72 -0
- package/dist/index-manager.d.ts +11 -0
- package/dist/index-manager.d.ts.map +1 -1
- package/dist/index-manager.js +30 -13
- package/dist/index-types.d.ts +17 -0
- package/dist/index-types.d.ts.map +1 -1
- package/dist/index.browser.d.ts +14 -0
- package/dist/index.browser.d.ts.map +1 -0
- package/dist/index.browser.js +13 -0
- package/dist/index.d.ts +8 -59
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -54
- package/dist/indexeddb-db.d.ts +32 -0
- package/dist/indexeddb-db.d.ts.map +1 -1
- package/dist/indexeddb-db.js +151 -1
- package/dist/memory-db.d.ts +26 -0
- package/dist/memory-db.d.ts.map +1 -1
- package/dist/memory-db.js +86 -0
- package/dist/runtime-registry.d.ts +32 -0
- package/dist/runtime-registry.d.ts.map +1 -0
- package/dist/runtime-registry.js +38 -0
- package/dist/studio-app/assets/{feltdb_wasm-B4wq4mqp.js → feltdb_wasm-CJv3wHzi.js} +1 -1
- package/dist/studio-app/assets/feltdb_wasm_bg-C8TG8r2n.wasm +0 -0
- package/dist/studio-app/assets/index-D3rT0SJi.js +28 -0
- package/dist/studio-app/index.html +1 -1
- package/dist/transaction.d.ts +98 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +86 -0
- package/dist/wasm/feltdb_wasm_bg.wasm +0 -0
- package/dist/workspace/browser.d.ts +22 -0
- package/dist/workspace/browser.d.ts.map +1 -0
- package/dist/workspace/browser.js +17 -0
- package/dist/workspace/git-identity.d.ts +35 -0
- package/dist/workspace/git-identity.d.ts.map +1 -0
- package/dist/workspace/git-identity.js +81 -0
- package/dist/workspace/index.d.ts +11 -1
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/index.js +6 -0
- package/dist/workspace/investigation-analysis.d.ts +47 -0
- package/dist/workspace/investigation-analysis.d.ts.map +1 -0
- package/dist/workspace/investigation-analysis.js +181 -0
- package/dist/workspace/investigation-lifecycle-manager.d.ts +86 -0
- package/dist/workspace/investigation-lifecycle-manager.d.ts.map +1 -0
- package/dist/workspace/investigation-lifecycle-manager.js +229 -0
- package/dist/workspace/investigation-supervisor.d.ts +100 -0
- package/dist/workspace/investigation-supervisor.d.ts.map +1 -0
- package/dist/workspace/investigation-supervisor.js +236 -0
- package/dist/workspace/runtime-investigation.d.ts +1 -1
- package/dist/workspace/runtime-investigation.d.ts.map +1 -1
- package/dist/workspace/runtime-investigation.js +46 -21
- package/dist/workspace/runtime-observation.d.ts +79 -0
- package/dist/workspace/runtime-observation.d.ts.map +1 -0
- package/dist/workspace/runtime-observation.js +152 -0
- package/dist/workspace/runtime-observer.d.ts +51 -0
- package/dist/workspace/runtime-observer.d.ts.map +1 -0
- package/dist/workspace/runtime-observer.js +268 -0
- package/dist/workspace/workspace-connection.d.ts.map +1 -1
- package/dist/workspace/workspace-connection.js +14 -5
- package/dist/workspace/workspace-types.d.ts +113 -0
- package/dist/workspace/workspace-types.d.ts.map +1 -1
- package/package.json +12 -4
- package/dist/create/server-source/crates/feltdb/src/phase_1c_three_node.rs +0 -523
- package/dist/studio-app/assets/feltdb_wasm_bg-Ceyi7l21.wasm +0 -0
- package/dist/studio-app/assets/index-BF45M757.js +0 -28
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
//! Production Gate P1 — application-facing atomicity.
|
|
2
|
+
//!
|
|
3
|
+
//! `apply_atomic_transaction` writes one fsynced transaction record, and
|
|
4
|
+
//! `replay_log` restores every row of that record together. These tests hold
|
|
5
|
+
//! the *application* store to the same all-or-nothing contract the transaction
|
|
6
|
+
//! primitive guarantees, including the case that matters most in practice:
|
|
7
|
+
//! the process died while the transaction record was being written.
|
|
8
|
+
|
|
9
|
+
#[cfg(test)]
|
|
10
|
+
mod tests {
|
|
11
|
+
use crate::{AtomicMutation, AtomicPrecondition, FeltDb};
|
|
12
|
+
use serde_json::json;
|
|
13
|
+
use std::io::{Seek, SeekFrom, Write};
|
|
14
|
+
use tempfile::TempDir;
|
|
15
|
+
|
|
16
|
+
fn mutation(capability: &str, key: &str, value: serde_json::Value) -> AtomicMutation {
|
|
17
|
+
AtomicMutation {
|
|
18
|
+
capability: capability.to_string(),
|
|
19
|
+
key: key.to_string(),
|
|
20
|
+
value: Some(value),
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// A cross-collection transaction, as an application would issue it.
|
|
25
|
+
fn user_order_audit() -> Vec<AtomicMutation> {
|
|
26
|
+
vec![
|
|
27
|
+
mutation("users", "users:u1", json!({ "id": "u1", "name": "Ada" })),
|
|
28
|
+
mutation("orders", "orders:o1", json!({ "id": "o1", "user": "u1", "total": 42 })),
|
|
29
|
+
mutation("audit", "audit:a1", json!({ "id": "a1", "event": "order.created" })),
|
|
30
|
+
]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
fn present(db: &FeltDb, key: &str) -> bool {
|
|
34
|
+
db.get_value(key).expect("read must succeed").is_some()
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
fn visible_count(db: &FeltDb) -> usize {
|
|
38
|
+
["users:u1", "orders:o1", "audit:a1"]
|
|
39
|
+
.iter()
|
|
40
|
+
.filter(|key| present(db, key))
|
|
41
|
+
.count()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#[test]
|
|
45
|
+
fn a_cross_collection_transaction_commits_every_operation() -> Result<(), Box<dyn std::error::Error>> {
|
|
46
|
+
let dir = TempDir::new()?;
|
|
47
|
+
let path = dir.path().join("app.log");
|
|
48
|
+
let db = FeltDb::open(&path)?;
|
|
49
|
+
|
|
50
|
+
let commit = db.apply_atomic_transaction("tx-1", None, &[], &user_order_audit(), None)?;
|
|
51
|
+
assert_eq!(commit.rows.len(), 3);
|
|
52
|
+
assert!(!commit.duplicate);
|
|
53
|
+
assert_eq!(visible_count(&db), 3);
|
|
54
|
+
Ok(())
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#[test]
|
|
58
|
+
fn a_cross_collection_transaction_survives_restart() -> Result<(), Box<dyn std::error::Error>> {
|
|
59
|
+
let dir = TempDir::new()?;
|
|
60
|
+
let path = dir.path().join("app.log");
|
|
61
|
+
|
|
62
|
+
{
|
|
63
|
+
let db = FeltDb::open(&path)?;
|
|
64
|
+
db.apply_atomic_transaction("tx-1", None, &[], &user_order_audit(), None)?;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
let reopened = FeltDb::open(&path)?;
|
|
68
|
+
assert_eq!(visible_count(&reopened), 3, "every row must recover together");
|
|
69
|
+
Ok(())
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#[test]
|
|
73
|
+
fn a_failed_precondition_leaves_no_operation_applied() -> Result<(), Box<dyn std::error::Error>> {
|
|
74
|
+
let dir = TempDir::new()?;
|
|
75
|
+
let path = dir.path().join("app.log");
|
|
76
|
+
let db = FeltDb::open(&path)?;
|
|
77
|
+
|
|
78
|
+
// The middle key must already exist at a given version; it does not.
|
|
79
|
+
let preconditions = vec![AtomicPrecondition {
|
|
80
|
+
capability: "orders".to_string(),
|
|
81
|
+
key: "orders:o1".to_string(),
|
|
82
|
+
expected_version: Some(7),
|
|
83
|
+
}];
|
|
84
|
+
|
|
85
|
+
let outcome = db.apply_atomic_transaction("tx-bad", None, &preconditions, &user_order_audit(), None);
|
|
86
|
+
assert!(outcome.is_err(), "a failed precondition must reject the transaction");
|
|
87
|
+
|
|
88
|
+
assert_eq!(visible_count(&db), 0, "no operation may be applied");
|
|
89
|
+
drop(db);
|
|
90
|
+
|
|
91
|
+
let reopened = FeltDb::open(&path)?;
|
|
92
|
+
assert_eq!(visible_count(&reopened), 0, "and nothing may be durable");
|
|
93
|
+
Ok(())
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#[test]
|
|
97
|
+
fn replaying_a_transaction_id_is_idempotent() -> Result<(), Box<dyn std::error::Error>> {
|
|
98
|
+
let dir = TempDir::new()?;
|
|
99
|
+
let path = dir.path().join("app.log");
|
|
100
|
+
let db = FeltDb::open(&path)?;
|
|
101
|
+
|
|
102
|
+
let first = db.apply_atomic_transaction("tx-1", None, &[], &user_order_audit(), None)?;
|
|
103
|
+
assert!(!first.duplicate);
|
|
104
|
+
let second = db.apply_atomic_transaction("tx-1", None, &[], &user_order_audit(), None)?;
|
|
105
|
+
assert!(second.duplicate, "the same transaction id must not apply twice");
|
|
106
|
+
assert_eq!(visible_count(&db), 3);
|
|
107
|
+
Ok(())
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#[test]
|
|
111
|
+
fn transaction_identity_survives_restart() -> Result<(), Box<dyn std::error::Error>> {
|
|
112
|
+
let dir = TempDir::new()?;
|
|
113
|
+
let path = dir.path().join("app.log");
|
|
114
|
+
|
|
115
|
+
{
|
|
116
|
+
let db = FeltDb::open(&path)?;
|
|
117
|
+
db.apply_atomic_transaction("tx-stable", None, &[], &user_order_audit(), None)?;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
let reopened = FeltDb::open(&path)?;
|
|
121
|
+
let replayed = reopened.apply_atomic_transaction("tx-stable", None, &[], &user_order_audit(), None)?;
|
|
122
|
+
assert!(replayed.duplicate, "identity must be restored so redelivery stays idempotent");
|
|
123
|
+
assert_eq!(visible_count(&reopened), 3);
|
|
124
|
+
Ok(())
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// The case that matters in production: the process died while the
|
|
128
|
+
/// transaction record was being written.
|
|
129
|
+
///
|
|
130
|
+
/// The half-written record is not a committed transaction, so recovery must
|
|
131
|
+
/// discard it and open the store with the previously committed history
|
|
132
|
+
/// intact. Refusing to open at all would turn a normal crash into an
|
|
133
|
+
/// outage.
|
|
134
|
+
#[test]
|
|
135
|
+
fn a_torn_transaction_record_is_discarded_and_the_store_still_opens()
|
|
136
|
+
-> Result<(), Box<dyn std::error::Error>> {
|
|
137
|
+
let dir = TempDir::new()?;
|
|
138
|
+
let path = dir.path().join("app.log");
|
|
139
|
+
|
|
140
|
+
{
|
|
141
|
+
let db = FeltDb::open(&path)?;
|
|
142
|
+
db.apply_atomic_transaction("tx-1", None, &[], &user_order_audit(), None)?;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Append a partial transaction record with no terminating newline,
|
|
146
|
+
// exactly as a crash mid-write would leave behind.
|
|
147
|
+
let complete = std::fs::read_to_string(&path)?;
|
|
148
|
+
let mut file = std::fs::OpenOptions::new().append(true).open(&path)?;
|
|
149
|
+
let torn = &complete[..complete.len() / 2];
|
|
150
|
+
file.write_all(torn.as_bytes())?;
|
|
151
|
+
file.flush()?;
|
|
152
|
+
drop(file);
|
|
153
|
+
|
|
154
|
+
let recovered = FeltDb::open(&path).map_err(|error| {
|
|
155
|
+
format!("a torn tail must not stop the store from opening: {error}")
|
|
156
|
+
})?;
|
|
157
|
+
assert_eq!(visible_count(&recovered), 3, "committed history must survive");
|
|
158
|
+
Ok(())
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/// A transaction that was still being written never committed, so none of
|
|
162
|
+
/// its rows may appear.
|
|
163
|
+
#[test]
|
|
164
|
+
fn a_transaction_torn_mid_write_applies_nothing() -> Result<(), Box<dyn std::error::Error>> {
|
|
165
|
+
let dir = TempDir::new()?;
|
|
166
|
+
let path = dir.path().join("app.log");
|
|
167
|
+
|
|
168
|
+
// Write a complete transaction, then a partial second one.
|
|
169
|
+
{
|
|
170
|
+
let db = FeltDb::open(&path)?;
|
|
171
|
+
db.apply_atomic_transaction("tx-1", None, &[], &user_order_audit(), None)?;
|
|
172
|
+
}
|
|
173
|
+
let after_first = std::fs::read_to_string(&path)?;
|
|
174
|
+
|
|
175
|
+
{
|
|
176
|
+
let db = FeltDb::open(&path)?;
|
|
177
|
+
db.apply_atomic_transaction(
|
|
178
|
+
"tx-2",
|
|
179
|
+
None,
|
|
180
|
+
&[],
|
|
181
|
+
&[mutation("users", "users:u2", json!({ "id": "u2", "name": "Grace" }))],
|
|
182
|
+
None,
|
|
183
|
+
)?;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Truncate the second record part-way through.
|
|
187
|
+
let full = std::fs::read_to_string(&path)?;
|
|
188
|
+
let second = &full[after_first.len()..];
|
|
189
|
+
let keep = after_first.len() + second.len() / 2;
|
|
190
|
+
let file = std::fs::OpenOptions::new().write(true).open(&path)?;
|
|
191
|
+
file.set_len(keep as u64)?;
|
|
192
|
+
file.sync_all()?;
|
|
193
|
+
drop(file);
|
|
194
|
+
|
|
195
|
+
let recovered = FeltDb::open(&path)?;
|
|
196
|
+
assert_eq!(visible_count(&recovered), 3, "the committed transaction survives");
|
|
197
|
+
assert!(!present(&recovered, "users:u2"), "a torn transaction must apply nothing");
|
|
198
|
+
Ok(())
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/// Damage before the end of the log is corruption, not an interrupted
|
|
202
|
+
/// write, and recovery must refuse rather than silently drop history.
|
|
203
|
+
#[test]
|
|
204
|
+
fn interior_corruption_is_still_refused() -> Result<(), Box<dyn std::error::Error>> {
|
|
205
|
+
let dir = TempDir::new()?;
|
|
206
|
+
let path = dir.path().join("app.log");
|
|
207
|
+
|
|
208
|
+
{
|
|
209
|
+
let db = FeltDb::open(&path)?;
|
|
210
|
+
db.apply_atomic_transaction("tx-1", None, &[], &user_order_audit(), None)?;
|
|
211
|
+
db.apply_atomic_transaction(
|
|
212
|
+
"tx-2",
|
|
213
|
+
None,
|
|
214
|
+
&[],
|
|
215
|
+
&[mutation("users", "users:u2", json!({ "id": "u2" }))],
|
|
216
|
+
None,
|
|
217
|
+
)?;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
let mut file = std::fs::OpenOptions::new().write(true).open(&path)?;
|
|
221
|
+
file.seek(SeekFrom::Start(30))?;
|
|
222
|
+
file.write_all(b"@@@@@@@@")?;
|
|
223
|
+
file.sync_all()?;
|
|
224
|
+
drop(file);
|
|
225
|
+
|
|
226
|
+
assert!(
|
|
227
|
+
FeltDb::open(&path).is_err(),
|
|
228
|
+
"corruption before the end of the log must not be silently discarded"
|
|
229
|
+
);
|
|
230
|
+
Ok(())
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
#[test]
|
|
234
|
+
fn single_operation_writes_remain_compatible() -> Result<(), Box<dyn std::error::Error>> {
|
|
235
|
+
let dir = TempDir::new()?;
|
|
236
|
+
let path = dir.path().join("app.log");
|
|
237
|
+
|
|
238
|
+
{
|
|
239
|
+
let db = FeltDb::open(&path)?;
|
|
240
|
+
// The existing single-operation API, unchanged.
|
|
241
|
+
db.insert("users:solo", json!({ "id": "solo", "name": "Alan" }))?;
|
|
242
|
+
// Mixed with a transaction.
|
|
243
|
+
db.apply_atomic_transaction("tx-1", None, &[], &user_order_audit(), None)?;
|
|
244
|
+
db.insert("users:solo2", json!({ "id": "solo2" }))?;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
let reopened = FeltDb::open(&path)?;
|
|
248
|
+
assert!(present(&reopened, "users:solo"), "single writes must still recover");
|
|
249
|
+
assert!(present(&reopened, "users:solo2"));
|
|
250
|
+
assert_eq!(visible_count(&reopened), 3, "transaction rows recover alongside them");
|
|
251
|
+
Ok(())
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
#[test]
|
|
255
|
+
fn deletes_participate_in_a_transaction() -> Result<(), Box<dyn std::error::Error>> {
|
|
256
|
+
let dir = TempDir::new()?;
|
|
257
|
+
let path = dir.path().join("app.log");
|
|
258
|
+
|
|
259
|
+
{
|
|
260
|
+
let db = FeltDb::open(&path)?;
|
|
261
|
+
db.apply_atomic_transaction("seed", None, &[], &user_order_audit(), None)?;
|
|
262
|
+
// Delete one row and create another, atomically.
|
|
263
|
+
db.apply_atomic_transaction(
|
|
264
|
+
"move",
|
|
265
|
+
None,
|
|
266
|
+
&[],
|
|
267
|
+
&[
|
|
268
|
+
AtomicMutation {
|
|
269
|
+
capability: "orders".to_string(),
|
|
270
|
+
key: "orders:o1".to_string(),
|
|
271
|
+
value: None,
|
|
272
|
+
},
|
|
273
|
+
mutation("orders", "orders:o2", json!({ "id": "o2", "total": 42 })),
|
|
274
|
+
],
|
|
275
|
+
None,
|
|
276
|
+
)?;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
let reopened = FeltDb::open(&path)?;
|
|
280
|
+
assert!(!present(&reopened, "orders:o1"), "the delete must persist");
|
|
281
|
+
assert!(present(&reopened, "orders:o2"), "the insert must persist");
|
|
282
|
+
assert!(present(&reopened, "users:u1"), "untouched rows are kept");
|
|
283
|
+
Ok(())
|
|
284
|
+
}
|
|
285
|
+
}
|