Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### 12.2.0 <small>(2026-??-??)</small>

#### Deprecations

* All enum cases have been converted from `UPPER_SNAKE_CASE` to `PascalCase`. A compatibility layer is available until Mako 13.

--------------------------------------------------------

### 12.0.3, 12.1.1 <small>(2026-03-01)</small>

#### Bugfixes
Expand Down
77 changes: 59 additions & 18 deletions src/mako/cli/input/Key.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,68 @@

namespace mako\cli\input;

use Deprecated;

/**
* Keyboard keys.
*/
enum Key: string
{
case UP = "\x1b[A";
case DOWN = "\x1b[B";
case LEFT = "\x1b[D";
case RIGHT = "\x1b[C";
case ENTER = "\n";
case SPACE = ' ';
case TAB = "\t";
case CTRL_A = "\x01";
case CTRL_B = "\x02";
case CTRL_C = "\x03";
case CTRL_D = "\x04";
case BACKSPACE = "\x7F";
case DELETE = "\x1b[3~";
case HOME = "\x1b[H";
case END = "\x1b[F";
case PAGE_UP = "\x1b[5~";
case PAGE_DOWN = "\x1b[6~";
case ESCAPE = "\x1b";
/* Start compatibility */
#[Deprecated('use Key::Up instead', 'Mako 12.2.0')]
public const UP = self::Up;
#[Deprecated('use Key::Down instead', 'Mako 12.2.0')]
public const DOWN = self::Down;
#[Deprecated('use Key::Left instead', 'Mako 12.2.0')]
public const LEFT = self::Left;
#[Deprecated('use Key::Right instead', 'Mako 12.2.0')]
public const RIGHT = self::Right;
#[Deprecated('use Key::Enter instead', 'Mako 12.2.0')]
public const ENTER = self::Enter;
#[Deprecated('use Key::Space instead', 'Mako 12.2.0')]
public const SPACE = self::Space;
#[Deprecated('use Key::Tab instead', 'Mako 12.2.0')]
public const TAB = self::Tab;
#[Deprecated('use Key::CtrlA instead', 'Mako 12.2.0')]
public const CTRL_A = self::CtrlA;
#[Deprecated('use Key::CtrlB instead', 'Mako 12.2.0')]
public const CTRL_B = self::CtrlB;
#[Deprecated('use Key::CtrlC instead', 'Mako 12.2.0')]
public const CTRL_C = self::CtrlC;
#[Deprecated('use Key::CtrlD instead', 'Mako 12.2.0')]
public const CTRL_D = self::CtrlD;
#[Deprecated('use Key::Backspace instead', 'Mako 12.2.0')]
public const BACKSPACE = self::Backspace;
#[Deprecated('use Key::Delete instead', 'Mako 12.2.0')]
public const DELETE = self::Delete;
#[Deprecated('use Key::Home instead', 'Mako 12.2.0')]
public const HOME = self::Home;
#[Deprecated('use Key::End instead', 'Mako 12.2.0')]
public const END = self::End;
#[Deprecated('use Key::PageUp instead', 'Mako 12.2.0')]
public const PAGE_UP = self::PageUp;
#[Deprecated('use Key::PageDown instead', 'Mako 12.2.0')]
public const PAGE_DOWN = self::PageDown;
#[Deprecated('use Key::Escape instead', 'Mako 12.2.0')]
public const ESCAPE = self::Escape;
/* End compatibility */

case Up = "\x1b[A";
case Down = "\x1b[B";
case Left = "\x1b[D";
case Right = "\x1b[C";
case Enter = "\n";
case Space = ' ';
case Tab = "\t";
case CtrlA = "\x01";
case CtrlB = "\x02";
case CtrlC = "\x03";
case CtrlD = "\x04";
case Backspace = "\x7F";
case Delete = "\x1b[3~";
case Home = "\x1b[H";
case End = "\x1b[F";
case PageUp = "\x1b[5~";
case PageDown = "\x1b[6~";
case Escape = "\x1b";
}
4 changes: 2 additions & 2 deletions src/mako/cli/input/components/Confirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ protected function interactiveConfirmation(): bool

$key = Key::tryFrom($this->input->readBytes(3));

