From 5487e3bd7bfaec454f2b6ca6d0c5f5a477f952a3 Mon Sep 17 00:00:00 2001 From: Alexander Onnikov Date: Fri, 8 Nov 2024 23:34:39 +0700 Subject: [PATCH] fix: more explicit api client interface (#7138) Signed-off-by: Alexander Onnikov --- packages/api-client/src/types.ts | 143 +++++++++++++++++++++++++++---- 1 file changed, 127 insertions(+), 16 deletions(-) diff --git a/packages/api-client/src/types.ts b/packages/api-client/src/types.ts index 0dae84e3e3..820ae9c48f 100644 --- a/packages/api-client/src/types.ts +++ b/packages/api-client/src/types.ts @@ -14,33 +14,144 @@ // import { type ClientSocketFactory } from '@hcengineering/client' -import { type Client, type TxOperations } from '@hcengineering/core' +import { + type AttachedData, + type AttachedDoc, + type Class, + type Data, + type Doc, + type DocumentQuery, + type DocumentUpdate, + type FindOptions, + type FindResult, + type Hierarchy, + type Mixin, + type MixinData, + type MixinUpdate, + type ModelDb, + type Ref, + type Space, + type TxResult, + type WithLookup +} from '@hcengineering/core' import { type MarkupOperations } from './markup' /** * Platform API client * @public * */ -export type PlatformClient = AsyncDisposable & -Pick< -TxOperations, -| 'createDoc' -| 'updateDoc' -| 'removeDoc' -| 'addCollection' -| 'updateCollection' -| 'removeCollection' -| 'createMixin' -| 'updateMixin' -> & -Pick & -MarkupOperations +export type PlatformClient = { + getHierarchy: () => Hierarchy + + getModel: () => ModelDb + + close: () => Promise +} & FindOperations & +DocOperations & +CollectionOperations & +MixinOperations & +MarkupOperations & +AsyncDisposable /** - * Configuration options for password-based authentication * @public */ +export interface FindOperations { + findAll: ( + _class: Ref>, + query: DocumentQuery, + options?: FindOptions | undefined + ) => Promise> + + findOne: ( + _class: Ref>, + query: DocumentQuery, + options?: FindOptions | undefined + ) => Promise | undefined> +} +/** + * @public + */ +export interface DocOperations { + createDoc: ( + _class: Ref>, + space: Ref, + attributes: Data, + id?: Ref + ) => Promise> + + updateDoc: ( + _class: Ref>, + space: Ref, + objectId: Ref, + operations: DocumentUpdate, + retrieve?: boolean + ) => Promise + + removeDoc: (_class: Ref>, space: Ref, objectId: Ref) => Promise +} + +/** + * @public + */ +export interface CollectionOperations { + addCollection: ( + _class: Ref>, + space: Ref, + attachedTo: Ref, + attachedToClass: Ref>, + collection: Extract | string, + attributes: AttachedData

, + id?: Ref

+ ) => Promise> + + updateCollection: ( + _class: Ref>, + space: Ref, + objectId: Ref

, + attachedTo: Ref, + attachedToClass: Ref>, + collection: Extract | string, + operations: DocumentUpdate

, + retrieve?: boolean + ) => Promise> + + removeCollection: ( + _class: Ref>, + space: Ref, + objectId: Ref

, + attachedTo: Ref, + attachedToClass: Ref>, + collection: Extract | string + ) => Promise> +} + +/** + * @public + */ +export interface MixinOperations { + createMixin: ( + objectId: Ref, + objectClass: Ref>, + objectSpace: Ref, + mixin: Ref>, + attributes: MixinData + ) => Promise + + updateMixin: ( + objectId: Ref, + objectClass: Ref>, + objectSpace: Ref, + mixin: Ref>, + attributes: MixinUpdate + ) => Promise +} + +/** + * Configuration options for password-based authentication + * @public + */ export interface PasswordAuthOptions { /** User's email address */ email: string