@peerbit/indexer-sqlite3 2.1.1 → 2.1.2-000e3f1
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/index.min.js +85 -49
- package/dist/index.min.js.map +2 -2
- package/dist/src/engine.d.ts +2 -0
- package/dist/src/engine.d.ts.map +1 -1
- package/dist/src/engine.js +81 -50
- package/dist/src/engine.js.map +1 -1
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/schema.js +9 -1
- package/dist/src/schema.js.map +1 -1
- package/package.json +8 -8
- package/src/engine.ts +113 -77
- package/src/schema.ts +22 -3
package/dist/index.min.js
CHANGED
|
@@ -19003,12 +19003,15 @@ function hashBlocks(w, v2, p, pos, len) {
|
|
|
19003
19003
|
// ../../crypto/dist/src/utils.js
|
|
19004
19004
|
var import_libsodium_wrappers = __toESM(require_libsodium_wrappers(), 1);
|
|
19005
19005
|
var fromHexString = (hexString) => import_libsodium_wrappers.default.from_hex(hexString);
|
|
19006
|
-
var
|
|
19006
|
+
var asU8 = (bytes) => {
|
|
19007
|
+
return bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
19008
|
+
};
|
|
19009
|
+
var toHexString = (bytes) => import_libsodium_wrappers.default.to_hex(asU8(bytes));
|
|
19007
19010
|
var toBase64 = (arr) => {
|
|
19008
|
-
return import_libsodium_wrappers.default.to_base64(arr, import_libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
19011
|
+
return import_libsodium_wrappers.default.to_base64(asU8(arr), import_libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
19009
19012
|
};
|
|
19010
19013
|
var toBase58 = (arr) => {
|
|
19011
|
-
return base58btc.baseEncode(arr);
|
|
19014
|
+
return base58btc.baseEncode(asU8(arr));
|
|
19012
19015
|
};
|
|
19013
19016
|
|
|
19014
19017
|
// ../../crypto/dist/src/hash.browser.js
|
|
@@ -19503,10 +19506,11 @@ var toId = (obj) => {
|
|
|
19503
19506
|
}
|
|
19504
19507
|
throw new Error("BigInt is not less than 2^64 - 1. Max value is " + (2 ** 64 - 1) + ". Provided value: " + obj);
|
|
19505
19508
|
}
|
|
19506
|
-
if (obj instanceof Uint8Array) {
|
|
19507
|
-
|
|
19509
|
+
if (obj instanceof Uint8Array || ArrayBuffer.isView(obj)) {
|
|
19510
|
+
const bytes = obj instanceof Uint8Array ? obj : new Uint8Array(obj.buffer, obj.byteOffset, obj.byteLength);
|
|
19511
|
+
return new Uint8ArrayKey(bytes);
|
|
19508
19512
|
}
|
|
19509
|
-
throw new Error("Unexpected index key: " + typeof obj + ", expected: string, number, bigint or
|
|
19513
|
+
throw new Error("Unexpected index key: " + typeof obj + ", expected: string, number, bigint, Uint8Array or ArrayBufferView");
|
|
19510
19514
|
};
|
|
19511
19515
|
|
|
19512
19516
|
// ../../../../node_modules/.pnpm/uuid@10.0.0/node_modules/uuid/dist/esm-browser/stringify.js
|
|
@@ -20380,7 +20384,11 @@ var resolvePrimaryFieldInfoFromSchema = (ctor, path, primary) => {
|
|
|
20380
20384
|
if (fieldType instanceof OptionKind) {
|
|
20381
20385
|
fieldType = fieldType.elementType;
|
|
20382
20386
|
}
|
|
20383
|
-
fieldType
|
|
20387
|
+
if (fieldType instanceof FixedArrayKind && fieldType.elementType === "u8") {
|
|
20388
|
+
fieldType = Uint8Array;
|
|
20389
|
+
} else {
|
|
20390
|
+
fieldType = unwrapNestedType(fieldType);
|
|
20391
|
+
}
|
|
20384
20392
|
if (fieldType instanceof VecKind) {
|
|
20385
20393
|
continue;
|
|
20386
20394
|
}
|
|
@@ -21934,6 +21942,30 @@ async function getIgnoreFK(stmt, values) {
|
|
|
21934
21942
|
}
|
|
21935
21943
|
var SQLLiteIndex = class {
|
|
21936
21944
|
properties;
|
|
21945
|
+
// SQLite writes are inherently serialized per connection.
|
|
21946
|
+
// We still need an explicit async barrier because our API is async and
|
|
21947
|
+
// awaits between statements (root insert -> many child inserts). Without
|
|
21948
|
+
// a barrier, concurrent `put()` and `del()` can interleave mid-insert and
|
|
21949
|
+
// create large volumes of FK constraint noise (and occasional timeouts in
|
|
21950
|
+
// browser/webworker runners).
|
|
21951
|
+
// TODO(perf): This is intentionally coarse-grained for correctness.
|
|
21952
|
+
// Possible optimizations:
|
|
21953
|
+
// 1) wrap nested writes in explicit transactions to reduce lock time;
|
|
21954
|
+
// 2) use table/key-scoped write queues when overlap detection is available.
|
|
21955
|
+
// Any relaxation must keep concurrent put/del stability across all runners.
|
|
21956
|
+
_writeBarrier = Promise.resolve();
|
|
21957
|
+
async withWriteBarrier(fn) {
|
|
21958
|
+
const prev = this._writeBarrier;
|
|
21959
|
+
let release;
|
|
21960
|
+
const next = new Promise((r) => release = r);
|
|
21961
|
+
this._writeBarrier = prev.then(() => next, () => next);
|
|
21962
|
+
await prev.catch(() => void 0);
|
|
21963
|
+
try {
|
|
21964
|
+
return await fn();
|
|
21965
|
+
} finally {
|
|
21966
|
+
release();
|
|
21967
|
+
}
|
|
21968
|
+
}
|
|
21937
21969
|
primaryKeyArr;
|
|
21938
21970
|
primaryKeyString;
|
|
21939
21971
|
planner;
|
|
@@ -22114,28 +22146,30 @@ var SQLLiteIndex = class {
|
|
|
22114
22146
|
return void 0;
|
|
22115
22147
|
}
|
|
22116
22148
|
async put(value, _id) {
|
|
22117
|
-
|
|
22118
|
-
|
|
22119
|
-
|
|
22120
|
-
|
|
22121
|
-
|
|
22122
|
-
|
|
22123
|
-
|
|
22124
|
-
|
|
22125
|
-
|
|
22126
|
-
|
|
22127
|
-
|
|
22128
|
-
|
|
22129
|
-
|
|
22130
|
-
|
|
22149
|
+
return this.withWriteBarrier(async () => {
|
|
22150
|
+
const classOfValue = value.constructor;
|
|
22151
|
+
return insert(async (values, table) => {
|
|
22152
|
+
let preId = values[table.primaryIndex];
|
|
22153
|
+
let statement = void 0;
|
|
22154
|
+
try {
|
|
22155
|
+
if (preId != null) {
|
|
22156
|
+
statement = this.properties.db.statements.get(replaceStatementKey(table));
|
|
22157
|
+
this.fkMode === "race-tolerant" ? await runIgnoreFK(statement, values) : await statement.run(values);
|
|
22158
|
+
return preId;
|
|
22159
|
+
} else {
|
|
22160
|
+
statement = this.properties.db.statements.get(putStatementKey(table));
|
|
22161
|
+
const out = this.fkMode === "race-tolerant" ? await getIgnoreFK(statement, values) : await statement.get(values);
|
|
22162
|
+
if (out == null) {
|
|
22163
|
+
return void 0;
|
|
22164
|
+
}
|
|
22165
|
+
return out[table.primary];
|
|
22131
22166
|
}
|
|
22132
|
-
|
|
22167
|
+
} finally {
|
|
22168
|
+
await statement?.reset?.();
|
|
22133
22169
|
}
|
|
22134
|
-
}
|
|
22135
|
-
|
|
22136
|
-
}
|
|
22137
|
-
}, value, this.tables, resolveTable(this.scopeString ? [this.scopeString] : [], this.tables, classOfValue, true), getSchema(classOfValue).fields, (_fn) => {
|
|
22138
|
-
throw new Error("Unexpected");
|
|
22170
|
+
}, value, this.tables, resolveTable(this.scopeString ? [this.scopeString] : [], this.tables, classOfValue, true), getSchema(classOfValue).fields, (_fn) => {
|
|
22171
|
+
throw new Error("Unexpected");
|
|
22172
|
+
});
|
|
22139
22173
|
});
|
|
22140
22174
|
}
|
|
22141
22175
|
iterate(request, options) {
|
|
@@ -22245,30 +22279,32 @@ var SQLLiteIndex = class {
|
|
|
22245
22279
|
return this.count();
|
|
22246
22280
|
}
|
|
22247
22281
|
async del(query) {
|
|
22248
|
-
|
|
22249
|
-
|
|
22250
|
-
|
|
22251
|
-
|
|
22252
|
-
|
|
22253
|
-
|
|
22254
|
-
|
|
22255
|
-
|
|
22256
|
-
|
|
22257
|
-
|
|
22258
|
-
|
|
22259
|
-
|
|
22260
|
-
|
|
22261
|
-
|
|
22262
|
-
|
|
22263
|
-
|
|
22282
|
+
return this.withWriteBarrier(async () => {
|
|
22283
|
+
let ret = [];
|
|
22284
|
+
let once = false;
|
|
22285
|
+
let lastError = void 0;
|
|
22286
|
+
for (const table of this._rootTables) {
|
|
22287
|
+
try {
|
|
22288
|
+
const { sql, bindable } = convertDeleteRequestToQuery(query, this.tables, table);
|
|
22289
|
+
const stmt = await this.properties.db.prepare(sql, sql);
|
|
22290
|
+
const results = await stmt.all(bindable);
|
|
22291
|
+
for (const result of results) {
|
|
22292
|
+
ret.push(toId(convertFromSQLType(result[table.primary], table.primaryField.from.type)));
|
|
22293
|
+
}
|
|
22294
|
+
once = true;
|
|
22295
|
+
} catch (error2) {
|
|
22296
|
+
if (error2 instanceof MissingFieldError) {
|
|
22297
|
+
lastError = error2;
|
|
22298
|
+
continue;
|
|
22299
|
+
}
|
|
22300
|
+
throw error2;
|
|
22264
22301
|
}
|
|
22265
|
-
throw error2;
|
|
22266
22302
|
}
|
|
22267
|
-
|
|
22268
|
-
|
|
22269
|
-
|
|
22270
|
-
|
|
22271
|
-
|
|
22303
|
+
if (!once) {
|
|
22304
|
+
throw lastError;
|
|
22305
|
+
}
|
|
22306
|
+
return ret;
|
|
22307
|
+
});
|
|
22272
22308
|
}
|
|
22273
22309
|
async sum(query) {
|
|
22274
22310
|
let ret = void 0;
|