drizzle-kit 1.0.0-beta.1-94774b0 → 1.0.0-beta.1-34ee105
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/api.js +63 -29
 - package/api.mjs +63 -29
 - package/bin.cjs +1 -1
 - package/package.json +1 -1
 
    
        package/api.js
    CHANGED
    
    | 
         @@ -23568,37 +23568,65 @@ function processRelations(tablesConfig, tables) { 
     | 
|
| 
       23568 
23568 
     | 
    
         
             
                  if (!is(relation, Relation)) {
         
     | 
| 
       23569 
23569 
     | 
    
         
             
                    continue;
         
     | 
| 
       23570 
23570 
     | 
    
         
             
                  }
         
     | 
| 
       23571 
     | 
    
         
            -
                   
     | 
| 
       23572 
     | 
    
         
            -
                   
     | 
| 
      
 23571 
     | 
    
         
            +
                  let reverseRelation;
         
     | 
| 
      
 23572 
     | 
    
         
            +
                  const {
         
     | 
| 
      
 23573 
     | 
    
         
            +
                    targetTableName,
         
     | 
| 
      
 23574 
     | 
    
         
            +
                    alias,
         
     | 
| 
      
 23575 
     | 
    
         
            +
                    sourceColumns,
         
     | 
| 
      
 23576 
     | 
    
         
            +
                    targetColumns,
         
     | 
| 
      
 23577 
     | 
    
         
            +
                    throughTable,
         
     | 
| 
      
 23578 
     | 
    
         
            +
                    sourceTable,
         
     | 
| 
      
 23579 
     | 
    
         
            +
                    through,
         
     | 
| 
      
 23580 
     | 
    
         
            +
                    targetTable,
         
     | 
| 
      
 23581 
     | 
    
         
            +
                    where,
         
     | 
| 
      
 23582 
     | 
    
         
            +
                    sourceColumnTableNames,
         
     | 
| 
      
 23583 
     | 
    
         
            +
                    targetColumnTableNames
         
     | 
| 
      
 23584 
     | 
    
         
            +
                  } = relation;
         
     | 
| 
      
 23585 
     | 
    
         
            +
                  const relationPrintName = `relations -> ${tableConfig.name}: { ${relationFieldName}: r.${is(relation, One) ? "one" : "many"}.${targetTableName}(...) }`;
         
     | 
| 
      
 23586 
     | 
    
         
            +
                  if (typeof alias === "string" && !alias) {
         
     | 
| 
       23573 
23587 
     | 
    
         
             
                    throw new Error(`${relationPrintName}: "alias" cannot be an empty string - omit it if you don't need it`);
         
     | 
| 
       23574 
23588 
     | 
    
         
             
                  }
         
     | 
| 
       23575 
     | 
    
         
            -
                  if ( 
     | 
| 
       23576 
     | 
    
         
            -
                    throw new Error(`${relationPrintName}: "from" cannot be  
     | 
| 
      
 23589 
     | 
    
         
            +
                  if (sourceColumns?.length === 0) {
         
     | 
| 
      
 23590 
     | 
    
         
            +
                    throw new Error(`${relationPrintName}: "from" cannot be empty`);
         
     | 
| 
       23577 
23591 
     | 
    
         
             
                  }
         
     | 
| 
       23578 
     | 
    
         
            -
                  if ( 
     | 
| 
       23579 
     | 
    
         
            -
                    throw new Error(`${relationPrintName}: "to" cannot be  
     | 
| 
      
 23592 
     | 
    
         
            +
                  if (targetColumns?.length === 0) {
         
     | 
| 
      
 23593 
     | 
    
         
            +
                    throw new Error(`${relationPrintName}: "to" cannot be empty`);
         
     | 
| 
       23580 
23594 
     | 
    
         
             
                  }
         
     | 
| 
       23581 
     | 
    
         
            -
                  if ( 
     | 
| 
       23582 
     | 
    
         
            -
                    if ( 
     | 
| 
      
 23595 
     | 
    
         
            +
                  if (sourceColumns && targetColumns) {
         
     | 
| 
      
 23596 
     | 
    
         
            +
                    if (sourceColumns.length !== targetColumns.length && !throughTable) {
         
     | 
| 
       23583 
23597 
     | 
    
         
             
                      throw new Error(
         
     | 
| 
       23584 
23598 
     | 
    
         
             
                        `${relationPrintName}: "from" and "to" fields without "through" must have the same length`
         
     | 
| 
       23585 
23599 
     | 
    
         
             
                      );
         
     | 
| 
       23586 
23600 
     | 
    
         
             
                    }
         
     | 
| 
       23587 
     | 
    
         
            -
                     
     | 
| 
       23588 
     | 
    
         
            -
                      if ( 
     | 
| 
      
 23601 
     | 
    
         
            +
                    for (const sName of sourceColumnTableNames) {
         
     | 
| 
      
 23602 
     | 
    
         
            +
                      if (sName !== sourceTableName) {
         
     | 
| 
      
 23603 
     | 
    
         
            +
                        throw new Error(
         
     | 
| 
      
 23604 
     | 
    
         
            +
                          `${relationPrintName}: all "from" columns must belong to table "${sourceTableName}", found column of table "${sName}"`
         
     | 
| 
      
 23605 
     | 
    
         
            +
                        );
         
     | 
| 
      
 23606 
     | 
    
         
            +
                      }
         
     | 
| 
      
 23607 
     | 
    
         
            +
                    }
         
     | 
| 
      
 23608 
     | 
    
         
            +
                    for (const tName of targetColumnTableNames) {
         
     | 
| 
      
 23609 
     | 
    
         
            +
                      if (tName !== targetTableName) {
         
     | 
| 
      
 23610 
     | 
    
         
            +
                        throw new Error(
         
     | 
| 
      
 23611 
     | 
    
         
            +
                          `${relationPrintName}: all "to" columns must belong to table "${targetTable}", found column of table "${tName}"`
         
     | 
| 
      
 23612 
     | 
    
         
            +
                        );
         
     | 
| 
      
 23613 
     | 
    
         
            +
                      }
         
     | 
| 
      
 23614 
     | 
    
         
            +
                    }
         
     | 
| 
      
 23615 
     | 
    
         
            +
                    if (through) {
         
     | 
| 
      
 23616 
     | 
    
         
            +
                      if (through.source.length !== sourceColumns.length || through.target.length !== targetColumns.length) {
         
     | 
| 
       23589 
23617 
     | 
    
         
             
                        throw new Error(
         
     | 
| 
       23590 
23618 
     | 
    
         
             
                          `${relationPrintName}: ".through(column)" must be used either on all columns in "from" and "to" or not defined on any of them`
         
     | 
| 
       23591 
23619 
     | 
    
         
             
                        );
         
     | 
| 
       23592 
23620 
     | 
    
         
             
                      }
         
     | 
| 
       23593 
     | 
    
         
            -
                      for (const column6 of  
     | 
| 
       23594 
     | 
    
         
            -
                        if (tables[column6._.tableName] !==  
     | 
| 
      
 23621 
     | 
    
         
            +
                      for (const column6 of through.source) {
         
     | 
| 
      
 23622 
     | 
    
         
            +
                        if (tables[column6._.tableName] !== throughTable) {
         
     | 
| 
       23595 
23623 
     | 
    
         
             
                          throw new Error(
         
     | 
| 
       23596 
23624 
     | 
    
         
             
                            `${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
         
     | 
| 
       23597 
23625 
     | 
    
         
             
                          );
         
     | 
| 
       23598 
23626 
     | 
    
         
             
                        }
         
     | 
| 
       23599 
23627 
     | 
    
         
             
                      }
         
     | 
| 
       23600 
     | 
    
         
            -
                      for (const column6 of  
     | 
| 
       23601 
     | 
    
         
            -
                        if (tables[column6._.tableName] !==  
     | 
| 
      
 23628 
     | 
    
         
            +
                      for (const column6 of through.target) {
         
     | 
| 
      
 23629 
     | 
    
         
            +
                        if (tables[column6._.tableName] !== throughTable) {
         
     | 
| 
       23602 
23630 
     | 
    
         
             
                          throw new Error(
         
     | 
| 
       23603 
23631 
     | 
    
         
             
                            `${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
         
     | 
| 
       23604 
23632 
     | 
    
         
             
                          );
         
     | 
| 
         @@ -23607,54 +23635,52 @@ function processRelations(tablesConfig, tables) { 
     | 
|
| 
       23607 
23635 
     | 
    
         
             
                    }
         
     | 
| 
       23608 
23636 
     | 
    
         
             
                    continue;
         
     | 
| 
       23609 
23637 
     | 
    
         
             
                  }
         
     | 
| 
       23610 
     | 
    
         
            -
                  if ( 
     | 
| 
      
 23638 
     | 
    
         
            +
                  if (sourceColumns || targetColumns) {
         
     | 
| 
       23611 
23639 
     | 
    
         
             
                    throw new Error(
         
     | 
| 
       23612 
23640 
     | 
    
         
             
                      `${relationPrintName}: relation must have either both "from" and "to" defined, or none of them`
         
     | 
| 
       23613 
23641 
     | 
    
         
             
                    );
         
     | 
| 
       23614 
23642 
     | 
    
         
             
                  }
         
     | 
| 
       23615 
     | 
    
         
            -
                   
     | 
| 
       23616 
     | 
    
         
            -
                  const targetTableTsName = relation.targetTableName;
         
     | 
| 
       23617 
     | 
    
         
            -
                  const reverseTableConfig = tablesConfig[targetTableTsName];
         
     | 
| 
      
 23643 
     | 
    
         
            +
                  const reverseTableConfig = tablesConfig[targetTableName];
         
     | 
| 
       23618 
23644 
     | 
    
         
             
                  if (!reverseTableConfig) {
         
     | 
| 
       23619 
23645 
     | 
    
         
             
                    throw new Error(
         
     | 
| 
       23620 
     | 
    
         
            -
                      `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relations of table "${ 
     | 
| 
      
 23646 
     | 
    
         
            +
                      `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relations of table "${targetTableName}" were found"`
         
     | 
| 
       23621 
23647 
     | 
    
         
             
                    );
         
     | 
| 
       23622 
23648 
     | 
    
         
             
                  }
         
     | 
| 
       23623 
     | 
    
         
            -
                  if ( 
     | 
| 
      
 23649 
     | 
    
         
            +
                  if (alias) {
         
     | 
| 
       23624 
23650 
     | 
    
         
             
                    const reverseRelations = Object.values(reverseTableConfig.relations).filter(
         
     | 
| 
       23625 
     | 
    
         
            -
                      (it) => is(it, Relation) && it.alias ===  
     | 
| 
      
 23651 
     | 
    
         
            +
                      (it) => is(it, Relation) && it.alias === alias && it !== relation
         
     | 
| 
       23626 
23652 
     | 
    
         
             
                    );
         
     | 
| 
       23627 
23653 
     | 
    
         
             
                    if (reverseRelations.length > 1) {
         
     | 
| 
       23628 
23654 
     | 
    
         
             
                      throw new Error(
         
     | 
| 
       23629 
     | 
    
         
            -
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations with alias "${ 
     | 
| 
      
 23655 
     | 
    
         
            +
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations with alias "${alias}" found in table "${targetTableName}": ${reverseRelations.map((it) => `"${it.fieldName}"`).join(", ")}`
         
     | 
| 
       23630 
23656 
     | 
    
         
             
                      );
         
     | 
| 
       23631 
23657 
     | 
    
         
             
                    }
         
     | 
| 
       23632 
23658 
     | 
    
         
             
                    reverseRelation = reverseRelations[0];
         
     | 
| 
       23633 
23659 
     | 
    
         
             
                    if (!reverseRelation) {
         
     | 
| 
       23634 
23660 
     | 
    
         
             
                      throw new Error(
         
     | 
| 
       23635 
     | 
    
         
            -
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and there is no reverse relation of table "${ 
     | 
| 
      
 23661 
     | 
    
         
            +
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and there is no reverse relation of table "${targetTableName}" with alias "${alias}"`
         
     | 
| 
       23636 
23662 
     | 
    
         
             
                      );
         
     | 
| 
       23637 
23663 
     | 
    
         
             
                    }
         
     | 
| 
       23638 
23664 
     | 
    
         
             
                  } else {
         
     | 
| 
       23639 
23665 
     | 
    
         
             
                    const reverseRelations = Object.values(reverseTableConfig.relations).filter(
         
     | 
| 
       23640 
     | 
    
         
            -
                      (it) => is(it, Relation) && it.targetTable ===  
     | 
| 
      
 23666 
     | 
    
         
            +
                      (it) => is(it, Relation) && it.targetTable === sourceTable && !it.alias && it !== relation
         
     | 
| 
       23641 
23667 
     | 
    
         
             
                    );
         
     | 
| 
       23642 
23668 
     | 
    
         
             
                    if (reverseRelations.length > 1) {
         
     | 
| 
       23643 
23669 
     | 
    
         
             
                      throw new Error(
         
     | 
| 
       23644 
     | 
    
         
            -
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations between "${ 
     | 
| 
      
 23670 
     | 
    
         
            +
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations between "${targetTableName}" and "${sourceTableName}" were found.
         
     | 
| 
       23645 
23671 
     | 
    
         
             
            Hint: you can specify "alias" on both sides of the relation with the same value`
         
     | 
| 
       23646 
23672 
     | 
    
         
             
                      );
         
     | 
| 
       23647 
23673 
     | 
    
         
             
                    }
         
     | 
| 
       23648 
23674 
     | 
    
         
             
                    reverseRelation = reverseRelations[0];
         
     | 
| 
       23649 
23675 
     | 
    
         
             
                    if (!reverseRelation) {
         
     | 
| 
       23650 
23676 
     | 
    
         
             
                      throw new Error(
         
     | 
| 
       23651 
     | 
    
         
            -
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relation of table "${ 
     | 
| 
      
 23677 
     | 
    
         
            +
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relation of table "${targetTableName}" with target table "${sourceTableName}" was found`
         
     | 
| 
       23652 
23678 
     | 
    
         
             
                      );
         
     | 
| 
       23653 
23679 
     | 
    
         
             
                    }
         
     | 
| 
       23654 
23680 
     | 
    
         
             
                  }
         
     | 
| 
       23655 
23681 
     | 
    
         
             
                  if (!reverseRelation.sourceColumns || !reverseRelation.targetColumns) {
         
     | 
| 
       23656 
23682 
     | 
    
         
             
                    throw new Error(
         
     | 
| 
       23657 
     | 
    
         
            -
                      `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and reverse relation "${ 
     | 
| 
      
 23683 
     | 
    
         
            +
                      `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and reverse relation "${targetTableName}.${reverseRelation.fieldName}" does not have "from"/"to" defined`
         
     | 
| 
       23658 
23684 
     | 
    
         
             
                    );
         
     | 
| 
       23659 
23685 
     | 
    
         
             
                  }
         
     | 
| 
       23660 
23686 
     | 
    
         
             
                  relation.sourceColumns = reverseRelation.targetColumns;
         
     | 
| 
         @@ -23664,8 +23690,8 @@ Hint: you can specify "alias" on both sides of the relation with the same value` 
     | 
|
| 
       23664 
23690 
     | 
    
         
             
                    target: reverseRelation.through.source
         
     | 
| 
       23665 
23691 
     | 
    
         
             
                  } : void 0;
         
     | 
| 
       23666 
23692 
     | 
    
         
             
                  relation.throughTable = reverseRelation.throughTable;
         
     | 
| 
       23667 
     | 
    
         
            -
                  relation.isReversed = ! 
     | 
| 
       23668 
     | 
    
         
            -
                  relation.where =  
     | 
| 
      
 23693 
     | 
    
         
            +
                  relation.isReversed = !where;
         
     | 
| 
      
 23694 
     | 
    
         
            +
                  relation.where = where ?? reverseRelation.where;
         
     | 
| 
       23669 
23695 
     | 
    
         
             
                }
         
     | 
| 
       23670 
23696 
     | 
    
         
             
              }
         
     | 
| 
       23671 
23697 
     | 
    
         
             
              return tablesConfig;
         
     | 
| 
         @@ -24025,6 +24051,10 @@ var init_relations = __esm({ 
     | 
|
| 
       24025 
24051 
     | 
    
         
             
                    __publicField(this, "through");
         
     | 
| 
       24026 
24052 
     | 
    
         
             
                    __publicField(this, "throughTable");
         
     | 
| 
       24027 
24053 
     | 
    
         
             
                    __publicField(this, "isReversed");
         
     | 
| 
      
 24054 
     | 
    
         
            +
                    /** @internal */
         
     | 
| 
      
 24055 
     | 
    
         
            +
                    __publicField(this, "sourceColumnTableNames", []);
         
     | 
| 
      
 24056 
     | 
    
         
            +
                    /** @internal */
         
     | 
| 
      
 24057 
     | 
    
         
            +
                    __publicField(this, "targetColumnTableNames", []);
         
     | 
| 
       24028 
24058 
     | 
    
         
             
                    this.targetTableName = targetTableName;
         
     | 
| 
       24029 
24059 
     | 
    
         
             
                    this.targetTable = targetTable;
         
     | 
| 
       24030 
24060 
     | 
    
         
             
                  }
         
     | 
| 
         @@ -24040,12 +24070,14 @@ var init_relations = __esm({ 
     | 
|
| 
       24040 
24070 
     | 
    
         
             
                    if (config?.from) {
         
     | 
| 
       24041 
24071 
     | 
    
         
             
                      this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
         
     | 
| 
       24042 
24072 
     | 
    
         
             
                        this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
         
     | 
| 
      
 24073 
     | 
    
         
            +
                        this.sourceColumnTableNames.push(it._.tableName);
         
     | 
| 
       24043 
24074 
     | 
    
         
             
                        return it._.column;
         
     | 
| 
       24044 
24075 
     | 
    
         
             
                      });
         
     | 
| 
       24045 
24076 
     | 
    
         
             
                    }
         
     | 
| 
       24046 
24077 
     | 
    
         
             
                    if (config?.to) {
         
     | 
| 
       24047 
24078 
     | 
    
         
             
                      this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
         
     | 
| 
       24048 
24079 
     | 
    
         
             
                        this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
         
     | 
| 
      
 24080 
     | 
    
         
            +
                        this.targetColumnTableNames.push(it._.tableName);
         
     | 
| 
       24049 
24081 
     | 
    
         
             
                        return it._.column;
         
     | 
| 
       24050 
24082 
     | 
    
         
             
                      });
         
     | 
| 
       24051 
24083 
     | 
    
         
             
                    }
         
     | 
| 
         @@ -24069,12 +24101,14 @@ var init_relations = __esm({ 
     | 
|
| 
       24069 
24101 
     | 
    
         
             
                    if (config?.from) {
         
     | 
| 
       24070 
24102 
     | 
    
         
             
                      this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
         
     | 
| 
       24071 
24103 
     | 
    
         
             
                        this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
         
     | 
| 
      
 24104 
     | 
    
         
            +
                        this.sourceColumnTableNames.push(it._.tableName);
         
     | 
| 
       24072 
24105 
     | 
    
         
             
                        return it._.column;
         
     | 
| 
       24073 
24106 
     | 
    
         
             
                      });
         
     | 
| 
       24074 
24107 
     | 
    
         
             
                    }
         
     | 
| 
       24075 
24108 
     | 
    
         
             
                    if (config?.to) {
         
     | 
| 
       24076 
24109 
     | 
    
         
             
                      this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
         
     | 
| 
       24077 
24110 
     | 
    
         
             
                        this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
         
     | 
| 
      
 24111 
     | 
    
         
            +
                        this.targetColumnTableNames.push(it._.tableName);
         
     | 
| 
       24078 
24112 
     | 
    
         
             
                        return it._.column;
         
     | 
| 
       24079 
24113 
     | 
    
         
             
                      });
         
     | 
| 
       24080 
24114 
     | 
    
         
             
                    }
         
     | 
    
        package/api.mjs
    CHANGED
    
    | 
         @@ -23573,37 +23573,65 @@ function processRelations(tablesConfig, tables) { 
     | 
|
| 
       23573 
23573 
     | 
    
         
             
                  if (!is(relation, Relation)) {
         
     | 
| 
       23574 
23574 
     | 
    
         
             
                    continue;
         
     | 
| 
       23575 
23575 
     | 
    
         
             
                  }
         
     | 
| 
       23576 
     | 
    
         
            -
                   
     | 
| 
       23577 
     | 
    
         
            -
                   
     | 
| 
      
 23576 
     | 
    
         
            +
                  let reverseRelation;
         
     | 
| 
      
 23577 
     | 
    
         
            +
                  const {
         
     | 
| 
      
 23578 
     | 
    
         
            +
                    targetTableName,
         
     | 
| 
      
 23579 
     | 
    
         
            +
                    alias,
         
     | 
| 
      
 23580 
     | 
    
         
            +
                    sourceColumns,
         
     | 
| 
      
 23581 
     | 
    
         
            +
                    targetColumns,
         
     | 
| 
      
 23582 
     | 
    
         
            +
                    throughTable,
         
     | 
| 
      
 23583 
     | 
    
         
            +
                    sourceTable,
         
     | 
| 
      
 23584 
     | 
    
         
            +
                    through,
         
     | 
| 
      
 23585 
     | 
    
         
            +
                    targetTable,
         
     | 
| 
      
 23586 
     | 
    
         
            +
                    where,
         
     | 
| 
      
 23587 
     | 
    
         
            +
                    sourceColumnTableNames,
         
     | 
| 
      
 23588 
     | 
    
         
            +
                    targetColumnTableNames
         
     | 
| 
      
 23589 
     | 
    
         
            +
                  } = relation;
         
     | 
| 
      
 23590 
     | 
    
         
            +
                  const relationPrintName = `relations -> ${tableConfig.name}: { ${relationFieldName}: r.${is(relation, One) ? "one" : "many"}.${targetTableName}(...) }`;
         
     | 
| 
      
 23591 
     | 
    
         
            +
                  if (typeof alias === "string" && !alias) {
         
     | 
| 
       23578 
23592 
     | 
    
         
             
                    throw new Error(`${relationPrintName}: "alias" cannot be an empty string - omit it if you don't need it`);
         
     | 
| 
       23579 
23593 
     | 
    
         
             
                  }
         
     | 
| 
       23580 
     | 
    
         
            -
                  if ( 
     | 
| 
       23581 
     | 
    
         
            -
                    throw new Error(`${relationPrintName}: "from" cannot be  
     | 
| 
      
 23594 
     | 
    
         
            +
                  if (sourceColumns?.length === 0) {
         
     | 
| 
      
 23595 
     | 
    
         
            +
                    throw new Error(`${relationPrintName}: "from" cannot be empty`);
         
     | 
| 
       23582 
23596 
     | 
    
         
             
                  }
         
     | 
| 
       23583 
     | 
    
         
            -
                  if ( 
     | 
| 
       23584 
     | 
    
         
            -
                    throw new Error(`${relationPrintName}: "to" cannot be  
     | 
| 
      
 23597 
     | 
    
         
            +
                  if (targetColumns?.length === 0) {
         
     | 
| 
      
 23598 
     | 
    
         
            +
                    throw new Error(`${relationPrintName}: "to" cannot be empty`);
         
     | 
| 
       23585 
23599 
     | 
    
         
             
                  }
         
     | 
| 
       23586 
     | 
    
         
            -
                  if ( 
     | 
| 
       23587 
     | 
    
         
            -
                    if ( 
     | 
| 
      
 23600 
     | 
    
         
            +
                  if (sourceColumns && targetColumns) {
         
     | 
| 
      
 23601 
     | 
    
         
            +
                    if (sourceColumns.length !== targetColumns.length && !throughTable) {
         
     | 
| 
       23588 
23602 
     | 
    
         
             
                      throw new Error(
         
     | 
| 
       23589 
23603 
     | 
    
         
             
                        `${relationPrintName}: "from" and "to" fields without "through" must have the same length`
         
     | 
| 
       23590 
23604 
     | 
    
         
             
                      );
         
     | 
| 
       23591 
23605 
     | 
    
         
             
                    }
         
     | 
| 
       23592 
     | 
    
         
            -
                     
     | 
| 
       23593 
     | 
    
         
            -
                      if ( 
     | 
| 
      
 23606 
     | 
    
         
            +
                    for (const sName of sourceColumnTableNames) {
         
     | 
| 
      
 23607 
     | 
    
         
            +
                      if (sName !== sourceTableName) {
         
     | 
| 
      
 23608 
     | 
    
         
            +
                        throw new Error(
         
     | 
| 
      
 23609 
     | 
    
         
            +
                          `${relationPrintName}: all "from" columns must belong to table "${sourceTableName}", found column of table "${sName}"`
         
     | 
| 
      
 23610 
     | 
    
         
            +
                        );
         
     | 
| 
      
 23611 
     | 
    
         
            +
                      }
         
     | 
| 
      
 23612 
     | 
    
         
            +
                    }
         
     | 
| 
      
 23613 
     | 
    
         
            +
                    for (const tName of targetColumnTableNames) {
         
     | 
| 
      
 23614 
     | 
    
         
            +
                      if (tName !== targetTableName) {
         
     | 
| 
      
 23615 
     | 
    
         
            +
                        throw new Error(
         
     | 
| 
      
 23616 
     | 
    
         
            +
                          `${relationPrintName}: all "to" columns must belong to table "${targetTable}", found column of table "${tName}"`
         
     | 
| 
      
 23617 
     | 
    
         
            +
                        );
         
     | 
| 
      
 23618 
     | 
    
         
            +
                      }
         
     | 
| 
      
 23619 
     | 
    
         
            +
                    }
         
     | 
| 
      
 23620 
     | 
    
         
            +
                    if (through) {
         
     | 
| 
      
 23621 
     | 
    
         
            +
                      if (through.source.length !== sourceColumns.length || through.target.length !== targetColumns.length) {
         
     | 
| 
       23594 
23622 
     | 
    
         
             
                        throw new Error(
         
     | 
| 
       23595 
23623 
     | 
    
         
             
                          `${relationPrintName}: ".through(column)" must be used either on all columns in "from" and "to" or not defined on any of them`
         
     | 
| 
       23596 
23624 
     | 
    
         
             
                        );
         
     | 
| 
       23597 
23625 
     | 
    
         
             
                      }
         
     | 
| 
       23598 
     | 
    
         
            -
                      for (const column6 of  
     | 
| 
       23599 
     | 
    
         
            -
                        if (tables[column6._.tableName] !==  
     | 
| 
      
 23626 
     | 
    
         
            +
                      for (const column6 of through.source) {
         
     | 
| 
      
 23627 
     | 
    
         
            +
                        if (tables[column6._.tableName] !== throughTable) {
         
     | 
| 
       23600 
23628 
     | 
    
         
             
                          throw new Error(
         
     | 
| 
       23601 
23629 
     | 
    
         
             
                            `${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
         
     | 
| 
       23602 
23630 
     | 
    
         
             
                          );
         
     | 
| 
       23603 
23631 
     | 
    
         
             
                        }
         
     | 
| 
       23604 
23632 
     | 
    
         
             
                      }
         
     | 
| 
       23605 
     | 
    
         
            -
                      for (const column6 of  
     | 
| 
       23606 
     | 
    
         
            -
                        if (tables[column6._.tableName] !==  
     | 
| 
      
 23633 
     | 
    
         
            +
                      for (const column6 of through.target) {
         
     | 
| 
      
 23634 
     | 
    
         
            +
                        if (tables[column6._.tableName] !== throughTable) {
         
     | 
| 
       23607 
23635 
     | 
    
         
             
                          throw new Error(
         
     | 
| 
       23608 
23636 
     | 
    
         
             
                            `${relationPrintName}: ".through(column)" must be used on the same table by all columns of the relation`
         
     | 
| 
       23609 
23637 
     | 
    
         
             
                          );
         
     | 
| 
         @@ -23612,54 +23640,52 @@ function processRelations(tablesConfig, tables) { 
     | 
|
| 
       23612 
23640 
     | 
    
         
             
                    }
         
     | 
| 
       23613 
23641 
     | 
    
         
             
                    continue;
         
     | 
| 
       23614 
23642 
     | 
    
         
             
                  }
         
     | 
| 
       23615 
     | 
    
         
            -
                  if ( 
     | 
| 
      
 23643 
     | 
    
         
            +
                  if (sourceColumns || targetColumns) {
         
     | 
| 
       23616 
23644 
     | 
    
         
             
                    throw new Error(
         
     | 
| 
       23617 
23645 
     | 
    
         
             
                      `${relationPrintName}: relation must have either both "from" and "to" defined, or none of them`
         
     | 
| 
       23618 
23646 
     | 
    
         
             
                    );
         
     | 
| 
       23619 
23647 
     | 
    
         
             
                  }
         
     | 
| 
       23620 
     | 
    
         
            -
                   
     | 
| 
       23621 
     | 
    
         
            -
                  const targetTableTsName = relation.targetTableName;
         
     | 
| 
       23622 
     | 
    
         
            -
                  const reverseTableConfig = tablesConfig[targetTableTsName];
         
     | 
| 
      
 23648 
     | 
    
         
            +
                  const reverseTableConfig = tablesConfig[targetTableName];
         
     | 
| 
       23623 
23649 
     | 
    
         
             
                  if (!reverseTableConfig) {
         
     | 
| 
       23624 
23650 
     | 
    
         
             
                    throw new Error(
         
     | 
| 
       23625 
     | 
    
         
            -
                      `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relations of table "${ 
     | 
| 
      
 23651 
     | 
    
         
            +
                      `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relations of table "${targetTableName}" were found"`
         
     | 
| 
       23626 
23652 
     | 
    
         
             
                    );
         
     | 
| 
       23627 
23653 
     | 
    
         
             
                  }
         
     | 
| 
       23628 
     | 
    
         
            -
                  if ( 
     | 
| 
      
 23654 
     | 
    
         
            +
                  if (alias) {
         
     | 
| 
       23629 
23655 
     | 
    
         
             
                    const reverseRelations = Object.values(reverseTableConfig.relations).filter(
         
     | 
| 
       23630 
     | 
    
         
            -
                      (it) => is(it, Relation) && it.alias ===  
     | 
| 
      
 23656 
     | 
    
         
            +
                      (it) => is(it, Relation) && it.alias === alias && it !== relation
         
     | 
| 
       23631 
23657 
     | 
    
         
             
                    );
         
     | 
| 
       23632 
23658 
     | 
    
         
             
                    if (reverseRelations.length > 1) {
         
     | 
| 
       23633 
23659 
     | 
    
         
             
                      throw new Error(
         
     | 
| 
       23634 
     | 
    
         
            -
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations with alias "${ 
     | 
| 
      
 23660 
     | 
    
         
            +
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations with alias "${alias}" found in table "${targetTableName}": ${reverseRelations.map((it) => `"${it.fieldName}"`).join(", ")}`
         
     | 
| 
       23635 
23661 
     | 
    
         
             
                      );
         
     | 
| 
       23636 
23662 
     | 
    
         
             
                    }
         
     | 
| 
       23637 
23663 
     | 
    
         
             
                    reverseRelation = reverseRelations[0];
         
     | 
| 
       23638 
23664 
     | 
    
         
             
                    if (!reverseRelation) {
         
     | 
| 
       23639 
23665 
     | 
    
         
             
                      throw new Error(
         
     | 
| 
       23640 
     | 
    
         
            -
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and there is no reverse relation of table "${ 
     | 
| 
      
 23666 
     | 
    
         
            +
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and there is no reverse relation of table "${targetTableName}" with alias "${alias}"`
         
     | 
| 
       23641 
23667 
     | 
    
         
             
                      );
         
     | 
| 
       23642 
23668 
     | 
    
         
             
                    }
         
     | 
| 
       23643 
23669 
     | 
    
         
             
                  } else {
         
     | 
| 
       23644 
23670 
     | 
    
         
             
                    const reverseRelations = Object.values(reverseTableConfig.relations).filter(
         
     | 
| 
       23645 
     | 
    
         
            -
                      (it) => is(it, Relation) && it.targetTable ===  
     | 
| 
      
 23671 
     | 
    
         
            +
                      (it) => is(it, Relation) && it.targetTable === sourceTable && !it.alias && it !== relation
         
     | 
| 
       23646 
23672 
     | 
    
         
             
                    );
         
     | 
| 
       23647 
23673 
     | 
    
         
             
                    if (reverseRelations.length > 1) {
         
     | 
| 
       23648 
23674 
     | 
    
         
             
                      throw new Error(
         
     | 
| 
       23649 
     | 
    
         
            -
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations between "${ 
     | 
| 
      
 23675 
     | 
    
         
            +
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and multiple relations between "${targetTableName}" and "${sourceTableName}" were found.
         
     | 
| 
       23650 
23676 
     | 
    
         
             
            Hint: you can specify "alias" on both sides of the relation with the same value`
         
     | 
| 
       23651 
23677 
     | 
    
         
             
                      );
         
     | 
| 
       23652 
23678 
     | 
    
         
             
                    }
         
     | 
| 
       23653 
23679 
     | 
    
         
             
                    reverseRelation = reverseRelations[0];
         
     | 
| 
       23654 
23680 
     | 
    
         
             
                    if (!reverseRelation) {
         
     | 
| 
       23655 
23681 
     | 
    
         
             
                      throw new Error(
         
     | 
| 
       23656 
     | 
    
         
            -
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relation of table "${ 
     | 
| 
      
 23682 
     | 
    
         
            +
                        `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and no reverse relation of table "${targetTableName}" with target table "${sourceTableName}" was found`
         
     | 
| 
       23657 
23683 
     | 
    
         
             
                      );
         
     | 
| 
       23658 
23684 
     | 
    
         
             
                    }
         
     | 
| 
       23659 
23685 
     | 
    
         
             
                  }
         
     | 
| 
       23660 
23686 
     | 
    
         
             
                  if (!reverseRelation.sourceColumns || !reverseRelation.targetColumns) {
         
     | 
| 
       23661 
23687 
     | 
    
         
             
                    throw new Error(
         
     | 
| 
       23662 
     | 
    
         
            -
                      `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and reverse relation "${ 
     | 
| 
      
 23688 
     | 
    
         
            +
                      `${relationPrintName}: not enough data provided to build the relation - "from"/"to" are not defined, and reverse relation "${targetTableName}.${reverseRelation.fieldName}" does not have "from"/"to" defined`
         
     | 
| 
       23663 
23689 
     | 
    
         
             
                    );
         
     | 
| 
       23664 
23690 
     | 
    
         
             
                  }
         
     | 
| 
       23665 
23691 
     | 
    
         
             
                  relation.sourceColumns = reverseRelation.targetColumns;
         
     | 
| 
         @@ -23669,8 +23695,8 @@ Hint: you can specify "alias" on both sides of the relation with the same value` 
     | 
|
| 
       23669 
23695 
     | 
    
         
             
                    target: reverseRelation.through.source
         
     | 
| 
       23670 
23696 
     | 
    
         
             
                  } : void 0;
         
     | 
| 
       23671 
23697 
     | 
    
         
             
                  relation.throughTable = reverseRelation.throughTable;
         
     | 
| 
       23672 
     | 
    
         
            -
                  relation.isReversed = ! 
     | 
| 
       23673 
     | 
    
         
            -
                  relation.where =  
     | 
| 
      
 23698 
     | 
    
         
            +
                  relation.isReversed = !where;
         
     | 
| 
      
 23699 
     | 
    
         
            +
                  relation.where = where ?? reverseRelation.where;
         
     | 
| 
       23674 
23700 
     | 
    
         
             
                }
         
     | 
| 
       23675 
23701 
     | 
    
         
             
              }
         
     | 
| 
       23676 
23702 
     | 
    
         
             
              return tablesConfig;
         
     | 
| 
         @@ -24030,6 +24056,10 @@ var init_relations = __esm({ 
     | 
|
| 
       24030 
24056 
     | 
    
         
             
                    __publicField(this, "through");
         
     | 
| 
       24031 
24057 
     | 
    
         
             
                    __publicField(this, "throughTable");
         
     | 
| 
       24032 
24058 
     | 
    
         
             
                    __publicField(this, "isReversed");
         
     | 
| 
      
 24059 
     | 
    
         
            +
                    /** @internal */
         
     | 
| 
      
 24060 
     | 
    
         
            +
                    __publicField(this, "sourceColumnTableNames", []);
         
     | 
| 
      
 24061 
     | 
    
         
            +
                    /** @internal */
         
     | 
| 
      
 24062 
     | 
    
         
            +
                    __publicField(this, "targetColumnTableNames", []);
         
     | 
| 
       24033 
24063 
     | 
    
         
             
                    this.targetTableName = targetTableName;
         
     | 
| 
       24034 
24064 
     | 
    
         
             
                    this.targetTable = targetTable;
         
     | 
| 
       24035 
24065 
     | 
    
         
             
                  }
         
     | 
| 
         @@ -24045,12 +24075,14 @@ var init_relations = __esm({ 
     | 
|
| 
       24045 
24075 
     | 
    
         
             
                    if (config?.from) {
         
     | 
| 
       24046 
24076 
     | 
    
         
             
                      this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
         
     | 
| 
       24047 
24077 
     | 
    
         
             
                        this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
         
     | 
| 
      
 24078 
     | 
    
         
            +
                        this.sourceColumnTableNames.push(it._.tableName);
         
     | 
| 
       24048 
24079 
     | 
    
         
             
                        return it._.column;
         
     | 
| 
       24049 
24080 
     | 
    
         
             
                      });
         
     | 
| 
       24050 
24081 
     | 
    
         
             
                    }
         
     | 
| 
       24051 
24082 
     | 
    
         
             
                    if (config?.to) {
         
     | 
| 
       24052 
24083 
     | 
    
         
             
                      this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
         
     | 
| 
       24053 
24084 
     | 
    
         
             
                        this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
         
     | 
| 
      
 24085 
     | 
    
         
            +
                        this.targetColumnTableNames.push(it._.tableName);
         
     | 
| 
       24054 
24086 
     | 
    
         
             
                        return it._.column;
         
     | 
| 
       24055 
24087 
     | 
    
         
             
                      });
         
     | 
| 
       24056 
24088 
     | 
    
         
             
                    }
         
     | 
| 
         @@ -24074,12 +24106,14 @@ var init_relations = __esm({ 
     | 
|
| 
       24074 
24106 
     | 
    
         
             
                    if (config?.from) {
         
     | 
| 
       24075 
24107 
     | 
    
         
             
                      this.sourceColumns = (Array.isArray(config.from) ? config.from : [config.from]).map((it) => {
         
     | 
| 
       24076 
24108 
     | 
    
         
             
                        this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
         
     | 
| 
      
 24109 
     | 
    
         
            +
                        this.sourceColumnTableNames.push(it._.tableName);
         
     | 
| 
       24077 
24110 
     | 
    
         
             
                        return it._.column;
         
     | 
| 
       24078 
24111 
     | 
    
         
             
                      });
         
     | 
| 
       24079 
24112 
     | 
    
         
             
                    }
         
     | 
| 
       24080 
24113 
     | 
    
         
             
                    if (config?.to) {
         
     | 
| 
       24081 
24114 
     | 
    
         
             
                      this.targetColumns = (Array.isArray(config.to) ? config.to : [config.to]).map((it) => {
         
     | 
| 
       24082 
24115 
     | 
    
         
             
                        this.throughTable ??= it._.through ? tables[it._.through._.tableName] : void 0;
         
     | 
| 
      
 24116 
     | 
    
         
            +
                        this.targetColumnTableNames.push(it._.tableName);
         
     | 
| 
       24083 
24117 
     | 
    
         
             
                        return it._.column;
         
     | 
| 
       24084 
24118 
     | 
    
         
             
                      });
         
     | 
| 
       24085 
24119 
     | 
    
         
             
                    }
         
     | 
    
        package/bin.cjs
    CHANGED
    
    | 
         @@ -93920,7 +93920,7 @@ init_utils5(); 
     | 
|
| 
       93920 
93920 
     | 
    
         
             
            var version2 = async () => {
         
     | 
| 
       93921 
93921 
     | 
    
         
             
              const { npmVersion } = await ormCoreVersions();
         
     | 
| 
       93922 
93922 
     | 
    
         
             
              const ormVersion = npmVersion ? `drizzle-orm: v${npmVersion}` : "";
         
     | 
| 
       93923 
     | 
    
         
            -
              const envVersion = "1.0.0-beta.1- 
     | 
| 
      
 93923 
     | 
    
         
            +
              const envVersion = "1.0.0-beta.1-34ee105";
         
     | 
| 
       93924 
93924 
     | 
    
         
             
              const kitVersion = envVersion ? `v${envVersion}` : "--";
         
     | 
| 
       93925 
93925 
     | 
    
         
             
              const versions = `drizzle-kit: ${kitVersion}
         
     | 
| 
       93926 
93926 
     | 
    
         
             
            ${ormVersion}`;
         
     |