@peerbit/indexer-sqlite3 2.0.1 → 2.0.2

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 CHANGED
@@ -20357,7 +20357,7 @@ var toSQLType = (type, isOptional = false) => {
20357
20357
  };
20358
20358
  var getSQLTable = (ctor, path, primary, inline, addJoinField, fromOptionalField = false) => {
20359
20359
  let clazzes = getDependencies(ctor, 0);
20360
- if (!clazzes) {
20360
+ if (!clazzes || clazzes.length === 0) {
20361
20361
  clazzes = [ctor];
20362
20362
  }
20363
20363
  let ret = [];
@@ -20692,21 +20692,28 @@ var getTableFromValue = (parentTable, tables, field2, value) => {
20692
20692
  if (!isNestedType(field2.type)) {
20693
20693
  clazzName = WRAPPED_SIMPLE_VALUE_VARIANT;
20694
20694
  } else {
20695
- const testCtors = value?.constructor ? [value?.constructor] : [
20696
- unwrapNestedType(field2.type),
20697
- ...getDependencies(unwrapNestedType(field2.type), 0) || []
20698
- ];
20699
- for (const ctor of testCtors) {
20700
- if (!ctor) {
20701
- continue;
20702
- }
20703
- const schema = getSchema(ctor);
20704
- if (!schema) {
20705
- continue;
20706
- }
20707
- if (ctor) {
20708
- clazzName = ctor;
20709
- break;
20695
+ const nestedType = unwrapNestedType(field2.type);
20696
+ const dependencies = getDependencies(nestedType, 0) || [];
20697
+ const candidatesFromSchema = [nestedType, ...dependencies].filter((x) => typeof x === "function");
20698
+ const runtimeCtor = value?.constructor;
20699
+ const runtimeSchema = runtimeCtor ? getSchema(runtimeCtor) : void 0;
20700
+ if (runtimeCtor && runtimeSchema?.variant !== void 0) {
20701
+ clazzName = runtimeCtor;
20702
+ } else {
20703
+ const tableCtors = candidatesFromSchema.filter((ctor) => {
20704
+ const schema = getSchema(ctor);
20705
+ return schema?.variant !== void 0;
20706
+ });
20707
+ if (tableCtors.length === 1) {
20708
+ clazzName = tableCtors[0];
20709
+ } else if (tableCtors.length > 1) {
20710
+ const declaredName = nestedType.name || "<anonymous>";
20711
+ const variants = tableCtors.map((ctor) => {
20712
+ const schema = getSchema(ctor);
20713
+ return `${ctor.name || "<anonymous>"}(${JSON.stringify(schema?.variant)})`;
20714
+ }).join(", ");
20715
+ const runtimeName = runtimeCtor?.name || (value == null ? "null" : typeof value);
20716
+ throw new Error(`Ambiguous polymorphic nested value for field "${field2.key}". Declared type ${declaredName} has multiple variants: ${variants}. Received ${runtimeName}. Pass an instance of the desired variant.`);
20710
20717
  }
20711
20718
  }
20712
20719
  }