Skip to content

Commit f5c0cfd

Browse files
Refactor object type constants to use VAR_OBJECT for consistency across the database adapter and validator classes
1 parent f62ff51 commit f5c0cfd

12 files changed

Lines changed: 47 additions & 47 deletions

File tree

src/Database/Adapter/Postgres.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,8 @@ public function createIndex(string $collection, string $id, string $type, array
886886
Database::INDEX_HNSW_COSINE,
887887
Database::INDEX_HNSW_DOT => 'INDEX',
888888
Database::INDEX_UNIQUE => 'UNIQUE INDEX',
889-
Database::Index_Object => 'INDEX',
890-
default => throw new DatabaseException('Unknown index type: ' . $type . '. Must be one of ' . Database::INDEX_KEY . ', ' . Database::INDEX_UNIQUE . ', ' . Database::INDEX_FULLTEXT . ', ' . Database::INDEX_SPATIAL . ', ' . Database::Index_Object . ', ' . Database::INDEX_HNSW_EUCLIDEAN . ', ' . Database::INDEX_HNSW_COSINE . ', ' . Database::INDEX_HNSW_DOT),
889+
Database::INDEX_OBJECT => 'INDEX',
890+
default => throw new DatabaseException('Unknown index type: ' . $type . '. Must be one of ' . Database::INDEX_KEY . ', ' . Database::INDEX_UNIQUE . ', ' . Database::INDEX_FULLTEXT . ', ' . Database::INDEX_SPATIAL . ', ' . Database::INDEX_OBJECT . ', ' . Database::INDEX_HNSW_EUCLIDEAN . ', ' . Database::INDEX_HNSW_COSINE . ', ' . Database::INDEX_HNSW_DOT),
891891
};
892892

893893
$key = "\"{$this->getNamespace()}_{$this->tenant}_{$collection}_{$id}\"";
@@ -906,7 +906,7 @@ public function createIndex(string $collection, string $id, string $type, array
906906
Database::INDEX_HNSW_EUCLIDEAN => " USING HNSW ({$attributes} vector_l2_ops)",
907907
Database::INDEX_HNSW_COSINE => " USING HNSW ({$attributes} vector_cosine_ops)",
908908
Database::INDEX_HNSW_DOT => " USING HNSW ({$attributes} vector_ip_ops)",
909-
Database::Index_Object => " USING GIN ({$attributes})",
909+
Database::INDEX_OBJECT => " USING GIN ({$attributes})",
910910
default => " ({$attributes})",
911911
};
912912

@@ -1855,7 +1855,7 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool
18551855
case Database::VAR_DATETIME:
18561856
return 'TIMESTAMP(3)';
18571857

1858-
case Database::TYPE_OBJECT:
1858+
case Database::VAR_OBJECT:
18591859
return 'JSONB';
18601860

18611861
case Database::VAR_POINT:
@@ -1871,7 +1871,7 @@ protected function getSQLType(string $type, int $size, bool $signed = true, bool
18711871
return "VECTOR({$size})";
18721872

18731873
default:
1874-
throw new DatabaseException('Unknown Type: ' . $type . '. Must be one of ' . Database::VAR_STRING . ', ' . Database::VAR_INTEGER . ', ' . Database::VAR_FLOAT . ', ' . Database::VAR_BOOLEAN . ', ' . Database::VAR_DATETIME . ', ' . Database::VAR_RELATIONSHIP . ', ' . Database::TYPE_OBJECT . ', ' . Database::VAR_POINT . ', ' . Database::VAR_LINESTRING . ', ' . Database::VAR_POLYGON);
1874+
throw new DatabaseException('Unknown Type: ' . $type . '. Must be one of ' . Database::VAR_STRING . ', ' . Database::VAR_INTEGER . ', ' . Database::VAR_FLOAT . ', ' . Database::VAR_BOOLEAN . ', ' . Database::VAR_DATETIME . ', ' . Database::VAR_RELATIONSHIP . ', ' . Database::VAR_OBJECT . ', ' . Database::VAR_POINT . ', ' . Database::VAR_LINESTRING . ', ' . Database::VAR_POLYGON);
18751875
}
18761876
}
18771877

src/Database/Adapter/SQL.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ public function getAttributeWidth(Document $collection): int
11261126
$total += 7;
11271127
break;
11281128

