@ferlab/next
Advanced tools
Comparing version 0.0.14 to 0.0.15
@@ -38,2 +38,8 @@ import { Client } from '@opensearch-project/opensearch'; | ||
}; | ||
export declare const getESAliases: (esClient: any) => Promise<any>; | ||
export declare const checkESAlias: (aliases: any, possibleAlias: any) => any; | ||
export declare const getEsMappingProperties: ({ esIndex, esClient, }: { | ||
esIndex: string; | ||
esClient: Client; | ||
}) => Promise<EsMapping>; | ||
export declare const getEsMapping: ({ esIndex, esClient, }: { | ||
@@ -40,0 +46,0 @@ esIndex: string; |
@@ -30,2 +30,14 @@ export const getBody = ({ field, value, path, nested = false }) => { | ||
}; | ||
export const getESAliases = async (esClient) => { | ||
const { body } = await esClient.cat.aliases({ format: 'json' }); | ||
return body; | ||
}; | ||
export const checkESAlias = (aliases, possibleAlias) => aliases?.find((foundIndex = { alias: undefined }) => foundIndex.alias === possibleAlias)?.index; | ||
export const getEsMappingProperties = async ({ esIndex, esClient, }) => { | ||
const aliases = await getESAliases(esClient); | ||
const alias = checkESAlias(aliases, esIndex); | ||
const response = await esClient.indices.getMapping({ index: alias }); | ||
const mappingProperties = response?.body?.[alias]?.mappings.properties; | ||
return mappingProperties; | ||
}; | ||
export const getEsMapping = async ({ esIndex, esClient, }) => { | ||
@@ -32,0 +44,0 @@ const response = await esClient.indices.getMapping({ index: esIndex }); |
import flattenDeep from 'lodash/flattenDeep'; | ||
import { getEsMapping } from '#src/elasticsearch/utils'; | ||
import { getEsMappingProperties } from '#src/elasticsearch/utils'; | ||
export const toQuery = (field = '') => field | ||
@@ -68,8 +68,4 @@ .split('.') | ||
export const createColumnSetState = async ({ graphqlField = '', esIndex = '', esClient, }) => { | ||
const rawEsmapping = await getEsMapping({ | ||
esIndex, | ||
esClient, | ||
}); | ||
const mapping = rawEsmapping[Object.keys(rawEsmapping)[0]].mappings; | ||
const columns = mappingToColumnsState(mapping.properties); | ||
const esMappingProperties = await getEsMappingProperties({ esIndex, esClient }); | ||
const columns = mappingToColumnsState(esMappingProperties); | ||
return { | ||
@@ -76,0 +72,0 @@ state: { |
import { ExtendedConfigsInterface, FacetsConfigsInterface, FieldFromMapping, I_ExtendedMappingSetFieldInput, TableConfigsInterface } from '../types'; | ||
export declare const getExtendedFields: ({ mapping, extendedMapping }: { | ||
mapping: any; | ||
extendedMapping: any; | ||
}) => Promise<{ | ||
export declare const getExtendedFields: (context: any, index: string) => Promise<{ | ||
displayName: string; | ||
@@ -7,0 +4,0 @@ displayValues: any; |
import startCase from 'lodash/startCase'; | ||
import { getEsMappingProperties } from '../../elasticsearch/utils'; | ||
import { ConfigProperties, } from '../types'; | ||
import flattenMapping from './flattenMapping'; | ||
export const getExtendedFields = async ({ mapping, extendedMapping }) => { | ||
export const getExtendedFields = async (context, index) => { | ||
try { | ||
const fieldsFromMapping = await flattenMappingToFields(mapping); | ||
const { getExtendedMappingByIndex, getESIndexByIndex, esClient } = context; | ||
const extendedMapping = getExtendedMappingByIndex(index); | ||
const esIndex = getESIndexByIndex(index); | ||
const esMappingProperties = await getEsMappingProperties({ esClient, esIndex }); | ||
const fieldsFromMapping = await flattenMappingToFields(esMappingProperties); | ||
return extendFields(fieldsFromMapping, extendedMapping); | ||
@@ -8,0 +13,0 @@ } |
import flattenDeep from 'lodash/flattenDeep'; | ||
const joinWith = (s = '.') => (x) => x ? x + s : ''; | ||
const flattenMapping = (properties, parent = '') => flattenDeep(Object.entries(properties).map(([field, data]) => | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
!data.properties | ||
const flattenMapping = (properties, parent = '') => flattenDeep(Object.entries(properties).map(([field, data]) => !data.properties | ||
? { | ||
field: joinWith()(parent) + field, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
type: data.type, | ||
@@ -16,8 +11,4 @@ } | ||
field: joinWith()(parent) + field, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
type: data.type || 'object', | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
...flattenMapping(data.properties, joinWith()(parent) + field), | ||
@@ -24,0 +15,0 @@ ])); |
import { Client } from '@opensearch-project/opensearch'; | ||
import { GraphQLResolveInfo } from 'graphql'; | ||
import { GraphQLResolveInfo, GraphQLSchema } from 'graphql'; | ||
export interface IQueryContext { | ||
es: Client; | ||
auth: any; | ||
schema: GraphQLSchema; | ||
esClient: Client; | ||
getExtendedMappingByIndex: (graphqlIndex: string) => I_ExtendedMappingSetFieldInput[]; | ||
getESIndexByIndex: (graphqlIndex: string) => string; | ||
MAX_DOWNLOAD_ROWS: number; | ||
ALLOW_CUSTOM_MAX_DOWNLOAD_ROWS: boolean; | ||
} | ||
export type ResolverOutput<T> = T | Promise<T>; | ||
export interface EsIndexLocation { | ||
esIndex: string; | ||
} | ||
export type Resolver<Output, Args = any> = ((a: any, args: Args, c: IQueryContext, d: GraphQLResolveInfo & { | ||
@@ -11,0 +14,0 @@ mergeInfo: any; |
@@ -7,3 +7,2 @@ import { format, isValid, parseISO } from 'date-fns'; | ||
import through2 from 'through2'; | ||
import { getEsMapping } from '#src/elasticsearch/utils'; | ||
import { getExtendedFields } from '../mapping/extendMapping'; | ||
@@ -264,7 +263,3 @@ const STANDARD_DATE = 'yyyy-MM-dd'; | ||
let chunkCounts = 0; | ||
const { getExtendedMappingByIndex, getESIndexByIndex, esClient } = context; | ||
const extendedMapping = getExtendedMappingByIndex(index); | ||
const esIndex = getESIndexByIndex(index); | ||
const mapping = await getEsMapping({ esIndex, esClient }); | ||
const extendedFields = await getExtendedFields({ extendedMapping, mapping }); | ||
const extendedFields = await getExtendedFields(context, index); | ||
const extendedFieldsDict = extendedFields?.reduce?.((acc, { field, ...extendedField }) => ({ | ||
@@ -271,0 +266,0 @@ ...acc, |
import { PassThrough } from 'stream'; | ||
import { getEsMapping } from '#src/elasticsearch/utils'; | ||
import runQuery from '../../graphql/runQuery'; | ||
@@ -22,7 +21,5 @@ import buildQuery from '../buildQuery'; | ||
const getAllData = async ({ chunkSize = DOWNLOAD_STREAM_BUFFER_SIZE, context, maxRows, sort = [], sqon, index }) => { | ||
const { getExtendedMappingByIndex, getESIndexByIndex, esClient, schema } = context; | ||
const extendedMapping = getExtendedMappingByIndex(index); | ||
const { esClient, schema, getESIndexByIndex } = context; | ||
const esIndex = getESIndexByIndex(index); | ||
const mapping = await getEsMapping({ esIndex, esClient }); | ||
const extendedFields = await getExtendedFields({ extendedMapping, mapping }); | ||
const extendedFields = await getExtendedFields(context, index); | ||
const stream = new PassThrough({ objectMode: true }); | ||
@@ -33,4 +30,2 @@ //todo: check if _id is still present for the concat | ||
const esSort = sort.map(({ field, order }) => ({ [field]: order })).concat({ _id: 'asc' }); | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment | ||
// @ts-ignore | ||
const nestedFieldNames = extendedFields.filter(({ type }) => type === 'nested').map(({ field }) => field); | ||
@@ -37,0 +32,0 @@ const query = buildQuery({ nestedFieldNames, filters: sqon }); |
{ | ||
"name": "@ferlab/next", | ||
"version": "0.0.14", | ||
"version": "0.0.15", | ||
"description": "Shared library for our wrappers GraphQL APIs", | ||
@@ -12,3 +12,5 @@ "main": "lib/index.js", | ||
"typings": "index.d.ts", | ||
"files": ["lib"], | ||
"files": [ | ||
"lib" | ||
], | ||
"imports": { | ||
@@ -15,0 +17,0 @@ "#src/*": "./lib/*" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
521611