refactor: front end code to unified design
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
|||||||
|
import { isProxy, toRaw } from 'vue';
|
||||||
|
|
||||||
|
function normalizeCloneable<T>(value: T): T {
|
||||||
|
if (value === null || value === undefined) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof value !== 'object') {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
const rawValue = isProxy(value) ? toRaw(value) : value;
|
||||||
|
|
||||||
|
if (Array.isArray(rawValue)) {
|
||||||
|
return rawValue.map(item => normalizeCloneable(item)) as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
const plainObject = Object.fromEntries(
|
||||||
|
Object.entries(rawValue).map(([key, nestedValue]) => [key, normalizeCloneable(nestedValue)])
|
||||||
|
);
|
||||||
|
|
||||||
|
return plainObject as T;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function clonePlain<T>(value: T): T {
|
||||||
|
return structuredClone(normalizeCloneable(value));
|
||||||
|
}
|
||||||
+54
-63
@@ -1,47 +1,52 @@
|
|||||||
/**
|
/**
|
||||||
* Class model for Collection Interface
|
* Class models for Collection interfaces
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { CollectionContentTypes, CollectionInterface, CollectionPropertiesInterface } from "@/types/collection";
|
import type {
|
||||||
|
CollectionContentTypes,
|
||||||
|
CollectionInterface,
|
||||||
|
CollectionModelInterface,
|
||||||
|
CollectionPropertiesInterface,
|
||||||
|
CollectionPropertiesModelInterface
|
||||||
|
} from '@/types/collection';
|
||||||
|
import type {
|
||||||
|
CollectionIdentifier,
|
||||||
|
ServiceIdentifier
|
||||||
|
} from '@/types/common';
|
||||||
|
import { clonePlain } from './clone-plain';
|
||||||
|
|
||||||
export class CollectionObject implements CollectionInterface {
|
export class CollectionObject implements CollectionModelInterface {
|
||||||
|
|
||||||
_data!: CollectionInterface;
|
private _data: CollectionInterface<CollectionPropertiesInterface>;
|
||||||
|
private _properties: CollectionPropertiesObject | undefined = undefined;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._data = {
|
this._data = {
|
||||||
|
'@type': 'people:collection',
|
||||||
|
version: 1,
|
||||||
provider: '',
|
provider: '',
|
||||||
service: '',
|
service: '' as ServiceIdentifier,
|
||||||
collection: null,
|
collection: null as CollectionIdentifier | null,
|
||||||
identifier: '',
|
identifier: '' as CollectionIdentifier,
|
||||||
signature: null,
|
properties: new CollectionPropertiesObject().toJson(),
|
||||||
created: null,
|
|
||||||
modified: null,
|
|
||||||
properties: new CollectionPropertiesObject(),
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJson(data: CollectionInterface): CollectionObject {
|
fromJson(data: CollectionInterface): CollectionObject {
|
||||||
this._data = data;
|
this._data = clonePlain(data);
|
||||||
if (data.properties) {
|
this._properties = undefined;
|
||||||
this._data.properties = new CollectionPropertiesObject().fromJson(data.properties as CollectionPropertiesInterface);
|
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(): CollectionInterface {
|
toJson(): CollectionInterface {
|
||||||
const json = { ...this._data };
|
const json = this._properties
|
||||||
if (this._data.properties instanceof CollectionPropertiesObject) {
|
? { ...this._data, properties: this._properties.toJson() }
|
||||||
json.properties = this._data.properties.toJson();
|
: this._data;
|
||||||
}
|
return clonePlain(json);
|
||||||
return json;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(): CollectionObject {
|
clone(): CollectionObject {
|
||||||
const cloned = new CollectionObject();
|
return new CollectionObject().fromJson(this.toJson());
|
||||||
cloned._data = { ...this._data };
|
|
||||||
cloned._data.properties = this.properties.clone();
|
|
||||||
return cloned;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Immutable Properties */
|
/** Immutable Properties */
|
||||||
@@ -50,16 +55,16 @@ export class CollectionObject implements CollectionInterface {
|
|||||||
return this._data.provider;
|
return this._data.provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
get service(): string | number {
|
get service(): ServiceIdentifier {
|
||||||
return this._data.service;
|
return this._data.service as ServiceIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
get collection(): string | number | null {
|
get collection(): CollectionIdentifier | null {
|
||||||
return this._data.collection;
|
return this._data.collection as CollectionIdentifier | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
get identifier(): string | number {
|
get identifier(): CollectionIdentifier {
|
||||||
return this._data.identifier;
|
return this._data.identifier as CollectionIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
get signature(): string | null | undefined {
|
get signature(): string | null | undefined {
|
||||||
@@ -74,37 +79,33 @@ export class CollectionObject implements CollectionInterface {
|
|||||||
return this._data.modified;
|
return this._data.modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Mutable Properties */
|
||||||
|
|
||||||
get properties(): CollectionPropertiesObject {
|
get properties(): CollectionPropertiesObject {
|
||||||
if (this._data.properties instanceof CollectionPropertiesObject) {
|
if (this._properties) {
|
||||||
return this._data.properties;
|
return this._properties;
|
||||||
|
}
|
||||||
|
else if (this._data.properties) {
|
||||||
|
const properties = new CollectionPropertiesObject().fromJson(this._data.properties as CollectionPropertiesInterface);
|
||||||
|
this._properties = properties;
|
||||||
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._data.properties) {
|
|
||||||
const hydrated = new CollectionPropertiesObject().fromJson(this._data.properties as CollectionPropertiesInterface);
|
|
||||||
this._data.properties = hydrated;
|
|
||||||
return hydrated;
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CollectionPropertiesObject();
|
return new CollectionPropertiesObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
set properties(value: CollectionPropertiesObject) {
|
set properties(value: CollectionPropertiesObject) {
|
||||||
if (value instanceof CollectionPropertiesObject) {
|
this._properties = value;
|
||||||
this._data.properties = value as any;
|
|
||||||
} else {
|
|
||||||
this._data.properties = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CollectionPropertiesObject implements CollectionPropertiesInterface {
|
export class CollectionPropertiesObject implements CollectionPropertiesModelInterface {
|
||||||
|
|
||||||
_data!: CollectionPropertiesInterface;
|
private _data: CollectionPropertiesInterface;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._data = {
|
this._data = {
|
||||||
'@type': 'chrono:collection',
|
'@type': 'chrono:calendar',
|
||||||
version: 1,
|
|
||||||
content: [],
|
content: [],
|
||||||
label: '',
|
label: '',
|
||||||
description: null,
|
description: null,
|
||||||
@@ -115,32 +116,22 @@ export class CollectionPropertiesObject implements CollectionPropertiesInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromJson(data: CollectionPropertiesInterface): CollectionPropertiesObject {
|
fromJson(data: CollectionPropertiesInterface): CollectionPropertiesObject {
|
||||||
this._data = data;
|
this._data = clonePlain(data);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(): CollectionPropertiesInterface {
|
toJson(): CollectionPropertiesInterface {
|
||||||
return this._data;
|
return clonePlain(this._data);
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(): CollectionPropertiesObject {
|
clone(): CollectionPropertiesObject {
|
||||||
const cloned = new CollectionPropertiesObject();
|
return new CollectionPropertiesObject().fromJson(this.toJson());
|
||||||
cloned._data = { ...this._data };
|
|
||||||
return cloned;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Immutable Properties */
|
/** Immutable Properties */
|
||||||
|
|
||||||
get '@type'(): string {
|
|
||||||
return this._data['@type'];
|
|
||||||
}
|
|
||||||
|
|
||||||
get version(): number {
|
|
||||||
return this._data.version;
|
|
||||||
}
|
|
||||||
|
|
||||||
get content(): CollectionContentTypes[] {
|
get content(): CollectionContentTypes[] {
|
||||||
return this._data.content || [];
|
return this._data.content ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Mutable Properties */
|
/** Mutable Properties */
|
||||||
@@ -185,4 +176,4 @@ export class CollectionPropertiesObject implements CollectionPropertiesInterface
|
|||||||
this._data.color = value;
|
this._data.color = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+51
-55
@@ -1,106 +1,102 @@
|
|||||||
/**
|
/**
|
||||||
* Class model for Entity Interface
|
* Class model for Entity Interface
|
||||||
*/
|
*/
|
||||||
import type { EntityInterface } from "@/types/entity";
|
|
||||||
import type { EventInterface } from "@/types/event";
|
|
||||||
import type { TaskInterface } from "@/types/task";
|
|
||||||
import type { JournalInterface } from "@/types/journal";
|
|
||||||
import { EventObject } from "./event";
|
|
||||||
import { TaskObject } from "./task";
|
|
||||||
import { JournalObject } from "./journal";
|
|
||||||
|
|
||||||
export class EntityObject implements EntityInterface {
|
import type { CollectionIdentifier, EntityIdentifier } from '@/types/common';
|
||||||
|
import type { EntityInterface, EntityModelInterface, EntityPropertiesInterface } from '@/types/entity';
|
||||||
|
import type { EventInterface } from '@/types/event';
|
||||||
|
import type { JournalInterface } from '@/types/journal';
|
||||||
|
import type { TaskInterface } from '@/types/task';
|
||||||
|
import { EventObject } from './event';
|
||||||
|
import { JournalObject } from './journal';
|
||||||
|
import { TaskObject } from './task';
|
||||||
|
import { clonePlain } from './clone-plain';
|
||||||
|
|
||||||
_data!: EntityInterface;
|
export type EntityPropertiesObject = EventObject | TaskObject | JournalObject;
|
||||||
|
|
||||||
|
export class EntityObject implements EntityModelInterface {
|
||||||
|
private _data: EntityInterface<EntityPropertiesInterface>;
|
||||||
|
private _properties: EntityPropertiesObject | undefined;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._data = {
|
this._data = {
|
||||||
|
'@type': 'chrono:entity',
|
||||||
|
version: 1,
|
||||||
provider: '',
|
provider: '',
|
||||||
service: '',
|
service: '',
|
||||||
collection: '',
|
collection: '' as CollectionIdentifier,
|
||||||
identifier: '',
|
identifier: '' as EntityIdentifier,
|
||||||
signature: null,
|
signature: null,
|
||||||
created: null,
|
created: null,
|
||||||
modified: null,
|
modified: null,
|
||||||
properties: new EventObject(),
|
properties: new EventObject().toJson(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJson(data: EntityInterface): EntityObject {
|
fromJson(data: EntityInterface): EntityObject {
|
||||||
this._data = data
|
this._data = clonePlain(data);
|
||||||
if (data.properties) {
|
this._properties = undefined;
|
||||||
const type = data.properties.type
|
|
||||||
if (type === 'task') {
|
|
||||||
this._data.properties = new TaskObject().fromJson(data.properties as TaskInterface);
|
|
||||||
} else if (type === 'journal') {
|
|
||||||
this._data.properties = new JournalObject().fromJson(data.properties as JournalInterface);
|
|
||||||
} else {
|
|
||||||
this._data.properties = new EventObject().fromJson(data.properties as EventInterface);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(): EntityInterface {
|
toJson(): EntityInterface {
|
||||||
const json = { ...this._data }
|
const json = this._properties
|
||||||
if (this._data.properties instanceof EventObject ||
|
? { ...this._data, properties: this._properties.toJson() }
|
||||||
this._data.properties instanceof TaskObject ||
|
: this._data;
|
||||||
this._data.properties instanceof JournalObject) {
|
return clonePlain(json);
|
||||||
json.properties = this._data.properties.toJson();
|
|
||||||
}
|
|
||||||
return json as EntityInterface
|
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(): EntityObject {
|
clone(): EntityObject {
|
||||||
const cloned = new EntityObject()
|
return new EntityObject().fromJson(this.toJson());
|
||||||
cloned._data = { ...this._data }
|
|
||||||
return cloned
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Immutable Properties */
|
/** Metadata Properties */
|
||||||
|
|
||||||
get provider(): string {
|
get provider(): string {
|
||||||
return this._data.provider
|
return this._data.provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
get service(): string {
|
get service(): string {
|
||||||
return this._data.service
|
return this._data.service;
|
||||||
}
|
}
|
||||||
|
|
||||||
get collection(): string | number {
|
get collection(): CollectionIdentifier {
|
||||||
return this._data.collection
|
return this._data.collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
get identifier(): string | number {
|
get identifier(): EntityIdentifier {
|
||||||
return this._data.identifier
|
return this._data.identifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
get signature(): string | null {
|
get signature(): string | null {
|
||||||
return this._data.signature
|
return this._data.signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
get created(): string | null {
|
get created(): string | null {
|
||||||
return this._data.created
|
return this._data.created;
|
||||||
}
|
}
|
||||||
|
|
||||||
get modified(): string | null {
|
get modified(): string | null {
|
||||||
return this._data.modified
|
return this._data.modified;
|
||||||
}
|
}
|
||||||
|
|
||||||
get properties(): EventObject | TaskObject | JournalObject {
|
/** Entity Properties (individual | organization | group) */
|
||||||
if (this._data.properties instanceof EventObject ||
|
|
||||||
this._data.properties instanceof TaskObject ||
|
get properties(): EntityPropertiesObject {
|
||||||
this._data.properties instanceof JournalObject) {
|
if (this._properties) return this._properties;
|
||||||
return this._data.properties
|
|
||||||
|
const raw = this._data.properties;
|
||||||
|
if (raw.type === 'task') {
|
||||||
|
this._properties = new TaskObject().fromJson(raw as TaskInterface);
|
||||||
|
} else if (raw.type === 'journal') {
|
||||||
|
this._properties = new JournalObject().fromJson(raw as JournalInterface);
|
||||||
|
} else {
|
||||||
|
this._properties = new EventObject().fromJson(raw as EventInterface);
|
||||||
}
|
}
|
||||||
|
return this._properties;
|
||||||
const defaultProperties = new EventObject();
|
|
||||||
this._data.properties = defaultProperties;
|
|
||||||
return defaultProperties
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set properties(value: EventObject | TaskObject | JournalObject) {
|
set properties(value: EntityPropertiesObject) {
|
||||||
this._data.properties = value
|
this._properties = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+103
-175
@@ -1,196 +1,124 @@
|
|||||||
/**
|
/**
|
||||||
* Identity implementation classes for Mail Manager services
|
* Identity models for Chrono Manager services
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
ServiceIdentity,
|
ServiceIdentity,
|
||||||
ServiceIdentityNone,
|
ServiceIdentityBasic,
|
||||||
ServiceIdentityBasic,
|
ServiceIdentityCertificate,
|
||||||
ServiceIdentityToken,
|
ServiceIdentityNone,
|
||||||
ServiceIdentityOAuth,
|
ServiceIdentityOAuth,
|
||||||
ServiceIdentityCertificate
|
ServiceIdentityToken
|
||||||
} from '@/types/service';
|
} from '@/types/service';
|
||||||
|
import { clonePlain } from './clone-plain';
|
||||||
|
import { MutationProxy } from './mutation-proxy';
|
||||||
|
|
||||||
/**
|
export abstract class Identity<T extends ServiceIdentity = ServiceIdentity> {
|
||||||
* Base Identity class
|
protected _original: T;
|
||||||
*/
|
protected _mutated: Partial<T>;
|
||||||
export abstract class Identity {
|
protected _mutationProxy: MutationProxy<T>;
|
||||||
abstract toJson(): ServiceIdentity;
|
protected _data: T;
|
||||||
|
|
||||||
static fromJson(data: ServiceIdentity): Identity {
|
protected constructor(initial: T) {
|
||||||
switch (data.type) {
|
this._original = clonePlain(initial);
|
||||||
case 'NA':
|
this._mutated = {};
|
||||||
return IdentityNone.fromJson(data);
|
this._mutationProxy = new MutationProxy<T>(() => this._original, () => this._mutated);
|
||||||
case 'BA':
|
this._data = this._mutationProxy.create();
|
||||||
return IdentityBasic.fromJson(data);
|
}
|
||||||
case 'TA':
|
|
||||||
return IdentityToken.fromJson(data);
|
protected load(data: T): this {
|
||||||
case 'OA':
|
this._original = clonePlain(data);
|
||||||
return IdentityOAuth.fromJson(data);
|
this._mutated = {};
|
||||||
case 'CC':
|
this._data = this._mutationProxy.create();
|
||||||
return IdentityCertificate.fromJson(data);
|
return this;
|
||||||
default:
|
}
|
||||||
throw new Error(`Unknown identity type: ${(data as any).type}`);
|
|
||||||
|
toJSON(): ServiceIdentity { return this.toJson(); }
|
||||||
|
toJson(): T;
|
||||||
|
toJson(delta: true): Partial<T>;
|
||||||
|
toJson(delta?: boolean): T | Partial<T> {
|
||||||
|
return delta
|
||||||
|
? clonePlain(this._mutated)
|
||||||
|
: { ...clonePlain(this._original), ...clonePlain(this._mutated) };
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract clone(): Identity;
|
||||||
|
mutated(): boolean { return Reflect.ownKeys(this._mutated).length > 0; }
|
||||||
|
|
||||||
|
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}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export class IdentityNone extends Identity<ServiceIdentityNone> {
|
||||||
* No authentication
|
constructor() { super({ type: 'NA' }); }
|
||||||
*/
|
static fromJson(_data: ServiceIdentityNone): IdentityNone { return new IdentityNone(); }
|
||||||
export class IdentityNone extends Identity {
|
clone(): IdentityNone { return IdentityNone.fromJson(this.toJson()); }
|
||||||
readonly type = 'NA' as const;
|
get type(): 'NA' { return this._data.type; }
|
||||||
|
|
||||||
static fromJson(_data: ServiceIdentityNone): IdentityNone {
|
|
||||||
return new IdentityNone();
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson(): ServiceIdentityNone {
|
|
||||||
return {
|
|
||||||
type: this.type
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export class IdentityBasic extends Identity<ServiceIdentityBasic> {
|
||||||
* Basic authentication (username/password)
|
constructor(identity: string = '', secret: string = '') { super({ type: 'BA', identity, secret }); }
|
||||||
*/
|
static fromJson(data: ServiceIdentityBasic): IdentityBasic { return new IdentityBasic().load(data); }
|
||||||
export class IdentityBasic extends Identity {
|
clone(): IdentityBasic { return IdentityBasic.fromJson(this.toJson()); }
|
||||||
readonly type = 'BA' as const;
|
get type(): 'BA' { return this._data.type; }
|
||||||
identity: string;
|
get identity(): string { return this._data.identity; }
|
||||||
secret: string;
|
set identity(value: string) { this._data.identity = value; }
|
||||||
|
get secret(): string { return this._data.secret; }
|
||||||
constructor(identity: string = '', secret: string = '') {
|
set secret(value: string) { this._data.secret = value; }
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export class IdentityToken extends Identity<ServiceIdentityToken> {
|
||||||
* Token authentication (API key, static token)
|
constructor(token: string = '') { super({ type: 'TA', token }); }
|
||||||
*/
|
static fromJson(data: ServiceIdentityToken): IdentityToken { return new IdentityToken().load(data); }
|
||||||
export class IdentityToken extends Identity {
|
clone(): IdentityToken { return IdentityToken.fromJson(this.toJson()); }
|
||||||
readonly type = 'TA' as const;
|
get type(): 'TA' { return this._data.type; }
|
||||||
token: string;
|
get token(): string { return this._data.token; }
|
||||||
|
set token(value: string) { this._data.token = value; }
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export class IdentityOAuth extends Identity<ServiceIdentityOAuth> {
|
||||||
* OAuth authentication
|
constructor(accessToken: string = '', accessScope?: string[], accessExpiry?: number, refreshToken?: string, refreshLocation?: string) {
|
||||||
*/
|
super({ type: 'OA', accessToken, accessScope, accessExpiry, refreshToken, refreshLocation });
|
||||||
export class IdentityOAuth extends Identity {
|
}
|
||||||
readonly type = 'OA' as const;
|
|
||||||
accessToken: string;
|
|
||||||
accessScope?: string[];
|
|
||||||
accessExpiry?: number;
|
|
||||||
refreshToken?: string;
|
|
||||||
refreshLocation?: string;
|
|
||||||
|
|
||||||
constructor(
|
static fromJson(data: ServiceIdentityOAuth): IdentityOAuth { return new IdentityOAuth().load(data); }
|
||||||
accessToken: string = '',
|
clone(): IdentityOAuth { return IdentityOAuth.fromJson(this.toJson()); }
|
||||||
accessScope?: string[],
|
isExpired(): boolean { return this.accessExpiry ? Date.now() / 1000 >= this.accessExpiry : false; }
|
||||||
accessExpiry?: number,
|
expiresIn(): number { return this.accessExpiry ? Math.max(0, this.accessExpiry - Date.now() / 1000) : Infinity; }
|
||||||
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 {
|
get type(): 'OA' { return this._data.type; }
|
||||||
return new IdentityOAuth(
|
get accessToken(): string { return this._data.accessToken; }
|
||||||
data.accessToken,
|
set accessToken(value: string) { this._data.accessToken = value; }
|
||||||
data.accessScope,
|
get accessScope(): string[] | undefined { return this._data.accessScope ? [...this._data.accessScope] : undefined; }
|
||||||
data.accessExpiry,
|
set accessScope(value: string[] | undefined) { this._data.accessScope = value ? [...value] : undefined; }
|
||||||
data.refreshToken,
|
get accessExpiry(): number | undefined { return this._data.accessExpiry; }
|
||||||
data.refreshLocation
|
set accessExpiry(value: number | undefined) { this._data.accessExpiry = value; }
|
||||||
);
|
get refreshToken(): string | undefined { return this._data.refreshToken; }
|
||||||
}
|
set refreshToken(value: string | undefined) { this._data.refreshToken = value; }
|
||||||
|
get refreshLocation(): string | undefined { return this._data.refreshLocation; }
|
||||||
toJson(): ServiceIdentityOAuth {
|
set refreshLocation(value: string | undefined) { this._data.refreshLocation = value; }
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export class IdentityCertificate extends Identity<ServiceIdentityCertificate> {
|
||||||
* Client certificate authentication (mTLS)
|
constructor(certificate: string = '', privateKey: string = '', passphrase?: string) {
|
||||||
*/
|
super({ type: 'CC', certificate, privateKey, passphrase });
|
||||||
export class IdentityCertificate extends Identity {
|
}
|
||||||
readonly type = 'CC' as const;
|
|
||||||
certificate: string;
|
|
||||||
privateKey: string;
|
|
||||||
passphrase?: string;
|
|
||||||
|
|
||||||
constructor(certificate: string = '', privateKey: string = '', passphrase?: string) {
|
static fromJson(data: ServiceIdentityCertificate): IdentityCertificate { return new IdentityCertificate().load(data); }
|
||||||
super();
|
clone(): IdentityCertificate { return IdentityCertificate.fromJson(this.toJson()); }
|
||||||
this.certificate = certificate;
|
get type(): 'CC' { return this._data.type; }
|
||||||
this.privateKey = privateKey;
|
get certificate(): string { return this._data.certificate; }
|
||||||
this.passphrase = passphrase;
|
set certificate(value: string) { this._data.certificate = value; }
|
||||||
}
|
get privateKey(): string { return this._data.privateKey; }
|
||||||
|
set privateKey(value: string) { this._data.privateKey = value; }
|
||||||
static fromJson(data: ServiceIdentityCertificate): IdentityCertificate {
|
get passphrase(): string | undefined { return this._data.passphrase; }
|
||||||
return new IdentityCertificate(
|
set passphrase(value: string | undefined) { this._data.passphrase = value; }
|
||||||
data.certificate,
|
|
||||||
data.privateKey,
|
|
||||||
data.passphrase
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
toJson(): ServiceIdentityCertificate {
|
|
||||||
return {
|
|
||||||
type: this.type,
|
|
||||||
certificate: this.certificate,
|
|
||||||
privateKey: this.privateKey,
|
|
||||||
...(this.passphrase && { passphrase: this.passphrase })
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -1,6 +1,6 @@
|
|||||||
export { ProviderObject } from './provider';
|
export { ProviderObject } from './provider';
|
||||||
export { ServiceObject } from './service';
|
export { ServiceObject } from './service';
|
||||||
export { CollectionObject } from './collection';
|
export { CollectionObject, CollectionPropertiesObject } from './collection';
|
||||||
export { EntityObject } from './entity';
|
export { EntityObject } from './entity';
|
||||||
export { EventObject } from './event';
|
export { EventObject } from './event';
|
||||||
export { TaskObject } from './task';
|
export { TaskObject } from './task';
|
||||||
@@ -16,7 +16,6 @@ export {
|
|||||||
export {
|
export {
|
||||||
Location,
|
Location,
|
||||||
LocationUri,
|
LocationUri,
|
||||||
LocationSocketSole,
|
|
||||||
LocationSocketSplit,
|
|
||||||
LocationFile
|
LocationFile
|
||||||
} from './location';
|
} from './location';
|
||||||
|
export { MutationProxy } from './mutation-proxy';
|
||||||
|
|||||||
+78
-227
@@ -1,240 +1,91 @@
|
|||||||
/**
|
/**
|
||||||
* Location implementation classes for Mail Manager services
|
* Location models for Chrono Manager services
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type {
|
import type { ServiceLocation, ServiceLocationFile, ServiceLocationUri } from '@/types/service';
|
||||||
ServiceLocation,
|
import { clonePlain } from './clone-plain';
|
||||||
ServiceLocationUri,
|
import { MutationProxy } from './mutation-proxy';
|
||||||
ServiceLocationSocketSole,
|
|
||||||
ServiceLocationSocketSplit,
|
|
||||||
ServiceLocationFile
|
|
||||||
} from '@/types/service';
|
|
||||||
|
|
||||||
/**
|
export abstract class Location<T extends ServiceLocation = ServiceLocation> {
|
||||||
* Base Location class
|
protected _original: T;
|
||||||
*/
|
protected _mutated: Partial<T>;
|
||||||
export abstract class Location {
|
protected _mutationProxy: MutationProxy<T>;
|
||||||
abstract toJson(): ServiceLocation;
|
protected _data: T;
|
||||||
|
|
||||||
static fromJson(data: ServiceLocation): Location {
|
protected constructor(initial: T) {
|
||||||
switch (data.type) {
|
this._original = clonePlain(initial);
|
||||||
case 'URI':
|
this._mutated = {};
|
||||||
return LocationUri.fromJson(data);
|
this._mutationProxy = new MutationProxy<T>(() => this._original, () => this._mutated);
|
||||||
case 'SOCKET_SOLE':
|
this._data = this._mutationProxy.create();
|
||||||
return LocationSocketSole.fromJson(data);
|
}
|
||||||
case 'SOCKET_SPLIT':
|
|
||||||
return LocationSocketSplit.fromJson(data);
|
protected load(data: T): this {
|
||||||
case 'FILE':
|
this._original = clonePlain(data);
|
||||||
return LocationFile.fromJson(data);
|
this._mutated = {};
|
||||||
default:
|
this._data = this._mutationProxy.create();
|
||||||
throw new Error(`Unknown location type: ${(data as any).type}`);
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
toJson(): T;
|
||||||
|
toJson(delta: true): Partial<T>;
|
||||||
|
toJson(delta?: boolean): T | Partial<T> {
|
||||||
|
return delta
|
||||||
|
? clonePlain(this._mutated)
|
||||||
|
: { ...clonePlain(this._original), ...clonePlain(this._mutated) };
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract clone(): Location;
|
||||||
|
|
||||||
|
mutated(): boolean {
|
||||||
|
return Reflect.ownKeys(this._mutated).length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static fromJson(data: ServiceLocation): Location {
|
||||||
|
switch (data.type) {
|
||||||
|
case 'URI': return LocationUri.fromJson(data);
|
||||||
|
case 'FILE': return LocationFile.fromJson(data);
|
||||||
|
default: throw new Error(`Unknown location type: ${(data as any).type}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export class LocationUri extends Location<ServiceLocationUri> {
|
||||||
* URI-based service location for API and web services
|
constructor(
|
||||||
* Used by: JMAP, Gmail API, etc.
|
scheme: string = 'https',
|
||||||
*/
|
host: string = '',
|
||||||
export class LocationUri extends Location {
|
port: number = 443,
|
||||||
readonly type = 'URI' as const;
|
path?: string,
|
||||||
scheme: string;
|
verifyPeer: boolean = true,
|
||||||
host: string;
|
verifyHost: boolean = true
|
||||||
port: number;
|
) {
|
||||||
path?: string;
|
super({ type: 'URI', scheme, host, port, ...(path !== undefined && { path }), verifyPeer, verifyHost });
|
||||||
verifyPeer: boolean;
|
}
|
||||||
verifyHost: boolean;
|
|
||||||
|
|
||||||
constructor(
|
static fromJson(data: ServiceLocationUri): LocationUri { return new LocationUri().load(data); }
|
||||||
scheme: string = 'https',
|
clone(): LocationUri { return LocationUri.fromJson(this.toJson()); }
|
||||||
host: string = '',
|
getUrl(): string { return `${this.scheme}://${this.host}:${this.port}${this.path || ''}`; }
|
||||||
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 {
|
get type(): 'URI' { return this._data.type; }
|
||||||
return new LocationUri(
|
get scheme(): string { return this._data.scheme; }
|
||||||
data.scheme,
|
set scheme(value: string) { this._data.scheme = value; }
|
||||||
data.host,
|
get host(): string { return this._data.host; }
|
||||||
data.port,
|
set host(value: string) { this._data.host = value; }
|
||||||
data.path,
|
get port(): number { return this._data.port; }
|
||||||
data.verifyPeer ?? true,
|
set port(value: number) { this._data.port = value; }
|
||||||
data.verifyHost ?? true
|
get path(): string | undefined { return this._data.path; }
|
||||||
);
|
set path(value: string | undefined) { this._data.path = value; }
|
||||||
}
|
get verifyPeer(): boolean { return this._data.verifyPeer ?? true; }
|
||||||
|
set verifyPeer(value: boolean) { this._data.verifyPeer = value; }
|
||||||
toJson(): ServiceLocationUri {
|
get verifyHost(): boolean { return this._data.verifyHost ?? true; }
|
||||||
return {
|
set verifyHost(value: boolean) { this._data.verifyHost = value; }
|
||||||
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}`;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
export class LocationFile extends Location<ServiceLocationFile> {
|
||||||
* Single socket-based service location
|
constructor(path: string = '') { super({ type: 'FILE', path }); }
|
||||||
* Used by: services using a single host/port combination
|
static fromJson(data: ServiceLocationFile): LocationFile { return new LocationFile().load(data); }
|
||||||
*/
|
clone(): LocationFile { return LocationFile.fromJson(this.toJson()); }
|
||||||
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(
|
get type(): 'FILE' { return this._data.type; }
|
||||||
host: string = '',
|
get path(): string { return this._data.path; }
|
||||||
port: number = 993,
|
set path(value: string) { this._data.path = value; }
|
||||||
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
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { clonePlain } from './clone-plain';
|
||||||
|
|
||||||
|
export class MutationProxy<T extends object> {
|
||||||
|
constructor(
|
||||||
|
private readonly getOriginal: () => T,
|
||||||
|
private readonly getMutated: () => Partial<T>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
create(): T {
|
||||||
|
return new Proxy({} as T, {
|
||||||
|
get: (_target, prop: string | symbol) => {
|
||||||
|
if (typeof prop !== 'string') return undefined;
|
||||||
|
|
||||||
|
const key = prop as keyof T;
|
||||||
|
const mutated = this.getMutated();
|
||||||
|
return key in mutated ? mutated[key] : this.getOriginal()[key];
|
||||||
|
},
|
||||||
|
set: (_target, prop: string | symbol, value: unknown) => {
|
||||||
|
if (typeof prop === 'string') {
|
||||||
|
const key = prop as keyof T;
|
||||||
|
(this.getMutated() as Record<keyof T, unknown>)[key] = clonePlain(value);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
has: (_target, prop: string | symbol) => {
|
||||||
|
if (typeof prop !== 'string') return false;
|
||||||
|
return prop in this.getMutated() || prop in this.getOriginal();
|
||||||
|
},
|
||||||
|
ownKeys: () => Array.from(new Set([
|
||||||
|
...Reflect.ownKeys(this.getOriginal()),
|
||||||
|
...Reflect.ownKeys(this.getMutated()),
|
||||||
|
])),
|
||||||
|
getOwnPropertyDescriptor: () => ({ enumerable: true, configurable: true }),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
-9
@@ -4,10 +4,12 @@
|
|||||||
|
|
||||||
import type {
|
import type {
|
||||||
ProviderInterface,
|
ProviderInterface,
|
||||||
ProviderCapabilitiesInterface
|
ProviderCapabilitiesInterface,
|
||||||
|
ProviderModelInterface
|
||||||
} from "@/types/provider";
|
} from "@/types/provider";
|
||||||
|
import { clonePlain } from './clone-plain';
|
||||||
|
|
||||||
export class ProviderObject implements ProviderInterface {
|
export class ProviderObject implements ProviderModelInterface {
|
||||||
|
|
||||||
_data!: ProviderInterface;
|
_data!: ProviderInterface;
|
||||||
|
|
||||||
@@ -21,12 +23,16 @@ export class ProviderObject implements ProviderInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fromJson(data: ProviderInterface): ProviderObject {
|
fromJson(data: ProviderInterface): ProviderObject {
|
||||||
this._data = data;
|
this._data = clonePlain(data);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(): ProviderInterface {
|
toJson(): ProviderInterface {
|
||||||
return this._data;
|
return clonePlain(this._data);
|
||||||
|
}
|
||||||
|
|
||||||
|
clone(): ProviderObject {
|
||||||
|
return new ProviderObject().fromJson(this.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
capable(capability: keyof ProviderCapabilitiesInterface): boolean {
|
capable(capability: keyof ProviderCapabilitiesInterface): boolean {
|
||||||
@@ -43,10 +49,6 @@ export class ProviderObject implements ProviderInterface {
|
|||||||
|
|
||||||
/** Immutable Properties */
|
/** Immutable Properties */
|
||||||
|
|
||||||
get '@type'(): string {
|
|
||||||
return this._data['@type'];
|
|
||||||
}
|
|
||||||
|
|
||||||
get identifier(): string {
|
get identifier(): string {
|
||||||
return this._data.identifier;
|
return this._data.identifier;
|
||||||
}
|
}
|
||||||
@@ -56,7 +58,7 @@ export class ProviderObject implements ProviderInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get capabilities(): ProviderCapabilitiesInterface {
|
get capabilities(): ProviderCapabilitiesInterface {
|
||||||
return this._data.capabilities;
|
return clonePlain(this._data.capabilities);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+86
-81
@@ -5,18 +5,26 @@
|
|||||||
import type {
|
import type {
|
||||||
ServiceInterface,
|
ServiceInterface,
|
||||||
ServiceCapabilitiesInterface,
|
ServiceCapabilitiesInterface,
|
||||||
ServiceIdentity,
|
ServiceLocation,
|
||||||
ServiceLocation
|
ServiceModelInterface
|
||||||
} from "@/types/service";
|
} from "@/types/service";
|
||||||
import { Identity } from './identity';
|
import { Identity } from './identity';
|
||||||
import { Location } from './location';
|
import { Location } from './location';
|
||||||
|
import { MutationProxy } from './mutation-proxy';
|
||||||
|
import { clonePlain } from './clone-plain';
|
||||||
|
|
||||||
export class ServiceObject implements ServiceInterface {
|
export class ServiceObject implements ServiceModelInterface {
|
||||||
|
private _original: ServiceInterface;
|
||||||
|
private _mutated: Partial<ServiceInterface>;
|
||||||
|
private _mutationProxy = new MutationProxy<ServiceInterface>(() => this._original, () => this._mutated);
|
||||||
_data!: ServiceInterface;
|
_data!: ServiceInterface;
|
||||||
|
private _location: Location | null | undefined = undefined;
|
||||||
|
private _identity: Identity | null | undefined = undefined;
|
||||||
|
private _locationAssigned = false;
|
||||||
|
private _identityAssigned = false;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this._data = {
|
this._original = {
|
||||||
'@type': 'chrono:service',
|
'@type': 'chrono:service',
|
||||||
provider: '',
|
provider: '',
|
||||||
identifier: null,
|
identifier: null,
|
||||||
@@ -24,15 +32,59 @@ export class ServiceObject implements ServiceInterface {
|
|||||||
enabled: false,
|
enabled: false,
|
||||||
capabilities: {}
|
capabilities: {}
|
||||||
};
|
};
|
||||||
|
this._mutated = {};
|
||||||
|
this._data = this._mutationProxy.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
fromJson(data: ServiceInterface): ServiceObject {
|
fromJson(data: ServiceInterface): ServiceObject {
|
||||||
this._data = data;
|
this._original = clonePlain(data);
|
||||||
|
this._mutated = {};
|
||||||
|
this._data = this._mutationProxy.create();
|
||||||
|
this._location = undefined;
|
||||||
|
this._identity = undefined;
|
||||||
|
this._locationAssigned = false;
|
||||||
|
this._identityAssigned = false;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJson(): ServiceInterface {
|
toJson(): ServiceInterface;
|
||||||
return this._data;
|
toJson(delta: true): Partial<ServiceInterface>;
|
||||||
|
toJson(delta?: boolean): ServiceInterface | Partial<ServiceInterface> {
|
||||||
|
if (delta) {
|
||||||
|
const json = clonePlain(this._mutated);
|
||||||
|
if (this._locationAssigned) {
|
||||||
|
json.location = this._location ? this._location.toJson() : null;
|
||||||
|
} else if (this._location?.mutated()) {
|
||||||
|
json.location = this._location.toJson(true) as ServiceInterface['location'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._identityAssigned) {
|
||||||
|
json.identity = this._identity ? this._identity.toJson() : null;
|
||||||
|
} else if (this._identity?.mutated()) {
|
||||||
|
json.identity = this._identity.toJson(true) as ServiceInterface['identity'];
|
||||||
|
}
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
const json: ServiceInterface = {
|
||||||
|
...clonePlain(this._original),
|
||||||
|
...clonePlain(this._mutated),
|
||||||
|
};
|
||||||
|
if (this._location !== undefined) json.location = this._location ? this._location.toJson() : null;
|
||||||
|
if (this._identity !== undefined) json.identity = this._identity ? this._identity.toJson() : null;
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
clone(): ServiceObject {
|
||||||
|
return new ServiceObject().fromJson(this.toJson());
|
||||||
|
}
|
||||||
|
|
||||||
|
mutated(): boolean {
|
||||||
|
return Reflect.ownKeys(this._mutated).length > 0
|
||||||
|
|| this._locationAssigned
|
||||||
|
|| this._identityAssigned
|
||||||
|
|| (this._location?.mutated() ?? false)
|
||||||
|
|| (this._identity?.mutated() ?? false);
|
||||||
}
|
}
|
||||||
|
|
||||||
capable(capability: keyof ServiceCapabilitiesInterface): boolean {
|
capable(capability: keyof ServiceCapabilitiesInterface): boolean {
|
||||||
@@ -41,88 +93,41 @@ export class ServiceObject implements ServiceInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
capability(capability: keyof ServiceCapabilitiesInterface): any | null {
|
capability(capability: keyof ServiceCapabilitiesInterface): any | null {
|
||||||
if (this._data.capabilities) {
|
return this._data.capabilities?.[capability] ?? null;
|
||||||
return this._data.capabilities[capability];
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Immutable Properties */
|
get provider(): string { return this._data.provider; }
|
||||||
|
get identifier(): string | number | null { return this._data.identifier; }
|
||||||
|
get capabilities(): ServiceCapabilitiesInterface { return this._data.capabilities ?? {}; }
|
||||||
|
|
||||||
get '@type'(): string {
|
get label(): string | null { return this._data.label; }
|
||||||
return this._data['@type'];
|
set label(value: string | null) { this._data.label = value; }
|
||||||
|
|
||||||
|
get enabled(): boolean { return this._data.enabled; }
|
||||||
|
set enabled(value: boolean) { this._data.enabled = value; }
|
||||||
|
|
||||||
|
get location(): Location | null {
|
||||||
|
if (this._location !== undefined) return this._location;
|
||||||
|
this._location = this._data.location ? Location.fromJson(this._data.location as ServiceLocation) : null;
|
||||||
|
return this._location;
|
||||||
}
|
}
|
||||||
|
|
||||||
get provider(): string {
|
set location(value: Location | null) {
|
||||||
return this._data.provider;
|
this._location = value;
|
||||||
|
this._locationAssigned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
get identifier(): string | number | null {
|
get identity(): Identity | null {
|
||||||
return this._data.identifier;
|
if (this._identity !== undefined) return this._identity;
|
||||||
|
this._identity = this._data.identity ? Identity.fromJson(this._data.identity) : null;
|
||||||
|
return this._identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
get capabilities(): ServiceCapabilitiesInterface | undefined {
|
set identity(value: Identity | null) {
|
||||||
return this._data.capabilities;
|
this._identity = value;
|
||||||
}
|
this._identityAssigned = true;
|
||||||
|
|
||||||
/** Mutable Properties */
|
|
||||||
|
|
||||||
get label(): string | null {
|
|
||||||
return this._data.label;
|
|
||||||
}
|
|
||||||
|
|
||||||
set label(value: string | null) {
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get auxiliary(): Record<string, any> { return this._data.auxiliary ?? {}; }
|
||||||
|
set auxiliary(value: Record<string, any>) { this._data.auxiliary = value; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,9 +70,15 @@ export const collectionService = {
|
|||||||
*
|
*
|
||||||
* @returns Promise with collection object
|
* @returns Promise with collection object
|
||||||
*/
|
*/
|
||||||
async fetch(request: CollectionFetchRequest): Promise<CollectionObject> {
|
async fetch(request: CollectionFetchRequest): Promise<Record<string, CollectionObject>> {
|
||||||
const response = await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request);
|
const response = await transceivePost<CollectionFetchRequest, CollectionFetchResponse>('collection.fetch', request);
|
||||||
return createCollectionObject(response);
|
|
||||||
|
const list: Record<string, CollectionObject> = {};
|
||||||
|
Object.entries(response).forEach(([, collection]) => {
|
||||||
|
list[collection.identifier] = createCollectionObject(collection);
|
||||||
|
});
|
||||||
|
|
||||||
|
return list;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,8 +129,14 @@ export const collectionService = {
|
|||||||
*
|
*
|
||||||
* @returns Promise with deletion result
|
* @returns Promise with deletion result
|
||||||
*/
|
*/
|
||||||
async delete(request: CollectionDeleteRequest): Promise<CollectionDeleteResponse> {
|
async delete(request: CollectionDeleteRequest): Promise<boolean | CollectionObject> {
|
||||||
return await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
|
const response = await transceivePost<CollectionDeleteRequest, CollectionDeleteResponse>('collection.delete', request);
|
||||||
|
|
||||||
|
if (response.disposition === 'moved' && response.mutation) {
|
||||||
|
return createCollectionObject(response.mutation);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,12 @@
|
|||||||
* Entity management service
|
* Entity management service
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { transceivePost } from './transceive';
|
import { transceivePost, transceiveStream } from './transceive';
|
||||||
import type {
|
import type {
|
||||||
EntityListRequest,
|
EntityListBulkRequest,
|
||||||
EntityListResponse,
|
EntityListBulkResponse,
|
||||||
|
EntityListStreamRequest,
|
||||||
|
EntityListStreamResponse,
|
||||||
EntityFetchRequest,
|
EntityFetchRequest,
|
||||||
EntityFetchResponse,
|
EntityFetchResponse,
|
||||||
EntityExtantRequest,
|
EntityExtantRequest,
|
||||||
@@ -18,6 +20,8 @@ import type {
|
|||||||
EntityDeleteResponse,
|
EntityDeleteResponse,
|
||||||
EntityDeltaRequest,
|
EntityDeltaRequest,
|
||||||
EntityDeltaResponse,
|
EntityDeltaResponse,
|
||||||
|
EntityMoveRequest,
|
||||||
|
EntityMoveResponse,
|
||||||
EntityInterface,
|
EntityInterface,
|
||||||
} from '../types/entity';
|
} from '../types/entity';
|
||||||
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
import { useIntegrationStore } from '@KTXC/stores/integrationStore';
|
||||||
@@ -31,7 +35,7 @@ function createEntityObject(data: EntityInterface): EntityObject {
|
|||||||
const integrationStore = useIntegrationStore();
|
const integrationStore = useIntegrationStore();
|
||||||
const factoryItem = integrationStore.getItemById('chrono_entity_factory', data.provider) as any;
|
const factoryItem = integrationStore.getItemById('chrono_entity_factory', data.provider) as any;
|
||||||
const factory = factoryItem?.factory;
|
const factory = factoryItem?.factory;
|
||||||
|
|
||||||
// Use provider factory if available, otherwise base class
|
// Use provider factory if available, otherwise base class
|
||||||
return factory ? factory(data) : new EntityObject().fromJson(data);
|
return factory ? factory(data) : new EntityObject().fromJson(data);
|
||||||
}
|
}
|
||||||
@@ -39,16 +43,11 @@ function createEntityObject(data: EntityInterface): EntityObject {
|
|||||||
export const entityService = {
|
export const entityService = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve list of entities, optionally filtered by source selector
|
* Retrieve list of entities, optionally filtered by source collection identifiers
|
||||||
*
|
|
||||||
* @param request - list request parameters
|
|
||||||
*
|
|
||||||
* @returns Promise with entity object list grouped by provider, service, collection, and entity identifier
|
|
||||||
*/
|
*/
|
||||||
async list(request: EntityListRequest = {}): Promise<Record<string, Record<string, Record<string, Record<string, EntityObject>>>>> {
|
async listBulk(request: EntityListBulkRequest = {}): Promise<Record<string, Record<string, Record<string, Record<string, EntityObject>>>>> {
|
||||||
const response = await transceivePost<EntityListRequest, EntityListResponse>('entity.list', request);
|
const response = await transceivePost<EntityListBulkRequest, EntityListBulkResponse>('entity.listBulk', request);
|
||||||
|
|
||||||
// Convert nested response to EntityObject instances
|
|
||||||
const providerList: Record<string, Record<string, Record<string, Record<string, EntityObject>>>> = {};
|
const providerList: Record<string, Record<string, Record<string, Record<string, EntityObject>>>> = {};
|
||||||
Object.entries(response).forEach(([providerId, providerServices]) => {
|
Object.entries(response).forEach(([providerId, providerServices]) => {
|
||||||
const serviceList: Record<string, Record<string, Record<string, EntityObject>>> = {};
|
const serviceList: Record<string, Record<string, Record<string, EntityObject>>> = {};
|
||||||
@@ -65,35 +64,39 @@ export const entityService = {
|
|||||||
});
|
});
|
||||||
providerList[providerId] = serviceList;
|
providerList[providerId] = serviceList;
|
||||||
});
|
});
|
||||||
|
|
||||||
return providerList;
|
return providerList;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a specific entity by provider and identifier
|
* Stream entities as NDJSON, invoking onEntity for each entity as it arrives.
|
||||||
*
|
*/
|
||||||
* @param request - fetch request parameters
|
async listStream(request: EntityListStreamRequest, onEntity: (entity: EntityObject) => void): Promise<{ total: number }> {
|
||||||
*
|
return await transceiveStream<EntityListStreamRequest, EntityListStreamResponse>(
|
||||||
* @returns Promise with entity objects keyed by identifier
|
'entity.listStream',
|
||||||
|
request,
|
||||||
|
(entity) => {
|
||||||
|
onEntity(createEntityObject(entity));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve specific entities by their identifiers
|
||||||
*/
|
*/
|
||||||
async fetch(request: EntityFetchRequest): Promise<Record<string, EntityObject>> {
|
async fetch(request: EntityFetchRequest): Promise<Record<string, EntityObject>> {
|
||||||
const response = await transceivePost<EntityFetchRequest, EntityFetchResponse>('entity.fetch', request);
|
const response = await transceivePost<EntityFetchRequest, EntityFetchResponse>('entity.fetch', request);
|
||||||
|
|
||||||
// Convert response to EntityObject instances
|
|
||||||
const list: Record<string, EntityObject> = {};
|
const list: Record<string, EntityObject> = {};
|
||||||
Object.entries(response).forEach(([identifier, entityData]) => {
|
Object.entries(response).forEach(([, entity]) => {
|
||||||
list[identifier] = createEntityObject(entityData);
|
list[entity.identifier] = createEntityObject(entity);
|
||||||
});
|
});
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve entity availability status for a given source selector
|
* Retrieve entity availability status for a given set of entity identifiers
|
||||||
*
|
|
||||||
* @param request - extant request parameters
|
|
||||||
*
|
|
||||||
* @returns Promise with entity availability status
|
|
||||||
*/
|
*/
|
||||||
async extant(request: EntityExtantRequest): Promise<EntityExtantResponse> {
|
async extant(request: EntityExtantRequest): Promise<EntityExtantResponse> {
|
||||||
return await transceivePost<EntityExtantRequest, EntityExtantResponse>('entity.extant', request);
|
return await transceivePost<EntityExtantRequest, EntityExtantResponse>('entity.extant', request);
|
||||||
@@ -101,10 +104,6 @@ export const entityService = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new entity
|
* Create a new entity
|
||||||
*
|
|
||||||
* @param request - create request parameters
|
|
||||||
*
|
|
||||||
* @returns Promise with created entity object
|
|
||||||
*/
|
*/
|
||||||
async create(request: EntityCreateRequest): Promise<EntityObject> {
|
async create(request: EntityCreateRequest): Promise<EntityObject> {
|
||||||
const response = await transceivePost<EntityCreateRequest, EntityCreateResponse>('entity.create', request);
|
const response = await transceivePost<EntityCreateRequest, EntityCreateResponse>('entity.create', request);
|
||||||
@@ -113,10 +112,6 @@ export const entityService = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an existing entity
|
* Update an existing entity
|
||||||
*
|
|
||||||
* @param request - update request parameters
|
|
||||||
*
|
|
||||||
* @returns Promise with updated entity object
|
|
||||||
*/
|
*/
|
||||||
async update(request: EntityUpdateRequest): Promise<EntityObject> {
|
async update(request: EntityUpdateRequest): Promise<EntityObject> {
|
||||||
const response = await transceivePost<EntityUpdateRequest, EntityUpdateResponse>('entity.update', request);
|
const response = await transceivePost<EntityUpdateRequest, EntityUpdateResponse>('entity.update', request);
|
||||||
@@ -124,11 +119,7 @@ export const entityService = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an entity
|
* Delete entities by their identifiers
|
||||||
*
|
|
||||||
* @param request - delete request parameters
|
|
||||||
*
|
|
||||||
* @returns Promise with deletion result
|
|
||||||
*/
|
*/
|
||||||
async delete(request: EntityDeleteRequest): Promise<EntityDeleteResponse> {
|
async delete(request: EntityDeleteRequest): Promise<EntityDeleteResponse> {
|
||||||
return await transceivePost<EntityDeleteRequest, EntityDeleteResponse>('entity.delete', request);
|
return await transceivePost<EntityDeleteRequest, EntityDeleteResponse>('entity.delete', request);
|
||||||
@@ -136,15 +127,18 @@ export const entityService = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve delta changes for entities
|
* Retrieve delta changes for entities
|
||||||
*
|
|
||||||
* @param request - delta request parameters
|
|
||||||
*
|
|
||||||
* @returns Promise with delta changes (created, modified, deleted)
|
|
||||||
*/
|
*/
|
||||||
async delta(request: EntityDeltaRequest): Promise<EntityDeltaResponse> {
|
async delta(request: EntityDeltaRequest): Promise<EntityDeltaResponse> {
|
||||||
return await transceivePost<EntityDeltaRequest, EntityDeltaResponse>('entity.delta', request);
|
return await transceivePost<EntityDeltaRequest, EntityDeltaResponse>('entity.delta', request);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move entities to a target collection
|
||||||
|
*/
|
||||||
|
async move(request: EntityMoveRequest): Promise<EntityMoveResponse> {
|
||||||
|
return await transceivePost<EntityMoveRequest, EntityMoveResponse>('entity.move', request);
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default entityService;
|
export default entityService;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { createFetchWrapper } from '@KTXC';
|
import { createFetchWrapper } from '@KTXC';
|
||||||
import type { ApiRequest, ApiResponse } from '../types/common';
|
import type { ApiRequest, ApiResponse, ApiStreamResponse } from '../types/common';
|
||||||
|
|
||||||
const fetchWrapper = createFetchWrapper();
|
const fetchWrapper = createFetchWrapper();
|
||||||
const API_URL = '/m/chrono_manager/v1';
|
const API_URL = '/m/chrono_manager/v1';
|
||||||
@@ -48,3 +48,82 @@ export async function transceivePost<TRequest, TResponse>(
|
|||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stream an NDJSON API response, unwrapping data frames for the caller.
|
||||||
|
*
|
||||||
|
* @param operation - Operation name, e.g. 'entity.listStream'
|
||||||
|
* @param data - Operation-specific request data
|
||||||
|
* @param onData - Synchronous callback invoked for every unwrapped data payload.
|
||||||
|
* @param options - Optional `user` override and an `onStart` hook.
|
||||||
|
* @returns Promise resolving to the final stream total from the control/end frame
|
||||||
|
*/
|
||||||
|
export async function transceiveStream<TRequest, TData>(
|
||||||
|
operation: string,
|
||||||
|
data: TRequest,
|
||||||
|
onData: (data: TData) => void,
|
||||||
|
options?: { user?: string; onStart?: (expected?: number) => void }
|
||||||
|
): Promise<{ total: number }> {
|
||||||
|
const request: ApiRequest<TRequest> = {
|
||||||
|
version: API_VERSION,
|
||||||
|
transaction: generateTransactionId(),
|
||||||
|
operation,
|
||||||
|
data,
|
||||||
|
user: options?.user,
|
||||||
|
};
|
||||||
|
|
||||||
|
let total = 0;
|
||||||
|
|
||||||
|
const dispatch = (line: string): void => {
|
||||||
|
const message = JSON.parse(line) as ApiStreamResponse<TData>;
|
||||||
|
|
||||||
|
if (message.type === 'control') {
|
||||||
|
if (message.status === 'start') {
|
||||||
|
options?.onStart?.(message.total);
|
||||||
|
} else if (message.status === 'end') {
|
||||||
|
total = message.total;
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message.type === 'error') {
|
||||||
|
throw new Error(`[${operation}] ${message.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
onData(message.data);
|
||||||
|
};
|
||||||
|
|
||||||
|
await fetchWrapper.post(API_URL, request, {
|
||||||
|
headers: { 'Accept': 'application/json' },
|
||||||
|
onStream: async (response: Response) => {
|
||||||
|
if (!response.body) {
|
||||||
|
throw new Error(`[${operation}] Response body is not readable`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const reader = response.body.getReader();
|
||||||
|
const decoder = new TextDecoder();
|
||||||
|
let buffer = '';
|
||||||
|
|
||||||
|
try {
|
||||||
|
while (true) {
|
||||||
|
const { done, value } = await reader.read();
|
||||||
|
if (done) break;
|
||||||
|
|
||||||
|
buffer += decoder.decode(value, { stream: true });
|
||||||
|
const lines = buffer.split('\n');
|
||||||
|
buffer = lines.pop()!;
|
||||||
|
|
||||||
|
for (const line of lines) {
|
||||||
|
if (line.trim()) dispatch(line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buffer.trim()) dispatch(buffer);
|
||||||
|
} finally {
|
||||||
|
reader.releaseLock();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return { total };
|
||||||
|
}
|
||||||
|
|||||||
+78
-144
@@ -4,9 +4,14 @@
|
|||||||
|
|
||||||
import { ref, computed, readonly } from 'vue'
|
import { ref, computed, readonly } from 'vue'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
|
import {
|
||||||
|
type ServiceIdentifier,
|
||||||
|
type CollectionIdentifier,
|
||||||
|
type ListFilter,
|
||||||
|
type ListSort,
|
||||||
|
} from '../types'
|
||||||
import { collectionService } from '../services'
|
import { collectionService } from '../services'
|
||||||
import { CollectionObject, CollectionPropertiesObject } from '../models/collection'
|
import { CollectionObject, CollectionPropertiesObject } from '../models/collection'
|
||||||
import type { SourceSelector, ListFilter, ListSort } from '../types'
|
|
||||||
|
|
||||||
export const useCollectionsStore = defineStore('chronoCollectionsStore', () => {
|
export const useCollectionsStore = defineStore('chronoCollectionsStore', () => {
|
||||||
// State
|
// State
|
||||||
@@ -33,101 +38,61 @@ export const useCollectionsStore = defineStore('chronoCollectionsStore', () => {
|
|||||||
*/
|
*/
|
||||||
const collectionsByService = computed(() => {
|
const collectionsByService = computed(() => {
|
||||||
const groups: Record<string, CollectionObject[]> = {}
|
const groups: Record<string, CollectionObject[]> = {}
|
||||||
|
|
||||||
Object.values(_collections.value).forEach((collection) => {
|
Object.values(_collections.value).forEach((collection) => {
|
||||||
const serviceKey = `${collection.provider}:${collection.service}`
|
const serviceKey = `${collection.provider}:${collection.service}`
|
||||||
if (!groups[serviceKey]) {
|
const serviceCollections = (groups[serviceKey] ??= [])
|
||||||
groups[serviceKey] = []
|
serviceCollections.push(collection)
|
||||||
}
|
|
||||||
groups[serviceKey].push(collection)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return groups
|
return groups
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a specific collection from store, with optional retrieval
|
* Get a specific collection from store, with optional retrieval
|
||||||
*
|
|
||||||
* @param provider - provider identifier
|
|
||||||
* @param service - service identifier
|
|
||||||
* @param identifier - collection identifier
|
|
||||||
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
|
|
||||||
*
|
|
||||||
* @returns Collection object or null
|
|
||||||
*/
|
*/
|
||||||
function collection(provider: string, service: string | number, identifier: string | number, retrieve: boolean = false): CollectionObject | null {
|
function collection(target: CollectionIdentifier, retrieve: boolean = false): CollectionObject | null {
|
||||||
const key = identifierKey(provider, service, identifier)
|
if (retrieve === true && !_collections.value[target]) {
|
||||||
if (retrieve === true && !_collections.value[key]) {
|
console.debug(`[Chrono Manager][Store] - Force fetching collection "${target}"`)
|
||||||
console.debug(`[Chrono Manager][Store] - Force fetching collection "${key}"`)
|
fetch([target])
|
||||||
fetch(provider, service, identifier)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _collections.value[key] || null
|
return _collections.value[target] || null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all collections for a specific service
|
* Get all collections for a specific service
|
||||||
*
|
|
||||||
* @param provider - provider identifier
|
|
||||||
* @param service - service identifier
|
|
||||||
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
|
|
||||||
*
|
|
||||||
* @returns Array of collection objects
|
|
||||||
*/
|
*/
|
||||||
function collectionsForService(provider: string, service: string | number, retrieve: boolean = false): CollectionObject[] {
|
function collectionsForService(provider: string, service: string | number, retrieve: boolean = false): CollectionObject[] {
|
||||||
const serviceKeyPrefix = `${provider}:${service}:`
|
const serviceIdentifier = `${provider}:${service}` as ServiceIdentifier
|
||||||
const serviceCollections = Object.entries(_collections.value)
|
const serviceCollections = Object.values(_collections.value)
|
||||||
.filter(([key]) => key.startsWith(serviceKeyPrefix))
|
.filter(collection => `${collection.provider}:${collection.service}` === serviceIdentifier)
|
||||||
.map(([_, collection]) => collection)
|
|
||||||
|
|
||||||
if (retrieve === true && serviceCollections.length === 0) {
|
if (retrieve === true && serviceCollections.length === 0) {
|
||||||
console.debug(`[Chrono Manager][Store] - Force fetching collections for service "${provider}:${service}"`)
|
console.debug(`[Chrono Manager][Store] - Force fetching collections for service "${serviceIdentifier}"`)
|
||||||
const sources: SourceSelector = {
|
list([serviceIdentifier])
|
||||||
[provider]: {
|
|
||||||
[String(service)]: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
list(sources)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return serviceCollections
|
return serviceCollections
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create unique key for a collection
|
* Retrieve all or specific collections, optionally filtered by service/collection identifiers
|
||||||
*/
|
*/
|
||||||
function identifierKey(provider: string, service: string | number | null, identifier: string | number | null): string {
|
async function list(sources?: ServiceIdentifier[] | CollectionIdentifier[], filter?: ListFilter, sort?: ListSort): Promise<Record<string, CollectionObject>> {
|
||||||
return `${provider}:${service ?? ''}:${identifier ?? ''}`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actions
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve all or specific collections, optionally filtered by source selector
|
|
||||||
*
|
|
||||||
* @param sources - optional source selector
|
|
||||||
* @param filter - optional list filter
|
|
||||||
* @param sort - optional list sort
|
|
||||||
*
|
|
||||||
* @returns Promise with collection object list keyed by provider, service, and collection identifier
|
|
||||||
*/
|
|
||||||
async function list(sources?: SourceSelector, filter?: ListFilter, sort?: ListSort): Promise<Record<string, CollectionObject>> {
|
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await collectionService.list({ sources, filter, sort })
|
const response = await collectionService.list({ sources, filter, sort })
|
||||||
|
|
||||||
// Flatten nested structure: provider:service:collection -> "provider:service:collection": object
|
|
||||||
const collections: Record<string, CollectionObject> = {}
|
const collections: Record<string, CollectionObject> = {}
|
||||||
Object.entries(response).forEach(([_providerId, providerServices]) => {
|
Object.entries(response).forEach(([_providerId, providerServices]) => {
|
||||||
Object.entries(providerServices).forEach(([_serviceId, serviceCollections]) => {
|
Object.entries(providerServices).forEach(([_serviceId, serviceCollections]) => {
|
||||||
Object.entries(serviceCollections).forEach(([_collectionId, collectionObj]) => {
|
Object.entries(serviceCollections).forEach(([_collectionId, collectionObj]) => {
|
||||||
const key = identifierKey(collectionObj.provider, collectionObj.service, collectionObj.identifier)
|
collections[collectionObj.identifier] = collectionObj
|
||||||
collections[key] = collectionObj
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// Merge retrieved collections into state
|
|
||||||
_collections.value = { ..._collections.value, ...collections }
|
_collections.value = { ..._collections.value, ...collections }
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully retrieved', Object.keys(collections).length, 'collections')
|
console.debug('[Chrono Manager][Store] - Successfully retrieved', Object.keys(collections).length, 'collections')
|
||||||
@@ -139,29 +104,23 @@ export const useCollectionsStore = defineStore('chronoCollectionsStore', () => {
|
|||||||
transceiving.value = false
|
transceiving.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve a specific collection by provider, service, and identifier
|
* Retrieve specific collections by their identifiers
|
||||||
*
|
|
||||||
* @param provider - provider identifier
|
|
||||||
* @param service - service identifier
|
|
||||||
* @param identifier - collection identifier
|
|
||||||
*
|
|
||||||
* @returns Promise with collection object
|
|
||||||
*/
|
*/
|
||||||
async function fetch(provider: string, service: string | number, identifier: string | number): Promise<CollectionObject> {
|
async function fetch(targets: CollectionIdentifier[]): Promise<Record<string, CollectionObject>> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await collectionService.fetch({ provider, service, collection: identifier })
|
const response = await collectionService.fetch({ targets })
|
||||||
|
|
||||||
// Merge fetched collection into state
|
|
||||||
const key = identifierKey(response.provider, response.service, response.identifier)
|
|
||||||
_collections.value[key] = response
|
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully fetched collection:', key)
|
Object.values(response).forEach(collectionObj => {
|
||||||
|
_collections.value[collectionObj.identifier] = collectionObj
|
||||||
|
})
|
||||||
|
|
||||||
|
console.debug('[Chrono Manager][Store] - Successfully fetched collections:', Object.keys(response).join(', '))
|
||||||
return response
|
return response
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('[Chrono Manager][Store] - Failed to fetch collection:', error)
|
console.error('[Chrono Manager][Store] - Failed to fetch collections:', error)
|
||||||
throw error
|
throw error
|
||||||
} finally {
|
} finally {
|
||||||
transceiving.value = false
|
transceiving.value = false
|
||||||
@@ -169,18 +128,14 @@ export const useCollectionsStore = defineStore('chronoCollectionsStore', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve collection availability status for a given source selector
|
* Retrieve collection availability status for the given collection identifiers
|
||||||
*
|
|
||||||
* @param sources - source selector to check availability for
|
|
||||||
*
|
|
||||||
* @returns Promise with collection availability status
|
|
||||||
*/
|
*/
|
||||||
async function extant(sources: SourceSelector) {
|
async function extant(targets: CollectionIdentifier[]): Promise<Record<string, Record<string, Record<string, boolean>>>> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await collectionService.extant({ sources })
|
const response = await collectionService.extant({ targets })
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'collections')
|
console.debug('[Chrono Manager][Store] - Successfully checked', targets ? targets.length : 0, 'collections')
|
||||||
return response
|
return response
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('[Chrono Manager][Store] - Failed to check collections:', error)
|
console.error('[Chrono Manager][Store] - Failed to check collections:', error)
|
||||||
@@ -191,30 +146,20 @@ export const useCollectionsStore = defineStore('chronoCollectionsStore', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new collection with given provider, service, and data
|
* Create a new collection with given provider, service, and properties
|
||||||
*
|
|
||||||
* @param provider - provider identifier for the new collection
|
|
||||||
* @param service - service identifier for the new collection
|
|
||||||
* @param collection - optional parent collection identifier
|
|
||||||
* @param data - collection properties for creation
|
|
||||||
*
|
|
||||||
* @returns Promise with created collection object
|
|
||||||
*/
|
*/
|
||||||
async function create(provider: string, service: string | number, collection: string | number | null, data: CollectionPropertiesObject): Promise<CollectionObject> {
|
async function create(provider: string, service: string | number, properties: CollectionPropertiesObject): Promise<CollectionObject> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await collectionService.create({
|
const response = await collectionService.create({
|
||||||
provider,
|
provider,
|
||||||
service,
|
service,
|
||||||
collection,
|
properties: properties.toJson(),
|
||||||
properties: data
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Merge created collection into state
|
_collections.value[response.identifier] = response
|
||||||
const key = identifierKey(response.provider, response.service, response.identifier)
|
|
||||||
_collections.value[key] = response
|
console.debug('[Chrono Manager][Store] - Successfully created collection:', response.identifier)
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully created collection:', key)
|
|
||||||
return response
|
return response
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('[Chrono Manager][Store] - Failed to create collection:', error)
|
console.error('[Chrono Manager][Store] - Failed to create collection:', error)
|
||||||
@@ -225,30 +170,19 @@ export const useCollectionsStore = defineStore('chronoCollectionsStore', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an existing collection with given provider, service, identifier, and data
|
* Update an existing collection with given target and properties
|
||||||
*
|
|
||||||
* @param provider - provider identifier for the collection to update
|
|
||||||
* @param service - service identifier for the collection to update
|
|
||||||
* @param identifier - collection identifier for the collection to update
|
|
||||||
* @param data - collection properties for update
|
|
||||||
*
|
|
||||||
* @returns Promise with updated collection object
|
|
||||||
*/
|
*/
|
||||||
async function update(provider: string, service: string | number, identifier: string | number, data: CollectionPropertiesObject): Promise<CollectionObject> {
|
async function update(target: CollectionIdentifier, properties: CollectionPropertiesObject): Promise<CollectionObject> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await collectionService.update({
|
const response = await collectionService.update({
|
||||||
provider,
|
target,
|
||||||
service,
|
properties: properties.toJson(),
|
||||||
identifier,
|
|
||||||
properties: data
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// Merge updated collection into state
|
_collections.value[response.identifier] = response
|
||||||
const key = identifierKey(response.provider, response.service, response.identifier)
|
|
||||||
_collections.value[key] = response
|
console.debug('[Chrono Manager][Store] - Successfully updated collection:', response.identifier)
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully updated collection:', key)
|
|
||||||
return response
|
return response
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('[Chrono Manager][Store] - Failed to update collection:', error)
|
console.error('[Chrono Manager][Store] - Failed to update collection:', error)
|
||||||
@@ -259,24 +193,28 @@ export const useCollectionsStore = defineStore('chronoCollectionsStore', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a collection by provider, service, and identifier
|
* Delete a collection by identifier.
|
||||||
*
|
|
||||||
* @param provider - provider identifier for the collection to delete
|
|
||||||
* @param service - service identifier for the collection to delete
|
|
||||||
* @param identifier - collection identifier for the collection to delete
|
|
||||||
*
|
|
||||||
* @returns Promise with deletion result
|
|
||||||
*/
|
*/
|
||||||
async function remove(provider: string, service: string | number, identifier: string | number): Promise<any> {
|
async function remove(target: CollectionIdentifier, force?: boolean): Promise<CollectionObject | boolean> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
await collectionService.delete({ provider, service, identifier })
|
const response = await collectionService.delete({ target, options: { force } })
|
||||||
|
|
||||||
// Remove deleted collection from state
|
|
||||||
const key = identifierKey(provider, service, identifier)
|
|
||||||
delete _collections.value[key]
|
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully deleted collection:', key)
|
if (response !== true && !(response instanceof CollectionObject)) {
|
||||||
|
console.warn('[Chrono Manager][Store] - Delete failed. Received unexpected response from delete operation:', response)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
delete _collections.value[target]
|
||||||
|
|
||||||
|
if (response instanceof CollectionObject) {
|
||||||
|
_collections.value[response.identifier] = response
|
||||||
|
console.debug('[Chrono Manager][Store] - Successfully moved collection', target, '->', response.identifier)
|
||||||
|
return response
|
||||||
|
}
|
||||||
|
|
||||||
|
console.debug('[Chrono Manager][Store] - Successfully deleted collection:', target)
|
||||||
|
return response
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('[Chrono Manager][Store] - Failed to delete collection:', error)
|
console.error('[Chrono Manager][Store] - Failed to delete collection:', error)
|
||||||
throw error
|
throw error
|
||||||
@@ -285,17 +223,13 @@ export const useCollectionsStore = defineStore('chronoCollectionsStore', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return public API
|
|
||||||
return {
|
return {
|
||||||
// State (readonly)
|
|
||||||
transceiving: readonly(transceiving),
|
transceiving: readonly(transceiving),
|
||||||
// Getters
|
|
||||||
count,
|
count,
|
||||||
has,
|
has,
|
||||||
collections,
|
collections,
|
||||||
collectionsByService,
|
collectionsByService,
|
||||||
collectionsForService,
|
collectionsForService,
|
||||||
// Actions
|
|
||||||
collection,
|
collection,
|
||||||
list,
|
list,
|
||||||
fetch,
|
fetch,
|
||||||
|
|||||||
+193
-212
@@ -6,7 +6,14 @@ import { ref, computed, readonly } from 'vue'
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { entityService } from '../services'
|
import { entityService } from '../services'
|
||||||
import { EntityObject } from '../models'
|
import { EntityObject } from '../models'
|
||||||
import type { SourceSelector, ListFilter, ListSort, ListRange } from '../types/common'
|
import type {
|
||||||
|
CollectionIdentifier,
|
||||||
|
EntityIdentifier,
|
||||||
|
ListFilter,
|
||||||
|
ListRange,
|
||||||
|
ListSort,
|
||||||
|
} from '../types/common'
|
||||||
|
import type { EntityPropertiesInterface } from '@/types/entity'
|
||||||
|
|
||||||
export const useEntitiesStore = defineStore('chronoEntitiesStore', () => {
|
export const useEntitiesStore = defineStore('chronoEntitiesStore', () => {
|
||||||
// State
|
// State
|
||||||
@@ -30,95 +37,44 @@ export const useEntitiesStore = defineStore('chronoEntitiesStore', () => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a specific entity from store, with optional retrieval
|
* Get a specific entity from store, with optional retrieval
|
||||||
*
|
|
||||||
* @param provider - provider identifier
|
|
||||||
* @param service - service identifier
|
|
||||||
* @param collection - collection identifier
|
|
||||||
* @param identifier - entity identifier
|
|
||||||
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
|
|
||||||
*
|
|
||||||
* @returns Entity object or null
|
|
||||||
*/
|
*/
|
||||||
function entity(provider: string, service: string | number, collection: string | number, identifier: string | number, retrieve: boolean = false): EntityObject | null {
|
function entity(target: EntityIdentifier, retrieve: boolean = false): EntityObject | null {
|
||||||
const key = identifierKey(provider, service, collection, identifier)
|
if (retrieve === true && !_entities.value[target]) {
|
||||||
if (retrieve === true && !_entities.value[key]) {
|
console.debug(`[Chrono Manager][Store] - Force fetching entity "${target}"`)
|
||||||
console.debug(`[Chrono Manager][Store] - Force fetching entity "${key}"`)
|
fetch([target])
|
||||||
fetch(provider, service, collection, [identifier])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return _entities.value[key] || null
|
return _entities.value[target] || null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all entities for a specific collection
|
* Get all entities for a specific collection
|
||||||
*
|
|
||||||
* @param provider - provider identifier
|
|
||||||
* @param service - service identifier
|
|
||||||
* @param collection - collection identifier
|
|
||||||
* @param retrieve - Retrieve behavior: true = fetch if missing or refresh, false = cache only
|
|
||||||
*
|
|
||||||
* @returns Array of entity objects
|
|
||||||
*/
|
*/
|
||||||
function entitiesForCollection(provider: string, service: string | number, collection: string | number, retrieve: boolean = false): EntityObject[] {
|
function entitiesForCollection(target: CollectionIdentifier, retrieve: boolean = false): EntityObject[] {
|
||||||
const collectionKeyPrefix = `${provider}:${service}:${collection}:`
|
|
||||||
const collectionEntities = Object.entries(_entities.value)
|
const collectionEntities = Object.entries(_entities.value)
|
||||||
.filter(([key]) => key.startsWith(collectionKeyPrefix))
|
.filter(([key]) => key.startsWith(`${target}:`))
|
||||||
.map(([_, entity]) => entity)
|
.map(([_, entity]) => entity)
|
||||||
|
|
||||||
if (retrieve === true && collectionEntities.length === 0) {
|
if (retrieve === true && collectionEntities.length === 0) {
|
||||||
console.debug(`[Chrono Manager][Store] - Force fetching entities for collection "${provider}:${service}:${collection}"`)
|
console.debug(`[Chrono Manager][Store] - Force fetching entities for collection "${target}"`)
|
||||||
const sources: SourceSelector = {
|
list([target])
|
||||||
[provider]: {
|
|
||||||
[String(service)]: {
|
|
||||||
[String(collection)]: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
list(sources)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return collectionEntities
|
return collectionEntities
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create unique key for an entity
|
* Retrieve all or specific entities, optionally filtered by source collection identifiers
|
||||||
*/
|
*/
|
||||||
function identifierKey(provider: string, service: string | number, collection: string | number, identifier: string | number): string {
|
async function list(sources: CollectionIdentifier[], filter?: ListFilter, sort?: ListSort, range?: ListRange): Promise<Record<string, EntityObject>> {
|
||||||
return `${provider}:${service}:${collection}:${identifier}`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Actions
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Retrieve all or specific entities, optionally filtered by source selector
|
|
||||||
*
|
|
||||||
* @param sources - optional source selector
|
|
||||||
* @param filter - optional list filter
|
|
||||||
* @param sort - optional list sort
|
|
||||||
* @param range - optional list range
|
|
||||||
*
|
|
||||||
* @returns Promise with entity object list keyed by identifier
|
|
||||||
*/
|
|
||||||
async function list(sources?: SourceSelector, filter?: ListFilter, sort?: ListSort, range?: ListRange): Promise<Record<string, EntityObject>> {
|
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await entityService.list({ sources, filter, sort, range })
|
|
||||||
|
|
||||||
// Flatten nested structure: provider:service:collection:entity -> "provider:service:collection:entity": object
|
|
||||||
const entities: Record<string, EntityObject> = {}
|
const entities: 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, entityData]) => {
|
|
||||||
const key = identifierKey(providerId, serviceId, collectionId, entityId)
|
|
||||||
entities[key] = entityData
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// Merge retrieved entities into state
|
await entityService.listStream({ sources, filter, sort, range }, (entity: EntityObject) => {
|
||||||
_entities.value = { ..._entities.value, ...entities }
|
_entities.value[entity.identifier] = entity
|
||||||
|
entities[entity.identifier] = entity
|
||||||
|
})
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully retrieved', Object.keys(entities).length, 'entities')
|
console.debug('[Chrono Manager][Store] - Successfully retrieved', Object.keys(entities).length, 'entities')
|
||||||
return entities
|
return entities
|
||||||
@@ -129,28 +85,19 @@ export const useEntitiesStore = defineStore('chronoEntitiesStore', () => {
|
|||||||
transceiving.value = false
|
transceiving.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve specific entities by provider, service, collection, and identifiers
|
* Retrieve specific entities by their identifiers
|
||||||
*
|
|
||||||
* @param provider - provider identifier
|
|
||||||
* @param service - service identifier
|
|
||||||
* @param collection - collection identifier
|
|
||||||
* @param identifiers - array of entity identifiers to fetch
|
|
||||||
*
|
|
||||||
* @returns Promise with entity objects keyed by identifier
|
|
||||||
*/
|
*/
|
||||||
async function fetch(provider: string, service: string | number, collection: string | number, identifiers: (string | number)[]): Promise<Record<string, EntityObject>> {
|
async function fetch(targets: EntityIdentifier[]): Promise<Record<string, EntityObject>> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await entityService.fetch({ provider, service, collection, identifiers })
|
const response = await entityService.fetch({ targets })
|
||||||
|
|
||||||
// Merge fetched entities into state
|
|
||||||
const entities: Record<string, EntityObject> = {}
|
const entities: Record<string, EntityObject> = {}
|
||||||
Object.entries(response).forEach(([identifier, entityData]) => {
|
Object.entries(response).forEach(([identifier, entity]) => {
|
||||||
const key = identifierKey(provider, service, collection, identifier)
|
entities[identifier] = entity
|
||||||
entities[key] = entityData
|
_entities.value[identifier] = entity
|
||||||
_entities.value[key] = entityData
|
|
||||||
})
|
})
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully fetched', Object.keys(entities).length, 'entities')
|
console.debug('[Chrono Manager][Store] - Successfully fetched', Object.keys(entities).length, 'entities')
|
||||||
@@ -164,16 +111,12 @@ export const useEntitiesStore = defineStore('chronoEntitiesStore', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve entity availability status for a given source selector
|
* Retrieve entity availability status for a given set of entity identifiers
|
||||||
*
|
|
||||||
* @param sources - source selector to check availability for
|
|
||||||
*
|
|
||||||
* @returns Promise with entity availability status
|
|
||||||
*/
|
*/
|
||||||
async function extant(sources: SourceSelector) {
|
async function extant(targets: EntityIdentifier[]) {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await entityService.extant({ sources })
|
const response = await entityService.extant({ targets })
|
||||||
console.debug('[Chrono Manager][Store] - Successfully checked entity availability')
|
console.debug('[Chrono Manager][Store] - Successfully checked entity availability')
|
||||||
return response
|
return response
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -184,132 +127,28 @@ export const useEntitiesStore = defineStore('chronoEntitiesStore', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new entity with given provider, service, collection, and data
|
|
||||||
*
|
|
||||||
* @param provider - provider identifier for the new entity
|
|
||||||
* @param service - service identifier for the new entity
|
|
||||||
* @param collection - collection identifier for the new entity
|
|
||||||
* @param data - entity properties for creation
|
|
||||||
*
|
|
||||||
* @returns Promise with created entity object
|
|
||||||
*/
|
|
||||||
async function create(provider: string, service: string | number, collection: string | number, data: any): Promise<EntityObject> {
|
|
||||||
transceiving.value = true
|
|
||||||
try {
|
|
||||||
const response = await entityService.create({ provider, service, collection, properties: data })
|
|
||||||
|
|
||||||
// Add created entity to state
|
|
||||||
const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
|
|
||||||
_entities.value[key] = response
|
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully created entity:', key)
|
|
||||||
return response
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('[Chrono Manager][Store] - Failed to create entity:', error)
|
|
||||||
throw error
|
|
||||||
} finally {
|
|
||||||
transceiving.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update an existing entity with given provider, service, collection, identifier, and data
|
|
||||||
*
|
|
||||||
* @param provider - provider identifier for the entity to update
|
|
||||||
* @param service - service identifier for the entity to update
|
|
||||||
* @param collection - collection identifier for the entity to update
|
|
||||||
* @param identifier - entity identifier for the entity to update
|
|
||||||
* @param data - entity properties for update
|
|
||||||
*
|
|
||||||
* @returns Promise with updated entity object
|
|
||||||
*/
|
|
||||||
async function update(provider: string, service: string | number, collection: string | number, identifier: string | number, data: any): Promise<EntityObject> {
|
|
||||||
transceiving.value = true
|
|
||||||
try {
|
|
||||||
const response = await entityService.update({ provider, service, collection, identifier, properties: data })
|
|
||||||
|
|
||||||
// Update entity in state
|
|
||||||
const key = identifierKey(response.provider, response.service, response.collection, response.identifier)
|
|
||||||
_entities.value[key] = response
|
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully updated entity:', key)
|
|
||||||
return response
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('[Chrono Manager][Store] - Failed to update entity:', error)
|
|
||||||
throw error
|
|
||||||
} finally {
|
|
||||||
transceiving.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete an entity by provider, service, collection, and identifier
|
|
||||||
*
|
|
||||||
* @param provider - provider identifier for the entity to delete
|
|
||||||
* @param service - service identifier for the entity to delete
|
|
||||||
* @param collection - collection identifier for the entity to delete
|
|
||||||
* @param identifier - entity identifier for the entity to delete
|
|
||||||
*
|
|
||||||
* @returns Promise with deletion result
|
|
||||||
*/
|
|
||||||
async function remove(provider: string, service: string | number, collection: string | number, identifier: string | number): Promise<any> {
|
|
||||||
transceiving.value = true
|
|
||||||
try {
|
|
||||||
const response = await entityService.delete({ provider, service, collection, identifier })
|
|
||||||
|
|
||||||
// Remove entity from state
|
|
||||||
const key = identifierKey(provider, service, collection, identifier)
|
|
||||||
delete _entities.value[key]
|
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully deleted entity:', key)
|
|
||||||
return response
|
|
||||||
} catch (error: any) {
|
|
||||||
console.error('[Chrono Manager][Store] - Failed to delete entity:', error)
|
|
||||||
throw error
|
|
||||||
} finally {
|
|
||||||
transceiving.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve delta changes for entities
|
* Retrieve delta changes for entities
|
||||||
*
|
|
||||||
* @param sources - source selector for delta check
|
|
||||||
*
|
|
||||||
* @returns Promise with delta changes (additions, modifications, deletions)
|
|
||||||
*
|
|
||||||
* Note: Delta returns only identifiers, not full entities.
|
|
||||||
* Caller should fetch full entities for additions/modifications separately.
|
|
||||||
*/
|
*/
|
||||||
async function delta(sources: SourceSelector) {
|
async function delta(targets: (CollectionIdentifier | EntityIdentifier)[]) {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await entityService.delta({ sources })
|
const response = await entityService.delta({ targets })
|
||||||
|
|
||||||
// Process delta and update store
|
Object.entries(response).forEach(([, providerData]) => {
|
||||||
Object.entries(response).forEach(([provider, providerData]) => {
|
|
||||||
// Skip if no changes for provider
|
|
||||||
if (providerData === false) return
|
if (providerData === false) return
|
||||||
|
|
||||||
Object.entries(providerData).forEach(([service, serviceData]) => {
|
Object.entries(providerData).forEach(([, serviceData]) => {
|
||||||
// Skip if no changes for service
|
|
||||||
if (serviceData === false) return
|
if (serviceData === false) return
|
||||||
|
|
||||||
Object.entries(serviceData).forEach(([collection, collectionData]) => {
|
Object.entries(serviceData).forEach(([, collectionData]) => {
|
||||||
// Skip if no changes for collection
|
|
||||||
if (collectionData === false) return
|
if (collectionData === false) return
|
||||||
|
|
||||||
// Process deletions (remove from store)
|
|
||||||
if (collectionData.deletions && collectionData.deletions.length > 0) {
|
if (collectionData.deletions && collectionData.deletions.length > 0) {
|
||||||
collectionData.deletions.forEach((identifier) => {
|
collectionData.deletions.forEach((identifier) => {
|
||||||
const key = identifierKey(provider, service, collection, identifier)
|
delete _entities.value[identifier]
|
||||||
delete _entities.value[key]
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note: additions and modifications contain only identifiers
|
|
||||||
// The caller should fetch full entities using the fetch() method
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -324,16 +163,156 @@ export const useEntitiesStore = defineStore('chronoEntitiesStore', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return public API
|
/**
|
||||||
|
* Create a new empty entity object
|
||||||
|
*/
|
||||||
|
function fresh(): EntityObject {
|
||||||
|
return new EntityObject()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new entity with given collection identifier and properties
|
||||||
|
*/
|
||||||
|
async function create(target: CollectionIdentifier, properties: EntityPropertiesInterface): Promise<EntityObject> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.create({ target, properties })
|
||||||
|
|
||||||
|
_entities.value[response.identifier] = response
|
||||||
|
|
||||||
|
console.debug('[Chrono Manager][Store] - Successfully created entity:', response.identifier)
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Chrono Manager][Store] - Failed to create entity:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing entity with given entity identifier and properties
|
||||||
|
*/
|
||||||
|
async function update(target: EntityIdentifier, properties: EntityPropertiesInterface): Promise<EntityObject> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.update({ target, properties })
|
||||||
|
|
||||||
|
_entities.value[response.identifier] = response
|
||||||
|
|
||||||
|
console.debug('[Chrono Manager][Store] - Successfully updated entity:', response.identifier)
|
||||||
|
return response
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Chrono Manager][Store] - Failed to update entity:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete entities by their identifiers.
|
||||||
|
*/
|
||||||
|
async function remove(targets: EntityIdentifier[]): Promise<{ successes: EntityIdentifier[], failures: EntityIdentifier[] }> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.delete({ targets })
|
||||||
|
const successes: EntityIdentifier[] = []
|
||||||
|
const failures: EntityIdentifier[] = []
|
||||||
|
|
||||||
|
Object.entries(response).forEach(([targetIdentifier, result]) => {
|
||||||
|
const originalIdentifier = targetIdentifier as EntityIdentifier
|
||||||
|
if (!result.disposition || result.disposition === 'error') {
|
||||||
|
console.warn(`[Chrono Manager][Store] - Entity delete on "${originalIdentifier}" returned an error: ${result.error})`)
|
||||||
|
failures.push(originalIdentifier)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.disposition !== 'moved' && result.disposition !== 'deleted') {
|
||||||
|
console.warn(`[Chrono Manager][Store] - Entity delete on "${originalIdentifier}" returned invalid disposition: ${result.disposition})`)
|
||||||
|
failures.push(originalIdentifier)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const cachedEntity = _entities.value[originalIdentifier]
|
||||||
|
|
||||||
|
if (result.disposition === 'moved' && cachedEntity && result.mutation) {
|
||||||
|
const movedEntity = cachedEntity.clone().fromJson({
|
||||||
|
...cachedEntity.toJson(),
|
||||||
|
collection: result.destination,
|
||||||
|
identifier: result.mutation,
|
||||||
|
})
|
||||||
|
_entities.value[result.mutation] = movedEntity
|
||||||
|
}
|
||||||
|
|
||||||
|
delete _entities.value[originalIdentifier]
|
||||||
|
successes.push(originalIdentifier)
|
||||||
|
})
|
||||||
|
|
||||||
|
console.debug('[Chrono Manager][Store] - Successfully deleted', successes.length, 'entities')
|
||||||
|
return { successes, failures }
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Chrono Manager][Store] - Failed to delete entities:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Move entities to another collection.
|
||||||
|
*/
|
||||||
|
async function move(target: CollectionIdentifier, sources: EntityIdentifier[]): Promise<{ successes: EntityIdentifier[], failures: EntityIdentifier[] }> {
|
||||||
|
transceiving.value = true
|
||||||
|
try {
|
||||||
|
const response = await entityService.move({ target, sources })
|
||||||
|
const successes: EntityIdentifier[] = []
|
||||||
|
const failures: EntityIdentifier[] = []
|
||||||
|
|
||||||
|
Object.entries(response).forEach(([sourceIdentifier, result]) => {
|
||||||
|
const originalIdentifier = sourceIdentifier as EntityIdentifier
|
||||||
|
if (!result.disposition || result.disposition === 'error') {
|
||||||
|
console.warn(`[Chrono Manager][Store] - Entity move on "${originalIdentifier}" returned an error: ${result.error})`)
|
||||||
|
failures.push(originalIdentifier)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.disposition !== 'moved') {
|
||||||
|
console.warn(`[Chrono Manager][Store] - Entity move on "${originalIdentifier}" returned invalid disposition: ${result.disposition})`)
|
||||||
|
failures.push(originalIdentifier)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const cachedEntity = _entities.value[originalIdentifier]
|
||||||
|
if (cachedEntity && result.mutation) {
|
||||||
|
const movedEntity = cachedEntity.clone().fromJson({
|
||||||
|
...cachedEntity.toJson(),
|
||||||
|
collection: result.destination,
|
||||||
|
identifier: result.mutation,
|
||||||
|
})
|
||||||
|
_entities.value[result.mutation] = movedEntity
|
||||||
|
delete _entities.value[originalIdentifier]
|
||||||
|
}
|
||||||
|
|
||||||
|
successes.push(originalIdentifier)
|
||||||
|
})
|
||||||
|
|
||||||
|
console.debug('[Chrono Manager][Store] - Successfully moved', successes.length, 'entities')
|
||||||
|
return { successes, failures }
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error('[Chrono Manager][Store] - Failed to move entities:', error)
|
||||||
|
throw error
|
||||||
|
} finally {
|
||||||
|
transceiving.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
// State (readonly)
|
|
||||||
transceiving: readonly(transceiving),
|
transceiving: readonly(transceiving),
|
||||||
// Getters
|
|
||||||
count,
|
count,
|
||||||
has,
|
has,
|
||||||
entities,
|
entities,
|
||||||
entitiesForCollection,
|
entitiesForCollection,
|
||||||
// Actions
|
|
||||||
entity,
|
entity,
|
||||||
list,
|
list,
|
||||||
fetch,
|
fetch,
|
||||||
@@ -342,5 +321,7 @@ export const useEntitiesStore = defineStore('chronoEntitiesStore', () => {
|
|||||||
update,
|
update,
|
||||||
delete: remove,
|
delete: remove,
|
||||||
delta,
|
delta,
|
||||||
|
fresh,
|
||||||
|
move,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { ref, computed, readonly } from 'vue'
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { providerService } from '../services'
|
import { providerService } from '../services'
|
||||||
import { ProviderObject } from '../models/provider'
|
import { ProviderObject } from '../models/provider'
|
||||||
import type { SourceSelector } from '../types'
|
import type { ProviderIdentifier } from '../types'
|
||||||
|
|
||||||
export const useProvidersStore = defineStore('chronoProvidersStore', () => {
|
export const useProvidersStore = defineStore('chronoProvidersStore', () => {
|
||||||
// State
|
// State
|
||||||
@@ -54,10 +54,10 @@ export const useProvidersStore = defineStore('chronoProvidersStore', () => {
|
|||||||
*
|
*
|
||||||
* @returns Promise with provider object list keyed by provider identifier
|
* @returns Promise with provider object list keyed by provider identifier
|
||||||
*/
|
*/
|
||||||
async function list(sources?: SourceSelector): Promise<Record<string, ProviderObject>> {
|
async function list(targets?: ProviderIdentifier[]): Promise<Record<string, ProviderObject>> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const providers = await providerService.list({ sources })
|
const providers = await providerService.list({ targets })
|
||||||
|
|
||||||
// Merge retrieved providers into state
|
// Merge retrieved providers into state
|
||||||
_providers.value = { ..._providers.value, ...providers }
|
_providers.value = { ..._providers.value, ...providers }
|
||||||
@@ -82,7 +82,7 @@ export const useProvidersStore = defineStore('chronoProvidersStore', () => {
|
|||||||
async function fetch(identifier: string): Promise<ProviderObject> {
|
async function fetch(identifier: string): Promise<ProviderObject> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const provider = await providerService.fetch({ identifier })
|
const provider = await providerService.fetch({ target: identifier })
|
||||||
|
|
||||||
// Merge fetched provider into state
|
// Merge fetched provider into state
|
||||||
_providers.value[provider.identifier] = provider
|
_providers.value[provider.identifier] = provider
|
||||||
@@ -104,10 +104,10 @@ export const useProvidersStore = defineStore('chronoProvidersStore', () => {
|
|||||||
*
|
*
|
||||||
* @returns Promise with provider availability status
|
* @returns Promise with provider availability status
|
||||||
*/
|
*/
|
||||||
async function extant(sources: SourceSelector) {
|
async function extant(targets: ProviderIdentifier[]) {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await providerService.extant({ sources })
|
const response = await providerService.extant({ targets })
|
||||||
|
|
||||||
Object.entries(response).forEach(([providerId, providerStatus]) => {
|
Object.entries(response).forEach(([providerId, providerStatus]) => {
|
||||||
if (providerStatus === false) {
|
if (providerStatus === false) {
|
||||||
@@ -115,7 +115,7 @@ export const useProvidersStore = defineStore('chronoProvidersStore', () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'providers')
|
console.debug('[Chrono Manager][Store] - Successfully checked', targets ? targets.length : 0, 'providers')
|
||||||
return response
|
return response
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('[Chrono Manager][Store] - Failed to check providers:', error)
|
console.error('[Chrono Manager][Store] - Failed to check providers:', error)
|
||||||
|
|||||||
+32
-16
@@ -7,7 +7,8 @@ import { defineStore } from 'pinia'
|
|||||||
import { serviceService } from '../services'
|
import { serviceService } from '../services'
|
||||||
import { ServiceObject } from '../models/service'
|
import { ServiceObject } from '../models/service'
|
||||||
import type {
|
import type {
|
||||||
SourceSelector,
|
CollectionIdentifier,
|
||||||
|
ServiceIdentifier,
|
||||||
ServiceInterface,
|
ServiceInterface,
|
||||||
} from '../types'
|
} from '../types'
|
||||||
|
|
||||||
@@ -55,20 +56,30 @@ export const useServicesStore = defineStore('chronoServicesStore', () => {
|
|||||||
* @returns Service object or null
|
* @returns Service object or null
|
||||||
*/
|
*/
|
||||||
function service(provider: string, identifier: string | number, retrieve: boolean = false): ServiceObject | null {
|
function service(provider: string, identifier: string | number, retrieve: boolean = false): ServiceObject | null {
|
||||||
const key = identifierKey(provider, identifier)
|
return serviceByIdentifier(identifierKey(provider, identifier), retrieve)
|
||||||
if (retrieve === true && !_services.value[key]) {
|
}
|
||||||
console.debug(`[Chrono Manager][Store] - Force fetching service "${key}"`)
|
|
||||||
fetch(provider, identifier)
|
/**
|
||||||
|
* Get a service from store by its unique identifier, with optional retrieval
|
||||||
|
*/
|
||||||
|
function serviceByIdentifier(identifier: ServiceIdentifier, retrieve: boolean = false): ServiceObject | null {
|
||||||
|
if (retrieve === true && !_services.value[identifier]) {
|
||||||
|
console.debug(`[Chrono Manager][Store] - Force fetching service "${identifier}"`)
|
||||||
|
const separatorIndex = identifier.indexOf(':')
|
||||||
|
const provider = identifier.slice(0, separatorIndex)
|
||||||
|
const serviceIdentifier = identifier.slice(separatorIndex + 1)
|
||||||
|
|
||||||
|
void fetch(provider, serviceIdentifier)
|
||||||
}
|
}
|
||||||
|
|
||||||
return _services.value[key] || null
|
return _services.value[identifier] ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unique key for a service
|
* Unique key for a service
|
||||||
*/
|
*/
|
||||||
function identifierKey(provider: string, identifier: string | number | null): string {
|
function identifierKey(provider: string, identifier: string | number | null): ServiceIdentifier {
|
||||||
return `${provider}:${identifier ?? ''}`
|
return `${provider}:${identifier ?? ''}` as ServiceIdentifier
|
||||||
}
|
}
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
@@ -80,10 +91,10 @@ export const useServicesStore = defineStore('chronoServicesStore', () => {
|
|||||||
*
|
*
|
||||||
* @returns Promise with service object list keyed by provider and service identifier
|
* @returns Promise with service object list keyed by provider and service identifier
|
||||||
*/
|
*/
|
||||||
async function list(sources?: SourceSelector): Promise<Record<string, ServiceObject>> {
|
async function list(targets?: ServiceIdentifier[] | CollectionIdentifier[]): Promise<Record<string, ServiceObject>> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await serviceService.list({ sources })
|
const response = await serviceService.list({ targets })
|
||||||
|
|
||||||
// Flatten nested structure: provider-id: { service-id: object } -> "provider-id:service-id": object
|
// Flatten nested structure: provider-id: { service-id: object } -> "provider-id:service-id": object
|
||||||
const services: Record<string, ServiceObject> = {}
|
const services: Record<string, ServiceObject> = {}
|
||||||
@@ -141,12 +152,12 @@ export const useServicesStore = defineStore('chronoServicesStore', () => {
|
|||||||
*
|
*
|
||||||
* @returns Promise with service availability status
|
* @returns Promise with service availability status
|
||||||
*/
|
*/
|
||||||
async function extant(sources: SourceSelector) {
|
async function extant(targets: ServiceIdentifier[]) {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const response = await serviceService.extant({ sources })
|
const response = await serviceService.extant({ targets })
|
||||||
|
|
||||||
console.debug('[Chrono Manager][Store] - Successfully checked', sources ? Object.keys(sources).length : 0, 'services')
|
console.debug('[Chrono Manager][Store] - Successfully checked', targets?.length ?? 0, 'services')
|
||||||
return response
|
return response
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error('[Chrono Manager][Store] - Failed to check services:', error)
|
console.error('[Chrono Manager][Store] - Failed to check services:', error)
|
||||||
@@ -192,10 +203,14 @@ export const useServicesStore = defineStore('chronoServicesStore', () => {
|
|||||||
*
|
*
|
||||||
* @returns Promise with updated service object
|
* @returns Promise with updated service object
|
||||||
*/
|
*/
|
||||||
async function update(provider: string, identifier: string | number, data: Partial<ServiceInterface>): Promise<ServiceObject> {
|
async function update(provider: string, identifier: string | number, delta: boolean, data: ServiceObject | Partial<ServiceInterface>): Promise<ServiceObject> {
|
||||||
transceiving.value = true
|
transceiving.value = true
|
||||||
try {
|
try {
|
||||||
const service = await serviceService.update({ provider, identifier, data })
|
const payload: Partial<ServiceInterface> = data instanceof ServiceObject
|
||||||
|
? (delta ? data.toJson(true) : data.toJson())
|
||||||
|
: data
|
||||||
|
|
||||||
|
const service = await serviceService.update({ provider, identifier, delta, data: payload })
|
||||||
|
|
||||||
// Merge updated service into state
|
// Merge updated service into state
|
||||||
const key = identifierKey(service.provider, service.identifier)
|
const key = identifierKey(service.provider, service.identifier)
|
||||||
@@ -249,6 +264,7 @@ export const useServicesStore = defineStore('chronoServicesStore', () => {
|
|||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
service,
|
service,
|
||||||
|
serviceByIdentifier,
|
||||||
list,
|
list,
|
||||||
fetch,
|
fetch,
|
||||||
extant,
|
extant,
|
||||||
|
|||||||
+28
-20
@@ -1,27 +1,37 @@
|
|||||||
/**
|
/**
|
||||||
* Collection type definitions
|
* Collection type definitions
|
||||||
*/
|
*/
|
||||||
import type { ListFilter, ListSort, SourceSelector } from './common';
|
import type {
|
||||||
|
ServiceIdentifier,
|
||||||
|
CollectionIdentifier,
|
||||||
|
ListFilter,
|
||||||
|
ListSort
|
||||||
|
} from './common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection information
|
* Collection information
|
||||||
*/
|
*/
|
||||||
export interface CollectionInterface {
|
export interface CollectionInterface<T = CollectionPropertiesInterface> {
|
||||||
|
'@type': string;
|
||||||
|
version: number;
|
||||||
provider: string;
|
provider: string;
|
||||||
service: string | number;
|
service: string | number;
|
||||||
collection: string | number | null;
|
collection: CollectionIdentifier | null;
|
||||||
identifier: string | number;
|
identifier: CollectionIdentifier;
|
||||||
signature?: string | null;
|
signature?: string | null;
|
||||||
created?: string | null;
|
created?: string | null;
|
||||||
modified?: string | null;
|
modified?: string | null;
|
||||||
properties: CollectionPropertiesInterface;
|
properties: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CollectionModelInterface extends Omit<CollectionInterface<CollectionPropertiesInterface>, '@type' | 'version' | 'properties'> {
|
||||||
|
properties: CollectionPropertiesModelInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type CollectionContentTypes = 'event' | 'task' | 'journal';
|
export type CollectionContentTypes = 'event' | 'task' | 'journal';
|
||||||
|
|
||||||
export interface CollectionBaseProperties {
|
export interface CollectionBaseProperties {
|
||||||
'@type': string;
|
'@type': string;
|
||||||
version: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CollectionImmutableProperties extends CollectionBaseProperties {
|
export interface CollectionImmutableProperties extends CollectionBaseProperties {
|
||||||
@@ -38,11 +48,13 @@ export interface CollectionMutableProperties extends CollectionBaseProperties {
|
|||||||
|
|
||||||
export interface CollectionPropertiesInterface extends CollectionMutableProperties, CollectionImmutableProperties {}
|
export interface CollectionPropertiesInterface extends CollectionMutableProperties, CollectionImmutableProperties {}
|
||||||
|
|
||||||
|
export interface CollectionPropertiesModelInterface extends Omit<CollectionPropertiesInterface, '@type'> {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection list
|
* Collection list
|
||||||
*/
|
*/
|
||||||
export interface CollectionListRequest {
|
export interface CollectionListRequest {
|
||||||
sources?: SourceSelector;
|
sources?: ServiceIdentifier[] | CollectionIdentifier[];
|
||||||
filter?: ListFilter;
|
filter?: ListFilter;
|
||||||
sort?: ListSort;
|
sort?: ListSort;
|
||||||
}
|
}
|
||||||
@@ -59,18 +71,18 @@ export interface CollectionListResponse {
|
|||||||
* Collection fetch
|
* Collection fetch
|
||||||
*/
|
*/
|
||||||
export interface CollectionFetchRequest {
|
export interface CollectionFetchRequest {
|
||||||
provider: string;
|
targets: CollectionIdentifier[];
|
||||||
service: string | number;
|
|
||||||
collection: string | number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CollectionFetchResponse extends CollectionInterface {}
|
export interface CollectionFetchResponse {
|
||||||
|
[identifier: CollectionIdentifier]: CollectionInterface;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Collection extant
|
* Collection extant
|
||||||
*/
|
*/
|
||||||
export interface CollectionExtantRequest {
|
export interface CollectionExtantRequest {
|
||||||
sources: SourceSelector;
|
targets: CollectionIdentifier[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CollectionExtantResponse {
|
export interface CollectionExtantResponse {
|
||||||
@@ -87,7 +99,6 @@ export interface CollectionExtantResponse {
|
|||||||
export interface CollectionCreateRequest {
|
export interface CollectionCreateRequest {
|
||||||
provider: string;
|
provider: string;
|
||||||
service: string | number;
|
service: string | number;
|
||||||
collection?: string | number | null; // Parent Collection Identifier
|
|
||||||
properties: CollectionMutableProperties;
|
properties: CollectionMutableProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,9 +108,7 @@ export interface CollectionCreateResponse extends CollectionInterface {}
|
|||||||
* Collection modify
|
* Collection modify
|
||||||
*/
|
*/
|
||||||
export interface CollectionUpdateRequest {
|
export interface CollectionUpdateRequest {
|
||||||
provider: string;
|
target: CollectionIdentifier;
|
||||||
service: string | number;
|
|
||||||
identifier: string | number;
|
|
||||||
properties: CollectionMutableProperties;
|
properties: CollectionMutableProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,14 +118,13 @@ export interface CollectionUpdateResponse extends CollectionInterface {}
|
|||||||
* Collection delete
|
* Collection delete
|
||||||
*/
|
*/
|
||||||
export interface CollectionDeleteRequest {
|
export interface CollectionDeleteRequest {
|
||||||
provider: string;
|
target: CollectionIdentifier;
|
||||||
service: string | number;
|
|
||||||
identifier: string | number;
|
|
||||||
options?: {
|
options?: {
|
||||||
force?: boolean; // Whether to force delete even if collection is not empty
|
force?: boolean; // Whether to force delete even if collection is not empty
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CollectionDeleteResponse {
|
export interface CollectionDeleteResponse {
|
||||||
success: boolean;
|
disposition: 'deleted' | 'moved';
|
||||||
|
mutation?: CollectionInterface | null; // If moved, the new location of the collection
|
||||||
}
|
}
|
||||||
|
|||||||
+46
-23
@@ -44,34 +44,57 @@ export interface ApiErrorResponse {
|
|||||||
export type ApiResponse<T = any> = ApiSuccessResponse<T> | ApiErrorResponse;
|
export type ApiResponse<T = any> = ApiSuccessResponse<T> | ApiErrorResponse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selector for targeting specific providers, services, collections, or entities in list or extant operations.
|
* Stream control start line.
|
||||||
*
|
|
||||||
* 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 interface ApiStreamStartResponse {
|
||||||
[provider: string]: boolean | ServiceSelector;
|
type: 'control';
|
||||||
};
|
status: 'start';
|
||||||
|
version: number;
|
||||||
|
transaction: string;
|
||||||
|
total?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export type ServiceSelector = {
|
/**
|
||||||
[service: string]: boolean | CollectionSelector;
|
* Stream control end line
|
||||||
};
|
*/
|
||||||
|
export interface ApiStreamEndResponse {
|
||||||
|
type: 'control';
|
||||||
|
status: 'end';
|
||||||
|
total: number;
|
||||||
|
}
|
||||||
|
|
||||||
export type CollectionSelector = {
|
/**
|
||||||
[collection: string | number]: boolean | EntitySelector;
|
* Stream error line
|
||||||
};
|
*/
|
||||||
|
export interface ApiStreamErrorResponse {
|
||||||
|
type: 'error';
|
||||||
|
message: string;
|
||||||
|
}
|
||||||
|
|
||||||
export type EntitySelector = (string | number)[];
|
export interface ApiStreamDataResponse<T = any> {
|
||||||
|
type: 'data';
|
||||||
|
data: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared stream control lines
|
||||||
|
*/
|
||||||
|
export type ApiStreamResponse<T = any> =
|
||||||
|
| ApiStreamStartResponse
|
||||||
|
| ApiStreamEndResponse
|
||||||
|
| ApiStreamErrorResponse
|
||||||
|
| ApiStreamDataResponse<T>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identifiers for targeting specific providers, services, collections, or entities in list or extant operations.
|
||||||
|
*
|
||||||
|
* Operations accept flat arrays of colon-separated identifier strings, e.g.
|
||||||
|
* ["caldav:account1:calendar", "caldav:account1:calendar:1001"].
|
||||||
|
*/
|
||||||
|
export type ProviderIdentifier = `${string}`;
|
||||||
|
export type ServiceIdentifier = `${string}:${string}`;
|
||||||
|
export type CollectionIdentifier = `${string}:${string}:${string | number}`;
|
||||||
|
export type EntityIdentifier = `${string}:${string}:${string}:${string | number}`;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter comparison for list operations
|
* Filter comparison for list operations
|
||||||
|
|||||||
+94
-56
@@ -1,64 +1,85 @@
|
|||||||
/**
|
/**
|
||||||
* Entity type definitions
|
* Entity type definitions
|
||||||
*/
|
*/
|
||||||
import type { ListFilter, ListRange, ListSort, SourceSelector } from './common';
|
import type {
|
||||||
|
CollectionIdentifier,
|
||||||
|
EntityIdentifier,
|
||||||
|
ListFilter,
|
||||||
|
ListRange,
|
||||||
|
ListSort,
|
||||||
|
} from './common';
|
||||||
import type { EventInterface } from './event';
|
import type { EventInterface } from './event';
|
||||||
import type { TaskInterface } from './task';
|
import type { TaskInterface } from './task';
|
||||||
import type { JournalInterface } from './journal';
|
import type { JournalInterface } from './journal';
|
||||||
|
|
||||||
|
export type EntityPropertiesInterface = EventInterface | TaskInterface | JournalInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity definition
|
* Entity definition
|
||||||
*/
|
*/
|
||||||
export interface EntityInterface<T = EventInterface | TaskInterface | JournalInterface> {
|
export interface EntityInterface<T = EntityPropertiesInterface> {
|
||||||
|
'@type': string;
|
||||||
|
version: number;
|
||||||
provider: string;
|
provider: string;
|
||||||
service: string;
|
service: string;
|
||||||
collection: string | number;
|
collection: CollectionIdentifier;
|
||||||
identifier: string | number;
|
identifier: EntityIdentifier;
|
||||||
signature: string | null;
|
signature: string | null;
|
||||||
created: string | null;
|
created: string | null;
|
||||||
modified: string | null;
|
modified: string | null;
|
||||||
properties: T;
|
properties: T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface EntityModelInterface extends Omit<EntityInterface<EntityPropertiesInterface>, '@type' | 'version'> {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity list
|
* Entity list bulk
|
||||||
*/
|
*/
|
||||||
export interface EntityListRequest {
|
export interface EntityListBulkRequest {
|
||||||
sources?: SourceSelector;
|
sources?: CollectionIdentifier[];
|
||||||
filter?: ListFilter;
|
filter?: ListFilter;
|
||||||
sort?: ListSort;
|
sort?: ListSort;
|
||||||
range?: ListRange;
|
range?: ListRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EntityListResponse {
|
export interface EntityListBulkResponse {
|
||||||
[providerId: string]: {
|
[providerId: string]: {
|
||||||
[serviceId: string]: {
|
[serviceId: string]: {
|
||||||
[collectionId: string]: {
|
[collectionId: string]: {
|
||||||
[identifier: string]: EntityInterface<EventInterface | TaskInterface | JournalInterface>;
|
[identifier: string]: EntityInterface;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity list stream
|
||||||
|
*/
|
||||||
|
export interface EntityListStreamRequest {
|
||||||
|
sources?: CollectionIdentifier[];
|
||||||
|
filter?: ListFilter;
|
||||||
|
sort?: ListSort;
|
||||||
|
range?: ListRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityListStreamResponse extends EntityInterface {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity fetch
|
* Entity fetch
|
||||||
*/
|
*/
|
||||||
export interface EntityFetchRequest {
|
export interface EntityFetchRequest {
|
||||||
provider: string;
|
targets: EntityIdentifier[];
|
||||||
service: string | number;
|
|
||||||
collection: string | number;
|
|
||||||
identifiers: (string | number)[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EntityFetchResponse {
|
export interface EntityFetchResponse {
|
||||||
[identifier: string]: EntityInterface<EventInterface | TaskInterface | JournalInterface>;
|
[identifier: string]: EntityInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entity extant
|
* Entity extant
|
||||||
*/
|
*/
|
||||||
export interface EntityExtantRequest {
|
export interface EntityExtantRequest {
|
||||||
sources: SourceSelector;
|
targets: EntityIdentifier[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EntityExtantResponse {
|
export interface EntityExtantResponse {
|
||||||
@@ -71,50 +92,13 @@ export interface EntityExtantResponse {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Entity create
|
|
||||||
*/
|
|
||||||
export interface EntityCreateRequest<T = EventInterface | TaskInterface | JournalInterface> {
|
|
||||||
provider: string;
|
|
||||||
service: string | number;
|
|
||||||
collection: string | number;
|
|
||||||
properties: T;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EntityCreateResponse<T = EventInterface | TaskInterface | JournalInterface> extends EntityInterface<T> {}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Entity update
|
|
||||||
*/
|
|
||||||
export interface EntityUpdateRequest<T = EventInterface | TaskInterface | JournalInterface> {
|
|
||||||
provider: string;
|
|
||||||
service: string | number;
|
|
||||||
collection: string | number;
|
|
||||||
identifier: string | number;
|
|
||||||
properties: T;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface EntityUpdateResponse<T = EventInterface | TaskInterface | JournalInterface> 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
|
* Entity delta
|
||||||
*/
|
*/
|
||||||
export interface EntityDeltaRequest {
|
export interface EntityDeltaRequest {
|
||||||
sources: SourceSelector;
|
// Each target is provider:service:collection, or provider:service:collection:signature
|
||||||
|
// to request a delta relative to a known signature (the signature is the entity slot).
|
||||||
|
targets: (CollectionIdentifier | EntityIdentifier)[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EntityDeltaResponse {
|
export interface EntityDeltaResponse {
|
||||||
@@ -128,4 +112,58 @@ export interface EntityDeltaResponse {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity create
|
||||||
|
*/
|
||||||
|
export interface EntityCreateRequest<T = EntityPropertiesInterface> {
|
||||||
|
target: CollectionIdentifier;
|
||||||
|
properties: T;
|
||||||
|
options?: Record<string, any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityCreateResponse<T = EntityPropertiesInterface> extends EntityInterface<T> {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity update
|
||||||
|
*/
|
||||||
|
export interface EntityUpdateRequest<T = EntityPropertiesInterface> {
|
||||||
|
target: EntityIdentifier;
|
||||||
|
properties: T;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityUpdateResponse<T = EntityPropertiesInterface> extends EntityInterface<T> {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity delete
|
||||||
|
*/
|
||||||
|
export interface EntityDeleteRequest {
|
||||||
|
targets: EntityIdentifier[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityDeleteResponse {
|
||||||
|
[targetIdentifier: EntityIdentifier]: {
|
||||||
|
disposition: 'deleted' | 'moved' | 'error';
|
||||||
|
destination: CollectionIdentifier | null;
|
||||||
|
mutation: EntityIdentifier | null;
|
||||||
|
error?: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entity move
|
||||||
|
*/
|
||||||
|
export interface EntityMoveRequest {
|
||||||
|
target: CollectionIdentifier;
|
||||||
|
sources: EntityIdentifier[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EntityMoveResponse {
|
||||||
|
[sourceIdentifier: EntityIdentifier]: {
|
||||||
|
disposition: 'moved' | 'error';
|
||||||
|
destination: CollectionIdentifier | null;
|
||||||
|
mutation: EntityIdentifier | null;
|
||||||
|
error?: string;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Provider type definitions
|
* Provider type definitions
|
||||||
*/
|
*/
|
||||||
import type { SourceSelector } from "./common";
|
import type { ProviderIdentifier } from './common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider capabilities
|
* Provider capabilities
|
||||||
@@ -28,22 +28,24 @@ export interface ProviderInterface {
|
|||||||
capabilities: ProviderCapabilitiesInterface;
|
capabilities: ProviderCapabilitiesInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ProviderModelInterface extends Omit<ProviderInterface, '@type'> {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider list
|
* Provider list
|
||||||
*/
|
*/
|
||||||
export interface ProviderListRequest {
|
export interface ProviderListRequest {
|
||||||
sources?: SourceSelector;
|
targets?: ProviderIdentifier[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProviderListResponse {
|
export interface ProviderListResponse {
|
||||||
[identifier: string]: ProviderInterface;
|
[identifier: ProviderIdentifier]: ProviderInterface;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provider fetch
|
* Provider fetch
|
||||||
*/
|
*/
|
||||||
export interface ProviderFetchRequest {
|
export interface ProviderFetchRequest {
|
||||||
identifier: string;
|
target: ProviderIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProviderFetchResponse extends ProviderInterface {}
|
export interface ProviderFetchResponse extends ProviderInterface {}
|
||||||
@@ -52,9 +54,9 @@ export interface ProviderFetchResponse extends ProviderInterface {}
|
|||||||
* Provider extant
|
* Provider extant
|
||||||
*/
|
*/
|
||||||
export interface ProviderExtantRequest {
|
export interface ProviderExtantRequest {
|
||||||
sources: SourceSelector;
|
targets: ProviderIdentifier[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProviderExtantResponse {
|
export interface ProviderExtantResponse {
|
||||||
[identifier: string]: boolean;
|
[identifier: ProviderIdentifier]: boolean;
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-3
@@ -1,7 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* Service type definitions
|
* Service type definitions
|
||||||
*/
|
*/
|
||||||
import type { SourceSelector, ListFilterComparisonOperator } from './common';
|
import type {
|
||||||
|
ServiceIdentifier,
|
||||||
|
CollectionIdentifier,
|
||||||
|
ListFilterComparisonOperator,
|
||||||
|
} from './common';
|
||||||
|
import type { Identity } from '@/models/identity';
|
||||||
|
import type { Location } from '@/models/location';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service capabilities
|
* Service capabilities
|
||||||
@@ -47,11 +53,18 @@ export interface ServiceInterface {
|
|||||||
auxiliary?: Record<string, any>; // Provider-specific extension data
|
auxiliary?: Record<string, any>; // Provider-specific extension data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ServiceModelInterface extends Omit<{
|
||||||
|
[K in keyof ServiceInterface]-?: Exclude<ServiceInterface[K], undefined>;
|
||||||
|
}, '@type' | 'location' | 'identity'> {
|
||||||
|
location: Location | null;
|
||||||
|
identity: Identity | null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service list
|
* Service list
|
||||||
*/
|
*/
|
||||||
export interface ServiceListRequest {
|
export interface ServiceListRequest {
|
||||||
sources?: SourceSelector;
|
targets?: ServiceIdentifier[] | CollectionIdentifier[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServiceListResponse {
|
export interface ServiceListResponse {
|
||||||
@@ -74,7 +87,7 @@ export interface ServiceFetchResponse extends ServiceInterface {}
|
|||||||
* Service extant
|
* Service extant
|
||||||
*/
|
*/
|
||||||
export interface ServiceExtantRequest {
|
export interface ServiceExtantRequest {
|
||||||
sources: SourceSelector;
|
targets: ServiceIdentifier[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ServiceExtantResponse {
|
export interface ServiceExtantResponse {
|
||||||
@@ -99,6 +112,7 @@ export interface ServiceCreateResponse extends ServiceInterface {}
|
|||||||
export interface ServiceUpdateRequest {
|
export interface ServiceUpdateRequest {
|
||||||
provider: string;
|
provider: string;
|
||||||
identifier: string | number;
|
identifier: string | number;
|
||||||
|
delta?: boolean;
|
||||||
data: Partial<ServiceInterface>;
|
data: Partial<ServiceInterface>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user