import type { DB, DBTransaction, LevelPath } from '@matrixai/db'; import type { Gestalt, GestaltAction, GestaltActions, GestaltKey, GestaltLinkId, GestaltNodeInfo, GestaltIdentityInfo, GestaltLink, GestaltLinkNode, GestaltInfo, GestaltLinkIdentity, GestaltId } from './types.js'; import type { ClaimId, NodeId, ProviderIdentityId } from '../ids/types.js'; import type ACL from '../acl/ACL.js'; import Logger from '@matrixai/logger'; import { createDestroyStartStop } from '@matrixai/async-init'; interface GestaltGraph extends createDestroyStartStop.CreateDestroyStartStop { } declare class GestaltGraph { static createGestaltGraph({ db, acl, logger, fresh, }: { db: DB; acl: ACL; logger?: Logger; fresh?: boolean; }): Promise; protected logger: Logger; protected db: DB; protected acl: ACL; readonly dbPath: Readonly; /** * Gestalt adjacency matrix represented as a collection vertex pairs. * Each vertex can be `GestaltNodeKey` or `GestaltIdentityKey`. * These are the allowable structures: * `GestaltGraph/matrix/{GestaltKey} -> null` * `GestaltGraph/matrix/{GestaltKey}/{GestaltKey} -> {raw(GestaltLinkId)}` */ readonly dbMatrixPath: Readonly; /** * Gestalt links. * `GestaltGraph/links/{GestaltLinkId} -> {json(GestaltLink)}` */ readonly dbLinksPath: Readonly; /** * Node information * `GestaltGraph/nodes/{GestaltKey} -> {json(GestaltNodeInfo)}` */ readonly dbNodesPath: Readonly; /** * Identity information * `GestaltGraph/identities/{GestaltKey} -> {json(GestaltIdentityInfo)}` */ readonly dbIdentitiesPath: LevelPath; /** * Last processed collection * `GestaltGraph/VertexProcessedTime/{GestaltIdEncoded} -> number` */ protected vertexProcessedTimePath: LevelPath; /** * Last processed collection * `GestaltGraph/vertexProcessedTimeOrder/{number}/{GestaltIdEncoded} -> gestaltIdEncoded` */ protected vertexProcessedTimeOrderPath: LevelPath; protected nodeClaimIdOldestPath: LevelPath; protected generateGestaltLinkId: () => GestaltLinkId; constructor({ db, acl, logger }: { db: DB; acl: ACL; logger: Logger; }); start({ fresh }?: { fresh?: boolean; }): Promise; stop(): Promise; destroy(): Promise; /** * Sets a node in the graph * Can be used to update an existing node * If this is a new node, it will set a new node pointer * to a new gestalt permission in the acl */ setNode(nodeInfo: GestaltNodeInfo, tran?: DBTransaction): Promise<['node', NodeId]>; setIdentity(identityInfo: GestaltIdentityInfo, tran?: DBTransaction): Promise<['identity', ProviderIdentityId]>; unsetNode(nodeId: NodeId, tran?: DBTransaction): Promise; unsetIdentity(providerIdentityId: ProviderIdentityId, tran?: DBTransaction): Promise; setVertex(gestaltInfo: GestaltInfo, tran?: DBTransaction): Promise; unsetVertex(gestaltId: GestaltId, tran?: DBTransaction): Promise; /** * Updates the last processed time in the database for the given vertex */ setVertexProcessedTime(vertex: GestaltId, processedTime: number, tran?: DBTransaction): Promise; /** * Removes the last processed time for a vertex */ unsetVertexProcessedTime(vertex: GestaltId, tran?: DBTransaction): Promise; /** * Gets the last processed time for a vertex */ getVertexProcessedTime(vertex: GestaltId, tran?: DBTransaction): Promise; /** * Gets the last processed time for a vertex */ getVertexProcessedTimes({ order, seek, limit, }?: { order?: 'asc' | 'desc'; seek?: number; limit?: number; }, tran?: DBTransaction): AsyncGenerator<[GestaltId, number]>; /** * Updates the newest `ClaimId` for a node if it's newer than the current id stored */ setClaimIdNewest(nodeId: NodeId, claimId: ClaimId, tran?: DBTransaction): Promise; getClaimIdNewest(nodeId: NodeId, tran?: DBTransaction): Promise; /** * This checks if the link node has matching issuer and subject. * It does not however verify the signatures. * Verifying signatures should be done before linking the nodes in the GG */ linkNodeAndNode(nodeInfo1: GestaltNodeInfo, nodeInfo2: GestaltNodeInfo, linkNode: Omit, tran?: DBTransaction): Promise; linkNodeAndIdentity(nodeInfo: GestaltNodeInfo, identityInfo: GestaltIdentityInfo, linkIdentity: Omit, tran?: DBTransaction): Promise; linkVertexAndVertex(gestaltInfo1: ['node', GestaltNodeInfo], gestaltInfo2: ['node', GestaltNodeInfo], link: ['node', Omit], tran?: DBTransaction): Promise; linkVertexAndVertex(gestaltInfo1: ['node', GestaltNodeInfo], gestaltInfo2: ['identity', GestaltIdentityInfo], link: ['identity', Omit], tran?: DBTransaction): Promise; linkVertexAndVertex(gestaltInfo1: ['identity', GestaltIdentityInfo], gestaltInfo2: ['node', GestaltNodeInfo], link: ['identity', Omit], tran?: DBTransaction): Promise; unlinkNodeAndNode(nodeId1: NodeId, nodeId2: NodeId, tran?: DBTransaction): Promise; unlinkNodeAndIdentity(nodeId: NodeId, providerIdentityId: ProviderIdentityId, tran?: DBTransaction): Promise; unlinkVertexAndVertex(gestaltId1: ['node', NodeId], gestaltId2: ['node', NodeId], tran?: DBTransaction): Promise; unlinkVertexAndVertex(gestaltId1: ['node', NodeId], gestaltId2: ['identity', ProviderIdentityId], tran?: DBTransaction): Promise; unlinkVertexAndVertex(gestaltId1: ['identity', ProviderIdentityId], gestaltId2: ['node', NodeId], tran?: DBTransaction): Promise; getGestaltActions(gestaltId: GestaltId, tran?: DBTransaction): Promise; setGestaltAction(gestaltId: GestaltId, action: GestaltAction, tran?: DBTransaction): Promise; unsetGestaltAction(gestaltId: GestaltId, action: GestaltAction, tran?: DBTransaction): Promise; getGestalts(tran?: DBTransaction): AsyncGenerator; getGestalt(gestaltId: GestaltId, tran?: DBTransaction): Promise; getGestaltByNode(nodeId: NodeId, tran?: DBTransaction): Promise; getGestaltByIdentity(providerIdentityId: ProviderIdentityId, tran?: DBTransaction): Promise; getNode(nodeId: NodeId, tran?: DBTransaction): Promise; getIdentity(providerIdentityId: ProviderIdentityId, tran?: DBTransaction): Promise; getVertex(gestaltId: ['node', NodeId], tran?: DBTransaction): Promise<['node', GestaltNodeInfo] | undefined>; getVertex(gestaltId: ['identity', ProviderIdentityId], tran?: DBTransaction): Promise<['identity', GestaltIdentityInfo] | undefined>; getVertex(gestaltId: GestaltId, tran?: DBTransaction): Promise; getLinkById(linkId: GestaltLinkId, tran?: DBTransaction): Promise; getLink(gestaltId1: ['node', NodeId], gestaltId2: ['node', NodeId], tran?: DBTransaction): Promise<['node', GestaltLinkNode] | undefined>; getLink(gestaltId1: ['identity', ProviderIdentityId], gestaltId2: ['node', NodeId], tran?: DBTransaction): Promise<['identity', GestaltLinkIdentity] | undefined>; getLink(gestaltId1: ['node', NodeId], gestaltId2: ['identity', ProviderIdentityId], tran?: DBTransaction): Promise<['identity', GestaltLinkIdentity] | undefined>; getLinks(gestaltId: GestaltId, tran?: DBTransaction): AsyncGenerator<[GestaltId, GestaltLink]>; /** * Gets a gestalt using BFS. * During execution the`visited` set indicates the vertexes that have been queued. * This BFS algorithm has to 2 stages: * 1. processing the vertex information. * 2. processing the vertex links by iterating the vertex neighbours. * When processing vertex information we need to avoid queued duplicate vertexes. * When processing vertex links we need to avoid already processed links. * When finished, the `visited` set indicates the vertexes that have been processed. */ protected getGestaltByKey(gestaltKey: GestaltKey, visited: Set | undefined, tran: DBTransaction): Promise; protected getIdentityLinkedNodeId(providerIdentityId: ProviderIdentityId, tran: DBTransaction): Promise; } export default GestaltGraph;