fix: more explicit api client interface (#7138)

Signed-off-by: Alexander Onnikov <Alexander.Onnikov@xored.com>
This commit is contained in:
Alexander Onnikov 2024-11-08 23:34:39 +07:00 committed by GitHub
parent 19d601b33e
commit 5487e3bd7b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,33 +14,144 @@
// //
import { type ClientSocketFactory } from '@hcengineering/client' 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' import { type MarkupOperations } from './markup'
/** /**
* Platform API client * Platform API client
* @public * @public
* */ * */
export type PlatformClient = AsyncDisposable & export type PlatformClient = {
Pick< getHierarchy: () => Hierarchy
TxOperations,
| 'createDoc' getModel: () => ModelDb
| 'updateDoc'
| 'removeDoc' close: () => Promise<void>
| 'addCollection' } & FindOperations &
| 'updateCollection' DocOperations &
| 'removeCollection' CollectionOperations &
| 'createMixin' MixinOperations &
| 'updateMixin' MarkupOperations &
> & AsyncDisposable
Pick<Client, 'getHierarchy' | 'getModel' | 'findAll' | 'findOne' | 'close'> &
MarkupOperations /**
* @public
*/
export interface FindOperations {
findAll: <T extends Doc>(
_class: Ref<Class<T>>,
query: DocumentQuery<T>,
options?: FindOptions<T> | undefined
) => Promise<FindResult<T>>
findOne: <T extends Doc>(
_class: Ref<Class<T>>,
query: DocumentQuery<T>,
options?: FindOptions<T> | undefined
) => Promise<WithLookup<T> | undefined>
}
/**
* @public
*/
export interface DocOperations {
createDoc: <T extends Doc>(
_class: Ref<Class<T>>,
space: Ref<Space>,
attributes: Data<T>,
id?: Ref<T>
) => Promise<Ref<T>>
updateDoc: <T extends Doc>(
_class: Ref<Class<T>>,
space: Ref<Space>,
objectId: Ref<T>,
operations: DocumentUpdate<T>,
retrieve?: boolean
) => Promise<TxResult>
removeDoc: <T extends Doc>(_class: Ref<Class<T>>, space: Ref<Space>, objectId: Ref<T>) => Promise<TxResult>
}
/**
* @public
*/
export interface CollectionOperations {
addCollection: <T extends Doc, P extends AttachedDoc>(
_class: Ref<Class<P>>,
space: Ref<Space>,
attachedTo: Ref<T>,
attachedToClass: Ref<Class<T>>,
collection: Extract<keyof T, string> | string,
attributes: AttachedData<P>,
id?: Ref<P>
) => Promise<Ref<P>>
updateCollection: <T extends Doc, P extends AttachedDoc>(
_class: Ref<Class<P>>,
space: Ref<Space>,
objectId: Ref<P>,
attachedTo: Ref<T>,
attachedToClass: Ref<Class<T>>,
collection: Extract<keyof T, string> | string,
operations: DocumentUpdate<P>,
retrieve?: boolean
) => Promise<Ref<T>>
removeCollection: <T extends Doc, P extends AttachedDoc>(
_class: Ref<Class<P>>,
space: Ref<Space>,
objectId: Ref<P>,
attachedTo: Ref<T>,
attachedToClass: Ref<Class<T>>,
collection: Extract<keyof T, string> | string
) => Promise<Ref<T>>
}
/**
* @public
*/
export interface MixinOperations {
createMixin: <D extends Doc, M extends D>(
objectId: Ref<D>,
objectClass: Ref<Class<D>>,
objectSpace: Ref<Space>,
mixin: Ref<Mixin<M>>,
attributes: MixinData<D, M>
) => Promise<TxResult>
updateMixin: <D extends Doc, M extends D>(
objectId: Ref<D>,
objectClass: Ref<Class<D>>,
objectSpace: Ref<Space>,
mixin: Ref<Mixin<M>>,
attributes: MixinUpdate<D, M>
) => Promise<TxResult>
}
/** /**
* Configuration options for password-based authentication * Configuration options for password-based authentication
* @public * @public
*/ */
export interface PasswordAuthOptions { export interface PasswordAuthOptions {
/** User's email address */ /** User's email address */
email: string email: string