Skip to content

Commit

Permalink
Add function to call OpenSearch api file from user.
Browse files Browse the repository at this point in the history
OpenSearch API is called from both sandbox and deploy.end
  • Loading branch information
ronitagarwala01 committed Dec 4, 2023
1 parent be7c145 commit f5e59c1
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { exists } from './paths'
import { join } from 'path'
import { pathToFileURL } from 'url'
import { launch } from './run.js'
import type { LocalSearch } from './run.js'
import { populate } from './data.js'
Expand Down Expand Up @@ -39,6 +42,25 @@ function getConfig(arc: {
else return {}
}

const openSearchApiFile = 'openSearchApi.js'

async function executeSearchRequests(cwd: string) {
//Load api call file and run all api calls to cluster
const apiPath = join(cwd, openSearchApiFile)
let result
if (await exists(apiPath)) {
console.log(`Found ${openSearchApiFile} file, running api calls...`)
result = (await import(pathToFileURL(apiPath).toString())).default

// result should be a function that returns a promise
if (typeof result === 'function') {
result = result()
}

await result
}
}

export const deploy = {
// @ts-expect-error: The Architect plugins API has no type definitions.
start({ cloudformation, inventory, arc, stage }) {
Expand All @@ -64,6 +86,10 @@ export const deploy = {
return serverlessServices
}
},
// @ts-expect-error: The Architect plugins API has no type definitions.
async end({ inventory }) {
executeSearchRequests(inventory.inv._project.cwd)
},
}

let local: LocalSearch
Expand All @@ -86,8 +112,10 @@ export const sandbox = {
}) {
const engine = getEngine(getConfig(arc).sandboxEngine)
local = await launch({ engine })
await executeSearchRequests(cwd)
await populate(cwd, { node: local.url })
},

async end() {
await local.stop()
},
Expand Down

0 comments on commit f5e59c1

Please sign in to comment.