Merge pull request 'refactor: improvemets' (#4) from refactor/improvements into main

Reviewed-on: #4
This commit was merged in pull request #4.
This commit is contained in:
2026-03-24 23:14:54 +00:00
2 changed files with 12 additions and 28 deletions

View File

@@ -720,34 +720,21 @@ class PersonalService implements ServiceBaseInterface, ServiceCollectionMutableI
// Node operations // Node operations
/** public function nodeList(string|int|null $collection = null, bool $recursive = false, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): array {
* @inheritdoc if ($collection === null) {
*/ $collection = self::ROOT_ID;
public function nodeList(string|int|null $location = null, bool $recursive = false, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null): array {
// null location is root
if ($location === null) {
$location = self::ROOT_ID;
} }
return $this->metaStore->nodeList($this->serviceTenantId, $this->serviceUserId, $location, $recursive, $filter, $sort, $range); return $this->metaStore->nodeList($this->serviceTenantId, $this->serviceUserId, $collection, $recursive, $filter, $sort, $range, $properties);
} }
/**
* @inheritdoc
*/
public function nodeListFilter(): IFilter { public function nodeListFilter(): IFilter {
return new Filter($this->serviceAbilities[self::CAPABILITY_COLLECTION_LIST_FILTER] ?? []); return new Filter($this->serviceAbilities[self::CAPABILITY_COLLECTION_LIST_FILTER] ?? []);
} }
/**
* @inheritdoc
*/
public function nodeListSort(): ISort { public function nodeListSort(): ISort {
return new Sort($this->serviceAbilities[self::CAPABILITY_COLLECTION_LIST_SORT] ?? []); return new Sort($this->serviceAbilities[self::CAPABILITY_COLLECTION_LIST_SORT] ?? []);
} }
/**
* @inheritdoc
*/
public function nodeListRange(RangeType $type): IRange { public function nodeListRange(RangeType $type): IRange {
if ($type !== RangeType::TALLY) { if ($type !== RangeType::TALLY) {
throw new InvalidParameterException("Invalid: Node range of type '{$type->value}' is not supported"); throw new InvalidParameterException("Invalid: Node range of type '{$type->value}' is not supported");
@@ -755,11 +742,8 @@ class PersonalService implements ServiceBaseInterface, ServiceCollectionMutableI
return new RangeTally(); return new RangeTally();
} }
/** public function nodeDelta(string|int|null $collection, string $signature, string $detail = 'ids'): Delta {
* @inheritdoc return new Delta();
*/
public function nodeDelta(string|int|null $location, string $signature, bool $recursive = false, string $detail = 'ids'): array {
return $this->metaStore->nodeDelta($this->serviceTenantId, $this->serviceUserId, $location, $signature, $recursive, $detail);
} }
/** /**

View File

@@ -545,14 +545,14 @@ class MetaStore {
// For non-recursive, filter by parent // For non-recursive, filter by parent
if (!$recursive) { if (!$recursive) {
$query['pid'] = $location; $query['cid'] = $location;
} elseif ($location !== null) { } elseif ($location !== null) {
// For recursive with specific location, we need to get all descendants // For recursive with specific location, we need to get all descendants
// This requires getting all collections first and building a list of IDs // This requires getting all collections first and building a list of IDs
$allCollectionIds = $this->getDescendantCollectionIds($tenantId, $userId, $location); $allCollectionIds = $this->getDescendantCollectionIds($tenantId, $userId, $location);
$allCollectionIds[] = $location; $allCollectionIds[] = $location;
$query['$or'] = [ $query['$or'] = [
['pid' => ['$in' => $allCollectionIds]], ['cid' => ['$in' => $allCollectionIds]],
['nid' => ['$in' => $allCollectionIds]], ['nid' => ['$in' => $allCollectionIds]],
]; ];
} }
@@ -578,13 +578,13 @@ class MetaStore {
$cursor = $this->_store->selectCollection($this->_NodeTable)->find($query, $options); $cursor = $this->_store->selectCollection($this->_NodeTable)->find($query, $options);
$list = []; $list = [];
foreach ($cursor as $entry) { foreach ($cursor as $entry) {
$nodeType = $entry['type'] ?? NodeType::Entity->value; $nodeType = $entry['type'];
if ($nodeType === NodeType::Collection->value) { if ($nodeType === NodeType::Collection->value) {
$node = (new NodeCollection())->fromStore($entry); $node = (new CollectionResource())->fromStore($entry);
} else { } else if ($nodeType === NodeType::Entity->value) {
$node = (new EntityResource())->fromStore($entry); $node = (new EntityResource())->fromStore($entry);
} }
$list[$node->id()] = $node; $list[$node->identifier()] = $node;
} }
return $list; return $list;
} }