refactor: front end
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "ktxm/file-manager",
|
"name": "ktxm/documents-manager",
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
"platform": {
|
"platform": {
|
||||||
"php": "8.2"
|
"php": "8.2"
|
||||||
},
|
},
|
||||||
"autoloader-suffix": "FileManager",
|
"autoloader-suffix": "DocumentsManager",
|
||||||
"vendor-dir": "lib/vendor"
|
"vendor-dir": "lib/vendor"
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"KTXM\\FileManager\\": "lib/"
|
"KTXM\\DocumentsManager\\": "lib/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -7,20 +7,17 @@ declare(strict_types=1);
|
|||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace KTXM\FileManager\Controllers;
|
namespace KTXM\DocumentsManager\Controllers;
|
||||||
|
|
||||||
use InvalidArgumentException;
|
|
||||||
use KTXC\Http\Response\JsonResponse;
|
use KTXC\Http\Response\JsonResponse;
|
||||||
use KTXC\Http\Response\Response;
|
use KTXC\Http\Response\Response;
|
||||||
use KTXC\Http\Response\StreamedResponse;
|
use KTXC\Http\Response\StreamedResponse;
|
||||||
use KTXC\SessionIdentity;
|
use KTXC\SessionIdentity;
|
||||||
use KTXC\SessionTenant;
|
use KTXC\SessionTenant;
|
||||||
use KTXF\Controller\ControllerAbstract;
|
use KTXF\Controller\ControllerAbstract;
|
||||||
use KTXF\Files\Node\INodeCollectionBase;
|
|
||||||
use KTXF\Files\Node\INodeEntityBase;
|
|
||||||
use KTXF\Routing\Attributes\AuthenticatedRoute;
|
use KTXF\Routing\Attributes\AuthenticatedRoute;
|
||||||
use KTXM\FileManager\Manager;
|
use KTXM\DocumentsManager\Manager;
|
||||||
use KTXM\FileManager\Transfer\StreamingZip;
|
use KTXM\DocumentsManager\Transfer\StreamingZip;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
@@ -39,7 +36,7 @@ class TransferController extends ControllerAbstract
|
|||||||
public function __construct(
|
public function __construct(
|
||||||
private readonly SessionTenant $tenantIdentity,
|
private readonly SessionTenant $tenantIdentity,
|
||||||
private readonly SessionIdentity $userIdentity,
|
private readonly SessionIdentity $userIdentity,
|
||||||
private Manager $fileManager,
|
private readonly Manager $manager,
|
||||||
private readonly LoggerInterface $logger
|
private readonly LoggerInterface $logger
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@@ -50,21 +47,16 @@ class TransferController extends ControllerAbstract
|
|||||||
*/
|
*/
|
||||||
#[AuthenticatedRoute(
|
#[AuthenticatedRoute(
|
||||||
'/download/entity/{provider}/{service}/{collection}/{identifier}',
|
'/download/entity/{provider}/{service}/{collection}/{identifier}',
|
||||||
name: 'filemanager.download.entity',
|
name: 'document_manager.download.entity',
|
||||||
methods: ['GET']
|
methods: ['GET']
|
||||||
)]
|
)]
|
||||||
public function downloadEntity(
|
public function downloadEntity(string $provider, string $service, string $collection, string $identifier): Response {
|
||||||
string $provider,
|
|
||||||
string $service,
|
|
||||||
string $collection,
|
|
||||||
string $identifier
|
|
||||||
): Response {
|
|
||||||
$tenantId = $this->tenantIdentity->identifier();
|
$tenantId = $this->tenantIdentity->identifier();
|
||||||
$userId = $this->userIdentity->identifier();
|
$userId = $this->userIdentity->identifier();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Fetch entity metadata
|
// Fetch entity metadata
|
||||||
$entities = $this->fileManager->entityFetch(
|
$entities = $this->manager->entityFetch(
|
||||||
$tenantId,
|
$tenantId,
|
||||||
$userId,
|
$userId,
|
||||||
$provider,
|
$provider,
|
||||||
@@ -80,11 +72,10 @@ class TransferController extends ControllerAbstract
|
|||||||
], Response::HTTP_NOT_FOUND);
|
], Response::HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var INodeEntityBase $entity */
|
|
||||||
$entity = $entities[$identifier];
|
$entity = $entities[$identifier];
|
||||||
|
|
||||||
// Get the stream
|
// Get the stream
|
||||||
$stream = $this->fileManager->entityReadStream(
|
$stream = $this->manager->entityReadStream(
|
||||||
$tenantId,
|
$tenantId,
|
||||||
$userId,
|
$userId,
|
||||||
$provider,
|
$provider,
|
||||||
@@ -100,22 +91,29 @@ class TransferController extends ControllerAbstract
|
|||||||
], Response::HTTP_NOT_FOUND);
|
], Response::HTTP_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
$filename = $entity->getLabel() ?? 'download';
|
$filename = $entity->getProperties()->getLabel() ?? 'download';
|
||||||
$mime = $entity->getMime() ?? 'application/octet-stream';
|
$mime = $entity->getProperties()->getMime() ?? 'application/octet-stream';
|
||||||
$size = $entity->size();
|
$size = $entity->getProperties()->size();
|
||||||
|
|
||||||
// Create streamed response
|
// Create streamed response
|
||||||
$response = new StreamedResponse(function () use ($stream) {
|
$response = new StreamedResponse(function () use ($stream) {
|
||||||
while (!feof($stream)) {
|
try {
|
||||||
echo fread($stream, 65536);
|
while (!feof($stream)) {
|
||||||
@ob_flush();
|
echo fread($stream, 65536);
|
||||||
flush();
|
@ob_flush();
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
fclose($stream);
|
||||||
}
|
}
|
||||||
fclose($stream);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$response->headers->set('Content-Type', $mime);
|
$response->headers->set('Content-Type', $mime);
|
||||||
$response->headers->set('Content-Length', (string) $size);
|
// Only advertise Content-Length when metadata is non-zero; a zero value
|
||||||
|
// would cause clients to believe the file is empty and discard the body.
|
||||||
|
if ($size > 0) {
|
||||||
|
$response->headers->set('Content-Length', (string) $size);
|
||||||
|
}
|
||||||
$response->headers->set('Content-Disposition',
|
$response->headers->set('Content-Disposition',
|
||||||
$response->headers->makeDisposition('attachment', $filename, $this->asciiFallback($filename))
|
$response->headers->makeDisposition('attachment', $filename, $this->asciiFallback($filename))
|
||||||
);
|
);
|
||||||
@@ -139,16 +137,10 @@ class TransferController extends ControllerAbstract
|
|||||||
*/
|
*/
|
||||||
#[AuthenticatedRoute(
|
#[AuthenticatedRoute(
|
||||||
'/download/archive',
|
'/download/archive',
|
||||||
name: 'filemanager.download.archive',
|
name: 'manager.download.archive',
|
||||||
methods: ['GET']
|
methods: ['GET']
|
||||||
)]
|
)]
|
||||||
public function downloadArchive(
|
public function downloadArchive(string $provider, string $service, array $ids = [], ?string $collection = null, string $name = 'download'): Response {
|
||||||
string $provider,
|
|
||||||
string $service,
|
|
||||||
array $ids = [],
|
|
||||||
string $collection = null,
|
|
||||||
string $name = 'download'
|
|
||||||
): Response {
|
|
||||||
$tenantId = $this->tenantIdentity->identifier();
|
$tenantId = $this->tenantIdentity->identifier();
|
||||||
$userId = $this->userIdentity->identifier();
|
$userId = $this->userIdentity->identifier();
|
||||||
|
|
||||||
@@ -184,7 +176,7 @@ class TransferController extends ControllerAbstract
|
|||||||
$zip = new StreamingZip(null, false); // No compression for speed
|
$zip = new StreamingZip(null, false); // No compression for speed
|
||||||
|
|
||||||
foreach ($files as $file) {
|
foreach ($files as $file) {
|
||||||
$stream = $this->fileManager->entityReadStream(
|
$stream = $this->manager->entityReadStream(
|
||||||
$tenantId,
|
$tenantId,
|
||||||
$userId,
|
$userId,
|
||||||
$provider,
|
$provider,
|
||||||
@@ -194,12 +186,15 @@ class TransferController extends ControllerAbstract
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($stream !== null) {
|
if ($stream !== null) {
|
||||||
$zip->addFileFromStream(
|
try {
|
||||||
$file['path'],
|
$zip->addFileFromStream(
|
||||||
$stream,
|
$file['path'],
|
||||||
$file['modTime'] ?? null
|
$stream,
|
||||||
);
|
$file['modTime'] ?? null
|
||||||
fclose($stream);
|
);
|
||||||
|
} finally {
|
||||||
|
fclose($stream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,20 +226,17 @@ class TransferController extends ControllerAbstract
|
|||||||
*/
|
*/
|
||||||
#[AuthenticatedRoute(
|
#[AuthenticatedRoute(
|
||||||
'/download/collection/{provider}/{service}/{identifier}',
|
'/download/collection/{provider}/{service}/{identifier}',
|
||||||
name: 'filemanager.download.collection',
|
name: 'manager.download.collection',
|
||||||
methods: ['GET']
|
methods: ['GET']
|
||||||
)]
|
)]
|
||||||
public function downloadCollection(
|
public function downloadCollection(string $provider, string $service, string $identifier): Response {
|
||||||
string $provider,
|
|
||||||
string $service,
|
|
||||||
string $identifier
|
|
||||||
): Response {
|
|
||||||
$tenantId = $this->tenantIdentity->identifier();
|
$tenantId = $this->tenantIdentity->identifier();
|
||||||
$userId = $this->userIdentity->identifier();
|
$userId = $this->userIdentity->identifier();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Fetch collection metadata
|
// Fetch collection metadata
|
||||||
$collection = $this->fileManager->collectionFetch(
|
/** @var CollectionBaseInterface|null $collection */
|
||||||
|
$collection = $this->manager->collectionFetch(
|
||||||
$tenantId,
|
$tenantId,
|
||||||
$userId,
|
$userId,
|
||||||
$provider,
|
$provider,
|
||||||
@@ -280,7 +272,7 @@ class TransferController extends ControllerAbstract
|
|||||||
if ($file['type'] === 'directory') {
|
if ($file['type'] === 'directory') {
|
||||||
$zip->addDirectory($file['path'], $file['modTime'] ?? null);
|
$zip->addDirectory($file['path'], $file['modTime'] ?? null);
|
||||||
} else {
|
} else {
|
||||||
$stream = $this->fileManager->entityReadStream(
|
$stream = $this->manager->entityReadStream(
|
||||||
$tenantId,
|
$tenantId,
|
||||||
$userId,
|
$userId,
|
||||||
$provider,
|
$provider,
|
||||||
@@ -290,12 +282,15 @@ class TransferController extends ControllerAbstract
|
|||||||
);
|
);
|
||||||
|
|
||||||
if ($stream !== null) {
|
if ($stream !== null) {
|
||||||
$zip->addFileFromStream(
|
try {
|
||||||
$file['path'],
|
$zip->addFileFromStream(
|
||||||
$stream,
|
$file['path'],
|
||||||
$file['modTime'] ?? null
|
$stream,
|
||||||
);
|
$file['modTime'] ?? null
|
||||||
fclose($stream);
|
);
|
||||||
|
} finally {
|
||||||
|
fclose($stream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -323,20 +318,14 @@ class TransferController extends ControllerAbstract
|
|||||||
/**
|
/**
|
||||||
* Resolve a list of entity/collection IDs into a flat file list for archiving
|
* Resolve a list of entity/collection IDs into a flat file list for archiving
|
||||||
*/
|
*/
|
||||||
private function resolveFilesForArchive(
|
private function resolveFilesForArchive(string $tenantId, string $userId, string $provider, string $service, ?string $collection, array $ids): array {
|
||||||
string $tenantId,
|
|
||||||
string $userId,
|
|
||||||
string $provider,
|
|
||||||
string $service,
|
|
||||||
?string $collection,
|
|
||||||
array $ids
|
|
||||||
): array {
|
|
||||||
$files = [];
|
$files = [];
|
||||||
|
|
||||||
foreach ($ids as $id) {
|
foreach ($ids as $id) {
|
||||||
// Try as entity first
|
// Try as entity first
|
||||||
if ($collection !== null) {
|
if ($collection !== null) {
|
||||||
$entities = $this->fileManager->entityFetch(
|
/** @var EntityBaseInterface[] $entities */
|
||||||
|
$entities = $this->manager->entityFetch(
|
||||||
$tenantId,
|
$tenantId,
|
||||||
$userId,
|
$userId,
|
||||||
$provider,
|
$provider,
|
||||||
@@ -346,7 +335,6 @@ class TransferController extends ControllerAbstract
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($entities) && isset($entities[$id])) {
|
if (!empty($entities) && isset($entities[$id])) {
|
||||||
/** @var INodeEntityBase $entity */
|
|
||||||
$entity = $entities[$id];
|
$entity = $entities[$id];
|
||||||
$files[] = [
|
$files[] = [
|
||||||
'type' => 'file',
|
'type' => 'file',
|
||||||
@@ -360,7 +348,8 @@ class TransferController extends ControllerAbstract
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try as collection (folder)
|
// Try as collection (folder)
|
||||||
$collectionNode = $this->fileManager->collectionFetch(
|
/** @var CollectionBaseInterface|null $collectionNode */
|
||||||
|
$collectionNode = $this->manager->collectionFetch(
|
||||||
$tenantId,
|
$tenantId,
|
||||||
$userId,
|
$userId,
|
||||||
$provider,
|
$provider,
|
||||||
@@ -394,10 +383,21 @@ class TransferController extends ControllerAbstract
|
|||||||
string $provider,
|
string $provider,
|
||||||
string $service,
|
string $service,
|
||||||
string $collectionId,
|
string $collectionId,
|
||||||
string $basePath
|
string $basePath,
|
||||||
|
int $depth = 0,
|
||||||
|
int $maxDepth = 20
|
||||||
): array {
|
): array {
|
||||||
$files = [];
|
$files = [];
|
||||||
|
|
||||||
|
// Guard against runaway recursion on pathologically deep trees
|
||||||
|
if ($depth > $maxDepth) {
|
||||||
|
$this->logger->warning('Max recursion depth reached, skipping deeper contents', [
|
||||||
|
'collection' => $collectionId,
|
||||||
|
'depth' => $depth,
|
||||||
|
]);
|
||||||
|
return $files;
|
||||||
|
}
|
||||||
|
|
||||||
// Add directory entry if we have a path
|
// Add directory entry if we have a path
|
||||||
if ($basePath !== '') {
|
if ($basePath !== '') {
|
||||||
$files[] = [
|
$files[] = [
|
||||||
@@ -410,7 +410,7 @@ class TransferController extends ControllerAbstract
|
|||||||
// Get all nodes in this collection using nodeList with recursive=false
|
// Get all nodes in this collection using nodeList with recursive=false
|
||||||
// We handle recursion ourselves to build proper paths
|
// We handle recursion ourselves to build proper paths
|
||||||
try {
|
try {
|
||||||
$nodes = $this->fileManager->nodeList(
|
$nodes = $this->manager->nodeList(
|
||||||
$tenantId,
|
$tenantId,
|
||||||
$userId,
|
$userId,
|
||||||
$provider,
|
$provider,
|
||||||
@@ -438,7 +438,9 @@ class TransferController extends ControllerAbstract
|
|||||||
$provider,
|
$provider,
|
||||||
$service,
|
$service,
|
||||||
(string) $node->id(),
|
(string) $node->id(),
|
||||||
$nodePath
|
$nodePath,
|
||||||
|
$depth + 1,
|
||||||
|
$maxDepth
|
||||||
);
|
);
|
||||||
$files = array_merge($files, $subFiles);
|
$files = array_merge($files, $subFiles);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
1174
lib/Manager.php
1174
lib/Manager.php
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace KTXM\FileManager;
|
namespace KTXM\DocumentsManager;
|
||||||
|
|
||||||
use KTXF\Module\ModuleBrowserInterface;
|
use KTXF\Module\ModuleBrowserInterface;
|
||||||
use KTXF\Module\ModuleInstanceAbstract;
|
use KTXF\Module\ModuleInstanceAbstract;
|
||||||
@@ -16,12 +16,12 @@ class Module extends ModuleInstanceAbstract implements ModuleBrowserInterface
|
|||||||
|
|
||||||
public function handle(): string
|
public function handle(): string
|
||||||
{
|
{
|
||||||
return 'file_manager';
|
return 'documents_manager';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function label(): string
|
public function label(): string
|
||||||
{
|
{
|
||||||
return 'File Manager';
|
return 'Documents Manager';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function author(): string
|
public function author(): string
|
||||||
@@ -31,7 +31,7 @@ class Module extends ModuleInstanceAbstract implements ModuleBrowserInterface
|
|||||||
|
|
||||||
public function description(): string
|
public function description(): string
|
||||||
{
|
{
|
||||||
return 'File management module for Ktrix - provides file and folder management functionalities';
|
return 'Documents management module for Ktrix - provides document and folder management functionalities';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function version(): string
|
public function version(): string
|
||||||
@@ -42,10 +42,10 @@ class Module extends ModuleInstanceAbstract implements ModuleBrowserInterface
|
|||||||
public function permissions(): array
|
public function permissions(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'file_manager' => [
|
'documents_manager' => [
|
||||||
'label' => 'Access File Manager',
|
'label' => 'Access Documents Manager',
|
||||||
'description' => 'View and access the file manager module',
|
'description' => 'View and access the documents manager module',
|
||||||
'group' => 'File Management'
|
'group' => 'Document Management'
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ class Module extends ModuleInstanceAbstract implements ModuleBrowserInterface
|
|||||||
public function registerBI(): array {
|
public function registerBI(): array {
|
||||||
return [
|
return [
|
||||||
'handle' => $this->handle(),
|
'handle' => $this->handle(),
|
||||||
'namespace' => 'FileManager',
|
'namespace' => 'DocumentsManager',
|
||||||
'version' => $this->version(),
|
'version' => $this->version(),
|
||||||
'label' => $this->label(),
|
'label' => $this->label(),
|
||||||
'author' => $this->author(),
|
'author' => $this->author(),
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ declare(strict_types=1);
|
|||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace KTXM\FileManager\Transfer;
|
namespace KTXM\DocumentsManager\Transfer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Native PHP streaming ZIP archive generator
|
* Native PHP streaming ZIP archive generator
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
/**
|
/**
|
||||||
* File Manager Module Boot Script
|
* Documents Manager Module Boot
|
||||||
*
|
|
||||||
* This script is executed when the file_manager module is loaded.
|
|
||||||
* It initializes the stores which manage file nodes (files and folders) state.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
console.log('[FileManager] Booting File Manager module...')
|
console.log('[Documents Manager] Booting module...')
|
||||||
|
|
||||||
console.log('[FileManager] File Manager module booted successfully')
|
console.log('[Documents Manager] Module booted successfully...')
|
||||||
|
|
||||||
// CSS will be injected by build process
|
// CSS will be injected by build process
|
||||||
//export const css = ['__CSS_FILENAME_PLACEHOLDER__']
|
//export const css = ['__CSS_FILENAME_PLACEHOLDER__']
|
||||||
|
|||||||
@@ -1,95 +1,144 @@
|
|||||||
/**
|
/**
|
||||||
* Class model for FileCollection Interface
|
* Class model for Collection Interface
|
||||||
*/
|
*/
|
||||||
import type { FileCollection } from "@/types/node";
|
|
||||||
|
|
||||||
export class FileCollectionObject implements FileCollection {
|
import type { CollectionContentTypes, CollectionInterface, CollectionModelInterface, CollectionPropertiesInterface } from "@/types/collection";
|
||||||
|
|
||||||
_data!: FileCollection;
|
export class CollectionObject implements CollectionModelInterface {
|
||||||
|
|
||||||
|
_data!: CollectionInterface;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._data = {
|
this._data = {
|
||||||
'@type': 'files.collection',
|
'@type': 'documents:collection',
|
||||||
in: null,
|
schema: 1,
|
||||||
id: '',
|
provider: '',
|
||||||
createdBy: '',
|
service: '',
|
||||||
createdOn: '',
|
collection: null,
|
||||||
modifiedBy: '',
|
identifier: '',
|
||||||
modifiedOn: '',
|
signature: null,
|
||||||
|
created: null,
|
||||||
|
modified: null,
|
||||||
|
properties: new CollectionPropertiesObject(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fromJson(data: CollectionInterface): CollectionObject {
|
||||||
|
this._data = data;
|
||||||
|
if (data.properties) {
|
||||||
|
this._data.properties = new CollectionPropertiesObject().fromJson(data.properties as CollectionPropertiesInterface);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): CollectionInterface {
|
||||||
|
const json = { ...this._data };
|
||||||
|
if (this._data.properties instanceof CollectionPropertiesObject) {
|
||||||
|
json.properties = this._data.properties.toJson();
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
clone(): CollectionObject {
|
||||||
|
const cloned = new CollectionObject();
|
||||||
|
cloned._data = { ...this._data };
|
||||||
|
cloned._data.properties = this.properties.clone();
|
||||||
|
return cloned;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Immutable Properties */
|
||||||
|
|
||||||
|
get schema(): number {
|
||||||
|
return this._data.schema;
|
||||||
|
}
|
||||||
|
|
||||||
|
get provider(): string {
|
||||||
|
return this._data.provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
get service(): string | number {
|
||||||
|
return this._data.service;
|
||||||
|
}
|
||||||
|
|
||||||
|
get collection(): string | number | null {
|
||||||
|
return this._data.collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
get identifier(): string | number {
|
||||||
|
return this._data.identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
get signature(): string | null {
|
||||||
|
return this._data.signature || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get created(): Date | null {
|
||||||
|
return this._data.created ? new Date(this._data.created) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get modified(): Date | null {
|
||||||
|
return this._data.modified ? new Date(this._data.modified) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
get properties(): CollectionPropertiesObject {
|
||||||
|
if (this._data.properties instanceof CollectionPropertiesObject) {
|
||||||
|
return this._data.properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._data.properties) {
|
||||||
|
const hydrated = new CollectionPropertiesObject().fromJson(this._data.properties as CollectionPropertiesInterface);
|
||||||
|
this._data.properties = hydrated;
|
||||||
|
return hydrated;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultProperties = new CollectionPropertiesObject();
|
||||||
|
this._data.properties = defaultProperties;
|
||||||
|
return defaultProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
set properties(value: CollectionPropertiesObject) {
|
||||||
|
if (value instanceof CollectionPropertiesObject) {
|
||||||
|
this._data.properties = value as any;
|
||||||
|
} else {
|
||||||
|
this._data.properties = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CollectionPropertiesObject implements CollectionPropertiesInterface {
|
||||||
|
|
||||||
|
_data!: CollectionPropertiesInterface;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this._data = {
|
||||||
|
content: [],
|
||||||
owner: '',
|
owner: '',
|
||||||
signature: '',
|
|
||||||
label: '',
|
label: '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJson(data: FileCollection): FileCollectionObject {
|
fromJson(data: CollectionPropertiesInterface): CollectionPropertiesObject {
|
||||||
this._data = data;
|
this._data = data;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(): FileCollection {
|
toJson(): CollectionPropertiesInterface {
|
||||||
return this._data;
|
return this._data;
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(): FileCollectionObject {
|
clone(): CollectionPropertiesObject {
|
||||||
const cloned = new FileCollectionObject();
|
const cloned = new CollectionPropertiesObject();
|
||||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
cloned._data = { ...this._data };
|
||||||
return cloned;
|
return cloned;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Properties */
|
/** Immutable Properties */
|
||||||
|
|
||||||
get '@type'(): 'files.collection' {
|
get content(): CollectionContentTypes[] {
|
||||||
return this._data['@type'];
|
return this._data.content || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
get in(): string | null {
|
/** Mutable Properties */
|
||||||
return this._data.in;
|
|
||||||
}
|
|
||||||
|
|
||||||
set in(value: string | null) {
|
|
||||||
this._data.in = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get id(): string {
|
|
||||||
return this._data.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
set id(value: string) {
|
|
||||||
this._data.id = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get createdBy(): string {
|
|
||||||
return this._data.createdBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
set createdBy(value: string) {
|
|
||||||
this._data.createdBy = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get createdOn(): string {
|
|
||||||
return this._data.createdOn;
|
|
||||||
}
|
|
||||||
|
|
||||||
set createdOn(value: string) {
|
|
||||||
this._data.createdOn = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get modifiedBy(): string {
|
|
||||||
return this._data.modifiedBy;
|
|
||||||
}
|
|
||||||
|
|
||||||
set modifiedBy(value: string) {
|
|
||||||
this._data.modifiedBy = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get modifiedOn(): string {
|
|
||||||
return this._data.modifiedOn;
|
|
||||||
}
|
|
||||||
|
|
||||||
set modifiedOn(value: string) {
|
|
||||||
this._data.modifiedOn = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get owner(): string {
|
get owner(): string {
|
||||||
return this._data.owner;
|
return this._data.owner;
|
||||||
@@ -99,34 +148,12 @@ export class FileCollectionObject implements FileCollection {
|
|||||||
this._data.owner = value;
|
this._data.owner = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
get signature(): string {
|
|
||||||
return this._data.signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
set signature(value: string) {
|
|
||||||
this._data.signature = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get label(): string {
|
get label(): string {
|
||||||
return this._data.label;
|
return this._data.label || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
set label(value: string) {
|
set label(value: string) {
|
||||||
this._data.label = value;
|
this._data.label = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Helper methods */
|
}
|
||||||
|
|
||||||
get isRoot(): boolean {
|
|
||||||
return this._data.id === '00000000-0000-0000-0000-000000000000';
|
|
||||||
}
|
|
||||||
|
|
||||||
get createdOnDate(): Date | null {
|
|
||||||
return this._data.createdOn ? new Date(this._data.createdOn) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
get modifiedOnDate(): Date | null {
|
|
||||||
return this._data.modifiedOn ? new Date(this._data.modifiedOn) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
79
src/models/document.ts
Normal file
79
src/models/document.ts
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
import type { DocumentInterface, DocumentModelInterface } from "@/types/document";
|
||||||
|
|
||||||
|
export class DocumentObject implements DocumentModelInterface {
|
||||||
|
|
||||||
|
_data!: DocumentInterface;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this._data = {
|
||||||
|
'@type': 'documents:document',
|
||||||
|
urid: null,
|
||||||
|
size: 0,
|
||||||
|
label: '',
|
||||||
|
mime: null,
|
||||||
|
format: null,
|
||||||
|
encoding: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fromJson(data: DocumentInterface): DocumentObject {
|
||||||
|
this._data = data;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): DocumentInterface {
|
||||||
|
return this._data;
|
||||||
|
}
|
||||||
|
|
||||||
|
clone(): DocumentObject {
|
||||||
|
const cloned = new DocumentObject();
|
||||||
|
cloned._data = { ...this._data };
|
||||||
|
return cloned;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Immutable Properties */
|
||||||
|
|
||||||
|
get urid(): string | null {
|
||||||
|
return this._data.urid;
|
||||||
|
}
|
||||||
|
|
||||||
|
get size(): number {
|
||||||
|
const parsed = typeof this._data.size === 'number' ? this._data.size : Number(this._data.size);
|
||||||
|
return Number.isFinite(parsed) && parsed >= 0 ? parsed : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mutable Properties */
|
||||||
|
|
||||||
|
get label(): string | null {
|
||||||
|
return this._data.label || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
set label(value: string) {
|
||||||
|
this._data.label = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get mime(): string | null {
|
||||||
|
return this._data.mime;
|
||||||
|
}
|
||||||
|
|
||||||
|
set mime(value: string) {
|
||||||
|
this._data.mime = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get format(): string | null {
|
||||||
|
return this._data.format;
|
||||||
|
}
|
||||||
|
|
||||||
|
set format(value: string) {
|
||||||
|
this._data.format = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get encoding(): string | null {
|
||||||
|
return this._data.encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
set encoding(value: string) {
|
||||||
|
this._data.encoding = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,200 +1,104 @@
|
|||||||
/**
|
/**
|
||||||
* Class model for FileEntity Interface
|
* Class model for Entity Interface
|
||||||
*/
|
*/
|
||||||
import type { FileEntity } from "@/types/node";
|
import type { EntityInterface, EntityModelInterface } from "@/types/entity";
|
||||||
|
import type { DocumentInterface, DocumentModelInterface } from "@/types/document";
|
||||||
|
import { DocumentObject } from "./document";
|
||||||
|
|
||||||
export class FileEntityObject implements FileEntity {
|
export class EntityObject implements EntityModelInterface {
|
||||||
|
|
||||||
_data!: FileEntity;
|
_data!: EntityInterface<DocumentInterface|DocumentModelInterface>;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._data = {
|
this._data = {
|
||||||
'@type': 'files.entity',
|
'@type': '',
|
||||||
in: null,
|
schema: 1,
|
||||||
id: '',
|
provider: '',
|
||||||
createdBy: '',
|
service: '',
|
||||||
createdOn: '',
|
collection: '',
|
||||||
modifiedBy: '',
|
identifier: '',
|
||||||
modifiedOn: '',
|
signature: null,
|
||||||
owner: '',
|
created: null,
|
||||||
signature: '',
|
modified: null,
|
||||||
label: '',
|
properties: new DocumentObject(),
|
||||||
size: 0,
|
|
||||||
mime: '',
|
|
||||||
format: '',
|
|
||||||
encoding: '',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJson(data: FileEntity): FileEntityObject {
|
fromJson(data: EntityInterface): EntityObject {
|
||||||
this._data = data;
|
this._data = data
|
||||||
|
if (data.properties) {
|
||||||
|
this._data.properties = new DocumentObject().fromJson(data.properties as DocumentInterface);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(): FileEntity {
|
toJson(): EntityInterface {
|
||||||
return this._data;
|
const json = { ...this._data }
|
||||||
|
if (this._data.properties instanceof DocumentObject) {
|
||||||
|
json.properties = this._data.properties.toJson();
|
||||||
|
}
|
||||||
|
return json as EntityInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(): FileEntityObject {
|
clone(): EntityObject {
|
||||||
const cloned = new FileEntityObject();
|
const cloned = new EntityObject()
|
||||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
cloned._data = { ...this._data }
|
||||||
return cloned;
|
cloned._data.properties = this.properties.clone();
|
||||||
|
return cloned
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Properties */
|
/** Immutable Properties */
|
||||||
|
|
||||||
get '@type'(): 'files.entity' {
|
get provider(): string {
|
||||||
return this._data['@type'];
|
return this._data.provider
|
||||||
}
|
}
|
||||||
|
|
||||||
get in(): string | null {
|
get schema(): number {
|
||||||
return this._data.in;
|
return this._data.schema
|
||||||
}
|
}
|
||||||
|
|
||||||
set in(value: string | null) {
|
get service(): string {
|
||||||
this._data.in = value;
|
return this._data.service
|
||||||
}
|
}
|
||||||
|
|
||||||
get id(): string {
|
get collection(): string | number {
|
||||||
return this._data.id;
|
return this._data.collection
|
||||||
}
|
}
|
||||||
|
|
||||||
set id(value: string) {
|
get identifier(): string | number {
|
||||||
this._data.id = value;
|
return this._data.identifier
|
||||||
}
|
}
|
||||||
|
|
||||||
get createdBy(): string {
|
get signature(): string | null {
|
||||||
return this._data.createdBy;
|
return this._data.signature
|
||||||
}
|
}
|
||||||
|
|
||||||
set createdBy(value: string) {
|
get created(): Date | null {
|
||||||
this._data.createdBy = value;
|
return this._data.created ? new Date(this._data.created) : null
|
||||||
}
|
}
|
||||||
|
|
||||||
get createdOn(): string {
|
get modified(): Date | null {
|
||||||
return this._data.createdOn;
|
return this._data.modified ? new Date(this._data.modified) : null
|
||||||
}
|
}
|
||||||
|
|
||||||
set createdOn(value: string) {
|
get properties(): DocumentObject {
|
||||||
this._data.createdOn = value;
|
if (this._data.properties instanceof DocumentObject) {
|
||||||
|
return this._data.properties
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._data.properties) {
|
||||||
|
const hydrated = new DocumentObject().fromJson(this._data.properties as DocumentInterface)
|
||||||
|
this._data.properties = hydrated
|
||||||
|
return hydrated
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultProperties = new DocumentObject()
|
||||||
|
this._data.properties = defaultProperties
|
||||||
|
return defaultProperties
|
||||||
}
|
}
|
||||||
|
|
||||||
get modifiedBy(): string {
|
set properties(value: DocumentObject) {
|
||||||
return this._data.modifiedBy;
|
this._data.properties = value
|
||||||
}
|
|
||||||
|
|
||||||
set modifiedBy(value: string) {
|
|
||||||
this._data.modifiedBy = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get modifiedOn(): string {
|
|
||||||
return this._data.modifiedOn;
|
|
||||||
}
|
|
||||||
|
|
||||||
set modifiedOn(value: string) {
|
|
||||||
this._data.modifiedOn = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get owner(): string {
|
|
||||||
return this._data.owner;
|
|
||||||
}
|
|
||||||
|
|
||||||
set owner(value: string) {
|
|
||||||
this._data.owner = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get signature(): string {
|
|
||||||
return this._data.signature;
|
|
||||||
}
|
|
||||||
|
|
||||||
set signature(value: string) {
|
|
||||||
this._data.signature = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get label(): string {
|
|
||||||
return this._data.label;
|
|
||||||
}
|
|
||||||
|
|
||||||
set label(value: string) {
|
|
||||||
this._data.label = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get size(): number {
|
|
||||||
return this._data.size;
|
|
||||||
}
|
|
||||||
|
|
||||||
set size(value: number) {
|
|
||||||
this._data.size = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get mime(): string {
|
|
||||||
return this._data.mime;
|
|
||||||
}
|
|
||||||
|
|
||||||
set mime(value: string) {
|
|
||||||
this._data.mime = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get format(): string {
|
|
||||||
return this._data.format;
|
|
||||||
}
|
|
||||||
|
|
||||||
set format(value: string) {
|
|
||||||
this._data.format = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get encoding(): string {
|
|
||||||
return this._data.encoding;
|
|
||||||
}
|
|
||||||
|
|
||||||
set encoding(value: string) {
|
|
||||||
this._data.encoding = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Helper methods */
|
|
||||||
|
|
||||||
get createdOnDate(): Date | null {
|
|
||||||
return this._data.createdOn ? new Date(this._data.createdOn) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
get modifiedOnDate(): Date | null {
|
|
||||||
return this._data.modifiedOn ? new Date(this._data.modifiedOn) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
get extension(): string {
|
|
||||||
const parts = this._data.label.split('.');
|
|
||||||
return parts.length > 1 ? parts[parts.length - 1] : '';
|
|
||||||
}
|
|
||||||
|
|
||||||
get sizeFormatted(): string {
|
|
||||||
const bytes = this._data.size;
|
|
||||||
if (bytes === 0) return '0 B';
|
|
||||||
const k = 1024;
|
|
||||||
const sizes = ['B', 'KB', 'MB', 'GB', 'TB'];
|
|
||||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
get isImage(): boolean {
|
|
||||||
return this._data.mime.startsWith('image/');
|
|
||||||
}
|
|
||||||
|
|
||||||
get isVideo(): boolean {
|
|
||||||
return this._data.mime.startsWith('video/');
|
|
||||||
}
|
|
||||||
|
|
||||||
get isAudio(): boolean {
|
|
||||||
return this._data.mime.startsWith('audio/');
|
|
||||||
}
|
|
||||||
|
|
||||||
get isText(): boolean {
|
|
||||||
return this._data.mime.startsWith('text/') ||
|
|
||||||
this._data.mime === 'application/json' ||
|
|
||||||
this._data.mime === 'application/xml';
|
|
||||||
}
|
|
||||||
|
|
||||||
get isPdf(): boolean {
|
|
||||||
return this._data.mime === 'application/pdf';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
196
src/models/identity.ts
Normal file
196
src/models/identity.ts
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
/**
|
||||||
|
* Identity implementation classes for Mail Manager services
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type {
|
||||||
|
ServiceIdentity,
|
||||||
|
ServiceIdentityNone,
|
||||||
|
ServiceIdentityBasic,
|
||||||
|
ServiceIdentityToken,
|
||||||
|
ServiceIdentityOAuth,
|
||||||
|
ServiceIdentityCertificate
|
||||||
|
} from '@/types/service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base Identity class
|
||||||
|
*/
|
||||||
|
export abstract class Identity {
|
||||||
|
abstract toJson(): ServiceIdentity;
|
||||||
|
|
||||||
|
static fromJson(data: ServiceIdentity): Identity {
|
||||||
|
switch (data.type) {
|
||||||
|
case 'NA':
|
||||||
|
return IdentityNone.fromJson(data);
|
||||||
|
case 'BA':
|
||||||
|
return IdentityBasic.fromJson(data);
|
||||||
|
case 'TA':
|
||||||
|
return IdentityToken.fromJson(data);
|
||||||
|
case 'OA':
|
||||||
|
return IdentityOAuth.fromJson(data);
|
||||||
|
case 'CC':
|
||||||
|
return IdentityCertificate.fromJson(data);
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown identity type: ${(data as any).type}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No authentication
|
||||||
|
*/
|
||||||
|
export class IdentityNone extends Identity {
|
||||||
|
readonly type = 'NA' as const;
|
||||||
|
|
||||||
|
static fromJson(_data: ServiceIdentityNone): IdentityNone {
|
||||||
|
return new IdentityNone();
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): ServiceIdentityNone {
|
||||||
|
return {
|
||||||
|
type: this.type
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Basic authentication (username/password)
|
||||||
|
*/
|
||||||
|
export class IdentityBasic extends Identity {
|
||||||
|
readonly type = 'BA' as const;
|
||||||
|
identity: string;
|
||||||
|
secret: string;
|
||||||
|
|
||||||
|
constructor(identity: string = '', secret: string = '') {
|
||||||
|
super();
|
||||||
|
this.identity = identity;
|
||||||
|
this.secret = secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(data: ServiceIdentityBasic): IdentityBasic {
|
||||||
|
return new IdentityBasic(data.identity, data.secret);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): ServiceIdentityBasic {
|
||||||
|
return {
|
||||||
|
type: this.type,
|
||||||
|
identity: this.identity,
|
||||||
|
secret: this.secret
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token authentication (API key, static token)
|
||||||
|
*/
|
||||||
|
export class IdentityToken extends Identity {
|
||||||
|
readonly type = 'TA' as const;
|
||||||
|
token: string;
|
||||||
|
|
||||||
|
constructor(token: string = '') {
|
||||||
|
super();
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(data: ServiceIdentityToken): IdentityToken {
|
||||||
|
return new IdentityToken(data.token);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): ServiceIdentityToken {
|
||||||
|
return {
|
||||||
|
type: this.type,
|
||||||
|
token: this.token
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OAuth authentication
|
||||||
|
*/
|
||||||
|
export class IdentityOAuth extends Identity {
|
||||||
|
readonly type = 'OA' as const;
|
||||||
|
accessToken: string;
|
||||||
|
accessScope?: string[];
|
||||||
|
accessExpiry?: number;
|
||||||
|
refreshToken?: string;
|
||||||
|
refreshLocation?: string;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
accessToken: string = '',
|
||||||
|
accessScope?: string[],
|
||||||
|
accessExpiry?: number,
|
||||||
|
refreshToken?: string,
|
||||||
|
refreshLocation?: string
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
this.accessScope = accessScope;
|
||||||
|
this.accessExpiry = accessExpiry;
|
||||||
|
this.refreshToken = refreshToken;
|
||||||
|
this.refreshLocation = refreshLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(data: ServiceIdentityOAuth): IdentityOAuth {
|
||||||
|
return new IdentityOAuth(
|
||||||
|
data.accessToken,
|
||||||
|
data.accessScope,
|
||||||
|
data.accessExpiry,
|
||||||
|
data.refreshToken,
|
||||||
|
data.refreshLocation
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): ServiceIdentityOAuth {
|
||||||
|
return {
|
||||||
|
type: this.type,
|
||||||
|
accessToken: this.accessToken,
|
||||||
|
...(this.accessScope && { accessScope: this.accessScope }),
|
||||||
|
...(this.accessExpiry && { accessExpiry: this.accessExpiry }),
|
||||||
|
...(this.refreshToken && { refreshToken: this.refreshToken }),
|
||||||
|
...(this.refreshLocation && { refreshLocation: this.refreshLocation })
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
isExpired(): boolean {
|
||||||
|
if (!this.accessExpiry) return false;
|
||||||
|
return Date.now() / 1000 >= this.accessExpiry;
|
||||||
|
}
|
||||||
|
|
||||||
|
expiresIn(): number {
|
||||||
|
if (!this.accessExpiry) return Infinity;
|
||||||
|
return Math.max(0, this.accessExpiry - Date.now() / 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client certificate authentication (mTLS)
|
||||||
|
*/
|
||||||
|
export class IdentityCertificate extends Identity {
|
||||||
|
readonly type = 'CC' as const;
|
||||||
|
certificate: string;
|
||||||
|
privateKey: string;
|
||||||
|
passphrase?: string;
|
||||||
|
|
||||||
|
constructor(certificate: string = '', privateKey: string = '', passphrase?: string) {
|
||||||
|
super();
|
||||||
|
this.certificate = certificate;
|
||||||
|
this.privateKey = privateKey;
|
||||||
|
this.passphrase = passphrase;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(data: ServiceIdentityCertificate): IdentityCertificate {
|
||||||
|
return new IdentityCertificate(
|
||||||
|
data.certificate,
|
||||||
|
data.privateKey,
|
||||||
|
data.passphrase
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): ServiceIdentityCertificate {
|
||||||
|
return {
|
||||||
|
type: this.type,
|
||||||
|
certificate: this.certificate,
|
||||||
|
privateKey: this.privateKey,
|
||||||
|
...(this.passphrase && { passphrase: this.passphrase })
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,4 @@
|
|||||||
/**
|
export { CollectionObject } from './collection';
|
||||||
* Central export point for all File Manager models
|
export { EntityObject } from './entity';
|
||||||
*/
|
|
||||||
|
|
||||||
export { FileCollectionObject } from './collection';
|
|
||||||
export { FileEntityObject } from './entity';
|
|
||||||
export { ProviderObject } from './provider';
|
export { ProviderObject } from './provider';
|
||||||
export { ServiceObject } from './service';
|
export { ServiceObject } from './service';
|
||||||
|
|||||||
240
src/models/location.ts
Normal file
240
src/models/location.ts
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
/**
|
||||||
|
* Location implementation classes for Mail Manager services
|
||||||
|
*/
|
||||||
|
|
||||||
|
import type {
|
||||||
|
ServiceLocation,
|
||||||
|
ServiceLocationUri,
|
||||||
|
ServiceLocationSocketSole,
|
||||||
|
ServiceLocationSocketSplit,
|
||||||
|
ServiceLocationFile
|
||||||
|
} from '@/types/service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base Location class
|
||||||
|
*/
|
||||||
|
export abstract class Location {
|
||||||
|
abstract toJson(): ServiceLocation;
|
||||||
|
|
||||||
|
static fromJson(data: ServiceLocation): Location {
|
||||||
|
switch (data.type) {
|
||||||
|
case 'URI':
|
||||||
|
return LocationUri.fromJson(data);
|
||||||
|
case 'SOCKET_SOLE':
|
||||||
|
return LocationSocketSole.fromJson(data);
|
||||||
|
case 'SOCKET_SPLIT':
|
||||||
|
return LocationSocketSplit.fromJson(data);
|
||||||
|
case 'FILE':
|
||||||
|
return LocationFile.fromJson(data);
|
||||||
|
default:
|
||||||
|
throw new Error(`Unknown location type: ${(data as any).type}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* URI-based service location for API and web services
|
||||||
|
* Used by: JMAP, Gmail API, etc.
|
||||||
|
*/
|
||||||
|
export class LocationUri extends Location {
|
||||||
|
readonly type = 'URI' as const;
|
||||||
|
scheme: string;
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
path?: string;
|
||||||
|
verifyPeer: boolean;
|
||||||
|
verifyHost: boolean;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
scheme: string = 'https',
|
||||||
|
host: string = '',
|
||||||
|
port: number = 443,
|
||||||
|
path?: string,
|
||||||
|
verifyPeer: boolean = true,
|
||||||
|
verifyHost: boolean = true
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
this.scheme = scheme;
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
this.path = path;
|
||||||
|
this.verifyPeer = verifyPeer;
|
||||||
|
this.verifyHost = verifyHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(data: ServiceLocationUri): LocationUri {
|
||||||
|
return new LocationUri(
|
||||||
|
data.scheme,
|
||||||
|
data.host,
|
||||||
|
data.port,
|
||||||
|
data.path,
|
||||||
|
data.verifyPeer ?? true,
|
||||||
|
data.verifyHost ?? true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): ServiceLocationUri {
|
||||||
|
return {
|
||||||
|
type: this.type,
|
||||||
|
scheme: this.scheme,
|
||||||
|
host: this.host,
|
||||||
|
port: this.port,
|
||||||
|
...(this.path && { path: this.path }),
|
||||||
|
...(this.verifyPeer !== undefined && { verifyPeer: this.verifyPeer }),
|
||||||
|
...(this.verifyHost !== undefined && { verifyHost: this.verifyHost })
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
getUrl(): string {
|
||||||
|
const path = this.path || '';
|
||||||
|
return `${this.scheme}://${this.host}:${this.port}${path}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Single socket-based service location
|
||||||
|
* Used by: services using a single host/port combination
|
||||||
|
*/
|
||||||
|
export class LocationSocketSole extends Location {
|
||||||
|
readonly type = 'SOCKET_SOLE' as const;
|
||||||
|
host: string;
|
||||||
|
port: number;
|
||||||
|
encryption: 'none' | 'ssl' | 'tls' | 'starttls';
|
||||||
|
verifyPeer: boolean;
|
||||||
|
verifyHost: boolean;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
host: string = '',
|
||||||
|
port: number = 993,
|
||||||
|
encryption: 'none' | 'ssl' | 'tls' | 'starttls' = 'ssl',
|
||||||
|
verifyPeer: boolean = true,
|
||||||
|
verifyHost: boolean = true
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
this.encryption = encryption;
|
||||||
|
this.verifyPeer = verifyPeer;
|
||||||
|
this.verifyHost = verifyHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(data: ServiceLocationSocketSole): LocationSocketSole {
|
||||||
|
return new LocationSocketSole(
|
||||||
|
data.host,
|
||||||
|
data.port,
|
||||||
|
data.encryption,
|
||||||
|
data.verifyPeer ?? true,
|
||||||
|
data.verifyHost ?? true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): ServiceLocationSocketSole {
|
||||||
|
return {
|
||||||
|
type: this.type,
|
||||||
|
host: this.host,
|
||||||
|
port: this.port,
|
||||||
|
encryption: this.encryption,
|
||||||
|
...(this.verifyPeer !== undefined && { verifyPeer: this.verifyPeer }),
|
||||||
|
...(this.verifyHost !== undefined && { verifyHost: this.verifyHost })
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Split socket-based service location
|
||||||
|
* Used by: traditional IMAP/SMTP configurations
|
||||||
|
*/
|
||||||
|
export class LocationSocketSplit extends Location {
|
||||||
|
readonly type = 'SOCKET_SPLIT' as const;
|
||||||
|
inboundHost: string;
|
||||||
|
inboundPort: number;
|
||||||
|
inboundEncryption: 'none' | 'ssl' | 'tls' | 'starttls';
|
||||||
|
outboundHost: string;
|
||||||
|
outboundPort: number;
|
||||||
|
outboundEncryption: 'none' | 'ssl' | 'tls' | 'starttls';
|
||||||
|
inboundVerifyPeer: boolean;
|
||||||
|
inboundVerifyHost: boolean;
|
||||||
|
outboundVerifyPeer: boolean;
|
||||||
|
outboundVerifyHost: boolean;
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
inboundHost: string = '',
|
||||||
|
inboundPort: number = 993,
|
||||||
|
inboundEncryption: 'none' | 'ssl' | 'tls' | 'starttls' = 'ssl',
|
||||||
|
outboundHost: string = '',
|
||||||
|
outboundPort: number = 465,
|
||||||
|
outboundEncryption: 'none' | 'ssl' | 'tls' | 'starttls' = 'ssl',
|
||||||
|
inboundVerifyPeer: boolean = true,
|
||||||
|
inboundVerifyHost: boolean = true,
|
||||||
|
outboundVerifyPeer: boolean = true,
|
||||||
|
outboundVerifyHost: boolean = true
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
this.inboundHost = inboundHost;
|
||||||
|
this.inboundPort = inboundPort;
|
||||||
|
this.inboundEncryption = inboundEncryption;
|
||||||
|
this.outboundHost = outboundHost;
|
||||||
|
this.outboundPort = outboundPort;
|
||||||
|
this.outboundEncryption = outboundEncryption;
|
||||||
|
this.inboundVerifyPeer = inboundVerifyPeer;
|
||||||
|
this.inboundVerifyHost = inboundVerifyHost;
|
||||||
|
this.outboundVerifyPeer = outboundVerifyPeer;
|
||||||
|
this.outboundVerifyHost = outboundVerifyHost;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(data: ServiceLocationSocketSplit): LocationSocketSplit {
|
||||||
|
return new LocationSocketSplit(
|
||||||
|
data.inboundHost,
|
||||||
|
data.inboundPort,
|
||||||
|
data.inboundEncryption,
|
||||||
|
data.outboundHost,
|
||||||
|
data.outboundPort,
|
||||||
|
data.outboundEncryption,
|
||||||
|
data.inboundVerifyPeer ?? true,
|
||||||
|
data.inboundVerifyHost ?? true,
|
||||||
|
data.outboundVerifyPeer ?? true,
|
||||||
|
data.outboundVerifyHost ?? true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): ServiceLocationSocketSplit {
|
||||||
|
return {
|
||||||
|
type: this.type,
|
||||||
|
inboundHost: this.inboundHost,
|
||||||
|
inboundPort: this.inboundPort,
|
||||||
|
inboundEncryption: this.inboundEncryption,
|
||||||
|
outboundHost: this.outboundHost,
|
||||||
|
outboundPort: this.outboundPort,
|
||||||
|
outboundEncryption: this.outboundEncryption,
|
||||||
|
...(this.inboundVerifyPeer !== undefined && { inboundVerifyPeer: this.inboundVerifyPeer }),
|
||||||
|
...(this.inboundVerifyHost !== undefined && { inboundVerifyHost: this.inboundVerifyHost }),
|
||||||
|
...(this.outboundVerifyPeer !== undefined && { outboundVerifyPeer: this.outboundVerifyPeer }),
|
||||||
|
...(this.outboundVerifyHost !== undefined && { outboundVerifyHost: this.outboundVerifyHost })
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File-based service location
|
||||||
|
* Used by: local file system providers
|
||||||
|
*/
|
||||||
|
export class LocationFile extends Location {
|
||||||
|
readonly type = 'FILE' as const;
|
||||||
|
path: string;
|
||||||
|
|
||||||
|
constructor(path: string = '') {
|
||||||
|
super();
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(data: ServiceLocationFile): LocationFile {
|
||||||
|
return new LocationFile(data.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): ServiceLocationFile {
|
||||||
|
return {
|
||||||
|
type: this.type,
|
||||||
|
path: this.path
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
* Class model for Provider Interface
|
* Class model for Provider Interface
|
||||||
*/
|
*/
|
||||||
import type { ProviderCapabilitiesInterface, ProviderInterface } from "@/types/provider";
|
|
||||||
|
import type {
|
||||||
|
ProviderInterface,
|
||||||
|
ProviderCapabilitiesInterface
|
||||||
|
} from "@/types/provider";
|
||||||
|
|
||||||
export class ProviderObject implements ProviderInterface {
|
export class ProviderObject implements ProviderInterface {
|
||||||
|
|
||||||
@@ -9,8 +13,8 @@ export class ProviderObject implements ProviderInterface {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._data = {
|
this._data = {
|
||||||
'@type': 'files:provider',
|
'@type': 'documents:provider',
|
||||||
id: '',
|
identifier: '',
|
||||||
label: '',
|
label: '',
|
||||||
capabilities: {},
|
capabilities: {},
|
||||||
};
|
};
|
||||||
@@ -25,21 +29,16 @@ export class ProviderObject implements ProviderInterface {
|
|||||||
return this._data;
|
return this._data;
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(): ProviderObject {
|
capable(capability: keyof ProviderCapabilitiesInterface): boolean {
|
||||||
const cloned = new ProviderObject();
|
const value = this._data.capabilities?.[capability];
|
||||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
return value !== undefined && value !== false;
|
||||||
return cloned;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
capable(capability: keyof ProviderCapabilitiesInterface): boolean {
|
capability(capability: keyof ProviderCapabilitiesInterface): any | null {
|
||||||
return !!(this._data.capabilities && this._data.capabilities[capability]);
|
|
||||||
}
|
|
||||||
|
|
||||||
capability(capability: keyof ProviderCapabilitiesInterface): boolean | string[] | Record<string, string> | Record<string, string[]> | undefined {
|
|
||||||
if (this._data.capabilities) {
|
if (this._data.capabilities) {
|
||||||
return this._data.capabilities[capability];
|
return this._data.capabilities[capability];
|
||||||
}
|
}
|
||||||
return undefined;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Immutable Properties */
|
/** Immutable Properties */
|
||||||
@@ -48,8 +47,8 @@ export class ProviderObject implements ProviderInterface {
|
|||||||
return this._data['@type'];
|
return this._data['@type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
get id(): string {
|
get identifier(): string {
|
||||||
return this._data.id;
|
return this._data.identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
get label(): string {
|
get label(): string {
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* Class model for Service Interface
|
* Class model for Service Interface
|
||||||
*/
|
*/
|
||||||
import type { ServiceInterface } from "@/types/service";
|
|
||||||
|
import type {
|
||||||
|
ServiceInterface,
|
||||||
|
ServiceCapabilitiesInterface,
|
||||||
|
ServiceIdentity,
|
||||||
|
ServiceLocation
|
||||||
|
} from "@/types/service";
|
||||||
|
import { Identity } from './identity';
|
||||||
|
import { Location } from './location';
|
||||||
|
|
||||||
export class ServiceObject implements ServiceInterface {
|
export class ServiceObject implements ServiceInterface {
|
||||||
|
|
||||||
@@ -9,11 +17,12 @@ export class ServiceObject implements ServiceInterface {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._data = {
|
this._data = {
|
||||||
'@type': 'files:service',
|
'@type': 'documents:service',
|
||||||
id: '',
|
|
||||||
provider: '',
|
provider: '',
|
||||||
label: '',
|
identifier: null,
|
||||||
rootId: '',
|
label: null,
|
||||||
|
enabled: false,
|
||||||
|
capabilities: {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,10 +35,16 @@ export class ServiceObject implements ServiceInterface {
|
|||||||
return this._data;
|
return this._data;
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(): ServiceObject {
|
capable(capability: keyof ServiceCapabilitiesInterface): boolean {
|
||||||
const cloned = new ServiceObject();
|
const value = this._data.capabilities?.[capability];
|
||||||
cloned._data = JSON.parse(JSON.stringify(this._data));
|
return value !== undefined && value !== false;
|
||||||
return cloned;
|
}
|
||||||
|
|
||||||
|
capability(capability: keyof ServiceCapabilitiesInterface): any | null {
|
||||||
|
if (this._data.capabilities) {
|
||||||
|
return this._data.capabilities[capability];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Immutable Properties */
|
/** Immutable Properties */
|
||||||
@@ -38,20 +53,76 @@ export class ServiceObject implements ServiceInterface {
|
|||||||
return this._data['@type'];
|
return this._data['@type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
get id(): string {
|
|
||||||
return this._data.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
get provider(): string {
|
get provider(): string {
|
||||||
return this._data.provider;
|
return this._data.provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
get label(): string {
|
get identifier(): string | number | null {
|
||||||
|
return this._data.identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
get capabilities(): ServiceCapabilitiesInterface | undefined {
|
||||||
|
return this._data.capabilities;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mutable Properties */
|
||||||
|
|
||||||
|
get label(): string | null {
|
||||||
return this._data.label;
|
return this._data.label;
|
||||||
}
|
}
|
||||||
|
|
||||||
get rootId(): string {
|
set label(value: string | null) {
|
||||||
return this._data.rootId;
|
this._data.label = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get enabled(): boolean {
|
||||||
|
return this._data.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
set enabled(value: boolean) {
|
||||||
|
this._data.enabled = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get location(): ServiceLocation | null {
|
||||||
|
return this._data.location ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
set location(value: ServiceLocation | null) {
|
||||||
|
this._data.location = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get identity(): ServiceIdentity | null {
|
||||||
|
return this._data.identity ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
set identity(value: ServiceIdentity | null) {
|
||||||
|
this._data.identity = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
get auxiliary(): Record<string, any> {
|
||||||
|
return this._data.auxiliary ?? {};
|
||||||
|
}
|
||||||
|
|
||||||
|
set auxiliary(value: Record<string, any>) {
|
||||||
|
this._data.auxiliary = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Helper Methods */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get identity as a class instance for easier manipulation
|
||||||
|
*/
|
||||||
|
getIdentity(): Identity | null {
|
||||||
|
if (!this._data.identity) return null;
|
||||||
|
return Identity.fromJson(this._data.identity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get location as a class instance for easier manipulation
|
||||||
|
*/
|
||||||
|
getLocation(): Location | null {
|
||||||
|
if (!this._data.location) return null;
|
||||||
|
return Location.fromJson(this._data.location);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
/**
|
|
||||||
* File Manager API Service
|
|
||||||
* Central service for making API calls to the file manager backend
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { createFetchWrapper } from '@KTXC';
|
|
||||||
|
|
||||||
const fetchWrapper = createFetchWrapper();
|
|
||||||
|
|
||||||
const BASE_URL = '/m/file_manager/v1';
|
|
||||||
|
|
||||||
interface ApiRequest {
|
|
||||||
version: number;
|
|
||||||
transaction: string;
|
|
||||||
operation: string;
|
|
||||||
data?: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ApiSuccessResponse<T> {
|
|
||||||
version: number;
|
|
||||||
transaction: string;
|
|
||||||
operation: string;
|
|
||||||
status: 'success';
|
|
||||||
data: T;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface ApiErrorResponse {
|
|
||||||
version: number;
|
|
||||||
transaction: string;
|
|
||||||
operation: string;
|
|
||||||
status: 'error';
|
|
||||||
error: {
|
|
||||||
code: number;
|
|
||||||
message: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
type ApiResponseRaw<T> = ApiSuccessResponse<T> | ApiErrorResponse;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generate a unique transaction ID
|
|
||||||
*/
|
|
||||||
function generateTransactionId(): string {
|
|
||||||
return `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute an API operation
|
|
||||||
*/
|
|
||||||
async function execute<T>(operation: string, data: Record<string, unknown> = {}): Promise<T> {
|
|
||||||
const request: ApiRequest = {
|
|
||||||
version: 1,
|
|
||||||
transaction: generateTransactionId(),
|
|
||||||
operation,
|
|
||||||
data,
|
|
||||||
};
|
|
||||||
|
|
||||||
const response: ApiResponseRaw<T> = await fetchWrapper.post(BASE_URL, request);
|
|
||||||
|
|
||||||
if (response.status === 'error') {
|
|
||||||
throw new Error(response.error.message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const fileManagerApi = {
|
|
||||||
execute,
|
|
||||||
generateTransactionId,
|
|
||||||
};
|
|
||||||
|
|
||||||
export default fileManagerApi;
|
|
||||||
@@ -2,194 +2,154 @@
|
|||||||
* Collection management service
|
* Collection management service
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fileManagerApi } from './api';
|
import { transceivePost } from './transceive';
|
||||||
import type { FilterCondition, SortCondition } from '@/types/common';
|
import type {
|
||||||
import type { FileCollection } from '@/types/node';
|
CollectionListRequest,
|
||||||
|
CollectionListResponse,
|
||||||
|
CollectionExtantRequest,
|
||||||
|
CollectionExtantResponse,
|
||||||
|
CollectionFetchRequest,
|
||||||
|
CollectionFetchResponse,
|
||||||
|
CollectionCreateRequest,
|
||||||
|
CollectionCreateResponse,
|
||||||
|
CollectionUpdateResponse,
|
||||||
|
CollectionUpdateRequest,
|
||||||
|
CollectionDeleteResponse,
|
||||||
|
CollectionDeleteRequest,
|
||||||
|
CollectionInterface,
|
||||||
|
} from '../types/collection';
|
||||||
|
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||||
|
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
|
||||||
|
* Uses provider-specific factory if available, otherwise returns base CollectionObject
|
||||||
|
*/
|
||||||
|
function createCollectionObject(data: CollectionInterface): CollectionObject {
|
||||||
|
const integrationStore = useIntegrationStore();
|
||||||
|
const factoryItem = integrationStore.getItemById('documents_collection_factory', data.provider) as any;
|
||||||
|
const factory = factoryItem?.factory;
|
||||||
|
|
||||||
|
// Use provider factory if available, otherwise base class
|
||||||
|
return factory ? factory(data) : new CollectionObject().fromJson(data);
|
||||||
|
}
|
||||||
|
|
||||||
export const collectionService = {
|
export const collectionService = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List collections within a location
|
* Retrieve list of collections, optionally filtered by source selector
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - list request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param location - Parent collection ID (null for root)
|
* @returns Promise with collection object list grouped by provider, service, and collection identifier
|
||||||
* @param filter - Optional filter conditions
|
|
||||||
* @param sort - Optional sort conditions
|
|
||||||
* @returns Promise with collection list
|
|
||||||
*/
|
*/
|
||||||
async list(
|
async list(request: CollectionListRequest = {}): Promise<Record<string, Record<string, Record<string, CollectionObject>>>> {
|
||||||
provider: string,
|
const response = await transceivePost<CollectionListRequest, CollectionListResponse>('collection.list', request);
|
||||||
service: string,
|
|
||||||
location?: string | null,
|
// Convert nested response to CollectionObject instances
|
||||||
filter?: FilterCondition[] | null,
|
const providerList: Record<string, Record<string, Record<string, CollectionObject>>> = {};
|
||||||
sort?: SortCondition[] | null
|
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||||
): Promise<FileCollection[]> {
|
const serviceList: Record<string, Record<string, CollectionObject>> = {};
|
||||||
return await fileManagerApi.execute<FileCollection[]>('collection.list', {
|
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
|
||||||
provider,
|
const collectionList: Record<string, CollectionObject> = {};
|
||||||
service,
|
Object.entries(serviceCollections as Record<string, unknown>).forEach(([collectionId, collectionData]) => {
|
||||||
location: location ?? null,
|
if (isCollectionPayload(collectionData)) {
|
||||||
filter: filter ?? null,
|
collectionList[collectionId] = createCollectionObject(collectionData);
|
||||||
sort: sort ?? null,
|
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;
|
||||||
|
});
|
||||||
|
providerList[providerId] = serviceList;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return providerList;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if a collection exists
|
* Retrieve a specific collection by provider and identifier
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - fetch request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param identifier - Collection identifier
|
* @returns Promise with collection object
|
||||||
* @returns Promise with extant status
|
|
||||||
*/
|
*/
|
||||||
async extant(
|
async fetch(request: CollectionFetchRequest): Promise<CollectionObject> {
|
||||||
provider: string,
|
const response = await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request);
|
||||||
service: string,
|
return createCollectionObject(response);
|
||||||
identifier: string
|
|
||||||
): Promise<boolean> {
|
|
||||||
const result = await fileManagerApi.execute<{ extant: boolean }>('collection.extant', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
identifier,
|
|
||||||
});
|
|
||||||
return result.extant;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a specific collection
|
* Retrieve collection availability status for a given source selector
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - extant request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param identifier - Collection identifier
|
* @returns Promise with collection availability status
|
||||||
* @returns Promise with collection details
|
|
||||||
*/
|
*/
|
||||||
async fetch(
|
async extant(request: CollectionExtantRequest): Promise<CollectionExtantResponse> {
|
||||||
provider: string,
|
return await transceivePost<CollectionExtantRequest, CollectionExtantResponse>('collection.extant', request);
|
||||||
service: string,
|
|
||||||
identifier: string
|
|
||||||
): Promise<FileCollection> {
|
|
||||||
return await fileManagerApi.execute<FileCollection>('collection.fetch', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
identifier,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new collection (folder)
|
* Create a new collection
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - create request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param location - Parent collection ID (null for root)
|
* @returns Promise with created collection object
|
||||||
* @param data - Collection data (label, etc.)
|
|
||||||
* @param options - Additional options
|
|
||||||
* @returns Promise with created collection
|
|
||||||
*/
|
*/
|
||||||
async create(
|
async create(request: CollectionCreateRequest): Promise<CollectionObject> {
|
||||||
provider: string,
|
if (request.properties instanceof CollectionPropertiesObject) {
|
||||||
service: string,
|
request.properties = request.properties.toJson();
|
||||||
location: string | null,
|
}
|
||||||
data: Partial<FileCollection>,
|
const response = await transceivePost<CollectionCreateRequest, CollectionCreateResponse>('collection.create', request);
|
||||||
options?: Record<string, unknown>
|
return createCollectionObject(response);
|
||||||
): Promise<FileCollection> {
|
|
||||||
return await fileManagerApi.execute<FileCollection>('collection.create', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
location,
|
|
||||||
data,
|
|
||||||
options: options ?? {},
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify an existing collection
|
* Update an existing collection
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - update request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param identifier - Collection identifier
|
* @returns Promise with updated collection object
|
||||||
* @param data - Data to modify
|
|
||||||
* @returns Promise with modified collection
|
|
||||||
*/
|
*/
|
||||||
async modify(
|
async update(request: CollectionUpdateRequest): Promise<CollectionObject> {
|
||||||
provider: string,
|
if (request.properties instanceof CollectionPropertiesObject) {
|
||||||
service: string,
|
request.properties = request.properties.toJson();
|
||||||
identifier: string,
|
}
|
||||||
data: Partial<FileCollection>
|
const response = await transceivePost<CollectionUpdateRequest, CollectionUpdateResponse>('collection.update', request);
|
||||||
): Promise<FileCollection> {
|
return createCollectionObject(response);
|
||||||
return await fileManagerApi.execute<FileCollection>('collection.modify', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
identifier,
|
|
||||||
data,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a collection
|
* Delete a collection
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - delete request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param identifier - Collection identifier
|
* @returns Promise with deletion result
|
||||||
* @returns Promise with success status
|
|
||||||
*/
|
*/
|
||||||
async destroy(
|
async delete(request: CollectionDeleteRequest): Promise<CollectionDeleteResponse> {
|
||||||
provider: string,
|
return await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
|
||||||
service: string,
|
|
||||||
identifier: string
|
|
||||||
): Promise<boolean> {
|
|
||||||
const result = await fileManagerApi.execute<{ success: boolean }>('collection.destroy', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
identifier,
|
|
||||||
});
|
|
||||||
return result.success;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* Copy a collection to a new location
|
|
||||||
*
|
|
||||||
* @param provider - Provider identifier
|
|
||||||
* @param service - Service identifier
|
|
||||||
* @param identifier - Collection identifier to copy
|
|
||||||
* @param location - Destination parent collection ID (null for root)
|
|
||||||
* @returns Promise with copied collection
|
|
||||||
*/
|
|
||||||
async copy(
|
|
||||||
provider: string,
|
|
||||||
service: string,
|
|
||||||
identifier: string,
|
|
||||||
location?: string | null
|
|
||||||
): Promise<FileCollection> {
|
|
||||||
return await fileManagerApi.execute<FileCollection>('collection.copy', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
identifier,
|
|
||||||
location: location ?? null,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Move a collection to a new location
|
|
||||||
*
|
|
||||||
* @param provider - Provider identifier
|
|
||||||
* @param service - Service identifier
|
|
||||||
* @param identifier - Collection identifier to move
|
|
||||||
* @param location - Destination parent collection ID (null for root)
|
|
||||||
* @returns Promise with moved collection
|
|
||||||
*/
|
|
||||||
async move(
|
|
||||||
provider: string,
|
|
||||||
service: string,
|
|
||||||
identifier: string,
|
|
||||||
location?: string | null
|
|
||||||
): Promise<FileCollection> {
|
|
||||||
return await fileManagerApi.execute<FileCollection>('collection.move', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
identifier,
|
|
||||||
location: location ?? null,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default collectionService;
|
export default collectionService;
|
||||||
|
|||||||
@@ -1,292 +1,175 @@
|
|||||||
/**
|
/**
|
||||||
* Entity (file) management service
|
* Entity management service
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fileManagerApi } from './api';
|
import { transceivePost } from './transceive';
|
||||||
import type { FilterCondition, SortCondition, RangeCondition } from '@/types/common';
|
import type {
|
||||||
import type { FileEntity } from '@/types/node';
|
EntityListRequest,
|
||||||
import type { EntityDeltaResult } from '@/types/api';
|
EntityListResponse,
|
||||||
|
EntityFetchRequest,
|
||||||
|
EntityFetchResponse,
|
||||||
|
EntityExtantRequest,
|
||||||
|
EntityExtantResponse,
|
||||||
|
EntityCreateRequest,
|
||||||
|
EntityCreateResponse,
|
||||||
|
EntityUpdateRequest,
|
||||||
|
EntityUpdateResponse,
|
||||||
|
EntityDeleteRequest,
|
||||||
|
EntityDeleteResponse,
|
||||||
|
EntityDeltaRequest,
|
||||||
|
EntityDeltaResponse,
|
||||||
|
EntityReadRequest,
|
||||||
|
EntityReadResponse,
|
||||||
|
EntityWriteRequest,
|
||||||
|
EntityWriteResponse,
|
||||||
|
EntityInterface,
|
||||||
|
} from '../types/entity';
|
||||||
|
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||||
|
import { EntityObject } from '../models';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to create the right entity model class based on provider identifier
|
||||||
|
* Uses provider-specific factory if available, otherwise returns base EntityObject
|
||||||
|
*/
|
||||||
|
function createEntityObject(data: EntityInterface): EntityObject {
|
||||||
|
const integrationStore = useIntegrationStore();
|
||||||
|
const factoryItem = integrationStore.getItemById('documents_entity_factory', data.provider) as any;
|
||||||
|
const factory = factoryItem?.factory;
|
||||||
|
|
||||||
|
// Use provider factory if available, otherwise base class
|
||||||
|
return factory ? factory(data) : new EntityObject().fromJson(data);
|
||||||
|
}
|
||||||
|
|
||||||
export const entityService = {
|
export const entityService = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List entities within a collection
|
* Retrieve list of entities, optionally filtered by source selector
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - list request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param collection - Collection identifier
|
* @returns Promise with entity object list grouped by provider, service, collection, and entity identifier
|
||||||
* @param filter - Optional filter conditions
|
|
||||||
* @param sort - Optional sort conditions
|
|
||||||
* @param range - Optional range/pagination conditions
|
|
||||||
* @returns Promise with entity list
|
|
||||||
*/
|
*/
|
||||||
async list(
|
async list(request: EntityListRequest = {}): Promise<Record<string, Record<string, Record<string, Record<string, EntityObject>>>>> {
|
||||||
provider: string,
|
const response = await transceivePost<EntityListRequest, EntityListResponse>('entity.list', request);
|
||||||
service: string,
|
|
||||||
collection: string,
|
// Convert nested response to EntityObject instances
|
||||||
filter?: FilterCondition[] | null,
|
const providerList: Record<string, Record<string, Record<string, Record<string, EntityObject>>>> = {};
|
||||||
sort?: SortCondition[] | null,
|
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||||
range?: RangeCondition | null
|
const serviceList: Record<string, Record<string, Record<string, EntityObject>>> = {};
|
||||||
): Promise<FileEntity[]> {
|
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
|
||||||
return await fileManagerApi.execute<FileEntity[]>('entity.list', {
|
const collectionList: Record<string, Record<string, EntityObject>> = {};
|
||||||
provider,
|
Object.entries(serviceCollections).forEach(([collectionId, collectionEntities]) => {
|
||||||
service,
|
const entityList: Record<string, EntityObject> = {};
|
||||||
collection,
|
Object.entries(collectionEntities).forEach(([entityId, entityData]) => {
|
||||||
filter: filter ?? null,
|
entityList[entityId] = createEntityObject(entityData);
|
||||||
sort: sort ?? null,
|
});
|
||||||
range: range ?? null,
|
collectionList[collectionId] = entityList;
|
||||||
|
});
|
||||||
|
serviceList[serviceId] = collectionList;
|
||||||
|
});
|
||||||
|
providerList[providerId] = serviceList;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return providerList;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get delta changes for entities since a signature
|
* Retrieve a specific entity by provider and identifier
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - fetch request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param collection - Collection identifier
|
* @returns Promise with entity objects keyed by identifier
|
||||||
* @param signature - Previous sync signature
|
|
||||||
* @param detail - Detail level ('ids' or 'full')
|
|
||||||
* @returns Promise with delta changes
|
|
||||||
*/
|
*/
|
||||||
async delta(
|
async fetch(request: EntityFetchRequest): Promise<Record<string, EntityObject>> {
|
||||||
provider: string,
|
const response = await transceivePost<EntityFetchRequest, EntityFetchResponse>('entity.fetch', request);
|
||||||
service: string,
|
|
||||||
collection: string,
|
// Convert response to EntityObject instances
|
||||||
signature: string,
|
const list: Record<string, EntityObject> = {};
|
||||||
detail: 'ids' | 'full' = 'ids'
|
Object.entries(response).forEach(([identifier, entityData]) => {
|
||||||
): Promise<EntityDeltaResult> {
|
list[identifier] = createEntityObject(entityData);
|
||||||
return await fileManagerApi.execute<EntityDeltaResult>('entity.delta', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
collection,
|
|
||||||
signature,
|
|
||||||
detail,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return list;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check which entities exist
|
* Retrieve entity availability status for a given source selector
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - extant request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param collection - Collection identifier
|
* @returns Promise with entity availability status
|
||||||
* @param identifiers - Entity identifiers to check
|
|
||||||
* @returns Promise with existence map
|
|
||||||
*/
|
*/
|
||||||
async extant(
|
async extant(request: EntityExtantRequest): Promise<EntityExtantResponse> {
|
||||||
provider: string,
|
return await transceivePost<EntityExtantRequest, EntityExtantResponse>('entity.extant', request);
|
||||||
service: string,
|
|
||||||
collection: string,
|
|
||||||
identifiers: string[]
|
|
||||||
): Promise<Record<string, boolean>> {
|
|
||||||
return await fileManagerApi.execute<Record<string, boolean>>('entity.extant', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
collection,
|
|
||||||
identifiers,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch specific entities
|
* Create a new entity
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - create request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param collection - Collection identifier
|
* @returns Promise with created entity object
|
||||||
* @param identifiers - Entity identifiers to fetch
|
|
||||||
* @returns Promise with entity list
|
|
||||||
*/
|
*/
|
||||||
async fetch(
|
async create(request: EntityCreateRequest): Promise<EntityObject> {
|
||||||
provider: string,
|
const response = await transceivePost<EntityCreateRequest, EntityCreateResponse>('entity.create', request);
|
||||||
service: string,
|
return createEntityObject(response);
|
||||||
collection: string,
|
|
||||||
identifiers: string[]
|
|
||||||
): Promise<FileEntity[]> {
|
|
||||||
return await fileManagerApi.execute<FileEntity[]>('entity.fetch', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
collection,
|
|
||||||
identifiers,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read entity content
|
* Update an existing entity
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - update request parameters
|
||||||
* @param service - Service identifier
|
|
||||||
* @param collection - Collection identifier
|
|
||||||
* @param identifier - Entity identifier
|
|
||||||
* @returns Promise with base64 encoded content
|
|
||||||
*/
|
|
||||||
async read(
|
|
||||||
provider: string,
|
|
||||||
service: string,
|
|
||||||
collection: string,
|
|
||||||
identifier: string
|
|
||||||
): Promise<{ content: string | null; encoding: 'base64' }> {
|
|
||||||
return await fileManagerApi.execute<{ content: string | null; encoding: 'base64' }>('entity.read', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
collection,
|
|
||||||
identifier,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new entity (file)
|
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @returns Promise with updated entity object
|
||||||
* @param service - Service identifier
|
|
||||||
* @param collection - Collection identifier (null for root)
|
|
||||||
* @param data - Entity data (label, mime, etc.)
|
|
||||||
* @param options - Additional options
|
|
||||||
* @returns Promise with created entity
|
|
||||||
*/
|
*/
|
||||||
async create(
|
async update(request: EntityUpdateRequest): Promise<EntityObject> {
|
||||||
provider: string,
|
const response = await transceivePost<EntityUpdateRequest, EntityUpdateResponse>('entity.update', request);
|
||||||
service: string,
|
return createEntityObject(response);
|
||||||
collection: string | null,
|
|
||||||
data: Partial<FileEntity>,
|
|
||||||
options?: Record<string, unknown>
|
|
||||||
): Promise<FileEntity> {
|
|
||||||
return await fileManagerApi.execute<FileEntity>('entity.create', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
collection,
|
|
||||||
data,
|
|
||||||
options: options ?? {},
|
|
||||||
});
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Modify an existing entity
|
|
||||||
*
|
|
||||||
* @param provider - Provider identifier
|
|
||||||
* @param service - Service identifier
|
|
||||||
* @param collection - Collection identifier (can be null)
|
|
||||||
* @param identifier - Entity identifier
|
|
||||||
* @param data - Data to modify
|
|
||||||
* @returns Promise with modified entity
|
|
||||||
*/
|
|
||||||
async modify(
|
|
||||||
provider: string,
|
|
||||||
service: string,
|
|
||||||
collection: string | null,
|
|
||||||
identifier: string,
|
|
||||||
data: Partial<FileEntity>
|
|
||||||
): Promise<FileEntity> {
|
|
||||||
return await fileManagerApi.execute<FileEntity>('entity.modify', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
collection,
|
|
||||||
identifier,
|
|
||||||
data,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an entity
|
* Delete an entity
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - delete request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param collection - Collection identifier (can be null)
|
* @returns Promise with deletion result
|
||||||
* @param identifier - Entity identifier
|
|
||||||
* @returns Promise with success status
|
|
||||||
*/
|
*/
|
||||||
async destroy(
|
async delete(request: EntityDeleteRequest): Promise<EntityDeleteResponse> {
|
||||||
provider: string,
|
return await transceivePost<EntityDeleteRequest, EntityDeleteResponse>('entity.delete', request);
|
||||||
service: string,
|
|
||||||
collection: string | null,
|
|
||||||
identifier: string
|
|
||||||
): Promise<boolean> {
|
|
||||||
const result = await fileManagerApi.execute<{ success: boolean }>('entity.destroy', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
collection,
|
|
||||||
identifier,
|
|
||||||
});
|
|
||||||
return result.success;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy an entity to a new location
|
* Retrieve delta changes for entities
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - delta request parameters
|
||||||
* @param service - Service identifier
|
*
|
||||||
* @param collection - Source collection identifier (can be null)
|
* @returns Promise with delta changes (created, modified, deleted)
|
||||||
* @param identifier - Entity identifier to copy
|
|
||||||
* @param destination - Destination collection ID (null for root)
|
|
||||||
* @returns Promise with copied entity
|
|
||||||
*/
|
*/
|
||||||
async copy(
|
async delta(request: EntityDeltaRequest): Promise<EntityDeltaResponse> {
|
||||||
provider: string,
|
return await transceivePost<EntityDeltaRequest, EntityDeltaResponse>('entity.delta', request);
|
||||||
service: string,
|
|
||||||
collection: string | null,
|
|
||||||
identifier: string,
|
|
||||||
destination?: string | null
|
|
||||||
): Promise<FileEntity> {
|
|
||||||
return await fileManagerApi.execute<FileEntity>('entity.copy', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
collection,
|
|
||||||
identifier,
|
|
||||||
destination: destination ?? null,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move an entity to a new location
|
* Read entity content
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - read request parameters
|
||||||
* @param service - Service identifier
|
* @returns Promise with base64 encoded content
|
||||||
* @param collection - Source collection identifier (can be null)
|
|
||||||
* @param identifier - Entity identifier to move
|
|
||||||
* @param destination - Destination collection ID (null for root)
|
|
||||||
* @returns Promise with moved entity
|
|
||||||
*/
|
*/
|
||||||
async move(
|
async read(request: EntityReadRequest): Promise<EntityReadResponse> {
|
||||||
provider: string,
|
return await transceivePost<EntityReadRequest, EntityReadResponse>('entity.read', request);
|
||||||
service: string,
|
|
||||||
collection: string | null,
|
|
||||||
identifier: string,
|
|
||||||
destination?: string | null
|
|
||||||
): Promise<FileEntity> {
|
|
||||||
return await fileManagerApi.execute<FileEntity>('entity.move', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
collection,
|
|
||||||
identifier,
|
|
||||||
destination: destination ?? null,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write content to an entity
|
* Write content to an entity
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - write request parameters
|
||||||
* @param service - Service identifier
|
* @returns Promise with write result
|
||||||
* @param collection - Collection identifier (can be null)
|
|
||||||
* @param identifier - Entity identifier
|
|
||||||
* @param content - Content to write (base64 encoded)
|
|
||||||
* @returns Promise with bytes written
|
|
||||||
*/
|
*/
|
||||||
async write(
|
async write(request: EntityWriteRequest): Promise<EntityWriteResponse> {
|
||||||
provider: string,
|
return await transceivePost<EntityWriteRequest, EntityWriteResponse>('entity.write', {
|
||||||
service: string,
|
...request,
|
||||||
collection: string | null,
|
encoding: request.encoding ?? 'base64',
|
||||||
identifier: string,
|
|
||||||
content: string
|
|
||||||
): Promise<number> {
|
|
||||||
const result = await fileManagerApi.execute<{ bytesWritten: number }>('entity.write', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
collection,
|
|
||||||
identifier,
|
|
||||||
content,
|
|
||||||
encoding: 'base64',
|
|
||||||
});
|
});
|
||||||
return result.bytesWritten;
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
* Central export point for all File Manager services
|
* Central export point for all File Manager services
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { fileManagerApi } from './api';
|
|
||||||
export { providerService } from './providerService';
|
export { providerService } from './providerService';
|
||||||
export { serviceService } from './serviceService';
|
export { serviceService } from './serviceService';
|
||||||
export { collectionService } from './collectionService';
|
export { collectionService } from './collectionService';
|
||||||
|
|||||||
@@ -2,73 +2,67 @@
|
|||||||
* Node (unified collection/entity) management service
|
* Node (unified collection/entity) management service
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fileManagerApi } from './api';
|
import { transceivePost } from './transceive'
|
||||||
import type { FilterCondition, SortCondition, RangeCondition } from '@/types/common';
|
import type { ListFilter, ListSort, ListRange } from '../types/common'
|
||||||
import type { FileNode } from '@/types/node';
|
import type { CollectionInterface } from '../types/collection'
|
||||||
import type { NodeDeltaResult } from '@/types/api';
|
import type { EntityInterface } from '../types/entity'
|
||||||
|
|
||||||
|
export type NodeItem = CollectionInterface | EntityInterface
|
||||||
|
|
||||||
|
export interface NodeListRequest {
|
||||||
|
provider: string
|
||||||
|
service: string | number
|
||||||
|
location?: string | number | null
|
||||||
|
recursive?: boolean
|
||||||
|
filter?: ListFilter | null
|
||||||
|
sort?: ListSort | null
|
||||||
|
range?: ListRange | null
|
||||||
|
}
|
||||||
|
|
||||||
|
export type NodeListResponse = Record<string, NodeItem>
|
||||||
|
|
||||||
|
export interface NodeDeltaRequest {
|
||||||
|
provider: string
|
||||||
|
service: string | number
|
||||||
|
location?: string | number | null
|
||||||
|
signature: string
|
||||||
|
recursive?: boolean
|
||||||
|
detail?: 'ids' | 'full'
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface NodeDeltaResult {
|
||||||
|
added: Array<string | number | NodeItem>
|
||||||
|
modified: Array<string | number | NodeItem>
|
||||||
|
removed: Array<string | number>
|
||||||
|
signature: string
|
||||||
|
}
|
||||||
|
|
||||||
export const nodeService = {
|
export const nodeService = {
|
||||||
|
|
||||||
/**
|
async list(request: NodeListRequest): Promise<NodeItem[]> {
|
||||||
* List all nodes (collections and entities) within a location
|
const response = await transceivePost<NodeListRequest, NodeListResponse>('node.list', {
|
||||||
*
|
provider: request.provider,
|
||||||
* @param provider - Provider identifier
|
service: request.service,
|
||||||
* @param service - Service identifier
|
location: request.location ?? null,
|
||||||
* @param location - Parent collection ID (null for root)
|
recursive: request.recursive ?? false,
|
||||||
* @param recursive - Whether to list recursively
|
filter: request.filter ?? null,
|
||||||
* @param filter - Optional filter conditions
|
sort: request.sort ?? null,
|
||||||
* @param sort - Optional sort conditions
|
range: request.range ?? null,
|
||||||
* @param range - Optional range/pagination conditions
|
})
|
||||||
* @returns Promise with node list
|
|
||||||
*/
|
return Object.values(response)
|
||||||
async list(
|
|
||||||
provider: string,
|
|
||||||
service: string,
|
|
||||||
location?: string | null,
|
|
||||||
recursive: boolean = false,
|
|
||||||
filter?: FilterCondition[] | null,
|
|
||||||
sort?: SortCondition[] | null,
|
|
||||||
range?: RangeCondition | null
|
|
||||||
): Promise<FileNode[]> {
|
|
||||||
return await fileManagerApi.execute<FileNode[]>('node.list', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
location: location ?? null,
|
|
||||||
recursive,
|
|
||||||
filter: filter ?? null,
|
|
||||||
sort: sort ?? null,
|
|
||||||
range: range ?? null,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
async delta(request: NodeDeltaRequest): Promise<NodeDeltaResult> {
|
||||||
* Get delta changes for nodes since a signature
|
return await transceivePost<NodeDeltaRequest, NodeDeltaResult>('node.delta', {
|
||||||
*
|
provider: request.provider,
|
||||||
* @param provider - Provider identifier
|
service: request.service,
|
||||||
* @param service - Service identifier
|
location: request.location ?? null,
|
||||||
* @param location - Parent collection ID (null for root)
|
signature: request.signature,
|
||||||
* @param signature - Previous sync signature
|
recursive: request.recursive ?? false,
|
||||||
* @param recursive - Whether to get delta recursively
|
detail: request.detail ?? 'ids',
|
||||||
* @param detail - Detail level ('ids' or 'full')
|
})
|
||||||
* @returns Promise with delta changes
|
|
||||||
*/
|
|
||||||
async delta(
|
|
||||||
provider: string,
|
|
||||||
service: string,
|
|
||||||
location: string | null,
|
|
||||||
signature: string,
|
|
||||||
recursive: boolean = false,
|
|
||||||
detail: 'ids' | 'full' = 'ids'
|
|
||||||
): Promise<NodeDeltaResult> {
|
|
||||||
return await fileManagerApi.execute<NodeDeltaResult>('node.delta', {
|
|
||||||
provider,
|
|
||||||
service,
|
|
||||||
location,
|
|
||||||
signature,
|
|
||||||
recursive,
|
|
||||||
detail,
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
};
|
}
|
||||||
|
|
||||||
export default nodeService;
|
export default nodeService
|
||||||
|
|||||||
@@ -2,32 +2,74 @@
|
|||||||
* Provider management service
|
* Provider management service
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fileManagerApi } from './api';
|
import type {
|
||||||
import type { SourceSelector } from '@/types/common';
|
ProviderListRequest,
|
||||||
import type { ProviderRecord } from '@/types/provider';
|
ProviderListResponse,
|
||||||
|
ProviderExtantRequest,
|
||||||
|
ProviderExtantResponse,
|
||||||
|
ProviderFetchRequest,
|
||||||
|
ProviderFetchResponse,
|
||||||
|
ProviderInterface,
|
||||||
|
} from '../types/provider';
|
||||||
|
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||||
|
import { transceivePost } from './transceive';
|
||||||
|
import { ProviderObject } from '../models/provider';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to create the right provider model class based on provider identifier
|
||||||
|
* Uses provider-specific factory if available, otherwise returns base ProviderObject
|
||||||
|
*/
|
||||||
|
function createProviderObject(data: ProviderInterface): ProviderObject {
|
||||||
|
const integrationStore = useIntegrationStore();
|
||||||
|
const factoryItem = integrationStore.getItemById('documents_provider_factory', data.identifier) as any;
|
||||||
|
const factory = factoryItem?.factory;
|
||||||
|
|
||||||
|
// Use provider factory if available, otherwise base class
|
||||||
|
return factory ? factory(data) : new ProviderObject().fromJson(data);
|
||||||
|
}
|
||||||
|
|
||||||
export const providerService = {
|
export const providerService = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all available providers
|
* Retrieve list of providers, optionally filtered by source selector
|
||||||
*
|
*
|
||||||
* @param sources - Optional source selector to filter providers
|
* @param request - list request parameters
|
||||||
* @returns Promise with provider list keyed by provider ID
|
*
|
||||||
|
* @returns Promise with provider object list keyed by provider identifier
|
||||||
*/
|
*/
|
||||||
async list(sources?: SourceSelector): Promise<ProviderRecord> {
|
async list(request: ProviderListRequest = {}): Promise<Record<string, ProviderObject>> {
|
||||||
return await fileManagerApi.execute<ProviderRecord>('provider.list', {
|
const response = await transceivePost<ProviderListRequest, ProviderListResponse>('provider.list', request);
|
||||||
sources: sources || null
|
|
||||||
|
// Convert response to ProviderObject instances
|
||||||
|
const list: Record<string, ProviderObject> = {};
|
||||||
|
Object.entries(response).forEach(([providerId, providerData]) => {
|
||||||
|
list[providerId] = createProviderObject(providerData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return list;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check which providers exist/are available
|
* Retrieve specific provider by identifier
|
||||||
|
*
|
||||||
|
* @param request - fetch request parameters
|
||||||
|
*
|
||||||
|
* @returns Promise with provider object
|
||||||
|
*/
|
||||||
|
async fetch(request: ProviderFetchRequest): Promise<ProviderObject> {
|
||||||
|
const response = await transceivePost<ProviderFetchRequest, ProviderFetchResponse>('provider.fetch', request);
|
||||||
|
return createProviderObject(response);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve provider availability status for a given source selector
|
||||||
|
*
|
||||||
|
* @param request - extant request parameters
|
||||||
*
|
*
|
||||||
* @param sources - Source selector with provider IDs to check
|
|
||||||
* @returns Promise with provider availability status
|
* @returns Promise with provider availability status
|
||||||
*/
|
*/
|
||||||
async extant(sources: SourceSelector): Promise<Record<string, boolean>> {
|
async extant(request: ProviderExtantRequest): Promise<ProviderExtantResponse> {
|
||||||
return await fileManagerApi.execute<Record<string, boolean>>('provider.extant', { sources });
|
return await transceivePost<ProviderExtantRequest, ProviderExtantResponse>('provider.extant', request);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,46 +2,161 @@
|
|||||||
* Service management service
|
* Service management service
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fileManagerApi } from './api';
|
import type {
|
||||||
import type { SourceSelector } from '@/types/common';
|
ServiceListRequest,
|
||||||
import type { ServiceInterface, ServiceRecord } from '@/types/service';
|
ServiceListResponse,
|
||||||
|
ServiceFetchRequest,
|
||||||
|
ServiceFetchResponse,
|
||||||
|
ServiceExtantRequest,
|
||||||
|
ServiceExtantResponse,
|
||||||
|
ServiceCreateResponse,
|
||||||
|
ServiceCreateRequest,
|
||||||
|
ServiceUpdateResponse,
|
||||||
|
ServiceUpdateRequest,
|
||||||
|
ServiceDeleteResponse,
|
||||||
|
ServiceDeleteRequest,
|
||||||
|
ServiceDiscoverRequest,
|
||||||
|
ServiceDiscoverResponse,
|
||||||
|
ServiceTestRequest,
|
||||||
|
ServiceTestResponse,
|
||||||
|
ServiceInterface,
|
||||||
|
} from '../types/service';
|
||||||
|
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||||
|
import { transceivePost } from './transceive';
|
||||||
|
import { ServiceObject } from '../models/service';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper to create the right service model class based on provider identifier
|
||||||
|
* Uses provider-specific factory if available, otherwise returns base ServiceObject
|
||||||
|
*/
|
||||||
|
function createServiceObject(data: ServiceInterface): ServiceObject {
|
||||||
|
const integrationStore = useIntegrationStore();
|
||||||
|
const factoryItem = integrationStore.getItemById('documents_service_factory', data.provider) as any;
|
||||||
|
const factory = factoryItem?.factory;
|
||||||
|
|
||||||
|
// Use provider factory if available, otherwise base class
|
||||||
|
return factory ? factory(data) : new ServiceObject().fromJson(data);
|
||||||
|
}
|
||||||
|
|
||||||
export const serviceService = {
|
export const serviceService = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List all available services
|
* Retrieve list of services, optionally filtered by source selector
|
||||||
*
|
*
|
||||||
* @param sources - Optional source selector to filter services
|
* @param request - list request parameters
|
||||||
* @returns Promise with service list grouped by provider
|
*
|
||||||
|
* @returns Promise with service object list grouped by provider and keyed by service identifier
|
||||||
*/
|
*/
|
||||||
async list(sources?: SourceSelector): Promise<ServiceRecord> {
|
async list(request: ServiceListRequest = {}): Promise<Record<string, Record<string, ServiceObject>>> {
|
||||||
return await fileManagerApi.execute<ServiceRecord>('service.list', {
|
const response = await transceivePost<ServiceListRequest, ServiceListResponse>('service.list', request);
|
||||||
sources: sources || null
|
|
||||||
|
// Convert nested response to ServiceObject instances
|
||||||
|
const providerList: Record<string, Record<string, ServiceObject>> = {};
|
||||||
|
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||||
|
const serviceList: Record<string, ServiceObject> = {};
|
||||||
|
Object.entries(providerServices).forEach(([serviceId, serviceData]) => {
|
||||||
|
serviceList[serviceId] = createServiceObject(serviceData);
|
||||||
|
});
|
||||||
|
providerList[providerId] = serviceList;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return providerList;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check which services exist/are available
|
* Retrieve a specific service by provider and identifier
|
||||||
|
*
|
||||||
|
* @param request - fetch request parameters
|
||||||
|
*
|
||||||
|
* @returns Promise with service object
|
||||||
|
*/
|
||||||
|
async fetch(request: ServiceFetchRequest): Promise<ServiceObject> {
|
||||||
|
const response = await transceivePost<ServiceFetchRequest, ServiceFetchResponse>('service.fetch', request);
|
||||||
|
return createServiceObject(response);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve service availability status for a given source selector
|
||||||
|
*
|
||||||
|
* @param request - extant request parameters
|
||||||
*
|
*
|
||||||
* @param sources - Source selector with service IDs to check
|
|
||||||
* @returns Promise with service availability status
|
* @returns Promise with service availability status
|
||||||
*/
|
*/
|
||||||
async extant(sources: SourceSelector): Promise<Record<string, boolean>> {
|
async extant(request: ServiceExtantRequest): Promise<ServiceExtantResponse> {
|
||||||
return await fileManagerApi.execute<Record<string, boolean>>('service.extant', { sources });
|
return await transceivePost<ServiceExtantRequest, ServiceExtantResponse>('service.extant', request);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a specific service
|
* Retrieve discoverable services for a given source selector, sorted by provider
|
||||||
*
|
*
|
||||||
* @param provider - Provider identifier
|
* @param request - discover request parameters
|
||||||
* @param identifier - Service identifier
|
*
|
||||||
* @returns Promise with service details
|
* @returns Promise with array of discovered services sorted by provider
|
||||||
*/
|
*/
|
||||||
async fetch(provider: string, identifier: string): Promise<ServiceInterface> {
|
async discover(request: ServiceDiscoverRequest): Promise<ServiceObject[]> {
|
||||||
return await fileManagerApi.execute<ServiceInterface>('service.fetch', {
|
const response = await transceivePost<ServiceDiscoverRequest, ServiceDiscoverResponse>('service.discover', request);
|
||||||
provider,
|
|
||||||
identifier
|
// Convert discovery results to ServiceObjects
|
||||||
|
const services: ServiceObject[] = [];
|
||||||
|
Object.entries(response).forEach(([providerId, location]) => {
|
||||||
|
const serviceData: ServiceInterface = {
|
||||||
|
'@type': 'documents:service',
|
||||||
|
provider: providerId,
|
||||||
|
identifier: null,
|
||||||
|
label: null,
|
||||||
|
enabled: false,
|
||||||
|
location: location,
|
||||||
|
};
|
||||||
|
services.push(createServiceObject(serviceData));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Sort by provider
|
||||||
|
return services.sort((a, b) => a.provider.localeCompare(b.provider));
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test service connectivity and configuration
|
||||||
|
*
|
||||||
|
* @param request - Service test request
|
||||||
|
* @returns Promise with test results
|
||||||
|
*/
|
||||||
|
async test(request: ServiceTestRequest): Promise<ServiceTestResponse> {
|
||||||
|
return await transceivePost<ServiceTestRequest, ServiceTestResponse>('service.test', request);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new service
|
||||||
|
*
|
||||||
|
* @param request - create request parameters
|
||||||
|
*
|
||||||
|
* @returns Promise with created service object
|
||||||
|
*/
|
||||||
|
async create(request: ServiceCreateRequest): Promise<ServiceObject> {
|
||||||
|
const response = await transceivePost<ServiceCreateRequest, ServiceCreateResponse>('service.create', request);
|
||||||
|
return createServiceObject(response);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update a existing service
|
||||||
|
*
|
||||||
|
* @param request - update request parameters
|
||||||
|
*
|
||||||
|
* @returns Promise with updated service object
|
||||||
|
*/
|
||||||
|
async update(request: ServiceUpdateRequest): Promise<ServiceObject> {
|
||||||
|
const response = await transceivePost<ServiceUpdateRequest, ServiceUpdateResponse>('service.update', request);
|
||||||
|
return createServiceObject(response);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a service
|
||||||
|
*
|
||||||
|
* @param request - delete request parameters
|
||||||
|
*
|
||||||
|
* @returns Promise with deletion result
|
||||||
|
*/
|
||||||
|
async delete(request: { provider: string; identifier: string | number }): Promise<any> {
|
||||||
|
return await transceivePost<ServiceDeleteRequest, ServiceDeleteResponse>('service.delete', request);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
50
src/services/transceive.ts
Normal file
50
src/services/transceive.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* API Client for Documents Manager
|
||||||
|
* Provides a centralized way to make API calls with envelope wrapping/unwrapping
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { createFetchWrapper } from '@KTXC';
|
||||||
|
import type { ApiRequest, ApiResponse } from '../types/common';
|
||||||
|
|
||||||
|
const fetchWrapper = createFetchWrapper();
|
||||||
|
const API_URL = '/m/documents_manager/v1';
|
||||||
|
const API_VERSION = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a unique transaction ID
|
||||||
|
*/
|
||||||
|
export function generateTransactionId(): string {
|
||||||
|
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make an API call with automatic envelope wrapping and unwrapping
|
||||||
|
*
|
||||||
|
* @param operation - Operation name (e.g., 'provider.list', 'service.autodiscover')
|
||||||
|
* @param data - Operation-specific request data
|
||||||
|
* @param user - Optional user identifier override
|
||||||
|
* @returns Promise with unwrapped response data
|
||||||
|
* @throws Error if the API returns an error status
|
||||||
|
*/
|
||||||
|
export async function transceivePost<TRequest, TResponse>(
|
||||||
|
operation: string,
|
||||||
|
data: TRequest,
|
||||||
|
user?: string
|
||||||
|
): Promise<TResponse> {
|
||||||
|
const request: ApiRequest<TRequest> = {
|
||||||
|
version: API_VERSION,
|
||||||
|
transaction: generateTransactionId(),
|
||||||
|
operation,
|
||||||
|
data,
|
||||||
|
user
|
||||||
|
};
|
||||||
|
|
||||||
|
const response: ApiResponse<TResponse> = await fetchWrapper.post(API_URL, request);
|
||||||
|
|
||||||
|
if (response.status === 'error') {
|
||||||
|
const errorMessage = `[${operation}] ${response.data.message}${response.data.code ? ` (code: ${response.data.code})` : ''}`;
|
||||||
|
throw new Error(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.data;
|
||||||
|
}
|
||||||
212
src/stores/collectionsStore.ts
Normal file
212
src/stores/collectionsStore.ts
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
/**
|
||||||
|
* Collections Store
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ref, computed, readonly } from 'vue'
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { collectionService } from '../services/collectionService'
|
||||||
|
import type {
|
||||||
|
SourceSelector,
|
||||||
|
ListFilter,
|
||||||
|
ListSort,
|
||||||
|
CollectionMutableProperties,
|
||||||
|
CollectionDeleteResponse,
|
||||||
|
} from '../types'
|
||||||
|
import { CollectionObject } from '../models/collection'
|
||||||
|
|
||||||
|
export const useCollectionsStore = defineStore('documentsCollectionsStore', () => {
|
||||||
|
// State
|
||||||
|
const _collections = ref<Record<string, CollectionObject>>({})
|
||||||
|
const transceiving = ref(false)
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
const count = computed(() => Object.keys(_collections.value).length)
|
||||||
|
const has = computed(() => count.value > 0)
|
||||||
|
const collections = computed(() => Object.values(_collections.value))
|
||||||
|
|
||||||
|
const collectionsByService = computed(() => {
|
||||||
|
const groups: Record<string, CollectionObject[]> = {}
|
||||||
|
|
||||||
|
Object.values(_collections.value).forEach((collection) => {
|
||||||
|
const serviceKey = `${collection.provider}:${collection.service}`
|
||||||
|
const serviceCollections = (groups[serviceKey] ??= [])
|
||||||
|
serviceCollections.push(collection)
|
||||||
|
})
|
||||||
|
|
||||||
|
return groups
|
||||||
|
})
|
||||||
|
|
||||||
|
function identifierKey(provider: string, service: string | number | null, identifier: string | number | null): string {
|
||||||
|
return `${provider}:${service ?? ''}:${identifier ?? ''}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function collection(provider: string, service: string | number, identifier: string | number, retrieve: boolean = false): CollectionObject | null {
|
||||||
|
const key = identifierKey(provider, service, identifier)
|
||||||
|
if (retrieve === true && !_collections.value[key]) {
|
||||||
|
console.debug(`[Documents Manager][Store] - Force fetching collection "${key}"`)
|
||||||
|
fetch(provider, service, identifier)
|
||||||
|
}
|
||||||
|
|
||||||
|
return _collections.value[key] || null
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectionsForService(provider: string, service: string | number): CollectionObject[] {
|
||||||
|
const serviceKeyPrefix = `${provider}:${service}:`
|
||||||
|
return Object.entries(_collections.value)
|
||||||
|
.filter(([key]) => key.startsWith(serviceKeyPrefix))
|
||||||
|
.map(([_, collectionObj]) => collectionObj)
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearService(provider: string, service: string | number): void {
|
||||||
|
const serviceKeyPrefix = `${provider}:${service}:`
|
||||||
|
Object.keys(_collections.value)
|
||||||
|
.filter((key) => key.startsWith(serviceKeyPrefix))
|
||||||
|
.forEach((key) => {
|
||||||
|
delete _collections.value[key]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearAll(): void {
|
||||||
|
_collections.value = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
async function list(sources?: SourceSelector, filter?: ListFilter, sort?: ListSort): Promise<Record<string, CollectionObject>> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await collectionService.list({ sources, filter, sort })
|
||||||
|
|
||||||
|
const hydrated: Record<string, CollectionObject> = {}
|
||||||
|
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||||
|
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
|
||||||
|
Object.entries(serviceCollections).forEach(([collectionId, collectionObj]) => {
|
||||||
|
const key = identifierKey(providerId, serviceId, collectionId)
|
||||||
|
hydrated[key] = collectionObj
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
_collections.value = { ..._collections.value, ...hydrated }
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully retrieved', Object.keys(hydrated).length, 'collections')
|
||||||
|
return hydrated
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to retrieve collections:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetch(provider: string, service: string | number, identifier: string | number): Promise<CollectionObject> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await collectionService.fetch({ provider, service, collection: identifier })
|
||||||
|
const key = identifierKey(response.provider, response.service, response.identifier)
|
||||||
|
_collections.value[key] = response
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully fetched collection:', key)
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to fetch collection:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function extant(sources: SourceSelector) {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await collectionService.extant({ sources })
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully checked collection availability')
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to check collection availability:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function create(
|
||||||
|
provider: string,
|
||||||
|
service: string | number,
|
||||||
|
collection: string | number | null,
|
||||||
|
properties: CollectionMutableProperties,
|
||||||
|
): Promise<CollectionObject> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await collectionService.create({ provider, service, collection, properties })
|
||||||
|
const key = identifierKey(response.provider, response.service, response.identifier)
|
||||||
|
_collections.value[key] = response
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully created collection:', key)
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to create collection:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function update(
|
||||||
|
provider: string,
|
||||||
|
service: string | number,
|
||||||
|
identifier: string | number,
|
||||||
|
properties: CollectionMutableProperties,
|
||||||
|
): Promise<CollectionObject> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await collectionService.update({ provider, service, identifier, properties })
|
||||||
|
const key = identifierKey(response.provider, response.service, response.identifier)
|
||||||
|
_collections.value[key] = response
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully updated collection:', key)
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to update collection:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(provider: string, service: string | number, identifier: string | number): Promise<CollectionDeleteResponse> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await collectionService.delete({ provider, service, identifier })
|
||||||
|
if (response.success) {
|
||||||
|
const key = identifierKey(provider, service, identifier)
|
||||||
|
delete _collections.value[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully deleted collection:', `${provider}:${service}:${identifier}`)
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to delete collection:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
transceiving: readonly(transceiving),
|
||||||
|
count,
|
||||||
|
has,
|
||||||
|
collections,
|
||||||
|
collectionsByService,
|
||||||
|
collection,
|
||||||
|
collectionsForService,
|
||||||
|
clearService,
|
||||||
|
clearAll,
|
||||||
|
list,
|
||||||
|
fetch,
|
||||||
|
extant,
|
||||||
|
create,
|
||||||
|
update,
|
||||||
|
delete: remove,
|
||||||
|
}
|
||||||
|
})
|
||||||
334
src/stores/entitiesStore.ts
Normal file
334
src/stores/entitiesStore.ts
Normal file
@@ -0,0 +1,334 @@
|
|||||||
|
/**
|
||||||
|
* Entities Store
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ref, computed, readonly } from 'vue'
|
||||||
|
import { defineStore } from 'pinia'
|
||||||
|
import { entityService } from '../services/entityService'
|
||||||
|
import { EntityObject } from '../models'
|
||||||
|
import type {
|
||||||
|
SourceSelector,
|
||||||
|
ListFilter,
|
||||||
|
ListSort,
|
||||||
|
ListRange,
|
||||||
|
DocumentInterface,
|
||||||
|
EntityDeleteResponse,
|
||||||
|
EntityDeltaResponse,
|
||||||
|
} from '../types'
|
||||||
|
|
||||||
|
export const useEntitiesStore = defineStore('documentsEntitiesStore', () => {
|
||||||
|
// State
|
||||||
|
const _entities = ref<Record<string, EntityObject>>({})
|
||||||
|
const transceiving = ref(false)
|
||||||
|
|
||||||
|
// Getters
|
||||||
|
const count = computed(() => Object.keys(_entities.value).length)
|
||||||
|
const has = computed(() => count.value > 0)
|
||||||
|
const entities = computed(() => Object.values(_entities.value))
|
||||||
|
|
||||||
|
const entitiesByService = computed(() => {
|
||||||
|
const groups: Record<string, EntityObject[]> = {}
|
||||||
|
|
||||||
|
Object.values(_entities.value).forEach((entity) => {
|
||||||
|
const serviceKey = `${entity.provider}:${entity.service}`
|
||||||
|
const serviceEntities = (groups[serviceKey] ??= [])
|
||||||
|
serviceEntities.push(entity)
|
||||||
|
})
|
||||||
|
|
||||||
|
return groups
|
||||||
|
})
|
||||||
|
|
||||||
|
function identifierKey(
|
||||||
|
provider: string,
|
||||||
|
service: string | number,
|
||||||
|
collection: string | number,
|
||||||
|
identifier: string | number,
|
||||||
|
): string {
|
||||||
|
return `${provider}:${service}:${collection}:${identifier}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function entity(
|
||||||
|
provider: string,
|
||||||
|
service: string | number,
|
||||||
|
collection: string | number,
|
||||||
|
identifier: string | number,
|
||||||
|
retrieve: boolean = false,
|
||||||
|
): EntityObject | null {
|
||||||
|
const key = identifierKey(provider, service, collection, identifier)
|
||||||
|
if (retrieve === true && !_entities.value[key]) {
|
||||||
|
console.debug(`[Documents Manager][Store] - Force fetching entity "${key}"`)
|
||||||
|
fetch(provider, service, collection, [identifier])
|
||||||
|
}
|
||||||
|
|
||||||
|
return _entities.value[key] || null
|
||||||
|
}
|
||||||
|
|
||||||
|
function entitiesForService(provider: string, service: string | number): EntityObject[] {
|
||||||
|
const serviceKeyPrefix = `${provider}:${service}:`
|
||||||
|
return Object.entries(_entities.value)
|
||||||
|
.filter(([key]) => key.startsWith(serviceKeyPrefix))
|
||||||
|
.map(([_, entityObj]) => entityObj)
|
||||||
|
}
|
||||||
|
|
||||||
|
function entitiesForCollection(provider: string, service: string | number, collection: string | number): EntityObject[] {
|
||||||
|
const collectionKeyPrefix = `${provider}:${service}:${collection}:`
|
||||||
|
return Object.entries(_entities.value)
|
||||||
|
.filter(([key]) => key.startsWith(collectionKeyPrefix))
|
||||||
|
.map(([_, entityObj]) => entityObj)
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearService(provider: string, service: string | number): void {
|
||||||
|
const serviceKeyPrefix = `${provider}:${service}:`
|
||||||
|
Object.keys(_entities.value)
|
||||||
|
.filter((key) => key.startsWith(serviceKeyPrefix))
|
||||||
|
.forEach((key) => {
|
||||||
|
delete _entities.value[key]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearCollection(provider: string, service: string | number, collection: string | number): void {
|
||||||
|
const collectionKeyPrefix = `${provider}:${service}:${collection}:`
|
||||||
|
Object.keys(_entities.value)
|
||||||
|
.filter((key) => key.startsWith(collectionKeyPrefix))
|
||||||
|
.forEach((key) => {
|
||||||
|
delete _entities.value[key]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearAll(): void {
|
||||||
|
_entities.value = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actions
|
||||||
|
async function list(sources?: SourceSelector, filter?: ListFilter, sort?: ListSort, range?: ListRange): Promise<Record<string, EntityObject>> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.list({ sources, filter, sort, range })
|
||||||
|
|
||||||
|
const hydrated: Record<string, EntityObject> = {}
|
||||||
|
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||||
|
Object.entries(providerServices).forEach(([serviceId, serviceCollections]) => {
|
||||||
|
Object.entries(serviceCollections).forEach(([collectionId, collectionEntities]) => {
|
||||||
|
Object.entries(collectionEntities).forEach(([entityId, entityObj]) => {
|
||||||
|
const key = identifierKey(providerId, serviceId, collectionId, entityId)
|
||||||
|
hydrated[key] = entityObj
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
_entities.value = { ..._entities.value, ...hydrated }
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully retrieved', Object.keys(hydrated).length, 'entities')
|
||||||
|
return hydrated
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to retrieve entities:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetch(
|
||||||
|
provider: string,
|
||||||
|
service: string | number,
|
||||||
|
collection: string | number,
|
||||||
|
identifiers: (string | number)[],
|
||||||
|
): Promise<Record<string, EntityObject>> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.fetch({ provider, service, collection, identifiers })
|
||||||
|
|
||||||
|
const hydrated: Record<string, EntityObject> = {}
|
||||||
|
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) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to fetch entities:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function extant(sources: SourceSelector) {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.extant({ sources })
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully checked entity availability')
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to check entity availability:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function create(
|
||||||
|
provider: string,
|
||||||
|
service: string | number,
|
||||||
|
collection: string | number,
|
||||||
|
properties: DocumentInterface,
|
||||||
|
options?: Record<string, unknown>,
|
||||||
|
): Promise<EntityObject> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.create({ provider, service, collection, properties, options })
|
||||||
|
const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
|
||||||
|
_entities.value[key] = response
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully created entity:', key)
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to create entity:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function update(
|
||||||
|
provider: string,
|
||||||
|
service: string | number,
|
||||||
|
collection: string | number,
|
||||||
|
identifier: string | number,
|
||||||
|
properties: DocumentInterface,
|
||||||
|
): Promise<EntityObject> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.update({ provider, service, collection, identifier, properties })
|
||||||
|
const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
|
||||||
|
_entities.value[key] = response
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully updated entity:', key)
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to update entity:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function remove(
|
||||||
|
provider: string,
|
||||||
|
service: string | number,
|
||||||
|
collection: string | number,
|
||||||
|
identifier: string | number,
|
||||||
|
): Promise<EntityDeleteResponse> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.delete({ provider, service, collection, identifier })
|
||||||
|
if (response.success) {
|
||||||
|
const key = identifierKey(provider, service, collection, identifier)
|
||||||
|
delete _entities.value[key]
|
||||||
|
}
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully deleted entity:', `${provider}:${service}:${collection}:${identifier}`)
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to delete entity:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function delta(sources: SourceSelector): Promise<EntityDeltaResponse> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.delta({ sources })
|
||||||
|
|
||||||
|
Object.entries(response).forEach(([provider, providerData]) => {
|
||||||
|
if (providerData === false) return
|
||||||
|
|
||||||
|
Object.entries(providerData).forEach(([service, serviceData]) => {
|
||||||
|
if (serviceData === false) return
|
||||||
|
|
||||||
|
Object.entries(serviceData).forEach(([collection, collectionData]) => {
|
||||||
|
if (collectionData === false) return
|
||||||
|
|
||||||
|
collectionData.deletions.forEach((identifier) => {
|
||||||
|
const key = identifierKey(provider, service, collection, identifier)
|
||||||
|
delete _entities.value[key]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully processed entity delta')
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to process entity delta:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function read(
|
||||||
|
provider: string,
|
||||||
|
service: string | number,
|
||||||
|
collection: string | number,
|
||||||
|
identifier: string | number,
|
||||||
|
): Promise<string | null> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.read({ provider, service, collection, identifier })
|
||||||
|
return response.content
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to read entity:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function write(
|
||||||
|
provider: string,
|
||||||
|
service: string | number,
|
||||||
|
collection: string | number,
|
||||||
|
identifier: string | number,
|
||||||
|
content: string,
|
||||||
|
): Promise<number> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.write({ provider, service, collection, identifier, content, encoding: 'base64' })
|
||||||
|
return response.bytesWritten
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to write entity:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
transceiving: readonly(transceiving),
|
||||||
|
count,
|
||||||
|
has,
|
||||||
|
entities,
|
||||||
|
entitiesByService,
|
||||||
|
entity,
|
||||||
|
entitiesForService,
|
||||||
|
entitiesForCollection,
|
||||||
|
clearService,
|
||||||
|
clearCollection,
|
||||||
|
clearAll,
|
||||||
|
list,
|
||||||
|
fetch,
|
||||||
|
extant,
|
||||||
|
create,
|
||||||
|
update,
|
||||||
|
delete: remove,
|
||||||
|
delta,
|
||||||
|
read,
|
||||||
|
write,
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
export { useProvidersStore } from './providersStore';
|
export { useProvidersStore } from './providersStore';
|
||||||
export { useServicesStore } from './servicesStore';
|
export { useServicesStore } from './servicesStore';
|
||||||
export { useNodesStore, ROOT_ID } from './nodesStore';
|
export { useCollectionsStore } from './collectionsStore';
|
||||||
|
export { useEntitiesStore } from './entitiesStore';
|
||||||
|
export { useNodesStore, ROOT_ID } from './nodesStore.ts';
|
||||||
@@ -1,646 +1,322 @@
|
|||||||
import { defineStore } from 'pinia'
|
/**
|
||||||
import { ref, computed } from 'vue'
|
* Nodes Store (thin wrapper over collections/entities stores)
|
||||||
import type { Ref, ComputedRef } from 'vue'
|
*/
|
||||||
import type { FileNode, FileCollection, FileEntity } from '../types/node'
|
|
||||||
import type { FilterCondition, SortCondition, RangeCondition } from '../types/common'
|
import { computed, ref, readonly } from 'vue'
|
||||||
import { isFileCollection } from '../types/node'
|
import { defineStore } from 'pinia'
|
||||||
import { collectionService } from '../services/collectionService'
|
import type {
|
||||||
import { entityService } from '../services/entityService'
|
SourceSelector,
|
||||||
import { nodeService } from '../services/nodeService'
|
ListFilter,
|
||||||
import { FileCollectionObject } from '../models/collection'
|
ListSort,
|
||||||
import { FileEntityObject } from '../models/entity'
|
ListRange,
|
||||||
|
CollectionMutableProperties,
|
||||||
|
DocumentInterface,
|
||||||
|
} from '../types'
|
||||||
|
import { CollectionObject, EntityObject } from '../models'
|
||||||
|
import { useCollectionsStore } from './collectionsStore'
|
||||||
|
import { useEntitiesStore } from './entitiesStore'
|
||||||
|
|
||||||
// Root collection constant
|
|
||||||
export const ROOT_ID = '00000000-0000-0000-0000-000000000000'
|
export const ROOT_ID = '00000000-0000-0000-0000-000000000000'
|
||||||
|
|
||||||
// Store structure: provider -> service -> nodeId -> node (either collection or entity object)
|
type NodeRecord = CollectionObject | EntityObject
|
||||||
type NodeRecord = FileCollectionObject | FileEntityObject
|
|
||||||
type ServiceNodeStore = Record<string, NodeRecord>
|
|
||||||
type ProviderNodeStore = Record<string, ServiceNodeStore>
|
|
||||||
type NodeStore = Record<string, ProviderNodeStore>
|
|
||||||
|
|
||||||
export const useNodesStore = defineStore('fileNodes', () => {
|
export const useNodesStore = defineStore('documentsNodesStore', () => {
|
||||||
const nodes: Ref<NodeStore> = ref({})
|
const collectionsStore = useCollectionsStore()
|
||||||
const syncTokens: Ref<Record<string, Record<string, string>>> = ref({}) // provider -> service -> token
|
const entitiesStore = useEntitiesStore()
|
||||||
const loading = ref(false)
|
|
||||||
const error: Ref<string | null> = ref(null)
|
|
||||||
|
|
||||||
// Computed: flat list of all nodes
|
const error = ref<string | null>(null)
|
||||||
const nodeList: ComputedRef<NodeRecord[]> = computed(() => {
|
|
||||||
const result: NodeRecord[] = []
|
const transceiving = computed(() => collectionsStore.transceiving || entitiesStore.transceiving)
|
||||||
Object.values(nodes.value).forEach(providerNodes => {
|
|
||||||
Object.values(providerNodes).forEach(serviceNodes => {
|
const nodeList = computed<NodeRecord[]>(() => {
|
||||||
result.push(...Object.values(serviceNodes))
|
return [...collectionsStore.collections, ...entitiesStore.entities]
|
||||||
|
})
|
||||||
|
|
||||||
|
const collectionList = computed<CollectionObject[]>(() => collectionsStore.collections)
|
||||||
|
const entityList = computed<EntityObject[]>(() => entitiesStore.entities)
|
||||||
|
|
||||||
|
function toId(value: string | number | null | undefined): string | null {
|
||||||
|
if (value === null || value === undefined || value === '') {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
return String(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
function getServiceNodes(providerId: string, serviceId: string | number): NodeRecord[] {
|
||||||
|
return [
|
||||||
|
...collectionsStore.collectionsForService(providerId, serviceId),
|
||||||
|
...entitiesStore.entitiesForService(providerId, serviceId),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNode(providerId: string, serviceId: string | number, nodeId: string | number): NodeRecord | undefined {
|
||||||
|
const targetId = String(nodeId)
|
||||||
|
return getServiceNodes(providerId, serviceId)
|
||||||
|
.find((node) => String(node.identifier) === targetId)
|
||||||
|
}
|
||||||
|
|
||||||
|
function isRoot(nodeId: string | number | null | undefined): boolean {
|
||||||
|
const normalized = toId(nodeId)
|
||||||
|
return normalized === null || normalized === ROOT_ID
|
||||||
|
}
|
||||||
|
|
||||||
|
function getChildren(providerId: string, serviceId: string | number, parentId: string | number | null): NodeRecord[] {
|
||||||
|
const serviceNodes = getServiceNodes(providerId, serviceId)
|
||||||
|
|
||||||
|
if (isRoot(parentId)) {
|
||||||
|
return serviceNodes.filter((node) => {
|
||||||
|
const parent = toId(node.collection)
|
||||||
|
return parent === null || parent === ROOT_ID
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
return result
|
|
||||||
})
|
|
||||||
|
|
||||||
// Computed: all collections (folders)
|
const targetParent = String(parentId)
|
||||||
const collectionList: ComputedRef<FileCollectionObject[]> = computed(() => {
|
return serviceNodes.filter((node) => toId(node.collection) === targetParent)
|
||||||
return nodeList.value.filter(
|
|
||||||
(node): node is FileCollectionObject => node['@type'] === 'files.collection'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Computed: all entities (files)
|
|
||||||
const entityList: ComputedRef<FileEntityObject[]> = computed(() => {
|
|
||||||
return nodeList.value.filter(
|
|
||||||
(node): node is FileEntityObject => node['@type'] === 'files.entity'
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Get a specific node
|
|
||||||
const getNode = (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
nodeId: string
|
|
||||||
): NodeRecord | undefined => {
|
|
||||||
return nodes.value[providerId]?.[serviceId]?.[nodeId]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all nodes for a service
|
function getChildCollections(providerId: string, serviceId: string | number, parentId: string | number | null): CollectionObject[] {
|
||||||
const getServiceNodes = (
|
return getChildren(providerId, serviceId, parentId)
|
||||||
providerId: string,
|
.filter((node): node is CollectionObject => node instanceof CollectionObject)
|
||||||
serviceId: string
|
|
||||||
): NodeRecord[] => {
|
|
||||||
return Object.values(nodes.value[providerId]?.[serviceId] || {})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get children of a parent node (or root nodes if parentId is null/ROOT_ID)
|
function getChildEntities(providerId: string, serviceId: string | number, parentId: string | number | null): EntityObject[] {
|
||||||
const getChildren = (
|
return getChildren(providerId, serviceId, parentId)
|
||||||
providerId: string,
|
.filter((node): node is EntityObject => node instanceof EntityObject)
|
||||||
serviceId: string,
|
|
||||||
parentId: string | null
|
|
||||||
): NodeRecord[] => {
|
|
||||||
const serviceNodes = nodes.value[providerId]?.[serviceId] || {}
|
|
||||||
const targetParent = parentId === ROOT_ID ? ROOT_ID : parentId
|
|
||||||
return Object.values(serviceNodes).filter(node => node.in === targetParent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get child collections (folders)
|
function getPath(providerId: string, serviceId: string | number, nodeId: string | number): NodeRecord[] {
|
||||||
const getChildCollections = (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
parentId: string | null
|
|
||||||
): FileCollectionObject[] => {
|
|
||||||
return getChildren(providerId, serviceId, parentId).filter(
|
|
||||||
(node): node is FileCollectionObject => node['@type'] === 'files.collection'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get child entities (files)
|
|
||||||
const getChildEntities = (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
parentId: string | null
|
|
||||||
): FileEntityObject[] => {
|
|
||||||
return getChildren(providerId, serviceId, parentId).filter(
|
|
||||||
(node): node is FileEntityObject => node['@type'] === 'files.entity'
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get path to root (ancestors)
|
|
||||||
const getPath = (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
nodeId: string
|
|
||||||
): NodeRecord[] => {
|
|
||||||
const path: NodeRecord[] = []
|
const path: NodeRecord[] = []
|
||||||
let currentNode = getNode(providerId, serviceId, nodeId)
|
let current = getNode(providerId, serviceId, nodeId)
|
||||||
|
|
||||||
while (currentNode) {
|
while (current) {
|
||||||
path.unshift(currentNode)
|
path.unshift(current)
|
||||||
if (currentNode.in === null || currentNode.in === ROOT_ID || currentNode.id === ROOT_ID) {
|
const parentId = toId(current.collection)
|
||||||
|
|
||||||
|
if (parentId === null || parentId === ROOT_ID) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
currentNode = getNode(providerId, serviceId, currentNode.in)
|
|
||||||
|
current = getNode(providerId, serviceId, parentId)
|
||||||
}
|
}
|
||||||
|
|
||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a node is the root
|
async function fetchCollections(
|
||||||
const isRoot = (nodeId: string): boolean => {
|
|
||||||
return nodeId === ROOT_ID
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper to hydrate a node based on its type
|
|
||||||
const hydrateNode = (data: FileNode): NodeRecord => {
|
|
||||||
if (isFileCollection(data)) {
|
|
||||||
return new FileCollectionObject().fromJson(data)
|
|
||||||
} else {
|
|
||||||
return new FileEntityObject().fromJson(data as FileEntity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set all nodes for a provider/service
|
|
||||||
const setNodes = (
|
|
||||||
providerId: string,
|
providerId: string,
|
||||||
serviceId: string,
|
serviceId: string | number,
|
||||||
data: FileNode[]
|
collectionId: string | number | null,
|
||||||
) => {
|
filter?: ListFilter,
|
||||||
if (!nodes.value[providerId]) {
|
sort?: ListSort,
|
||||||
nodes.value[providerId] = {}
|
): Promise<CollectionObject[]> {
|
||||||
}
|
error.value = null
|
||||||
const hydrated: ServiceNodeStore = {}
|
try {
|
||||||
for (const nodeData of data) {
|
const sources: SourceSelector = {
|
||||||
hydrated[nodeData.id] = hydrateNode(nodeData)
|
[providerId]: {
|
||||||
}
|
[String(serviceId)]: collectionId === null
|
||||||
nodes.value[providerId][serviceId] = hydrated
|
? true
|
||||||
}
|
: { [String(collectionId)]: true },
|
||||||
|
},
|
||||||
// Add/update a single node
|
|
||||||
const addNode = (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
node: FileNode
|
|
||||||
) => {
|
|
||||||
if (!nodes.value[providerId]) {
|
|
||||||
nodes.value[providerId] = {}
|
|
||||||
}
|
|
||||||
if (!nodes.value[providerId][serviceId]) {
|
|
||||||
nodes.value[providerId][serviceId] = {}
|
|
||||||
}
|
|
||||||
nodes.value[providerId][serviceId][node.id] = hydrateNode(node)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add multiple nodes (handles both array and object formats from API)
|
|
||||||
const addNodes = (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
data: FileNode[] | Record<string, FileNode>
|
|
||||||
) => {
|
|
||||||
if (!nodes.value[providerId]) {
|
|
||||||
nodes.value[providerId] = {}
|
|
||||||
}
|
|
||||||
if (!nodes.value[providerId][serviceId]) {
|
|
||||||
nodes.value[providerId][serviceId] = {}
|
|
||||||
}
|
|
||||||
// Handle both array and object (keyed by ID) formats
|
|
||||||
const nodeArray = Array.isArray(data) ? data : Object.values(data)
|
|
||||||
for (const nodeData of nodeArray) {
|
|
||||||
nodes.value[providerId][serviceId][nodeData.id] = hydrateNode(nodeData)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove a node
|
|
||||||
const removeNode = (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
nodeId: string
|
|
||||||
) => {
|
|
||||||
if (nodes.value[providerId]?.[serviceId]) {
|
|
||||||
delete nodes.value[providerId][serviceId][nodeId]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove multiple nodes
|
|
||||||
const removeNodes = (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
nodeIds: string[]
|
|
||||||
) => {
|
|
||||||
if (nodes.value[providerId]?.[serviceId]) {
|
|
||||||
for (const id of nodeIds) {
|
|
||||||
delete nodes.value[providerId][serviceId][id]
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear all nodes for a service
|
await collectionsStore.list(sources, filter, sort)
|
||||||
const clearServiceNodes = (
|
return collectionsStore.collectionsForService(providerId, serviceId)
|
||||||
providerId: string,
|
|
||||||
serviceId: string
|
|
||||||
) => {
|
|
||||||
if (nodes.value[providerId]) {
|
|
||||||
delete nodes.value[providerId][serviceId]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear all nodes
|
|
||||||
const clearNodes = () => {
|
|
||||||
nodes.value = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sync token management
|
|
||||||
const getSyncToken = (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string
|
|
||||||
): string | undefined => {
|
|
||||||
return syncTokens.value[providerId]?.[serviceId]
|
|
||||||
}
|
|
||||||
|
|
||||||
const setSyncToken = (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
token: string
|
|
||||||
) => {
|
|
||||||
if (!syncTokens.value[providerId]) {
|
|
||||||
syncTokens.value[providerId] = {}
|
|
||||||
}
|
|
||||||
syncTokens.value[providerId][serviceId] = token
|
|
||||||
}
|
|
||||||
|
|
||||||
// ==================== API Actions ====================
|
|
||||||
|
|
||||||
// Fetch nodes (collections and entities) for a location
|
|
||||||
const fetchNodes = async (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
location?: string | null,
|
|
||||||
recursive: boolean = false,
|
|
||||||
filter?: FilterCondition[] | null,
|
|
||||||
sort?: SortCondition[] | null,
|
|
||||||
range?: RangeCondition | null
|
|
||||||
): Promise<NodeRecord[]> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
|
||||||
const data = await nodeService.list(
|
|
||||||
providerId,
|
|
||||||
serviceId,
|
|
||||||
location,
|
|
||||||
recursive,
|
|
||||||
filter,
|
|
||||||
sort,
|
|
||||||
range
|
|
||||||
)
|
|
||||||
// API returns object keyed by ID, convert to array
|
|
||||||
const nodeArray = Array.isArray(data) ? data : Object.values(data)
|
|
||||||
addNodes(providerId, serviceId, nodeArray)
|
|
||||||
return nodeArray.map(hydrateNode)
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to fetch nodes'
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch collections (folders) for a location
|
|
||||||
const fetchCollections = async (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
location?: string | null,
|
|
||||||
filter?: FilterCondition[] | null,
|
|
||||||
sort?: SortCondition[] | null
|
|
||||||
): Promise<FileCollectionObject[]> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
|
||||||
const data = await collectionService.list(providerId, serviceId, location, filter, sort)
|
|
||||||
// API returns object keyed by ID, convert to array
|
|
||||||
const collectionArray = Array.isArray(data) ? data : Object.values(data)
|
|
||||||
addNodes(providerId, serviceId, collectionArray)
|
|
||||||
return collectionArray.map(c => new FileCollectionObject().fromJson(c))
|
|
||||||
} 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
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch entities (files) for a collection
|
async function fetchEntities(
|
||||||
const fetchEntities = async (
|
|
||||||
providerId: string,
|
providerId: string,
|
||||||
serviceId: string,
|
serviceId: string | number,
|
||||||
collection: string,
|
collectionId: string | number | null,
|
||||||
filter?: FilterCondition[] | null,
|
filter?: ListFilter,
|
||||||
sort?: SortCondition[] | null,
|
sort?: ListSort,
|
||||||
range?: RangeCondition | null
|
range?: ListRange,
|
||||||
): Promise<FileEntityObject[]> => {
|
): Promise<EntityObject[]> {
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
error.value = null
|
||||||
try {
|
try {
|
||||||
const data = await entityService.list(providerId, serviceId, collection, filter, sort, range)
|
const sources: SourceSelector = {
|
||||||
// API returns object keyed by ID, convert to array
|
[providerId]: {
|
||||||
const entityArray = Array.isArray(data) ? data : Object.values(data)
|
[String(serviceId)]: collectionId === null
|
||||||
addNodes(providerId, serviceId, entityArray)
|
? true
|
||||||
return entityArray.map(e => new FileEntityObject().fromJson(e))
|
: { [String(collectionId)]: true },
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a collection (folder)
|
async function fetchNodes(
|
||||||
const createCollection = async (
|
|
||||||
providerId: string,
|
providerId: string,
|
||||||
serviceId: string,
|
serviceId: string | number,
|
||||||
location: string | null,
|
parentId: string | number | null = ROOT_ID,
|
||||||
data: Partial<FileCollection>,
|
filter?: ListFilter,
|
||||||
options?: Record<string, unknown>
|
sort?: ListSort,
|
||||||
): Promise<FileCollectionObject> => {
|
range?: ListRange,
|
||||||
loading.value = true
|
): Promise<NodeRecord[]> {
|
||||||
error.value = null
|
error.value = null
|
||||||
try {
|
try {
|
||||||
const created = await collectionService.create(providerId, serviceId, location, data, options)
|
await Promise.all([
|
||||||
addNode(providerId, serviceId, created)
|
fetchCollections(providerId, serviceId, parentId, filter, sort),
|
||||||
return new FileCollectionObject().fromJson(created)
|
fetchEntities(providerId, serviceId, parentId, filter, sort, range),
|
||||||
|
])
|
||||||
|
|
||||||
|
return getChildren(providerId, serviceId, parentId)
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof Error ? e.message : 'Failed to fetch nodes'
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createCollection(
|
||||||
|
providerId: string,
|
||||||
|
serviceId: string | number,
|
||||||
|
parentCollectionId: string | number | null,
|
||||||
|
properties: CollectionMutableProperties,
|
||||||
|
): Promise<CollectionObject> {
|
||||||
|
error.value = null
|
||||||
|
try {
|
||||||
|
return await collectionsStore.create(providerId, serviceId, parentCollectionId, 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
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create an entity (file)
|
async function updateCollection(
|
||||||
const createEntity = async (
|
|
||||||
providerId: string,
|
providerId: string,
|
||||||
serviceId: string,
|
serviceId: string | number,
|
||||||
collection: string | null,
|
identifier: string | number,
|
||||||
data: Partial<FileEntity>,
|
properties: CollectionMutableProperties,
|
||||||
options?: Record<string, unknown>
|
): Promise<CollectionObject> {
|
||||||
): Promise<FileEntityObject> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
error.value = null
|
||||||
try {
|
try {
|
||||||
const created = await entityService.create(providerId, serviceId, collection, data, options)
|
return await collectionsStore.update(providerId, serviceId, identifier, properties)
|
||||||
addNode(providerId, serviceId, created)
|
} catch (e) {
|
||||||
return new FileEntityObject().fromJson(created)
|
error.value = e instanceof Error ? e.message : 'Failed to update collection'
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteCollection(
|
||||||
|
providerId: string,
|
||||||
|
serviceId: string | number,
|
||||||
|
identifier: string | number,
|
||||||
|
): Promise<boolean> {
|
||||||
|
error.value = null
|
||||||
|
try {
|
||||||
|
const response = await collectionsStore.delete(providerId, serviceId, identifier)
|
||||||
|
return response.success
|
||||||
|
} catch (e) {
|
||||||
|
error.value = e instanceof Error ? e.message : 'Failed to delete collection'
|
||||||
|
throw e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createEntity(
|
||||||
|
providerId: string,
|
||||||
|
serviceId: string | number,
|
||||||
|
collectionId: string | number,
|
||||||
|
properties: DocumentInterface,
|
||||||
|
options?: Record<string, unknown>,
|
||||||
|
): Promise<EntityObject> {
|
||||||
|
error.value = null
|
||||||
|
try {
|
||||||
|
return await entitiesStore.create(providerId, serviceId, collectionId, 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
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify a collection
|
async function updateEntity(
|
||||||
const modifyCollection = async (
|
|
||||||
providerId: string,
|
providerId: string,
|
||||||
serviceId: string,
|
serviceId: string | number,
|
||||||
identifier: string,
|
collectionId: string | number,
|
||||||
data: Partial<FileCollection>
|
identifier: string | number,
|
||||||
): Promise<FileCollectionObject> => {
|
properties: DocumentInterface,
|
||||||
loading.value = true
|
): Promise<EntityObject> {
|
||||||
error.value = null
|
error.value = null
|
||||||
try {
|
try {
|
||||||
const modified = await collectionService.modify(providerId, serviceId, identifier, data)
|
return await entitiesStore.update(providerId, serviceId, collectionId, identifier, properties)
|
||||||
addNode(providerId, serviceId, modified)
|
|
||||||
return new FileCollectionObject().fromJson(modified)
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to modify collection'
|
error.value = e instanceof Error ? e.message : 'Failed to update entity'
|
||||||
throw e
|
throw e
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify an entity
|
async function deleteEntity(
|
||||||
const modifyEntity = async (
|
|
||||||
providerId: string,
|
providerId: string,
|
||||||
serviceId: string,
|
serviceId: string | number,
|
||||||
collection: string | null,
|
collectionId: string | number,
|
||||||
identifier: string,
|
identifier: string | number,
|
||||||
data: Partial<FileEntity>
|
): Promise<boolean> {
|
||||||
): Promise<FileEntityObject> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
error.value = null
|
||||||
try {
|
try {
|
||||||
const modified = await entityService.modify(providerId, serviceId, collection, identifier, data)
|
const response = await entitiesStore.delete(providerId, serviceId, collectionId, identifier)
|
||||||
addNode(providerId, serviceId, modified)
|
return response.success
|
||||||
return new FileEntityObject().fromJson(modified)
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to modify entity'
|
error.value = e instanceof Error ? e.message : 'Failed to delete entity'
|
||||||
throw e
|
throw e
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destroy a collection
|
async function readEntity(
|
||||||
const destroyCollection = async (
|
|
||||||
providerId: string,
|
providerId: string,
|
||||||
serviceId: string,
|
serviceId: string | number,
|
||||||
identifier: string
|
collectionId: string | number,
|
||||||
): Promise<boolean> => {
|
identifier: string | number,
|
||||||
loading.value = true
|
): Promise<string | null> {
|
||||||
error.value = null
|
error.value = null
|
||||||
try {
|
try {
|
||||||
const success = await collectionService.destroy(providerId, serviceId, identifier)
|
return await entitiesStore.read(providerId, serviceId, collectionId, identifier)
|
||||||
if (success) {
|
|
||||||
removeNode(providerId, serviceId, identifier)
|
|
||||||
}
|
|
||||||
return success
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to destroy collection'
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Destroy an entity
|
|
||||||
const destroyEntity = async (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
collection: string | null,
|
|
||||||
identifier: string
|
|
||||||
): Promise<boolean> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
|
||||||
const success = await entityService.destroy(providerId, serviceId, collection, identifier)
|
|
||||||
if (success) {
|
|
||||||
removeNode(providerId, serviceId, identifier)
|
|
||||||
}
|
|
||||||
return success
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to destroy entity'
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy a collection
|
|
||||||
const copyCollection = async (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
identifier: string,
|
|
||||||
location?: string | null
|
|
||||||
): Promise<FileCollectionObject> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
|
||||||
const copied = await collectionService.copy(providerId, serviceId, identifier, location)
|
|
||||||
addNode(providerId, serviceId, copied)
|
|
||||||
return new FileCollectionObject().fromJson(copied)
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to copy collection'
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy an entity
|
|
||||||
const copyEntity = async (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
collection: string | null,
|
|
||||||
identifier: string,
|
|
||||||
destination?: string | null
|
|
||||||
): Promise<FileEntityObject> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
|
||||||
const copied = await entityService.copy(providerId, serviceId, collection, identifier, destination)
|
|
||||||
addNode(providerId, serviceId, copied)
|
|
||||||
return new FileEntityObject().fromJson(copied)
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to copy entity'
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move a collection
|
|
||||||
const moveCollection = async (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
identifier: string,
|
|
||||||
location?: string | null
|
|
||||||
): Promise<FileCollectionObject> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
|
||||||
const moved = await collectionService.move(providerId, serviceId, identifier, location)
|
|
||||||
addNode(providerId, serviceId, moved)
|
|
||||||
return new FileCollectionObject().fromJson(moved)
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to move collection'
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Move an entity
|
|
||||||
const moveEntity = async (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
collection: string | null,
|
|
||||||
identifier: string,
|
|
||||||
destination?: string | null
|
|
||||||
): Promise<FileEntityObject> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
|
||||||
const moved = await entityService.move(providerId, serviceId, collection, identifier, destination)
|
|
||||||
addNode(providerId, serviceId, moved)
|
|
||||||
return new FileEntityObject().fromJson(moved)
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to move entity'
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read entity content
|
|
||||||
const readEntity = async (
|
|
||||||
providerId: string,
|
|
||||||
serviceId: string,
|
|
||||||
collection: string,
|
|
||||||
identifier: string
|
|
||||||
): Promise<string | null> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
|
||||||
const result = await entityService.read(providerId, serviceId, collection, identifier)
|
|
||||||
return result.content
|
|
||||||
} 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
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write entity content
|
async function writeEntity(
|
||||||
const writeEntity = async (
|
|
||||||
providerId: string,
|
providerId: string,
|
||||||
serviceId: string,
|
serviceId: string | number,
|
||||||
collection: string | null,
|
collectionId: string | number,
|
||||||
identifier: string,
|
identifier: string | number,
|
||||||
content: string
|
content: string,
|
||||||
): Promise<number> => {
|
): Promise<number> {
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
error.value = null
|
||||||
try {
|
try {
|
||||||
return await entityService.write(providerId, serviceId, collection, identifier, content)
|
return await entitiesStore.write(providerId, serviceId, collectionId, identifier, 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
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sync delta changes
|
function clearServiceNodes(providerId: string, serviceId: string | number): void {
|
||||||
const syncDelta = async (
|
collectionsStore.clearService(providerId, serviceId)
|
||||||
providerId: string,
|
entitiesStore.clearService(providerId, serviceId)
|
||||||
serviceId: string,
|
}
|
||||||
location: string | null,
|
|
||||||
signature: string,
|
function clearNodes(): void {
|
||||||
recursive: boolean = false,
|
collectionsStore.clearAll()
|
||||||
detail: 'ids' | 'full' = 'full'
|
entitiesStore.clearAll()
|
||||||
): Promise<void> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
|
||||||
const delta = await nodeService.delta(providerId, serviceId, location, signature, recursive, detail)
|
|
||||||
|
|
||||||
// Handle removed nodes
|
|
||||||
if (delta.removed.length > 0) {
|
|
||||||
removeNodes(providerId, serviceId, delta.removed)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle added/modified nodes
|
|
||||||
if (detail === 'full') {
|
|
||||||
const addedNodes = delta.added as FileNode[]
|
|
||||||
const modifiedNodes = delta.modified as FileNode[]
|
|
||||||
if (addedNodes.length > 0) {
|
|
||||||
addNodes(providerId, serviceId, addedNodes)
|
|
||||||
}
|
|
||||||
if (modifiedNodes.length > 0) {
|
|
||||||
addNodes(providerId, serviceId, modifiedNodes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update sync token
|
|
||||||
if (delta.signature) {
|
|
||||||
setSyncToken(providerId, serviceId, delta.signature)
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to sync delta'
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
loading.value = false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// State
|
transceiving: readonly(transceiving),
|
||||||
nodes,
|
error: readonly(error),
|
||||||
syncTokens,
|
|
||||||
loading,
|
|
||||||
error,
|
|
||||||
// Constants
|
|
||||||
ROOT_ID,
|
ROOT_ID,
|
||||||
// Computed
|
|
||||||
nodeList,
|
nodeList,
|
||||||
collectionList,
|
collectionList,
|
||||||
entityList,
|
entityList,
|
||||||
// Getters
|
|
||||||
getNode,
|
getNode,
|
||||||
getServiceNodes,
|
getServiceNodes,
|
||||||
getChildren,
|
getChildren,
|
||||||
@@ -648,40 +324,18 @@ export const useNodesStore = defineStore('fileNodes', () => {
|
|||||||
getChildEntities,
|
getChildEntities,
|
||||||
getPath,
|
getPath,
|
||||||
isRoot,
|
isRoot,
|
||||||
// Setters
|
|
||||||
setNodes,
|
|
||||||
addNode,
|
|
||||||
addNodes,
|
|
||||||
removeNode,
|
|
||||||
removeNodes,
|
|
||||||
clearServiceNodes,
|
|
||||||
clearNodes,
|
|
||||||
// Sync
|
|
||||||
getSyncToken,
|
|
||||||
setSyncToken,
|
|
||||||
// API Actions - Fetch
|
|
||||||
fetchNodes,
|
fetchNodes,
|
||||||
fetchCollections,
|
fetchCollections,
|
||||||
fetchEntities,
|
fetchEntities,
|
||||||
// API Actions - Create
|
|
||||||
createCollection,
|
createCollection,
|
||||||
|
updateCollection,
|
||||||
|
deleteCollection,
|
||||||
createEntity,
|
createEntity,
|
||||||
// API Actions - Modify
|
updateEntity,
|
||||||
modifyCollection,
|
deleteEntity,
|
||||||
modifyEntity,
|
|
||||||
// API Actions - Destroy
|
|
||||||
destroyCollection,
|
|
||||||
destroyEntity,
|
|
||||||
// API Actions - Copy
|
|
||||||
copyCollection,
|
|
||||||
copyEntity,
|
|
||||||
// API Actions - Move
|
|
||||||
moveCollection,
|
|
||||||
moveEntity,
|
|
||||||
// API Actions - Content
|
|
||||||
readEntity,
|
readEntity,
|
||||||
writeEntity,
|
writeEntity,
|
||||||
// API Actions - Sync
|
clearServiceNodes,
|
||||||
syncDelta,
|
clearNodes,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,104 +1,142 @@
|
|||||||
|
/**
|
||||||
|
* Providers Store
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ref, computed, readonly } from 'vue'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ref, computed } from 'vue'
|
import { providerService } from '../services'
|
||||||
import type { Ref, ComputedRef } from 'vue'
|
|
||||||
import type { ProviderInterface, ProviderRecord, ProviderCapabilitiesInterface } from '../types/provider'
|
|
||||||
import type { SourceSelector } from '../types/common'
|
|
||||||
import { providerService } from '../services/providerService'
|
|
||||||
import { ProviderObject } from '../models/provider'
|
import { ProviderObject } from '../models/provider'
|
||||||
|
import type { SourceSelector } from '../types'
|
||||||
|
|
||||||
export const useProvidersStore = defineStore('fileProviders', () => {
|
export const useProvidersStore = defineStore('documentsProvidersStore', () => {
|
||||||
const providers: Ref<Record<string, ProviderObject>> = ref({})
|
// State
|
||||||
const loading = ref(false)
|
const _providers = ref<Record<string, ProviderObject>>({})
|
||||||
const error: Ref<string | null> = ref(null)
|
const transceiving = ref(false)
|
||||||
const initialized = ref(false)
|
|
||||||
|
|
||||||
const providerList: ComputedRef<ProviderObject[]> = computed(() =>
|
/**
|
||||||
Object.values(providers.value)
|
* Get count of providers in store
|
||||||
)
|
*/
|
||||||
|
const count = computed(() => Object.keys(_providers.value).length)
|
||||||
|
|
||||||
const providerIds: ComputedRef<string[]> = computed(() =>
|
/**
|
||||||
Object.keys(providers.value)
|
* Check if any providers are present in store
|
||||||
)
|
*/
|
||||||
|
const has = computed(() => count.value > 0)
|
||||||
|
|
||||||
const getProvider = (id: string): ProviderObject | undefined => {
|
/**
|
||||||
return providers.value[id]
|
* Get all providers present in store
|
||||||
}
|
*/
|
||||||
|
const providers = computed(() => Object.values(_providers.value))
|
||||||
|
|
||||||
const hasProvider = (id: string): boolean => {
|
/**
|
||||||
return id in providers.value
|
* Get a specific provider from store, with optional retrieval
|
||||||
}
|
*
|
||||||
|
* @param identifier - Provider identifier
|
||||||
const isCapable = (providerId: string, capability: keyof ProviderCapabilitiesInterface): boolean => {
|
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
|
||||||
const provider = providers.value[providerId]
|
*
|
||||||
return provider ? provider.capable(capability) : false
|
* @returns Provider object or null
|
||||||
}
|
*/
|
||||||
|
function provider(identifier: string, retrieve: boolean = false): ProviderObject | null {
|
||||||
const setProviders = (data: ProviderRecord) => {
|
if (retrieve === true && !_providers.value[identifier]) {
|
||||||
const hydrated: Record<string, ProviderObject> = {}
|
console.debug(`[Documents Manager][Store] - Force fetching provider "${identifier}"`)
|
||||||
for (const [id, providerData] of Object.entries(data)) {
|
fetch(identifier)
|
||||||
hydrated[id] = new ProviderObject().fromJson(providerData)
|
|
||||||
}
|
}
|
||||||
providers.value = hydrated
|
|
||||||
initialized.value = true
|
return _providers.value[identifier] || null
|
||||||
}
|
}
|
||||||
|
|
||||||
const addProvider = (id: string, provider: ProviderInterface) => {
|
// Actions
|
||||||
providers.value[id] = new ProviderObject().fromJson(provider)
|
|
||||||
}
|
|
||||||
|
|
||||||
const removeProvider = (id: string) => {
|
/**
|
||||||
delete providers.value[id]
|
* Retrieve all or specific providers, optionally filtered by source selector
|
||||||
}
|
*
|
||||||
|
* @param request - list request parameters
|
||||||
const clearProviders = () => {
|
*
|
||||||
providers.value = {}
|
* @returns Promise with provider object list keyed by provider identifier
|
||||||
initialized.value = false
|
*/
|
||||||
}
|
async function list(sources?: SourceSelector): Promise<Record<string, ProviderObject>> {
|
||||||
|
transceiving.value = true
|
||||||
// API actions
|
|
||||||
const fetchProviders = async (sources?: SourceSelector): Promise<void> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
try {
|
||||||
const data = await providerService.list(sources)
|
const providers = await providerService.list({ sources })
|
||||||
setProviders(data)
|
|
||||||
} catch (e) {
|
// Merge retrieved providers into state
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to fetch providers'
|
_providers.value = { ..._providers.value, ...providers }
|
||||||
throw e
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully retrieved', Object.keys(providers).length, 'providers')
|
||||||
|
return providers
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to retrieve providers:', error)
|
||||||
|
throw error
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
transceiving.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkProviderExtant = async (sources: SourceSelector): Promise<Record<string, boolean>> => {
|
/**
|
||||||
|
* Retrieve a specific provider by identifier
|
||||||
|
*
|
||||||
|
* @param identifier - provider identifier
|
||||||
|
*
|
||||||
|
* @returns Promise with provider object
|
||||||
|
*/
|
||||||
|
async function fetch(identifier: string): Promise<ProviderObject> {
|
||||||
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
return await providerService.extant(sources)
|
const provider = await providerService.fetch({ identifier })
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to check providers'
|
// Merge fetched provider into state
|
||||||
throw e
|
_providers.value[provider.identifier] = provider
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully fetched provider:', provider.identifier)
|
||||||
|
return provider
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to fetch provider:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve provider availability status for a given source selector
|
||||||
|
*
|
||||||
|
* @param sources - source selector to check availability for
|
||||||
|
*
|
||||||
|
* @returns Promise with provider availability status
|
||||||
|
*/
|
||||||
|
async function extant(sources: SourceSelector) {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await providerService.extant({ sources })
|
||||||
|
|
||||||
|
Object.entries(response).forEach(([providerId, providerStatus]) => {
|
||||||
|
if (providerStatus === false) {
|
||||||
|
delete _providers.value[providerId]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'providers')
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to check providers:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return public API
|
||||||
return {
|
return {
|
||||||
// State
|
// State
|
||||||
|
transceiving: readonly(transceiving),
|
||||||
|
// computed
|
||||||
|
count,
|
||||||
|
has,
|
||||||
providers,
|
providers,
|
||||||
loading,
|
provider,
|
||||||
error,
|
// functions
|
||||||
initialized,
|
list,
|
||||||
// Computed
|
fetch,
|
||||||
providerList,
|
extant,
|
||||||
providerIds,
|
|
||||||
// Getters
|
|
||||||
getProvider,
|
|
||||||
hasProvider,
|
|
||||||
isCapable,
|
|
||||||
// Setters
|
|
||||||
setProviders,
|
|
||||||
addProvider,
|
|
||||||
removeProvider,
|
|
||||||
clearProviders,
|
|
||||||
// Actions
|
|
||||||
fetchProviders,
|
|
||||||
checkProviderExtant,
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,131 +1,259 @@
|
|||||||
|
/**
|
||||||
|
* Services Store
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { ref, computed, readonly } from 'vue'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { ref, computed } from 'vue'
|
import { serviceService } from '../services'
|
||||||
import type { Ref, ComputedRef } from 'vue'
|
|
||||||
import type { ServiceInterface, ServiceRecord } from '../types/service'
|
|
||||||
import type { SourceSelector } from '../types/common'
|
|
||||||
import { serviceService } from '../services/serviceService'
|
|
||||||
import { ServiceObject } from '../models/service'
|
import { ServiceObject } from '../models/service'
|
||||||
|
import type {
|
||||||
|
SourceSelector,
|
||||||
|
ServiceInterface,
|
||||||
|
} from '../types'
|
||||||
|
|
||||||
// Nested structure: provider -> service -> ServiceObject
|
export const useServicesStore = defineStore('documentsServicesStore', () => {
|
||||||
type ServiceStore = Record<string, Record<string, ServiceObject>>
|
// State
|
||||||
|
const _services = ref<Record<string, ServiceObject>>({})
|
||||||
|
const transceiving = ref(false)
|
||||||
|
|
||||||
export const useServicesStore = defineStore('fileServices', () => {
|
/**
|
||||||
const services: Ref<ServiceStore> = ref({})
|
* Get count of services in store
|
||||||
const loading = ref(false)
|
*/
|
||||||
const error: Ref<string | null> = ref(null)
|
const count = computed(() => Object.keys(_services.value).length)
|
||||||
const initialized = ref(false)
|
|
||||||
|
|
||||||
const serviceList: ComputedRef<ServiceObject[]> = computed(() => {
|
/**
|
||||||
const result: ServiceObject[] = []
|
* Check if any services are present in store
|
||||||
Object.values(services.value).forEach(providerServices => {
|
*/
|
||||||
result.push(...Object.values(providerServices))
|
const has = computed(() => count.value > 0)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all services present in store
|
||||||
|
*/
|
||||||
|
const services = computed(() => Object.values(_services.value))
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all services present in store grouped by provider
|
||||||
|
*/
|
||||||
|
const servicesByProvider = computed(() => {
|
||||||
|
const groups: Record<string, ServiceObject[]> = {}
|
||||||
|
|
||||||
|
Object.values(_services.value).forEach((service) => {
|
||||||
|
const providerServices = (groups[service.provider] ??= [])
|
||||||
|
providerServices.push(service)
|
||||||
})
|
})
|
||||||
return result
|
|
||||||
|
return groups
|
||||||
})
|
})
|
||||||
|
|
||||||
const getService = (providerId: string, serviceId: string): ServiceObject | undefined => {
|
/**
|
||||||
return services.value[providerId]?.[serviceId]
|
* Get a specific service from store, with optional retrieval
|
||||||
}
|
*
|
||||||
|
* @param provider - provider identifier
|
||||||
const hasService = (providerId: string, serviceId: string): boolean => {
|
* @param identifier - service identifier
|
||||||
return !!services.value[providerId]?.[serviceId]
|
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
|
||||||
}
|
*
|
||||||
|
* @returns Service object or null
|
||||||
const getProviderServices = (providerId: string): ServiceObject[] => {
|
*/
|
||||||
return Object.values(services.value[providerId] || {})
|
function service(provider: string, identifier: string | number, retrieve: boolean = false): ServiceObject | null {
|
||||||
}
|
const key = identifierKey(provider, identifier)
|
||||||
|
if (retrieve === true && !_services.value[key]) {
|
||||||
const getRootId = (providerId: string, serviceId: string): string | undefined => {
|
console.debug(`[Documents Manager][Store] - Force fetching service "${key}"`)
|
||||||
return services.value[providerId]?.[serviceId]?.rootId
|
fetch(provider, identifier)
|
||||||
}
|
|
||||||
|
|
||||||
const setServices = (data: ServiceRecord) => {
|
|
||||||
const hydrated: ServiceStore = {}
|
|
||||||
for (const [id, serviceData] of Object.entries(data)) {
|
|
||||||
const providerId = serviceData.provider
|
|
||||||
if (!hydrated[providerId]) {
|
|
||||||
hydrated[providerId] = {}
|
|
||||||
}
|
|
||||||
hydrated[providerId][id] = new ServiceObject().fromJson(serviceData)
|
|
||||||
}
|
}
|
||||||
services.value = hydrated
|
|
||||||
initialized.value = true
|
return _services.value[key] || null
|
||||||
}
|
}
|
||||||
|
|
||||||
const addService = (providerId: string, serviceId: string, service: ServiceInterface) => {
|
/**
|
||||||
if (!services.value[providerId]) {
|
* Unique key for a service
|
||||||
services.value[providerId] = {}
|
*/
|
||||||
}
|
function identifierKey(provider: string, identifier: string | number | null): string {
|
||||||
services.value[providerId][serviceId] = new ServiceObject().fromJson(service)
|
return `${provider}:${identifier ?? ''}`
|
||||||
}
|
}
|
||||||
|
|
||||||
const removeService = (providerId: string, serviceId: string) => {
|
// Actions
|
||||||
if (services.value[providerId]) {
|
|
||||||
delete services.value[providerId][serviceId]
|
/**
|
||||||
}
|
* Retrieve all or specific services, optionally filtered by source selector
|
||||||
}
|
*
|
||||||
|
* @param sources - optional source selector
|
||||||
const clearServices = () => {
|
*
|
||||||
services.value = {}
|
* @returns Promise with service object list keyed by provider and service identifier
|
||||||
initialized.value = false
|
*/
|
||||||
}
|
async function list(sources?: SourceSelector): Promise<Record<string, ServiceObject>> {
|
||||||
|
transceiving.value = true
|
||||||
// API actions
|
|
||||||
const fetchServices = async (sources?: SourceSelector): Promise<void> => {
|
|
||||||
loading.value = true
|
|
||||||
error.value = null
|
|
||||||
try {
|
try {
|
||||||
const data = await serviceService.list(sources)
|
const response = await serviceService.list({ sources })
|
||||||
setServices(data)
|
|
||||||
} catch (e) {
|
// Flatten nested structure: provider-id: { service-id: object } -> "provider-id:service-id": object
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to fetch services'
|
const services: Record<string, ServiceObject> = {}
|
||||||
throw e
|
Object.entries(response).forEach(([_providerId, providerServices]) => {
|
||||||
|
Object.entries(providerServices).forEach(([_serviceId, serviceObj]) => {
|
||||||
|
const key = identifierKey(serviceObj.provider, serviceObj.identifier)
|
||||||
|
services[key] = serviceObj
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Merge retrieved services into state
|
||||||
|
_services.value = { ..._services.value, ...services }
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully retrieved', Object.keys(services).length, 'services')
|
||||||
|
return services
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to retrieve services:', error)
|
||||||
|
throw error
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
transceiving.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkServiceExtant = async (sources: SourceSelector): Promise<Record<string, boolean>> => {
|
/**
|
||||||
|
* Retrieve a specific service by provider and identifier
|
||||||
|
*
|
||||||
|
* @param provider - provider identifier
|
||||||
|
* @param identifier - service identifier
|
||||||
|
*
|
||||||
|
* @returns Promise with service object
|
||||||
|
*/
|
||||||
|
async function fetch(provider: string, identifier: string | number): Promise<ServiceObject> {
|
||||||
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
return await serviceService.extant(sources)
|
const service = await serviceService.fetch({ provider, identifier })
|
||||||
} catch (e) {
|
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to check services'
|
// Merge fetched service into state
|
||||||
throw e
|
const key = identifierKey(service.provider, service.identifier)
|
||||||
|
_services.value[key] = service
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully fetched service:', key)
|
||||||
|
return service
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to fetch service:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fetchService = async (providerId: string, serviceId: string): Promise<ServiceObject> => {
|
/**
|
||||||
|
* Retrieve service availability status for a given source selector
|
||||||
|
*
|
||||||
|
* @param sources - source selector to check availability for
|
||||||
|
*
|
||||||
|
* @returns Promise with service availability status
|
||||||
|
*/
|
||||||
|
async function extant(sources: SourceSelector) {
|
||||||
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const data = await serviceService.fetch(providerId, serviceId)
|
const response = await serviceService.extant({ sources })
|
||||||
addService(providerId, serviceId, data)
|
|
||||||
return services.value[providerId][serviceId]
|
console.debug('[Documents Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'services')
|
||||||
} catch (e) {
|
return response
|
||||||
error.value = e instanceof Error ? e.message : 'Failed to fetch service'
|
} catch (error: any) {
|
||||||
throw e
|
console.error('[Documents Manager][Store] - Failed to check services:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new service with given provider and data
|
||||||
|
*
|
||||||
|
* @param provider - provider identifier for the new service
|
||||||
|
* @param data - partial service data for creation
|
||||||
|
*
|
||||||
|
* @returns Promise with created service object
|
||||||
|
*/
|
||||||
|
async function create(provider: string, data: Partial<ServiceInterface>): Promise<ServiceObject> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const service = await serviceService.create({ provider, data })
|
||||||
|
|
||||||
|
// Merge created service into state
|
||||||
|
const key = identifierKey(service.provider, service.identifier)
|
||||||
|
_services.value[key] = service
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully created service:', key)
|
||||||
|
return service
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to create service:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing service with given provider, identifier, and data
|
||||||
|
*
|
||||||
|
* @param provider - provider identifier for the service to update
|
||||||
|
* @param identifier - service identifier for the service to update
|
||||||
|
* @param data - partial service data for update
|
||||||
|
*
|
||||||
|
* @returns Promise with updated service object
|
||||||
|
*/
|
||||||
|
async function update(provider: string, identifier: string | number, data: Partial<ServiceInterface>): Promise<ServiceObject> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const service = await serviceService.update({ provider, identifier, data })
|
||||||
|
|
||||||
|
// Merge updated service into state
|
||||||
|
const key = identifierKey(service.provider, service.identifier)
|
||||||
|
_services.value[key] = service
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully updated service:', key)
|
||||||
|
return service
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to update service:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a service by provider and identifier
|
||||||
|
*
|
||||||
|
* @param provider - provider identifier for the service to delete
|
||||||
|
* @param identifier - service identifier for the service to delete
|
||||||
|
*
|
||||||
|
* @returns Promise with deletion result
|
||||||
|
*/
|
||||||
|
async function remove(provider: string, identifier: string | number): Promise<any> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
await serviceService.delete({ provider, identifier })
|
||||||
|
|
||||||
|
// Remove deleted service from state
|
||||||
|
const key = identifierKey(provider, identifier)
|
||||||
|
delete _services.value[key]
|
||||||
|
|
||||||
|
console.debug('[Documents Manager][Store] - Successfully deleted service:', key)
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Documents Manager][Store] - Failed to delete service:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return public API
|
||||||
return {
|
return {
|
||||||
// State
|
// State (readonly)
|
||||||
services,
|
transceiving: readonly(transceiving),
|
||||||
loading,
|
|
||||||
error,
|
|
||||||
initialized,
|
|
||||||
// Computed
|
|
||||||
serviceList,
|
|
||||||
// Getters
|
// Getters
|
||||||
getService,
|
count,
|
||||||
hasService,
|
has,
|
||||||
getProviderServices,
|
services,
|
||||||
getRootId,
|
servicesByProvider,
|
||||||
// Setters
|
|
||||||
setServices,
|
|
||||||
addService,
|
|
||||||
removeService,
|
|
||||||
clearServices,
|
|
||||||
// Actions
|
// Actions
|
||||||
fetchServices,
|
service,
|
||||||
checkServiceExtant,
|
list,
|
||||||
fetchService,
|
fetch,
|
||||||
|
extant,
|
||||||
|
create,
|
||||||
|
update,
|
||||||
|
delete: remove,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
262
src/types/api.ts
262
src/types/api.ts
@@ -1,262 +0,0 @@
|
|||||||
/**
|
|
||||||
* File Manager API Types - Request and Response interfaces
|
|
||||||
*/
|
|
||||||
|
|
||||||
import type { SourceSelector, FilterCondition, SortCondition, RangeCondition, ApiResponse } from '@/types/common';
|
|
||||||
import type { ProviderRecord } from '@/types/provider';
|
|
||||||
import type { ServiceInterface, ServiceRecord } from '@/types/service';
|
|
||||||
import type { FileCollection, FileEntity, FileNode } from '@/types/node';
|
|
||||||
|
|
||||||
// ==================== Provider Types ====================
|
|
||||||
|
|
||||||
export type ProviderListResponse = ApiResponse<ProviderRecord>;
|
|
||||||
|
|
||||||
export interface ProviderExtantRequest {
|
|
||||||
sources: SourceSelector;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ProviderExtantResponse = ApiResponse<Record<string, boolean>>;
|
|
||||||
|
|
||||||
// ==================== Service Types ====================
|
|
||||||
|
|
||||||
export type ServiceListResponse = ApiResponse<ServiceRecord>;
|
|
||||||
|
|
||||||
export interface ServiceExtantRequest {
|
|
||||||
sources: SourceSelector;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ServiceExtantResponse = ApiResponse<Record<string, boolean>>;
|
|
||||||
|
|
||||||
export interface ServiceFetchRequest {
|
|
||||||
provider: string;
|
|
||||||
identifier: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type ServiceFetchResponse = ApiResponse<ServiceInterface>;
|
|
||||||
|
|
||||||
// ==================== Collection Types ====================
|
|
||||||
|
|
||||||
export interface CollectionListRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
location?: string | null;
|
|
||||||
filter?: FilterCondition[] | null;
|
|
||||||
sort?: SortCondition[] | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CollectionListResponse = ApiResponse<FileCollection[]>;
|
|
||||||
|
|
||||||
export interface CollectionExtantRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
identifier: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CollectionExtantResponse = ApiResponse<{ extant: boolean }>;
|
|
||||||
|
|
||||||
export interface CollectionFetchRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
identifier: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CollectionFetchResponse = ApiResponse<FileCollection>;
|
|
||||||
|
|
||||||
export interface CollectionCreateRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
location?: string | null;
|
|
||||||
data: Partial<FileCollection>;
|
|
||||||
options?: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CollectionCreateResponse = ApiResponse<FileCollection>;
|
|
||||||
|
|
||||||
export interface CollectionModifyRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
identifier: string;
|
|
||||||
data: Partial<FileCollection>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CollectionModifyResponse = ApiResponse<FileCollection>;
|
|
||||||
|
|
||||||
export interface CollectionDestroyRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
identifier: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CollectionDestroyResponse = ApiResponse<{ success: boolean }>;
|
|
||||||
|
|
||||||
export interface CollectionCopyRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
identifier: string;
|
|
||||||
location?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CollectionCopyResponse = ApiResponse<FileCollection>;
|
|
||||||
|
|
||||||
export interface CollectionMoveRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
identifier: string;
|
|
||||||
location?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CollectionMoveResponse = ApiResponse<FileCollection>;
|
|
||||||
|
|
||||||
// ==================== Entity Types ====================
|
|
||||||
|
|
||||||
export interface EntityListRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection: string;
|
|
||||||
filter?: FilterCondition[] | null;
|
|
||||||
sort?: SortCondition[] | null;
|
|
||||||
range?: RangeCondition | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityListResponse = ApiResponse<FileEntity[]>;
|
|
||||||
|
|
||||||
export interface EntityDeltaRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection: string;
|
|
||||||
signature: string;
|
|
||||||
detail?: 'ids' | 'full';
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EntityDeltaResult {
|
|
||||||
added: string[] | FileEntity[];
|
|
||||||
modified: string[] | FileEntity[];
|
|
||||||
removed: string[];
|
|
||||||
signature: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityDeltaResponse = ApiResponse<EntityDeltaResult>;
|
|
||||||
|
|
||||||
export interface EntityExtantRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection: string;
|
|
||||||
identifiers: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityExtantResponse = ApiResponse<Record<string, boolean>>;
|
|
||||||
|
|
||||||
export interface EntityFetchRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection: string;
|
|
||||||
identifiers: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityFetchResponse = ApiResponse<FileEntity[]>;
|
|
||||||
|
|
||||||
export interface EntityReadRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection: string;
|
|
||||||
identifier: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EntityReadResult {
|
|
||||||
content: string | null;
|
|
||||||
encoding: 'base64';
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityReadResponse = ApiResponse<EntityReadResult>;
|
|
||||||
|
|
||||||
export interface EntityCreateRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection?: string | null;
|
|
||||||
data: Partial<FileEntity>;
|
|
||||||
options?: Record<string, unknown>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityCreateResponse = ApiResponse<FileEntity>;
|
|
||||||
|
|
||||||
export interface EntityModifyRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection?: string | null;
|
|
||||||
identifier: string;
|
|
||||||
data: Partial<FileEntity>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityModifyResponse = ApiResponse<FileEntity>;
|
|
||||||
|
|
||||||
export interface EntityDestroyRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection?: string | null;
|
|
||||||
identifier: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityDestroyResponse = ApiResponse<{ success: boolean }>;
|
|
||||||
|
|
||||||
export interface EntityCopyRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection?: string | null;
|
|
||||||
identifier: string;
|
|
||||||
destination?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityCopyResponse = ApiResponse<FileEntity>;
|
|
||||||
|
|
||||||
export interface EntityMoveRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection?: string | null;
|
|
||||||
identifier: string;
|
|
||||||
destination?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityMoveResponse = ApiResponse<FileEntity>;
|
|
||||||
|
|
||||||
export interface EntityWriteRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
collection?: string | null;
|
|
||||||
identifier: string;
|
|
||||||
content: string;
|
|
||||||
encoding?: 'base64';
|
|
||||||
}
|
|
||||||
|
|
||||||
export type EntityWriteResponse = ApiResponse<{ bytesWritten: number }>;
|
|
||||||
|
|
||||||
// ==================== Node Types (Unified/Recursive) ====================
|
|
||||||
|
|
||||||
export interface NodeListRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
location?: string | null;
|
|
||||||
recursive?: boolean;
|
|
||||||
filter?: FilterCondition[] | null;
|
|
||||||
sort?: SortCondition[] | null;
|
|
||||||
range?: RangeCondition | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type NodeListResponse = ApiResponse<FileNode[]>;
|
|
||||||
|
|
||||||
export interface NodeDeltaRequest {
|
|
||||||
provider: string;
|
|
||||||
service: string;
|
|
||||||
location?: string | null;
|
|
||||||
signature: string;
|
|
||||||
recursive?: boolean;
|
|
||||||
detail?: 'ids' | 'full';
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface NodeDeltaResult {
|
|
||||||
added: string[] | FileNode[];
|
|
||||||
modified: string[] | FileNode[];
|
|
||||||
removed: string[];
|
|
||||||
signature: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type NodeDeltaResponse = ApiResponse<NodeDeltaResult>;
|
|
||||||
150
src/types/collection.ts
Normal file
150
src/types/collection.ts
Normal file
@@ -0,0 +1,150 @@
|
|||||||
|
/**
|
||||||
|
* Collection type definitions
|
||||||
|
*/
|
||||||
|
import type { ListFilter, ListSort, SourceSelector } from './common';
|
||||||
|
|
||||||
|
|
||||||
|
export interface CollectionModelInterface extends Omit<CollectionInterface, '@type' | 'created' | 'modified'> {
|
||||||
|
created: Date | null;
|
||||||
|
modified: Date | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection information
|
||||||
|
*/
|
||||||
|
export interface CollectionInterface {
|
||||||
|
'@type': string;
|
||||||
|
schema: number;
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection: string | number | null;
|
||||||
|
identifier: string | number;
|
||||||
|
signature: string | null;
|
||||||
|
created: string | null;
|
||||||
|
modified: string | null;
|
||||||
|
properties: CollectionPropertiesInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CollectionContentTypes = 'file' | 'folder';
|
||||||
|
|
||||||
|
export interface CollectionBaseProperties {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionImmutableProperties extends CollectionBaseProperties {
|
||||||
|
content: CollectionContentTypes[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionMutableProperties extends CollectionBaseProperties {
|
||||||
|
owner: string;
|
||||||
|
label: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionPropertiesInterface extends CollectionMutableProperties, CollectionImmutableProperties {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection list
|
||||||
|
*/
|
||||||
|
export interface CollectionListRequest {
|
||||||
|
sources?: SourceSelector;
|
||||||
|
filter?: ListFilter;
|
||||||
|
sort?: ListSort;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionListResponse {
|
||||||
|
[providerId: string]: {
|
||||||
|
[serviceId: string]: {
|
||||||
|
[collectionId: string]: CollectionInterface;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection fetch
|
||||||
|
*/
|
||||||
|
export interface CollectionFetchRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection: string | number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionFetchResponse extends CollectionInterface {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection extant
|
||||||
|
*/
|
||||||
|
export interface CollectionExtantRequest {
|
||||||
|
sources: SourceSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionExtantResponse {
|
||||||
|
[providerId: string]: {
|
||||||
|
[serviceId: string]: {
|
||||||
|
[collectionId: string]: boolean;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection create
|
||||||
|
*/
|
||||||
|
export interface CollectionCreateRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection?: string | number | null; // Parent Collection Identifier
|
||||||
|
properties: CollectionMutableProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionCreateResponse extends CollectionInterface {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection modify
|
||||||
|
*/
|
||||||
|
export interface CollectionUpdateRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
identifier: string | number;
|
||||||
|
properties: CollectionMutableProperties;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionUpdateResponse extends CollectionInterface {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection delete
|
||||||
|
*/
|
||||||
|
export interface CollectionDeleteRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
identifier: string | number;
|
||||||
|
options?: {
|
||||||
|
force?: boolean; // Whether to force delete even if collection is not empty
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionDeleteResponse {
|
||||||
|
success: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection copy
|
||||||
|
*/
|
||||||
|
export interface CollectionCopyRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string;
|
||||||
|
identifier: string;
|
||||||
|
location?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionCopyResponse extends CollectionInterface {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Collection move
|
||||||
|
*/
|
||||||
|
export interface CollectionMoveRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string;
|
||||||
|
identifier: string;
|
||||||
|
location?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionMoveResponse extends CollectionInterface {}
|
||||||
@@ -1,85 +1,156 @@
|
|||||||
/**
|
/**
|
||||||
* Common types for file manager
|
* Common types shared across provider, service, collection, and entity request and responses.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base API request envelope
|
||||||
|
*/
|
||||||
|
export interface ApiRequest<T = any> {
|
||||||
|
version: number;
|
||||||
|
transaction: string;
|
||||||
|
operation: string;
|
||||||
|
data: T;
|
||||||
|
user?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Success response envelope
|
||||||
|
*/
|
||||||
|
export interface ApiSuccessResponse<T = any> {
|
||||||
|
version: number;
|
||||||
|
transaction: string;
|
||||||
|
operation: string;
|
||||||
|
status: 'success';
|
||||||
|
data: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Error response envelope
|
||||||
|
*/
|
||||||
|
export interface ApiErrorResponse {
|
||||||
|
version: number;
|
||||||
|
transaction: string;
|
||||||
|
operation: string;
|
||||||
|
status: 'error';
|
||||||
|
data: {
|
||||||
|
code: number;
|
||||||
|
message: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combined response type
|
||||||
|
*/
|
||||||
|
export type ApiResponse<T = any> = ApiSuccessResponse<T> | ApiErrorResponse;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Selector for targeting specific providers, services, collections, or entities in list or extant operations.
|
||||||
|
*
|
||||||
|
* Example usage:
|
||||||
|
* {
|
||||||
|
* "provider1": true, // Select all services/collections/entities under provider1
|
||||||
|
* "provider2": {
|
||||||
|
* "serviceA": true, // Select all collections/entities under serviceA of provider2
|
||||||
|
* "serviceB": {
|
||||||
|
* "collectionX": true, // Select all entities under collectionX of serviceB of provider2
|
||||||
|
* "collectionY": [1, 2, 3] // Select entities with identifiers 1, 2, and 3 under collectionY of serviceB of provider2
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
export type SourceSelector = {
|
export type SourceSelector = {
|
||||||
[provider: string]: boolean | ServiceSelector;
|
[provider: string]: boolean | ServiceSelector;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ServiceSelector = {
|
export type ServiceSelector = {
|
||||||
[service: string]: boolean;
|
[service: string]: boolean | CollectionSelector;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SortDirection = {
|
export type CollectionSelector = {
|
||||||
Ascending: 'asc',
|
[collection: string | number]: boolean | EntitySelector;
|
||||||
Descending: 'desc'
|
};
|
||||||
|
|
||||||
|
export type EntitySelector = (string | number)[];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter comparison for list operations
|
||||||
|
*/
|
||||||
|
export const ListFilterComparisonOperator = {
|
||||||
|
EQ: 1, // Equal
|
||||||
|
NEQ: 2, // Not Equal
|
||||||
|
GT: 4, // Greater Than
|
||||||
|
LT: 8, // Less Than
|
||||||
|
GTE: 16, // Greater Than or Equal
|
||||||
|
LTE: 32, // Less Than or Equal
|
||||||
|
IN: 64, // In Array
|
||||||
|
NIN: 128, // Not In Array
|
||||||
|
LIKE: 256, // Like
|
||||||
|
NLIKE: 512, // Not Like
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type SortDirection = typeof SortDirection[keyof typeof SortDirection];
|
export type ListFilterComparisonOperator = typeof ListFilterComparisonOperator[keyof typeof ListFilterComparisonOperator];
|
||||||
|
|
||||||
export const RangeType = {
|
/**
|
||||||
Tally: 'tally',
|
* Filter conjunction for list operations
|
||||||
Date: 'date'
|
*/
|
||||||
|
export const ListFilterConjunctionOperator = {
|
||||||
|
NONE: '',
|
||||||
|
AND: 'AND',
|
||||||
|
OR: 'OR',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
export type RangeType = typeof RangeType[keyof typeof RangeType];
|
export type ListFilterConjunctionOperator = typeof ListFilterConjunctionOperator[keyof typeof ListFilterConjunctionOperator];
|
||||||
|
|
||||||
export const RangeAnchorType = {
|
/**
|
||||||
Absolute: 'absolute',
|
* Filter condition for list operations
|
||||||
Relative: 'relative'
|
*
|
||||||
} as const;
|
* Tuple format: [value, comparator?, conjunction?]
|
||||||
|
*/
|
||||||
|
export type ListFilterCondition = [
|
||||||
|
string | number | boolean | string[] | number[],
|
||||||
|
ListFilterComparisonOperator?,
|
||||||
|
ListFilterConjunctionOperator?
|
||||||
|
];
|
||||||
|
|
||||||
export type RangeAnchorType = typeof RangeAnchorType[keyof typeof RangeAnchorType];
|
/**
|
||||||
|
* Filter for list operations
|
||||||
export const FilterOperator = {
|
*
|
||||||
Equals: 'eq',
|
* Values can be:
|
||||||
NotEquals: 'ne',
|
* - Simple primitives (string | number | boolean) for default equality comparison
|
||||||
GreaterThan: 'gt',
|
* - ListFilterCondition tuple for explicit comparator/conjunction
|
||||||
LessThan: 'lt',
|
*
|
||||||
GreaterThanOrEquals: 'gte',
|
* Examples:
|
||||||
LessThanOrEquals: 'lte',
|
* - Simple usage: { name: "John" }
|
||||||
Contains: 'contains',
|
* - With comparator: { age: [25, ListFilterComparisonOperator.GT] }
|
||||||
StartsWith: 'startsWith',
|
* - With conjunction: { age: [25, ListFilterComparisonOperator.GT, ListFilterConjunctionOperator.AND] }
|
||||||
EndsWith: 'endsWith',
|
* - With array value for IN operator: { status: [["active", "pending"], ListFilterComparisonOperator.IN] }
|
||||||
In: 'in',
|
*/
|
||||||
NotIn: 'notIn'
|
export interface ListFilter {
|
||||||
} as const;
|
[attribute: string]: string | number | boolean | ListFilterCondition;
|
||||||
|
|
||||||
export type FilterOperator = typeof FilterOperator[keyof typeof FilterOperator];
|
|
||||||
|
|
||||||
export interface FilterCondition {
|
|
||||||
attribute: string;
|
|
||||||
value: unknown;
|
|
||||||
operator?: FilterOperator;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SortCondition {
|
/**
|
||||||
attribute: string;
|
* Sort for list operations
|
||||||
direction: SortDirection;
|
*
|
||||||
|
* Values can be:
|
||||||
|
* - true for ascending
|
||||||
|
* - false for descending
|
||||||
|
*/
|
||||||
|
export interface ListSort {
|
||||||
|
[attribute: string]: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RangeCondition {
|
/**
|
||||||
type: RangeType;
|
* Range for list operations
|
||||||
anchor?: RangeAnchorType;
|
*
|
||||||
position?: string | number;
|
* Values can be:
|
||||||
tally?: number;
|
* - relative based on item identifier
|
||||||
}
|
* - absolute based on item count
|
||||||
|
*/
|
||||||
export interface ApiRequest {
|
export interface ListRange {
|
||||||
version: number;
|
type: 'tally';
|
||||||
transaction: string;
|
anchor: 'relative' | 'absolute';
|
||||||
operation: string;
|
position: string | number;
|
||||||
data?: Record<string, unknown>;
|
tally: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ApiResponse<T = unknown> {
|
|
||||||
version: number;
|
|
||||||
transaction: string;
|
|
||||||
operation: string;
|
|
||||||
status: 'success' | 'error';
|
|
||||||
data?: T;
|
|
||||||
error?: {
|
|
||||||
code: number;
|
|
||||||
message: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
20
src/types/document.ts
Normal file
20
src/types/document.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* Document-related type definitions
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Document interface
|
||||||
|
*/
|
||||||
|
export interface DocumentModelInterface extends Omit<DocumentInterface, '@type' | 'label'> {
|
||||||
|
label: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DocumentInterface {
|
||||||
|
'@type': string;
|
||||||
|
urid: string | null;
|
||||||
|
size: number;
|
||||||
|
label: string;
|
||||||
|
mime: string | null;
|
||||||
|
format: string | null;
|
||||||
|
encoding: string | null;
|
||||||
|
}
|
||||||
194
src/types/entity.ts
Normal file
194
src/types/entity.ts
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
/**
|
||||||
|
* Entity type definitions
|
||||||
|
*/
|
||||||
|
import type { ListFilter, ListRange, ListSort, SourceSelector } from './common';
|
||||||
|
import type { DocumentInterface, DocumentModelInterface } from './document';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity definition
|
||||||
|
*/
|
||||||
|
export interface EntityModelInterface extends Omit<EntityInterface<DocumentModelInterface>, '@type' | 'created' | 'modified'> {
|
||||||
|
created: Date | null;
|
||||||
|
modified: Date | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityInterface<T = DocumentInterface> {
|
||||||
|
'@type': string;
|
||||||
|
schema: number;
|
||||||
|
provider: string;
|
||||||
|
service: string;
|
||||||
|
collection: string | number;
|
||||||
|
identifier: string | number;
|
||||||
|
signature: string | null;
|
||||||
|
created: string | null;
|
||||||
|
modified: string | null;
|
||||||
|
properties: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity list
|
||||||
|
*/
|
||||||
|
export interface EntityListRequest {
|
||||||
|
sources?: SourceSelector;
|
||||||
|
filter?: ListFilter;
|
||||||
|
sort?: ListSort;
|
||||||
|
range?: ListRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityListResponse {
|
||||||
|
[providerId: string]: {
|
||||||
|
[serviceId: string]: {
|
||||||
|
[collectionId: string]: {
|
||||||
|
[identifier: string]: EntityInterface<DocumentInterface>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity fetch
|
||||||
|
*/
|
||||||
|
export interface EntityFetchRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection: string | number;
|
||||||
|
identifiers: (string | number)[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityFetchResponse {
|
||||||
|
[identifier: string]: EntityInterface<DocumentInterface>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity extant
|
||||||
|
*/
|
||||||
|
export interface EntityExtantRequest {
|
||||||
|
sources: SourceSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityExtantResponse {
|
||||||
|
[providerId: string]: {
|
||||||
|
[serviceId: string]: {
|
||||||
|
[collectionId: string]: {
|
||||||
|
[identifier: string]: boolean;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity create
|
||||||
|
*/
|
||||||
|
export interface EntityCreateRequest<T = DocumentInterface> {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection: string | number;
|
||||||
|
properties: T;
|
||||||
|
options?: Record<string, unknown>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityCreateResponse<T = DocumentInterface> extends EntityInterface<T> {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity update
|
||||||
|
*/
|
||||||
|
export interface EntityUpdateRequest<T = DocumentInterface> {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection: string | number;
|
||||||
|
identifier: string | number;
|
||||||
|
properties: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityUpdateResponse<T = DocumentInterface> extends EntityInterface<T> {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity delete
|
||||||
|
*/
|
||||||
|
export interface EntityDeleteRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection: string | number;
|
||||||
|
identifier: string | number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityDeleteResponse {
|
||||||
|
success: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity delta
|
||||||
|
*/
|
||||||
|
export interface EntityDeltaRequest {
|
||||||
|
sources: SourceSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityDeltaResponse {
|
||||||
|
[providerId: string]: false | {
|
||||||
|
[serviceId: string]: false | {
|
||||||
|
[collectionId: string]: false | {
|
||||||
|
signature: string;
|
||||||
|
additions: (string | number)[];
|
||||||
|
modifications: (string | number)[];
|
||||||
|
deletions: (string | number)[];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity copy
|
||||||
|
*/
|
||||||
|
export interface EntityCopyRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection: string | number;
|
||||||
|
identifier: string | number;
|
||||||
|
destination?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityCopyResponse<T = DocumentInterface> extends EntityInterface<T> {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity move
|
||||||
|
*/
|
||||||
|
export interface EntityMoveRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection: string | number;
|
||||||
|
identifier: string | number;
|
||||||
|
destination?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityMoveResponse<T = DocumentInterface> extends EntityInterface<T> {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity read content
|
||||||
|
*/
|
||||||
|
export interface EntityReadRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection: string | number;
|
||||||
|
identifier: string | number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityReadResult {
|
||||||
|
content: string | null;
|
||||||
|
encoding: 'base64';
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EntityReadResponse = EntityReadResult;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity write content
|
||||||
|
*/
|
||||||
|
export interface EntityWriteRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string | number;
|
||||||
|
collection: string | number;
|
||||||
|
identifier: string | number;
|
||||||
|
content: string;
|
||||||
|
encoding?: 'base64';
|
||||||
|
}
|
||||||
|
|
||||||
|
export type EntityWriteResponse = { bytesWritten: number };
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
/**
|
export type * from './common';
|
||||||
* File manager types barrel export
|
export type * from './provider';
|
||||||
*/
|
export type * from './service';
|
||||||
|
export type * from './collection';
|
||||||
export * from './common';
|
export type * from './entity';
|
||||||
export * from './provider';
|
export type * from './document';
|
||||||
export * from './service';
|
export type * from './node';
|
||||||
export * from './node';
|
|
||||||
export * from './api';
|
|
||||||
|
|||||||
@@ -1,65 +1,37 @@
|
|||||||
/**
|
/**
|
||||||
* Node types for file manager (collections and entities)
|
* Node types for combined operations
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export type NodeType = 'files.collection' | 'files.entity';
|
import type { CollectionInterface } from "./collection";
|
||||||
|
import type { ApiResponse, ListFilterCondition, ListRange, ListSort } from "./common";
|
||||||
|
import type { EntityInterface } from "./entity";
|
||||||
|
|
||||||
export interface NodeBase {
|
export interface NodeListRequest {
|
||||||
'@type': NodeType;
|
provider: string;
|
||||||
in: string | null;
|
service: string;
|
||||||
id: string;
|
location?: string | null;
|
||||||
createdBy: string;
|
recursive?: boolean;
|
||||||
createdOn: string;
|
filter?: ListFilterCondition | null;
|
||||||
modifiedBy: string;
|
sort?: ListSort | null;
|
||||||
modifiedOn: string;
|
range?: ListRange | null;
|
||||||
owner: string;
|
}
|
||||||
|
|
||||||
|
export type NodeListResponse = ApiResponse<CollectionInterface | EntityInterface>;
|
||||||
|
|
||||||
|
export interface NodeDeltaRequest {
|
||||||
|
provider: string;
|
||||||
|
service: string;
|
||||||
|
location?: string | null;
|
||||||
signature: string;
|
signature: string;
|
||||||
label: string;
|
recursive?: boolean;
|
||||||
|
detail?: 'ids' | 'full';
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface FileCollection extends NodeBase {
|
export interface NodeDeltaResult {
|
||||||
'@type': 'files.collection';
|
added: string[];
|
||||||
}
|
modified: string[];
|
||||||
|
|
||||||
export interface FileEntity extends NodeBase {
|
|
||||||
'@type': 'files.entity';
|
|
||||||
size: number;
|
|
||||||
mime: string;
|
|
||||||
format: string;
|
|
||||||
encoding: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type FileNode = FileCollection | FileEntity;
|
|
||||||
|
|
||||||
export interface NodeListResult {
|
|
||||||
items: FileNode[];
|
|
||||||
total: number;
|
|
||||||
hasMore?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EntityListResult {
|
|
||||||
items: FileEntity[];
|
|
||||||
total: number;
|
|
||||||
hasMore?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CollectionListResult {
|
|
||||||
items: FileCollection[];
|
|
||||||
total: number;
|
|
||||||
hasMore?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface DeltaResult {
|
|
||||||
added: FileNode[];
|
|
||||||
modified: FileNode[];
|
|
||||||
removed: string[];
|
removed: string[];
|
||||||
signature: string;
|
signature: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isFileCollection(node: FileNode): node is FileCollection {
|
export type NodeDeltaResponse = ApiResponse<NodeDeltaResult>;
|
||||||
return node['@type'] === 'files.collection';
|
|
||||||
}
|
|
||||||
|
|
||||||
export function isFileEntity(node: FileNode): node is FileEntity {
|
|
||||||
return node['@type'] === 'files.entity';
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,49 +1,60 @@
|
|||||||
/**
|
/**
|
||||||
* Provider types for file manager
|
* Provider type definitions
|
||||||
*/
|
*/
|
||||||
|
import type { SourceSelector } from "./common";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider capabilities
|
||||||
|
*/
|
||||||
export interface ProviderCapabilitiesInterface {
|
export interface ProviderCapabilitiesInterface {
|
||||||
CollectionList?: boolean;
|
ServiceList?: boolean;
|
||||||
CollectionListFilter?: boolean | Record<string, string>;
|
ServiceFetch?: boolean;
|
||||||
CollectionListSort?: boolean | string[];
|
ServiceExtant?: boolean;
|
||||||
CollectionExtant?: boolean;
|
ServiceCreate?: boolean;
|
||||||
CollectionFetch?: boolean;
|
ServiceUpdate?: boolean;
|
||||||
CollectionCreate?: boolean;
|
ServiceDelete?: boolean;
|
||||||
CollectionModify?: boolean;
|
ServiceDiscover?: boolean;
|
||||||
CollectionDestroy?: boolean;
|
ServiceTest?: boolean;
|
||||||
CollectionCopy?: boolean;
|
[key: string]: boolean | object | string[] | undefined;
|
||||||
CollectionMove?: boolean;
|
|
||||||
EntityList?: boolean;
|
|
||||||
EntityListFilter?: boolean | Record<string, string>;
|
|
||||||
EntityListSort?: boolean | string[];
|
|
||||||
EntityListRange?: boolean | Record<string, string[]>;
|
|
||||||
EntityDelta?: boolean;
|
|
||||||
EntityExtant?: boolean;
|
|
||||||
EntityFetch?: boolean;
|
|
||||||
EntityRead?: boolean;
|
|
||||||
EntityReadStream?: boolean;
|
|
||||||
EntityReadChunk?: boolean;
|
|
||||||
EntityCreate?: boolean;
|
|
||||||
EntityModify?: boolean;
|
|
||||||
EntityDestroy?: boolean;
|
|
||||||
EntityCopy?: boolean;
|
|
||||||
EntityMove?: boolean;
|
|
||||||
EntityWrite?: boolean;
|
|
||||||
EntityWriteStream?: boolean;
|
|
||||||
EntityWriteChunk?: boolean;
|
|
||||||
NodeList?: boolean;
|
|
||||||
NodeListFilter?: boolean | Record<string, string>;
|
|
||||||
NodeListSort?: boolean | string[];
|
|
||||||
NodeListRange?: boolean | Record<string, string[]>;
|
|
||||||
NodeDelta?: boolean;
|
|
||||||
[key: string]: boolean | string[] | Record<string, string> | Record<string, string[]> | undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider information
|
||||||
|
*/
|
||||||
export interface ProviderInterface {
|
export interface ProviderInterface {
|
||||||
'@type': string;
|
'@type': string;
|
||||||
id: string;
|
identifier: string;
|
||||||
label: string;
|
label: string;
|
||||||
capabilities: ProviderCapabilitiesInterface;
|
capabilities: ProviderCapabilitiesInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProviderRecord = Record<string, ProviderInterface>;
|
/**
|
||||||
|
* Provider list
|
||||||
|
*/
|
||||||
|
export interface ProviderListRequest {
|
||||||
|
sources?: SourceSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProviderListResponse {
|
||||||
|
[identifier: string]: ProviderInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider fetch
|
||||||
|
*/
|
||||||
|
export interface ProviderFetchRequest {
|
||||||
|
identifier: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProviderFetchResponse extends ProviderInterface {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provider extant
|
||||||
|
*/
|
||||||
|
export interface ProviderExtantRequest {
|
||||||
|
sources: SourceSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ProviderExtantResponse {
|
||||||
|
[identifier: string]: boolean;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,13 +1,307 @@
|
|||||||
/**
|
/**
|
||||||
* Service types for file manager
|
* Service type definitions
|
||||||
*/
|
*/
|
||||||
|
import type { SourceSelector, ListFilterComparisonOperator } from './common';
|
||||||
|
|
||||||
export interface ServiceInterface {
|
/**
|
||||||
'@type': string;
|
* Service capabilities
|
||||||
id: string;
|
*/
|
||||||
provider: string;
|
export interface ServiceCapabilitiesInterface {
|
||||||
label: string;
|
// Collection capabilities
|
||||||
rootId: string;
|
CollectionList?: boolean;
|
||||||
|
CollectionListFilter?: ServiceListFilterCollection;
|
||||||
|
CollectionListSort?: ServiceListSortCollection;
|
||||||
|
CollectionExtant?: boolean;
|
||||||
|
CollectionFetch?: boolean;
|
||||||
|
CollectionCreate?: boolean;
|
||||||
|
CollectionUpdate?: boolean;
|
||||||
|
CollectionDelete?: boolean;
|
||||||
|
CollectionCopy?: boolean;
|
||||||
|
CollectionMove?: boolean;
|
||||||
|
// Entity capabilities
|
||||||
|
EntityList?: boolean;
|
||||||
|
EntityListFilter?: ServiceListFilterEntity;
|
||||||
|
EntityListSort?: ServiceListSortEntity;
|
||||||
|
EntityListRange?: ServiceListRange;
|
||||||
|
EntityDelta?: boolean;
|
||||||
|
EntityExtant?: boolean;
|
||||||
|
EntityFetch?: boolean;
|
||||||
|
EntityCreate?: boolean;
|
||||||
|
EntityUpdate?: boolean;
|
||||||
|
EntityDelete?: boolean;
|
||||||
|
EntityMove?: boolean;
|
||||||
|
EntityCopy?: boolean;
|
||||||
|
EntityRead?: boolean;
|
||||||
|
EntityReadStream?: boolean;
|
||||||
|
EntityReadChunk?: boolean;
|
||||||
|
EntityWrite?: boolean;
|
||||||
|
EntityWriteStream?: boolean;
|
||||||
|
EntityWriteChunk?: boolean;
|
||||||
|
// Node capabilities
|
||||||
|
NodeList?: boolean;
|
||||||
|
NodeListFilter?: boolean | Record<string, string>;
|
||||||
|
NodeListSort?: boolean | string[];
|
||||||
|
NodeListRange?: boolean | Record<string, string[]>;
|
||||||
|
NodeDelta?: boolean;
|
||||||
|
|
||||||
|
[key: string]: boolean | object | string | string[] | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ServiceRecord = Record<string, ServiceInterface>;
|
/**
|
||||||
|
* Service information
|
||||||
|
*/
|
||||||
|
export interface ServiceInterface {
|
||||||
|
'@type': string;
|
||||||
|
provider: string;
|
||||||
|
identifier: string | number | null;
|
||||||
|
label: string | null;
|
||||||
|
enabled: boolean;
|
||||||
|
capabilities?: ServiceCapabilitiesInterface;
|
||||||
|
location?: ServiceLocation | null;
|
||||||
|
identity?: ServiceIdentity | null;
|
||||||
|
auxiliary?: Record<string, any>; // Provider-specific extension data
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service list
|
||||||
|
*/
|
||||||
|
export interface ServiceListRequest {
|
||||||
|
sources?: SourceSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServiceListResponse {
|
||||||
|
[provider: string]: {
|
||||||
|
[identifier: string]: ServiceInterface;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service fetch
|
||||||
|
*/
|
||||||
|
export interface ServiceFetchRequest {
|
||||||
|
provider: string;
|
||||||
|
identifier: string | number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServiceFetchResponse extends ServiceInterface {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service extant
|
||||||
|
*/
|
||||||
|
export interface ServiceExtantRequest {
|
||||||
|
sources: SourceSelector;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServiceExtantResponse {
|
||||||
|
[provider: string]: {
|
||||||
|
[identifier: string]: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service create
|
||||||
|
*/
|
||||||
|
export interface ServiceCreateRequest {
|
||||||
|
provider: string;
|
||||||
|
data: Partial<ServiceInterface>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServiceCreateResponse extends ServiceInterface {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service update
|
||||||
|
*/
|
||||||
|
export interface ServiceUpdateRequest {
|
||||||
|
provider: string;
|
||||||
|
identifier: string | number;
|
||||||
|
data: Partial<ServiceInterface>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServiceUpdateResponse extends ServiceInterface {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service delete
|
||||||
|
*/
|
||||||
|
export interface ServiceDeleteRequest {
|
||||||
|
provider: string;
|
||||||
|
identifier: string | number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServiceDeleteResponse {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service discovery
|
||||||
|
*/
|
||||||
|
export interface ServiceDiscoverRequest {
|
||||||
|
identity: string; // Email address or domain
|
||||||
|
provider?: string; // Optional: specific provider ('jmap', 'smtp', etc.) or null for all
|
||||||
|
location?: string; // Optional: known hostname (bypasses DNS lookup)
|
||||||
|
secret?: string; // Optional: password/token for credential validation
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServiceDiscoverResponse {
|
||||||
|
[provider: string]: ServiceLocation; // Uses existing ServiceLocation discriminated union
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service connection test
|
||||||
|
*/
|
||||||
|
export interface ServiceTestRequest {
|
||||||
|
provider: string;
|
||||||
|
// For existing service
|
||||||
|
identifier?: string | number | null;
|
||||||
|
// For fresh configuration
|
||||||
|
location?: ServiceLocation | null;
|
||||||
|
identity?: ServiceIdentity | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ServiceTestResponse {
|
||||||
|
success: boolean;
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service location - Base
|
||||||
|
*/
|
||||||
|
export interface ServiceLocationBase {
|
||||||
|
type: 'URI' | 'FILE';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service location - URI-based type
|
||||||
|
*/
|
||||||
|
export interface ServiceLocationUri extends ServiceLocationBase {
|
||||||
|
type: 'URI';
|
||||||
|
scheme: string; // e.g., 'https', 'http'
|
||||||
|
host: string; // e.g., 'api.example.com'
|
||||||
|
port: number; // e.g., 443
|
||||||
|
path?: string; // e.g., '/v1/api'
|
||||||
|
verifyPeer?: boolean; // Verify SSL/TLS peer certificate
|
||||||
|
verifyHost?: boolean; // Verify SSL/TLS certificate host
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service location - File-based type (e.g., for local mail delivery or Unix socket)
|
||||||
|
*/
|
||||||
|
export interface ServiceLocationFile extends ServiceLocationBase {
|
||||||
|
type: 'FILE';
|
||||||
|
path: string; // File system path
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service location types
|
||||||
|
*/
|
||||||
|
export type ServiceLocation =
|
||||||
|
| ServiceLocationUri
|
||||||
|
| ServiceLocationFile;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service identity - base
|
||||||
|
*/
|
||||||
|
export interface ServiceIdentityBase {
|
||||||
|
type: 'NA' | 'BA' | 'TA' | 'OA' | 'CC';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service identity - No authentication
|
||||||
|
*/
|
||||||
|
export interface ServiceIdentityNone extends ServiceIdentityBase {
|
||||||
|
type: 'NA';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service identity - Basic authentication type
|
||||||
|
*/
|
||||||
|
export interface ServiceIdentityBasic extends ServiceIdentityBase {
|
||||||
|
type: 'BA';
|
||||||
|
identity: string; // Username/email
|
||||||
|
secret: string; // Password
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token authentication (API key, static token)
|
||||||
|
*/
|
||||||
|
export interface ServiceIdentityToken extends ServiceIdentityBase {
|
||||||
|
type: 'TA';
|
||||||
|
token: string; // Authentication token/API key
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OAuth authentication
|
||||||
|
*/
|
||||||
|
export interface ServiceIdentityOAuth extends ServiceIdentityBase {
|
||||||
|
type: 'OA';
|
||||||
|
accessToken: string; // Current access token
|
||||||
|
accessScope?: string[]; // Token scopes
|
||||||
|
accessExpiry?: number; // Unix timestamp when token expires
|
||||||
|
refreshToken?: string; // Refresh token for getting new access tokens
|
||||||
|
refreshLocation?: string; // Token refresh endpoint URL
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Client certificate authentication (mTLS)
|
||||||
|
*/
|
||||||
|
export interface ServiceIdentityCertificate extends ServiceIdentityBase {
|
||||||
|
type: 'CC';
|
||||||
|
certificate: string; // X.509 certificate (PEM format or file path)
|
||||||
|
privateKey: string; // Private key (PEM format or file path)
|
||||||
|
passphrase?: string; // Optional passphrase for encrypted private key
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service identity configuration
|
||||||
|
* Discriminated union of all identity types
|
||||||
|
*/
|
||||||
|
export type ServiceIdentity =
|
||||||
|
| ServiceIdentityNone
|
||||||
|
| ServiceIdentityBasic
|
||||||
|
| ServiceIdentityToken
|
||||||
|
| ServiceIdentityOAuth
|
||||||
|
| ServiceIdentityCertificate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* List filter specification format
|
||||||
|
*
|
||||||
|
* Format: "type:length:defaultComparator:supportedComparators"
|
||||||
|
*
|
||||||
|
* Examples:
|
||||||
|
* - "s:200:256:771" = String field, max 200 chars, default LIKE, supports EQ|NEQ|LIKE|NLIKE
|
||||||
|
* - "a:10:64:192" = Array field, max 10 items, default IN, supports IN|NIN
|
||||||
|
* - "i:0:1:31" = Integer field, default EQ, supports EQ|NEQ|GT|LT|GTE|LTE
|
||||||
|
*
|
||||||
|
* Type codes:
|
||||||
|
* - s = string
|
||||||
|
* - i = integer
|
||||||
|
* - b = boolean
|
||||||
|
* - a = array
|
||||||
|
*
|
||||||
|
* Comparator values are bitmasks that can be combined
|
||||||
|
*/
|
||||||
|
export type ServiceListFilterCollection = {
|
||||||
|
'label'?: string;
|
||||||
|
[attribute: string]: string | undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type ServiceListFilterEntity = {
|
||||||
|
'text'?: string;
|
||||||
|
'label'?: string;
|
||||||
|
[attribute: string]: string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Service list sort specification
|
||||||
|
*/
|
||||||
|
export type ServiceListSortCollection = ("label" | string)[];
|
||||||
|
export type ServiceListSortEntity = ( "label" | string)[];
|
||||||
|
|
||||||
|
export type ServiceListRange = {
|
||||||
|
'tally'?: string[];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export interface ServiceListFilterDefinition {
|
||||||
|
type: 'string' | 'integer' | 'date' | 'boolean' | 'array';
|
||||||
|
length: number;
|
||||||
|
defaultComparator: ListFilterComparisonOperator;
|
||||||
|
supportedComparators: ListFilterComparisonOperator[];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user