if ($key === Key::SPACE || $key === Key::LEFT || $key === Key::RIGHT) {
if ($key === Key::Space || $key === Key::Left || $key === Key::Right) {
$this->toggleSelection();
}
elseif ($key === Key::ENTER) {
elseif ($key === Key::Enter) {
return $this->currentSelection;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/mako/cli/input/components/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,16 +268,16 @@ protected function interactiveSelect(array $options, callable $optionFormatter):

$key = Key::tryFrom($this->input->readBytes(3));

if ($key === Key::UP) {
if ($key === Key::Up) {
$this->moveCursorUp();
}
elseif ($key === Key::DOWN) {
elseif ($key === Key::Down) {
$this->moveCursorDown();
}
elseif ($key === Key::SPACE || $key === Key::LEFT || $key === Key::RIGHT) {
elseif ($key === Key::Space || $key === Key::Left || $key === Key::Right) {
$this->toggleSelection();
}
elseif ($key === Key::ENTER) {
elseif ($key === Key::Enter) {
$selection = $this->getSelection();

if ($this->allowEmptySelection || $selection !== null) {
Expand Down
10 changes: 5 additions & 5 deletions src/mako/database/query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ public function orWhereColumn(array|string $column1, string $operator, array|str
*
* @return $this
*/
public function whereVectorDistance(string $column, array|string|Subquery $vector, float $maxDistance, VectorDistance $vectorDistance = VectorDistance::COSINE, string $separator = 'AND'): static
public function whereVectorDistance(string $column, array|string|Subquery $vector, float $maxDistance, VectorDistance $vectorDistance = VectorDistance::Cosine, string $separator = 'AND'): static
{
$this->wheres[] = [
'type' => 'whereVectorDistance',
Expand All @@ -666,7 +666,7 @@ public function whereVectorDistance(string $column, array|string|Subquery $vecto
*
* @return $this
*/
public function orWhereVectorDistance(string $column, array|string|Subquery $vector, float $maxDistance, VectorDistance $vectorDistance = VectorDistance::COSINE): static
public function orWhereVectorDistance(string $column, array|string|Subquery $vector, float $maxDistance, VectorDistance $vectorDistance = VectorDistance::Cosine): static
{
return $this->whereVectorDistance($column, $vector, $maxDistance, $vectorDistance, 'OR');
}
Expand Down Expand Up @@ -1130,7 +1130,7 @@ public function descendingRaw(string $raw, array $parameters = []): static
/**
* Adds a vector ORDER BY clause.
*/
public function orderByVectorDistance(string $column, array|string|Subquery $vector, VectorDistance $vectorDistance = VectorDistance::COSINE, string $order = 'ASC'): static
public function orderByVectorDistance(string $column, array|string|Subquery $vector, VectorDistance $vectorDistance = VectorDistance::Cosine, string $order = 'ASC'): static
{
$this->orderings[] = [
'type' => 'vectorDistanceOrdering',
Expand All @@ -1146,15 +1146,15 @@ public function orderByVectorDistance(string $column, array|string|Subquery $vec
/**
* Adds a ascending vector ORDER BY clause.
*/
public function ascendingVectorDistance(string $column, array|string|Subquery $vector, VectorDistance $vectorDistance = VectorDistance::COSINE): static
public function ascendingVectorDistance(string $column, array|string|Subquery $vector, VectorDistance $vectorDistance = VectorDistance::Cosine): static
{
return $this->orderByVectorDistance($column, $vector, $vectorDistance, 'ASC');
}

/**
* Adds a descending vector ORDER BY clause.
*/
public function descendingVectorDistance(string $column, array|string|Subquery $vector, VectorDistance $vectorDistance = VectorDistance::COSINE): static
public function descendingVectorDistance(string $column, array|string|Subquery $vector, VectorDistance $vectorDistance = VectorDistance::Cosine): static
{
return $this->orderByVectorDistance($column, $vector, $vectorDistance, 'DESC');
}
Expand Down
13 changes: 11 additions & 2 deletions src/mako/database/query/VectorDistance.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@

namespace mako\database\query;

use Deprecated;

/**
* Vector distance.
*/
enum VectorDistance
{
case COSINE;
case EUCLIDEAN;
/* Start compatibility */
#[Deprecated('use VectorDistance::Cosine instead', 'Mako 12.2.0')]
public const COSINE = self::Cosine;
#[Deprecated('use VectorDistance::Euclidean instead', 'Mako 12.2.0')]
public const EUCLIDEAN = self::Euclidean;
/* End compatibility */

case Cosine;
case Euclidean;
}
4 changes: 2 additions & 2 deletions src/mako/database/query/compilers/MariaDB.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ protected function vectorDistance(array $vectorDistance): string
}

$function = match ($vectorDistance['vectorDistance']) {
VectorDistance::COSINE => 'VEC_DISTANCE_COSINE',
VectorDistance::EUCLIDEAN => 'VEC_DISTANCE_EUCLIDEAN',
VectorDistance::Cosine => 'VEC_DISTANCE_COSINE',
VectorDistance::Euclidean => 'VEC_DISTANCE_EUCLIDEAN',
};

return "{$function}({$this->column($vectorDistance['column'], false)}, {$vector})";
Expand Down
4 changes: 2 additions & 2 deletions src/mako/database/query/compilers/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ protected function vectorDistance(array $vectorDistance): string
}

$function = match ($vectorDistance['vectorDistance']) {
VectorDistance::COSINE => 'COSINE',
VectorDistance::EUCLIDEAN => 'EUCLIDEAN',
VectorDistance::Cosine => 'COSINE',
VectorDistance::Euclidean => 'EUCLIDEAN',
};

return "DISTANCE({$this->column($vectorDistance['column'], false)}, {$vector}, '{$function}')";
Expand Down
4 changes: 2 additions & 2 deletions src/mako/database/query/compilers/Postgres.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ protected function vectorDistance(array $vectorDistance): string
}

$function = match ($vectorDistance['vectorDistance']) {
VectorDistance::COSINE => '<=>',
VectorDistance::EUCLIDEAN => '<->',
VectorDistance::Cosine => '<=>',
VectorDistance::Euclidean => '<->',
};

return "{$this->column($vectorDistance['column'], false)} {$function} {$vector}";
Expand Down
14 changes: 7 additions & 7 deletions src/mako/database/query/values/out/VectorDistance.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class VectorDistance extends Value
public function __construct(
protected string $column,
protected array|string $vector,
protected VectorDistanceType $vectorDistance = VectorDistanceType::COSINE,
protected VectorDistanceType $vectorDistance = VectorDistanceType::Cosine,
protected ?string $alias = null
) {
}
Expand All @@ -41,8 +41,8 @@ public function __construct(
protected function getMariaDbDistance(Compiler $compiler): string
{
$function = match ($this->vectorDistance) {
VectorDistanceType::COSINE => 'VEC_DISTANCE_COSINE',
VectorDistanceType::EUCLIDEAN => 'VEC_DISTANCE_EUCLIDEAN',
VectorDistanceType::Cosine => 'VEC_DISTANCE_COSINE',
VectorDistanceType::Euclidean => 'VEC_DISTANCE_EUCLIDEAN',
};

return "{$function}({$compiler->escapeColumnName($this->column)}, VEC_FromText(?))";
Expand All @@ -54,8 +54,8 @@ protected function getMariaDbDistance(Compiler $compiler): string
protected function getMySqlDistance(Compiler $compiler): string
{
$function = match ($this->vectorDistance) {
VectorDistanceType::COSINE => 'COSINE',
VectorDistanceType::EUCLIDEAN => 'EUCLIDEAN',
VectorDistanceType::Cosine => 'COSINE',
VectorDistanceType::Euclidean => 'EUCLIDEAN',
};

return "DISTANCE({$compiler->escapeColumnName($this->column)}, STRING_TO_VECTOR(?), '{$function}')";
Expand All @@ -67,8 +67,8 @@ protected function getMySqlDistance(Compiler $compiler): string
protected function getPostgresDistance(Compiler $compiler): string
{
$function = match ($this->vectorDistance) {
VectorDistanceType::COSINE => '<=>',
VectorDistanceType::EUCLIDEAN => '<->',
VectorDistanceType::Cosine => '<=>',
VectorDistanceType::Euclidean => '<->',
};

return "{$compiler->columnName($this->column)} {$function} ?";
Expand Down
25 changes: 20 additions & 5 deletions src/mako/env/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,29 @@

namespace mako\env;

use Deprecated;

/**
* Type.
*/
enum Type
{
case BOOL;
case INT;
case FLOAT;
case JSON_AS_OBJECT;
case JSON_AS_ARRAY;
/* Start compatibility */
#[Deprecated('use Type::Bool instead', 'Mako 12.2.0')]
public const BOOL = self::Bool;
#[Deprecated('use Type::Int instead', 'Mako 12.2.0')]
public const INT = self::Int;
#[Deprecated('use Type::Float instead', 'Mako 12.2.0')]
public const FLOAT = self::Float;
#[Deprecated('use Type::JsonAsObject instead', 'Mako 12.2.0')]
public const JSON_AS_OBJECT = self::JsonAsObject;
#[Deprecated('use Type::JsonAsArray instead', 'Mako 12.2.0')]
public const JSON_AS_ARRAY = self::JsonAsArray;
/* End compatibility */

case Bool;
case Int;
case Float;
case JsonAsObject;
case JsonAsArray;
}
2 changes: 1 addition & 1 deletion src/mako/error/handlers/web/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getExceptionId(): string
*/
protected function getHttpStatus(Throwable $exception): Status
{
return ($exception instanceof HttpStatusException) ? $exception->getStatus() : Status::INTERNAL_SERVER_ERROR;
return ($exception instanceof HttpStatusException) ? $exception->getStatus() : Status::InternalServerError;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/mako/file/FileInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function validateHmac(string $hmac, #[SensitiveParameter] string $key, st
*/
public function getPermissions(): Permissions
{
return Permissions::fromInt($this->getPerms() & Permission::FULL->value);
return Permissions::fromInt($this->getPerms() & Permission::FullWithAllSpecial->value);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/mako/file/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function setPermissions(string $path, int|Permissions $permissions): bool
*/
public function getPermissions(string $path): Permissions
{
return Permissions::fromInt(fileperms($path) & Permission::FULL->value);
return Permissions::fromInt(fileperms($path) & Permission::FullWithAllSpecial->value);
}

/**
Expand Down
Loading