@peerbit/indexer-sqlite3 3.0.5 → 3.0.7
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/assets/sqlite3/sqlite3.worker.min.js +13 -6
- package/dist/benchmark/query-planner.d.ts +2 -0
- package/dist/benchmark/query-planner.d.ts.map +1 -0
- package/dist/benchmark/query-planner.js +97 -0
- package/dist/benchmark/query-planner.js.map +1 -0
- package/dist/index.min.js +807 -453
- package/dist/index.min.js.map +4 -4
- package/dist/src/engine.d.ts +15 -4
- package/dist/src/engine.d.ts.map +1 -1
- package/dist/src/engine.js +364 -179
- package/dist/src/engine.js.map +1 -1
- package/dist/src/query-planner.d.ts +20 -0
- package/dist/src/query-planner.d.ts.map +1 -1
- package/dist/src/query-planner.js +191 -21
- package/dist/src/query-planner.js.map +1 -1
- package/dist/src/schema.d.ts +6 -2
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/schema.js +11 -8
- package/dist/src/schema.js.map +1 -1
- package/dist/src/sqlite3-messages.worker.d.ts +8 -1
- package/dist/src/sqlite3-messages.worker.d.ts.map +1 -1
- package/dist/src/sqlite3-messages.worker.js.map +1 -1
- package/dist/src/sqlite3.browser.d.ts.map +1 -1
- package/dist/src/sqlite3.browser.js +21 -0
- package/dist/src/sqlite3.browser.js.map +1 -1
- package/dist/src/sqlite3.wasm.d.ts.map +1 -1
- package/dist/src/sqlite3.wasm.js +4 -1
- package/dist/src/sqlite3.wasm.js.map +1 -1
- package/dist/src/sqlite3.worker.js +6 -0
- package/dist/src/sqlite3.worker.js.map +1 -1
- package/dist/src/types.d.ts +4 -0
- package/dist/src/types.d.ts.map +1 -1
- package/package.json +7 -6
- package/src/engine.ts +464 -235
- package/src/query-planner.ts +247 -22
- package/src/schema.ts +21 -4
- package/src/sqlite3-messages.worker.ts +6 -0
- package/src/sqlite3.browser.ts +33 -0
- package/src/sqlite3.wasm.ts +4 -1
- package/src/sqlite3.worker.ts +6 -0
- package/src/types.ts +3 -0
package/dist/index.min.js
CHANGED
|
@@ -18431,275 +18431,6 @@ var resize = (arr, newSize, defaultValue) => {
|
|
|
18431
18431
|
arr.length = newSize;
|
|
18432
18432
|
};
|
|
18433
18433
|
|
|
18434
|
-
// ../../../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bytes.js
|
|
18435
|
-
var empty = new Uint8Array(0);
|
|
18436
|
-
function coerce(o) {
|
|
18437
|
-
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
18438
|
-
return o;
|
|
18439
|
-
}
|
|
18440
|
-
if (o instanceof ArrayBuffer) {
|
|
18441
|
-
return new Uint8Array(o);
|
|
18442
|
-
}
|
|
18443
|
-
if (ArrayBuffer.isView(o)) {
|
|
18444
|
-
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
18445
|
-
}
|
|
18446
|
-
throw new Error("Unknown type, must be binary type");
|
|
18447
|
-
}
|
|
18448
|
-
|
|
18449
|
-
// ../../../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
18450
|
-
function base(ALPHABET, name) {
|
|
18451
|
-
if (ALPHABET.length >= 255) {
|
|
18452
|
-
throw new TypeError("Alphabet too long");
|
|
18453
|
-
}
|
|
18454
|
-
var BASE_MAP = new Uint8Array(256);
|
|
18455
|
-
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
18456
|
-
BASE_MAP[j] = 255;
|
|
18457
|
-
}
|
|
18458
|
-
for (var i = 0; i < ALPHABET.length; i++) {
|
|
18459
|
-
var x = ALPHABET.charAt(i);
|
|
18460
|
-
var xc = x.charCodeAt(0);
|
|
18461
|
-
if (BASE_MAP[xc] !== 255) {
|
|
18462
|
-
throw new TypeError(x + " is ambiguous");
|
|
18463
|
-
}
|
|
18464
|
-
BASE_MAP[xc] = i;
|
|
18465
|
-
}
|
|
18466
|
-
var BASE = ALPHABET.length;
|
|
18467
|
-
var LEADER = ALPHABET.charAt(0);
|
|
18468
|
-
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
18469
|
-
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
18470
|
-
function encode(source) {
|
|
18471
|
-
if (source instanceof Uint8Array)
|
|
18472
|
-
;
|
|
18473
|
-
else if (ArrayBuffer.isView(source)) {
|
|
18474
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
18475
|
-
} else if (Array.isArray(source)) {
|
|
18476
|
-
source = Uint8Array.from(source);
|
|
18477
|
-
}
|
|
18478
|
-
if (!(source instanceof Uint8Array)) {
|
|
18479
|
-
throw new TypeError("Expected Uint8Array");
|
|
18480
|
-
}
|
|
18481
|
-
if (source.length === 0) {
|
|
18482
|
-
return "";
|
|
18483
|
-
}
|
|
18484
|
-
var zeroes = 0;
|
|
18485
|
-
var length = 0;
|
|
18486
|
-
var pbegin = 0;
|
|
18487
|
-
var pend = source.length;
|
|
18488
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
18489
|
-
pbegin++;
|
|
18490
|
-
zeroes++;
|
|
18491
|
-
}
|
|
18492
|
-
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
18493
|
-
var b58 = new Uint8Array(size);
|
|
18494
|
-
while (pbegin !== pend) {
|
|
18495
|
-
var carry = source[pbegin];
|
|
18496
|
-
var i2 = 0;
|
|
18497
|
-
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
18498
|
-
carry += 256 * b58[it1] >>> 0;
|
|
18499
|
-
b58[it1] = carry % BASE >>> 0;
|
|
18500
|
-
carry = carry / BASE >>> 0;
|
|
18501
|
-
}
|
|
18502
|
-
if (carry !== 0) {
|
|
18503
|
-
throw new Error("Non-zero carry");
|
|
18504
|
-
}
|
|
18505
|
-
length = i2;
|
|
18506
|
-
pbegin++;
|
|
18507
|
-
}
|
|
18508
|
-
var it2 = size - length;
|
|
18509
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
18510
|
-
it2++;
|
|
18511
|
-
}
|
|
18512
|
-
var str = LEADER.repeat(zeroes);
|
|
18513
|
-
for (; it2 < size; ++it2) {
|
|
18514
|
-
str += ALPHABET.charAt(b58[it2]);
|
|
18515
|
-
}
|
|
18516
|
-
return str;
|
|
18517
|
-
}
|
|
18518
|
-
function decodeUnsafe(source) {
|
|
18519
|
-
if (typeof source !== "string") {
|
|
18520
|
-
throw new TypeError("Expected String");
|
|
18521
|
-
}
|
|
18522
|
-
if (source.length === 0) {
|
|
18523
|
-
return new Uint8Array();
|
|
18524
|
-
}
|
|
18525
|
-
var psz = 0;
|
|
18526
|
-
if (source[psz] === " ") {
|
|
18527
|
-
return;
|
|
18528
|
-
}
|
|
18529
|
-
var zeroes = 0;
|
|
18530
|
-
var length = 0;
|
|
18531
|
-
while (source[psz] === LEADER) {
|
|
18532
|
-
zeroes++;
|
|
18533
|
-
psz++;
|
|
18534
|
-
}
|
|
18535
|
-
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
18536
|
-
var b256 = new Uint8Array(size);
|
|
18537
|
-
while (source[psz]) {
|
|
18538
|
-
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
18539
|
-
if (carry === 255) {
|
|
18540
|
-
return;
|
|
18541
|
-
}
|
|
18542
|
-
var i2 = 0;
|
|
18543
|
-
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
18544
|
-
carry += BASE * b256[it3] >>> 0;
|
|
18545
|
-
b256[it3] = carry % 256 >>> 0;
|
|
18546
|
-
carry = carry / 256 >>> 0;
|
|
18547
|
-
}
|
|
18548
|
-
if (carry !== 0) {
|
|
18549
|
-
throw new Error("Non-zero carry");
|
|
18550
|
-
}
|
|
18551
|
-
length = i2;
|
|
18552
|
-
psz++;
|
|
18553
|
-
}
|
|
18554
|
-
if (source[psz] === " ") {
|
|
18555
|
-
return;
|
|
18556
|
-
}
|
|
18557
|
-
var it4 = size - length;
|
|
18558
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
18559
|
-
it4++;
|
|
18560
|
-
}
|
|
18561
|
-
var vch = new Uint8Array(zeroes + (size - it4));
|
|
18562
|
-
var j2 = zeroes;
|
|
18563
|
-
while (it4 !== size) {
|
|
18564
|
-
vch[j2++] = b256[it4++];
|
|
18565
|
-
}
|
|
18566
|
-
return vch;
|
|
18567
|
-
}
|
|
18568
|
-
function decode(string) {
|
|
18569
|
-
var buffer = decodeUnsafe(string);
|
|
18570
|
-
if (buffer) {
|
|
18571
|
-
return buffer;
|
|
18572
|
-
}
|
|
18573
|
-
throw new Error(`Non-${name} character`);
|
|
18574
|
-
}
|
|
18575
|
-
return {
|
|
18576
|
-
encode,
|
|
18577
|
-
decodeUnsafe,
|
|
18578
|
-
decode
|
|
18579
|
-
};
|
|
18580
|
-
}
|
|
18581
|
-
var src = base;
|
|
18582
|
-
var _brrp__multiformats_scope_baseX = src;
|
|
18583
|
-
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
18584
|
-
|
|
18585
|
-
// ../../../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base.js
|
|
18586
|
-
var Encoder = class {
|
|
18587
|
-
name;
|
|
18588
|
-
prefix;
|
|
18589
|
-
baseEncode;
|
|
18590
|
-
constructor(name, prefix, baseEncode) {
|
|
18591
|
-
this.name = name;
|
|
18592
|
-
this.prefix = prefix;
|
|
18593
|
-
this.baseEncode = baseEncode;
|
|
18594
|
-
}
|
|
18595
|
-
encode(bytes) {
|
|
18596
|
-
if (bytes instanceof Uint8Array) {
|
|
18597
|
-
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
18598
|
-
} else {
|
|
18599
|
-
throw Error("Unknown type, must be binary type");
|
|
18600
|
-
}
|
|
18601
|
-
}
|
|
18602
|
-
};
|
|
18603
|
-
var Decoder = class {
|
|
18604
|
-
name;
|
|
18605
|
-
prefix;
|
|
18606
|
-
baseDecode;
|
|
18607
|
-
prefixCodePoint;
|
|
18608
|
-
constructor(name, prefix, baseDecode) {
|
|
18609
|
-
this.name = name;
|
|
18610
|
-
this.prefix = prefix;
|
|
18611
|
-
const prefixCodePoint = prefix.codePointAt(0);
|
|
18612
|
-
if (prefixCodePoint === void 0) {
|
|
18613
|
-
throw new Error("Invalid prefix character");
|
|
18614
|
-
}
|
|
18615
|
-
this.prefixCodePoint = prefixCodePoint;
|
|
18616
|
-
this.baseDecode = baseDecode;
|
|
18617
|
-
}
|
|
18618
|
-
decode(text) {
|
|
18619
|
-
if (typeof text === "string") {
|
|
18620
|
-
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
18621
|
-
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
18622
|
-
}
|
|
18623
|
-
return this.baseDecode(text.slice(this.prefix.length));
|
|
18624
|
-
} else {
|
|
18625
|
-
throw Error("Can only multibase decode strings");
|
|
18626
|
-
}
|
|
18627
|
-
}
|
|
18628
|
-
or(decoder) {
|
|
18629
|
-
return or(this, decoder);
|
|
18630
|
-
}
|
|
18631
|
-
};
|
|
18632
|
-
var ComposedDecoder = class {
|
|
18633
|
-
decoders;
|
|
18634
|
-
constructor(decoders) {
|
|
18635
|
-
this.decoders = decoders;
|
|
18636
|
-
}
|
|
18637
|
-
or(decoder) {
|
|
18638
|
-
return or(this, decoder);
|
|
18639
|
-
}
|
|
18640
|
-
decode(input) {
|
|
18641
|
-
const prefix = input[0];
|
|
18642
|
-
const decoder = this.decoders[prefix];
|
|
18643
|
-
if (decoder != null) {
|
|
18644
|
-
return decoder.decode(input);
|
|
18645
|
-
} else {
|
|
18646
|
-
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
18647
|
-
}
|
|
18648
|
-
}
|
|
18649
|
-
};
|
|
18650
|
-
function or(left, right) {
|
|
18651
|
-
return new ComposedDecoder({
|
|
18652
|
-
...left.decoders ?? { [left.prefix]: left },
|
|
18653
|
-
...right.decoders ?? { [right.prefix]: right }
|
|
18654
|
-
});
|
|
18655
|
-
}
|
|
18656
|
-
var Codec = class {
|
|
18657
|
-
name;
|
|
18658
|
-
prefix;
|
|
18659
|
-
baseEncode;
|
|
18660
|
-
baseDecode;
|
|
18661
|
-
encoder;
|
|
18662
|
-
decoder;
|
|
18663
|
-
constructor(name, prefix, baseEncode, baseDecode) {
|
|
18664
|
-
this.name = name;
|
|
18665
|
-
this.prefix = prefix;
|
|
18666
|
-
this.baseEncode = baseEncode;
|
|
18667
|
-
this.baseDecode = baseDecode;
|
|
18668
|
-
this.encoder = new Encoder(name, prefix, baseEncode);
|
|
18669
|
-
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
18670
|
-
}
|
|
18671
|
-
encode(input) {
|
|
18672
|
-
return this.encoder.encode(input);
|
|
18673
|
-
}
|
|
18674
|
-
decode(input) {
|
|
18675
|
-
return this.decoder.decode(input);
|
|
18676
|
-
}
|
|
18677
|
-
};
|
|
18678
|
-
function from({ name, prefix, encode, decode }) {
|
|
18679
|
-
return new Codec(name, prefix, encode, decode);
|
|
18680
|
-
}
|
|
18681
|
-
function baseX({ name, prefix, alphabet }) {
|
|
18682
|
-
const { encode, decode } = base_x_default(alphabet, name);
|
|
18683
|
-
return from({
|
|
18684
|
-
prefix,
|
|
18685
|
-
name,
|
|
18686
|
-
encode,
|
|
18687
|
-
decode: (text) => coerce(decode(text))
|
|
18688
|
-
});
|
|
18689
|
-
}
|
|
18690
|
-
|
|
18691
|
-
// ../../../../node_modules/.pnpm/multiformats@13.4.1/node_modules/multiformats/dist/src/bases/base58.js
|
|
18692
|
-
var base58btc = baseX({
|
|
18693
|
-
name: "base58btc",
|
|
18694
|
-
prefix: "z",
|
|
18695
|
-
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
18696
|
-
});
|
|
18697
|
-
var base58flickr = baseX({
|
|
18698
|
-
name: "base58flickr",
|
|
18699
|
-
prefix: "Z",
|
|
18700
|
-
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
18701
|
-
});
|
|
18702
|
-
|
|
18703
18434
|
// ../../../../node_modules/.pnpm/@stablelib+int@2.0.1/node_modules/@stablelib/int/lib/int.js
|
|
18704
18435
|
var isInteger = Number.isInteger;
|
|
18705
18436
|
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
@@ -19001,7 +18732,278 @@ function hashBlocks(w, v2, p, pos, len) {
|
|
|
19001
18732
|
}
|
|
19002
18733
|
|
|
19003
18734
|
// ../../crypto/dist/src/utils.js
|
|
19004
|
-
var import_libsodium_wrappers = __toESM(require_libsodium_wrappers(), 1);
|
|
18735
|
+
var import_libsodium_wrappers = __toESM(require_libsodium_wrappers(), 1);
|
|
18736
|
+
|
|
18737
|
+
// ../../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bytes.js
|
|
18738
|
+
var empty = new Uint8Array(0);
|
|
18739
|
+
function coerce(o) {
|
|
18740
|
+
if (o instanceof Uint8Array && o.constructor.name === "Uint8Array") {
|
|
18741
|
+
return o;
|
|
18742
|
+
}
|
|
18743
|
+
if (o instanceof ArrayBuffer) {
|
|
18744
|
+
return new Uint8Array(o);
|
|
18745
|
+
}
|
|
18746
|
+
if (ArrayBuffer.isView(o)) {
|
|
18747
|
+
return new Uint8Array(o.buffer, o.byteOffset, o.byteLength);
|
|
18748
|
+
}
|
|
18749
|
+
throw new Error("Unknown type, must be binary type");
|
|
18750
|
+
}
|
|
18751
|
+
|
|
18752
|
+
// ../../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/vendor/base-x.js
|
|
18753
|
+
function base(ALPHABET, name) {
|
|
18754
|
+
if (ALPHABET.length >= 255) {
|
|
18755
|
+
throw new TypeError("Alphabet too long");
|
|
18756
|
+
}
|
|
18757
|
+
var BASE_MAP = new Uint8Array(256);
|
|
18758
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
18759
|
+
BASE_MAP[j] = 255;
|
|
18760
|
+
}
|
|
18761
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
18762
|
+
var x = ALPHABET.charAt(i);
|
|
18763
|
+
var xc = x.charCodeAt(0);
|
|
18764
|
+
if (BASE_MAP[xc] !== 255) {
|
|
18765
|
+
throw new TypeError(x + " is ambiguous");
|
|
18766
|
+
}
|
|
18767
|
+
BASE_MAP[xc] = i;
|
|
18768
|
+
}
|
|
18769
|
+
var BASE = ALPHABET.length;
|
|
18770
|
+
var LEADER = ALPHABET.charAt(0);
|
|
18771
|
+
var FACTOR = Math.log(BASE) / Math.log(256);
|
|
18772
|
+
var iFACTOR = Math.log(256) / Math.log(BASE);
|
|
18773
|
+
function encode(source) {
|
|
18774
|
+
if (source instanceof Uint8Array)
|
|
18775
|
+
;
|
|
18776
|
+
else if (ArrayBuffer.isView(source)) {
|
|
18777
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
18778
|
+
} else if (Array.isArray(source)) {
|
|
18779
|
+
source = Uint8Array.from(source);
|
|
18780
|
+
}
|
|
18781
|
+
if (!(source instanceof Uint8Array)) {
|
|
18782
|
+
throw new TypeError("Expected Uint8Array");
|
|
18783
|
+
}
|
|
18784
|
+
if (source.length === 0) {
|
|
18785
|
+
return "";
|
|
18786
|
+
}
|
|
18787
|
+
var zeroes = 0;
|
|
18788
|
+
var length = 0;
|
|
18789
|
+
var pbegin = 0;
|
|
18790
|
+
var pend = source.length;
|
|
18791
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
18792
|
+
pbegin++;
|
|
18793
|
+
zeroes++;
|
|
18794
|
+
}
|
|
18795
|
+
var size = (pend - pbegin) * iFACTOR + 1 >>> 0;
|
|
18796
|
+
var b58 = new Uint8Array(size);
|
|
18797
|
+
while (pbegin !== pend) {
|
|
18798
|
+
var carry = source[pbegin];
|
|
18799
|
+
var i2 = 0;
|
|
18800
|
+
for (var it1 = size - 1; (carry !== 0 || i2 < length) && it1 !== -1; it1--, i2++) {
|
|
18801
|
+
carry += 256 * b58[it1] >>> 0;
|
|
18802
|
+
b58[it1] = carry % BASE >>> 0;
|
|
18803
|
+
carry = carry / BASE >>> 0;
|
|
18804
|
+
}
|
|
18805
|
+
if (carry !== 0) {
|
|
18806
|
+
throw new Error("Non-zero carry");
|
|
18807
|
+
}
|
|
18808
|
+
length = i2;
|
|
18809
|
+
pbegin++;
|
|
18810
|
+
}
|
|
18811
|
+
var it2 = size - length;
|
|
18812
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
18813
|
+
it2++;
|
|
18814
|
+
}
|
|
18815
|
+
var str = LEADER.repeat(zeroes);
|
|
18816
|
+
for (; it2 < size; ++it2) {
|
|
18817
|
+
str += ALPHABET.charAt(b58[it2]);
|
|
18818
|
+
}
|
|
18819
|
+
return str;
|
|
18820
|
+
}
|
|
18821
|
+
function decodeUnsafe(source) {
|
|
18822
|
+
if (typeof source !== "string") {
|
|
18823
|
+
throw new TypeError("Expected String");
|
|
18824
|
+
}
|
|
18825
|
+
if (source.length === 0) {
|
|
18826
|
+
return new Uint8Array();
|
|
18827
|
+
}
|
|
18828
|
+
var psz = 0;
|
|
18829
|
+
if (source[psz] === " ") {
|
|
18830
|
+
return;
|
|
18831
|
+
}
|
|
18832
|
+
var zeroes = 0;
|
|
18833
|
+
var length = 0;
|
|
18834
|
+
while (source[psz] === LEADER) {
|
|
18835
|
+
zeroes++;
|
|
18836
|
+
psz++;
|
|
18837
|
+
}
|
|
18838
|
+
var size = (source.length - psz) * FACTOR + 1 >>> 0;
|
|
18839
|
+
var b256 = new Uint8Array(size);
|
|
18840
|
+
while (source[psz]) {
|
|
18841
|
+
var carry = BASE_MAP[source.charCodeAt(psz)];
|
|
18842
|
+
if (carry === 255) {
|
|
18843
|
+
return;
|
|
18844
|
+
}
|
|
18845
|
+
var i2 = 0;
|
|
18846
|
+
for (var it3 = size - 1; (carry !== 0 || i2 < length) && it3 !== -1; it3--, i2++) {
|
|
18847
|
+
carry += BASE * b256[it3] >>> 0;
|
|
18848
|
+
b256[it3] = carry % 256 >>> 0;
|
|
18849
|
+
carry = carry / 256 >>> 0;
|
|
18850
|
+
}
|
|
18851
|
+
if (carry !== 0) {
|
|
18852
|
+
throw new Error("Non-zero carry");
|
|
18853
|
+
}
|
|
18854
|
+
length = i2;
|
|
18855
|
+
psz++;
|
|
18856
|
+
}
|
|
18857
|
+
if (source[psz] === " ") {
|
|
18858
|
+
return;
|
|
18859
|
+
}
|
|
18860
|
+
var it4 = size - length;
|
|
18861
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
18862
|
+
it4++;
|
|
18863
|
+
}
|
|
18864
|
+
var vch = new Uint8Array(zeroes + (size - it4));
|
|
18865
|
+
var j2 = zeroes;
|
|
18866
|
+
while (it4 !== size) {
|
|
18867
|
+
vch[j2++] = b256[it4++];
|
|
18868
|
+
}
|
|
18869
|
+
return vch;
|
|
18870
|
+
}
|
|
18871
|
+
function decode(string) {
|
|
18872
|
+
var buffer = decodeUnsafe(string);
|
|
18873
|
+
if (buffer) {
|
|
18874
|
+
return buffer;
|
|
18875
|
+
}
|
|
18876
|
+
throw new Error(`Non-${name} character`);
|
|
18877
|
+
}
|
|
18878
|
+
return {
|
|
18879
|
+
encode,
|
|
18880
|
+
decodeUnsafe,
|
|
18881
|
+
decode
|
|
18882
|
+
};
|
|
18883
|
+
}
|
|
18884
|
+
var src = base;
|
|
18885
|
+
var _brrp__multiformats_scope_baseX = src;
|
|
18886
|
+
var base_x_default = _brrp__multiformats_scope_baseX;
|
|
18887
|
+
|
|
18888
|
+
// ../../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base.js
|
|
18889
|
+
var Encoder = class {
|
|
18890
|
+
name;
|
|
18891
|
+
prefix;
|
|
18892
|
+
baseEncode;
|
|
18893
|
+
constructor(name, prefix, baseEncode) {
|
|
18894
|
+
this.name = name;
|
|
18895
|
+
this.prefix = prefix;
|
|
18896
|
+
this.baseEncode = baseEncode;
|
|
18897
|
+
}
|
|
18898
|
+
encode(bytes) {
|
|
18899
|
+
if (bytes instanceof Uint8Array) {
|
|
18900
|
+
return `${this.prefix}${this.baseEncode(bytes)}`;
|
|
18901
|
+
} else {
|
|
18902
|
+
throw Error("Unknown type, must be binary type");
|
|
18903
|
+
}
|
|
18904
|
+
}
|
|
18905
|
+
};
|
|
18906
|
+
var Decoder = class {
|
|
18907
|
+
name;
|
|
18908
|
+
prefix;
|
|
18909
|
+
baseDecode;
|
|
18910
|
+
prefixCodePoint;
|
|
18911
|
+
constructor(name, prefix, baseDecode) {
|
|
18912
|
+
this.name = name;
|
|
18913
|
+
this.prefix = prefix;
|
|
18914
|
+
const prefixCodePoint = prefix.codePointAt(0);
|
|
18915
|
+
if (prefixCodePoint === void 0) {
|
|
18916
|
+
throw new Error("Invalid prefix character");
|
|
18917
|
+
}
|
|
18918
|
+
this.prefixCodePoint = prefixCodePoint;
|
|
18919
|
+
this.baseDecode = baseDecode;
|
|
18920
|
+
}
|
|
18921
|
+
decode(text) {
|
|
18922
|
+
if (typeof text === "string") {
|
|
18923
|
+
if (text.codePointAt(0) !== this.prefixCodePoint) {
|
|
18924
|
+
throw Error(`Unable to decode multibase string ${JSON.stringify(text)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);
|
|
18925
|
+
}
|
|
18926
|
+
return this.baseDecode(text.slice(this.prefix.length));
|
|
18927
|
+
} else {
|
|
18928
|
+
throw Error("Can only multibase decode strings");
|
|
18929
|
+
}
|
|
18930
|
+
}
|
|
18931
|
+
or(decoder) {
|
|
18932
|
+
return or(this, decoder);
|
|
18933
|
+
}
|
|
18934
|
+
};
|
|
18935
|
+
var ComposedDecoder = class {
|
|
18936
|
+
decoders;
|
|
18937
|
+
constructor(decoders) {
|
|
18938
|
+
this.decoders = decoders;
|
|
18939
|
+
}
|
|
18940
|
+
or(decoder) {
|
|
18941
|
+
return or(this, decoder);
|
|
18942
|
+
}
|
|
18943
|
+
decode(input) {
|
|
18944
|
+
const prefix = input[0];
|
|
18945
|
+
const decoder = this.decoders[prefix];
|
|
18946
|
+
if (decoder != null) {
|
|
18947
|
+
return decoder.decode(input);
|
|
18948
|
+
} else {
|
|
18949
|
+
throw RangeError(`Unable to decode multibase string ${JSON.stringify(input)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`);
|
|
18950
|
+
}
|
|
18951
|
+
}
|
|
18952
|
+
};
|
|
18953
|
+
function or(left, right) {
|
|
18954
|
+
return new ComposedDecoder({
|
|
18955
|
+
...left.decoders ?? { [left.prefix]: left },
|
|
18956
|
+
...right.decoders ?? { [right.prefix]: right }
|
|
18957
|
+
});
|
|
18958
|
+
}
|
|
18959
|
+
var Codec = class {
|
|
18960
|
+
name;
|
|
18961
|
+
prefix;
|
|
18962
|
+
baseEncode;
|
|
18963
|
+
baseDecode;
|
|
18964
|
+
encoder;
|
|
18965
|
+
decoder;
|
|
18966
|
+
constructor(name, prefix, baseEncode, baseDecode) {
|
|
18967
|
+
this.name = name;
|
|
18968
|
+
this.prefix = prefix;
|
|
18969
|
+
this.baseEncode = baseEncode;
|
|
18970
|
+
this.baseDecode = baseDecode;
|
|
18971
|
+
this.encoder = new Encoder(name, prefix, baseEncode);
|
|
18972
|
+
this.decoder = new Decoder(name, prefix, baseDecode);
|
|
18973
|
+
}
|
|
18974
|
+
encode(input) {
|
|
18975
|
+
return this.encoder.encode(input);
|
|
18976
|
+
}
|
|
18977
|
+
decode(input) {
|
|
18978
|
+
return this.decoder.decode(input);
|
|
18979
|
+
}
|
|
18980
|
+
};
|
|
18981
|
+
function from({ name, prefix, encode, decode }) {
|
|
18982
|
+
return new Codec(name, prefix, encode, decode);
|
|
18983
|
+
}
|
|
18984
|
+
function baseX({ name, prefix, alphabet }) {
|
|
18985
|
+
const { encode, decode } = base_x_default(alphabet, name);
|
|
18986
|
+
return from({
|
|
18987
|
+
prefix,
|
|
18988
|
+
name,
|
|
18989
|
+
encode,
|
|
18990
|
+
decode: (text) => coerce(decode(text))
|
|
18991
|
+
});
|
|
18992
|
+
}
|
|
18993
|
+
|
|
18994
|
+
// ../../../../node_modules/.pnpm/multiformats@13.4.2/node_modules/multiformats/dist/src/bases/base58.js
|
|
18995
|
+
var base58btc = baseX({
|
|
18996
|
+
name: "base58btc",
|
|
18997
|
+
prefix: "z",
|
|
18998
|
+
alphabet: "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
|
18999
|
+
});
|
|
19000
|
+
var base58flickr = baseX({
|
|
19001
|
+
name: "base58flickr",
|
|
19002
|
+
prefix: "Z",
|
|
19003
|
+
alphabet: "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
|
|
19004
|
+
});
|
|
19005
|
+
|
|
19006
|
+
// ../../crypto/dist/src/utils.js
|
|
19005
19007
|
var fromHexString = (hexString) => import_libsodium_wrappers.default.from_hex(hexString);
|
|
19006
19008
|
var asU8 = (bytes) => {
|
|
19007
19009
|
return bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
@@ -21217,15 +21219,15 @@ var resolveInstanceFromValue = async (fromTablePrefixedValues, tables, table, re
|
|
|
21217
21219
|
}
|
|
21218
21220
|
return Object.assign(Object.create(table.ctor.prototype), obj);
|
|
21219
21221
|
};
|
|
21220
|
-
var convertDeleteRequestToQuery = (request, tables, table) => {
|
|
21221
|
-
const { query, bindable } = convertRequestToQuery("delete", { query: coerceLocalQueries(request.query) }, tables, table);
|
|
21222
|
+
var convertDeleteRequestToQuery = (request, tables, table, options) => {
|
|
21223
|
+
const { query, bindable } = convertRequestToQuery("delete", { query: coerceLocalQueries(request.query) }, tables, table, void 0, [], options);
|
|
21222
21224
|
return {
|
|
21223
21225
|
sql: `DELETE FROM ${table.name} WHERE ${table.name}.${table.primary} IN (SELECT ${table.primary} from ${table.name} ${query}) returning ${table.primary}`,
|
|
21224
21226
|
bindable
|
|
21225
21227
|
};
|
|
21226
21228
|
};
|
|
21227
|
-
var convertSumRequestToQuery = (request, tables, table) => {
|
|
21228
|
-
const { query, bindable } = convertRequestToQuery("sum", { query: coerceLocalQueries(request.query), key: request.key }, tables, table);
|
|
21229
|
+
var convertSumRequestToQuery = (request, tables, table, options) => {
|
|
21230
|
+
const { query, bindable } = convertRequestToQuery("sum", { query: coerceLocalQueries(request.query), key: request.key }, tables, table, void 0, [], options);
|
|
21229
21231
|
const inlineName = getInlineTableFieldName(request.key);
|
|
21230
21232
|
const field2 = table.fields.find((x) => x.name === inlineName);
|
|
21231
21233
|
if (unwrapNestedType(field2.from.type) === "u64") {
|
|
@@ -21402,7 +21404,12 @@ var _buildJoin = (table, options) => {
|
|
|
21402
21404
|
if (table.columns.length > 0) {
|
|
21403
21405
|
const usedColumns = removeDuplicatesOrdered(table.columns);
|
|
21404
21406
|
const usesImplicitPrimaryKeyIndex = table.type === "root" && table.table.primary !== false && usedColumns.length === 1 && usedColumns[0] === table.table.primary;
|
|
21405
|
-
|
|
21407
|
+
if (options?.planner && !usesImplicitPrimaryKeyIndex) {
|
|
21408
|
+
const indexKey = options.planner.resolveIndex(table.table.name, usedColumns);
|
|
21409
|
+
indexedBy = options.planner.forceIndex ? ` INDEXED BY ${indexKey} ` : "";
|
|
21410
|
+
} else {
|
|
21411
|
+
indexedBy = "";
|
|
21412
|
+
}
|
|
21406
21413
|
}
|
|
21407
21414
|
if (table.type !== "root") {
|
|
21408
21415
|
let nonInlinedParent = table.table.parent && getNonInlinedTable(table.table.parent);
|
|
@@ -21690,10 +21697,14 @@ var __runInitializers4 = function(thisArg, initializers, value) {
|
|
|
21690
21697
|
}
|
|
21691
21698
|
return useValue ? value : void 0;
|
|
21692
21699
|
};
|
|
21693
|
-
var getSortedNameKey = (tableName, names) => [tableName, ...names.sort()].join(",");
|
|
21694
|
-
var
|
|
21700
|
+
var getSortedNameKey = (tableName, names) => [tableName, ...[...names].sort()].join(",");
|
|
21701
|
+
var getIndexColumnKey = (field2) => `${field2.name}${field2.collation ? `_collate_${field2.collation.toLowerCase()}` : ""}`;
|
|
21702
|
+
var createIndexKey = (tableName, fields) => `${tableName}_index_${fields.map((x) => getIndexColumnKey(x).replace(/[^a-zA-Z0-9_]/g, "_")).join("_")}`;
|
|
21703
|
+
var createIndexColumnSQL = (field2) => `${escapeColumnName(field2.name)}${field2.collation ? ` COLLATE ${field2.collation}` : ""}`;
|
|
21695
21704
|
var HALF_MAX_U32 = 2147483647;
|
|
21696
21705
|
var HALF_MAX_U64 = 9223372036854775807n;
|
|
21706
|
+
var PARENT_TABLE_ID2 = "__parent_id";
|
|
21707
|
+
var AMBIGUOUS_CHILD_FORCE_AFTER_USES = 6e3;
|
|
21697
21708
|
var flattenQuery = function* (props) {
|
|
21698
21709
|
if (!props) {
|
|
21699
21710
|
return yield props;
|
|
@@ -21848,21 +21859,40 @@ var QueryPlanner = class {
|
|
|
21848
21859
|
let indexCreateCommands = void 0;
|
|
21849
21860
|
let pickedIndexKeys = /* @__PURE__ */ new Map();
|
|
21850
21861
|
let indexCreationPromiseToAwait = [];
|
|
21862
|
+
let forceIndex = this.props.forceIndexes !== false;
|
|
21851
21863
|
return {
|
|
21864
|
+
get forceIndex() {
|
|
21865
|
+
return forceIndex;
|
|
21866
|
+
},
|
|
21852
21867
|
beforePrepare: async () => {
|
|
21853
21868
|
if (indexCreateCommands != null) {
|
|
21854
|
-
|
|
21869
|
+
const commandsToCreate = [];
|
|
21870
|
+
for (const command of indexCreateCommands) {
|
|
21871
|
+
if (this.pendingIndexCreation.has(command.key)) {
|
|
21872
|
+
await this.pendingIndexCreation.get(command.key);
|
|
21873
|
+
continue;
|
|
21874
|
+
}
|
|
21875
|
+
commandsToCreate.push(command);
|
|
21876
|
+
}
|
|
21877
|
+
if (commandsToCreate.length > 0) {
|
|
21878
|
+
const creationPromise = Promise.resolve(this.props.exec([
|
|
21879
|
+
...commandsToCreate.map((command) => command.cmd),
|
|
21880
|
+
...this.props.optimizeAfterCreate === false ? [] : ["PRAGMA optimize"]
|
|
21881
|
+
].join(";")));
|
|
21882
|
+
for (const { key } of commandsToCreate) {
|
|
21883
|
+
this.pendingIndexCreation.set(key, creationPromise);
|
|
21884
|
+
}
|
|
21855
21885
|
try {
|
|
21856
|
-
|
|
21857
|
-
|
|
21886
|
+
await creationPromise;
|
|
21887
|
+
for (const { key, deferred } of commandsToCreate) {
|
|
21888
|
+
this.pendingIndexCreation.delete(key);
|
|
21889
|
+
deferred.resolve();
|
|
21858
21890
|
}
|
|
21859
|
-
const promise = this.props.exec(cmd);
|
|
21860
|
-
this.pendingIndexCreation.set(key, promise);
|
|
21861
|
-
await promise;
|
|
21862
|
-
this.pendingIndexCreation.delete(key);
|
|
21863
|
-
deferred.resolve();
|
|
21864
21891
|
} catch (error2) {
|
|
21865
|
-
deferred
|
|
21892
|
+
for (const { key, deferred } of commandsToCreate) {
|
|
21893
|
+
this.pendingIndexCreation.delete(key);
|
|
21894
|
+
deferred.reject(error2);
|
|
21895
|
+
}
|
|
21866
21896
|
}
|
|
21867
21897
|
}
|
|
21868
21898
|
}
|
|
@@ -21874,6 +21904,7 @@ var QueryPlanner = class {
|
|
|
21874
21904
|
await Promise.all(indexCreationPromiseToAwait);
|
|
21875
21905
|
},
|
|
21876
21906
|
resolveIndex: (tableName, columns) => {
|
|
21907
|
+
forceIndex = this.props.forceIndexes !== false;
|
|
21877
21908
|
const sortedNameKey = getSortedNameKey(tableName, columns);
|
|
21878
21909
|
let indexStats = obj.columnsToIndexes.get(sortedNameKey);
|
|
21879
21910
|
if (indexStats === void 0) {
|
|
@@ -21883,10 +21914,10 @@ var QueryPlanner = class {
|
|
|
21883
21914
|
obj.columnsToIndexes.set(sortedNameKey, indexStats);
|
|
21884
21915
|
}
|
|
21885
21916
|
if (indexStats.results.length === 0) {
|
|
21886
|
-
const
|
|
21887
|
-
for (const columns2 of
|
|
21917
|
+
const candidates = generateIndexCandidates(query, columns);
|
|
21918
|
+
for (const columns2 of candidates) {
|
|
21888
21919
|
const indexKey = createIndexKey(tableName, columns2);
|
|
21889
|
-
const command = `create index if not exists ${indexKey} on ${tableName} (${columns2.map((n) =>
|
|
21920
|
+
const command = `create index if not exists ${indexKey} on ${tableName} (${columns2.map((n) => createIndexColumnSQL(n)).join(", ")})`;
|
|
21890
21921
|
let deferred = pDefer();
|
|
21891
21922
|
(indexCreateCommands || (indexCreateCommands = [])).push({
|
|
21892
21923
|
cmd: command,
|
|
@@ -21903,11 +21934,17 @@ var QueryPlanner = class {
|
|
|
21903
21934
|
avg: -1,
|
|
21904
21935
|
// setting -1 will force the first time to be the fastest (i.e. new indices are always tested once)
|
|
21905
21936
|
indexKey,
|
|
21937
|
+
columns: columns2,
|
|
21906
21938
|
created: () => created,
|
|
21907
21939
|
creationPromiseDeferred: deferred
|
|
21908
21940
|
});
|
|
21909
21941
|
}
|
|
21910
21942
|
}
|
|
21943
|
+
const isAmbiguousChildPredicate = query.sort.length === 0 && columns.includes(PARENT_TABLE_ID2) && columns.length > 1;
|
|
21944
|
+
if (isAmbiguousChildPredicate) {
|
|
21945
|
+
const totalUses = indexStats.results.reduce((sum, result) => sum + result.used, 0);
|
|
21946
|
+
forceIndex = this.props.forceIndexes !== false && totalUses >= AMBIGUOUS_CHILD_FORCE_AFTER_USES;
|
|
21947
|
+
}
|
|
21911
21948
|
let fastestIndex = indexStats.results[0];
|
|
21912
21949
|
fastestIndex.used++;
|
|
21913
21950
|
if (!fastestIndex.created()) {
|
|
@@ -21942,10 +21979,132 @@ var QueryPlanner = class {
|
|
|
21942
21979
|
};
|
|
21943
21980
|
}
|
|
21944
21981
|
};
|
|
21945
|
-
var
|
|
21946
|
-
if (
|
|
21947
|
-
return [
|
|
21948
|
-
|
|
21982
|
+
var queryKeyToColumnName = (key) => {
|
|
21983
|
+
if (key.length > 2) {
|
|
21984
|
+
return `${key.slice(0, -1).join("_")}__${key[key.length - 1]}`;
|
|
21985
|
+
}
|
|
21986
|
+
return key.join("__");
|
|
21987
|
+
};
|
|
21988
|
+
var pushUniqueColumn = (list, column) => {
|
|
21989
|
+
const key = getIndexColumnKey(column);
|
|
21990
|
+
if (!list.some((x) => getIndexColumnKey(x) === key)) {
|
|
21991
|
+
list.push(column);
|
|
21992
|
+
}
|
|
21993
|
+
};
|
|
21994
|
+
var pushColumns = (target, columns) => {
|
|
21995
|
+
for (const column of columns) {
|
|
21996
|
+
pushUniqueColumn(target, column);
|
|
21997
|
+
}
|
|
21998
|
+
};
|
|
21999
|
+
var getIndexableQueryColumns = (query, availableColumns) => {
|
|
22000
|
+
const equality = [];
|
|
22001
|
+
const range = [];
|
|
22002
|
+
const visit = (item, path = []) => {
|
|
22003
|
+
if (item instanceof And) {
|
|
22004
|
+
for (const condition of item.and) {
|
|
22005
|
+
visit(condition, path);
|
|
22006
|
+
}
|
|
22007
|
+
return;
|
|
22008
|
+
}
|
|
22009
|
+
if (item instanceof Or) {
|
|
22010
|
+
for (const condition of item.or) {
|
|
22011
|
+
visit(condition, path);
|
|
22012
|
+
}
|
|
22013
|
+
return;
|
|
22014
|
+
}
|
|
22015
|
+
if (item instanceof Not) {
|
|
22016
|
+
return;
|
|
22017
|
+
}
|
|
22018
|
+
if (item instanceof Nested) {
|
|
22019
|
+
for (const condition of item.query) {
|
|
22020
|
+
visit(condition, [...path, ...item.path]);
|
|
22021
|
+
}
|
|
22022
|
+
return;
|
|
22023
|
+
}
|
|
22024
|
+
let key;
|
|
22025
|
+
let target;
|
|
22026
|
+
let collation;
|
|
22027
|
+
if (item instanceof IntegerCompare) {
|
|
22028
|
+
key = item.key;
|
|
22029
|
+
target = item.compare === Compare.Equal ? equality : range;
|
|
22030
|
+
} else if (item instanceof StringMatch) {
|
|
22031
|
+
key = item.key;
|
|
22032
|
+
if (item.method === StringMatchMethod.contains) {
|
|
22033
|
+
return;
|
|
22034
|
+
}
|
|
22035
|
+
target = item.method === StringMatchMethod.exact ? equality : range;
|
|
22036
|
+
collation = item.caseInsensitive ? "NOCASE" : void 0;
|
|
22037
|
+
} else if (item instanceof ByteMatchQuery || item instanceof BoolQuery || item instanceof IsNull) {
|
|
22038
|
+
key = item.key;
|
|
22039
|
+
target = equality;
|
|
22040
|
+
}
|
|
22041
|
+
if (!key || !target) {
|
|
22042
|
+
return;
|
|
22043
|
+
}
|
|
22044
|
+
const columnName = queryKeyToColumnName([...path, ...key]);
|
|
22045
|
+
if (availableColumns.has(columnName)) {
|
|
22046
|
+
pushUniqueColumn(target, { name: columnName, collation });
|
|
22047
|
+
}
|
|
22048
|
+
};
|
|
22049
|
+
for (const item of query) {
|
|
22050
|
+
visit(item);
|
|
22051
|
+
}
|
|
22052
|
+
return { equality, range };
|
|
22053
|
+
};
|
|
22054
|
+
var getSortableColumns = (sort, availableColumns) => {
|
|
22055
|
+
const out = [];
|
|
22056
|
+
for (const item of sort) {
|
|
22057
|
+
const columnName = queryKeyToColumnName(item.key);
|
|
22058
|
+
if (availableColumns.has(columnName)) {
|
|
22059
|
+
pushUniqueColumn(out, { name: columnName });
|
|
22060
|
+
}
|
|
22061
|
+
}
|
|
22062
|
+
return out;
|
|
22063
|
+
};
|
|
22064
|
+
var normalizeCandidate = (columns) => {
|
|
22065
|
+
const out = [];
|
|
22066
|
+
pushColumns(out, columns);
|
|
22067
|
+
return out;
|
|
22068
|
+
};
|
|
22069
|
+
var generateIndexCandidates = (query, columns) => {
|
|
22070
|
+
if (columns.length === 0) {
|
|
22071
|
+
return [];
|
|
22072
|
+
}
|
|
22073
|
+
const availableColumns = new Set(columns);
|
|
22074
|
+
const { equality, range } = getIndexableQueryColumns(query.query, availableColumns);
|
|
22075
|
+
const sort = getSortableColumns(query.sort, availableColumns);
|
|
22076
|
+
const join = availableColumns.has(PARENT_TABLE_ID2) ? [{ name: PARENT_TABLE_ID2 }] : [];
|
|
22077
|
+
const knownColumnNames = new Set([...join, ...equality, ...range, ...sort].map((x) => x.name));
|
|
22078
|
+
const remaining = columns.filter((column) => !knownColumnNames.has(column)).map((name) => ({ name }));
|
|
22079
|
+
const candidates = [];
|
|
22080
|
+
const pushCandidate = (...parts) => {
|
|
22081
|
+
const candidate = normalizeCandidate(parts.flat());
|
|
22082
|
+
if (candidate.length > 0 && !candidates.some((existing) => existing.map(getIndexColumnKey).join(",") === candidate.map(getIndexColumnKey).join(","))) {
|
|
22083
|
+
candidates.push(candidate);
|
|
22084
|
+
}
|
|
22085
|
+
};
|
|
22086
|
+
if (sort.length > 0 && range.length > 0) {
|
|
22087
|
+
pushCandidate(join, equality, sort, range, remaining);
|
|
22088
|
+
pushCandidate(join, equality, range, sort, remaining);
|
|
22089
|
+
} else if (sort.length > 0) {
|
|
22090
|
+
pushCandidate(join, equality, sort, range, remaining);
|
|
22091
|
+
} else {
|
|
22092
|
+
if (join.length > 0 && (equality.length > 0 || range.length > 0)) {
|
|
22093
|
+
pushCandidate(equality, range, join, remaining);
|
|
22094
|
+
}
|
|
22095
|
+
pushCandidate(join, equality, range, remaining);
|
|
22096
|
+
}
|
|
22097
|
+
if (join.length > 0 && (equality.length > 0 || range.length > 0)) {
|
|
22098
|
+
if (sort.length > 0 && range.length > 0) {
|
|
22099
|
+
pushCandidate(equality, sort, range, join, remaining);
|
|
22100
|
+
pushCandidate(equality, range, sort, join, remaining);
|
|
22101
|
+
} else if (sort.length > 0) {
|
|
22102
|
+
pushCandidate(equality, range, sort, join, remaining);
|
|
22103
|
+
}
|
|
22104
|
+
}
|
|
22105
|
+
pushCandidate(columns.map((name) => ({ name })));
|
|
22106
|
+
pushCandidate([...columns].reverse().map((name) => ({ name })));
|
|
22107
|
+
return candidates;
|
|
21949
22108
|
};
|
|
21950
22109
|
|
|
21951
22110
|
// dist/src/utils.js
|
|
@@ -22011,13 +22170,16 @@ var createBatchInsertSQL = (table, rows) => {
|
|
|
22011
22170
|
length: rows
|
|
22012
22171
|
}).map(() => rowPlaceholder).join(", ")};`;
|
|
22013
22172
|
};
|
|
22173
|
+
var createInsertReturningSQL = (table) => `insert into ${table.name} (${table.fields.map((field2) => escapeColumnName(field2.name)).join(", ")}) VALUES (${table.fields.map((_x) => "?").join(", ")}) RETURNING ${table.primary};`;
|
|
22174
|
+
var createInsertKnownIdSQL = (table) => `insert into ${table.name} (${table.fields.map((field2) => escapeColumnName(field2.name)).join(", ")}) VALUES (${table.fields.map((_x) => "?").join(", ")});`;
|
|
22175
|
+
var createReplaceSQL = (table) => `insert or replace into ${table.name} (${table.fields.map((field2) => escapeColumnName(field2.name)).join(", ")}) VALUES (${table.fields.map((_x) => "?").join(", ")});`;
|
|
22014
22176
|
var canUseWithoutRowId = (table) => {
|
|
22015
22177
|
if (table.inline || table.primary === false || !table.primaryField) {
|
|
22016
22178
|
return false;
|
|
22017
22179
|
}
|
|
22018
22180
|
return !/^INTEGER\b/i.test(table.primaryField.type);
|
|
22019
22181
|
};
|
|
22020
|
-
var SQLiteIndex = class {
|
|
22182
|
+
var SQLiteIndex = class _SQLiteIndex {
|
|
22021
22183
|
properties;
|
|
22022
22184
|
// SQLite writes are inherently serialized per connection.
|
|
22023
22185
|
// We still need an explicit async barrier because our API is async and
|
|
@@ -22047,13 +22209,14 @@ var SQLiteIndex = class {
|
|
|
22047
22209
|
primaryKeyString;
|
|
22048
22210
|
planner;
|
|
22049
22211
|
scopeString;
|
|
22050
|
-
_rootTables;
|
|
22051
|
-
_tables;
|
|
22052
|
-
_cursor;
|
|
22212
|
+
_rootTables = [];
|
|
22213
|
+
_tables = /* @__PURE__ */ new Map();
|
|
22214
|
+
_cursor = /* @__PURE__ */ new Map();
|
|
22053
22215
|
// TODO choose limit better
|
|
22054
22216
|
cursorPruner;
|
|
22055
22217
|
iteratorTimeout;
|
|
22056
22218
|
closed = true;
|
|
22219
|
+
state = "closed";
|
|
22057
22220
|
fkMode;
|
|
22058
22221
|
id;
|
|
22059
22222
|
constructor(properties, options) {
|
|
@@ -22070,21 +22233,74 @@ var SQLiteIndex = class {
|
|
|
22070
22233
|
persisted() {
|
|
22071
22234
|
return this.properties.persisted ?? true;
|
|
22072
22235
|
}
|
|
22236
|
+
static _emptyTables = /* @__PURE__ */ new Map();
|
|
22237
|
+
static _emptyRootTables = [];
|
|
22238
|
+
static _emptyCursor = /* @__PURE__ */ new Map();
|
|
22239
|
+
static closedIterator() {
|
|
22240
|
+
return {
|
|
22241
|
+
all: async () => [],
|
|
22242
|
+
close: async () => void 0,
|
|
22243
|
+
done: () => true,
|
|
22244
|
+
next: async () => [],
|
|
22245
|
+
pending: async () => 0
|
|
22246
|
+
};
|
|
22247
|
+
}
|
|
22248
|
+
async ifOpen(fallback, fn) {
|
|
22249
|
+
if (this.isClosing()) {
|
|
22250
|
+
return fallback;
|
|
22251
|
+
}
|
|
22252
|
+
this.assertOpen();
|
|
22253
|
+
try {
|
|
22254
|
+
return await fn();
|
|
22255
|
+
} catch (error2) {
|
|
22256
|
+
if (this.isClosing()) {
|
|
22257
|
+
return fallback;
|
|
22258
|
+
}
|
|
22259
|
+
throw error2;
|
|
22260
|
+
}
|
|
22261
|
+
}
|
|
22262
|
+
async withWriteIfOpen(fallback, fn) {
|
|
22263
|
+
if (this.isClosing()) {
|
|
22264
|
+
return fallback;
|
|
22265
|
+
}
|
|
22266
|
+
this.assertOpen();
|
|
22267
|
+
return this.withWriteBarrier(() => this.ifOpen(fallback, fn));
|
|
22268
|
+
}
|
|
22269
|
+
assertOpen() {
|
|
22270
|
+
if (this.state !== "open") {
|
|
22271
|
+
throw new NotStartedError();
|
|
22272
|
+
}
|
|
22273
|
+
}
|
|
22274
|
+
isClosing() {
|
|
22275
|
+
return this.state === "closing";
|
|
22276
|
+
}
|
|
22277
|
+
setClosing() {
|
|
22278
|
+
this.state = "closing";
|
|
22279
|
+
this.closed = true;
|
|
22280
|
+
}
|
|
22281
|
+
setClosed() {
|
|
22282
|
+
this.state = "closed";
|
|
22283
|
+
this.closed = true;
|
|
22284
|
+
}
|
|
22285
|
+
setOpen() {
|
|
22286
|
+
this.state = "open";
|
|
22287
|
+
this.closed = false;
|
|
22288
|
+
}
|
|
22073
22289
|
get tables() {
|
|
22074
22290
|
if (this.closed) {
|
|
22075
|
-
|
|
22291
|
+
return _SQLiteIndex._emptyTables;
|
|
22076
22292
|
}
|
|
22077
22293
|
return this._tables;
|
|
22078
22294
|
}
|
|
22079
22295
|
get rootTables() {
|
|
22080
22296
|
if (this.closed) {
|
|
22081
|
-
|
|
22297
|
+
return _SQLiteIndex._emptyRootTables;
|
|
22082
22298
|
}
|
|
22083
22299
|
return this._rootTables;
|
|
22084
22300
|
}
|
|
22085
22301
|
get cursor() {
|
|
22086
22302
|
if (this.closed) {
|
|
22087
|
-
|
|
22303
|
+
return _SQLiteIndex._emptyCursor;
|
|
22088
22304
|
}
|
|
22089
22305
|
return this._cursor;
|
|
22090
22306
|
}
|
|
@@ -22105,9 +22321,12 @@ var SQLiteIndex = class {
|
|
|
22105
22321
|
return this;
|
|
22106
22322
|
}
|
|
22107
22323
|
async start() {
|
|
22108
|
-
if (this.
|
|
22324
|
+
if (this.state === "open") {
|
|
22109
22325
|
return;
|
|
22110
22326
|
}
|
|
22327
|
+
if (this.state === "closing") {
|
|
22328
|
+
throw new NotStartedError();
|
|
22329
|
+
}
|
|
22111
22330
|
if (this.primaryKeyArr == null || this.primaryKeyArr.length === 0) {
|
|
22112
22331
|
throw new Error("Not initialized");
|
|
22113
22332
|
}
|
|
@@ -22125,6 +22344,8 @@ var SQLiteIndex = class {
|
|
|
22125
22344
|
);
|
|
22126
22345
|
this._rootTables = tables.filter((x) => x.parent == null);
|
|
22127
22346
|
const allTables = tables;
|
|
22347
|
+
const startupStatements = [];
|
|
22348
|
+
const startupTableStatements = /* @__PURE__ */ new Map();
|
|
22128
22349
|
for (const table of allTables) {
|
|
22129
22350
|
this._tables.set(table.name, table);
|
|
22130
22351
|
for (const child of table.children) {
|
|
@@ -22135,15 +22356,38 @@ var SQLiteIndex = class {
|
|
|
22135
22356
|
}
|
|
22136
22357
|
const tableOptions = canUseWithoutRowId(table) ? " strict, without rowid" : " strict";
|
|
22137
22358
|
const sqlCreateTable = `create table if not exists ${table.name} (${[...table.fields, ...table.constraints].map((s) => s.definition).join(", ")})${tableOptions}`;
|
|
22138
|
-
|
|
22139
|
-
|
|
22140
|
-
|
|
22141
|
-
|
|
22142
|
-
|
|
22143
|
-
|
|
22144
|
-
|
|
22359
|
+
startupTableStatements.set(table.name, sqlCreateTable);
|
|
22360
|
+
startupStatements.push({
|
|
22361
|
+
id: putStatementKey(table),
|
|
22362
|
+
sql: createInsertReturningSQL(table)
|
|
22363
|
+
}, {
|
|
22364
|
+
id: insertKnownIdStatementKey(table),
|
|
22365
|
+
sql: createInsertKnownIdSQL(table)
|
|
22366
|
+
}, {
|
|
22367
|
+
id: replaceStatementKey(table),
|
|
22368
|
+
sql: createReplaceSQL(table)
|
|
22369
|
+
});
|
|
22145
22370
|
if (table.parent) {
|
|
22146
|
-
|
|
22371
|
+
startupStatements.push({
|
|
22372
|
+
id: resolveChildrenStatement(table),
|
|
22373
|
+
sql: selectChildren(table)
|
|
22374
|
+
});
|
|
22375
|
+
}
|
|
22376
|
+
}
|
|
22377
|
+
if (startupTableStatements.size > 0) {
|
|
22378
|
+
const existingTables = await this.getExistingSQLiteObjects("table", [
|
|
22379
|
+
...startupTableStatements.keys()
|
|
22380
|
+
]);
|
|
22381
|
+
const missingTableStatements = [...startupTableStatements.entries()].filter(([tableName]) => !existingTables.has(tableName)).map(([, sql]) => sql);
|
|
22382
|
+
if (missingTableStatements.length > 0) {
|
|
22383
|
+
await this.properties.db.exec(missingTableStatements.join(";"));
|
|
22384
|
+
}
|
|
22385
|
+
}
|
|
22386
|
+
if (this.properties.db.prepareMany) {
|
|
22387
|
+
await this.properties.db.prepareMany(startupStatements);
|
|
22388
|
+
} else {
|
|
22389
|
+
for (const statement of startupStatements) {
|
|
22390
|
+
await this.properties.db.prepare(statement.sql, statement.id);
|
|
22147
22391
|
}
|
|
22148
22392
|
}
|
|
22149
22393
|
this.cursorPruner = setInterval(() => {
|
|
@@ -22154,7 +22398,17 @@ var SQLiteIndex = class {
|
|
|
22154
22398
|
}
|
|
22155
22399
|
}
|
|
22156
22400
|
}, this.iteratorTimeout);
|
|
22157
|
-
this.
|
|
22401
|
+
this.setOpen();
|
|
22402
|
+
}
|
|
22403
|
+
async getExistingSQLiteObjects(type, names) {
|
|
22404
|
+
if (names.length === 0) {
|
|
22405
|
+
return /* @__PURE__ */ new Set();
|
|
22406
|
+
}
|
|
22407
|
+
const sql = `select name from sqlite_master where type = ? and name in (${names.map(() => "?").join(", ")})`;
|
|
22408
|
+
const statement = this.properties.db.statements.get(sql) || await this.properties.db.prepare(sql, sql);
|
|
22409
|
+
const rows = await statement.all([type, ...names]);
|
|
22410
|
+
await statement.reset?.();
|
|
22411
|
+
return new Set(rows.map((row) => row.name).filter((name) => typeof name === "string"));
|
|
22158
22412
|
}
|
|
22159
22413
|
async clearStatements() {
|
|
22160
22414
|
if (await this.properties.db.status() === "closed") {
|
|
@@ -22162,52 +22416,82 @@ var SQLiteIndex = class {
|
|
|
22162
22416
|
}
|
|
22163
22417
|
}
|
|
22164
22418
|
async stop() {
|
|
22165
|
-
if (this.closed) {
|
|
22419
|
+
if (this.state === "closed") {
|
|
22166
22420
|
return;
|
|
22167
22421
|
}
|
|
22168
|
-
this.
|
|
22169
|
-
|
|
22170
|
-
|
|
22171
|
-
this._tables.clear();
|
|
22172
|
-
for (const [k, _v] of this._cursor) {
|
|
22173
|
-
await this.clearupIterator(k);
|
|
22174
|
-
}
|
|
22175
|
-
await this.planner.stop();
|
|
22176
|
-
}
|
|
22177
|
-
async drop() {
|
|
22178
|
-
if (!this.closed) {
|
|
22179
|
-
this.closed = true;
|
|
22422
|
+
if (this.state === "closing") {
|
|
22423
|
+
await this._writeBarrier.catch(() => void 0);
|
|
22424
|
+
return;
|
|
22180
22425
|
}
|
|
22181
|
-
|
|
22426
|
+
this.setClosing();
|
|
22427
|
+
try {
|
|
22182
22428
|
clearInterval(this.cursorPruner);
|
|
22183
|
-
this.
|
|
22184
|
-
|
|
22185
|
-
|
|
22186
|
-
|
|
22187
|
-
|
|
22188
|
-
|
|
22429
|
+
await this._writeBarrier.catch(() => void 0);
|
|
22430
|
+
await this.clearStatements();
|
|
22431
|
+
this._tables?.clear();
|
|
22432
|
+
if (this._cursor) {
|
|
22433
|
+
for (const [k, _v] of this._cursor) {
|
|
22434
|
+
await this.clearupIterator(k);
|
|
22435
|
+
}
|
|
22436
|
+
}
|
|
22437
|
+
await this.planner.stop();
|
|
22438
|
+
} finally {
|
|
22439
|
+
this.setClosed();
|
|
22189
22440
|
}
|
|
22190
|
-
|
|
22191
|
-
|
|
22192
|
-
|
|
22441
|
+
}
|
|
22442
|
+
async drop() {
|
|
22443
|
+
const wasOpen = this.state === "open";
|
|
22444
|
+
if (wasOpen) {
|
|
22445
|
+
this.setClosing();
|
|
22193
22446
|
}
|
|
22194
|
-
|
|
22195
|
-
|
|
22196
|
-
|
|
22447
|
+
try {
|
|
22448
|
+
if (this.cursorPruner != null) {
|
|
22449
|
+
clearInterval(this.cursorPruner);
|
|
22450
|
+
this.cursorPruner = void 0;
|
|
22451
|
+
}
|
|
22452
|
+
if (wasOpen) {
|
|
22453
|
+
await this._writeBarrier.catch(() => void 0);
|
|
22454
|
+
}
|
|
22455
|
+
const status = await this.properties.db.status?.();
|
|
22456
|
+
if (status === "closed") {
|
|
22457
|
+
this._tables?.clear();
|
|
22458
|
+
return;
|
|
22459
|
+
}
|
|
22460
|
+
await this.clearStatements();
|
|
22461
|
+
if (this._rootTables) {
|
|
22462
|
+
for (const table of this._rootTables) {
|
|
22463
|
+
await this.properties.db.exec(`drop table if exists ${table.name}`);
|
|
22464
|
+
}
|
|
22465
|
+
}
|
|
22466
|
+
this._tables?.clear();
|
|
22467
|
+
if (this._cursor) {
|
|
22468
|
+
for (const [k, _v] of this._cursor) {
|
|
22469
|
+
await this.clearupIterator(k);
|
|
22470
|
+
}
|
|
22471
|
+
}
|
|
22472
|
+
await this.planner.stop();
|
|
22473
|
+
} finally {
|
|
22474
|
+
this.setClosed();
|
|
22197
22475
|
}
|
|
22198
|
-
await this.planner.stop();
|
|
22199
22476
|
}
|
|
22200
22477
|
async resolveDependencies(parentId, table) {
|
|
22201
|
-
const stmt = this.
|
|
22478
|
+
const stmt = await this.getOrPrepareStatement(resolveChildrenStatement(table), selectChildren(table));
|
|
22202
22479
|
const results = await stmt.all([parentId]);
|
|
22203
22480
|
await stmt.reset?.();
|
|
22204
22481
|
return results;
|
|
22205
22482
|
}
|
|
22483
|
+
async getOrPrepareStatement(key, sql) {
|
|
22484
|
+
const existing = this.properties.db.statements.get(key);
|
|
22485
|
+
if (existing) {
|
|
22486
|
+
return existing;
|
|
22487
|
+
}
|
|
22488
|
+
return this.properties.db.prepare(sql, key);
|
|
22489
|
+
}
|
|
22206
22490
|
async get(id, options) {
|
|
22207
|
-
|
|
22208
|
-
const
|
|
22209
|
-
|
|
22210
|
-
|
|
22491
|
+
return this.ifOpen(void 0, async () => {
|
|
22492
|
+
for (const table of this._rootTables) {
|
|
22493
|
+
const { join: joinMap, selects } = selectAllFieldsFromTable(table, options?.shape);
|
|
22494
|
+
const sql = `${generateSelectQuery(table, selects)} ${buildJoin(joinMap).join} where ${table.name}.${this.primaryKeyString} = ? limit 1`;
|
|
22211
22495
|
const stmt = await this.properties.db.prepare(sql, sql);
|
|
22212
22496
|
const rows = await stmt.get([
|
|
22213
22497
|
table.primaryField?.from?.type ? convertToSQLType(id.key, table.primaryField.from.type) : id.key
|
|
@@ -22219,17 +22503,12 @@ var SQLiteIndex = class {
|
|
|
22219
22503
|
value: await resolveInstanceFromValue(rows, this.tables, table, this.resolveDependencies.bind(this), true, options?.shape),
|
|
22220
22504
|
id
|
|
22221
22505
|
};
|
|
22222
|
-
} catch (error2) {
|
|
22223
|
-
if (this.closed) {
|
|
22224
|
-
throw new NotStartedError();
|
|
22225
|
-
}
|
|
22226
|
-
throw error2;
|
|
22227
22506
|
}
|
|
22228
|
-
|
|
22229
|
-
|
|
22507
|
+
return void 0;
|
|
22508
|
+
});
|
|
22230
22509
|
}
|
|
22231
22510
|
async put(value, _id, options) {
|
|
22232
|
-
return this.
|
|
22511
|
+
return this.withWriteIfOpen(void 0, async () => {
|
|
22233
22512
|
const classOfValue = value.constructor;
|
|
22234
22513
|
return insert(async (values, table) => {
|
|
22235
22514
|
let preId = values[table.primaryIndex];
|
|
@@ -22238,7 +22517,7 @@ var SQLiteIndex = class {
|
|
|
22238
22517
|
if (preId != null) {
|
|
22239
22518
|
const shouldReplace = options?.replace ?? true;
|
|
22240
22519
|
if (!shouldReplace) {
|
|
22241
|
-
statement = this.
|
|
22520
|
+
statement = await this.getOrPrepareStatement(insertKnownIdStatementKey(table), createInsertKnownIdSQL(table));
|
|
22242
22521
|
try {
|
|
22243
22522
|
this.fkMode === "race-tolerant" ? await runIgnoreFK(statement, values) : await statement.run(values);
|
|
22244
22523
|
} catch (error2) {
|
|
@@ -22246,16 +22525,16 @@ var SQLiteIndex = class {
|
|
|
22246
22525
|
throw error2;
|
|
22247
22526
|
}
|
|
22248
22527
|
await statement.reset?.();
|
|
22249
|
-
statement = this.
|
|
22528
|
+
statement = await this.getOrPrepareStatement(replaceStatementKey(table), createReplaceSQL(table));
|
|
22250
22529
|
this.fkMode === "race-tolerant" ? await runIgnoreFK(statement, values) : await statement.run(values);
|
|
22251
22530
|
}
|
|
22252
22531
|
} else {
|
|
22253
|
-
statement = this.
|
|
22532
|
+
statement = await this.getOrPrepareStatement(replaceStatementKey(table), createReplaceSQL(table));
|
|
22254
22533
|
this.fkMode === "race-tolerant" ? await runIgnoreFK(statement, values) : await statement.run(values);
|
|
22255
22534
|
}
|
|
22256
22535
|
return preId;
|
|
22257
22536
|
} else {
|
|
22258
|
-
statement = this.
|
|
22537
|
+
statement = await this.getOrPrepareStatement(putStatementKey(table), createInsertReturningSQL(table));
|
|
22259
22538
|
const out = this.fkMode === "race-tolerant" ? await getIgnoreFK(statement, values) : await statement.get(values);
|
|
22260
22539
|
if (out == null) {
|
|
22261
22540
|
return void 0;
|
|
@@ -22282,6 +22561,10 @@ var SQLiteIndex = class {
|
|
|
22282
22561
|
});
|
|
22283
22562
|
}
|
|
22284
22563
|
iterate(request, options) {
|
|
22564
|
+
if (this.isClosing()) {
|
|
22565
|
+
return _SQLiteIndex.closedIterator();
|
|
22566
|
+
}
|
|
22567
|
+
this.assertOpen();
|
|
22285
22568
|
let offset = 0;
|
|
22286
22569
|
let once = false;
|
|
22287
22570
|
let requestId = v4_default();
|
|
@@ -22296,43 +22579,60 @@ var SQLiteIndex = class {
|
|
|
22296
22579
|
});
|
|
22297
22580
|
let planningScope;
|
|
22298
22581
|
const fetch2 = async (amount) => {
|
|
22299
|
-
|
|
22300
|
-
|
|
22301
|
-
planningScope = this.planner.scope(normalizedQuery);
|
|
22302
|
-
let { sql, bindable: toBind } = convertSearchRequestToQuery(normalizedQuery, this.tables, this._rootTables, {
|
|
22303
|
-
planner: planningScope,
|
|
22304
|
-
shape: options?.shape,
|
|
22305
|
-
fetchAll: amount === "all"
|
|
22306
|
-
// if we are to fetch all, we dont need stable sorting
|
|
22307
|
-
});
|
|
22308
|
-
sqlFetch = sql;
|
|
22309
|
-
bindable = toBind;
|
|
22310
|
-
await planningScope.beforePrepare();
|
|
22311
|
-
stmt = await this.properties.db.prepare(sqlFetch, sqlFetch);
|
|
22312
|
-
iterator.expire = Date.now() + this.iteratorTimeout;
|
|
22313
|
-
}
|
|
22314
|
-
once = true;
|
|
22315
|
-
const allResults = await planningScope.perform(async () => {
|
|
22316
|
-
const allResults2 = await stmt.all([
|
|
22317
|
-
...bindable,
|
|
22318
|
-
...amount !== "all" ? [amount, offset] : []
|
|
22319
|
-
]);
|
|
22320
|
-
return allResults2;
|
|
22321
|
-
});
|
|
22322
|
-
let results = await Promise.all(allResults.map(async (row) => {
|
|
22323
|
-
let selectedTable = this._rootTables.find((table) => row[getTablePrefixedField(table, this.primaryKeyString)] != null);
|
|
22324
|
-
const value = await resolveInstanceFromValue(row, this.tables, selectedTable, this.resolveDependencies.bind(this), true, options?.shape);
|
|
22325
|
-
return {
|
|
22326
|
-
value,
|
|
22327
|
-
id: toId(convertFromSQLType(row[getTablePrefixedField(selectedTable, this.primaryKeyString)], selectedTable.primaryField.from.type))
|
|
22328
|
-
};
|
|
22329
|
-
}));
|
|
22330
|
-
offset += results.length;
|
|
22331
|
-
if (amount === "all" || results.length < amount) {
|
|
22582
|
+
const closeAsDone = () => {
|
|
22583
|
+
once = true;
|
|
22332
22584
|
hasMore = false;
|
|
22333
|
-
|
|
22585
|
+
kept = 0;
|
|
22586
|
+
return [];
|
|
22587
|
+
};
|
|
22588
|
+
if (this.isClosing()) {
|
|
22589
|
+
return closeAsDone();
|
|
22590
|
+
}
|
|
22591
|
+
this.assertOpen();
|
|
22592
|
+
try {
|
|
22593
|
+
kept = void 0;
|
|
22594
|
+
if (!once) {
|
|
22595
|
+
planningScope = this.planner.scope(normalizedQuery);
|
|
22596
|
+
let { sql, bindable: toBind } = convertSearchRequestToQuery(normalizedQuery, this.tables, this._rootTables, {
|
|
22597
|
+
planner: planningScope,
|
|
22598
|
+
shape: options?.shape,
|
|
22599
|
+
fetchAll: amount === "all"
|
|
22600
|
+
// if we are to fetch all, we dont need stable sorting
|
|
22601
|
+
});
|
|
22602
|
+
sqlFetch = sql;
|
|
22603
|
+
bindable = toBind;
|
|
22604
|
+
await planningScope.beforePrepare();
|
|
22605
|
+
stmt = await this.properties.db.prepare(sqlFetch, sqlFetch);
|
|
22606
|
+
iterator.expire = Date.now() + this.iteratorTimeout;
|
|
22607
|
+
}
|
|
22608
|
+
once = true;
|
|
22609
|
+
const allResults = await planningScope.perform(async () => {
|
|
22610
|
+
const allResults2 = await stmt.all([
|
|
22611
|
+
...bindable,
|
|
22612
|
+
...amount !== "all" ? [amount, offset] : []
|
|
22613
|
+
]);
|
|
22614
|
+
return allResults2;
|
|
22615
|
+
});
|
|
22616
|
+
let results = await Promise.all(allResults.map(async (row) => {
|
|
22617
|
+
let selectedTable = this._rootTables.find((table) => row[getTablePrefixedField(table, this.primaryKeyString)] != null);
|
|
22618
|
+
const value = await resolveInstanceFromValue(row, this.tables, selectedTable, this.resolveDependencies.bind(this), true, options?.shape);
|
|
22619
|
+
return {
|
|
22620
|
+
value,
|
|
22621
|
+
id: toId(convertFromSQLType(row[getTablePrefixedField(selectedTable, this.primaryKeyString)], selectedTable.primaryField.from.type))
|
|
22622
|
+
};
|
|
22623
|
+
}));
|
|
22624
|
+
offset += results.length;
|
|
22625
|
+
if (amount === "all" || results.length < amount) {
|
|
22626
|
+
hasMore = false;
|
|
22627
|
+
await this.clearupIterator(requestId);
|
|
22628
|
+
}
|
|
22629
|
+
return results;
|
|
22630
|
+
} catch (error2) {
|
|
22631
|
+
if (this.isClosing()) {
|
|
22632
|
+
return closeAsDone();
|
|
22633
|
+
}
|
|
22634
|
+
throw error2;
|
|
22334
22635
|
}
|
|
22335
|
-
return results;
|
|
22336
22636
|
};
|
|
22337
22637
|
const iterator = {
|
|
22338
22638
|
fetch: fetch2,
|
|
@@ -22354,12 +22654,20 @@ var SQLiteIndex = class {
|
|
|
22354
22654
|
return results;
|
|
22355
22655
|
},
|
|
22356
22656
|
close: () => {
|
|
22657
|
+
once = true;
|
|
22357
22658
|
hasMore = false;
|
|
22358
22659
|
kept = 0;
|
|
22359
22660
|
this.clearupIterator(requestId);
|
|
22360
22661
|
},
|
|
22361
22662
|
next: (amount) => fetch2(amount),
|
|
22362
22663
|
pending: async () => {
|
|
22664
|
+
if (this.isClosing()) {
|
|
22665
|
+
once = true;
|
|
22666
|
+
hasMore = false;
|
|
22667
|
+
kept = 0;
|
|
22668
|
+
return 0;
|
|
22669
|
+
}
|
|
22670
|
+
this.assertOpen();
|
|
22363
22671
|
if (!hasMore) {
|
|
22364
22672
|
return 0;
|
|
22365
22673
|
}
|
|
@@ -22371,7 +22679,12 @@ var SQLiteIndex = class {
|
|
|
22371
22679
|
hasMore = kept > 0;
|
|
22372
22680
|
return kept;
|
|
22373
22681
|
},
|
|
22374
|
-
done: () =>
|
|
22682
|
+
done: () => {
|
|
22683
|
+
if (this.isClosing()) {
|
|
22684
|
+
return true;
|
|
22685
|
+
}
|
|
22686
|
+
return once ? !hasMore : void 0;
|
|
22687
|
+
}
|
|
22375
22688
|
};
|
|
22376
22689
|
}
|
|
22377
22690
|
async clearupIterator(id) {
|
|
@@ -22382,21 +22695,29 @@ var SQLiteIndex = class {
|
|
|
22382
22695
|
this._cursor.delete(id);
|
|
22383
22696
|
}
|
|
22384
22697
|
async getSize() {
|
|
22385
|
-
|
|
22386
|
-
|
|
22387
|
-
|
|
22388
|
-
|
|
22698
|
+
return this.ifOpen(0, async () => {
|
|
22699
|
+
if (this.tables.size === 0) {
|
|
22700
|
+
return 0;
|
|
22701
|
+
}
|
|
22702
|
+
return this.count();
|
|
22703
|
+
});
|
|
22389
22704
|
}
|
|
22390
22705
|
async del(query) {
|
|
22391
|
-
return this.
|
|
22706
|
+
return this.withWriteIfOpen([], async () => {
|
|
22392
22707
|
let ret = [];
|
|
22393
22708
|
let once = false;
|
|
22394
22709
|
let lastError = void 0;
|
|
22395
22710
|
for (const table of this._rootTables) {
|
|
22396
22711
|
try {
|
|
22397
|
-
const
|
|
22712
|
+
const planningScope = this.planner.scope(new PlannableQuery({
|
|
22713
|
+
query: coerceLocalQueries(query.query)
|
|
22714
|
+
}));
|
|
22715
|
+
const { sql, bindable } = convertDeleteRequestToQuery(query, this.tables, table, {
|
|
22716
|
+
planner: planningScope
|
|
22717
|
+
});
|
|
22718
|
+
await planningScope.beforePrepare();
|
|
22398
22719
|
const stmt = await this.properties.db.prepare(sql, sql);
|
|
22399
|
-
const results = await stmt.all(bindable);
|
|
22720
|
+
const results = await planningScope.perform(async () => stmt.all(bindable));
|
|
22400
22721
|
for (const result of results) {
|
|
22401
22722
|
ret.push(toId(convertFromSQLType(result[table.primary], table.primaryField.from.type)));
|
|
22402
22723
|
}
|
|
@@ -22416,69 +22737,79 @@ var SQLiteIndex = class {
|
|
|
22416
22737
|
});
|
|
22417
22738
|
}
|
|
22418
22739
|
async sum(query) {
|
|
22419
|
-
|
|
22420
|
-
|
|
22421
|
-
|
|
22422
|
-
|
|
22423
|
-
|
|
22424
|
-
|
|
22425
|
-
|
|
22426
|
-
|
|
22427
|
-
|
|
22428
|
-
|
|
22429
|
-
const { sql, bindable } = convertSumRequestToQuery(query, this.tables, table);
|
|
22430
|
-
const stmt = await this.properties.db.prepare(sql, sql);
|
|
22431
|
-
const result = await stmt.get(bindable);
|
|
22432
|
-
if (result != null) {
|
|
22433
|
-
const value = result.sum;
|
|
22434
|
-
if (ret == null) {
|
|
22435
|
-
ret = value;
|
|
22436
|
-
} else {
|
|
22437
|
-
ret += value;
|
|
22740
|
+
return this.ifOpen(0, async () => {
|
|
22741
|
+
let ret = void 0;
|
|
22742
|
+
let once = false;
|
|
22743
|
+
let lastError = void 0;
|
|
22744
|
+
let inlinedName = getInlineTableFieldName(query.key);
|
|
22745
|
+
for (const table of this._rootTables) {
|
|
22746
|
+
try {
|
|
22747
|
+
if (table.fields.find((x) => x.name === inlinedName) == null) {
|
|
22748
|
+
lastError = new MissingFieldError("Missing field: " + (Array.isArray(query.key) ? query.key : [query.key]).join("."));
|
|
22749
|
+
continue;
|
|
22438
22750
|
}
|
|
22439
|
-
|
|
22440
|
-
|
|
22441
|
-
|
|
22442
|
-
|
|
22443
|
-
|
|
22444
|
-
|
|
22751
|
+
const planningScope = this.planner.scope(new PlannableQuery({
|
|
22752
|
+
query: coerceLocalQueries(query.query)
|
|
22753
|
+
}));
|
|
22754
|
+
const { sql, bindable } = convertSumRequestToQuery(query, this.tables, table, {
|
|
22755
|
+
planner: planningScope
|
|
22756
|
+
});
|
|
22757
|
+
await planningScope.beforePrepare();
|
|
22758
|
+
const stmt = await this.properties.db.prepare(sql, sql);
|
|
22759
|
+
const result = await planningScope.perform(async () => stmt.get(bindable));
|
|
22760
|
+
if (result != null) {
|
|
22761
|
+
const value = result.sum;
|
|
22762
|
+
if (ret == null) {
|
|
22763
|
+
ret = value;
|
|
22764
|
+
} else {
|
|
22765
|
+
ret += value;
|
|
22766
|
+
}
|
|
22767
|
+
once = true;
|
|
22768
|
+
}
|
|
22769
|
+
} catch (error2) {
|
|
22770
|
+
if (error2 instanceof MissingFieldError) {
|
|
22771
|
+
lastError = error2;
|
|
22772
|
+
continue;
|
|
22773
|
+
}
|
|
22774
|
+
throw error2;
|
|
22445
22775
|
}
|
|
22446
|
-
throw error2;
|
|
22447
22776
|
}
|
|
22448
|
-
|
|
22449
|
-
|
|
22450
|
-
|
|
22451
|
-
|
|
22452
|
-
|
|
22777
|
+
if (!once) {
|
|
22778
|
+
throw lastError;
|
|
22779
|
+
}
|
|
22780
|
+
return ret != null ? ret : 0;
|
|
22781
|
+
});
|
|
22453
22782
|
}
|
|
22454
22783
|
async count(request) {
|
|
22455
|
-
|
|
22456
|
-
|
|
22457
|
-
|
|
22458
|
-
|
|
22459
|
-
|
|
22460
|
-
|
|
22461
|
-
|
|
22462
|
-
|
|
22463
|
-
|
|
22464
|
-
|
|
22465
|
-
|
|
22466
|
-
|
|
22467
|
-
|
|
22468
|
-
|
|
22469
|
-
|
|
22470
|
-
|
|
22784
|
+
return this.ifOpen(0, async () => {
|
|
22785
|
+
let ret = 0;
|
|
22786
|
+
let once = false;
|
|
22787
|
+
let lastError = void 0;
|
|
22788
|
+
for (const table of this._rootTables) {
|
|
22789
|
+
try {
|
|
22790
|
+
const { sql, bindable } = convertCountRequestToQuery(request, this.tables, table);
|
|
22791
|
+
const stmt = await this.properties.db.prepare(sql, sql);
|
|
22792
|
+
const result = await stmt.get(bindable);
|
|
22793
|
+
if (result != null) {
|
|
22794
|
+
ret += Number(result.count);
|
|
22795
|
+
once = true;
|
|
22796
|
+
}
|
|
22797
|
+
} catch (error2) {
|
|
22798
|
+
if (error2 instanceof MissingFieldError) {
|
|
22799
|
+
lastError = error2;
|
|
22800
|
+
continue;
|
|
22801
|
+
}
|
|
22802
|
+
throw error2;
|
|
22471
22803
|
}
|
|
22472
|
-
throw error2;
|
|
22473
22804
|
}
|
|
22474
|
-
|
|
22475
|
-
|
|
22476
|
-
|
|
22477
|
-
|
|
22478
|
-
|
|
22805
|
+
if (!once) {
|
|
22806
|
+
throw lastError;
|
|
22807
|
+
}
|
|
22808
|
+
return ret;
|
|
22809
|
+
});
|
|
22479
22810
|
}
|
|
22480
22811
|
get cursorCount() {
|
|
22481
|
-
return this.
|
|
22812
|
+
return this.closed ? 0 : this._cursor.size;
|
|
22482
22813
|
}
|
|
22483
22814
|
};
|
|
22484
22815
|
var SQLiteIndices = class _SQLiteIndices {
|
|
@@ -22537,7 +22868,10 @@ var SQLiteIndices = class _SQLiteIndices {
|
|
|
22537
22868
|
async start() {
|
|
22538
22869
|
this.closed = false;
|
|
22539
22870
|
if (!this.properties.parent) {
|
|
22540
|
-
await this.properties.db.
|
|
22871
|
+
const status = await this.properties.db.status();
|
|
22872
|
+
if (status !== "open") {
|
|
22873
|
+
await this.properties.db.open();
|
|
22874
|
+
}
|
|
22541
22875
|
}
|
|
22542
22876
|
for (const scope of this.scopes.values()) {
|
|
22543
22877
|
await scope.start();
|
|
@@ -22828,7 +23162,6 @@ var create = async (directory, options) => {
|
|
|
22828
23162
|
directory: poolDirectory
|
|
22829
23163
|
});
|
|
22830
23164
|
poolUtil = activePoolUtil;
|
|
22831
|
-
await activePoolUtil.reserveMinimumCapacity(100);
|
|
22832
23165
|
sqliteDb = new activePoolUtil.OpfsSAHPoolDb(dbFileName);
|
|
22833
23166
|
} else {
|
|
22834
23167
|
sqliteDb = new sqlite32.oo1.DB(":memory:");
|
|
@@ -23085,6 +23418,27 @@ var ProxyDatabase = class {
|
|
|
23085
23418
|
}
|
|
23086
23419
|
return statement;
|
|
23087
23420
|
}
|
|
23421
|
+
async prepareMany(statements) {
|
|
23422
|
+
if (statements.length === 0) {
|
|
23423
|
+
return [];
|
|
23424
|
+
}
|
|
23425
|
+
const missing = statements.filter((statement) => !this.statements.get(statement.id));
|
|
23426
|
+
if (missing.length > 0) {
|
|
23427
|
+
const statementIds = await this.send({
|
|
23428
|
+
type: "prepare-many",
|
|
23429
|
+
statements: missing,
|
|
23430
|
+
id: v4_default(),
|
|
23431
|
+
databaseId: this.databaseId
|
|
23432
|
+
});
|
|
23433
|
+
for (const [index, statementId] of statementIds.entries()) {
|
|
23434
|
+
const definition = missing[index];
|
|
23435
|
+
const statement = new ProxyStatement(this.send.bind(this), this.databaseId, statementId, definition.sql, this.options);
|
|
23436
|
+
this.statements.set(statementId, statement);
|
|
23437
|
+
this.statements.set(definition.id, statement);
|
|
23438
|
+
}
|
|
23439
|
+
}
|
|
23440
|
+
return statements.map((statement) => this.statements.get(statement.id));
|
|
23441
|
+
}
|
|
23088
23442
|
async open() {
|
|
23089
23443
|
return this.send({ type: "open", id: v4_default(), databaseId: this.databaseId });
|
|
23090
23444
|
}
|