-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* extension-improvements override addFunctions method of NetlifyExtension class * extension-improvements add empty default for appName * extension-improvements add slack auth token to dbconfig * extension-improvements updating configurations, types
- Loading branch information
1 parent
7951c42
commit 78ae0c0
Showing
11 changed files
with
150 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import * as mongodb from 'mongodb'; | ||
|
||
export const teardown = async (client: mongodb.MongoClient): Promise<void> => { | ||
await client.close(); | ||
}; | ||
|
||
// Handles memoization of db object, and initial connection logic if needs to be initialized | ||
export const dbClient = async ({ | ||
uri, | ||
appName, | ||
}: { uri: string; appName: string }): Promise<mongodb.MongoClient> => { | ||
const client = new mongodb.MongoClient(uri, { appName }); | ||
try { | ||
await client.connect(); | ||
return client; | ||
} catch (error) { | ||
throw new Error(`Error at client connection: ${error} `); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import type * as mongodb from 'mongodb'; | ||
import { getPoolDb } from './atlasClusterConnector'; | ||
import { getPoolDb } from './clusterZeroConnector'; | ||
import type { DocsetsDocument } from './types'; | ||
|
||
export const getDocsetsCollection = async ({ | ||
URI, | ||
clusterZeroURI, | ||
databaseName, | ||
collectionName, | ||
extensionName, | ||
}: { | ||
URI: string; | ||
clusterZeroURI: string; | ||
databaseName: string; | ||
collectionName: string; | ||
extensionName: string; | ||
extensionName?: string; | ||
}): Promise<mongodb.Collection<DocsetsDocument>> => { | ||
const dbSession = await getPoolDb({ | ||
URI, | ||
clusterZeroURI, | ||
databaseName, | ||
appName: extensionName, | ||
appName: extensionName ?? '', | ||
}); | ||
return dbSession.collection<DocsetsDocument>(collectionName); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
import type * as mongodb from 'mongodb'; | ||
import { getPoolDb } from './atlasClusterConnector'; | ||
import { getPoolDb } from './clusterZeroConnector'; | ||
import type { ReposBranchesDocument } from './types'; | ||
|
||
export const getReposBranchesCollection = async ({ | ||
URI, | ||
clusterZeroURI, | ||
databaseName, | ||
collectionName, | ||
extensionName, | ||
}: { | ||
URI: string; | ||
clusterZeroURI: string; | ||
databaseName: string; | ||
collectionName: string; | ||
extensionName: string; | ||
extensionName?: string; | ||
}): Promise<mongodb.Collection<ReposBranchesDocument>> => { | ||
const dbSession = await getPoolDb({ | ||
URI, | ||
clusterZeroURI, | ||
databaseName, | ||
appName: extensionName, | ||
appName: extensionName ?? '', | ||
}); | ||
return dbSession.collection<ReposBranchesDocument>(collectionName); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,22 @@ | ||
import type * as mongodb from 'mongodb'; | ||
import { getSearchDb } from './atlasClusterConnector'; | ||
|
||
export interface SearchDocument { | ||
url: string; | ||
slug: string; | ||
lastModified: Date; | ||
manifestRevisionId: string; | ||
searchProperty: Array<string>; | ||
includeInGlobalSearch: boolean; | ||
} | ||
import { getSearchDb } from './searchClusterConnector'; | ||
import type { SearchDocument } from './types'; | ||
|
||
export const getDocumentsCollection = async ({ | ||
URI, | ||
searchURI, | ||
databaseName, | ||
collectionName, | ||
extensionName, | ||
}: { | ||
URI: string; | ||
searchURI: string; | ||
databaseName: string; | ||
collectionName: string; | ||
extensionName: string; | ||
extensionName?: string; | ||
}): Promise<mongodb.Collection<SearchDocument>> => { | ||
const dbSession = await getSearchDb({ | ||
URI, | ||
searchURI, | ||
databaseName, | ||
appName: extensionName, | ||
appName: extensionName ?? '', | ||
}); | ||
return dbSession.collection<SearchDocument>(collectionName); | ||
}; |
27 changes: 27 additions & 0 deletions
27
libs/util/src/databaseConnection/searchClusterConnector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import type * as mongodb from 'mongodb'; | ||
import { teardown, dbClient } from './clusterConnector'; | ||
|
||
let searchClusterClient: mongodb.MongoClient; | ||
|
||
export const getSearchDb = async ({ | ||
searchURI, | ||
databaseName, | ||
appName, | ||
}: { | ||
searchURI: string; | ||
databaseName: string; | ||
appName: string; | ||
}): Promise<mongodb.Db> => { | ||
if (!searchClusterClient) { | ||
console.info('Creating new instance of Cluster Zero client'); | ||
searchClusterClient = await dbClient({ uri: searchURI, appName }); | ||
} | ||
return searchClusterClient.db(databaseName); | ||
}; | ||
|
||
export const closeSearchDb = async () => { | ||
if (searchClusterClient) await teardown(searchClusterClient); | ||
else { | ||
console.info('No client connection open to Search Cluster client'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.