@cero-base/core 1.15.0 → 1.15.1
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/package.json +1 -1
- package/src/database/index.js +21 -7
package/package.json
CHANGED
package/src/database/index.js
CHANGED
|
@@ -195,13 +195,16 @@ export class Database extends ReadyResource {
|
|
|
195
195
|
// no cero row records another writer's oplog length to fall back to.
|
|
196
196
|
isTrusted: async (writer, view) => {
|
|
197
197
|
try {
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
//
|
|
202
|
-
//
|
|
203
|
-
|
|
204
|
-
|
|
198
|
+
const row = await bounded(view.get(`@${this.ns}/devices`, { id: toId(writer) }))
|
|
199
|
+
if (!row) return false
|
|
200
|
+
if (row.v) return true
|
|
201
|
+
// only where the view PROVABLY holds no device yet (a boot's
|
|
202
|
+
// genesis-era reference) may the genesis writer vouch — its core IS
|
|
203
|
+
// the db key, and its signatures are unforgeable. Everyone else
|
|
204
|
+
// stays refused: an empty view is the window an ex-member targets.
|
|
205
|
+
const any = await bounded(view.find(`@${this.ns}/devices`, { limit: 1 }).toArray())
|
|
206
|
+
if (!any) return false
|
|
207
|
+
return any.v.length === 0 && !!this.key && b4a.equals(writer, this.key)
|
|
205
208
|
} catch {
|
|
206
209
|
return false
|
|
207
210
|
}
|
|
@@ -1240,6 +1243,17 @@ export class Database extends ReadyResource {
|
|
|
1240
1243
|
}
|
|
1241
1244
|
}
|
|
1242
1245
|
|
|
1246
|
+
// A trust decision reads a historic checkout view, whose blocks may not be
|
|
1247
|
+
// servable yet — an unbounded read there wedges autobee's drain forever. The
|
|
1248
|
+
// value is wrapped so a timeout (null) is never mistaken for what the read
|
|
1249
|
+
// would have returned; undecidable in time means "not trusted", and the
|
|
1250
|
+
// caller retries.
|
|
1251
|
+
const bounded = (promise, ms = 2000) =>
|
|
1252
|
+
Promise.race([
|
|
1253
|
+
promise.then((v) => ({ v })),
|
|
1254
|
+
new Promise((resolve) => setTimeout(() => resolve(null), ms))
|
|
1255
|
+
])
|
|
1256
|
+
|
|
1243
1257
|
// Fields the write path stamps itself — always allowed even if not user-declared.
|
|
1244
1258
|
const SYSTEM_FIELDS = new Set(['id', 'memberId', 'index', 'createdAt', 'updatedAt'])
|
|
1245
1259
|
|