UNPKG

@shopware-ag/meteor-admin-sdk

Version:

The Meteor SDK for the Shopware Administration.

28 lines (27 loc) 2 kB
import type RepositoryFactory from './repository'; import type { Entity } from '../_internals/data/Entity'; import type EntityCollection from '../_internals/data/EntityCollection'; import type { ApiContext } from '../_internals/data/EntityCollection'; import type Criteria from './Criteria'; export type SDKRepository<EntityName extends keyof EntitySchema.Entities> = ReturnType<typeof RepositoryFactory<EntityName>>; export type RepositorySource<EntityName extends keyof EntitySchema.Entities> = Pick<SDKRepository<EntityName>, 'search' | 'get' | 'save' | 'clone' | 'saveAll' | 'delete'> & { hasChanges: (entity: Entity<EntityName>) => Promise<boolean | null> | boolean; create: (context?: ApiContext, entityId?: string | null) => Promise<Entity<EntityName> | null> | Entity<EntityName>; }; /** * Repository adapter that can wrap different source implementations * and provide a consistent interface */ export declare class RepositoryAdapter<EntityName extends keyof EntitySchema.Entities> implements SDKRepository<EntityName> { private sourceRepository; constructor(sourceRepository: RepositorySource<EntityName>); search(criteria: Criteria, context?: ApiContext): Promise<EntityCollection<EntityName> | null>; get(id: string, context?: ApiContext, criteria?: Criteria): Promise<Entity<EntityName> | null>; save(entity: Entity<EntityName>, context?: ApiContext): Promise<void | null>; clone(entityId: string, behavior: unknown, context?: ApiContext): Promise<unknown>; hasChanges(entity: Entity<EntityName>): Promise<boolean | null>; saveAll(entities: EntityCollection<EntityName>, context?: ApiContext): Promise<unknown>; delete(entityId: string, context?: ApiContext): Promise<void | null>; create(context?: ApiContext, entityId?: string): Promise<Entity<EntityName> | null>; } export declare function createRepositoryAdapter<EntityName extends keyof EntitySchema.Entities>(source: RepositorySource<EntityName>): SDKRepository<EntityName>;