diff --git a/package.json b/package.json index 810457b..ce8210e 100644 --- a/package.json +++ b/package.json @@ -43,9 +43,9 @@ "@babel/preset-typescript": "^7.23.2", "@types/debug": "^4.1.10", "@types/express": "^4.17.20", - "@types/node": "^14.18.63", "@types/jest": "^26.0.24", "@types/lodash": "^4.14.200", + "@types/node": "^14.18.63", "@typescript-eslint/eslint-plugin": "^6.8.0", "@typescript-eslint/parser": "^6.8.0", "babel-loader": "^8.3.0", @@ -71,9 +71,9 @@ }, "dependencies": { "@babel/runtime": "^7.23.2", + "@biothings-explorer/utils": "workspace:../utils", "@commitlint/cli": "^17.8.1", "@commitlint/config-conventional": "^11.0.0", - "@biothings-explorer/utils": "workspace:../utils", "axios": "^0.21.4", "camelcase": "^6.3.0", "core-js": "^3.33.1", diff --git a/src/config.ts b/src/config.ts index eabb585..358135c 100644 --- a/src/config.ts +++ b/src/config.ts @@ -20,10 +20,10 @@ export const FILTER_FIELDS: FIELDS_FOR_FILTER[] = [ export const SMARTAPI_URL = "https://smart-api.info/api/query?q=tags.name:translator&size=1000&fields=paths,servers,tags,components.x-bte*,info,_meta"; -export const SINGLE_API_SMARTAPI_QUERY_TEMPLATE = "https://smart-api.info/api/metadata/{smartapi_id}"; +export const SINGLE_API_SMARTAPI_QUERY_TEMPLATE = "https://smart-api.info/api/metadata/{smartAPIID}"; export const TEAM_SMARTAPI_QUERY_TEMPLATE = - 'https://smart-api.info/api/query?q=info.x-translator.team:"{team_name}"&size=1000&fields=paths,servers,tags,components.x-bte*,info,_meta'; + 'https://smart-api.info/api/query?q=info.x-translator.team:"{teamName}"&size=1000&fields=paths,servers,tags,components.x-bte*,info,_meta'; export const COMPONENT_SMARTAPI_QUERY_TEMPLATE = 'https://smart-api.info/api/query?q=info.x-translator.component:"{component_name}"&size=1000&fields=paths,servers,tags,components.x-bte*,info,_meta'; diff --git a/src/index.ts b/src/index.ts index 999ebeb..62815e8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,6 +6,7 @@ import { ft } from "./filter"; import path from "path"; import Debug from "debug"; import QueryOperationObject from "./parser/query_operation"; +import { lockWithActionAsync } from "@biothings-explorer/utils"; const debug = Debug("bte:smartapi-kg:MetaKG"); export * from "./types"; @@ -66,6 +67,18 @@ export default class MetaKG { return this.ops; } + /* Async wrapper for using constructMetaKGSync to enable using async file locking */ + async constructMetaKGWithFileLock(includeReasoner = false, options: BuilderOptions = {}): Promise { + this._ops = await lockWithActionAsync( + [this._file_path, this._predicates_path], + async () => { + return syncBuilderFactory(options, includeReasoner, this._file_path, this._predicates_path); + }, + debug + ); + return this.ops; + } + /** * Filters the whole meta kg based on apiList, teamName, tag or component * @param {Object} options - filtering options diff --git a/src/load/single_spec_async_loader.ts b/src/load/single_spec_async_loader.ts index 34110b3..d13e4df 100644 --- a/src/load/single_spec_async_loader.ts +++ b/src/load/single_spec_async_loader.ts @@ -4,9 +4,9 @@ import { SmartAPISpec } from "../parser/types"; export default class SingleSpecAsyncLoader extends BaseAsyncLoader { private _smartapi_id: string; - constructor(smartapiID: string) { - super(SINGLE_API_SMARTAPI_QUERY_TEMPLATE.replace("{smartapi_id}", smartapiID)); - this._smartapi_id = smartapiID; + constructor(smartAPIID: string) { + super(SINGLE_API_SMARTAPI_QUERY_TEMPLATE.replace("{smartAPIID}", smartAPIID)); + this._smartapi_id = smartAPIID; } protected async fetch(): Promise { diff --git a/src/load/team_specs_async_loader.ts b/src/load/team_specs_async_loader.ts index cc44cbe..d78d562 100644 --- a/src/load/team_specs_async_loader.ts +++ b/src/load/team_specs_async_loader.ts @@ -5,7 +5,7 @@ import { SmartAPISpec } from "../parser/types"; export default class TeamSpecsAsyncLoader extends BaseAsyncLoader { constructor(teamName: string) { - super(TEAM_SMARTAPI_QUERY_TEMPLATE.replace("{team_name}", teamName)); + super(TEAM_SMARTAPI_QUERY_TEMPLATE.replace("{teamName}", teamName)); } protected async fetch(): Promise {