@peerbit/indexer-sqlite3 2.0.2 → 2.1.0-874976b
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 +2 -2
- package/dist/index.min.js +78 -31
- package/dist/index.min.js.map +4 -4
- package/dist/src/schema.d.ts.map +1 -1
- package/dist/src/schema.js +80 -29
- package/dist/src/schema.js.map +1 -1
- package/package.json +8 -8
- package/src/schema.ts +108 -34
|
@@ -17094,7 +17094,7 @@ var init_sqlite_wasm = __esm({
|
|
|
17094
17094
|
}
|
|
17095
17095
|
});
|
|
17096
17096
|
|
|
17097
|
-
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.
|
|
17097
|
+
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.1/node_modules/@dao-xyz/borsh/lib/esm/binary.js
|
|
17098
17098
|
var import_float = __toESM(require_float(), 1);
|
|
17099
17099
|
var import_utf8 = __toESM(require_utf8(), 1);
|
|
17100
17100
|
var allocUnsafeFn = () => {
|
|
@@ -17116,7 +17116,7 @@ var writeStringBufferFnFn = () => {
|
|
|
17116
17116
|
};
|
|
17117
17117
|
var writeStringBufferFn = writeStringBufferFnFn();
|
|
17118
17118
|
|
|
17119
|
-
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.
|
|
17119
|
+
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.1/node_modules/@dao-xyz/borsh/lib/esm/index.js
|
|
17120
17120
|
var _a;
|
|
17121
17121
|
var symbolMetadataSymbol = Symbol.metadata ?? Symbol.for("Symbol.metadata");
|
|
17122
17122
|
var STAGE3_FINALIZERS_SYMBOL = Symbol.for("@dao-xyz/stage3-finalizers");
|
package/dist/index.min.js
CHANGED
|
@@ -17094,11 +17094,11 @@ var init_sqlite_wasm = __esm({
|
|
|
17094
17094
|
}
|
|
17095
17095
|
});
|
|
17096
17096
|
|
|
17097
|
-
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.
|
|
17097
|
+
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.1/node_modules/@dao-xyz/borsh/lib/esm/binary.js
|
|
17098
17098
|
var import_float = __toESM(require_float(), 1);
|
|
17099
17099
|
var import_utf8 = __toESM(require_utf8(), 1);
|
|
17100
17100
|
|
|
17101
|
-
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.
|
|
17101
|
+
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.1/node_modules/@dao-xyz/borsh/lib/esm/bigint.js
|
|
17102
17102
|
function arrayToHex(arr, reverse = false) {
|
|
17103
17103
|
return [...reverse ? new Uint8Array(arr).reverse() : new Uint8Array(arr)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
17104
17104
|
}
|
|
@@ -17211,7 +17211,7 @@ var checkInt = (value, min, max, byteLength) => {
|
|
|
17211
17211
|
}
|
|
17212
17212
|
};
|
|
17213
17213
|
|
|
17214
|
-
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.
|
|
17214
|
+
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.1/node_modules/@dao-xyz/borsh/lib/esm/error.js
|
|
17215
17215
|
var BorshError = class extends Error {
|
|
17216
17216
|
constructor(message) {
|
|
17217
17217
|
super(message);
|
|
@@ -17224,7 +17224,7 @@ var BorshError = class extends Error {
|
|
|
17224
17224
|
}
|
|
17225
17225
|
};
|
|
17226
17226
|
|
|
17227
|
-
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.
|
|
17227
|
+
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.1/node_modules/@dao-xyz/borsh/lib/esm/binary.js
|
|
17228
17228
|
var allocUnsafeFn = () => {
|
|
17229
17229
|
if (globalThis.Buffer) {
|
|
17230
17230
|
return globalThis.Buffer.allocUnsafe;
|
|
@@ -17646,14 +17646,14 @@ var BinaryReader = class _BinaryReader {
|
|
|
17646
17646
|
}
|
|
17647
17647
|
};
|
|
17648
17648
|
|
|
17649
|
-
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.
|
|
17649
|
+
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.1/node_modules/@dao-xyz/borsh/lib/esm/types.js
|
|
17650
17650
|
var extendingClasses = (clazz) => {
|
|
17651
17651
|
let ret = [];
|
|
17652
17652
|
if (clazz instanceof Function) {
|
|
17653
17653
|
let baseClass = clazz;
|
|
17654
17654
|
while (baseClass) {
|
|
17655
17655
|
const newBaseClass = Object.getPrototypeOf(baseClass);
|
|
17656
|
-
if (newBaseClass && newBaseClass !== Object && newBaseClass.
|
|
17656
|
+
if (newBaseClass && newBaseClass !== Object && newBaseClass !== Function.prototype) {
|
|
17657
17657
|
ret.push(newBaseClass);
|
|
17658
17658
|
baseClass = newBaseClass;
|
|
17659
17659
|
} else {
|
|
@@ -17727,7 +17727,7 @@ var StructKind = class {
|
|
|
17727
17727
|
}
|
|
17728
17728
|
};
|
|
17729
17729
|
|
|
17730
|
-
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.
|
|
17730
|
+
// ../../../../node_modules/.pnpm/@dao-xyz+borsh@6.0.1/node_modules/@dao-xyz/borsh/lib/esm/index.js
|
|
17731
17731
|
var _a;
|
|
17732
17732
|
var symbolMetadataSymbol = Symbol.metadata ?? Symbol.for("Symbol.metadata");
|
|
17733
17733
|
var STAGE3_FINALIZERS_SYMBOL = Symbol.for("@dao-xyz/stage3-finalizers");
|
|
@@ -20355,6 +20355,54 @@ var toSQLType = (type, isOptional = false) => {
|
|
|
20355
20355
|
}
|
|
20356
20356
|
return isOptional ? ret : ret + " NOT NULL";
|
|
20357
20357
|
};
|
|
20358
|
+
var createScalarSQLField = (path, field2, type, primary, isOptional) => {
|
|
20359
|
+
const name = getInlineTableFieldName(path.slice(1), field2.key);
|
|
20360
|
+
const isPrimary = primary !== false && name === primary;
|
|
20361
|
+
const sqlType = toSQLType(type, isOptional);
|
|
20362
|
+
return {
|
|
20363
|
+
name,
|
|
20364
|
+
key: field2.key,
|
|
20365
|
+
definition: `${escapeColumnName(name)} ${sqlType} ${isPrimary ? "PRIMARY KEY" : ""}`,
|
|
20366
|
+
type: sqlType,
|
|
20367
|
+
isPrimary,
|
|
20368
|
+
from: field2,
|
|
20369
|
+
unwrappedType: unwrapNestedType(field2.type),
|
|
20370
|
+
path: [...path.slice(1), field2.key]
|
|
20371
|
+
};
|
|
20372
|
+
};
|
|
20373
|
+
var resolvePrimaryFieldInfoFromSchema = (ctor, path, primary) => {
|
|
20374
|
+
const schema = getSchema(ctor);
|
|
20375
|
+
if (!schema) {
|
|
20376
|
+
return void 0;
|
|
20377
|
+
}
|
|
20378
|
+
for (const field2 of schema.fields) {
|
|
20379
|
+
let fieldType = field2.type;
|
|
20380
|
+
if (fieldType instanceof OptionKind) {
|
|
20381
|
+
fieldType = fieldType.elementType;
|
|
20382
|
+
}
|
|
20383
|
+
fieldType = unwrapNestedType(fieldType);
|
|
20384
|
+
if (fieldType instanceof VecKind) {
|
|
20385
|
+
continue;
|
|
20386
|
+
}
|
|
20387
|
+
if (typeof fieldType === "string" || isUint8ArrayType(fieldType)) {
|
|
20388
|
+
const sqlField = createScalarSQLField(path, field2, fieldType, primary, true);
|
|
20389
|
+
if (sqlField.isPrimary) {
|
|
20390
|
+
return {
|
|
20391
|
+
name: sqlField.name,
|
|
20392
|
+
type: sqlField.type,
|
|
20393
|
+
from: sqlField.from,
|
|
20394
|
+
unwrappedType: sqlField.unwrappedType
|
|
20395
|
+
};
|
|
20396
|
+
}
|
|
20397
|
+
} else if (typeof fieldType === "function" && clazzCanBeInlined(fieldType)) {
|
|
20398
|
+
const nested = resolvePrimaryFieldInfoFromSchema(fieldType, [...path, field2.key], primary);
|
|
20399
|
+
if (nested) {
|
|
20400
|
+
return nested;
|
|
20401
|
+
}
|
|
20402
|
+
}
|
|
20403
|
+
}
|
|
20404
|
+
return void 0;
|
|
20405
|
+
};
|
|
20358
20406
|
var getSQLTable = (ctor, path, primary, inline, addJoinField, fromOptionalField = false) => {
|
|
20359
20407
|
let clazzes = getDependencies(ctor, 0);
|
|
20360
20408
|
if (!clazzes || clazzes.length === 0) {
|
|
@@ -20438,10 +20486,20 @@ var getSQLFields = (tableName, path, ctor, primary, addJoinFieldFromParent, tabl
|
|
|
20438
20486
|
const sqlFields = [];
|
|
20439
20487
|
const sqlConstraints = [];
|
|
20440
20488
|
let foundPrimary = false;
|
|
20489
|
+
const parentPrimaryFieldInfo = primary === false || primary === CHILD_TABLE_ID ? {
|
|
20490
|
+
name: CHILD_TABLE_ID,
|
|
20491
|
+
type: "INTEGER",
|
|
20492
|
+
from: void 0,
|
|
20493
|
+
unwrappedType: void 0
|
|
20494
|
+
} : resolvePrimaryFieldInfoFromSchema(ctor, path, primary) || {
|
|
20495
|
+
// Fallback: nested tables use synthetic integer ids, and we allow that
|
|
20496
|
+
// primary to be unresolved here.
|
|
20497
|
+
name: primary,
|
|
20498
|
+
type: "INTEGER",
|
|
20499
|
+
from: void 0,
|
|
20500
|
+
unwrappedType: void 0
|
|
20501
|
+
};
|
|
20441
20502
|
const addJoinFields = primary === false ? addJoinFieldFromParent : (fields2, contstraints) => {
|
|
20442
|
-
const parentPrimaryField = primary != null ? sqlFields.find((field2) => field2.name === primary) : void 0;
|
|
20443
|
-
const parentPrimaryFieldName = parentPrimaryField?.name || CHILD_TABLE_ID;
|
|
20444
|
-
const parentPrimaryFieldType = parentPrimaryField ? parentPrimaryField.type : "INTEGER";
|
|
20445
20503
|
fields2.unshift(
|
|
20446
20504
|
{
|
|
20447
20505
|
name: CHILD_TABLE_ID,
|
|
@@ -20457,17 +20515,17 @@ var getSQLFields = (tableName, path, ctor, primary, addJoinFieldFromParent, tabl
|
|
|
20457
20515
|
{
|
|
20458
20516
|
name: PARENT_TABLE_ID,
|
|
20459
20517
|
key: PARENT_TABLE_ID,
|
|
20460
|
-
definition: `${PARENT_TABLE_ID} ${
|
|
20461
|
-
type:
|
|
20462
|
-
from:
|
|
20463
|
-
unwrappedType:
|
|
20518
|
+
definition: `${PARENT_TABLE_ID} ${parentPrimaryFieldInfo.type}`,
|
|
20519
|
+
type: parentPrimaryFieldInfo.type,
|
|
20520
|
+
from: parentPrimaryFieldInfo.from,
|
|
20521
|
+
unwrappedType: parentPrimaryFieldInfo.unwrappedType,
|
|
20464
20522
|
isPrimary: false,
|
|
20465
20523
|
path: [PARENT_TABLE_ID]
|
|
20466
20524
|
}
|
|
20467
20525
|
);
|
|
20468
20526
|
contstraints.push({
|
|
20469
20527
|
name: `${PARENT_TABLE_ID}_fk`,
|
|
20470
|
-
definition: `CONSTRAINT ${PARENT_TABLE_ID}_fk FOREIGN KEY(${PARENT_TABLE_ID}) REFERENCES ${tableName}(${
|
|
20528
|
+
definition: `CONSTRAINT ${PARENT_TABLE_ID}_fk FOREIGN KEY(${PARENT_TABLE_ID}) REFERENCES ${tableName}(${parentPrimaryFieldInfo.name}) ON DELETE CASCADE`
|
|
20471
20529
|
});
|
|
20472
20530
|
};
|
|
20473
20531
|
const handleNestedType = (key, field2) => {
|
|
@@ -20546,28 +20604,17 @@ var getSQLFields = (tableName, path, ctor, primary, addJoinFieldFromParent, tabl
|
|
|
20546
20604
|
}
|
|
20547
20605
|
}
|
|
20548
20606
|
};
|
|
20549
|
-
const handleSimpleField = (
|
|
20550
|
-
|
|
20551
|
-
|
|
20552
|
-
|
|
20553
|
-
const fieldType = toSQLType(type, isOptional2);
|
|
20554
|
-
sqlFields.push({
|
|
20555
|
-
name: keyString,
|
|
20556
|
-
key,
|
|
20557
|
-
definition: `${escapeColumnName(keyString)} ${fieldType} ${isPrimary ? "PRIMARY KEY" : ""}`,
|
|
20558
|
-
type: fieldType,
|
|
20559
|
-
isPrimary,
|
|
20560
|
-
from: field2,
|
|
20561
|
-
unwrappedType: unwrapNestedType(field2.type),
|
|
20562
|
-
path: [...path.slice(1), key]
|
|
20563
|
-
});
|
|
20607
|
+
const handleSimpleField = (field2, type, isOptional2) => {
|
|
20608
|
+
const sqlField = createScalarSQLField(path, field2, type, primary, isOptional2);
|
|
20609
|
+
foundPrimary = foundPrimary || sqlField.isPrimary;
|
|
20610
|
+
sqlFields.push(sqlField);
|
|
20564
20611
|
};
|
|
20565
20612
|
const handleField = (key, field2, type, isOptional2) => {
|
|
20566
20613
|
if (type instanceof FixedArrayKind && type.elementType === "u8") {
|
|
20567
20614
|
type = Uint8Array;
|
|
20568
20615
|
}
|
|
20569
20616
|
if (typeof type === "string" || type === Uint8Array) {
|
|
20570
|
-
handleSimpleField(
|
|
20617
|
+
handleSimpleField(field2, type, true);
|
|
20571
20618
|
} else if (typeof type === "function" && clazzCanBeInlined(type)) {
|
|
20572
20619
|
const subPath = [...path, key];
|
|
20573
20620
|
const subtables = getSQLTable(type, subPath, false, true, addJoinFields, isOptional2);
|