@dossierhq/core
Version:
The core Dossier library used by clients and server alike, used to interact with schema and entities directly, as well as remotely through a client.
63 lines (62 loc) • 3.7 kB
TypeScript
import { type ErrorType, type Result } from '../ErrorResult.js';
import type { ArchiveEntitySyncEvent, ChangelogEvent, CreateEntitySyncEvent, PublishEntitiesSyncEvent, SyncEvent, UnarchiveEntitySyncEvent, UnpublishEntitiesSyncEvent, UpdateEntitySyncEvent, UpdateSchemaSyncEvent } from '../events/EventTypes.js';
import type { Connection, Edge, Entity, EntityCreatePayload, EntityDeletePayload, EntityInfo, EntityPublishingPayload, EntityUpdatePayload, EntityUpsertPayload, PageInfo, PublishedEntity, PublishedEntityInfo } from '../Types.js';
export interface JsonConnection<T extends JsonEdge<unknown, ErrorType>> {
pageInfo: PageInfo;
edges: T[];
}
export interface JsonEdge<TOk, TError extends ErrorType> {
node: JsonResult<TOk, TError>;
cursor: string;
}
export type JsonResult<TOk, TError extends ErrorType> = {
value: TOk;
} | {
error: TError;
message: string;
};
interface JsonEntityInfo extends Omit<EntityInfo, 'createdAt' | 'updatedAt'> {
createdAt: string;
updatedAt: string;
}
export interface JsonEntity extends Omit<Entity, 'info'> {
info: JsonEntityInfo;
}
interface JsonPublishedEntityInfo extends Omit<PublishedEntityInfo, 'createdAt'> {
createdAt: string;
}
export interface JsonPublishedEntity extends Omit<PublishedEntity, 'info'> {
info: JsonPublishedEntityInfo;
}
export interface JsonEntityCreatePayload extends Omit<EntityCreatePayload, 'entity'> {
entity: JsonEntity;
}
export interface JsonEntityUpdatePayload extends Omit<EntityUpdatePayload, 'entity'> {
entity: JsonEntity;
}
export interface JsonEntityUpsertPayload extends Omit<EntityUpsertPayload, 'entity'> {
entity: JsonEntity;
}
export interface JsonEntityPublishingPayload<TEffect> extends Omit<EntityPublishingPayload<TEffect>, 'updatedAt'> {
updatedAt: string;
}
export interface JsonEntityDeletePayload extends Omit<EntityDeletePayload, 'deletedAt'> {
deletedAt: string;
}
type WithCreatedAt<T extends {
createdAt: Date;
}> = Omit<T, 'createdAt'> & {
createdAt: string;
};
export type JsonChangelogEvent<TEvent extends ChangelogEvent = ChangelogEvent> = WithCreatedAt<TEvent>;
export type JsonSyncEvent = WithCreatedAt<UpdateSchemaSyncEvent> | WithCreatedAt<CreateEntitySyncEvent> | WithCreatedAt<UpdateEntitySyncEvent> | WithCreatedAt<PublishEntitiesSyncEvent> | WithCreatedAt<UnpublishEntitiesSyncEvent> | WithCreatedAt<ArchiveEntitySyncEvent> | WithCreatedAt<UnarchiveEntitySyncEvent>;
export declare function convertJsonConnection<TIn extends JsonEdge<unknown, ErrorType>, TOut extends Edge<unknown, ErrorType>>(jsonConnection: JsonConnection<TIn> | null, edgeConverter: (edge: TIn) => TOut): Connection<TOut> | null;
export declare function convertJsonEdge<TOkIn, TOkOut, TError extends ErrorType>(jsonEdge: JsonEdge<TOkIn, TError>, nodeConverter: (node: TOkIn) => TOkOut): Edge<TOkOut, TError>;
export declare function convertJsonResult<TOk, TError extends ErrorType>(jsonResult: JsonResult<TOk, TError>): Result<TOk, TError>;
export declare function convertJsonEntity(entity: JsonEntity): Entity;
export declare function convertJsonPublishedEntity(entity: JsonPublishedEntity): PublishedEntity;
export declare function convertJsonPublishingPayload<TEffect>(payload: JsonEntityPublishingPayload<TEffect>): EntityPublishingPayload<TEffect>;
export declare function convertJsonDeletePayload(payload: JsonEntityDeletePayload): EntityDeletePayload;
export declare function convertJsonChangelogEventEdge<TEvent extends ChangelogEvent, TError extends ErrorType>(edge: JsonEdge<JsonChangelogEvent<TEvent>, TError>): Edge<ChangelogEvent, TError>;
export declare function convertJsonSyncEvent(syncEvent: JsonSyncEvent): SyncEvent;
export {};