1129-
case Database::TYPE_OBJECT:
1129+
case Database::VAR_OBJECT:
11301130
/**
11311131
* JSONB/JSON type
11321132
* Only the pointer contributes 20 bytes to the row size

src/Database/Database.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Database
4848
public const VAR_UUID7 = 'uuid7';
4949

5050
// object type
51-
public const TYPE_OBJECT = 'object';
51+
public const VAR_OBJECT = 'object';
5252

5353
// Vector types
5454
public const VAR_VECTOR = 'vector';
@@ -74,7 +74,7 @@ class Database
7474
public const INDEX_UNIQUE = 'unique';
7575
public const INDEX_SPATIAL = 'spatial';
7676
// keeping
77-
public const Index_Object = 'object';
77+
public const INDEX_OBJECT = 'object';
7878
public const INDEX_HNSW_EUCLIDEAN = 'hnsw_euclidean';
7979
public const INDEX_HNSW_COSINE = 'hnsw_cosine';
8080
public const INDEX_HNSW_DOT = 'hnsw_dot';
@@ -2016,7 +2016,7 @@ private function validateAttribute(
20162016
case self::VAR_DATETIME:
20172017
case self::VAR_RELATIONSHIP:
20182018
break;
2019-
case self::TYPE_OBJECT:
2019+
case self::VAR_OBJECT:
20202020
if (!$this->adapter->getSupportForObject()) {
20212021
throw new DatabaseException('Object attributes are not supported');
20222022
}
@@ -2135,7 +2135,7 @@ protected function validateDefaultTypes(string $type, mixed $default): void
21352135

21362136
if ($defaultType === 'array') {
21372137
// Spatial types require the array itself
2138-
if (!in_array($type, Database::SPATIAL_TYPES) && $type != Database::TYPE_OBJECT) {
2138+
if (!in_array($type, Database::SPATIAL_TYPES) && $type != Database::VAR_OBJECT) {
21392139
foreach ($default as $value) {
21402140
$this->validateDefaultTypes($type, $value);
21412141
}
@@ -2432,7 +2432,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
24322432
}
24332433
break;
24342434

2435-
case self::TYPE_OBJECT:
2435+
case self::VAR_OBJECT:
24362436
if (!$this->adapter->getSupportForObject()) {
24372437
throw new DatabaseException('Object attributes are not supported');
24382438
}
@@ -2491,7 +2491,7 @@ public function updateAttribute(string $collection, string $id, ?string $type =
24912491
self::VAR_FLOAT,
24922492
self::VAR_BOOLEAN,
24932493
self::VAR_DATETIME,
2494-
self::VAR_RELATIONSHIP . ', ' . self::TYPE_OBJECT
2494+
self::VAR_RELATIONSHIP . ', ' . self::VAR_OBJECT
24952495
];
24962496
if ($this->adapter->getSupportForVectors()) {
24972497
$supportedTypes[] = self::VAR_VECTOR;
@@ -3490,14 +3490,14 @@ public function createIndex(string $collection, string $id, string $type, array
34903490
}
34913491
break;
34923492

3493-
case self::Index_Object:
3493+
case self::INDEX_OBJECT:
34943494
if (!$this->adapter->getSupportForObject()) {
34953495
throw new DatabaseException('Object indexes are not supported');
34963496
}
34973497
break;
34983498

34993499
default:
3500-
throw new DatabaseException('Unknown index type: ' . $type . '. Must be one of ' . Database::INDEX_KEY . ', ' . Database::INDEX_UNIQUE . ', ' . Database::INDEX_FULLTEXT . ', ' . Database::INDEX_SPATIAL . ', ' . Database::Index_Object . ', ' . Database::INDEX_HNSW_EUCLIDEAN . ', ' . Database::INDEX_HNSW_COSINE . ', ' . Database::INDEX_HNSW_DOT);
3500+
throw new DatabaseException('Unknown index type: ' . $type . '. Must be one of ' . Database::INDEX_KEY . ', ' . Database::INDEX_UNIQUE . ', ' . Database::INDEX_FULLTEXT . ', ' . Database::INDEX_SPATIAL . ', ' . Database::INDEX_OBJECT . ', ' . Database::INDEX_HNSW_EUCLIDEAN . ', ' . Database::INDEX_HNSW_COSINE . ', ' . Database::INDEX_HNSW_DOT);
35013501
}
35023502

35033503
/** @var array<Document> $collectionAttributes */
@@ -3529,7 +3529,7 @@ public function createIndex(string $collection, string $id, string $type, array
35293529
}
35303530
}
35313531

