@deenruv/elasticsearch-plugin 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +122 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +20 -0
- package/lib/index.js.map +1 -0
- package/lib/src/api/api-extensions.d.ts +3 -0
- package/lib/src/api/api-extensions.js +148 -0
- package/lib/src/api/api-extensions.js.map +1 -0
- package/lib/src/api/custom-mappings.resolver.d.ts +12 -0
- package/lib/src/api/custom-mappings.resolver.js +47 -0
- package/lib/src/api/custom-mappings.resolver.js.map +1 -0
- package/lib/src/api/custom-script-fields.resolver.d.ts +12 -0
- package/lib/src/api/custom-script-fields.resolver.js +50 -0
- package/lib/src/api/custom-script-fields.resolver.js.map +1 -0
- package/lib/src/api/elasticsearch-resolver.d.ts +34 -0
- package/lib/src/api/elasticsearch-resolver.js +150 -0
- package/lib/src/api/elasticsearch-resolver.js.map +1 -0
- package/lib/src/build-elastic-body.d.ts +8 -0
- package/lib/src/build-elastic-body.js +173 -0
- package/lib/src/build-elastic-body.js.map +1 -0
- package/lib/src/constants.d.ts +3 -0
- package/lib/src/constants.js +7 -0
- package/lib/src/constants.js.map +1 -0
- package/lib/src/elasticsearch.health.d.ts +9 -0
- package/lib/src/elasticsearch.health.js +52 -0
- package/lib/src/elasticsearch.health.js.map +1 -0
- package/lib/src/elasticsearch.service.d.ts +56 -0
- package/lib/src/elasticsearch.service.js +469 -0
- package/lib/src/elasticsearch.service.js.map +1 -0
- package/lib/src/indexing/elasticsearch-index.service.d.ts +24 -0
- package/lib/src/indexing/elasticsearch-index.service.js +163 -0
- package/lib/src/indexing/elasticsearch-index.service.js.map +1 -0
- package/lib/src/indexing/indexer.controller.d.ts +98 -0
- package/lib/src/indexing/indexer.controller.js +790 -0
- package/lib/src/indexing/indexer.controller.js.map +1 -0
- package/lib/src/indexing/indexing-utils.d.ts +8 -0
- package/lib/src/indexing/indexing-utils.js +109 -0
- package/lib/src/indexing/indexing-utils.js.map +1 -0
- package/lib/src/options.d.ts +695 -0
- package/lib/src/options.js +59 -0
- package/lib/src/options.js.map +1 -0
- package/lib/src/plugin.d.ts +192 -0
- package/lib/src/plugin.js +371 -0
- package/lib/src/plugin.js.map +1 -0
- package/lib/src/types.d.ts +262 -0
- package/lib/src/types.js +17 -0
- package/lib/src/types.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { Coordinate, CurrencyCode, LanguageCode, PriceRange, SearchInput, SearchResponse, SearchResult } from "@deenruv/common/lib/generated-types";
|
|
2
|
+
import { ID, JsonCompatible } from "@deenruv/common/lib/shared-types";
|
|
3
|
+
import { Asset, SerializedRequestContext } from "@deenruv/core";
|
|
4
|
+
export type ElasticSearchResult = SearchResult & {
|
|
5
|
+
inStock: boolean;
|
|
6
|
+
};
|
|
7
|
+
export type ElasticSearchInput = SearchInput & {
|
|
8
|
+
priceRange?: PriceRange;
|
|
9
|
+
priceRangeWithTax?: PriceRange;
|
|
10
|
+
inStock?: boolean;
|
|
11
|
+
[extendedInputField: string]: any;
|
|
12
|
+
};
|
|
13
|
+
export type ElasticSearchResponse = SearchResponse & {
|
|
14
|
+
priceRange: SearchPriceData;
|
|
15
|
+
items: ElasticSearchResult[];
|
|
16
|
+
};
|
|
17
|
+
export type SearchPriceData = {
|
|
18
|
+
range: PriceRange;
|
|
19
|
+
rangeWithTax: PriceRange;
|
|
20
|
+
buckets: PriceRangeBucket[];
|
|
21
|
+
bucketsWithTax: PriceRangeBucket[];
|
|
22
|
+
};
|
|
23
|
+
export type PriceRangeBucket = {
|
|
24
|
+
to: number;
|
|
25
|
+
count: number;
|
|
26
|
+
};
|
|
27
|
+
export declare enum ElasticSearchSortMode {
|
|
28
|
+
/** Pick the lowest value */
|
|
29
|
+
MIN = "min",
|
|
30
|
+
/** Pick the highest value */
|
|
31
|
+
MAX = "max",
|
|
32
|
+
/** Use the sum of all values as sort value. Only applicable for number based array fields */
|
|
33
|
+
SUM = "sum",
|
|
34
|
+
/** Use the average of all values as sort value. Only applicable for number based array fields */
|
|
35
|
+
AVG = "avg",
|
|
36
|
+
/** Use the median of all values as sort value. Only applicable for number based array fields */
|
|
37
|
+
MEDIAN = "median"
|
|
38
|
+
}
|
|
39
|
+
export type ElasticSearchSortParameter = {
|
|
40
|
+
missing?: "_last" | "_first" | string;
|
|
41
|
+
mode?: ElasticSearchSortMode;
|
|
42
|
+
order: "asc" | "desc";
|
|
43
|
+
} & {
|
|
44
|
+
[key: string]: any;
|
|
45
|
+
};
|
|
46
|
+
export type ElasticSearchSortInput = Array<{
|
|
47
|
+
[key: string]: ElasticSearchSortParameter;
|
|
48
|
+
}>;
|
|
49
|
+
export type IndexItemAssets = {
|
|
50
|
+
productAssetId: ID | undefined;
|
|
51
|
+
productPreview: string;
|
|
52
|
+
productPreviewFocalPoint: Coordinate | undefined;
|
|
53
|
+
productVariantAssetId: ID | undefined;
|
|
54
|
+
productVariantPreview: string;
|
|
55
|
+
productVariantPreviewFocalPoint: Coordinate | undefined;
|
|
56
|
+
};
|
|
57
|
+
export type VariantIndexItem = Omit<SearchResult, "score" | "price" | "priceWithTax" | "productAsset" | "productVariantAsset"> & IndexItemAssets & {
|
|
58
|
+
channelId: ID;
|
|
59
|
+
languageCode: LanguageCode;
|
|
60
|
+
price: number;
|
|
61
|
+
priceWithTax: number;
|
|
62
|
+
collectionSlugs: string[];
|
|
63
|
+
productEnabled: boolean;
|
|
64
|
+
productPriceMin: number;
|
|
65
|
+
productPriceMax: number;
|
|
66
|
+
productPriceWithTaxMin: number;
|
|
67
|
+
productPriceWithTaxMax: number;
|
|
68
|
+
productFacetIds: ID[];
|
|
69
|
+
productFacetValueIds: ID[];
|
|
70
|
+
productCollectionIds: ID[];
|
|
71
|
+
productCollectionSlugs: string[];
|
|
72
|
+
productChannelIds: ID[];
|
|
73
|
+
[customMapping: string]: any;
|
|
74
|
+
inStock: boolean;
|
|
75
|
+
productInStock: boolean;
|
|
76
|
+
};
|
|
77
|
+
export type ProductIndexItem = IndexItemAssets & {
|
|
78
|
+
sku: string;
|
|
79
|
+
slug: string;
|
|
80
|
+
productId: ID;
|
|
81
|
+
channelId: ID;
|
|
82
|
+
languageCode: LanguageCode;
|
|
83
|
+
productName: string;
|
|
84
|
+
productVariantId: ID;
|
|
85
|
+
productVariantName: string;
|
|
86
|
+
currencyCode: CurrencyCode;
|
|
87
|
+
description: string;
|
|
88
|
+
facetIds: ID[];
|
|
89
|
+
facetValueIds: ID[];
|
|
90
|
+
collectionIds: ID[];
|
|
91
|
+
collectionSlugs: string[];
|
|
92
|
+
channelIds: ID[];
|
|
93
|
+
enabled: boolean;
|
|
94
|
+
productEnabled: boolean;
|
|
95
|
+
priceMin: number;
|
|
96
|
+
priceMax: number;
|
|
97
|
+
priceWithTaxMin: number;
|
|
98
|
+
priceWithTaxMax: number;
|
|
99
|
+
[customMapping: string]: any;
|
|
100
|
+
};
|
|
101
|
+
export type SearchHit<T> = {
|
|
102
|
+
_id: string;
|
|
103
|
+
_index: string;
|
|
104
|
+
_score: number;
|
|
105
|
+
_source: T;
|
|
106
|
+
_type: string;
|
|
107
|
+
fields?: any;
|
|
108
|
+
};
|
|
109
|
+
export type SearchRequestBody = {
|
|
110
|
+
query?: any;
|
|
111
|
+
sort?: any[];
|
|
112
|
+
from?: number;
|
|
113
|
+
size?: number;
|
|
114
|
+
track_total_hits?: number | boolean;
|
|
115
|
+
aggs?: any;
|
|
116
|
+
collapse?: any;
|
|
117
|
+
_source?: boolean;
|
|
118
|
+
script_fields?: any;
|
|
119
|
+
};
|
|
120
|
+
export type SearchResponseBody<T = any> = {
|
|
121
|
+
hits: {
|
|
122
|
+
hits: Array<SearchHit<T>>;
|
|
123
|
+
total: {
|
|
124
|
+
relation: string;
|
|
125
|
+
value: number;
|
|
126
|
+
};
|
|
127
|
+
max_score: number;
|
|
128
|
+
};
|
|
129
|
+
timed_out: boolean;
|
|
130
|
+
took: number;
|
|
131
|
+
_shards: {
|
|
132
|
+
failed: number;
|
|
133
|
+
skipped: number;
|
|
134
|
+
successful: number;
|
|
135
|
+
total: number;
|
|
136
|
+
};
|
|
137
|
+
aggregations?: {
|
|
138
|
+
[key: string]: {
|
|
139
|
+
doc_count_error_upper_bound: 0;
|
|
140
|
+
sum_other_doc_count: 89;
|
|
141
|
+
buckets: Array<{
|
|
142
|
+
key: string;
|
|
143
|
+
doc_count: number;
|
|
144
|
+
total: {
|
|
145
|
+
value: number;
|
|
146
|
+
};
|
|
147
|
+
}>;
|
|
148
|
+
value: any;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
export type BulkOperationType = "index" | "update" | "delete";
|
|
153
|
+
export type BulkOperation = {
|
|
154
|
+
[operation in BulkOperationType]?: {
|
|
155
|
+
_id: string;
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
export type BulkOperationDoc<T> = T | {
|
|
159
|
+
doc: T;
|
|
160
|
+
doc_as_upsert?: boolean;
|
|
161
|
+
};
|
|
162
|
+
export type BulkResponseResult = {
|
|
163
|
+
[operation in BulkOperationType]?: {
|
|
164
|
+
_index: string;
|
|
165
|
+
_type: string;
|
|
166
|
+
_id: string;
|
|
167
|
+
_version?: number;
|
|
168
|
+
result?: string;
|
|
169
|
+
_shards: {
|
|
170
|
+
total: number;
|
|
171
|
+
successful: number;
|
|
172
|
+
failed: number;
|
|
173
|
+
};
|
|
174
|
+
status: number;
|
|
175
|
+
_seq_no?: number;
|
|
176
|
+
_primary_term?: number;
|
|
177
|
+
error?: any;
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
export type BulkResponseBody = {
|
|
181
|
+
took: number;
|
|
182
|
+
errors: boolean;
|
|
183
|
+
items: BulkResponseResult[];
|
|
184
|
+
};
|
|
185
|
+
export interface ReindexMessageResponse {
|
|
186
|
+
total: number;
|
|
187
|
+
completed: number;
|
|
188
|
+
duration: number;
|
|
189
|
+
}
|
|
190
|
+
export type ReindexMessageData = {
|
|
191
|
+
ctx: SerializedRequestContext;
|
|
192
|
+
};
|
|
193
|
+
export type UpdateProductMessageData = {
|
|
194
|
+
ctx: SerializedRequestContext;
|
|
195
|
+
productId: ID;
|
|
196
|
+
};
|
|
197
|
+
export type UpdateVariantMessageData = {
|
|
198
|
+
ctx: SerializedRequestContext;
|
|
199
|
+
variantIds: ID[];
|
|
200
|
+
};
|
|
201
|
+
export interface UpdateVariantsByIdMessageData {
|
|
202
|
+
ctx: SerializedRequestContext;
|
|
203
|
+
ids: ID[];
|
|
204
|
+
}
|
|
205
|
+
export interface ProductChannelMessageData {
|
|
206
|
+
ctx: SerializedRequestContext;
|
|
207
|
+
productId: ID;
|
|
208
|
+
channelId: ID;
|
|
209
|
+
}
|
|
210
|
+
export type VariantChannelMessageData = {
|
|
211
|
+
ctx: SerializedRequestContext;
|
|
212
|
+
productVariantId: ID;
|
|
213
|
+
channelId: ID;
|
|
214
|
+
};
|
|
215
|
+
export interface UpdateAssetMessageData {
|
|
216
|
+
ctx: SerializedRequestContext;
|
|
217
|
+
asset: JsonCompatible<Required<Asset>>;
|
|
218
|
+
}
|
|
219
|
+
type Maybe<T> = T | undefined;
|
|
220
|
+
type NamedJobData<Type extends string, MessageData> = {
|
|
221
|
+
type: Type;
|
|
222
|
+
} & MessageData;
|
|
223
|
+
export type ReindexJobData = NamedJobData<"reindex", ReindexMessageData>;
|
|
224
|
+
type UpdateProductJobData = NamedJobData<"update-product", UpdateProductMessageData>;
|
|
225
|
+
type UpdateVariantsJobData = NamedJobData<"update-variants", UpdateVariantMessageData>;
|
|
226
|
+
type DeleteProductJobData = NamedJobData<"delete-product", UpdateProductMessageData>;
|
|
227
|
+
type DeleteVariantJobData = NamedJobData<"delete-variant", UpdateVariantMessageData>;
|
|
228
|
+
type UpdateVariantsByIdJobData = NamedJobData<"update-variants-by-id", UpdateVariantsByIdMessageData>;
|
|
229
|
+
type UpdateAssetJobData = NamedJobData<"update-asset", UpdateAssetMessageData>;
|
|
230
|
+
type DeleteAssetJobData = NamedJobData<"delete-asset", UpdateAssetMessageData>;
|
|
231
|
+
type AssignProductToChannelJobData = NamedJobData<"assign-product-to-channel", ProductChannelMessageData>;
|
|
232
|
+
type RemoveProductFromChannelJobData = NamedJobData<"remove-product-from-channel", ProductChannelMessageData>;
|
|
233
|
+
type AssignVariantToChannelJobData = NamedJobData<"assign-variant-to-channel", VariantChannelMessageData>;
|
|
234
|
+
type RemoveVariantFromChannelJobData = NamedJobData<"remove-variant-from-channel", VariantChannelMessageData>;
|
|
235
|
+
export type UpdateIndexQueueJobData = ReindexJobData | UpdateProductJobData | UpdateVariantsJobData | DeleteProductJobData | DeleteVariantJobData | UpdateVariantsByIdJobData | UpdateAssetJobData | DeleteAssetJobData | AssignProductToChannelJobData | RemoveProductFromChannelJobData | AssignVariantToChannelJobData | RemoveVariantFromChannelJobData;
|
|
236
|
+
export type GraphQlPrimitive = "ID" | "String" | "Int" | "Float" | "Boolean";
|
|
237
|
+
export type PrimitiveTypeVariations<T extends GraphQlPrimitive> = T | `${T}!` | `[${T}!]` | `[${T}!]!`;
|
|
238
|
+
type GraphQlPermittedReturnType = PrimitiveTypeVariations<GraphQlPrimitive>;
|
|
239
|
+
type CustomMappingDefinition<Args extends any[], T extends GraphQlPermittedReturnType, R> = {
|
|
240
|
+
graphQlType: T;
|
|
241
|
+
public?: boolean;
|
|
242
|
+
valueFn: (...args: Args) => Promise<R> | R;
|
|
243
|
+
};
|
|
244
|
+
type TypeVariationMap<GqlType extends GraphQlPrimitive, TsType> = {
|
|
245
|
+
[Key in PrimitiveTypeVariations<GqlType>]: Key extends `[${string}!]!` ? TsType[] : Key extends `[${string}!]` ? Maybe<TsType[]> : Key extends `${string}!` ? TsType : Maybe<TsType>;
|
|
246
|
+
};
|
|
247
|
+
type GraphQlTypeMap = TypeVariationMap<"ID", ID> & TypeVariationMap<"String", string> & TypeVariationMap<"Int", number> & TypeVariationMap<"Float", number> & TypeVariationMap<"Boolean", boolean>;
|
|
248
|
+
export type CustomMapping<Args extends any[]> = {
|
|
249
|
+
[Type in GraphQlPermittedReturnType]: CustomMappingDefinition<Args, Type, GraphQlTypeMap[Type]>;
|
|
250
|
+
}[GraphQlPermittedReturnType];
|
|
251
|
+
export type CustomScriptContext = "product" | "variant" | "both";
|
|
252
|
+
type CustomScriptMappingDefinition<Args extends any[], T extends GraphQlPermittedReturnType> = {
|
|
253
|
+
graphQlType: T;
|
|
254
|
+
context: CustomScriptContext;
|
|
255
|
+
scriptFn: (...args: Args) => {
|
|
256
|
+
script: string;
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
export type CustomScriptMapping<Args extends any[]> = {
|
|
260
|
+
[Type in GraphQlPermittedReturnType]: CustomScriptMappingDefinition<Args, Type>;
|
|
261
|
+
}[GraphQlPermittedReturnType];
|
|
262
|
+
export {};
|
package/lib/src/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ElasticSearchSortMode = void 0;
|
|
4
|
+
var ElasticSearchSortMode;
|
|
5
|
+
(function (ElasticSearchSortMode) {
|
|
6
|
+
/** Pick the lowest value */
|
|
7
|
+
ElasticSearchSortMode["MIN"] = "min";
|
|
8
|
+
/** Pick the highest value */
|
|
9
|
+
ElasticSearchSortMode["MAX"] = "max";
|
|
10
|
+
/** Use the sum of all values as sort value. Only applicable for number based array fields */
|
|
11
|
+
ElasticSearchSortMode["SUM"] = "sum";
|
|
12
|
+
/** Use the average of all values as sort value. Only applicable for number based array fields */
|
|
13
|
+
ElasticSearchSortMode["AVG"] = "avg";
|
|
14
|
+
/** Use the median of all values as sort value. Only applicable for number based array fields */
|
|
15
|
+
ElasticSearchSortMode["MEDIAN"] = "median";
|
|
16
|
+
})(ElasticSearchSortMode || (exports.ElasticSearchSortMode = ElasticSearchSortMode = {}));
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAwCA,IAAY,qBAWX;AAXD,WAAY,qBAAqB;IAC/B,4BAA4B;IAC5B,oCAAW,CAAA;IACX,6BAA6B;IAC7B,oCAAW,CAAA;IACX,6FAA6F;IAC7F,oCAAW,CAAA;IACX,iGAAiG;IACjG,oCAAW,CAAA;IACX,gGAAgG;IAChG,0CAAiB,CAAA;AACnB,CAAC,EAXW,qBAAqB,qCAArB,qBAAqB,QAWhC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@deenruv/elasticsearch-plugin",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"types": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib/**/*"
|
|
9
|
+
],
|
|
10
|
+
"homepage": "https://deenruv.com/",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@elastic/elasticsearch": "~7.9.1",
|
|
16
|
+
"@nestjs/common": "^10.3.10",
|
|
17
|
+
"@nestjs/graphql": "^12.2.0",
|
|
18
|
+
"@nestjs/terminus": "^10.2.3",
|
|
19
|
+
"deepmerge": "^4.2.2",
|
|
20
|
+
"fast-deep-equal": "^3.1.3",
|
|
21
|
+
"@deenruv/common": "^1.0.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"rimraf": "^5.0.5",
|
|
25
|
+
"rxjs": "7.8.1",
|
|
26
|
+
"typescript": "5.3.3",
|
|
27
|
+
"@deenruv/core": "^1.0.0"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@deenruv/core": "^0.1.0",
|
|
31
|
+
"@nestjs/core": "^10.3.10",
|
|
32
|
+
"graphql-tag": "^2.12.6",
|
|
33
|
+
"rxjs": "7.8.1",
|
|
34
|
+
"typeorm": "^0.3.20"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"watch": "tsc -p ./tsconfig.build.json --watch",
|
|
38
|
+
"build": "rimraf lib && tsc -p ./tsconfig.build.json",
|
|
39
|
+
"lint": "eslint .",
|
|
40
|
+
"lint:fix": "eslint --fix .",
|
|
41
|
+
"test": "vitest --run",
|
|
42
|
+
"e2e": "cross-env PACKAGE=elasticsearch-plugin vitest --config ../../e2e-common/vitest.config.mts --run",
|
|
43
|
+
"e2e:watch": "cross-env PACKAGE=elasticsearch-plugin vitest --config ../../e2e-common/vitest.config.mts"
|
|
44
|
+
}
|
|
45
|
+
}
|