8 Commits

Author SHA1 Message Date
Sebastian c97618bdd1 chore(deps): update dependency phpunit/phpunit to v12.5.35
JS Unit Tests / test (pull_request) Successful in 55s
Build Test / test (pull_request) Successful in 1m7s
PHP Integration Tests / Integration Tests (pull_request) Failing after 1m48s
PHP Unit Tests / test (pull_request) Successful in 2m41s
2026-09-10 03:04:06 +00:00
Sebastian 4b37be3e7a feat: use resource identifiers
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-09-05 20:12:27 -04:00
Sebastian 26ed0c8aad feat: use resource identifier
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-09-05 20:10:08 -04:00
Sebastian 41de70da75 refactor: use common validation
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-09-05 20:05:08 -04:00
Sebastian e802c8fc0f feat: use ResourceIdentifiers
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-09-05 17:27:55 -04:00
Sebastian 7d18bcab1a feat: node list back end
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-09-04 22:12:27 -04:00
Sebastian 93aa1b0f24 refactor(module): register browser integration through context
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-08-31 22:55:11 -04:00
Sebastian cbcf2e5acb fix(preview): return no content when preview is unavailable
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-08-31 22:55:11 -04:00
16 changed files with 1020 additions and 799 deletions
Generated
+46 -34
View File
@@ -9,20 +9,20 @@
"packages-dev": [ "packages-dev": [
{ {
"name": "myclabs/deep-copy", "name": "myclabs/deep-copy",
"version": "1.13.4", "version": "1.14.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/myclabs/DeepCopy.git", "url": "https://github.com/myclabs/DeepCopy.git",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a" "reference": "8680aa248f8e07bc8fb43f56f0f5fc77a0c96aae"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a", "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/8680aa248f8e07bc8fb43f56f0f5fc77a0c96aae",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a", "reference": "8680aa248f8e07bc8fb43f56f0f5fc77a0c96aae",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.1 || ^8.0" "php": "^8.0"
}, },
"conflict": { "conflict": {
"doctrine/collections": "<1.6.8", "doctrine/collections": "<1.6.8",
@@ -57,15 +57,15 @@
], ],
"support": { "support": {
"issues": "https://github.com/myclabs/DeepCopy/issues", "issues": "https://github.com/myclabs/DeepCopy/issues",
"source": "https://github.com/myclabs/DeepCopy/tree/1.13.4" "source": "https://github.com/myclabs/DeepCopy/tree/1.14.0"
}, },
"funding": [ "funding": [
{ {
"url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", "url": "https://github.com/mnapoli",
"type": "tidelift" "type": "github"
} }
], ],
"time": "2025-08-01T08:46:24+00:00" "time": "2026-08-11T10:17:44+00:00"
}, },
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
@@ -332,23 +332,23 @@
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
"version": "6.0.1", "version": "6.0.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "3d1cd096ef6bea4bf2762ba586e35dbd317cbfd5" "reference": "a248d1640ab059b075f53a2ef0f9856e864e06b5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3d1cd096ef6bea4bf2762ba586e35dbd317cbfd5", "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a248d1640ab059b075f53a2ef0f9856e864e06b5",
"reference": "3d1cd096ef6bea4bf2762ba586e35dbd317cbfd5", "reference": "a248d1640ab059b075f53a2ef0f9856e864e06b5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.3" "php": ">=8.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^12.0" "phpunit/phpunit": "^12.5.33"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@@ -381,7 +381,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
"security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy",
"source": "https://github.com/sebastianbergmann/php-file-iterator/tree/6.0.1" "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/6.0.2"
}, },
"funding": [ "funding": [
{ {
@@ -401,7 +401,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2026-02-02T14:04:18+00:00" "time": "2026-08-25T14:40:53+00:00"
}, },
{ {
"name": "phpunit/php-invoker", "name": "phpunit/php-invoker",
@@ -589,16 +589,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "12.5.31", "version": "12.5.35",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "0608d157a284f15cc73b99a3327eff06b66a176d" "reference": "345ac22e42cb14cdc7aa8428655d8bb8c82a4aab"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0608d157a284f15cc73b99a3327eff06b66a176d", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/345ac22e42cb14cdc7aa8428655d8bb8c82a4aab",
"reference": "0608d157a284f15cc73b99a3327eff06b66a176d", "reference": "345ac22e42cb14cdc7aa8428655d8bb8c82a4aab",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -608,18 +608,18 @@
"ext-libxml": "*", "ext-libxml": "*",
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-xmlwriter": "*", "ext-xmlwriter": "*",
"myclabs/deep-copy": "^1.13.4", "myclabs/deep-copy": "^1.14.0",
"phar-io/manifest": "^2.0.4", "phar-io/manifest": "^2.0.4",
"phar-io/version": "^3.2.1", "phar-io/version": "^3.2.1",
"php": ">=8.3", "php": ">=8.3",
"phpunit/php-code-coverage": "^12.5.7", "phpunit/php-code-coverage": "^12.5.7",
"phpunit/php-file-iterator": "^6.0.1", "phpunit/php-file-iterator": "^6.0.2",
"phpunit/php-invoker": "^6.0.0", "phpunit/php-invoker": "^6.0.0",
"phpunit/php-text-template": "^5.0.0", "phpunit/php-text-template": "^5.0.0",
"phpunit/php-timer": "^8.0.0", "phpunit/php-timer": "^8.0.0",
"sebastian/cli-parser": "^4.2.1", "sebastian/cli-parser": "^4.2.1",
"sebastian/comparator": "^7.1.8", "sebastian/comparator": "^7.1.8",
"sebastian/diff": "^7.0.0", "sebastian/diff": "^7.0.1",
"sebastian/environment": "^8.1.2", "sebastian/environment": "^8.1.2",
"sebastian/exporter": "^7.0.3", "sebastian/exporter": "^7.0.3",
"sebastian/global-state": "^8.0.3", "sebastian/global-state": "^8.0.3",
@@ -667,7 +667,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy", "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.31" "source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.35"
}, },
"funding": [ "funding": [
{ {
@@ -675,7 +675,7 @@
"type": "other" "type": "other"
} }
], ],
"time": "2026-07-06T14:54:16+00:00" "time": "2026-09-09T04:48:50+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",
@@ -898,24 +898,24 @@
}, },
{ {
"name": "sebastian/diff", "name": "sebastian/diff",
"version": "7.0.0", "version": "7.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/diff.git", "url": "https://github.com/sebastianbergmann/diff.git",
"reference": "7ab1ea946c012266ca32390913653d844ecd085f" "reference": "cd4cabe39f8a4e8ee6818ba99f10a05561ea4ad6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7ab1ea946c012266ca32390913653d844ecd085f", "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/cd4cabe39f8a4e8ee6818ba99f10a05561ea4ad6",
"reference": "7ab1ea946c012266ca32390913653d844ecd085f", "reference": "cd4cabe39f8a4e8ee6818ba99f10a05561ea4ad6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.3" "php": ">=8.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^12.0", "phpunit/phpunit": "^12.5.33",
"symfony/process": "^7.2" "symfony/process": "^7.4.17"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@@ -953,15 +953,27 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/diff/issues", "issues": "https://github.com/sebastianbergmann/diff/issues",
"security": "https://github.com/sebastianbergmann/diff/security/policy", "security": "https://github.com/sebastianbergmann/diff/security/policy",
"source": "https://github.com/sebastianbergmann/diff/tree/7.0.0" "source": "https://github.com/sebastianbergmann/diff/tree/7.0.1"
}, },
"funding": [ "funding": [
{ {
"url": "https://github.com/sebastianbergmann", "url": "https://github.com/sebastianbergmann",
"type": "github" "type": "github"
},
{
"url": "https://liberapay.com/sebastianbergmann",
"type": "liberapay"
},
{
"url": "https://thanks.dev/u/gh/sebastianbergmann",
"type": "thanks_dev"
},
{
"url": "https://tidelift.com/funding/github/packagist/sebastian/diff",
"type": "tidelift"
} }
], ],
"time": "2025-02-07T04:55:46+00:00" "time": "2026-08-25T15:35:54+00:00"
}, },
{ {
"name": "sebastian/environment", "name": "sebastian/environment",
@@ -1701,5 +1713,5 @@
"platform-overrides": { "platform-overrides": {
"php": "8.3" "php": "8.3"
}, },
"plugin-api-version": "2.6.0" "plugin-api-version": "2.9.0"
} }
File diff suppressed because it is too large Load Diff
+7 -9
View File
@@ -62,14 +62,14 @@ class TransferController extends ControllerAbstract
/** @var EntityBaseInterface[] $entities */ /** @var EntityBaseInterface[] $entities */
$entities = $this->manager->entityFetchBulk($tenantId, $userId, $target); $entities = $this->manager->entityFetchBulk($tenantId, $userId, $target);
if (empty($entities) || !isset($entities[$identifier])) { if (!isset($entities[(string) $target])) {
return new JsonResponse([ return new JsonResponse([
'status' => 'error', 'status' => 'error',
'error' => ['code' => 404, 'message' => 'File not found'] 'error' => ['code' => 404, 'message' => 'File not found']
], Response::HTTP_NOT_FOUND); ], Response::HTTP_NOT_FOUND);
} }
$entity = $entities[$identifier]; $entity = $entities[(string) $target];
// Get the stream // Get the stream
$stream = $this->manager->entityReadStream($tenantId, $userId, $target); $stream = $this->manager->entityReadStream($tenantId, $userId, $target);
@@ -130,10 +130,7 @@ class TransferController extends ControllerAbstract
$variant, $variant,
); );
if ($preview === null) { if ($preview === null) {
return new JsonResponse([ return new Response('', Response::HTTP_NO_CONTENT);
'status' => 'error',
'error' => ['code' => 404, 'message' => 'Preview unavailable'],
], Response::HTTP_NOT_FOUND);
} }
$response = new StreamedResponse($preview->resource->stream()); $response = new StreamedResponse($preview->resource->stream());
@@ -330,15 +327,16 @@ class TransferController extends ControllerAbstract
foreach ($ids as $id) { foreach ($ids as $id) {
// Try as entity first // Try as entity first
if ($collection !== null) { if ($collection !== null) {
$target = new EntityIdentifier($provider, $service, $collection, (string) $id);
/** @var EntityBaseInterface[] $entities */ /** @var EntityBaseInterface[] $entities */
$entities = $this->manager->entityFetchBulk( $entities = $this->manager->entityFetchBulk(
$tenantId, $tenantId,
$userId, $userId,
new EntityIdentifier($provider, $service, $collection, (string)$id) $target
); );
if (!empty($entities) && isset($entities[$id])) { if (isset($entities[(string) $target])) {
$entity = $entities[$id]; $entity = $entities[(string) $target];
$files[] = [ $files[] = [
'type' => 'file', 'type' => 'file',
'id' => $id, 'id' => $id,
+98 -12
View File
@@ -20,10 +20,12 @@ use KTXF\Documents\Service\ServiceBaseInterface;
use KTXF\Documents\Service\ServiceCollectionMutableInterface; use KTXF\Documents\Service\ServiceCollectionMutableInterface;
use KTXF\Documents\Service\ServiceEntityMutableInterface; use KTXF\Documents\Service\ServiceEntityMutableInterface;
use KTXF\Documents\Service\ServiceMutableInterface; use KTXF\Documents\Service\ServiceMutableInterface;
use KTXF\Documents\Service\ServiceNodeListInterface;
use KTXF\Resource\Filter\IFilter; use KTXF\Resource\Filter\IFilter;
use KTXF\Preview\PreviewSource; use KTXF\Preview\PreviewSource;
use KTXF\Resource\BinaryResource; use KTXF\Resource\BinaryResource;
use KTXF\Resource\Identifier\CollectionIdentifier; use KTXF\Resource\Identifier\CollectionIdentifier;
use KTXF\Resource\Identifier\ServiceIdentifier;
use KTXF\Resource\Identifier\EntityIdentifier; use KTXF\Resource\Identifier\EntityIdentifier;
use KTXF\Resource\Identifier\ResourceIdentifiers; use KTXF\Resource\Identifier\ResourceIdentifiers;
use KTXF\Resource\Provider\ResourceServiceIdentityInterface; use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
@@ -506,18 +508,16 @@ class Manager {
* *
* @param string $tenantId tenant identifier * @param string $tenantId tenant identifier
* @param string $userId user identifier * @param string $userId user identifier
* @param string $provider provider identifier * @param ServiceIdentifier|CollectionIdentifier $target service root or parent collection
* @param string|int $service service identifier
* @param CollectionIdentifier|null $target target parent collection identifier (null for root)
* @param CollectionPropertiesMutableInterface|array $properties properties for the new collection * @param CollectionPropertiesMutableInterface|array $properties properties for the new collection
* @param array $options additional options for creation * @param array $options additional options for creation
* *
* @return CollectionBaseInterface * @return CollectionBaseInterface
* @throws InvalidArgumentException * @throws InvalidArgumentException
*/ */
public function collectionCreate(string $tenantId, string $userId, string $provider, string|int $service, CollectionIdentifier|null $target, CollectionPropertiesMutableInterface|array $properties, array $options = []): CollectionBaseInterface { public function collectionCreate(string $tenantId, string $userId, ServiceIdentifier|CollectionIdentifier $target, CollectionPropertiesMutableInterface|array $properties, array $options = []): CollectionBaseInterface {
// retrieve service // retrieve service
$service = $this->serviceFetch($tenantId, $userId, $provider, $service); $service = $this->serviceFetch($tenantId, $userId, $target->provider(), $target->service());
// Check if service supports collection creation // Check if service supports collection creation
if ($service->getEnabled() === false) { if ($service->getEnabled() === false) {
throw new InvalidArgumentException("Service '{$service->identifier()}' not found or is disabled"); throw new InvalidArgumentException("Service '{$service->identifier()}' not found or is disabled");
@@ -533,7 +533,7 @@ class Manager {
$properties = $service->collectionFresh()->getProperties()->jsonDeserialize($properties); $properties = $service->collectionFresh()->getProperties()->jsonDeserialize($properties);
} }
// Create collection // Create collection
return $service->collectionCreate($target, $properties, $options); return $service->collectionCreate($target instanceof CollectionIdentifier ? $target : null, $properties, $options);
} }
/** /**
@@ -811,21 +811,28 @@ class Manager {
* @return array<string,EntityBaseInterface> * @return array<string,EntityBaseInterface>
*/ */
public function entityFetchBulk(string $tenantId, ?string $userId, EntityIdentifier ...$identifiers): array { public function entityFetchBulk(string $tenantId, ?string $userId, EntityIdentifier ...$identifiers): array {
// group identifiers by provider/service // Keep locations separate: providers may return maps keyed by local ID.
$groupedIdentifiers = []; $groupedIdentifiers = [];
foreach ($identifiers as $identifier) { foreach ($identifiers as $identifier) {
$groupedIdentifiers[$identifier->provider()][$identifier->service()][] = $identifier; $groupedIdentifiers[$identifier->provider()][$identifier->service()][$identifier->collection()][] = $identifier;
} }
// retrieve each service and fetch entities // retrieve each service and fetch entities
$list = []; $list = [];
foreach ($groupedIdentifiers as $providerId => $services) { foreach ($groupedIdentifiers as $providerId => $services) {
foreach ($services as $serviceId => $entities) { foreach ($services as $serviceId => $collections) {
$service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId); $service = $this->serviceFetch($tenantId, $userId, $providerId, $serviceId);
if ($service->getEnabled() === false) { if ($service->getEnabled() === false) {
throw new InvalidArgumentException("Service '{$providerId}:{$serviceId}' not found or is disabled"); throw new InvalidArgumentException("Service '{$providerId}:{$serviceId}' not found or is disabled");
} }
// retrieve entities and merge into list foreach ($collections as $entities) {
$list = array_merge($list, $service->entityFetchBulk(...$entities)); $fetched = $service->entityFetchBulk(...$entities);
foreach ($entities as $identifier) {
$entity = $fetched[(string) $identifier] ?? $fetched[$identifier->entity()] ?? null;
if ($entity !== null) {
$list[(string) $identifier] = $entity;
}
}
}
} }
} }
return $list; return $list;
@@ -1353,7 +1360,7 @@ class Manager {
*/ */
public function entityPreview(string $tenantId, string $userId, EntityIdentifier $target, string $variant = 'inline'): ?Preview { public function entityPreview(string $tenantId, string $userId, EntityIdentifier $target, string $variant = 'inline'): ?Preview {
$entities = $this->entityFetchBulk($tenantId, $userId, $target); $entities = $this->entityFetchBulk($tenantId, $userId, $target);
$entity = $entities[$target->entity()] ?? reset($entities); $entity = $entities[(string) $target] ?? null;
if (!$entity instanceof EntityBaseInterface) { if (!$entity instanceof EntityBaseInterface) {
return null; return null;
} }
@@ -1405,5 +1412,84 @@ class Manager {
return $this->previewManager->fetch($tenantId, $source, $variant); return $this->previewManager->fetch($tenantId, $source, $variant);
} }
/**
* List collections and entities within a location as one unified, paginated set
*
* Folders are ordered before files within the returned range. Unlike
* {@see collectionList} and {@see entityListBulk}, this requires the target
* service to natively implement {@see ServiceNodeListInterface} — there is
* intentionally no fallback for services that only support the separate
* collection/entity listing operations, since every current caller targets a
* single provider/service/location per request.
*
* @since 2026.09.01
*
* @param string $tenantId Tenant identifier
* @param string $userId User identifier
* @param ResourceIdentifiers|null $targets Node sources with collection identifiers
* @param array|null $filter Node filter
* @param array|null $sort Node sort
* @param array|null $range Node range/pagination
*
* @return \Generator<int,CollectionBaseInterface|EntityBaseInterface> Nodes in provider order
*
* @throws InvalidArgumentException If the resolved service does not support unified node listing
*/
public function nodeList(string $tenantId, string $userId, ?ResourceIdentifiers $targets = null, array|null $filter = null, array|null $sort = null, array|null $range = null): \Generator {
// confirm that sources are provided
if ($targets === null) {
$targets = new ResourceIdentifiers([]);
}
// retrieve services for each provider
$aggregateServices = $this->serviceList($tenantId, $userId, $targets);
// retrieve nodes for each service
foreach ($aggregateServices as $services) {
/** @var ServiceBaseInterface $service */
foreach ($services as $service) {
// omit disabled services
if ($service->getEnabled() === false) {
continue;
}
if ($service instanceof ServiceNodeListInterface === false) {
throw new InvalidArgumentException("Service '{$service->identifier()}' does not support paginated node listing");
}
// retrieve collections for each service
$collectionSelected = $targets->byProvider($service->provider())->byService($service->identifier())->collections();
if ($collectionSelected === []) {
// documents are hierarchical: service level selection lists the root collection
$collectionSelected = [''];
}
// construct filter for nodes
$nodeFilter = null;
if ($filter !== null && $filter !== []) {
$nodeFilter = $service->nodeListFilter();
foreach ($filter as $attribute => $value) {
$nodeFilter->condition($attribute, $value);
}
}
// construct sort for nodes
$nodeSort = null;
if ($sort !== null && $sort !== []) {
$nodeSort = $service->nodeListSort();
foreach ($sort as $attribute => $direction) {
$nodeSort->condition($attribute, $direction);
}
}
// construct range for nodes
$nodeRange = null;
if ($range !== null && $range !== [] && isset($range['type'])) {
$nodeRange = $service->nodeListRange(RangeType::from($range['type']))->jsonDeserialize($range);
}
// Preserve provider order without grouping or buffering nodes.
foreach ($collectionSelected as $collectionId) {
$nodes = $service->nodeList($collectionId, $nodeFilter, $nodeSort, $nodeRange);
foreach ($nodes as $node) {
yield $node;
}
}
}
}
}
} }
+8 -12
View File
@@ -2,13 +2,14 @@
namespace KTXM\DocumentsManager; namespace KTXM\DocumentsManager;
use KTXF\Module\ModuleBrowserInterface; use KTXF\Module\Configuration\BrowserModuleContextInterface;
use KTXF\Module\Configuration\ModuleContextInterface;
use KTXF\Module\ModuleInstanceAbstract; use KTXF\Module\ModuleInstanceAbstract;
/** /**
* File Manager Module * File Manager Module
*/ */
class Module extends ModuleInstanceAbstract implements ModuleBrowserInterface class Module extends ModuleInstanceAbstract
{ {
public function __construct() public function __construct()
@@ -50,16 +51,11 @@ class Module extends ModuleInstanceAbstract implements ModuleBrowserInterface
]; ];
} }
public function registerBI(): array { public function configure(ModuleContextInterface $context): void
return [ {
'handle' => $this->handle(), if ($context instanceof BrowserModuleContextInterface) {
'namespace' => 'DocumentsManager', $context->registerModule($this, 'DocumentsManager', 'static/module.mjs');
'version' => $this->version(), }
'label' => $this->label(),
'author' => $this->author(),
'description' => $this->description(),
'boot' => 'static/module.mjs',
];
} }
} }
+71 -27
View File
@@ -8,7 +8,7 @@ import type { Ref, ComputedRef } from 'vue'
import { useProvidersStore } from '@/stores/providersStore' import { useProvidersStore } from '@/stores/providersStore'
import { useServicesStore } from '@/stores/servicesStore' import { useServicesStore } from '@/stores/servicesStore'
import { useNodesStore, ROOT_ID } from '@/stores/nodesStore' import { useNodesStore, ROOT_ID } from '@/stores/nodesStore'
import type { ListFilter, ListSort, ListRange } from '@/types/common' import type { ListFilter, ListSort, ListRange, ServiceIdentifier, CollectionIdentifier } from '@/types/common'
import type { DocumentInterface } from '@/types/document' import type { DocumentInterface } from '@/types/document'
import { CollectionObject } from '@/models/collection' import { CollectionObject } from '@/models/collection'
import { EntityObject } from '@/models/entity' import { EntityObject } from '@/models/entity'
@@ -16,6 +16,9 @@ import { EntityObject } from '@/models/entity'
// Base URL for file manager transfer endpoints // Base URL for file manager transfer endpoints
const TRANSFER_BASE_URL = '/m/documents_manager' const TRANSFER_BASE_URL = '/m/documents_manager'
// Number of collections+entities requested per page
const DEFAULT_PAGE_TALLY = 64
export interface UseDocumentManagerOptions { export interface UseDocumentManagerOptions {
providerId: string | Ref<string> | ComputedRef<string> providerId: string | Ref<string> | ComputedRef<string>
serviceId: string | Ref<string> | ComputedRef<string> serviceId: string | Ref<string> | ComputedRef<string>
@@ -32,6 +35,12 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
const currentProviderId = () => unref(providerId) const currentProviderId = () => unref(providerId)
const currentServiceId = () => unref(serviceId) const currentServiceId = () => unref(serviceId)
const currentSources = (): (ServiceIdentifier | CollectionIdentifier)[] => [
currentLocation.value === ROOT_ID
? `${currentProviderId()}:${currentServiceId()}`
: `${currentProviderId()}:${currentServiceId()}:${currentLocation.value}`,
]
// Current location (folder being viewed) // Current location (folder being viewed)
const currentLocation: Ref<string> = ref(ROOT_ID) const currentLocation: Ref<string> = ref(ROOT_ID)
@@ -39,6 +48,13 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
const isLoading = computed(() => nodesStore.transceiving) const isLoading = computed(() => nodesStore.transceiving)
const error = computed(() => nodesStore.error) const error = computed(() => nodesStore.error)
// Pagination state for the current location + filter + sort
const currentFilter: Ref<ListFilter | undefined> = ref(undefined)
const currentSort: Ref<ListSort | undefined> = ref(undefined)
const loadedCount = ref(0)
const hasMore = ref(false)
const isLoadingMore = ref(false)
// Provider and service // Provider and service
const provider = computed(() => providersStore.provider(currentProviderId())) const provider = computed(() => providersStore.provider(currentProviderId()))
const service = computed(() => servicesStore.service(currentProviderId(), currentServiceId())) const service = computed(() => servicesStore.service(currentProviderId(), currentServiceId()))
@@ -71,7 +87,7 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
// Navigate to a folder // Navigate to a folder
const navigateTo = async (collectionId: string | null) => { const navigateTo = async (collectionId: string | null) => {
currentLocation.value = collectionId || ROOT_ID currentLocation.value = collectionId || ROOT_ID
await refresh() await resetAndLoad(currentFilter.value, currentSort.value)
} }
// Navigate up one level // Navigate up one level
@@ -90,28 +106,55 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
await navigateTo(ROOT_ID) await navigateTo(ROOT_ID)
} }
// Refresh current location // Reset the current location's loaded items and (re)fetch the first page,
const refresh = async ( // optionally with a new filter/sort (e.g. search query or sort field change)
filter?: ListFilter, const resetAndLoad = async (filter?: ListFilter, sort?: ListSort) => {
sort?: ListSort, currentFilter.value = filter
range?: ListRange currentSort.value = sort
) => { loadedCount.value = 0
await nodesStore.fetchNodes( hasMore.value = false
currentProviderId(),
currentServiceId(), const range: ListRange = { type: 'tally', anchor: 'absolute', position: 0, tally: DEFAULT_PAGE_TALLY }
currentLocation.value === ROOT_ID ? ROOT_ID : currentLocation.value, const result = await nodesStore.fetchNodes(
currentSources(),
filter, filter,
sort, sort,
range range,
'reset'
) )
loadedCount.value = result.collections.length + result.entities.length
hasMore.value = !result.isLastPage
}
// Fetch the next page of the current location (infinite scroll "load more")
const loadMore = async () => {
if (!hasMore.value || isLoadingMore.value) {
return
}
isLoadingMore.value = true
try {
const range: ListRange = { type: 'tally', anchor: 'absolute', position: loadedCount.value, tally: DEFAULT_PAGE_TALLY }
const result = await nodesStore.fetchNodes(
currentSources(),
currentFilter.value,
currentSort.value,
range,
'append'
)
loadedCount.value += result.collections.length + result.entities.length
hasMore.value = !result.isLastPage
} finally {
isLoadingMore.value = false
}
} }
// Create a new folder // Create a new folder
const createFolder = async (label: string): Promise<CollectionObject> => { const createFolder = async (label: string): Promise<CollectionObject> => {
return await nodesStore.createCollection( return await nodesStore.createCollection(
currentProviderId(), `${currentProviderId()}:${currentServiceId()}:${currentLocation.value}`,
currentServiceId(),
currentLocation.value === ROOT_ID ? ROOT_ID : currentLocation.value,
{ label, owner: '' } { label, owner: '' }
) )
} }
@@ -132,9 +175,7 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
} }
return await nodesStore.createEntity( return await nodesStore.createEntity(
currentProviderId(), `${currentProviderId()}:${currentServiceId()}:${currentLocation.value}`,
currentServiceId(),
currentLocation.value === ROOT_ID ? ROOT_ID : currentLocation.value,
properties properties
) )
} }
@@ -147,7 +188,7 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
} }
if (node instanceof CollectionObject) { if (node instanceof CollectionObject) {
return await nodesStore.updateCollection(currentProviderId(), currentServiceId(), nodeId, { return await nodesStore.updateCollection(`${node.provider}:${node.service}:${nodeId}`, {
label: newLabel, label: newLabel,
owner: node.properties.owner, owner: node.properties.owner,
}) })
@@ -161,7 +202,7 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
format: node.properties.format, format: node.properties.format,
encoding: node.properties.encoding, encoding: node.properties.encoding,
} }
return await nodesStore.updateEntity(currentProviderId(), currentServiceId(), node.collection, nodeId, properties) return await nodesStore.updateEntity(`${node.provider}:${node.service}:${node.collection || ROOT_ID}:${nodeId}`, properties)
} }
} }
@@ -173,9 +214,9 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
} }
if (node instanceof CollectionObject) { if (node instanceof CollectionObject) {
return await nodesStore.deleteCollection(currentProviderId(), currentServiceId(), nodeId) return await nodesStore.deleteCollection(`${node.provider}:${node.service}:${nodeId}`)
} else { } else {
return await nodesStore.deleteEntity(currentProviderId(), currentServiceId(), node.collection, nodeId) return await nodesStore.deleteEntity(`${node.provider}:${node.service}:${node.collection || ROOT_ID}:${nodeId}`)
} }
} }
@@ -185,7 +226,7 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
if (!node || !(node instanceof EntityObject)) { if (!node || !(node instanceof EntityObject)) {
throw new Error('Entity not found') throw new Error('Entity not found')
} }
return await nodesStore.readEntity(currentProviderId(), currentServiceId(), node.collection || ROOT_ID, entityId) return await nodesStore.readEntity(`${node.provider}:${node.service}:${node.collection || ROOT_ID}:${entityId}`)
} }
// Write file content // Write file content
@@ -194,7 +235,7 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
if (!node || !(node instanceof EntityObject)) { if (!node || !(node instanceof EntityObject)) {
throw new Error('Entity not found') throw new Error('Entity not found')
} }
return await nodesStore.writeEntity(currentProviderId(), currentServiceId(), node.collection, entityId, content) return await nodesStore.writeEntity(`${node.provider}:${node.service}:${node.collection || ROOT_ID}:${entityId}`, content)
} }
// Get a URL suitable for inline viewing (img src / video src) // Get a URL suitable for inline viewing (img src / video src)
@@ -253,7 +294,7 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
await providersStore.list([currentProviderId()]) await providersStore.list([currentProviderId()])
await servicesStore.list() await servicesStore.list()
if (autoFetch) { if (autoFetch) {
await refresh() await resetAndLoad()
} }
} }
@@ -262,6 +303,8 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
currentLocation, currentLocation,
isLoading, isLoading,
error, error,
hasMore,
isLoadingMore,
// Provider/Service // Provider/Service
provider, provider,
@@ -279,7 +322,8 @@ export function useDocumentManager(options: UseDocumentManagerOptions) {
navigateTo, navigateTo,
navigateUp, navigateUp,
navigateToRoot, navigateToRoot,
refresh, resetAndLoad,
loadMore,
// Operations // Operations
createFolder, createFolder,
+6 -29
View File
@@ -25,23 +25,11 @@ import type {
import { useIntegrationStore } from '@KTXC/stores/integrationStore'; import { useIntegrationStore } from '@KTXC/stores/integrationStore';
import { CollectionObject, CollectionPropertiesObject } from '../models/collection'; import { CollectionObject, CollectionPropertiesObject } from '../models/collection';
function isCollectionPayload(value: unknown): value is CollectionInterface {
if (!value || typeof value !== 'object') {
return false;
}
const candidate = value as Record<string, unknown>;
return (
('identifier' in candidate || 'provider' in candidate || 'service' in candidate)
&& 'properties' in candidate
);
}
/** /**
* Helper to create the right collection model class based on provider identifier * Helper to create the right collection model class based on provider identifier
* Uses provider-specific factory if available, otherwise returns base CollectionObject * Uses provider-specific factory if available, otherwise returns base CollectionObject
*/ */
function createCollectionObject(data: CollectionInterface): CollectionObject { export function createCollectionObject(data: CollectionInterface): CollectionObject {
const integrationStore = useIntegrationStore(); const integrationStore = useIntegrationStore();
const factoryItem = integrationStore.getItemById('documents_collection_factory', data.provider) as any; const factoryItem = integrationStore.getItemById('documents_collection_factory', data.provider) as any;
const factory = factoryItem?.factory; const factory = factoryItem?.factory;
@@ -68,19 +56,8 @@ export const collectionService = {
const serviceList: Record<string, Record<string, CollectionObject>> = {}; const serviceList: Record<string, Record<string, CollectionObject>> = {};
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => { Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
const collectionList: Record<string, CollectionObject> = {}; const collectionList: Record<string, CollectionObject> = {};
Object.entries(serviceCollections as Record<string, unknown>).forEach(([collectionId, collectionData]) => { Object.entries(serviceCollections).forEach(([collectionId, collectionData]) => {
if (isCollectionPayload(collectionData)) {
collectionList[collectionId] = createCollectionObject(collectionData); collectionList[collectionId] = createCollectionObject(collectionData);
return;
}
if (collectionData && typeof collectionData === 'object') {
Object.entries(collectionData as Record<string, unknown>).forEach(([nestedCollectionId, nestedCollectionData]) => {
if (isCollectionPayload(nestedCollectionData)) {
collectionList[nestedCollectionId] = createCollectionObject(nestedCollectionData);
}
});
}
}); });
serviceList[serviceId] = collectionList; serviceList[serviceId] = collectionList;
}); });
@@ -91,15 +68,15 @@ export const collectionService = {
}, },
/** /**
* Retrieve a specific collection by provider and identifier * Retrieve collections by resource identifier
* *
* @param request - fetch request parameters * @param request - fetch request parameters
* *
* @returns Promise with collection object * @returns Promise with collections keyed by resource identifier
*/ */
async fetch(request: CollectionFetchRequest): Promise<CollectionObject> { async fetch(request: CollectionFetchRequest): Promise<Record<string, CollectionObject>> {
const response = await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request); const response = await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request);
return createCollectionObject(response); return Object.fromEntries(Object.entries(response).map(([target, data]) => [target, createCollectionObject(data)]));
}, },
/** /**
+1 -1
View File
@@ -35,7 +35,7 @@ import { EntityObject } from '../models';
* Helper to create the right entity model class based on provider identifier * Helper to create the right entity model class based on provider identifier
* Uses provider-specific factory if available, otherwise returns base EntityObject * Uses provider-specific factory if available, otherwise returns base EntityObject
*/ */
function createEntityObject(data: EntityInterface): EntityObject { export function createEntityObject(data: EntityInterface): EntityObject {
const integrationStore = useIntegrationStore(); const integrationStore = useIntegrationStore();
const factoryItem = integrationStore.getItemById('documents_entity_factory', data.provider) as any; const factoryItem = integrationStore.getItemById('documents_entity_factory', data.provider) as any;
const factory = factoryItem?.factory; const factory = factoryItem?.factory;
+34
View File
@@ -0,0 +1,34 @@
import { transceiveStream } from './transceive';
import type { NodeListRequest, NodeInterface } from '../types/node';
import { createCollectionObject } from './collectionService';
import { createEntityObject } from './entityService';
import type { CollectionObject } from '../models/collection';
import type { EntityObject } from '../models/entity';
export type NodeListResult = (CollectionObject | EntityObject)[];
export const nodeService = {
/** Hydrate a mixed page in the exact order returned by the provider. */
async list(request: NodeListRequest = {}): Promise<NodeListResult> {
const nodes: NodeListResult = [];
const { total } = await transceiveStream<NodeListRequest, NodeInterface>('node.list', request, node => {
switch (node['@type']) {
case 'document:collection':
nodes.push(createCollectionObject(node));
break;
case 'document:entity':
nodes.push(createEntityObject(node));
break;
default:
throw new Error('Unsupported node type in node.list response');
}
}, { requireEnd: true });
if (total !== nodes.length) {
throw new Error('Incomplete node.list stream');
}
// Publish only complete pages so a retry uses the same offset after failure.
return nodes;
},
};
export default nodeService;
+7 -1
View File
@@ -62,7 +62,7 @@ export async function transceiveStream<TRequest, TData>(
operation: string, operation: string,
data: TRequest, data: TRequest,
onData: (data: TData) => void, onData: (data: TData) => void,
options?: { user?: string; onStart?: (expected?: number) => void } options?: { user?: string; onStart?: (expected?: number) => void; requireEnd?: boolean }
): Promise<{ total: number }> { ): Promise<{ total: number }> {
const request: ApiRequest<TRequest> = { const request: ApiRequest<TRequest> = {
version: API_VERSION, version: API_VERSION,
@@ -73,6 +73,7 @@ export async function transceiveStream<TRequest, TData>(
}; };
let total = 0; let total = 0;
let ended = false;
const dispatch = (line: string): void => { const dispatch = (line: string): void => {
const message = JSON.parse(line) as ApiStreamResponse<TData>; const message = JSON.parse(line) as ApiStreamResponse<TData>;
@@ -82,6 +83,7 @@ export async function transceiveStream<TRequest, TData>(
options?.onStart?.(message.total); options?.onStart?.(message.total);
} else if (message.status === 'end') { } else if (message.status === 'end') {
total = message.total; total = message.total;
ended = true;
} }
return; return;
} }
@@ -118,6 +120,7 @@ export async function transceiveStream<TRequest, TData>(
} }
} }
buffer += decoder.decode();
if (buffer.trim()) dispatch(buffer); if (buffer.trim()) dispatch(buffer);
} finally { } finally {
reader.releaseLock(); reader.releaseLock();
@@ -125,5 +128,8 @@ export async function transceiveStream<TRequest, TData>(
}, },
}); });
if (options?.requireEnd && !ended) {
throw new Error(`[${operation}] Stream ended without a completion frame`);
}
return { total }; return { total };
} }
+41 -29
View File
@@ -40,25 +40,25 @@ export const useCollectionsStore = defineStore('documentsCollectionsStore', () =
return `${provider}:${service ?? ''}:${identifier ?? ''}` return `${provider}:${service ?? ''}:${identifier ?? ''}`
} }
function collection(provider: string, service: string | number, identifier: string | number, retrieve: boolean = false): CollectionObject | null { function collection(target: CollectionIdentifier, retrieve: boolean = false): CollectionObject | null {
const key = identifierKey(provider, service, identifier) const key = target
if (retrieve === true && !_collections.value[key]) { if (retrieve === true && !_collections.value[key]) {
console.debug(`[Documents Manager][Store] - Force fetching collection "${key}"`) console.debug(`[Documents Manager][Store] - Force fetching collection "${key}"`)
fetch(provider, service, identifier) void fetch([target])
} }
return _collections.value[key] || null return _collections.value[key] || null
} }
function collectionsForService(provider: string, service: string | number): CollectionObject[] { function collectionsForService(target: ServiceIdentifier): CollectionObject[] {
const serviceKeyPrefix = `${provider}:${service}:` const serviceKeyPrefix = `${target}:`
return Object.entries(_collections.value) return Object.entries(_collections.value)
.filter(([key]) => key.startsWith(serviceKeyPrefix)) .filter(([key]) => key.startsWith(serviceKeyPrefix))
.map(([_, collectionObj]) => collectionObj) .map(([_, collectionObj]) => collectionObj)
} }
function clearService(provider: string, service: string | number): void { function clearService(target: ServiceIdentifier): void {
const serviceKeyPrefix = `${provider}:${service}:` const serviceKeyPrefix = `${target}:`
Object.keys(_collections.value) Object.keys(_collections.value)
.filter((key) => key.startsWith(serviceKeyPrefix)) .filter((key) => key.startsWith(serviceKeyPrefix))
.forEach((key) => { .forEach((key) => {
@@ -70,6 +70,27 @@ export const useCollectionsStore = defineStore('documentsCollectionsStore', () =
_collections.value = {} _collections.value = {}
} }
/**
* Merge externally-hydrated collections into the store (used by paginated node fetches)
*/
function mergeMany(collections: CollectionObject[]): void {
const hydrated: Record<string, CollectionObject> = {}
collections.forEach((collectionObj) => {
const key = identifierKey(collectionObj.provider, collectionObj.service, collectionObj.identifier)
hydrated[key] = collectionObj
})
_collections.value = { ..._collections.value, ...hydrated }
}
/**
* Remove specific collections by their own identifiers (used to evict a stale page before a reset)
*/
function removeMany(targets: CollectionIdentifier[]): void {
targets.forEach((target) => {
delete _collections.value[target]
})
}
// Actions // Actions
async function list(sources?: (ServiceIdentifier | CollectionIdentifier)[], filter?: ListFilter, sort?: ListSort): Promise<Record<string, CollectionObject>> { async function list(sources?: (ServiceIdentifier | CollectionIdentifier)[], filter?: ListFilter, sort?: ListSort): Promise<Record<string, CollectionObject>> {
transceiving.value = true transceiving.value = true
@@ -98,14 +119,11 @@ export const useCollectionsStore = defineStore('documentsCollectionsStore', () =
} }
} }
async function fetch(provider: string, service: string | number, identifier: string | number): Promise<CollectionObject> { async function fetch(targets: CollectionIdentifier[]): Promise<Record<string, CollectionObject>> {
transceiving.value = true transceiving.value = true
try { try {
const response = await collectionService.fetch({ targets: [`${provider}:${service}:${identifier}`] }) const response = await collectionService.fetch({ targets })
const key = identifierKey(response.provider, response.service, response.identifier) _collections.value = { ..._collections.value, ...response }
_collections.value[key] = response
console.debug('[Documents Manager][Store] - Successfully fetched collection:', key)
return response return response
} catch (error: any) { } catch (error: any) {
console.error('[Documents Manager][Store] - Failed to fetch collection:', error) console.error('[Documents Manager][Store] - Failed to fetch collection:', error)
@@ -130,17 +148,12 @@ export const useCollectionsStore = defineStore('documentsCollectionsStore', () =
} }
async function create( async function create(
provider: string, target: ServiceIdentifier | CollectionIdentifier,
service: string | number,
collection: string | number | null,
properties: CollectionMutableProperties, properties: CollectionMutableProperties,
): Promise<CollectionObject> { ): Promise<CollectionObject> {
transceiving.value = true transceiving.value = true
try { try {
const target: CollectionIdentifier | undefined = collection !== null && collection !== undefined && collection !== '' const response = await collectionService.create({ target, properties })
? `${provider}:${service}:${collection}`
: undefined
const response = await collectionService.create({ provider, service: String(service), target, properties })
const key = identifierKey(response.provider, response.service, response.identifier) const key = identifierKey(response.provider, response.service, response.identifier)
_collections.value[key] = response _collections.value[key] = response
@@ -155,14 +168,12 @@ export const useCollectionsStore = defineStore('documentsCollectionsStore', () =
} }
async function update( async function update(
provider: string, target: CollectionIdentifier,
service: string | number,
identifier: string | number,
properties: CollectionMutableProperties, properties: CollectionMutableProperties,
): Promise<CollectionObject> { ): Promise<CollectionObject> {
transceiving.value = true transceiving.value = true
try { try {
const response = await collectionService.update({ target: `${provider}:${service}:${identifier}`, properties }) const response = await collectionService.update({ target, properties })
const key = identifierKey(response.provider, response.service, response.identifier) const key = identifierKey(response.provider, response.service, response.identifier)
_collections.value[key] = response _collections.value[key] = response
@@ -176,17 +187,16 @@ export const useCollectionsStore = defineStore('documentsCollectionsStore', () =
} }
} }
async function remove(provider: string, service: string | number, identifier: string | number): Promise<{ success: boolean }> { async function remove(target: CollectionIdentifier): Promise<{ success: boolean }> {
transceiving.value = true transceiving.value = true
try { try {
const response = await collectionService.delete({ target: `${provider}:${service}:${identifier}` }) const response = await collectionService.delete({ target })
const success = response.disposition === 'deleted' || response.disposition === 'moved' const success = response.disposition === 'deleted' || response.disposition === 'moved'
if (success) { if (success) {
const key = identifierKey(provider, service, identifier) delete _collections.value[target]
delete _collections.value[key]
} }
console.debug('[Documents Manager][Store] - Successfully deleted collection:', `${provider}:${service}:${identifier}`) console.debug('[Documents Manager][Store] - Successfully deleted collection:', target)
return { success } return { success }
} catch (error: any) { } catch (error: any) {
console.error('[Documents Manager][Store] - Failed to delete collection:', error) console.error('[Documents Manager][Store] - Failed to delete collection:', error)
@@ -206,6 +216,8 @@ export const useCollectionsStore = defineStore('documentsCollectionsStore', () =
collectionsForService, collectionsForService,
clearService, clearService,
clearAll, clearAll,
mergeMany,
removeMany,
list, list,
fetch, fetch,
extant, extant,
+48 -62
View File
@@ -49,37 +49,34 @@ export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
} }
function entity( function entity(
provider: string, target: EntityIdentifier,
service: string | number,
collection: string | number,
identifier: string | number,
retrieve: boolean = false, retrieve: boolean = false,
): EntityObject | null { ): EntityObject | null {
const key = identifierKey(provider, service, collection, identifier) const key = target
if (retrieve === true && !_entities.value[key]) { if (retrieve === true && !_entities.value[key]) {
console.debug(`[Documents Manager][Store] - Force fetching entity "${key}"`) console.debug(`[Documents Manager][Store] - Force fetching entity "${key}"`)
fetch(provider, service, collection, [identifier]) void fetch([target])
} }
return _entities.value[key] || null return _entities.value[key] || null
} }
function entitiesForService(provider: string, service: string | number): EntityObject[] { function entitiesForService(target: ServiceIdentifier): EntityObject[] {
const serviceKeyPrefix = `${provider}:${service}:` const serviceKeyPrefix = `${target}:`
return Object.entries(_entities.value) return Object.entries(_entities.value)
.filter(([key]) => key.startsWith(serviceKeyPrefix)) .filter(([key]) => key.startsWith(serviceKeyPrefix))
.map(([_, entityObj]) => entityObj) .map(([_, entityObj]) => entityObj)
} }
function entitiesForCollection(provider: string, service: string | number, collection: string | number): EntityObject[] { function entitiesForCollection(target: CollectionIdentifier): EntityObject[] {
const collectionKeyPrefix = `${provider}:${service}:${collection}:` const collectionKeyPrefix = `${target}:`
return Object.entries(_entities.value) return Object.entries(_entities.value)
.filter(([key]) => key.startsWith(collectionKeyPrefix)) .filter(([key]) => key.startsWith(collectionKeyPrefix))
.map(([_, entityObj]) => entityObj) .map(([_, entityObj]) => entityObj)
} }
function clearService(provider: string, service: string | number): void { function clearService(target: ServiceIdentifier): void {
const serviceKeyPrefix = `${provider}:${service}:` const serviceKeyPrefix = `${target}:`
Object.keys(_entities.value) Object.keys(_entities.value)
.filter((key) => key.startsWith(serviceKeyPrefix)) .filter((key) => key.startsWith(serviceKeyPrefix))
.forEach((key) => { .forEach((key) => {
@@ -87,8 +84,8 @@ export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
}) })
} }
function clearCollection(provider: string, service: string | number, collection: string | number): void { function clearCollection(target: CollectionIdentifier): void {
const collectionKeyPrefix = `${provider}:${service}:${collection}:` const collectionKeyPrefix = `${target}:`
Object.keys(_entities.value) Object.keys(_entities.value)
.filter((key) => key.startsWith(collectionKeyPrefix)) .filter((key) => key.startsWith(collectionKeyPrefix))
.forEach((key) => { .forEach((key) => {
@@ -100,6 +97,18 @@ export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
_entities.value = {} _entities.value = {}
} }
/**
* Merge externally-hydrated entities into the store (used by paginated node fetches)
*/
function mergeMany(entities: EntityObject[]): void {
const hydrated: Record<string, EntityObject> = {}
entities.forEach((entityObj) => {
const key = identifierKey(entityObj.provider, entityObj.service, entityObj.collection, entityObj.identifier)
hydrated[key] = entityObj
})
_entities.value = { ..._entities.value, ...hydrated }
}
// Actions // Actions
async function list(sources?: (ServiceIdentifier | CollectionIdentifier)[], filter?: ListFilter, sort?: ListSort, range?: ListRange): Promise<Record<string, EntityObject>> { async function list(sources?: (ServiceIdentifier | CollectionIdentifier)[], filter?: ListFilter, sort?: ListSort, range?: ListRange): Promise<Record<string, EntityObject>> {
transceiving.value = true transceiving.value = true
@@ -131,25 +140,13 @@ export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
} }
async function fetch( async function fetch(
provider: string, targets: EntityIdentifier[],
service: string | number,
collection: string | number,
identifiers: (string | number)[],
): Promise<Record<string, EntityObject>> { ): Promise<Record<string, EntityObject>> {
transceiving.value = true transceiving.value = true
try { try {
const targets: EntityIdentifier[] = identifiers.map((identifier) => `${provider}:${service}:${collection}:${identifier}` as EntityIdentifier)
const response = await entityService.fetch({ targets }) const response = await entityService.fetch({ targets })
_entities.value = { ..._entities.value, ...response }
const hydrated: Record<string, EntityObject> = {} return response
Object.entries(response).forEach(([identifier, entityObj]) => {
const key = identifierKey(provider, service, collection, identifier)
hydrated[key] = entityObj
_entities.value[key] = entityObj
})
console.debug('[Documents Manager][Store] - Successfully fetched', Object.keys(hydrated).length, 'entities')
return hydrated
} catch (error: any) { } catch (error: any) {
console.error('[Documents Manager][Store] - Failed to fetch entities:', error) console.error('[Documents Manager][Store] - Failed to fetch entities:', error)
throw error throw error
@@ -173,15 +170,13 @@ export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
} }
async function create( async function create(
provider: string, target: CollectionIdentifier,
service: string | number,
collection: string | number,
properties: DocumentInterface, properties: DocumentInterface,
options?: Record<string, unknown>, options?: Record<string, unknown>,
): Promise<EntityObject> { ): Promise<EntityObject> {
transceiving.value = true transceiving.value = true
try { try {
const response = await entityService.create({ target: `${provider}:${service}:${collection}`, properties, options }) const response = await entityService.create({ target, properties, options })
const key = identifierKey(response.provider, response.service, response.collection, response.identifier) const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
_entities.value[key] = response _entities.value[key] = response
@@ -196,15 +191,12 @@ export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
} }
async function update( async function update(
provider: string, target: EntityIdentifier,
service: string | number,
collection: string | number,
identifier: string | number,
properties: DocumentInterface, properties: DocumentInterface,
): Promise<EntityObject> { ): Promise<EntityObject> {
transceiving.value = true transceiving.value = true
try { try {
const response = await entityService.update({ target: `${provider}:${service}:${collection}:${identifier}`, properties }) const response = await entityService.update({ target, properties })
const key = identifierKey(response.provider, response.service, response.collection, response.identifier) const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
_entities.value[key] = response _entities.value[key] = response
@@ -219,23 +211,22 @@ export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
} }
async function remove( async function remove(
provider: string, targets: EntityIdentifier[],
service: string | number, ): Promise<{ successes: EntityIdentifier[]; failures: EntityIdentifier[] }> {
collection: string | number,
identifier: string | number,
): Promise<{ success: boolean }> {
transceiving.value = true transceiving.value = true
try { try {
const target: EntityIdentifier = `${provider}:${service}:${collection}:${identifier}` const response = await entityService.delete({ targets })
const response = await entityService.delete({ targets: [target] }) const successes: EntityIdentifier[] = []
const success = response[target]?.disposition === 'deleted' const failures: EntityIdentifier[] = []
if (success) { for (const target of targets) {
const key = identifierKey(provider, service, collection, identifier) if (response[target]?.disposition === 'deleted') {
delete _entities.value[key] delete _entities.value[target]
successes.push(target)
} else {
failures.push(target)
} }
}
console.debug('[Documents Manager][Store] - Successfully deleted entity:', target) return { successes, failures }
return { success }
} catch (error: any) { } catch (error: any) {
console.error('[Documents Manager][Store] - Failed to delete entity:', error) console.error('[Documents Manager][Store] - Failed to delete entity:', error)
throw error throw error
@@ -277,14 +268,11 @@ export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
} }
async function read( async function read(
provider: string, target: EntityIdentifier,
service: string | number,
collection: string | number,
identifier: string | number,
): Promise<string | null> { ): Promise<string | null> {
transceiving.value = true transceiving.value = true
try { try {
const response = await entityService.read({ target: `${provider}:${service}:${collection}:${identifier}` }) const response = await entityService.read({ target })
return response.content return response.content
} catch (error: any) { } catch (error: any) {
console.error('[Documents Manager][Store] - Failed to read entity:', error) console.error('[Documents Manager][Store] - Failed to read entity:', error)
@@ -295,15 +283,12 @@ export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
} }
async function write( async function write(
provider: string, target: EntityIdentifier,
service: string | number,
collection: string | number,
identifier: string | number,
content: string, content: string,
): Promise<number> { ): Promise<number> {
transceiving.value = true transceiving.value = true
try { try {
const response = await entityService.write({ target: `${provider}:${service}:${collection}:${identifier}`, content, encoding: 'base64' }) const response = await entityService.write({ target, content, encoding: 'base64' })
return response.bytesWritten return response.bytesWritten
} catch (error: any) { } catch (error: any) {
console.error('[Documents Manager][Store] - Failed to write entity:', error) console.error('[Documents Manager][Store] - Failed to write entity:', error)
@@ -325,6 +310,7 @@ export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
clearService, clearService,
clearCollection, clearCollection,
clearAll, clearAll,
mergeMany,
list, list,
fetch, fetch,
extant, extant,
+76 -68
View File
@@ -6,6 +6,7 @@ import { computed, ref, readonly } from 'vue'
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import type { import type {
CollectionIdentifier, CollectionIdentifier,
EntityIdentifier,
ServiceIdentifier, ServiceIdentifier,
ListFilter, ListFilter,
ListSort, ListSort,
@@ -16,6 +17,7 @@ import type {
import { CollectionObject, EntityObject } from '../models' import { CollectionObject, EntityObject } from '../models'
import { useCollectionsStore } from './collectionsStore' import { useCollectionsStore } from './collectionsStore'
import { useEntitiesStore } from './entitiesStore' import { useEntitiesStore } from './entitiesStore'
import { nodeService } from '../services/nodeService'
export const ROOT_ID = '00000000-0000-0000-0000-000000000000' export const ROOT_ID = '00000000-0000-0000-0000-000000000000'
@@ -46,8 +48,8 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
function getServiceNodes(providerId: string, serviceId: string | number): NodeRecord[] { function getServiceNodes(providerId: string, serviceId: string | number): NodeRecord[] {
return [ return [
...collectionsStore.collectionsForService(providerId, serviceId), ...collectionsStore.collectionsForService(`${providerId}:${serviceId}`),
...entitiesStore.entitiesForService(providerId, serviceId), ...entitiesStore.entitiesForService(`${providerId}:${serviceId}`),
] ]
} }
@@ -105,20 +107,13 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
async function fetchCollections( async function fetchCollections(
providerId: string, sources?: (ServiceIdentifier | CollectionIdentifier)[],
serviceId: string | number,
collectionId: string | number | null,
filter?: ListFilter, filter?: ListFilter,
sort?: ListSort, sort?: ListSort,
): Promise<CollectionObject[]> { ): Promise<CollectionObject[]> {
error.value = null error.value = null
try { try {
const sources: (ServiceIdentifier | CollectionIdentifier)[] = collectionId === null return Object.values(await collectionsStore.list(sources, filter, sort))
? [`${providerId}:${serviceId}`]
: [`${providerId}:${serviceId}:${collectionId}`]
await collectionsStore.list(sources, filter, sort)
return collectionsStore.collectionsForService(providerId, serviceId)
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to fetch collections' error.value = e instanceof Error ? e.message : 'Failed to fetch collections'
throw e throw e
@@ -126,43 +121,76 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
async function fetchEntities( async function fetchEntities(
providerId: string, sources?: (ServiceIdentifier | CollectionIdentifier)[],
serviceId: string | number,
collectionId: string | number | null,
filter?: ListFilter, filter?: ListFilter,
sort?: ListSort, sort?: ListSort,
range?: ListRange, range?: ListRange,
): Promise<EntityObject[]> { ): Promise<EntityObject[]> {
error.value = null error.value = null
try { try {
const sources: (ServiceIdentifier | CollectionIdentifier)[] = collectionId === null return Object.values(await entitiesStore.list(sources, filter, sort, range))
? [`${providerId}:${serviceId}`]
: [`${providerId}:${serviceId}:${collectionId}`]
await entitiesStore.list(sources, filter, sort, range)
return entitiesStore.entitiesForCollection(providerId, serviceId, collectionId)
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to fetch entities' error.value = e instanceof Error ? e.message : 'Failed to fetch entities'
throw e throw e
} }
} }
/**
* Fetch a unified node listing, optionally limited to a page by range.
*/
async function fetchNodes( async function fetchNodes(
providerId: string, sources?: (ServiceIdentifier | CollectionIdentifier)[],
serviceId: string | number,
parentId: string | number | null = ROOT_ID,
filter?: ListFilter, filter?: ListFilter,
sort?: ListSort, sort?: ListSort,
range?: ListRange, range?: ListRange,
): Promise<NodeRecord[]> { mode: 'reset' | 'append' = 'reset',
): Promise<{ collections: CollectionObject[]; entities: EntityObject[]; isLastPage: boolean }> {
error.value = null error.value = null
try { try {
await Promise.all([ const result = await nodeService.list({ sources, filter, sort, range })
fetchCollections(providerId, serviceId, parentId, filter, sort),
fetchEntities(providerId, serviceId, parentId, filter, sort, range),
])
return getChildren(providerId, serviceId, parentId) // Service selectors list the root; collection selectors list that folder.
// Omitted sources list roots across services, not every cached descendant.
const locations = new Map<string, { provider: string; service: string; parent: string }>()
if (sources?.length) {
for (const source of sources) {
const [provider, service, parent] = source.split(':')
const location = { provider: provider!, service: service!, parent: isRoot(parent) ? ROOT_ID : parent! }
locations.set(`${location.provider}:${location.service}:${location.parent}`, location)
}
} else {
for (const node of [...nodeList.value, ...result]) {
const location = { provider: node.provider, service: String(node.service), parent: ROOT_ID }
locations.set(`${location.provider}:${location.service}:${ROOT_ID}`, location)
}
}
// Replace only the selected locations, and only after the stream succeeds.
if (mode === 'reset') {
for (const { provider, service, parent } of locations.values()) {
const staleIds = getChildCollections(provider, service, parent)
.map((node): CollectionIdentifier => `${node.provider}:${node.service}:${node.identifier}`)
collectionsStore.removeMany(staleIds)
entitiesStore.clearCollection(`${provider}:${service}:${parent}`)
}
}
const pageCollections = result.filter((node): node is CollectionObject => node instanceof CollectionObject)
const pageEntities = result.filter((node): node is EntityObject => node instanceof EntityObject)
collectionsStore.mergeMany(pageCollections)
entitiesStore.mergeMany(pageEntities)
// The backend applies the range independently to each selected location.
const counts = new Map<string, number>()
for (const node of result) {
const parent = isRoot(node.collection) ? ROOT_ID : String(node.collection)
const key = `${node.provider}:${node.service}:${parent}`
counts.set(key, (counts.get(key) ?? 0) + 1)
}
const isLastPage = range === undefined || [...counts.values()].every(count => count < range.tally)
return { collections: pageCollections, entities: pageEntities, isLastPage }
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to fetch nodes' error.value = e instanceof Error ? e.message : 'Failed to fetch nodes'
throw e throw e
@@ -170,14 +198,12 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
async function createCollection( async function createCollection(
providerId: string, target: ServiceIdentifier | CollectionIdentifier,
serviceId: string | number,
parentCollectionId: string | number | null,
properties: CollectionMutableProperties, properties: CollectionMutableProperties,
): Promise<CollectionObject> { ): Promise<CollectionObject> {
error.value = null error.value = null
try { try {
return await collectionsStore.create(providerId, serviceId, parentCollectionId, properties) return await collectionsStore.create(target, properties)
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to create collection' error.value = e instanceof Error ? e.message : 'Failed to create collection'
throw e throw e
@@ -185,14 +211,12 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
async function updateCollection( async function updateCollection(
providerId: string, target: CollectionIdentifier,
serviceId: string | number,
identifier: string | number,
properties: CollectionMutableProperties, properties: CollectionMutableProperties,
): Promise<CollectionObject> { ): Promise<CollectionObject> {
error.value = null error.value = null
try { try {
return await collectionsStore.update(providerId, serviceId, identifier, properties) return await collectionsStore.update(target, properties)
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to update collection' error.value = e instanceof Error ? e.message : 'Failed to update collection'
throw e throw e
@@ -200,13 +224,11 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
async function deleteCollection( async function deleteCollection(
providerId: string, target: CollectionIdentifier,
serviceId: string | number,
identifier: string | number,
): Promise<boolean> { ): Promise<boolean> {
error.value = null error.value = null
try { try {
const response = await collectionsStore.delete(providerId, serviceId, identifier) const response = await collectionsStore.delete(target)
return response.success return response.success
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to delete collection' error.value = e instanceof Error ? e.message : 'Failed to delete collection'
@@ -215,15 +237,13 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
async function createEntity( async function createEntity(
providerId: string, target: CollectionIdentifier,
serviceId: string | number,
collectionId: string | number,
properties: DocumentInterface, properties: DocumentInterface,
options?: Record<string, unknown>, options?: Record<string, unknown>,
): Promise<EntityObject> { ): Promise<EntityObject> {
error.value = null error.value = null
try { try {
return await entitiesStore.create(providerId, serviceId, collectionId, properties, options) return await entitiesStore.create(target, properties, options)
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to create entity' error.value = e instanceof Error ? e.message : 'Failed to create entity'
throw e throw e
@@ -231,15 +251,12 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
async function updateEntity( async function updateEntity(
providerId: string, target: EntityIdentifier,
serviceId: string | number,
collectionId: string | number,
identifier: string | number,
properties: DocumentInterface, properties: DocumentInterface,
): Promise<EntityObject> { ): Promise<EntityObject> {
error.value = null error.value = null
try { try {
return await entitiesStore.update(providerId, serviceId, collectionId, identifier, properties) return await entitiesStore.update(target, properties)
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to update entity' error.value = e instanceof Error ? e.message : 'Failed to update entity'
throw e throw e
@@ -247,15 +264,12 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
async function deleteEntity( async function deleteEntity(
providerId: string, target: EntityIdentifier,
serviceId: string | number,
collectionId: string | number,
identifier: string | number,
): Promise<boolean> { ): Promise<boolean> {
error.value = null error.value = null
try { try {
const response = await entitiesStore.delete(providerId, serviceId, collectionId, identifier) const response = await entitiesStore.delete([target])
return response.success return response.successes.includes(target)
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to delete entity' error.value = e instanceof Error ? e.message : 'Failed to delete entity'
throw e throw e
@@ -263,14 +277,11 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
async function readEntity( async function readEntity(
providerId: string, target: EntityIdentifier,
serviceId: string | number,
collectionId: string | number,
identifier: string | number,
): Promise<string | null> { ): Promise<string | null> {
error.value = null error.value = null
try { try {
return await entitiesStore.read(providerId, serviceId, collectionId, identifier) return await entitiesStore.read(target)
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to read entity' error.value = e instanceof Error ? e.message : 'Failed to read entity'
throw e throw e
@@ -278,15 +289,12 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
async function writeEntity( async function writeEntity(
providerId: string, target: EntityIdentifier,
serviceId: string | number,
collectionId: string | number,
identifier: string | number,
content: string, content: string,
): Promise<number> { ): Promise<number> {
error.value = null error.value = null
try { try {
return await entitiesStore.write(providerId, serviceId, collectionId, identifier, content) return await entitiesStore.write(target, content)
} catch (e) { } catch (e) {
error.value = e instanceof Error ? e.message : 'Failed to write entity' error.value = e instanceof Error ? e.message : 'Failed to write entity'
throw e throw e
@@ -294,8 +302,8 @@ export const useNodesStore = defineStore('documentsNodesStore', () => {
} }
function clearServiceNodes(providerId: string, serviceId: string | number): void { function clearServiceNodes(providerId: string, serviceId: string | number): void {
collectionsStore.clearService(providerId, serviceId) collectionsStore.clearService(`${providerId}:${serviceId}`)
entitiesStore.clearService(providerId, serviceId) entitiesStore.clearService(`${providerId}:${serviceId}`)
} }
function clearNodes(): void { function clearNodes(): void {
+2 -4
View File
@@ -66,7 +66,7 @@ export interface CollectionFetchRequest {
targets: CollectionIdentifier[]; targets: CollectionIdentifier[];
} }
export interface CollectionFetchResponse extends CollectionInterface {} export type CollectionFetchResponse = Record<CollectionIdentifier, CollectionInterface>;
/** /**
* Collection extant * Collection extant
@@ -87,9 +87,7 @@ export interface CollectionExtantResponse {
* Collection create * Collection create
*/ */
export interface CollectionCreateRequest { export interface CollectionCreateRequest {
provider: string; target: ServiceIdentifier | CollectionIdentifier; // Service root or parent collection
service: string | number;
target?: CollectionIdentifier | null; // Parent collection identifier (absent for root)
properties: CollectionMutableProperties; properties: CollectionMutableProperties;
options?: Record<string, unknown>; options?: Record<string, unknown>;
} }
+1
View File
@@ -3,4 +3,5 @@ export type * from './provider';
export type * from './service'; export type * from './service';
export type * from './collection'; export type * from './collection';
export type * from './entity'; export type * from './entity';
export type * from './node';
export type * from './document'; export type * from './document';
+23
View File
@@ -0,0 +1,23 @@
/**
* Node (unified collections + entities) type definitions
*/
import type { CollectionIdentifier, ListFilter, ListRange, ListSort, ServiceIdentifier } from './common';
import type { CollectionInterface } from './collection';
import type { EntityInterface } from './entity';
/**
* Node list
*/
export interface NodeListRequest {
sources?: (ServiceIdentifier | CollectionIdentifier)[];
filter?: ListFilter;
sort?: ListSort;
range?: ListRange;
}
export type NodeInterface =
| (Omit<CollectionInterface, '@type'> & { '@type': 'document:collection' })
| (Omit<EntityInterface, '@type'> & { '@type': 'document:entity' });
/** Payload of each data frame in the node.list NDJSON stream. */
export type NodeListResponse = NodeInterface;