3532-
if ($type === self::Index_Object) {
3532+
if ($type === self::INDEX_OBJECT) {
35333533
if (count($attributes) !== 1) {
35343534
throw new IndexException('Object index can be created on a single object attribute');
35353535
}
@@ -3540,7 +3540,7 @@ public function createIndex(string $collection, string $id, string $type, array
35403540
}
35413541

35423542
$attributeType = $indexAttributesWithTypes[$attr];
3543-
if ($attributeType !== self::TYPE_OBJECT) {
3543+
if ($attributeType !== self::VAR_OBJECT) {
35443544
throw new IndexException('Object index can only be created on object attributes. Attribute "' . $attr . '" is of type "' . $attributeType . '"');
35453545
}
35463546
}
@@ -7561,7 +7561,7 @@ public function casting(Document $collection, Document $document): Document
75617561
case self::VAR_FLOAT:
75627562
$node = (float)$node;
75637563
break;
7564-
case self::TYPE_OBJECT:
7564+
case self::VAR_OBJECT:
75657565
// Decode JSONB string to array
75667566
if (is_string($node)) {
75677567
$node = json_decode($node, true);

src/Database/Query.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ public function isSpatialAttribute(): bool
982982
*/
983983
public function isObjectAttribute(): bool
984984
{
985-
return $this->attributeType === Database::TYPE_OBJECT;
985+
return $this->attributeType === Database::VAR_OBJECT;
986986
}
987987

988988
// Spatial query methods

src/Database/Validator/Index.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function __construct(
6464
*/
6565
public function getType(): string
6666
{
67-
return self::TYPE_OBJECT;
67+
return self::VAR_OBJECT;
6868
}
6969

7070
/**
@@ -546,7 +546,7 @@ public function checkObjectIndexes(Document $index): bool
546546
$attributes = $index->getAttribute('attributes', []);
547547
$orders = $index->getAttribute('orders', []);
548548

549-
if ($type !== Database::Index_Object) {
549+
if ($type !== Database::INDEX_OBJECT) {
550550
return true;
551551
}
552552

@@ -569,7 +569,7 @@ public function checkObjectIndexes(Document $index): bool
569569
$attribute = $this->attributes[\strtolower($attributeName)] ?? new Document();
570570
$attributeType = $attribute->getAttribute('type', '');
571571

572-
if ($attributeType !== Database::TYPE_OBJECT) {
572+
if ($attributeType !== Database::VAR_OBJECT) {
573573
$this->message = 'Object index can only be created on object attributes. Attribute "' . $attributeName . '" is of type "' . $attributeType . '"';
574574
return false;
575575
}

src/Database/Validator/IndexDependency.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ public function isArray(): bool
8080
*/
8181
public function getType(): string
8282
{
83-
return self::TYPE_OBJECT;
83+
return self::VAR_OBJECT;
8484
}
8585
}

src/Database/Validator/Queries.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,6 @@ public function isArray(): bool
168168
*/
169169
public function getType(): string
170170
{
171-
return self::TYPE_OBJECT;
171+
return self::VAR_OBJECT;
172172
}
173173
}

src/Database/Validator/Query/Base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function isArray(): bool
4848
*/
4949
public function getType(): string
5050
{
51-
return self::TYPE_OBJECT;
51+
return self::VAR_OBJECT;
5252
}
5353

5454
/**

src/Database/Validator/Query/Filter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ protected function isValidAttributeAndValues(string $attribute, array $values, s
162162
$validator = new Text(255, 0); // The query is always on uid
163163
break;
164164

165-
case Database::TYPE_OBJECT:
165+
case Database::VAR_OBJECT:
166166
// For JSONB/object queries, value must be an array
167167
if (!is_array($value)) {
168168
$this->message = 'Query value for object type must be an array';
@@ -244,7 +244,7 @@ protected function isValidAttributeAndValues(string $attribute, array $values, s
244244
!$array &&
245245
in_array($method, [Query::TYPE_CONTAINS, Query::TYPE_NOT_CONTAINS]) &&
246246
$attributeSchema['type'] !== Database::VAR_STRING &&
247-
$attributeSchema['type'] !== Database::TYPE_OBJECT &&
247+
$attributeSchema['type'] !== Database::VAR_OBJECT &&
248248
!in_array($attributeSchema['type'], Database::SPATIAL_TYPES)
249249
) {
250250
$queryType = $method === Query::TYPE_NOT_CONTAINS ? 'notContains' : 'contains';

src/Database/Validator/Structure.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ protected function checkForInvalidAttributeValues(array $structure, array $keys)
358358
);
359359
break;
360360

361-
case Database::TYPE_OBJECT:
361+
case Database::VAR_OBJECT:
362362
// For JSONB/object types, just validate it's an array (associative or list)
363363
if (!is_array($value)) {
364364
$this->message = 'Attribute "'.$key.'" has invalid type. Value must be an array for object type';

0 commit comments

Comments
 (0)