Skip to content

Commit

Permalink
Update dependencies (#578)
Browse files Browse the repository at this point in the history
* update to v6.0.13
* update to v7.15.0
* update imported ES types
  • Loading branch information
yahiakr authored and guumaster committed Mar 16, 2022
1 parent cb7148d commit bf686b2
Show file tree
Hide file tree
Showing 35 changed files with 462 additions and 897 deletions.
1 change: 1 addition & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = {
testTimeout: 10000,
clearMocks: true,
roots: [
'<rootDir>/test'
Expand Down
16 changes: 6 additions & 10 deletions lib/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { MongoosasticDocument } from './types'

export function postSave(doc: MongoosasticDocument): void {
export async function postSave(doc: MongoosasticDocument): Promise<void> {
if (!doc) {
return
}
Expand All @@ -20,15 +20,11 @@ export function postSave(doc: MongoosasticDocument): void {
const populate = options && options.populate
if (doc) {
if (populate && populate.length) {
populate.forEach((populateOpts) => {
doc.populate(populateOpts)
})
doc.execPopulate().then((popDoc) => {
popDoc
.index()
.then((res) => onIndex(null, res))
.catch((err) => onIndex(err, null))
})
const popDoc = await doc.populate(populate)
popDoc
.index()
.then((res) => onIndex(null, res))
.catch((err) => onIndex(err, null))
} else {
doc
.index()
Expand Down
4 changes: 2 additions & 2 deletions lib/search.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ApiResponse } from '@elastic/elasticsearch'
import { Search } from '@elastic/elasticsearch/api/requestParams'
import { QueryContainer, SearchRequest, SearchResponse } from '@elastic/elasticsearch/api/types'
import { QueryDslQueryContainer, SearchRequest, SearchResponse } from '@elastic/elasticsearch/api/types'
import { EsSearchOptions, HydratedSearchResults, MongoosasticDocument, MongoosasticModel } from './types'
import { getIndexName, hydrate, isString, isStringArray, reformatESTotalNumber } from './utils'

export async function search(
this: MongoosasticModel<MongoosasticDocument>,
query: QueryContainer,
query: QueryDslQueryContainer,
opts: EsSearchOptions = {}
): Promise<ApiResponse<SearchResponse, unknown> | ApiResponse<HydratedSearchResults>> {
const fullQuery = {
Expand Down
6 changes: 3 additions & 3 deletions lib/statics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Search } from '@elastic/elasticsearch/api/requestParams'
import { Property, PropertyName, QueryContainer, SearchResponse } from '@elastic/elasticsearch/api/types'
import { MappingProperty, PropertyName, QueryDslQueryContainer, SearchResponse } from '@elastic/elasticsearch/api/types'
import { ApiResponse, RequestBody } from '@elastic/elasticsearch/lib/Transport'
import { EventEmitter } from 'events'
import { FilterQuery } from 'mongoose'
Expand All @@ -12,7 +12,7 @@ import { filterMappingFromMixed, getIndexName, reformatESTotalNumber } from './u
export async function createMapping(
this: MongoosasticModel<MongoosasticDocument>,
body: RequestBody
): Promise<Record<PropertyName, Property>> {
): Promise<Record<PropertyName, MappingProperty>> {
const options = this.esOptions()
const client = this.esClient()

Expand Down Expand Up @@ -184,7 +184,7 @@ export async function refresh(this: MongoosasticModel<MongoosasticDocument>): Pr

export async function esCount(
this: MongoosasticModel<MongoosasticDocument>,
query: QueryContainer
query: QueryDslQueryContainer
): Promise<ApiResponse> {
if (query === undefined) {
query = {
Expand Down
30 changes: 15 additions & 15 deletions lib/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import { ApiResponse, Client, ClientOptions } from '@elastic/elasticsearch'
import {
CountResponse,
Highlight,
Hit,
HitsMetadata,
Property,
IndicesRefreshResponse,
MappingProperty,
MappingTypeMapping,
PropertyName,
QueryContainer,
RefreshResponse,
QueryDslQueryContainer,
SearchHighlight,
SearchHit,
SearchHitsMetadata,
SearchRequest,
SearchResponse,
TypeMapping,
} from '@elastic/elasticsearch/api/types'
import { RequestBody } from '@elastic/elasticsearch/lib/Transport'
import { EventEmitter } from 'events'
Expand All @@ -30,15 +30,15 @@ declare interface RoutingFn {
(doc: Document): any;
}

declare interface GeneratedMapping extends TypeMapping {
declare interface GeneratedMapping extends MappingTypeMapping {
cast?(doc: any): any;
}

declare interface HydratedSearchResults<TDocument = unknown> extends SearchResponse<TDocument> {
hits: HydratedSearchHits<TDocument>;
}

declare interface HydratedSearchHits<TDocument> extends HitsMetadata<TDocument> {
declare interface HydratedSearchHits<TDocument> extends SearchHitsMetadata<TDocument> {
hydrated: Array<TDocument>;
}

Expand Down Expand Up @@ -117,7 +117,7 @@ declare type Options = {

declare type EsSearchOptions = {
aggs?: any;
highlight?: Highlight;
highlight?: SearchHighlight;
hydrate?: boolean;
hydrateOptions?: QueryOptions;
hydrateWithESResults?: any;
Expand All @@ -130,7 +130,7 @@ declare type EsSearchOptions = {

declare interface MongoosasticDocument<TDocument = any> extends Document<TDocument>, EventEmitter {
_highlight?: Record<string, string[]> | undefined;
_esResult?: Hit<TDocument>;
_esResult?: SearchHit<TDocument>;

esClient(): Client;

Expand All @@ -144,11 +144,11 @@ declare interface MongoosasticDocument<TDocument = any> extends Document<TDocume
interface MongoosasticModel<T> extends Model<T> {
bulkError(): EventEmitter;

createMapping(body?: RequestBody): Promise<Record<PropertyName, Property>>;
createMapping(body?: RequestBody): Promise<Record<PropertyName, MappingProperty>>;

esClient(): Client;

esCount(query?: QueryContainer): Promise<ApiResponse<CountResponse>>;
esCount(query?: QueryDslQueryContainer): Promise<ApiResponse<CountResponse>>;

esOptions(): Options;

Expand All @@ -162,9 +162,9 @@ interface MongoosasticModel<T> extends Model<T> {

getMapping(): Record<string, any>;

refresh(): Promise<ApiResponse<RefreshResponse>>;
refresh(): Promise<ApiResponse<IndicesRefreshResponse>>;

search(query: QueryContainer, options?: EsSearchOptions): Promise<ApiResponse<HydratedSearchResults<T>>>;
search(query: QueryDslQueryContainer, options?: EsSearchOptions): Promise<ApiResponse<HydratedSearchResults<T>>>;

synchronize(query?: any, options?: SynchronizeOptions): EventEmitter;
}
Expand Down
8 changes: 4 additions & 4 deletions lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiResponse } from '@elastic/elasticsearch'
import { Property, PropertyName, SearchResponse, TotalHits } from '@elastic/elasticsearch/api/types'
import { MappingProperty, PropertyName, SearchResponse, SearchTotalHits } from '@elastic/elasticsearch/api/types'
import { isEmpty } from 'lodash'
import {
DeleteByIdOptions,
Expand Down Expand Up @@ -28,8 +28,8 @@ export function getIndexName(doc: MongoosasticDocument | MongoosasticModel<Mongo
}
}

export function filterMappingFromMixed(props: Record<PropertyName, Property>): Record<PropertyName, Property> {
const filteredMapping: Record<PropertyName, Property> = {}
export function filterMappingFromMixed(props: Record<PropertyName, MappingProperty>): Record<PropertyName, MappingProperty> {
const filteredMapping: Record<PropertyName, MappingProperty> = {}
Object.keys(props).map((key) => {
const field = props[key]
if (field.type !== 'mixed') {
Expand Down Expand Up @@ -103,7 +103,7 @@ export function reformatESTotalNumber<T = unknown>(
res: ApiResponse<SearchResponse<T>>
): ApiResponse<SearchResponse<T>> {
Object.assign(res.body.hits, {
total: (res.body.hits.total as TotalHits).value,
total: (res.body.hits.total as SearchTotalHits).value,
extTotal: res.body.hits.total,
})
return res
Expand Down

0 comments on commit bf686b2

Please sign in to comment.