@mdbase-dev/sdk 0.2.72 → 0.2.75
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/app-storage/app-binary-index.js +72 -29
- package/dist/app-storage/app-binary-index.js.map +1 -1
- package/dist/app-storage/sqlite-index.d.ts +10 -0
- package/dist/app-storage/sqlite-index.js +94 -23
- package/dist/app-storage/sqlite-index.js.map +1 -1
- package/dist/application/asset-pins.json +4 -4
- package/dist/application/worker.js +145 -52
- package/dist/browser/mdbase-sdk.js +146 -53
- package/dist/browser/mdbase-sdk.min.js +55 -55
- package/dist/native/provenance.json +5 -5
- package/dist/native/runtime.wasm +0 -0
- package/package.json +1 -1
|
@@ -15698,12 +15698,12 @@ function appReleaseTrust() {
|
|
|
15698
15698
|
// src/application/asset-pins.json
|
|
15699
15699
|
var asset_pins_default = {
|
|
15700
15700
|
runtime: {
|
|
15701
|
-
sha256: "
|
|
15702
|
-
bytes:
|
|
15703
|
-
maxBytes:
|
|
15701
|
+
sha256: "408685f37c0c57d41f8d547b4f449a6e5431ade527cc142c3d8ff68284a27cf3",
|
|
15702
|
+
bytes: 4186213,
|
|
15703
|
+
maxBytes: 4186213,
|
|
15704
15704
|
source: {
|
|
15705
15705
|
repository: "mdbase-dev/mdbase-connect",
|
|
15706
|
-
commit: "
|
|
15706
|
+
commit: "17d4e67654736620746baca9d556171a1de2e966"
|
|
15707
15707
|
}
|
|
15708
15708
|
},
|
|
15709
15709
|
sqlite: {
|
|
@@ -40664,6 +40664,7 @@ var AppScopedSignInSession = class {
|
|
|
40664
40664
|
};
|
|
40665
40665
|
|
|
40666
40666
|
// src/app-storage/sqlite-index.ts
|
|
40667
|
+
var validatedPackets = /* @__PURE__ */ new WeakMap();
|
|
40667
40668
|
var IndexError = class extends Error {
|
|
40668
40669
|
constructor(kind, detail, stmt = null) {
|
|
40669
40670
|
super(`${kind}${stmt === null ? "" : `@${stmt}`}(${detail})`);
|
|
@@ -40724,6 +40725,9 @@ var SqliteIndex = class _SqliteIndex {
|
|
|
40724
40725
|
db.exec("PRAGMA locking_mode=EXCLUSIVE");
|
|
40725
40726
|
db.exec("PRAGMA journal_mode=WAL");
|
|
40726
40727
|
db.exec(`PRAGMA synchronous=${synchronous}`);
|
|
40728
|
+
if (synchronous === "FULL") {
|
|
40729
|
+
db.exec("PRAGMA cache_size=-32768; PRAGMA wal_autocheckpoint=4096");
|
|
40730
|
+
}
|
|
40727
40731
|
}
|
|
40728
40732
|
if (opts.verifyPragmas && (String(db.selectValue("PRAGMA locking_mode")).toLowerCase() !== "exclusive" || String(db.selectValue("PRAGMA journal_mode")).toLowerCase() !== "wal" || db.selectValue("PRAGMA synchronous") !== (synchronous === "FULL" ? 2 : 1))) throw new IndexError("Other", "SQLite did not apply the requested storage profile");
|
|
40729
40733
|
const hadHost = db.selectValue("SELECT count(*) FROM sqlite_master WHERE name='_mdbn_host'") > 0;
|
|
@@ -40755,6 +40759,14 @@ var SqliteIndex = class _SqliteIndex {
|
|
|
40755
40759
|
}
|
|
40756
40760
|
return st;
|
|
40757
40761
|
}
|
|
40762
|
+
statementBuffer(params2) {
|
|
40763
|
+
let bytes10 = 0;
|
|
40764
|
+
for (const p of params2) {
|
|
40765
|
+
if (p.kind === "Blob") bytes10 += Math.max(1, p.value.byteLength);
|
|
40766
|
+
if (p.kind === "Text") bytes10 += Math.max(1, p.value.length * 3);
|
|
40767
|
+
}
|
|
40768
|
+
return bytes10 ? this.sqlite3.wasm.alloc(bytes10) : 0;
|
|
40769
|
+
}
|
|
40758
40770
|
bind(st, params2, buffer) {
|
|
40759
40771
|
const pointer = st.pointer;
|
|
40760
40772
|
const wasm = this.sqlite3.wasm;
|
|
@@ -40793,25 +40805,59 @@ var SqliteIndex = class _SqliteIndex {
|
|
|
40793
40805
|
if (rc) this.db.checkRc(rc);
|
|
40794
40806
|
}
|
|
40795
40807
|
}
|
|
40808
|
+
bindPacket(st, packet, i, base) {
|
|
40809
|
+
const raw = this.sqlite3.wasm.exports;
|
|
40810
|
+
const pointer = st.pointer, view = packet.view;
|
|
40811
|
+
let at = packet.offsets[i];
|
|
40812
|
+
const count = view.getUint32(at - 4, true);
|
|
40813
|
+
for (let idx = 1; idx <= count; idx++) {
|
|
40814
|
+
const tag = view.getUint8(at++);
|
|
40815
|
+
let rc;
|
|
40816
|
+
switch (tag) {
|
|
40817
|
+
case 0:
|
|
40818
|
+
rc = raw.sqlite3_bind_null(pointer, idx);
|
|
40819
|
+
break;
|
|
40820
|
+
case 1:
|
|
40821
|
+
rc = raw.sqlite3_bind_int64(pointer, idx, view.getBigInt64(at, true));
|
|
40822
|
+
at += 8;
|
|
40823
|
+
break;
|
|
40824
|
+
case 2:
|
|
40825
|
+
st.bind(idx, view.getFloat64(at, true));
|
|
40826
|
+
at += 8;
|
|
40827
|
+
continue;
|
|
40828
|
+
case 3:
|
|
40829
|
+
case 4: {
|
|
40830
|
+
const length = view.getUint32(at, true);
|
|
40831
|
+
at += 4;
|
|
40832
|
+
rc = tag === 3 ? raw.sqlite3_bind_text(pointer, idx, base + at, length, 0) : raw.sqlite3_bind_blob(pointer, idx, base + at, length, 0);
|
|
40833
|
+
at += length;
|
|
40834
|
+
break;
|
|
40835
|
+
}
|
|
40836
|
+
default:
|
|
40837
|
+
throw new IndexError("Other", "invalid tag in validated packet");
|
|
40838
|
+
}
|
|
40839
|
+
if (rc) this.db.checkRc(rc);
|
|
40840
|
+
}
|
|
40841
|
+
}
|
|
40796
40842
|
column(pointer, i, tag, addBytes) {
|
|
40797
|
-
const
|
|
40843
|
+
const raw = this.sqlite3.wasm.exports;
|
|
40798
40844
|
switch (tag) {
|
|
40799
40845
|
case SQLITE_NULL:
|
|
40800
40846
|
addBytes(1);
|
|
40801
40847
|
return { kind: "Null" };
|
|
40802
40848
|
case SQLITE_INTEGER:
|
|
40803
40849
|
addBytes(9);
|
|
40804
|
-
return { kind: "Integer", value: exactInteger(
|
|
40850
|
+
return { kind: "Integer", value: exactInteger(raw.sqlite3_column_int64(pointer, i)) };
|
|
40805
40851
|
case SQLITE_FLOAT:
|
|
40806
40852
|
addBytes(9);
|
|
40807
|
-
return { kind: "Real", value:
|
|
40853
|
+
return { kind: "Real", value: raw.sqlite3_column_double(pointer, i) };
|
|
40808
40854
|
case SQLITE_TEXT:
|
|
40809
|
-
addBytes(5 +
|
|
40810
|
-
return { kind: "Text", value: capi.sqlite3_column_text(pointer, i) };
|
|
40855
|
+
addBytes(5 + raw.sqlite3_column_bytes(pointer, i));
|
|
40856
|
+
return { kind: "Text", value: this.sqlite3.capi.sqlite3_column_text(pointer, i) };
|
|
40811
40857
|
case SQLITE_BLOB: {
|
|
40812
|
-
const length =
|
|
40858
|
+
const length = raw.sqlite3_column_bytes(pointer, i);
|
|
40813
40859
|
addBytes(5 + length);
|
|
40814
|
-
const start =
|
|
40860
|
+
const start = raw.sqlite3_column_blob(pointer, i);
|
|
40815
40861
|
if (length && !start) throw new IndexError("Other", "SQLite blob unavailable");
|
|
40816
40862
|
return { kind: "Blob", value: this.sqlite3.wasm.heap8u().slice(start, start + length) };
|
|
40817
40863
|
}
|
|
@@ -40822,7 +40868,20 @@ var SqliteIndex = class _SqliteIndex {
|
|
|
40822
40868
|
/** `IndexStorage::run`. */
|
|
40823
40869
|
run(batch, limits) {
|
|
40824
40870
|
if (this.closed) throw new IndexError("Other", "index closed");
|
|
40825
|
-
const
|
|
40871
|
+
const packet = validatedPackets.get(batch);
|
|
40872
|
+
if (!packet?.hasPayload) return this.runBatch(batch, limits, packet);
|
|
40873
|
+
const wasm = this.sqlite3.wasm;
|
|
40874
|
+
const view = packet.view;
|
|
40875
|
+
const buffer = wasm.alloc(view.byteLength + 1);
|
|
40876
|
+
try {
|
|
40877
|
+
wasm.heap8u().set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength), buffer);
|
|
40878
|
+
return this.runBatch(batch, limits, packet, buffer);
|
|
40879
|
+
} finally {
|
|
40880
|
+
wasm.dealloc(buffer);
|
|
40881
|
+
}
|
|
40882
|
+
}
|
|
40883
|
+
runBatch(batch, limits, packet, packetBase = 0) {
|
|
40884
|
+
const raw = this.sqlite3.wasm.exports;
|
|
40826
40885
|
const tx = batch.mode === "Transaction";
|
|
40827
40886
|
const out = [];
|
|
40828
40887
|
let rows2 = 0, valueCount = 0, bytes10 = 13;
|
|
@@ -40841,18 +40900,19 @@ var SqliteIndex = class _SqliteIndex {
|
|
|
40841
40900
|
throw classifyError(e);
|
|
40842
40901
|
}
|
|
40843
40902
|
}
|
|
40844
|
-
for (let i = 0; i < batch.stmts.length; i++) {
|
|
40903
|
+
for (let i = 0; i < (packet?.offsets.length ?? batch.stmts.length); i++) {
|
|
40845
40904
|
const s = batch.stmts[i];
|
|
40846
40905
|
try {
|
|
40847
40906
|
const st = this.prepare(s.sql);
|
|
40848
|
-
let
|
|
40849
|
-
for (const p of s.params) {
|
|
40850
|
-
if (p.kind === "Blob") bindBytes += Math.max(1, p.value.byteLength);
|
|
40851
|
-
if (p.kind === "Text") bindBytes += Math.max(1, p.value.length * 3);
|
|
40852
|
-
}
|
|
40853
|
-
const buffer = bindBytes ? this.sqlite3.wasm.alloc(bindBytes) : 0;
|
|
40907
|
+
let buffer = 0;
|
|
40854
40908
|
try {
|
|
40855
|
-
|
|
40909
|
+
if (packet) {
|
|
40910
|
+
this.bindPacket(st, packet, i, packetBase);
|
|
40911
|
+
} else {
|
|
40912
|
+
const params2 = s.params;
|
|
40913
|
+
buffer = this.statementBuffer(params2);
|
|
40914
|
+
this.bind(st, params2, buffer);
|
|
40915
|
+
}
|
|
40856
40916
|
const pointer = st.pointer;
|
|
40857
40917
|
const columns = st.columnCount;
|
|
40858
40918
|
if (limits && (!Number.isSafeInteger(columns) || columns < 0 || columns > limits.maxColumns)) {
|
|
@@ -40864,15 +40924,15 @@ var SqliteIndex = class _SqliteIndex {
|
|
|
40864
40924
|
if (limits && ++rows2 > limits.maxRows) throw new IndexError("Full", "index reply row budget exceeded");
|
|
40865
40925
|
for (let c = 0; c < columns; c++) {
|
|
40866
40926
|
if (limits && ++valueCount > limits.maxValues) throw new IndexError("Full", "index reply value budget exceeded");
|
|
40867
|
-
const tag =
|
|
40927
|
+
const tag = raw.sqlite3_column_type(pointer, c);
|
|
40868
40928
|
values.push(this.column(pointer, c, tag, addBytes));
|
|
40869
40929
|
}
|
|
40870
40930
|
}
|
|
40871
40931
|
out.push({
|
|
40872
40932
|
columns,
|
|
40873
40933
|
values,
|
|
40874
|
-
changes: exactInteger(
|
|
40875
|
-
lastInsertRowid: exactInteger(
|
|
40934
|
+
changes: exactInteger(raw.sqlite3_changes(this.db.pointer)),
|
|
40935
|
+
lastInsertRowid: exactInteger(raw.sqlite3_last_insert_rowid(this.db.pointer))
|
|
40876
40936
|
});
|
|
40877
40937
|
} finally {
|
|
40878
40938
|
try {
|
|
@@ -40943,15 +41003,19 @@ var invalid5 = () => new IndexError("Other", "invalid app index ABI");
|
|
|
40943
41003
|
var full = () => new IndexError("Full", "app index ABI budget exceeded");
|
|
40944
41004
|
var utf85 = new TextDecoder("utf-8", { fatal: true, ignoreBOM: true });
|
|
40945
41005
|
var encoder2 = new TextEncoder();
|
|
41006
|
+
function validateText(bytes10, view, at, end) {
|
|
41007
|
+
while (at + 4 <= end && !(view.getUint32(at) & 2155905152)) at += 4;
|
|
41008
|
+
while (at < end && bytes10[at] < 128) at++;
|
|
41009
|
+
if (at < end) utf85.decode(bytes10.subarray(at, end));
|
|
41010
|
+
}
|
|
40946
41011
|
var Reader2 = class {
|
|
40947
41012
|
constructor(bytes10) {
|
|
40948
41013
|
this.bytes = bytes10;
|
|
40949
|
-
if (bytes10.length > APP_INDEX_LIMITS.maxBytes) throw full();
|
|
40950
41014
|
this.view = new DataView(bytes10.buffer, bytes10.byteOffset, bytes10.byteLength);
|
|
40951
41015
|
}
|
|
40952
41016
|
bytes;
|
|
40953
41017
|
pos = 0;
|
|
40954
|
-
|
|
41018
|
+
hasPayload = false;
|
|
40955
41019
|
view;
|
|
40956
41020
|
advance(n) {
|
|
40957
41021
|
if (!Number.isSafeInteger(n) || n < 0 || n > this.bytes.length - this.pos) throw invalid5();
|
|
@@ -40981,27 +41045,39 @@ var Reader2 = class {
|
|
|
40981
41045
|
text(max) {
|
|
40982
41046
|
return utf85.decode(this.data(max));
|
|
40983
41047
|
}
|
|
40984
|
-
|
|
40985
|
-
|
|
40986
|
-
|
|
40987
|
-
|
|
40988
|
-
|
|
40989
|
-
|
|
40990
|
-
|
|
40991
|
-
|
|
40992
|
-
|
|
40993
|
-
|
|
40994
|
-
|
|
40995
|
-
|
|
40996
|
-
|
|
40997
|
-
|
|
40998
|
-
|
|
40999
|
-
|
|
41000
|
-
|
|
41001
|
-
|
|
41002
|
-
|
|
41003
|
-
|
|
41004
|
-
|
|
41048
|
+
params(count, out) {
|
|
41049
|
+
for (let i = 0; i < count; i++) {
|
|
41050
|
+
const tag = this.byte();
|
|
41051
|
+
switch (tag) {
|
|
41052
|
+
case 0:
|
|
41053
|
+
out?.push({ kind: "Null" });
|
|
41054
|
+
break;
|
|
41055
|
+
case 1: {
|
|
41056
|
+
const at = this.advance(8);
|
|
41057
|
+
out?.push({ kind: "Integer", value: this.view.getBigInt64(at, true) });
|
|
41058
|
+
break;
|
|
41059
|
+
}
|
|
41060
|
+
case 2: {
|
|
41061
|
+
const value2 = this.view.getFloat64(this.advance(8), true);
|
|
41062
|
+
if (!Number.isFinite(value2)) throw invalid5();
|
|
41063
|
+
out?.push({ kind: "Real", value: value2 });
|
|
41064
|
+
break;
|
|
41065
|
+
}
|
|
41066
|
+
case 3:
|
|
41067
|
+
case 4: {
|
|
41068
|
+
const at = this.advance(this.count(APP_INDEX_LIMITS.maxBytes, 1));
|
|
41069
|
+
this.hasPayload = true;
|
|
41070
|
+
if (out) {
|
|
41071
|
+
const data = this.bytes.subarray(at, this.pos);
|
|
41072
|
+
out.push(tag === 3 ? { kind: "Text", value: utf85.decode(data) } : { kind: "Blob", value: data.slice() });
|
|
41073
|
+
} else if (tag === 3) {
|
|
41074
|
+
validateText(this.bytes, this.view, at, this.pos);
|
|
41075
|
+
}
|
|
41076
|
+
break;
|
|
41077
|
+
}
|
|
41078
|
+
default:
|
|
41079
|
+
throw invalid5();
|
|
41080
|
+
}
|
|
41005
41081
|
}
|
|
41006
41082
|
}
|
|
41007
41083
|
done() {
|
|
@@ -41021,15 +41097,31 @@ function request2(bytes10) {
|
|
|
41021
41097
|
if (mode > 1) throw invalid5();
|
|
41022
41098
|
const count = r.count(APP_INDEX_LIMITS.maxStatements, 8);
|
|
41023
41099
|
const stmts = [];
|
|
41100
|
+
const offsets = new Uint32Array(count);
|
|
41101
|
+
let total = 0;
|
|
41024
41102
|
for (let i = 0; i < count; i++) {
|
|
41025
41103
|
const sql = r.text(APP_INDEX_LIMITS.maxSqlBytes);
|
|
41026
41104
|
const n = r.count(APP_INDEX_LIMITS.maxParameters, 1);
|
|
41027
|
-
|
|
41028
|
-
|
|
41029
|
-
|
|
41105
|
+
total += n;
|
|
41106
|
+
if (total > APP_INDEX_LIMITS.maxValues) throw full();
|
|
41107
|
+
offsets[i] = r.pos;
|
|
41108
|
+
r.params(n);
|
|
41109
|
+
let decoded;
|
|
41110
|
+
stmts.push({
|
|
41111
|
+
sql,
|
|
41112
|
+
get params() {
|
|
41113
|
+
if (decoded) return decoded;
|
|
41114
|
+
r.pos = offsets[i];
|
|
41115
|
+
const params2 = [];
|
|
41116
|
+
r.params(n, params2);
|
|
41117
|
+
return decoded = params2;
|
|
41118
|
+
}
|
|
41119
|
+
});
|
|
41030
41120
|
}
|
|
41031
41121
|
r.done();
|
|
41032
|
-
|
|
41122
|
+
const batch = { mode: mode === 0 ? "Transaction" : "Autocommit", stmts };
|
|
41123
|
+
validatedPackets.set(batch, { view: r.view, offsets, hasPayload: r.hasPayload });
|
|
41124
|
+
return batch;
|
|
41033
41125
|
}
|
|
41034
41126
|
var Writer2 = class {
|
|
41035
41127
|
bytes = new Uint8Array(128);
|
|
@@ -41158,7 +41250,8 @@ var AppBinaryIndexHost = class {
|
|
|
41158
41250
|
let expected = null;
|
|
41159
41251
|
try {
|
|
41160
41252
|
if (this.needsRecovery) throw invalid5();
|
|
41161
|
-
|
|
41253
|
+
if (bytes10.byteLength > APP_INDEX_LIMITS.maxBytes) throw full();
|
|
41254
|
+
const batch = request2(new Uint8Array(bytes10));
|
|
41162
41255
|
expected = batch.stmts.length;
|
|
41163
41256
|
const limits = APP_INDEX_LIMITS;
|
|
41164
41257
|
return results(this.index.run(batch, limits), expected);
|
|
@@ -41189,7 +41282,7 @@ function appSqlHost(host, exports) {
|
|
|
41189
41282
|
host.fence();
|
|
41190
41283
|
throw full();
|
|
41191
41284
|
}
|
|
41192
|
-
const reply = host.run(new Uint8Array(x.memory.buffer, ptr, len)
|
|
41285
|
+
const reply = host.run(new Uint8Array(x.memory.buffer, ptr, len));
|
|
41193
41286
|
const out = x.alloc(reply.length);
|
|
41194
41287
|
range(x.memory, out, reply.length);
|
|
41195
41288
|
if (reentered || out === 0 || out < ptr + len && ptr < out + reply.length) throw invalid5();
|
|
@@ -30000,10 +30000,11 @@ ${end.comment}` : end.comment;
|
|
|
30000
30000
|
if (typeof value2 === "number" && Number.isSafeInteger(value2)) return BigInt(value2);
|
|
30001
30001
|
throw new IndexError("Other", "SQLite integer is not losslessly represented");
|
|
30002
30002
|
}
|
|
30003
|
-
var IndexError, textEncoder2, SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, SQLITE_NULL, HOST_TABLE, SqliteIndex;
|
|
30003
|
+
var validatedPackets, IndexError, textEncoder2, SQLITE_INTEGER, SQLITE_FLOAT, SQLITE_TEXT, SQLITE_BLOB, SQLITE_NULL, HOST_TABLE, SqliteIndex;
|
|
30004
30004
|
var init_sqlite_index = __esm({
|
|
30005
30005
|
"src/app-storage/sqlite-index.ts"() {
|
|
30006
30006
|
"use strict";
|
|
30007
|
+
validatedPackets = /* @__PURE__ */ new WeakMap();
|
|
30007
30008
|
IndexError = class extends Error {
|
|
30008
30009
|
constructor(kind, detail, stmt = null) {
|
|
30009
30010
|
super(`${kind}${stmt === null ? "" : `@${stmt}`}(${detail})`);
|
|
@@ -30047,6 +30048,9 @@ ${end.comment}` : end.comment;
|
|
|
30047
30048
|
db.exec("PRAGMA locking_mode=EXCLUSIVE");
|
|
30048
30049
|
db.exec("PRAGMA journal_mode=WAL");
|
|
30049
30050
|
db.exec(`PRAGMA synchronous=${synchronous}`);
|
|
30051
|
+
if (synchronous === "FULL") {
|
|
30052
|
+
db.exec("PRAGMA cache_size=-32768; PRAGMA wal_autocheckpoint=4096");
|
|
30053
|
+
}
|
|
30050
30054
|
}
|
|
30051
30055
|
if (opts.verifyPragmas && (String(db.selectValue("PRAGMA locking_mode")).toLowerCase() !== "exclusive" || String(db.selectValue("PRAGMA journal_mode")).toLowerCase() !== "wal" || db.selectValue("PRAGMA synchronous") !== (synchronous === "FULL" ? 2 : 1))) throw new IndexError("Other", "SQLite did not apply the requested storage profile");
|
|
30052
30056
|
const hadHost = db.selectValue("SELECT count(*) FROM sqlite_master WHERE name='_mdbn_host'") > 0;
|
|
@@ -30078,6 +30082,14 @@ ${end.comment}` : end.comment;
|
|
|
30078
30082
|
}
|
|
30079
30083
|
return st;
|
|
30080
30084
|
}
|
|
30085
|
+
statementBuffer(params2) {
|
|
30086
|
+
let bytes10 = 0;
|
|
30087
|
+
for (const p of params2) {
|
|
30088
|
+
if (p.kind === "Blob") bytes10 += Math.max(1, p.value.byteLength);
|
|
30089
|
+
if (p.kind === "Text") bytes10 += Math.max(1, p.value.length * 3);
|
|
30090
|
+
}
|
|
30091
|
+
return bytes10 ? this.sqlite3.wasm.alloc(bytes10) : 0;
|
|
30092
|
+
}
|
|
30081
30093
|
bind(st, params2, buffer) {
|
|
30082
30094
|
const pointer = st.pointer;
|
|
30083
30095
|
const wasm = this.sqlite3.wasm;
|
|
@@ -30116,25 +30128,59 @@ ${end.comment}` : end.comment;
|
|
|
30116
30128
|
if (rc) this.db.checkRc(rc);
|
|
30117
30129
|
}
|
|
30118
30130
|
}
|
|
30131
|
+
bindPacket(st, packet, i, base) {
|
|
30132
|
+
const raw = this.sqlite3.wasm.exports;
|
|
30133
|
+
const pointer = st.pointer, view2 = packet.view;
|
|
30134
|
+
let at = packet.offsets[i];
|
|
30135
|
+
const count = view2.getUint32(at - 4, true);
|
|
30136
|
+
for (let idx = 1; idx <= count; idx++) {
|
|
30137
|
+
const tag = view2.getUint8(at++);
|
|
30138
|
+
let rc;
|
|
30139
|
+
switch (tag) {
|
|
30140
|
+
case 0:
|
|
30141
|
+
rc = raw.sqlite3_bind_null(pointer, idx);
|
|
30142
|
+
break;
|
|
30143
|
+
case 1:
|
|
30144
|
+
rc = raw.sqlite3_bind_int64(pointer, idx, view2.getBigInt64(at, true));
|
|
30145
|
+
at += 8;
|
|
30146
|
+
break;
|
|
30147
|
+
case 2:
|
|
30148
|
+
st.bind(idx, view2.getFloat64(at, true));
|
|
30149
|
+
at += 8;
|
|
30150
|
+
continue;
|
|
30151
|
+
case 3:
|
|
30152
|
+
case 4: {
|
|
30153
|
+
const length = view2.getUint32(at, true);
|
|
30154
|
+
at += 4;
|
|
30155
|
+
rc = tag === 3 ? raw.sqlite3_bind_text(pointer, idx, base + at, length, 0) : raw.sqlite3_bind_blob(pointer, idx, base + at, length, 0);
|
|
30156
|
+
at += length;
|
|
30157
|
+
break;
|
|
30158
|
+
}
|
|
30159
|
+
default:
|
|
30160
|
+
throw new IndexError("Other", "invalid tag in validated packet");
|
|
30161
|
+
}
|
|
30162
|
+
if (rc) this.db.checkRc(rc);
|
|
30163
|
+
}
|
|
30164
|
+
}
|
|
30119
30165
|
column(pointer, i, tag, addBytes) {
|
|
30120
|
-
const
|
|
30166
|
+
const raw = this.sqlite3.wasm.exports;
|
|
30121
30167
|
switch (tag) {
|
|
30122
30168
|
case SQLITE_NULL:
|
|
30123
30169
|
addBytes(1);
|
|
30124
30170
|
return { kind: "Null" };
|
|
30125
30171
|
case SQLITE_INTEGER:
|
|
30126
30172
|
addBytes(9);
|
|
30127
|
-
return { kind: "Integer", value: exactInteger(
|
|
30173
|
+
return { kind: "Integer", value: exactInteger(raw.sqlite3_column_int64(pointer, i)) };
|
|
30128
30174
|
case SQLITE_FLOAT:
|
|
30129
30175
|
addBytes(9);
|
|
30130
|
-
return { kind: "Real", value:
|
|
30176
|
+
return { kind: "Real", value: raw.sqlite3_column_double(pointer, i) };
|
|
30131
30177
|
case SQLITE_TEXT:
|
|
30132
|
-
addBytes(5 +
|
|
30133
|
-
return { kind: "Text", value: capi.sqlite3_column_text(pointer, i) };
|
|
30178
|
+
addBytes(5 + raw.sqlite3_column_bytes(pointer, i));
|
|
30179
|
+
return { kind: "Text", value: this.sqlite3.capi.sqlite3_column_text(pointer, i) };
|
|
30134
30180
|
case SQLITE_BLOB: {
|
|
30135
|
-
const length =
|
|
30181
|
+
const length = raw.sqlite3_column_bytes(pointer, i);
|
|
30136
30182
|
addBytes(5 + length);
|
|
30137
|
-
const start =
|
|
30183
|
+
const start = raw.sqlite3_column_blob(pointer, i);
|
|
30138
30184
|
if (length && !start) throw new IndexError("Other", "SQLite blob unavailable");
|
|
30139
30185
|
return { kind: "Blob", value: this.sqlite3.wasm.heap8u().slice(start, start + length) };
|
|
30140
30186
|
}
|
|
@@ -30145,7 +30191,20 @@ ${end.comment}` : end.comment;
|
|
|
30145
30191
|
/** `IndexStorage::run`. */
|
|
30146
30192
|
run(batch, limits) {
|
|
30147
30193
|
if (this.closed) throw new IndexError("Other", "index closed");
|
|
30148
|
-
const
|
|
30194
|
+
const packet = validatedPackets.get(batch);
|
|
30195
|
+
if (!packet?.hasPayload) return this.runBatch(batch, limits, packet);
|
|
30196
|
+
const wasm = this.sqlite3.wasm;
|
|
30197
|
+
const view2 = packet.view;
|
|
30198
|
+
const buffer = wasm.alloc(view2.byteLength + 1);
|
|
30199
|
+
try {
|
|
30200
|
+
wasm.heap8u().set(new Uint8Array(view2.buffer, view2.byteOffset, view2.byteLength), buffer);
|
|
30201
|
+
return this.runBatch(batch, limits, packet, buffer);
|
|
30202
|
+
} finally {
|
|
30203
|
+
wasm.dealloc(buffer);
|
|
30204
|
+
}
|
|
30205
|
+
}
|
|
30206
|
+
runBatch(batch, limits, packet, packetBase = 0) {
|
|
30207
|
+
const raw = this.sqlite3.wasm.exports;
|
|
30149
30208
|
const tx = batch.mode === "Transaction";
|
|
30150
30209
|
const out = [];
|
|
30151
30210
|
let rows2 = 0, valueCount = 0, bytes10 = 13;
|
|
@@ -30164,18 +30223,19 @@ ${end.comment}` : end.comment;
|
|
|
30164
30223
|
throw classifyError(e);
|
|
30165
30224
|
}
|
|
30166
30225
|
}
|
|
30167
|
-
for (let i = 0; i < batch.stmts.length; i++) {
|
|
30226
|
+
for (let i = 0; i < (packet?.offsets.length ?? batch.stmts.length); i++) {
|
|
30168
30227
|
const s = batch.stmts[i];
|
|
30169
30228
|
try {
|
|
30170
30229
|
const st = this.prepare(s.sql);
|
|
30171
|
-
let
|
|
30172
|
-
for (const p of s.params) {
|
|
30173
|
-
if (p.kind === "Blob") bindBytes += Math.max(1, p.value.byteLength);
|
|
30174
|
-
if (p.kind === "Text") bindBytes += Math.max(1, p.value.length * 3);
|
|
30175
|
-
}
|
|
30176
|
-
const buffer = bindBytes ? this.sqlite3.wasm.alloc(bindBytes) : 0;
|
|
30230
|
+
let buffer = 0;
|
|
30177
30231
|
try {
|
|
30178
|
-
|
|
30232
|
+
if (packet) {
|
|
30233
|
+
this.bindPacket(st, packet, i, packetBase);
|
|
30234
|
+
} else {
|
|
30235
|
+
const params2 = s.params;
|
|
30236
|
+
buffer = this.statementBuffer(params2);
|
|
30237
|
+
this.bind(st, params2, buffer);
|
|
30238
|
+
}
|
|
30179
30239
|
const pointer = st.pointer;
|
|
30180
30240
|
const columns = st.columnCount;
|
|
30181
30241
|
if (limits && (!Number.isSafeInteger(columns) || columns < 0 || columns > limits.maxColumns)) {
|
|
@@ -30187,15 +30247,15 @@ ${end.comment}` : end.comment;
|
|
|
30187
30247
|
if (limits && ++rows2 > limits.maxRows) throw new IndexError("Full", "index reply row budget exceeded");
|
|
30188
30248
|
for (let c = 0; c < columns; c++) {
|
|
30189
30249
|
if (limits && ++valueCount > limits.maxValues) throw new IndexError("Full", "index reply value budget exceeded");
|
|
30190
|
-
const tag =
|
|
30250
|
+
const tag = raw.sqlite3_column_type(pointer, c);
|
|
30191
30251
|
values.push(this.column(pointer, c, tag, addBytes));
|
|
30192
30252
|
}
|
|
30193
30253
|
}
|
|
30194
30254
|
out.push({
|
|
30195
30255
|
columns,
|
|
30196
30256
|
values,
|
|
30197
|
-
changes: exactInteger(
|
|
30198
|
-
lastInsertRowid: exactInteger(
|
|
30257
|
+
changes: exactInteger(raw.sqlite3_changes(this.db.pointer)),
|
|
30258
|
+
lastInsertRowid: exactInteger(raw.sqlite3_last_insert_rowid(this.db.pointer))
|
|
30199
30259
|
});
|
|
30200
30260
|
} finally {
|
|
30201
30261
|
try {
|
|
@@ -30251,6 +30311,11 @@ ${end.comment}` : end.comment;
|
|
|
30251
30311
|
});
|
|
30252
30312
|
|
|
30253
30313
|
// src/app-storage/app-binary-index.ts
|
|
30314
|
+
function validateText(bytes10, view2, at, end) {
|
|
30315
|
+
while (at + 4 <= end && !(view2.getUint32(at) & 2155905152)) at += 4;
|
|
30316
|
+
while (at < end && bytes10[at] < 128) at++;
|
|
30317
|
+
if (at < end) utf83.decode(bytes10.subarray(at, end));
|
|
30318
|
+
}
|
|
30254
30319
|
function request(bytes10) {
|
|
30255
30320
|
const r = new Reader2(bytes10);
|
|
30256
30321
|
if (!r.take(8).every((b, i) => b === MAGIC[i])) throw invalid7();
|
|
@@ -30264,15 +30329,31 @@ ${end.comment}` : end.comment;
|
|
|
30264
30329
|
if (mode > 1) throw invalid7();
|
|
30265
30330
|
const count = r.count(APP_INDEX_LIMITS.maxStatements, 8);
|
|
30266
30331
|
const stmts = [];
|
|
30332
|
+
const offsets = new Uint32Array(count);
|
|
30333
|
+
let total = 0;
|
|
30267
30334
|
for (let i = 0; i < count; i++) {
|
|
30268
30335
|
const sql = r.text(APP_INDEX_LIMITS.maxSqlBytes);
|
|
30269
30336
|
const n = r.count(APP_INDEX_LIMITS.maxParameters, 1);
|
|
30270
|
-
|
|
30271
|
-
|
|
30272
|
-
|
|
30337
|
+
total += n;
|
|
30338
|
+
if (total > APP_INDEX_LIMITS.maxValues) throw full();
|
|
30339
|
+
offsets[i] = r.pos;
|
|
30340
|
+
r.params(n);
|
|
30341
|
+
let decoded;
|
|
30342
|
+
stmts.push({
|
|
30343
|
+
sql,
|
|
30344
|
+
get params() {
|
|
30345
|
+
if (decoded) return decoded;
|
|
30346
|
+
r.pos = offsets[i];
|
|
30347
|
+
const params2 = [];
|
|
30348
|
+
r.params(n, params2);
|
|
30349
|
+
return decoded = params2;
|
|
30350
|
+
}
|
|
30351
|
+
});
|
|
30273
30352
|
}
|
|
30274
30353
|
r.done();
|
|
30275
|
-
|
|
30354
|
+
const batch = { mode: mode === 0 ? "Transaction" : "Autocommit", stmts };
|
|
30355
|
+
validatedPackets.set(batch, { view: r.view, offsets, hasPayload: r.hasPayload });
|
|
30356
|
+
return batch;
|
|
30276
30357
|
}
|
|
30277
30358
|
function results(out, expected) {
|
|
30278
30359
|
if (!Array.isArray(out) || out.length !== expected) throw invalid7();
|
|
@@ -30326,7 +30407,7 @@ ${end.comment}` : end.comment;
|
|
|
30326
30407
|
host.fence();
|
|
30327
30408
|
throw full();
|
|
30328
30409
|
}
|
|
30329
|
-
const reply = host.run(new Uint8Array(x.memory.buffer, ptr, len)
|
|
30410
|
+
const reply = host.run(new Uint8Array(x.memory.buffer, ptr, len));
|
|
30330
30411
|
const out = x.alloc(reply.length);
|
|
30331
30412
|
range(x.memory, out, reply.length);
|
|
30332
30413
|
if (reentered || out === 0 || out < ptr + len && ptr < out + reply.length) throw invalid7();
|
|
@@ -30365,12 +30446,11 @@ ${end.comment}` : end.comment;
|
|
|
30365
30446
|
Reader2 = class {
|
|
30366
30447
|
constructor(bytes10) {
|
|
30367
30448
|
this.bytes = bytes10;
|
|
30368
|
-
if (bytes10.length > APP_INDEX_LIMITS.maxBytes) throw full();
|
|
30369
30449
|
this.view = new DataView(bytes10.buffer, bytes10.byteOffset, bytes10.byteLength);
|
|
30370
30450
|
}
|
|
30371
30451
|
bytes;
|
|
30372
30452
|
pos = 0;
|
|
30373
|
-
|
|
30453
|
+
hasPayload = false;
|
|
30374
30454
|
view;
|
|
30375
30455
|
advance(n) {
|
|
30376
30456
|
if (!Number.isSafeInteger(n) || n < 0 || n > this.bytes.length - this.pos) throw invalid7();
|
|
@@ -30400,27 +30480,39 @@ ${end.comment}` : end.comment;
|
|
|
30400
30480
|
text(max) {
|
|
30401
30481
|
return utf83.decode(this.data(max));
|
|
30402
30482
|
}
|
|
30403
|
-
|
|
30404
|
-
|
|
30405
|
-
|
|
30406
|
-
|
|
30407
|
-
|
|
30408
|
-
|
|
30409
|
-
|
|
30410
|
-
|
|
30411
|
-
|
|
30412
|
-
|
|
30413
|
-
|
|
30414
|
-
|
|
30415
|
-
|
|
30416
|
-
|
|
30417
|
-
|
|
30418
|
-
|
|
30419
|
-
|
|
30420
|
-
|
|
30421
|
-
|
|
30422
|
-
|
|
30423
|
-
|
|
30483
|
+
params(count, out) {
|
|
30484
|
+
for (let i = 0; i < count; i++) {
|
|
30485
|
+
const tag = this.byte();
|
|
30486
|
+
switch (tag) {
|
|
30487
|
+
case 0:
|
|
30488
|
+
out?.push({ kind: "Null" });
|
|
30489
|
+
break;
|
|
30490
|
+
case 1: {
|
|
30491
|
+
const at = this.advance(8);
|
|
30492
|
+
out?.push({ kind: "Integer", value: this.view.getBigInt64(at, true) });
|
|
30493
|
+
break;
|
|
30494
|
+
}
|
|
30495
|
+
case 2: {
|
|
30496
|
+
const value2 = this.view.getFloat64(this.advance(8), true);
|
|
30497
|
+
if (!Number.isFinite(value2)) throw invalid7();
|
|
30498
|
+
out?.push({ kind: "Real", value: value2 });
|
|
30499
|
+
break;
|
|
30500
|
+
}
|
|
30501
|
+
case 3:
|
|
30502
|
+
case 4: {
|
|
30503
|
+
const at = this.advance(this.count(APP_INDEX_LIMITS.maxBytes, 1));
|
|
30504
|
+
this.hasPayload = true;
|
|
30505
|
+
if (out) {
|
|
30506
|
+
const data = this.bytes.subarray(at, this.pos);
|
|
30507
|
+
out.push(tag === 3 ? { kind: "Text", value: utf83.decode(data) } : { kind: "Blob", value: data.slice() });
|
|
30508
|
+
} else if (tag === 3) {
|
|
30509
|
+
validateText(this.bytes, this.view, at, this.pos);
|
|
30510
|
+
}
|
|
30511
|
+
break;
|
|
30512
|
+
}
|
|
30513
|
+
default:
|
|
30514
|
+
throw invalid7();
|
|
30515
|
+
}
|
|
30424
30516
|
}
|
|
30425
30517
|
}
|
|
30426
30518
|
done() {
|
|
@@ -30523,7 +30615,8 @@ ${end.comment}` : end.comment;
|
|
|
30523
30615
|
let expected = null;
|
|
30524
30616
|
try {
|
|
30525
30617
|
if (this.needsRecovery) throw invalid7();
|
|
30526
|
-
|
|
30618
|
+
if (bytes10.byteLength > APP_INDEX_LIMITS.maxBytes) throw full();
|
|
30619
|
+
const batch = request(new Uint8Array(bytes10));
|
|
30527
30620
|
expected = batch.stmts.length;
|
|
30528
30621
|
const limits = APP_INDEX_LIMITS;
|
|
30529
30622
|
return results(this.index.run(batch, limits), expected);
|
|
@@ -51265,12 +51358,12 @@ ${end.comment}` : end.comment;
|
|
|
51265
51358
|
// src/application/asset-pins.json
|
|
51266
51359
|
var asset_pins_default = {
|
|
51267
51360
|
runtime: {
|
|
51268
|
-
sha256: "
|
|
51269
|
-
bytes:
|
|
51270
|
-
maxBytes:
|
|
51361
|
+
sha256: "408685f37c0c57d41f8d547b4f449a6e5431ade527cc142c3d8ff68284a27cf3",
|
|
51362
|
+
bytes: 4186213,
|
|
51363
|
+
maxBytes: 4186213,
|
|
51271
51364
|
source: {
|
|
51272
51365
|
repository: "mdbase-dev/mdbase-connect",
|
|
51273
|
-
commit: "
|
|
51366
|
+
commit: "17d4e67654736620746baca9d556171a1de2e966"
|
|
51274
51367
|
}
|
|
51275
51368
|
},
|
|
51276
51369
|
sqlite: {
|