From 2198ece740a42a8edd8a7037ad19e93eb96427dc Mon Sep 17 00:00:00 2001 From: tokebe <43009413+tokebe@users.noreply.github.com> Date: Thu, 27 Apr 2023 12:18:08 -0700 Subject: [PATCH] feat: support pprovenance refactor (trapi 1.4) --- .../sync_builder_factory.ts | 28 +++++++++++++++---- src/parser/types.ts | 7 +++-- src/types.ts | 1 + 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/operations_builder/sync_builder_factory.ts b/src/operations_builder/sync_builder_factory.ts index fd6f44f..b342ad3 100644 --- a/src/operations_builder/sync_builder_factory.ts +++ b/src/operations_builder/sync_builder_factory.ts @@ -7,18 +7,34 @@ export const syncBuilderFactory = ( options: BuilderOptions, includeReasoner: boolean, smartapi_path: string, - predicates_path: string + predicates_path: string, ): SmartAPIKGOperationObject[] => { let builder; if (includeReasoner === true) { - builder = new SyncOperationsBuilderWithReasoner( - options, - smartapi_path, - predicates_path - ); + builder = new SyncOperationsBuilderWithReasoner(options, smartapi_path, predicates_path); } else { builder = new SyncOperationsBuilder(options, smartapi_path); } const ops = builder.build(); + + const primaryKnowledgeAPIs = new Set(); + options.apiList?.include.forEach(api => { + if (api.primarySource) { + if (api.id) primaryKnowledgeAPIs.add(api.id); + if (api.infores) primaryKnowledgeAPIs.add(api.infores); + } + }); + options.apiList?.exclude.forEach(api => { + if (api.primarySource) { + if (api.id) primaryKnowledgeAPIs.add(api.id); + if (api.infores) primaryKnowledgeAPIs.add(api.infores); + } + }); + ops.map(op => { + const apiIsPrimaryKnowledgeSource = + primaryKnowledgeAPIs.has(op.association.smartapi.id) || + primaryKnowledgeAPIs.has(op.association["x-translator"].infores); + op.association.apiIsPrimaryKnowledgeSource = apiIsPrimaryKnowledgeSource ? true : false; + }); return ops; }; diff --git a/src/parser/types.ts b/src/parser/types.ts index 15cc99b..8c51e09 100644 --- a/src/parser/types.ts +++ b/src/parser/types.ts @@ -1,7 +1,7 @@ export interface XTranslatorObject { component: string; team: string[]; - "infores"?: string; + infores?: string; } interface SmartAIPInfoObject { @@ -111,7 +111,7 @@ export interface XBTEKGSOperationObject { inputs: XBTEKGSOperationBioEntityObject[]; outputs: XBTEKGSOperationBioEntityObject[]; predicate: string; - qualifiers?: { [qualifierType: string]: string; }; + qualifiers?: { [qualifierType: string]: string }; source?: string; parameters?: XBTEParametersObject; requestBody?: any; @@ -157,12 +157,13 @@ interface KGAssociationObject { source?: string; api_name?: string; component?: string; + apiIsPrimaryKnowledgeSource?: boolean; smartapi?: SmartAPIRegistryRecordObject; "x-translator"?: any; "x-trapi"?: XTRAPIObject; qualifiers?: { [qualifierType: string]: string; - } + }; } export interface QueryOperationInterface { diff --git a/src/types.ts b/src/types.ts index 839c17f..0fc2e07 100644 --- a/src/types.ts +++ b/src/types.ts @@ -5,6 +5,7 @@ export interface SmartAPIQueryResult { } export interface apiListItem { + primarySource?: boolean; id?: string; infores?: string; name: string;