Find all composition definitions, attention method require builder instance in order to
properly check that embedded class exists.

@param SchemaBuilder $builder

@return CompositionDefinition[]
498435
public function getCompositions(SchemaBuilder $builder): array
    {
        $result = [];
        foreach ($this->reflection->getSchema() as $field => $type) {
            if (is_string($type) && $builder->hasSchema($type)) {
                $result[$field] = new CompositionDefinition(DocumentEntity::ONE, $type);
            }

            if (is_array($type) && isset($type[0]) && $builder->hasSchema($type[0])) {
                $result[$field] = new CompositionDefinition(DocumentEntity::MANY, $type[0]);
            }
        }

        return $result;
    }
427479
private function remapBuilderColumns(Builder $builder): void {
    if($builder->aggregate === null) {
      if($builder->columns === ['*']) {
        $builder->columns = array_keys($this->to_db);
      }

      if(is_string($builder->columns)) {
        $builder->columns = [$builder->columns];
      }

      $this->remapColumns($builder->columns);
    } else {
      if($builder->aggregate['columns'] == ['*']) {
        return;
      }

      $this->remapColumns($builder->aggregate['columns'], false);
    }
  }
122988
protected function findTargets(SchemaBuilder $builder): \Generator
    {
        foreach ($builder->getSchemas() as $schema) {
            if (!is_a($schema->getClass(), $this->getDefinition()->getTarget(), true)) {
                //Not our targets
                continue;
            }
            yield $schema;
        }
    }
686725
public function apply(Builder $builder)
    {
        $this->builder = $builder;

        if (method_exists($this, $this->orderBy())) {
            call_user_func([$this, $this->orderBy()]);
        }

        return $this->builder;
    }
141885
public function search(Builder $builder)
    {
        try {
            return $this->performSearch($builder);
        } catch (IndexNotFoundException $e) {
            $this->initIndex($builder->model);
        }
    }
541407
protected function packDefaults(SchemaBuilder $builder, array $overwriteDefaults = []): array
    {
        //Defined compositions
        $compositions = $this->getCompositions($builder);

        //User defined default values
        $userDefined = $overwriteDefaults + $this->getDefaults();

        //We need mutators to normalize default values
        $mutators = $this->getMutators();

        $defaults = [];
        foreach ($this->getFields() as $field => $type) {
            $default = is_array($type) ? [] : null;

            if (array_key_exists($field, $userDefined)) {
                //No merge to keep fields order intact
                $default = $userDefined[$field];
            }

            //Registering default values
            $defaults[$field] = $this->mutateValue(
                $builder,
                $compositions,
                $userDefined,
                $mutators,
                $field,
                $default
            );
        }

        return $defaults;
    }
99846
public function addSchema(SchemaInterface $schema): SchemaBuilder
    {
        $this->schemas[$schema->getClass()] = $schema;

        return $this;
    }
1161391
public function getSchema(): ?Builder
    {
        if (!$this->hasSchema()) {
            $this->setSchema($this->getDefaultSchema());
        }
        return $this->schema;
    }
336826
public function compile(ClassBuilder $builder)
    {
        $writer = new StreamWriter($this->options);
        $writer->writeLine('<?php');
        $writer->writeLine();

        $this->compileClassDefinition($builder, $writer);
        $this->compilePropertyDefinitions($builder, $writer);
        $this->compileMethodDefinitions($builder, $writer);

        $writer->writeLine('}');

        return $writer;
    }
93481
protected function initializeFromBuilder(Builder $builder)
    {
        $this->setModel($builder->getModel())
            ->setEagerLoads($builder->getEagerLoads());

        $builder->macro('getProtected', function (Builder $builder, string $property) {
            return $builder->{$property};
        });

        $this->scopes = $builder->getProtected('scopes');

        $this->localMacros = $builder->getProtected('localMacros');

        $this->onDelete = $builder->getProtected('onDelete');
    }
942274
public function filter(Builder $builder): Builder
    {
        if (is_null($this->parameters) || $this->request->filled($this->parameters)) {
            return $this->run($builder);
        }

        return $builder;
    }
991149
public function getSchemaTables(Schema $schema)
    {
        $tables = [];

        foreach ($this->tables->keys() as $name) {
            /** @var BaseTable $table */
            $table = $this->tables[$name];
            $tables[$name] = $table->buildTable($schema, $name, $this->charset, $this->collate);
        }

        foreach ($this->tableGenerators as $generator) {
            $table = $generator($schema);

            if (is_array($table)) {
                /** @var Table[] $table */
                foreach ($table as $t) {
                    $alias = str_replace($this->prefix, '', $t->getName());
                    $t->addOption('alias', $alias);
                    $t->addOption('charset', $this->charset);
                    $t->addOption('collate', $this->collate);
                    $tables[$alias] = $t;
                }
            } else {
                /** @var Table $table */
                $alias = str_replace($this->prefix, '', $table->getName());
                $table->addOption('alias', $alias);
                $table->addOption('charset', $this->charset);
                $table->addOption('collate', $this->collate);
                $tables[$alias] = $table;
            }
        }

        return $tables;
    }
736567
public function handleBuilder($builder, $values)
    {
        return $builder->whereNotIn(
            $this->directiveArgValue('key', $this->definitionNode->name->value),
            $values
        );
    }
469745
protected function _getSortableAttributes(Builder $builder)
    {
        if (method_exists($builder->getModel(), 'getSortableAttributes')) {
            return $builder->getModel()->getSortableAttributes();
        }

        if (property_exists($builder->getModel(), 'sortable')) {
            return $builder->getModel()->sortable;
        }

        throw new RuntimeException(sprintf('Model %s must either implement getSortableAttributes() or have $sortable property set', get_class($builder->getModel())));
    }
571648
private function _makeBuilderForAggregations($fields)
    {
        $table   = $this->_builder->table;
        $where   = $this->_builder->where;
        $limit   = $this->_builder->limit;
        $offset  = $this->_builder->offset;

        $builder         = new Builder();
        $builder->prefix = "select";
        $builder->fields = $fields;
        $builder->table  = $table;
        $builder->where  = $where;
        $builder->limit  = $limit;
        $builder->offset = $offset;
        return $builder;
    }
153732
public function objectMethods($builder)
    {
        $this->builder = $builder;
        $script = '';
        $this->getFieldTranslation($script);    //методы переводов указанного поля

        return $script;
    }
510866
public function scopeWithoutTenants(Builder $builder, $tenants): Builder
    {
        $tenants = $this->prepareTenantIds($tenants);

        return $builder->whereDoesntHave('tenants', function (Builder $builder) use ($tenants) {
            $builder->whereIn('id', $tenants);
        });
    }