records and edgs

This commit is contained in:
2024-08-19 17:48:10 +03:00
parent 509d7c13f2
commit c97be8666e
46 changed files with 4790 additions and 1387 deletions
-24
View File
@@ -1,24 +0,0 @@
<?php
namespace Lucent\Schema;
use Lucent\Primitive\Collection;
class BlockSchema implements Schema
{
public Type $type = Type::BLOCK;
/**
* @param Collection<FieldInterface> $fields
*/
function __construct(
public string $name,
public string $label,
public Collection $fields
)
{
}
}
+2 -1
View File
@@ -21,7 +21,8 @@ class CollectionSchema implements Schema
public bool $isEntry = false,
public string $color = "",
public string $sortBy = "-_sys.updatedAt",
public string $titleTemplate = "",
public ?string $cardTitle = null,
public ?string $cardImage = null,
public int $revisions = 0,
public array $read = [],
public array $write = [],
+2 -1
View File
@@ -22,7 +22,8 @@ class FilesSchema implements Schema
public bool $isEntry = false,
public string $sortBy = "-_sys.updatedAt",
public string $color = "",
public string $titleTemplate = "",
public ?string $cardTitle = null,
public ?string $cardImage = null,
public int $revisions = 0,
public array $read = [],
public array $write = [],
+4 -106
View File
@@ -25,7 +25,8 @@ class SchemaService
isEntry: $schemaArr["isEntry"] ?? false,
color: $schemaArr["color"] ?? "",
sortBy: $schemaArr["sortBy"] ?? "-_sys.updatedAt",
titleTemplate: $schemaArr["titleTemplate"] ?? "",
cardTitle: $schemaArr["titleTemplate"] ?? $schemaArr["cardTitle"] ?? null,
cardImage: $schemaArr["cardImage"] ?? null,
revisions: $schemaArr["revisions"] ?? 0,
read: $schemaArr["read"] ?? [],
write: $schemaArr["write"] ?? [],
@@ -39,15 +40,11 @@ class SchemaService
isEntry: $schemaArr["isEntry"] ?? false,
sortBy: $schemaArr["sortBy"] ?? "-_sys.updatedAt",
color: $schemaArr["color"] ?? "",
titleTemplate: $schemaArr["titleTemplate"] ?? "",
cardTitle: $schemaArr["titleTemplate"] ?? $schemaArr["cardTitle"] ?? null,
cardImage: $schemaArr["cardImage"] ?? null,
revisions: $schemaArr["revisions"] ?? 0,
read: $schemaArr["read"] ?? [],
write: $schemaArr["write"] ?? [],
),
"block" => new BlockSchema(
name: $schemaArr["name"],
label: $schemaArr["label"],
fields: (new Collection($schemaArr["fields"]))->map([$this, 'mapBlockFields'])
)
};
@@ -67,103 +64,4 @@ class SchemaService
unset($field["ui"]);
return new $className(...$field);
}
//
// /**
// * @param array<string> $visible
// * @throws LucentException
// */
// public function create(
// string $name,
// string $label,
// string $type,
// bool $isEntry,
// int $revisionRetentionDays,
// int $revisionRetentionNumber,
// int $trashedRetentionDays,
// array $fields,
// string $titleTemplate = "",
// array $visible = [],
// string $path = ""
// ): Schema
// {
// if (empty($name) || empty($label)) {
// throw new LucentException("Name and Label are required");
// }
//
// $newFields = [];
// if (!empty($fields)) {
// $newFields = array_map([Field::class, 'fromArray'], $fields);
// }
//
// $schema = new Schema(
// name: new SchemaName($name),
// label: $label,
// type: Type::from($type),
// visible: new Collection($visible),
// fields: new Collection($newFields),
// isEntry: $isEntry,
// color: "",
// titleTemplate: $titleTemplate,
// views: new Collection(),
// revisionRetentionDays: $revisionRetentionDays,
// revisionRetentionNumber: $revisionRetentionNumber,
// trashedRetentionDays: $trashedRetentionDays,
// path: $path,
// );
//
// $this->schemaRepo->insert($schema);
// return $schema;
//
// }
//
// /**
// * @param array<string> $visible
// * @throws LucentException
// */
// public function update(
// string $name,
// string $label,
// bool $isEntry,
// string $color,
// array $visible,
// string $titleTemplate,
// int $revisionRetentionDays,
// int $revisionRetentionNumber,
// int $trashedRetentionDays,
// string $path = ""
// ): Schema
// {
// if (empty($name) || empty($label)) {
// throw new LucentException("Name and Label are required");
// }
//
//
// $channel = ChannelRepo::current();
// $schema = $channel->schemas->firstWhere("name", $name);
// $schema->label = $label;
// $schema->isEntry = $isEntry;
// $schema->color = $color;
// $schema->visible = new Collection($visible);
// $schema->titleTemplate = $titleTemplate;
// $schema->revisionRetentionDays = $revisionRetentionDays;
// $schema->revisionRetentionNumber = $revisionRetentionNumber;
// $schema->trashedRetentionDays = $trashedRetentionDays;
// $schema->path = $path;
// $this->schemaRepo->update($schema);
// return $schema;
// }
//
// public function delete(string $name): void
// {
// $channel = ChannelRepo::current();
// $schema = $channel->schemas->firstWhere("name", $name);
// if ($schema) {
// $this->schemaRepo->delete($schema);
// }
//
// }
}
+4 -6
View File
@@ -3,7 +3,6 @@
namespace Lucent\Schema\Validator;
use Lucent\Channel\ChannelService;
use Lucent\Edge\EdgeCollection;
use Lucent\Primitive\Collection;
use Lucent\Record\RecordData;
use Lucent\Schema\FieldInterface;
@@ -23,21 +22,20 @@ class Validator
* @return Collection<ValidatorError>
*/
public function check(
string $schemaName,
RecordData $data,
?EdgeCollection $edges,
string $schemaName,
RecordData $data,
): Collection
{
$schema = $this->channelService->getSchema($schemaName)->get();
return $schema->fields
->map(fn(FieldInterface $f) => $this->validate($f, $data, $edges))
->map(fn(FieldInterface $f) => $this->validate($f, $data))
->filter(fn(?ValidatorError $error) => !empty($error))
->values();
}
public function validate(FieldInterface $field, RecordData $recordData, ?EdgeCollection $edges): ?ValidatorError
public function validate(FieldInterface $field, RecordData $recordData): ?ValidatorError
{
$value = $recordData->get($field->name);
if ($field instanceof RequiredInterface && $field->required && $field->failRequired($value)) {