/* eslint-disable @typescript-eslint/naming-convention */ import type { ReferenceNodeObject, TriplesMap } from '@comake/rmlmapper-js'; import type { GraphObject, IdMap, IncludedBlock, IndexMap, LanguageMap, ListObject, NodeObject, SetObject, TypeMap } from 'jsonld'; import type { Frame } from 'jsonld/jsonld-spec'; import type { EngineConstants } from '../constants'; import type { FindAllOptions, FindOneOptions, FindOptionsWhere } from '../storage/FindOptionsTypes'; import type { GroupByOptions, GroupByResponse } from '../storage/GroupOptionTypes'; import type { RawQueryResult } from '../storage/query-adapter/QueryAdapter'; import type { RDF, SHACL } from './Vocabularies'; export type JSONPrimitive = string | number | boolean | null; // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style export interface JSONObject { [key: string]: JSONValue | undefined; } export interface JSONArray extends Array {} export type JSONValue = JSONPrimitive | JSONObject | JSONValue[]; export interface RdfList { [RDF.first]: T; [RDF.rest]?: RdfList | typeof RDF.nil | ReferenceNodeObject; } export interface ValueObject { ['@type']: string; ['@value']: T; ['@language']?: string; ['@direction']?: string; } export type IRIObject = { '@id': T }; export type ShaclIRI = string | IRIObject; export type ShaclIRIOrLiteral = ShaclIRI | ValueObject; export type NodeKindValues = | typeof SHACL.Literal | typeof SHACL.IRI | typeof SHACL.BlankNode | typeof SHACL.BlankNodeOrIRI | typeof SHACL.BlankNodeOrLiteral | typeof SHACL.IRIOrLiteral; export type BaseShape = NodeObject & { [SHACL.targetNode]?: ShaclIRIOrLiteral; [SHACL.targetClass]?: ShaclIRI; [SHACL.targetSubjectsOf]?: ShaclIRI; [SHACL.targetObjectOf]?: ShaclIRI; [SHACL.severity]?: ShaclIRI; [SHACL.message]?: OrArray>; [SHACL.deactivated]?: ValueObject; [SHACL.and]?: ShapesListShape; [SHACL.class]?: OrArray; [SHACL.closed]?: ValueObject; [SHACL.ignoredProperties]?: ShaclIRI[]; [SHACL.disjoint]?: OrArray; [SHACL.equals]?: OrArray; [SHACL.in]?: ListObject; [SHACL.languageIn]?: string[]; [SHACL.maxExclusive]?: ValueObject; [SHACL.maxInclusive]?: ValueObject; [SHACL.maxLength]?: ValueObject; [SHACL.minExclusive]?: ValueObject; [SHACL.minInclusive]?: ValueObject; [SHACL.minLength]?: ValueObject; [SHACL.nodeKind]?: IRIObject; [SHACL.or]?: ShapesListShape; [SHACL.pattern]?: ValueObject; [SHACL.flags]?: ValueObject; [SHACL.xone]?: ShapesListShape; }; export type ShapesListShape = (PropertyShape | NodeShape)[]; export interface PropertyShape extends BaseShape { [SHACL.path]: PathTypes; [SHACL.datatype]?: ShaclIRI; [SHACL.node]?: OrArray; [SHACL.name]?: ValueObject; [SHACL.description]?: ValueObject; [SHACL.minCount]?: ValueObject; [SHACL.maxCount]?: ValueObject; [SHACL.lessThanOrEquals]?: OrArray; [SHACL.lessThan]?: OrArray; [SHACL.qualifiedValueShape]?: OrArray; [SHACL.qualifiedMaxCount]?: ValueObject; [SHACL.qualifiedMinCount]?: ValueObject; [SHACL.qualifiedValueShapesDisjoint]?: ValueObject; [SHACL.uniqueLang]?: ValueObject; } export interface NodeShape extends BaseShape { '@type': typeof SHACL.NodeShape; [EngineConstants.prop.label]?: ValueObject; [SHACL.property]: OrArray; } export interface InverseShaclPath extends NodeObject { [SHACL.inversePath]: PathShape; } export interface ZeroOrMoreShaclPath extends NodeObject { [SHACL.zeroOrMorePath]: PathShape; } export interface OneOrMoreShaclPath extends NodeObject { [SHACL.oneOrMorePath]: PathShape; } export interface ZeroOrOneShaclPath extends NodeObject { [SHACL.zeroOrOnePath]: PathShape; } export interface AlternativeShaclPath extends NodeObject { [SHACL.alternativePath]: PathTypes[]; } export type PathTypes = | ShaclIRI | AlternativeShaclPath | ZeroOrMoreShaclPath | OneOrMoreShaclPath | ZeroOrOneShaclPath | InverseShaclPath; export type PathShape = OrArray; export type Mapping = NodeObject & { [EngineConstants.prop.preProcessingMapping]?: OrArray; [EngineConstants.prop.preProcessingMappingFrame]?: ValueObject; [EngineConstants.prop.inputsMapping]?: OrArray; [EngineConstants.prop.inputsMappingFrame]?: ValueObject; [EngineConstants.prop.inputsMappingRef]?: string | ValueObject; [EngineConstants.prop.operationId]?: ValueObject; [EngineConstants.prop.operationMapping]?: TriplesMap; [EngineConstants.prop.capability]?: ReferenceNodeObject; [EngineConstants.prop.outputsMapping]?: OrArray; [EngineConstants.prop.outputsMappingFrame]?: ValueObject; [EngineConstants.prop.series]?: { '@list': CapabilityMapping[] } | (RdfList & NodeObject); [EngineConstants.prop.parallel]?: OrArray; }; export type Capability = NodeObject & { '@id': string; '@type': typeof EngineConstants.spec.capability; [EngineConstants.prop.label]?: ValueObject; [EngineConstants.prop.inputsContext]?: ValueObject; [EngineConstants.prop.inputs]?: NodeShape | ReferenceNodeObject; [EngineConstants.prop.outputsContext]?: ValueObject; [EngineConstants.prop.outputs]?: NodeShape | ReferenceNodeObject; }; export type CapabilityMapping = Mapping & { [EngineConstants.prop.capability]: ReferenceNodeObject; [EngineConstants.prop.object]?: ReferenceNodeObject; [EngineConstants.prop.integration]?: ReferenceNodeObject; }; export type MappingWithInputs = CapabilityMapping & Required>; export type MappingWithInputsReference = CapabilityMapping & Required>; export type MappingWithOutputsMapping = CapabilityMapping & Required< Pick< CapabilityMapping, typeof EngineConstants.prop.outputsMapping | typeof EngineConstants.prop.outputsMappingFrame > >; export type MappingWithSeries = CapabilityMapping & Required>; export type MappingWithParallel = CapabilityMapping & Required>; export interface SeriesCapabilityArgs extends JSONObject { originalCapabilityParameters: JSONObject; previousCapabilityReturnValue: JSONObject; allStepsResults: JSONObject[]; } export type TriggerMapping = Mapping & { [EngineConstants.prop.integration]: ReferenceNodeObject; }; export type PossibleArrayFieldValues = | boolean | number | string | NodeObject | GraphObject | ValueObject | ListObject | SetObject; export type EntityFieldSingularValue = | boolean | number | string | NodeObject | GraphObject | ValueObject | ListObject | SetObject; export type EntityFieldValue = | OrArray | LanguageMap | IndexMap | IncludedBlock | IdMap | TypeMap | NodeObject[keyof NodeObject]; export interface Entity { '@id': string; '@type': OrArray; [key: string]: EntityFieldValue; } export type OrArray = T | T[]; export interface OperationResponse extends JSONObject { data: JSONObject; operationParameters: JSONObject; } export interface CapabilityConfig { /** * Callbacks to execute upon events. * If global callbacks are provided, both are executed. */ callbacks?: Callbacks; /** * When true, disables validation of capability parameters and * return values according to schemas. Overrides the global setting. */ readonly disableValidation?: boolean; /** * An object containing files keyed on their title that can be used in mappings. * Merged with the global setting. The capability config taking prededence in the case of overlapping names. */ readonly inputFiles?: Record; /** * Manually defined functions which can be used in mappings. * Merged with the global setting. The capability config taking prededence in the case of overlapping names. */ readonly functions?: Record any>; /** * When true, the operation will be streamed. */ readonly stream?: boolean; /** * When true, the operation will be buffered. */ readonly buffer?: boolean; /** * Additional options to pass to the axios request. */ readonly axiosOptions?: Record; } export interface Callbacks { /** * Callback run when a Capability starts being executed */ onCapabilityStart?: (capability: string, args: Record) => void; /** * Callback run when a Capability is finished being executed */ onCapabilityEnd?: (capability: string, returnValue: Record) => void; } export interface SKLEngineInterface { /** * Finds the first entity by the given find options */ find: (options?: FindOneOptions) => Promise; /** * Finds the first entity that matches the given where condition */ findBy: (where: FindOptionsWhere, notFoundErrorMessage?: string) => Promise; /** * Finds the first entity that matches the given where condition, or undefined if not found */ findByIfExists: (options: FindOptionsWhere) => Promise; /** * Finds entities that match the given find options */ findAll: (options?: FindAllOptions) => Promise; /** * Groups entities by the given options */ groupBy: (options: GroupByOptions) => Promise; /** * Finds entities that match the given where condition */ findAllBy: (where: FindOptionsWhere) => Promise; /** * Determines if an entity matching the given options exists */ exists: (options?: FindAllOptions) => Promise; /** * Returns a count of entities matching the given options */ count: (options?: FindAllOptions) => Promise; /** * Saves a given entity or entities */ save: ((entity: Entity) => Promise) & ((entities: Entity[]) => Promise); /** * Updates an entity or entities partially */ update: ((id: string, attributes: Partial) => Promise) & ((ids: string[], attributes: Partial) => Promise); /** * Removes an entity or entities from the database by id */ delete: ((id: string) => Promise) & ((ids: string[]) => Promise); /** * Removes a given entity or entities from the database */ destroy: ((entity: Entity) => Promise) & ((entities: Entity[]) => Promise); /** * Performs a mapping operation */ performMapping: ( args: JSONValue, mapping: OrArray, frame?: Record, capabilityConfig?: CapabilityConfig, ) => Promise; /** * Executes a raw query */ executeRawQuery: (query: string) => Promise; /** * Executes a raw update query */ executeRawUpdate: (query: string) => Promise; /** * Executes a raw construct query */ executeRawConstructQuery: (query: string, frame?: Frame) => Promise; /** * Record of capability handlers by name */ capability: Record Promise>; /** * Finds and executes a capability */ findAndExecuteCapability: ( capabilityId: string, args: JSONObject, capabilityConfig?: CapabilityConfig, ) => Promise>; executeCapability: ( capability: Capability, capabilityArgs: JSONObject, capabilityConfig?: CapabilityConfig, ) => Promise>; executeMapping: ( mapping: Mapping, args: JSONObject, capabilityConfig?: CapabilityConfig, account?: Entity, ) => Promise>; }