UNPKG

@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.

57 lines 1.81 kB
/// <reference types="./JsonUtils.d.ts" /> import { createErrorResult, ok } from '../ErrorResult.js'; export function convertJsonConnection(jsonConnection, edgeConverter) { if (!jsonConnection) { return null; } return { pageInfo: jsonConnection.pageInfo, edges: jsonConnection.edges.map(edgeConverter) }; } export function convertJsonEdge(jsonEdge, nodeConverter) { const nodeJson = convertJsonResult(jsonEdge.node); const node = nodeJson.isOk() ? nodeJson.map(nodeConverter) : nodeJson; return { node, cursor: jsonEdge.cursor }; } export function convertJsonResult(jsonResult) { if ('value' in jsonResult) { return ok(jsonResult.value); } return createErrorResult(jsonResult.error, jsonResult.message); } export function convertJsonEntity(entity) { return { ...entity, info: { ...entity.info, createdAt: new Date(entity.info.createdAt), updatedAt: new Date(entity.info.updatedAt), }, }; } export function convertJsonPublishedEntity(entity) { return { ...entity, info: { ...entity.info, createdAt: new Date(entity.info.createdAt), }, }; } export function convertJsonPublishingPayload(payload) { return { ...payload, updatedAt: new Date(payload.updatedAt), }; } export function convertJsonDeletePayload(payload) { return { ...payload, deletedAt: new Date(payload.deletedAt), }; } export function convertJsonChangelogEventEdge(edge) { return convertJsonEdge(edge, (node) => ({ ...node, createdAt: new Date(node.createdAt) })); } export function convertJsonSyncEvent(syncEvent) { return { ...syncEvent, createdAt: new Date(syncEvent.createdAt) }; } //# sourceMappingURL=JsonUtils.js.map