js-bao 0.12.0-alpha.19 → 0.12.0-alpha.20
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/browser.cjs +244 -133
- package/dist/browser.d.cts +129 -1
- package/dist/browser.d.ts +129 -1
- package/dist/browser.js +244 -133
- package/dist/client.cjs +2 -0
- package/dist/client.d.cts +6 -0
- package/dist/client.d.ts +6 -0
- package/dist/client.js +2 -0
- package/dist/cloudflare-do.cjs +2 -0
- package/dist/cloudflare-do.d.cts +6 -0
- package/dist/cloudflare-do.d.ts +6 -0
- package/dist/cloudflare-do.js +2 -0
- package/dist/cloudflare.cjs +2 -0
- package/dist/cloudflare.d.cts +6 -0
- package/dist/cloudflare.d.ts +6 -0
- package/dist/cloudflare.js +2 -0
- package/dist/codegen-v2.cjs +76 -3
- package/dist/format2-worker.js +10 -1
- package/dist/index.cjs +257 -143
- package/dist/index.d.cts +552 -107
- package/dist/index.d.ts +552 -107
- package/dist/index.js +254 -143
- package/dist/node.cjs +249 -133
- package/dist/node.d.cts +129 -1
- package/dist/node.d.ts +129 -1
- package/dist/node.js +246 -133
- package/package.json +1 -1
package/dist/browser.cjs
CHANGED
|
@@ -5139,10 +5139,12 @@ var init_reservedFieldNames = __esm({
|
|
|
5139
5139
|
}
|
|
5140
5140
|
},
|
|
5141
5141
|
exempt: {
|
|
5142
|
+
Fields: "the Swift model's field-token type, which a model with a field of the same name names FieldTokens instead; not a JavaScript record member",
|
|
5142
5143
|
aggregate: "a static read on the Swift model, which a field of the same name coexists with; not a JavaScript record member",
|
|
5143
5144
|
autoStampFields: "a static on the Swift model, which a field of the same name coexists with; not a JavaScript record member",
|
|
5144
5145
|
count: "a static read on the Swift model, which a field of the same name coexists with; not a JavaScript record member",
|
|
5145
5146
|
encode: "the Swift model's labelled encode(to:), which a field of the same name coexists with; not a JavaScript record member",
|
|
5147
|
+
fields: "a static on the Swift model (its field tokens), which a field of the same name coexists with; not a JavaScript record member",
|
|
5146
5148
|
find: "a static read on the Swift model, which a field of the same name coexists with; not a JavaScript record member",
|
|
5147
5149
|
findAll: "a static read on the Swift model, which a field of the same name coexists with; not a JavaScript record member",
|
|
5148
5150
|
findByUnique: "a static read on the Swift model, which a field of the same name coexists with; not a JavaScript record member",
|
|
@@ -12842,9 +12844,9 @@ var init_BaseModel = __esm({
|
|
|
12842
12844
|
}
|
|
12843
12845
|
// Keep toJSON for backward compatibility, but delegate to getCurrentJSState
|
|
12844
12846
|
toJSON() {
|
|
12845
|
-
const
|
|
12847
|
+
const state2 = this.getCurrentJSState();
|
|
12846
12848
|
const names = fieldNamesOfClass(this.constructor);
|
|
12847
|
-
return names ? toCurrentRow(() => names, "",
|
|
12849
|
+
return names ? toCurrentRow(() => names, "", state2) : state2;
|
|
12848
12850
|
}
|
|
12849
12851
|
/**
|
|
12850
12852
|
* Refuse a read through a class whose ORM instance has been destroyed
|
|
@@ -14499,7 +14501,9 @@ __export(browser_exports, {
|
|
|
14499
14501
|
countViewRows: () => countViewRows,
|
|
14500
14502
|
currentNameOf: () => currentNameOf,
|
|
14501
14503
|
db3JsonText: () => db3JsonText,
|
|
14504
|
+
db3TypeRegistry: () => db3TypeRegistry,
|
|
14502
14505
|
db3ViewTranslator: () => db3ViewTranslator,
|
|
14506
|
+
declareDb3Types: () => declareDb3Types,
|
|
14503
14507
|
declareFieldNameTypes: () => declareFieldNameTypes,
|
|
14504
14508
|
declaredTypeProblem: () => declaredTypeProblem,
|
|
14505
14509
|
declineRecordLogIndex: () => declineRecordLogIndex,
|
|
@@ -14571,6 +14575,7 @@ __export(browser_exports, {
|
|
|
14571
14575
|
refusedWritesOf: () => refusedWritesOf,
|
|
14572
14576
|
registerFunctionDefault: () => registerFunctionDefault,
|
|
14573
14577
|
requestStoragePersistence: () => requestStoragePersistence,
|
|
14578
|
+
resetDb3TypesForTesting: () => resetDb3TypesForTesting,
|
|
14574
14579
|
resetJsBao: () => resetJsBao,
|
|
14575
14580
|
resolveChunkOrdinal: () => resolveChunkOrdinal,
|
|
14576
14581
|
resolveUpsertTarget: () => resolveUpsertTarget,
|
|
@@ -16620,15 +16625,15 @@ function heldClearedOf(sql, docId) {
|
|
|
16620
16625
|
if (!docs) held.set(sql, docs = /* @__PURE__ */ new Map());
|
|
16621
16626
|
if (docs.has(docId)) return docs.get(docId);
|
|
16622
16627
|
let cleared = null;
|
|
16623
|
-
let
|
|
16628
|
+
let state2;
|
|
16624
16629
|
try {
|
|
16625
|
-
[
|
|
16630
|
+
[state2] = Array.from(sql.exec(`SELECT typed, db3_type FROM record_log_state WHERE doc_id = ?`, docId));
|
|
16626
16631
|
} catch {
|
|
16627
16632
|
return null;
|
|
16628
16633
|
}
|
|
16629
|
-
if (
|
|
16634
|
+
if (state2?.typed === "yes" && typeof state2.db3_type === "string") {
|
|
16630
16635
|
try {
|
|
16631
|
-
const map = JSON.parse(
|
|
16636
|
+
const map = JSON.parse(state2.db3_type).cleared;
|
|
16632
16637
|
if (map && typeof map === "object") {
|
|
16633
16638
|
const entries = Object.entries(map).filter(([, names]) => Array.isArray(names) && names.length > 0);
|
|
16634
16639
|
if (entries.length) cleared = new Map(entries.map(([model, names]) => [model, new Set(names.map(String))]));
|
|
@@ -18275,8 +18280,8 @@ function storeIndexReadOptions(sql, model, documents, textIndex, vectorIndex) {
|
|
|
18275
18280
|
const searched = { ...textIndex ? { textIndex } : {}, ...vectorIndex ? { vectorIndex } : {} };
|
|
18276
18281
|
if (documents.length !== 1) return searched;
|
|
18277
18282
|
const [docId] = documents;
|
|
18278
|
-
const [
|
|
18279
|
-
const localOnly = Number(
|
|
18283
|
+
const [state2] = Array.from(sql.exec(`SELECT local_only FROM record_log_state WHERE doc_id = ?`, docId));
|
|
18284
|
+
const localOnly = Number(state2?.local_only ?? 0) === 1;
|
|
18280
18285
|
const members = Array.from(
|
|
18281
18286
|
sql.exec(`SELECT 1 FROM record_log_indexes WHERE doc_id = ? AND model = ? AND members IS NOT NULL LIMIT 1`, docId, model)
|
|
18282
18287
|
).length > 0;
|
|
@@ -18325,10 +18330,10 @@ function nearIndexOf(sql, model, filter, include, documents, support, deviceInde
|
|
|
18325
18330
|
return nearRead(near, { table: index.table, annTable: index.annTable, distance: index.vector.distance }, vector);
|
|
18326
18331
|
}
|
|
18327
18332
|
function declaredFieldOf(sql, docId, model, field) {
|
|
18328
|
-
const [
|
|
18329
|
-
if (
|
|
18333
|
+
const [state2] = Array.from(sql.exec(`SELECT typed, db3_type FROM record_log_state WHERE doc_id = ?`, docId));
|
|
18334
|
+
if (state2?.typed !== "yes" || typeof state2.db3_type !== "string") return null;
|
|
18330
18335
|
try {
|
|
18331
|
-
const held2 = JSON.parse(
|
|
18336
|
+
const held2 = JSON.parse(state2.db3_type);
|
|
18332
18337
|
const fields = held2.models?.[model];
|
|
18333
18338
|
if (!fields) return null;
|
|
18334
18339
|
const kind = Object.prototype.hasOwnProperty.call(fields, field) ? fields[field] : null;
|
|
@@ -19257,9 +19262,9 @@ init_types();
|
|
|
19257
19262
|
var keyText = (key) => recordKeyString(key);
|
|
19258
19263
|
var RECORD_LOG_UNBATCHABLE_ID = /\u0000|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/;
|
|
19259
19264
|
var isStringArray2 = (value) => Array.isArray(value) && value.every((member) => typeof member === "string");
|
|
19260
|
-
var copyReceipts = (
|
|
19261
|
-
...
|
|
19262
|
-
attempts:
|
|
19265
|
+
var copyReceipts = (state2) => ({
|
|
19266
|
+
...state2,
|
|
19267
|
+
attempts: state2.attempts.map((a) => ({ ...a, ...a.replaced ? { replaced: [...a.replaced] } : {} }))
|
|
19263
19268
|
});
|
|
19264
19269
|
var RecordLogClient = class {
|
|
19265
19270
|
/**
|
|
@@ -19293,9 +19298,9 @@ var RecordLogClient = class {
|
|
|
19293
19298
|
* pending log; the store applies it to the view as a guess.
|
|
19294
19299
|
*/
|
|
19295
19300
|
write(m, more = {}) {
|
|
19296
|
-
const
|
|
19301
|
+
const state2 = this.tables.writerState(this.writer);
|
|
19297
19302
|
const entry = {
|
|
19298
|
-
seq:
|
|
19303
|
+
seq: state2.nextSeq,
|
|
19299
19304
|
e: this.tables.epochs().open,
|
|
19300
19305
|
k: this.tables.cursor(),
|
|
19301
19306
|
m,
|
|
@@ -19303,7 +19308,7 @@ var RecordLogClient = class {
|
|
|
19303
19308
|
...more.upsertOn !== void 0 ? { upsertOn: more.upsertOn } : {},
|
|
19304
19309
|
...more.ts !== void 0 ? { ts: more.ts } : {}
|
|
19305
19310
|
};
|
|
19306
|
-
this.tables.setWriterState(this.writer, { ...
|
|
19311
|
+
this.tables.setWriterState(this.writer, { ...state2, nextSeq: state2.nextSeq + 1 });
|
|
19307
19312
|
this.tables.putPending(this.writer, entry);
|
|
19308
19313
|
return entry;
|
|
19309
19314
|
}
|
|
@@ -19611,7 +19616,7 @@ var RecordLogClient = class {
|
|
|
19611
19616
|
handBack((p) => p.seq === out.seq);
|
|
19612
19617
|
return result;
|
|
19613
19618
|
}
|
|
19614
|
-
const
|
|
19619
|
+
const state2 = this.tables.writerState(writer);
|
|
19615
19620
|
if (out.scope === "record") {
|
|
19616
19621
|
const froms = /* @__PURE__ */ new Map();
|
|
19617
19622
|
for (const r of out.records) froms.set(keyText(r), { key: { model: r.model, id: r.id }, from: r.from });
|
|
@@ -19637,17 +19642,17 @@ var RecordLogClient = class {
|
|
|
19637
19642
|
const records = [];
|
|
19638
19643
|
for (const { key, from } of froms.values()) {
|
|
19639
19644
|
if (this.tables.handled(writer, key).has(from)) continue;
|
|
19640
|
-
this.tables.setHandled(writer, key, from,
|
|
19645
|
+
this.tables.setHandled(writer, key, from, state2.nextSeq);
|
|
19641
19646
|
records.push({ model: key.model, id: key.id, from });
|
|
19642
19647
|
}
|
|
19643
|
-
if (records.length) result.frames.push({ type: "record.resume", nextSeq:
|
|
19648
|
+
if (records.length) result.frames.push({ type: "record.resume", nextSeq: state2.nextSeq, records });
|
|
19644
19649
|
return result;
|
|
19645
19650
|
}
|
|
19646
|
-
const stale = out.from <
|
|
19647
|
-
handBack((p) => p.seq >= out.from && (!stale || p.seq <
|
|
19651
|
+
const stale = out.from < state2.resumedAt;
|
|
19652
|
+
handBack((p) => p.seq >= out.from && (!stale || p.seq < state2.resumedAt));
|
|
19648
19653
|
if (stale) return result;
|
|
19649
|
-
this.tables.setWriterState(writer, { ...
|
|
19650
|
-
result.frames.push({ type: "record.resume", nextSeq:
|
|
19654
|
+
this.tables.setWriterState(writer, { ...state2, resumedAt: state2.nextSeq });
|
|
19655
|
+
result.frames.push({ type: "record.resume", nextSeq: state2.nextSeq });
|
|
19651
19656
|
return result;
|
|
19652
19657
|
}
|
|
19653
19658
|
/**
|
|
@@ -19669,9 +19674,9 @@ var RecordLogClient = class {
|
|
|
19669
19674
|
this.tables.beginReplace();
|
|
19670
19675
|
const generation = this.tables.replacing?.() ?? null;
|
|
19671
19676
|
if (this.tables.receipts && this.tables.setReceipts) {
|
|
19672
|
-
const
|
|
19673
|
-
const attempts = attempt !== void 0 && generation !== null ?
|
|
19674
|
-
this.tables.setReceipts({ ...
|
|
19677
|
+
const state2 = this.tables.receipts() ?? { n: 0, since: null, attempts: [] };
|
|
19678
|
+
const attempts = attempt !== void 0 && generation !== null ? state2.attempts.map((a) => a.attempt === attempt ? { ...a, generation } : a) : state2.attempts;
|
|
19679
|
+
this.tables.setReceipts({ ...state2, since: state2.n, attempts });
|
|
19675
19680
|
}
|
|
19676
19681
|
return generation;
|
|
19677
19682
|
}
|
|
@@ -19751,16 +19756,16 @@ var RecordLogClient = class {
|
|
|
19751
19756
|
*/
|
|
19752
19757
|
settleReceipts(full, own3) {
|
|
19753
19758
|
const tables = this.tables;
|
|
19754
|
-
const
|
|
19755
|
-
if (!
|
|
19756
|
-
const since = full ?
|
|
19757
|
-
const mine = own3 === void 0 ? void 0 :
|
|
19759
|
+
const state2 = tables.receipts?.() ?? null;
|
|
19760
|
+
if (!state2 || !tables.setReceipts) return;
|
|
19761
|
+
const since = full ? state2.since : null;
|
|
19762
|
+
const mine = own3 === void 0 ? void 0 : state2.attempts.find((a) => a.attempt === own3);
|
|
19758
19763
|
const ended = (a) => a.attempt === own3 || mine !== void 0 && a.kind === mine.kind && a.id === mine.id && a.last <= mine.last || since !== null && a.last <= since;
|
|
19759
|
-
const attempts =
|
|
19760
|
-
const nextSince = full ? null :
|
|
19761
|
-
if (attempts.length ===
|
|
19762
|
-
tables.setReceipts(attempts.length || nextSince !== null ? { n:
|
|
19763
|
-
if (attempts.length <
|
|
19764
|
+
const attempts = state2.attempts.filter((a) => !ended(a));
|
|
19765
|
+
const nextSince = full ? null : state2.since;
|
|
19766
|
+
if (attempts.length === state2.attempts.length && nextSince === state2.since) return;
|
|
19767
|
+
tables.setReceipts(attempts.length || nextSince !== null ? { n: state2.n, since: nextSince, attempts } : null);
|
|
19768
|
+
if (attempts.length < state2.attempts.length) tables.keepLoads?.(attempts.map((a) => a.attempt));
|
|
19764
19769
|
}
|
|
19765
19770
|
/** Whether receipt `attempt` is still in progress in the store. */
|
|
19766
19771
|
receiptInProgress(attempt) {
|
|
@@ -19782,11 +19787,11 @@ var RecordLogClient = class {
|
|
|
19782
19787
|
*/
|
|
19783
19788
|
touchReceipt(attempt, progress = {}) {
|
|
19784
19789
|
const tables = this.receiptTables();
|
|
19785
|
-
const
|
|
19786
|
-
const at =
|
|
19787
|
-
if (!
|
|
19788
|
-
const n =
|
|
19789
|
-
const attempts = this.unresumable(
|
|
19790
|
+
const state2 = tables.receipts();
|
|
19791
|
+
const at = state2 ? state2.attempts.findIndex((a) => a.attempt === attempt) : -1;
|
|
19792
|
+
if (!state2 || at < 0) throw new RecordLogStaleReceiptError(attempt);
|
|
19793
|
+
const n = state2.n + 1;
|
|
19794
|
+
const attempts = this.unresumable(state2.attempts, { receipt: attempt });
|
|
19790
19795
|
const was = attempts[at];
|
|
19791
19796
|
attempts[at] = {
|
|
19792
19797
|
...was,
|
|
@@ -19794,7 +19799,7 @@ var RecordLogClient = class {
|
|
|
19794
19799
|
...progress.chunk ? { done: (was.done ?? 0) + 1 } : {},
|
|
19795
19800
|
...progress.completed ? { completed: true } : {}
|
|
19796
19801
|
};
|
|
19797
|
-
tables.setReceipts({ ...
|
|
19802
|
+
tables.setReceipts({ ...state2, n, attempts });
|
|
19798
19803
|
}
|
|
19799
19804
|
/**
|
|
19800
19805
|
* Confirmed rows change under the replacement in progress other than by
|
|
@@ -19807,10 +19812,10 @@ var RecordLogClient = class {
|
|
|
19807
19812
|
changedUnderReplacement(by) {
|
|
19808
19813
|
const tables = this.tables;
|
|
19809
19814
|
if ((tables.replacing?.() ?? null) === null) return;
|
|
19810
|
-
const
|
|
19811
|
-
if (!
|
|
19812
|
-
const attempts = this.unresumable(
|
|
19813
|
-
if (attempts.some((a, i) => a !==
|
|
19815
|
+
const state2 = tables.receipts?.() ?? null;
|
|
19816
|
+
if (!state2 || !tables.setReceipts) return;
|
|
19817
|
+
const attempts = this.unresumable(state2.attempts, by);
|
|
19818
|
+
if (attempts.some((a, i) => a !== state2.attempts[i])) tables.setReceipts({ ...state2, attempts });
|
|
19814
19819
|
}
|
|
19815
19820
|
/** `attempts`, the segment attempt owning the replacement in progress without its generation unless `by` is its own. */
|
|
19816
19821
|
unresumable(attempts, by) {
|
|
@@ -19843,8 +19848,8 @@ var RecordLogClient = class {
|
|
|
19843
19848
|
*/
|
|
19844
19849
|
beginReceipt(receipt) {
|
|
19845
19850
|
const tables = this.receiptTables();
|
|
19846
|
-
const
|
|
19847
|
-
const n =
|
|
19851
|
+
const state2 = tables.receipts() ?? { n: 0, since: null, attempts: [] };
|
|
19852
|
+
const n = state2.n + 1;
|
|
19848
19853
|
const attempt = `${n}.${Math.random().toString(36).slice(2, 10)}`;
|
|
19849
19854
|
const entry = {
|
|
19850
19855
|
kind: receipt.kind,
|
|
@@ -19855,7 +19860,7 @@ var RecordLogClient = class {
|
|
|
19855
19860
|
done: 0,
|
|
19856
19861
|
...receipt.kind === "load" ? { generation: tables.generation() } : {}
|
|
19857
19862
|
};
|
|
19858
|
-
tables.setReceipts({ ...
|
|
19863
|
+
tables.setReceipts({ ...state2, n, attempts: [...state2.attempts, entry] });
|
|
19859
19864
|
return attempt;
|
|
19860
19865
|
}
|
|
19861
19866
|
/**
|
|
@@ -19875,29 +19880,29 @@ var RecordLogClient = class {
|
|
|
19875
19880
|
*/
|
|
19876
19881
|
resumeReceipt(receipt) {
|
|
19877
19882
|
const tables = this.receiptTables();
|
|
19878
|
-
const
|
|
19879
|
-
if (!
|
|
19883
|
+
const state2 = tables.receipts();
|
|
19884
|
+
if (!state2) return null;
|
|
19880
19885
|
let at = -1;
|
|
19881
|
-
for (let i =
|
|
19882
|
-
const a =
|
|
19886
|
+
for (let i = state2.attempts.length - 1; i >= 0 && at < 0; i--) {
|
|
19887
|
+
const a = state2.attempts[i];
|
|
19883
19888
|
if (a.kind === receipt.kind && a.id === receipt.id && a.fingerprint === receipt.fingerprint) at = i;
|
|
19884
19889
|
}
|
|
19885
19890
|
if (at < 0) return null;
|
|
19886
|
-
const old =
|
|
19891
|
+
const old = state2.attempts[at];
|
|
19887
19892
|
const done = old.done ?? 0;
|
|
19888
19893
|
if (old.generation === void 0 || receipt.chunks !== void 0 && done > receipt.chunks) return null;
|
|
19889
19894
|
const current = old.kind === "segment" ? tables.replacing() : tables.generation();
|
|
19890
19895
|
if (current !== old.generation) return null;
|
|
19891
19896
|
if (old.kind === "segment") {
|
|
19892
|
-
const since =
|
|
19893
|
-
if (since === null ||
|
|
19897
|
+
const since = state2.since;
|
|
19898
|
+
if (since === null || state2.attempts.some((a, i) => i !== at && a.last > since)) return null;
|
|
19894
19899
|
}
|
|
19895
|
-
const n =
|
|
19900
|
+
const n = state2.n + 1;
|
|
19896
19901
|
const attempt = `${n}.${Math.random().toString(36).slice(2, 10)}`;
|
|
19897
|
-
const attempts =
|
|
19902
|
+
const attempts = state2.attempts.slice();
|
|
19898
19903
|
attempts[at] = { ...old, attempt, last: n, replaced: [...old.replaced ?? [], old.attempt] };
|
|
19899
19904
|
tables.renameLoad(old.attempt, attempt);
|
|
19900
|
-
tables.setReceipts({ ...
|
|
19905
|
+
tables.setReceipts({ ...state2, n, attempts });
|
|
19901
19906
|
return { attempt, done, completed: old.completed === true, generation: old.generation };
|
|
19902
19907
|
}
|
|
19903
19908
|
/** The latest receipt begun and not completed, or `null` when none is. */
|
|
@@ -20023,12 +20028,12 @@ var RecordLogClient = class {
|
|
|
20023
20028
|
*/
|
|
20024
20029
|
keepSegmentChunk(chunk) {
|
|
20025
20030
|
this.assertGeneration(chunk.generation);
|
|
20026
|
-
const
|
|
20027
|
-
if (!
|
|
20031
|
+
const state2 = this.receiptTables().receipts();
|
|
20032
|
+
if (!state2 || !state2.attempts.some((a) => a.attempt === chunk.attempt)) throw new RecordLogStaleReceiptError(chunk.attempt);
|
|
20028
20033
|
if (this.readBeforeClear(chunk.model, chunk.readAt)) return { mismatch: true };
|
|
20029
20034
|
const entry = this.tables.heldSegment?.()?.chunks.find((c) => c.object === chunk.object);
|
|
20030
20035
|
const same = entry !== void 0 && entry.model === chunk.model && entry.sha256 === chunk.sha256 && entry.rows === chunk.rows && entry.firstId === chunk.firstId && entry.lastId === chunk.lastId;
|
|
20031
|
-
const alone =
|
|
20036
|
+
const alone = state2.attempts.every((a) => a.attempt === chunk.attempt);
|
|
20032
20037
|
const range = { model: chunk.model, firstId: chunk.firstId, lastId: chunk.lastId };
|
|
20033
20038
|
if (!same || !alone || !this.tables.keepConfirmedRange?.({ ...range, rows: chunk.rows })) return { mismatch: true };
|
|
20034
20039
|
this.touchReceipt(chunk.attempt, { chunk: true });
|
|
@@ -20211,8 +20216,8 @@ var MemoryRecordLogTables = class {
|
|
|
20211
20216
|
receipts() {
|
|
20212
20217
|
return this.receiptValue ? copyReceipts(this.receiptValue) : null;
|
|
20213
20218
|
}
|
|
20214
|
-
setReceipts(
|
|
20215
|
-
this.receiptValue =
|
|
20219
|
+
setReceipts(state2) {
|
|
20220
|
+
this.receiptValue = state2 ? copyReceipts(state2) : null;
|
|
20216
20221
|
}
|
|
20217
20222
|
noteLoadKeys(attempt, keys) {
|
|
20218
20223
|
let named = this.loadKeys.get(attempt);
|
|
@@ -20303,10 +20308,10 @@ var MemoryRecordLogTables = class {
|
|
|
20303
20308
|
const w = this.writerOf(writer);
|
|
20304
20309
|
return { nextSeq: w.nextSeq, resumedAt: w.resumedAt };
|
|
20305
20310
|
}
|
|
20306
|
-
setWriterState(writer,
|
|
20311
|
+
setWriterState(writer, state2) {
|
|
20307
20312
|
const w = this.writerOf(writer);
|
|
20308
|
-
w.nextSeq =
|
|
20309
|
-
w.resumedAt =
|
|
20313
|
+
w.nextSeq = state2.nextSeq;
|
|
20314
|
+
w.resumedAt = state2.resumedAt;
|
|
20310
20315
|
}
|
|
20311
20316
|
pending(writer) {
|
|
20312
20317
|
return [...this.writers.get(writer)?.pending ?? []];
|
|
@@ -20699,8 +20704,8 @@ function convertToOneCopy(sql) {
|
|
|
20699
20704
|
const hasState = named.includes("record_log_state");
|
|
20700
20705
|
for (const docId of remaining) {
|
|
20701
20706
|
sql.transaction(() => {
|
|
20702
|
-
const [
|
|
20703
|
-
const replacing =
|
|
20707
|
+
const [state2] = hasState ? Array.from(sql.exec(`SELECT replacing, rows_gen FROM record_log_state WHERE doc_id = ?`, docId)) : [];
|
|
20708
|
+
const replacing = state2?.replacing === null || state2?.replacing === void 0 ? null : Number(state2.replacing);
|
|
20704
20709
|
const [top] = Array.from(sql.exec(`SELECT MAX(rowid) AS top FROM record_log_rows WHERE doc_id = ?`, docId));
|
|
20705
20710
|
const offset = Number(top?.top ?? 0) + 1;
|
|
20706
20711
|
sql.exec(
|
|
@@ -20716,7 +20721,7 @@ function convertToOneCopy(sql) {
|
|
|
20716
20721
|
`INSERT INTO ${OVERLAY_V10} (doc_id, _type, _id, _data, _gen)
|
|
20717
20722
|
SELECT v.doc_id, v._type, v._id, NULL, ? FROM record_log_view v
|
|
20718
20723
|
WHERE v.doc_id = ? AND NOT EXISTS (SELECT 1 FROM record_log_rows r WHERE r.doc_id = v.doc_id AND r._type = v._type AND r._id = v._id)`,
|
|
20719
|
-
Number(
|
|
20724
|
+
Number(state2?.rows_gen ?? 0),
|
|
20720
20725
|
docId
|
|
20721
20726
|
);
|
|
20722
20727
|
const [count] = Array.from(sql.exec(`SELECT COUNT(*) AS n FROM ${OVERLAY_V10} WHERE doc_id = ?`, docId));
|
|
@@ -20898,10 +20903,19 @@ function quote2(identifier) {
|
|
|
20898
20903
|
|
|
20899
20904
|
// src/record-log-client/store.ts
|
|
20900
20905
|
init_types();
|
|
20901
|
-
function
|
|
20902
|
-
|
|
20906
|
+
function heldTypeNameOf(state2) {
|
|
20907
|
+
if (state2?.typed !== "yes" || !state2.db3_type) return null;
|
|
20908
|
+
try {
|
|
20909
|
+
const name = JSON.parse(String(state2.db3_type)).name;
|
|
20910
|
+
return typeof name === "string" && name !== "" ? name : null;
|
|
20911
|
+
} catch {
|
|
20912
|
+
return null;
|
|
20913
|
+
}
|
|
20914
|
+
}
|
|
20915
|
+
function knownHeadOf(state2) {
|
|
20916
|
+
const head = state2?.known_head;
|
|
20903
20917
|
if (head === null || head === void 0) return { knownHead: null, knownHeadAt: null };
|
|
20904
|
-
const at =
|
|
20918
|
+
const at = state2?.known_head_at;
|
|
20905
20919
|
return { knownHead: Number(head), knownHeadAt: at === null || at === void 0 ? null : Number(at) };
|
|
20906
20920
|
}
|
|
20907
20921
|
function localIndexesText(indexes) {
|
|
@@ -20933,8 +20947,8 @@ function recordLogRowRevision(row) {
|
|
|
20933
20947
|
return `${text.length}:${(4294967296 * (2097151 & h2) + (h1 >>> 0)).toString(36)}`;
|
|
20934
20948
|
}
|
|
20935
20949
|
var keyText2 = (key) => recordKeyString(key);
|
|
20936
|
-
function latestReceipt(
|
|
20937
|
-
const last =
|
|
20950
|
+
function latestReceipt(state2) {
|
|
20951
|
+
const last = state2?.attempts[state2.attempts.length - 1];
|
|
20938
20952
|
if (!last) return null;
|
|
20939
20953
|
if (last.fingerprint === void 0) return { kind: last.kind, id: last.id };
|
|
20940
20954
|
return { kind: last.kind, id: last.id, done: last.done ?? 0, completed: last.completed === true };
|
|
@@ -21038,20 +21052,20 @@ var SqlRecordLogTables = class {
|
|
|
21038
21052
|
this.sql.exec(`UPDATE record_log_state SET cursor = ? WHERE doc_id = ?`, cursor, this.docId);
|
|
21039
21053
|
}
|
|
21040
21054
|
knownHead() {
|
|
21041
|
-
const
|
|
21042
|
-
if (
|
|
21043
|
-
return { head: Number(
|
|
21055
|
+
const state2 = this.state();
|
|
21056
|
+
if (state2?.known_head === null || state2?.known_head === void 0) return null;
|
|
21057
|
+
return { head: Number(state2.known_head), at: Number(state2.known_head_at ?? 0) };
|
|
21044
21058
|
}
|
|
21045
21059
|
setKnownHead(head, at) {
|
|
21046
21060
|
this.ensureState();
|
|
21047
21061
|
this.sql.exec(`UPDATE record_log_state SET known_head = ?, known_head_at = ? WHERE doc_id = ?`, head, at, this.docId);
|
|
21048
21062
|
}
|
|
21049
21063
|
epochs() {
|
|
21050
|
-
const
|
|
21064
|
+
const state2 = this.state();
|
|
21051
21065
|
return {
|
|
21052
|
-
open: Number(
|
|
21053
|
-
grant: Number(
|
|
21054
|
-
entries: Number(
|
|
21066
|
+
open: Number(state2?.open_epoch ?? RECORD_LOG_FIRST_EPOCH),
|
|
21067
|
+
grant: Number(state2?.grant_epoch ?? RECORD_LOG_FIRST_EPOCH + 1),
|
|
21068
|
+
entries: Number(state2?.epoch_entries ?? RECORD_LOG_DEFAULT_EPOCH_ENTRIES)
|
|
21055
21069
|
};
|
|
21056
21070
|
}
|
|
21057
21071
|
setEpochs(epochs) {
|
|
@@ -21078,12 +21092,12 @@ var SqlRecordLogTables = class {
|
|
|
21078
21092
|
}
|
|
21079
21093
|
/** The typed mark, the type and its held declarations, vector fields and enforced enums. */
|
|
21080
21094
|
typeState() {
|
|
21081
|
-
const
|
|
21082
|
-
const typed =
|
|
21095
|
+
const state2 = this.state();
|
|
21096
|
+
const typed = state2?.typed === "yes" ? "yes" : state2?.typed === "no" ? "no" : "unknown";
|
|
21083
21097
|
const none = { declarations: null, vectors: null, vectorsKnown: true, enums: null, enumsKnown: true, cleared: null, clearedKnown: true };
|
|
21084
|
-
if (typed !== "yes" || !
|
|
21098
|
+
if (typed !== "yes" || !state2?.db3_type) return { typed, db3Type: null, ...none };
|
|
21085
21099
|
try {
|
|
21086
|
-
const held2 = JSON.parse(String(
|
|
21100
|
+
const held2 = JSON.parse(String(state2.db3_type));
|
|
21087
21101
|
const declarations = held2.models ?? null;
|
|
21088
21102
|
return {
|
|
21089
21103
|
typed,
|
|
@@ -21162,13 +21176,13 @@ var SqlRecordLogTables = class {
|
|
|
21162
21176
|
this.sql.exec(`UPDATE record_log_state SET local_indexes = ? WHERE doc_id = ?`, JSON.stringify(sorted), this.docId);
|
|
21163
21177
|
}
|
|
21164
21178
|
generation() {
|
|
21165
|
-
const
|
|
21166
|
-
if (
|
|
21167
|
-
return Number(
|
|
21179
|
+
const state2 = this.state();
|
|
21180
|
+
if (state2?.replacing !== null && state2?.replacing !== void 0) return Number(state2.replacing);
|
|
21181
|
+
return Number(state2?.rows_gen ?? 0);
|
|
21168
21182
|
}
|
|
21169
21183
|
replacing() {
|
|
21170
|
-
const
|
|
21171
|
-
return
|
|
21184
|
+
const state2 = this.state();
|
|
21185
|
+
return state2?.replacing === null || state2?.replacing === void 0 ? null : Number(state2.replacing);
|
|
21172
21186
|
}
|
|
21173
21187
|
receipts() {
|
|
21174
21188
|
const text = this.state()?.receipt;
|
|
@@ -21177,9 +21191,9 @@ var SqlRecordLogTables = class {
|
|
|
21177
21191
|
if (Array.isArray(stored.attempts)) return stored;
|
|
21178
21192
|
return stored.kind && stored.id ? { n: 0, since: null, attempts: [{ kind: stored.kind, id: stored.id, attempt: "", last: 0 }] } : null;
|
|
21179
21193
|
}
|
|
21180
|
-
setReceipts(
|
|
21194
|
+
setReceipts(state2) {
|
|
21181
21195
|
this.ensureState();
|
|
21182
|
-
this.sql.exec(`UPDATE record_log_state SET receipt = ? WHERE doc_id = ?`,
|
|
21196
|
+
this.sql.exec(`UPDATE record_log_state SET receipt = ? WHERE doc_id = ?`, state2 ? JSON.stringify(state2) : null, this.docId);
|
|
21183
21197
|
}
|
|
21184
21198
|
heldSegment() {
|
|
21185
21199
|
const text = this.state()?.segment;
|
|
@@ -21195,12 +21209,12 @@ var SqlRecordLogTables = class {
|
|
|
21195
21209
|
* generation, and the completed generation.
|
|
21196
21210
|
*/
|
|
21197
21211
|
writeContext() {
|
|
21198
|
-
const
|
|
21199
|
-
const replacement =
|
|
21200
|
-
const completed = Number(
|
|
21212
|
+
const state2 = this.state();
|
|
21213
|
+
const replacement = state2?.replacing === null || state2?.replacing === void 0 ? null : Number(state2.replacing);
|
|
21214
|
+
const completed = Number(state2?.rows_gen ?? 0);
|
|
21201
21215
|
return {
|
|
21202
21216
|
replacing: replacement !== null,
|
|
21203
|
-
staged: replacement !== null &&
|
|
21217
|
+
staged: replacement !== null && state2?.staged !== null && state2?.staged !== void 0 && Number(state2.staged) === replacement,
|
|
21204
21218
|
replacement,
|
|
21205
21219
|
generation: replacement ?? completed,
|
|
21206
21220
|
completed
|
|
@@ -21260,9 +21274,9 @@ var SqlRecordLogTables = class {
|
|
|
21260
21274
|
);
|
|
21261
21275
|
}
|
|
21262
21276
|
keepConfirmedRange(range) {
|
|
21263
|
-
const
|
|
21264
|
-
if (
|
|
21265
|
-
const completed = Number(
|
|
21277
|
+
const state2 = this.state();
|
|
21278
|
+
if (state2?.replacing === null || state2?.replacing === void 0) return false;
|
|
21279
|
+
const completed = Number(state2.rows_gen ?? 0);
|
|
21266
21280
|
const within = `doc_id = ? AND _type = ? AND _id >= ? AND _id <= ? AND _gen = ?`;
|
|
21267
21281
|
const bindings2 = [this.docId, range.model, range.firstId, range.lastId, completed];
|
|
21268
21282
|
const shown = `${within} AND NOT EXISTS (${OVERLAY_ROW_OF("record_log_view")})`;
|
|
@@ -21274,8 +21288,8 @@ var SqlRecordLogTables = class {
|
|
|
21274
21288
|
...bindings2
|
|
21275
21289
|
);
|
|
21276
21290
|
if (Number(count?.n ?? 0) !== range.rows) return false;
|
|
21277
|
-
this.sql.exec(`UPDATE record_log_view SET _gen = ? WHERE ${shown}`, Number(
|
|
21278
|
-
this.sql.exec(`UPDATE record_log_rows SET _gen = ? WHERE ${held2}`, Number(
|
|
21291
|
+
this.sql.exec(`UPDATE record_log_view SET _gen = ? WHERE ${shown}`, Number(state2.replacing), ...bindings2);
|
|
21292
|
+
this.sql.exec(`UPDATE record_log_rows SET _gen = ? WHERE ${held2}`, Number(state2.replacing), ...bindings2);
|
|
21279
21293
|
return true;
|
|
21280
21294
|
}
|
|
21281
21295
|
noteLoadKeys(attempt, keys) {
|
|
@@ -21766,9 +21780,9 @@ var SqlRecordLogTables = class {
|
|
|
21766
21780
|
}
|
|
21767
21781
|
/** Whether the replacement in progress is staged (the view keeps the previous completed generation). */
|
|
21768
21782
|
staged() {
|
|
21769
|
-
const
|
|
21770
|
-
if (
|
|
21771
|
-
return
|
|
21783
|
+
const state2 = this.state();
|
|
21784
|
+
if (state2?.replacing === null || state2?.replacing === void 0) return false;
|
|
21785
|
+
return state2.staged !== null && state2.staged !== void 0 && Number(state2.staged) === Number(state2.replacing);
|
|
21772
21786
|
}
|
|
21773
21787
|
/**
|
|
21774
21788
|
* The models whose view rows a staged replacement's completion changes,
|
|
@@ -21812,9 +21826,9 @@ var SqlRecordLogTables = class {
|
|
|
21812
21826
|
* is refreshed. Answers the records whose confirmed rows were removed.
|
|
21813
21827
|
*/
|
|
21814
21828
|
completeReplace() {
|
|
21815
|
-
const
|
|
21816
|
-
if (
|
|
21817
|
-
const gen = Number(
|
|
21829
|
+
const state2 = this.state();
|
|
21830
|
+
if (state2?.replacing === null || state2?.replacing === void 0) return [];
|
|
21831
|
+
const gen = Number(state2.replacing);
|
|
21818
21832
|
const docId = this.docId;
|
|
21819
21833
|
const keyOf = (r) => ({ model: String(r._type), id: String(r._id) });
|
|
21820
21834
|
const removed = rowsOf3(
|
|
@@ -21878,8 +21892,8 @@ var SqlRecordLogTables = class {
|
|
|
21878
21892
|
return removed;
|
|
21879
21893
|
}
|
|
21880
21894
|
isReplacing() {
|
|
21881
|
-
const
|
|
21882
|
-
return
|
|
21895
|
+
const state2 = this.state();
|
|
21896
|
+
return state2?.replacing !== null && state2?.replacing !== void 0;
|
|
21883
21897
|
}
|
|
21884
21898
|
buffered(l) {
|
|
21885
21899
|
return this.held.get(l);
|
|
@@ -21925,11 +21939,11 @@ var SqlRecordLogTables = class {
|
|
|
21925
21939
|
);
|
|
21926
21940
|
return { nextSeq: Number(row?.next_seq ?? 1), resumedAt: Number(row?.resumed_at ?? 0) };
|
|
21927
21941
|
}
|
|
21928
|
-
setWriterState(writer,
|
|
21942
|
+
setWriterState(writer, state2) {
|
|
21929
21943
|
this.sql.exec(
|
|
21930
21944
|
`UPDATE record_log_writers SET next_seq = ?, resumed_at = ? WHERE doc_id = ? AND writer = ?`,
|
|
21931
|
-
|
|
21932
|
-
|
|
21945
|
+
state2.nextSeq,
|
|
21946
|
+
state2.resumedAt,
|
|
21933
21947
|
this.docId,
|
|
21934
21948
|
writer
|
|
21935
21949
|
);
|
|
@@ -22271,15 +22285,15 @@ var RecordLogStore = class {
|
|
|
22271
22285
|
lowestPending: Number(row.lowest),
|
|
22272
22286
|
pending: Number(row.pending)
|
|
22273
22287
|
}));
|
|
22274
|
-
const [
|
|
22288
|
+
const [state2] = rowsOf3(this.sql, `SELECT * FROM record_log_state WHERE doc_id = ?`, this.docId);
|
|
22275
22289
|
return {
|
|
22276
22290
|
cursor: this.tables.cursor(),
|
|
22277
22291
|
rows: Number(count?.n ?? 0),
|
|
22278
22292
|
writers,
|
|
22279
22293
|
replacing: this.tables.isReplacing(),
|
|
22280
22294
|
staged: this.tables.staged(),
|
|
22281
|
-
lastCatchUpAt:
|
|
22282
|
-
...
|
|
22295
|
+
lastCatchUpAt: state2?.last_catch_up_at === null || state2?.last_catch_up_at === void 0 ? null : Number(state2.last_catch_up_at),
|
|
22296
|
+
...state2 ? { localOnly: Number(state2.local_only ?? 0) === 1, ...knownHeadOf(state2), db3Type: heldTypeNameOf(state2) } : {}
|
|
22283
22297
|
};
|
|
22284
22298
|
}
|
|
22285
22299
|
/** This client's writer, or `null` before one is minted. */
|
|
@@ -22405,13 +22419,13 @@ var RecordLogStore = class {
|
|
|
22405
22419
|
}
|
|
22406
22420
|
/** The permission mark alone. */
|
|
22407
22421
|
permissionMark() {
|
|
22408
|
-
const [
|
|
22409
|
-
return
|
|
22422
|
+
const [state2] = rowsOf3(this.sql, `SELECT permission FROM record_log_state WHERE doc_id = ?`, this.docId);
|
|
22423
|
+
return state2?.permission ?? null;
|
|
22410
22424
|
}
|
|
22411
22425
|
/** Everything a facade mirrors, in one read. */
|
|
22412
22426
|
marks() {
|
|
22413
22427
|
const epochs = this.tables.epochs();
|
|
22414
|
-
const [
|
|
22428
|
+
const [state2] = rowsOf3(this.sql, `SELECT * FROM record_log_state WHERE doc_id = ?`, this.docId);
|
|
22415
22429
|
const writer = this.writer();
|
|
22416
22430
|
const writerState = writer ? this.tables.writerState(writer) : null;
|
|
22417
22431
|
const [pending] = writer ? rowsOf3(
|
|
@@ -22424,11 +22438,11 @@ var RecordLogStore = class {
|
|
|
22424
22438
|
cursor: this.tables.cursor(),
|
|
22425
22439
|
...epochs,
|
|
22426
22440
|
constraints: this.tables.constraints(),
|
|
22427
|
-
permission:
|
|
22441
|
+
permission: state2?.permission ?? null,
|
|
22428
22442
|
replacing: this.tables.isReplacing(),
|
|
22429
22443
|
replacement: this.tables.replacing(),
|
|
22430
22444
|
staged: this.tables.staged(),
|
|
22431
|
-
lastCatchUpAt:
|
|
22445
|
+
lastCatchUpAt: state2?.last_catch_up_at ?? null,
|
|
22432
22446
|
writer,
|
|
22433
22447
|
nextSeq: writerState?.nextSeq ?? 1,
|
|
22434
22448
|
resumedAt: writerState?.resumedAt ?? 0,
|
|
@@ -22439,9 +22453,9 @@ var RecordLogStore = class {
|
|
|
22439
22453
|
segment: this.tables.heldSegment(),
|
|
22440
22454
|
...this.tables.typeState(),
|
|
22441
22455
|
models: this.modelsHeld(),
|
|
22442
|
-
localOnly: Number(
|
|
22456
|
+
localOnly: Number(state2?.local_only ?? 0) === 1,
|
|
22443
22457
|
localIndexes: this.tables.localIndexes(),
|
|
22444
|
-
...knownHeadOf(
|
|
22458
|
+
...knownHeadOf(state2)
|
|
22445
22459
|
};
|
|
22446
22460
|
}
|
|
22447
22461
|
/**
|
|
@@ -27672,9 +27686,9 @@ var RecordLogStoreAsync = class _RecordLogStoreAsync {
|
|
|
27672
27686
|
});
|
|
27673
27687
|
}
|
|
27674
27688
|
/** Record epochs, constraints, permission and what the room said of the db3's type; refresh the mirror. */
|
|
27675
|
-
setState(
|
|
27689
|
+
setState(state2) {
|
|
27676
27690
|
return this.run("setState", async () => {
|
|
27677
|
-
this.mirror = await this.host.dispatch({ kind: "setState", writer: this.writer(), ...
|
|
27691
|
+
this.mirror = await this.host.dispatch({ kind: "setState", writer: this.writer(), ...state2 });
|
|
27678
27692
|
return this.mirror;
|
|
27679
27693
|
});
|
|
27680
27694
|
}
|
|
@@ -28583,6 +28597,11 @@ var RecordLogDocumentSession = class {
|
|
|
28583
28597
|
roomStreams = false;
|
|
28584
28598
|
/** The room refused this client's wire version (`DB3_CLIENT_OUTDATED`): the session does not open again. */
|
|
28585
28599
|
outdated = false;
|
|
28600
|
+
/**
|
|
28601
|
+
* This client does not open the db3's type (`DB3_TYPE_UNKNOWN_TO_CLIENT`):
|
|
28602
|
+
* the session opens again only once its host accepts the type.
|
|
28603
|
+
*/
|
|
28604
|
+
typeRefused = false;
|
|
28586
28605
|
/** When the first of the `building` answers in a row arrived; `null` when the last answer was another form. */
|
|
28587
28606
|
buildingSince = null;
|
|
28588
28607
|
/** Streamed catch-ups: pages applied, pages ignored as another stream's, credits sent. */
|
|
@@ -28741,6 +28760,16 @@ var RecordLogDocumentSession = class {
|
|
|
28741
28760
|
Logger.debug(`[record-log] ${this.docId}: not opened: the room needs a newer client (DB3_CLIENT_OUTDATED)`);
|
|
28742
28761
|
return;
|
|
28743
28762
|
}
|
|
28763
|
+
const heldType = this.store.marks().typed === "yes" ? this.store.marks().db3Type?.name : void 0;
|
|
28764
|
+
if (heldType && this.host.acceptsType?.(this.docId, heldType) === false) {
|
|
28765
|
+
Logger.debug(`[record-log] ${this.docId}: not opened: its type ${heldType} is not one this client opens (DB3_TYPE_UNKNOWN_TO_CLIENT)`);
|
|
28766
|
+
if (!this.typeRefused) {
|
|
28767
|
+
this.typeRefused = true;
|
|
28768
|
+
this.host.syncFailed(this.docId, "DB3_TYPE_UNKNOWN_TO_CLIENT");
|
|
28769
|
+
}
|
|
28770
|
+
return;
|
|
28771
|
+
}
|
|
28772
|
+
this.typeRefused = false;
|
|
28744
28773
|
if (!this.connected()) {
|
|
28745
28774
|
this.host.syncFailed(this.docId, "not connected");
|
|
28746
28775
|
return;
|
|
@@ -28749,9 +28778,9 @@ var RecordLogDocumentSession = class {
|
|
|
28749
28778
|
this.phase = "opening";
|
|
28750
28779
|
const generation = this.generation;
|
|
28751
28780
|
const own3 = this.store.writer();
|
|
28752
|
-
const
|
|
28781
|
+
const state2 = await this.store.storedState();
|
|
28753
28782
|
if (generation !== this.generation) return;
|
|
28754
|
-
this.orphans =
|
|
28783
|
+
this.orphans = state2.writers.filter((w) => w.writer !== own3 && w.pending > 0).map((w) => ({ writer: w.writer, lowestPending: w.lowestPending }));
|
|
28755
28784
|
if (this.orphans.length) {
|
|
28756
28785
|
Logger.info(`[record-log] ${this.docId}: draining ${this.orphans.length} earlier session writer(s) before opening`);
|
|
28757
28786
|
}
|
|
@@ -29095,6 +29124,12 @@ var RecordLogDocumentSession = class {
|
|
|
29095
29124
|
Logger.debug(`[record-log] ${this.docId}: the room speaks wire version ${frame.wireVersion}; this client ${RECORD_LOG_WIRE_VERSION}`);
|
|
29096
29125
|
}
|
|
29097
29126
|
const generation = this.generation;
|
|
29127
|
+
const said = typeOfOpened(frame, this.docId);
|
|
29128
|
+
if (said.type?.typed === "yes" && this.host.acceptsType?.(this.docId, said.type.db3Type.name) === false) {
|
|
29129
|
+
await this.store.setState({ type: said.type });
|
|
29130
|
+
if (generation !== this.generation) return;
|
|
29131
|
+
return this.endForType(said.type.db3Type.name);
|
|
29132
|
+
}
|
|
29098
29133
|
const epochs = frame.epochs ?? {};
|
|
29099
29134
|
const current = Number(epochs.current ?? 1);
|
|
29100
29135
|
const high = Number(epochs.high ?? current);
|
|
@@ -29109,7 +29144,7 @@ var RecordLogDocumentSession = class {
|
|
|
29109
29144
|
// refusal it answered before is over.
|
|
29110
29145
|
...!this.current.orphan && this.store.marks().permission === "refused" ? { permission: null } : {},
|
|
29111
29146
|
// The room says whether the db3 is typed, and by what (#5020).
|
|
29112
|
-
...
|
|
29147
|
+
...said,
|
|
29113
29148
|
// Its head, to a client at wire version 3 (#5221).
|
|
29114
29149
|
...heardOf(frame, receivedAt)
|
|
29115
29150
|
});
|
|
@@ -30209,6 +30244,18 @@ var RecordLogDocumentSession = class {
|
|
|
30209
30244
|
* (#4799), or `DOCUMENT_DELETED` when the db3 was deleted (#5049). The own
|
|
30210
30245
|
* writer's next `record.opened` lifts the mark.
|
|
30211
30246
|
*/
|
|
30247
|
+
/**
|
|
30248
|
+
* End the conversation for a type this client does not open
|
|
30249
|
+
* (`DB3_TYPE_UNKNOWN_TO_CLIENT`): nothing more is sent, unsent writes stay
|
|
30250
|
+
* in the store, and the session opens again only once its host accepts
|
|
30251
|
+
* the type. The host closes the db3 on the socket.
|
|
30252
|
+
*/
|
|
30253
|
+
endForType(name) {
|
|
30254
|
+
Logger.debug(`[record-log] ${this.docId}: its type ${name} is not one this client opens; the session ends (DB3_TYPE_UNKNOWN_TO_CLIENT)`);
|
|
30255
|
+
this.typeRefused = true;
|
|
30256
|
+
this.disconnected();
|
|
30257
|
+
this.host.syncFailed(this.docId, "DB3_TYPE_UNKNOWN_TO_CLIENT");
|
|
30258
|
+
}
|
|
30212
30259
|
async accessRefused(frame) {
|
|
30213
30260
|
if (this.phase === "closed") return;
|
|
30214
30261
|
const reason = frame.code === "DB3_SYNC_OFF" || frame.code === "DOCUMENT_DELETED" ? frame.code : "ACCESS_DENIED";
|
|
@@ -30251,6 +30298,7 @@ var RecordLogDocumentSession = class {
|
|
|
30251
30298
|
await this.store.setState({
|
|
30252
30299
|
type: { typed: "yes", db3Type: { name: frame.db3Type, hash: held2?.name === frame.db3Type ? held2.hash : null } }
|
|
30253
30300
|
});
|
|
30301
|
+
if (this.host.acceptsType?.(this.docId, frame.db3Type) === false) return this.endForType(frame.db3Type);
|
|
30254
30302
|
}
|
|
30255
30303
|
this.host.declared?.(this.docId);
|
|
30256
30304
|
return;
|
|
@@ -30398,6 +30446,14 @@ var RecordLogSessions = class {
|
|
|
30398
30446
|
setConnection(connection) {
|
|
30399
30447
|
this.connection = connection;
|
|
30400
30448
|
}
|
|
30449
|
+
typePredicate = null;
|
|
30450
|
+
/**
|
|
30451
|
+
* Say which db3 types this instance's sessions open (`null`: every type).
|
|
30452
|
+
* Asked as {@link RecordLogSessionHost.acceptsType} is.
|
|
30453
|
+
*/
|
|
30454
|
+
setTypePredicate(predicate) {
|
|
30455
|
+
this.typePredicate = predicate;
|
|
30456
|
+
}
|
|
30401
30457
|
/** Hear that a document's open completed. Returns an unsubscribe. */
|
|
30402
30458
|
onSynced(listener) {
|
|
30403
30459
|
this.syncedListeners.add(listener);
|
|
@@ -30504,6 +30560,7 @@ var RecordLogSessions = class {
|
|
|
30504
30560
|
}
|
|
30505
30561
|
},
|
|
30506
30562
|
now: () => this.host.now?.() ?? Date.now(),
|
|
30563
|
+
acceptsType: (id, name) => this.typePredicate?.(id, name) ?? true,
|
|
30507
30564
|
status: (id, status) => {
|
|
30508
30565
|
for (const listener of [...this.statusListeners]) {
|
|
30509
30566
|
try {
|
|
@@ -31001,10 +31058,10 @@ function dropLocalIndex(declarations, registrations, name) {
|
|
|
31001
31058
|
|
|
31002
31059
|
// src/record-log-client/binding.ts
|
|
31003
31060
|
var RECORD_LOG_TEARDOWN_DRAIN_BOUND_MS = 2e3;
|
|
31004
|
-
function isRecordLogResident(
|
|
31005
|
-
if (createdLocally ||
|
|
31006
|
-
if (
|
|
31007
|
-
return !
|
|
31061
|
+
function isRecordLogResident(state2, createdLocally = false) {
|
|
31062
|
+
if (createdLocally || state2.localOnly === true) return true;
|
|
31063
|
+
if (state2.lastCatchUpAt === null || state2.lastCatchUpAt === void 0) return false;
|
|
31064
|
+
return !state2.replacing || state2.staged === true;
|
|
31008
31065
|
}
|
|
31009
31066
|
function declarationOf(schema) {
|
|
31010
31067
|
const fields = {};
|
|
@@ -32004,6 +32061,7 @@ var DocumentManagerImpl = class {
|
|
|
32004
32061
|
const binding = this.recordLog;
|
|
32005
32062
|
return {
|
|
32006
32063
|
setConnection: (connection) => binding.sessions.setConnection(connection),
|
|
32064
|
+
setTypePredicate: (predicate) => binding.sessions.setTypePredicate(predicate),
|
|
32007
32065
|
isRecordLogDocument: (docId) => binding.storeOf(docId) !== null,
|
|
32008
32066
|
start: (docId) => binding.sessions.start(docId),
|
|
32009
32067
|
receive: (docId, frame) => binding.sessions.receive(docId, frame),
|
|
@@ -34010,7 +34068,19 @@ var SWIFT_CODEGEN_RESERVED_NAMES = [
|
|
|
34010
34068
|
"UniqueConstraint",
|
|
34011
34069
|
"UniqueField",
|
|
34012
34070
|
"UpsertMode",
|
|
34013
|
-
"Void"
|
|
34071
|
+
"Void",
|
|
34072
|
+
// The typed reads: `Fields` (or `FieldTokens`), its tokens and `TypedQueryModel`.
|
|
34073
|
+
"FieldTokens",
|
|
34074
|
+
"Fields",
|
|
34075
|
+
"ModelBooleanField",
|
|
34076
|
+
"ModelDateField",
|
|
34077
|
+
"ModelEnumField",
|
|
34078
|
+
"ModelIdField",
|
|
34079
|
+
"ModelJSONField",
|
|
34080
|
+
"ModelNumberField",
|
|
34081
|
+
"ModelStringField",
|
|
34082
|
+
"ModelStringSetField",
|
|
34083
|
+
"TypedQueryModel"
|
|
34014
34084
|
];
|
|
34015
34085
|
var QUERY_TABLE_COLUMNS = ["id", "type"];
|
|
34016
34086
|
var TYPE_PRECEDENCE = ["string", "number", "boolean", "stringset"];
|
|
@@ -34206,3 +34276,44 @@ init_jsonFields();
|
|
|
34206
34276
|
init_vector();
|
|
34207
34277
|
init_yjsRuntime();
|
|
34208
34278
|
init_fieldNames();
|
|
34279
|
+
|
|
34280
|
+
// src/models/db3Types.ts
|
|
34281
|
+
var STATE_KEY = /* @__PURE__ */ Symbol.for("js-bao.db3TypeRegistry");
|
|
34282
|
+
function state() {
|
|
34283
|
+
const holder = globalThis;
|
|
34284
|
+
let current = holder[STATE_KEY];
|
|
34285
|
+
if (!current) {
|
|
34286
|
+
current = { knownTypesOnly: false, names: /* @__PURE__ */ new Set(), archived: /* @__PURE__ */ new Set() };
|
|
34287
|
+
holder[STATE_KEY] = current;
|
|
34288
|
+
}
|
|
34289
|
+
return current;
|
|
34290
|
+
}
|
|
34291
|
+
function declareDb3Types(declarations) {
|
|
34292
|
+
const current = state();
|
|
34293
|
+
if (declarations?.knownTypesOnly === true) current.knownTypesOnly = true;
|
|
34294
|
+
for (const type of declarations?.types ?? []) {
|
|
34295
|
+
if (typeof type?.name !== "string" || type.name === "") continue;
|
|
34296
|
+
if (!current.names.has(type.name)) current.sorted = null;
|
|
34297
|
+
current.names.add(type.name);
|
|
34298
|
+
if (type.archived === true) current.archived.add(type.name);
|
|
34299
|
+
}
|
|
34300
|
+
}
|
|
34301
|
+
function db3TypeRegistry() {
|
|
34302
|
+
const current = state();
|
|
34303
|
+
return {
|
|
34304
|
+
knownTypesOnly: current.knownTypesOnly,
|
|
34305
|
+
get names() {
|
|
34306
|
+
if (!current.sorted) current.sorted = Object.freeze([...current.names].sort());
|
|
34307
|
+
return current.sorted;
|
|
34308
|
+
},
|
|
34309
|
+
isKnown: (name) => current.names.has(name),
|
|
34310
|
+
isArchived: (name) => current.archived.has(name)
|
|
34311
|
+
};
|
|
34312
|
+
}
|
|
34313
|
+
function resetDb3TypesForTesting() {
|
|
34314
|
+
const current = state();
|
|
34315
|
+
current.knownTypesOnly = false;
|
|
34316
|
+
current.names.clear();
|
|
34317
|
+
current.archived.clear();
|
|
34318
|
+
current.sorted = null;
|
|
34319
|
+
}
|