@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,163 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.ElasticsearchIndexService = void 0;
|
|
13
|
+
const common_1 = require("@nestjs/common");
|
|
14
|
+
const shared_utils_1 = require("@deenruv/common/lib/shared-utils");
|
|
15
|
+
const core_1 = require("@deenruv/core");
|
|
16
|
+
const constants_1 = require("../constants");
|
|
17
|
+
const indexer_controller_1 = require("./indexer.controller");
|
|
18
|
+
let ElasticsearchIndexService = class ElasticsearchIndexService {
|
|
19
|
+
constructor(jobService, indexerController) {
|
|
20
|
+
this.jobService = jobService;
|
|
21
|
+
this.indexerController = indexerController;
|
|
22
|
+
}
|
|
23
|
+
async onApplicationBootstrap() {
|
|
24
|
+
this.updateIndexQueue = await this.jobService.createQueue({
|
|
25
|
+
name: "update-search-index",
|
|
26
|
+
process: (job) => {
|
|
27
|
+
const data = job.data;
|
|
28
|
+
switch (data.type) {
|
|
29
|
+
case "reindex":
|
|
30
|
+
core_1.Logger.verbose("sending ReindexMessage");
|
|
31
|
+
return this.jobWithProgress(job, this.indexerController.reindex(data));
|
|
32
|
+
case "update-product":
|
|
33
|
+
return this.indexerController.updateProduct(data);
|
|
34
|
+
case "update-variants":
|
|
35
|
+
return this.indexerController.updateVariants(data);
|
|
36
|
+
case "delete-product":
|
|
37
|
+
return this.indexerController.deleteProduct(data);
|
|
38
|
+
case "delete-variant":
|
|
39
|
+
return this.indexerController.deleteVariants(data);
|
|
40
|
+
case "update-variants-by-id":
|
|
41
|
+
return this.jobWithProgress(job, this.indexerController.updateVariantsById(data));
|
|
42
|
+
case "update-asset":
|
|
43
|
+
return this.indexerController.updateAsset(data);
|
|
44
|
+
case "delete-asset":
|
|
45
|
+
return this.indexerController.deleteAsset(data);
|
|
46
|
+
case "assign-product-to-channel":
|
|
47
|
+
return this.indexerController.assignProductToChannel(data);
|
|
48
|
+
case "remove-product-from-channel":
|
|
49
|
+
return this.indexerController.removeProductFromChannel(data);
|
|
50
|
+
case "assign-variant-to-channel":
|
|
51
|
+
return this.indexerController.assignVariantToChannel(data);
|
|
52
|
+
case "remove-variant-from-channel":
|
|
53
|
+
return this.indexerController.removeVariantFromChannel(data);
|
|
54
|
+
default:
|
|
55
|
+
(0, shared_utils_1.assertNever)(data);
|
|
56
|
+
return Promise.resolve();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
reindex(ctx) {
|
|
62
|
+
return this.updateIndexQueue.add({ type: "reindex", ctx: ctx.serialize() }, { ctx });
|
|
63
|
+
}
|
|
64
|
+
updateProduct(ctx, product) {
|
|
65
|
+
return this.updateIndexQueue.add({
|
|
66
|
+
type: "update-product",
|
|
67
|
+
ctx: ctx.serialize(),
|
|
68
|
+
productId: product.id,
|
|
69
|
+
}, { ctx });
|
|
70
|
+
}
|
|
71
|
+
updateVariants(ctx, variants) {
|
|
72
|
+
const variantIds = variants.map((v) => v.id);
|
|
73
|
+
return this.updateIndexQueue.add({ type: "update-variants", ctx: ctx.serialize(), variantIds }, { ctx });
|
|
74
|
+
}
|
|
75
|
+
deleteProduct(ctx, product) {
|
|
76
|
+
return this.updateIndexQueue.add({
|
|
77
|
+
type: "delete-product",
|
|
78
|
+
ctx: ctx.serialize(),
|
|
79
|
+
productId: product.id,
|
|
80
|
+
}, { ctx });
|
|
81
|
+
}
|
|
82
|
+
deleteVariant(ctx, variants) {
|
|
83
|
+
const variantIds = variants.map((v) => v.id);
|
|
84
|
+
return this.updateIndexQueue.add({ type: "delete-variant", ctx: ctx.serialize(), variantIds }, { ctx });
|
|
85
|
+
}
|
|
86
|
+
assignProductToChannel(ctx, product, channelId) {
|
|
87
|
+
return this.updateIndexQueue.add({
|
|
88
|
+
type: "assign-product-to-channel",
|
|
89
|
+
ctx: ctx.serialize(),
|
|
90
|
+
productId: product.id,
|
|
91
|
+
channelId,
|
|
92
|
+
}, { ctx });
|
|
93
|
+
}
|
|
94
|
+
removeProductFromChannel(ctx, product, channelId) {
|
|
95
|
+
return this.updateIndexQueue.add({
|
|
96
|
+
type: "remove-product-from-channel",
|
|
97
|
+
ctx: ctx.serialize(),
|
|
98
|
+
productId: product.id,
|
|
99
|
+
channelId,
|
|
100
|
+
}, { ctx });
|
|
101
|
+
}
|
|
102
|
+
assignVariantToChannel(ctx, productVariantId, channelId) {
|
|
103
|
+
return this.updateIndexQueue.add({
|
|
104
|
+
type: "assign-variant-to-channel",
|
|
105
|
+
ctx: ctx.serialize(),
|
|
106
|
+
productVariantId,
|
|
107
|
+
channelId,
|
|
108
|
+
}, { ctx });
|
|
109
|
+
}
|
|
110
|
+
removeVariantFromChannel(ctx, productVariantId, channelId) {
|
|
111
|
+
return this.updateIndexQueue.add({
|
|
112
|
+
type: "remove-variant-from-channel",
|
|
113
|
+
ctx: ctx.serialize(),
|
|
114
|
+
productVariantId,
|
|
115
|
+
channelId,
|
|
116
|
+
}, { ctx });
|
|
117
|
+
}
|
|
118
|
+
updateVariantsById(ctx, ids) {
|
|
119
|
+
return this.updateIndexQueue.add({ type: "update-variants-by-id", ctx: ctx.serialize(), ids }, { ctx });
|
|
120
|
+
}
|
|
121
|
+
updateAsset(ctx, asset) {
|
|
122
|
+
return this.updateIndexQueue.add({ type: "update-asset", ctx: ctx.serialize(), asset: asset }, { ctx });
|
|
123
|
+
}
|
|
124
|
+
deleteAsset(ctx, asset) {
|
|
125
|
+
return this.updateIndexQueue.add({ type: "delete-asset", ctx: ctx.serialize(), asset: asset }, { ctx });
|
|
126
|
+
}
|
|
127
|
+
jobWithProgress(job, ob) {
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
let total;
|
|
130
|
+
let duration = 0;
|
|
131
|
+
let completed = 0;
|
|
132
|
+
ob.subscribe({
|
|
133
|
+
next: (response) => {
|
|
134
|
+
if (!total) {
|
|
135
|
+
total = response.total;
|
|
136
|
+
}
|
|
137
|
+
duration = response.duration;
|
|
138
|
+
completed = response.completed;
|
|
139
|
+
const progress = total === 0 ? 100 : Math.ceil((completed / total) * 100);
|
|
140
|
+
job.setProgress(progress);
|
|
141
|
+
},
|
|
142
|
+
complete: () => {
|
|
143
|
+
resolve({
|
|
144
|
+
success: true,
|
|
145
|
+
indexedItemCount: total,
|
|
146
|
+
timeTaken: duration,
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
error: (err) => {
|
|
150
|
+
core_1.Logger.error(err.message || JSON.stringify(err), constants_1.loggerCtx, err.stack);
|
|
151
|
+
reject(err);
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
exports.ElasticsearchIndexService = ElasticsearchIndexService;
|
|
158
|
+
exports.ElasticsearchIndexService = ElasticsearchIndexService = __decorate([
|
|
159
|
+
(0, common_1.Injectable)(),
|
|
160
|
+
__metadata("design:paramtypes", [core_1.JobQueueService,
|
|
161
|
+
indexer_controller_1.ElasticsearchIndexerController])
|
|
162
|
+
], ElasticsearchIndexService);
|
|
163
|
+
//# sourceMappingURL=elasticsearch-index.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elasticsearch-index.service.js","sourceRoot":"","sources":["../../../src/indexing/elasticsearch-index.service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAAoE;AACpE,mEAA+D;AAC/D,wCAUuB;AAGvB,4CAAyC;AAGzC,6DAG8B;AAGvB,IAAM,yBAAyB,GAA/B,MAAM,yBAAyB;IAGpC,YACU,UAA2B,EAC3B,iBAAiD;QADjD,eAAU,GAAV,UAAU,CAAiB;QAC3B,sBAAiB,GAAjB,iBAAiB,CAAgC;IACxD,CAAC;IAEJ,KAAK,CAAC,sBAAsB;QAC1B,IAAI,CAAC,gBAAgB,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC;YACxD,IAAI,EAAE,qBAAqB;YAC3B,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBACf,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;gBACtB,QAAQ,IAAI,CAAC,IAAI,EAAE,CAAC;oBAClB,KAAK,SAAS;wBACZ,aAAM,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;wBACzC,OAAO,IAAI,CAAC,eAAe,CACzB,GAAG,EACH,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,IAAI,CAAC,CACrC,CAAC;oBACJ,KAAK,gBAAgB;wBACnB,OAAO,IAAI,CAAC,iBAAiB,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;oBACpD,KAAK,iBAAiB;wBACpB,OAAO,IAAI,CAAC,iBAAiB,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;oBACrD,KAAK,gBAAgB;wBACnB,OAA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C;gBACD,KAAK,EAAE,CAAC,GAAQ,EAAE,EAAE;oBAClB,aAAM,CAAC,KAAK,CACV,GAAG,CAAC,OAAO,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAClC,qBAAS,EACT,GAAG,CAAC,KAAK,CACV,CAAC;oBACF,MAAM,CAAC,GAAG,CAAC,CAAC;gBACd,CAAC;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AAxNY,8DAAyB;oCAAzB,yBAAyB;IADrC,IAAA,mBAAU,GAAE;qCAKW,sBAAe;QACR,mDAA8B;GALhD,yBAAyB,CAwNrC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { OnModuleDestroy, OnModuleInit } from "@nestjs/common";
|
|
2
|
+
import { ModuleRef } from "@nestjs/core";
|
|
3
|
+
import { ConfigService, EntityRelationPaths, Product, ProductPriceApplicator, ProductVariant, ProductVariantService, RequestContextCacheService, TransactionalConnection } from "@deenruv/core";
|
|
4
|
+
import { Observable } from "rxjs";
|
|
5
|
+
import { VARIANT_INDEX_NAME } from "../constants";
|
|
6
|
+
import { ElasticsearchOptions } from "../options";
|
|
7
|
+
import { BulkOperation, BulkOperationDoc, ProductChannelMessageData, ReindexMessageData, UpdateAssetMessageData, UpdateProductMessageData, UpdateVariantMessageData, UpdateVariantsByIdMessageData, VariantChannelMessageData, VariantIndexItem } from "../types";
|
|
8
|
+
export declare const defaultProductRelations: Array<EntityRelationPaths<Product>>;
|
|
9
|
+
export declare const defaultVariantRelations: Array<EntityRelationPaths<ProductVariant>>;
|
|
10
|
+
export interface ReindexMessageResponse {
|
|
11
|
+
total: number;
|
|
12
|
+
completed: number;
|
|
13
|
+
duration: number;
|
|
14
|
+
}
|
|
15
|
+
type BulkVariantOperation = {
|
|
16
|
+
index: typeof VARIANT_INDEX_NAME;
|
|
17
|
+
operation: BulkOperation | BulkOperationDoc<VariantIndexItem>;
|
|
18
|
+
};
|
|
19
|
+
export declare class ElasticsearchIndexerController implements OnModuleInit, OnModuleDestroy {
|
|
20
|
+
private connection;
|
|
21
|
+
private options;
|
|
22
|
+
private productPriceApplicator;
|
|
23
|
+
private configService;
|
|
24
|
+
private productVariantService;
|
|
25
|
+
private requestContextCache;
|
|
26
|
+
private moduleRef;
|
|
27
|
+
private client;
|
|
28
|
+
private asyncQueue;
|
|
29
|
+
private productRelations;
|
|
30
|
+
private variantRelations;
|
|
31
|
+
private injector;
|
|
32
|
+
constructor(connection: TransactionalConnection, options: Required<ElasticsearchOptions>, productPriceApplicator: ProductPriceApplicator, configService: ConfigService, productVariantService: ProductVariantService, requestContextCache: RequestContextCacheService, moduleRef: ModuleRef);
|
|
33
|
+
onModuleInit(): any;
|
|
34
|
+
onModuleDestroy(): any;
|
|
35
|
+
/**
|
|
36
|
+
* Updates the search index only for the affected product.
|
|
37
|
+
*/
|
|
38
|
+
updateProduct({ ctx: rawContext, productId, }: UpdateProductMessageData): Promise<boolean>;
|
|
39
|
+
/**
|
|
40
|
+
* Updates the search index only for the affected product.
|
|
41
|
+
*/
|
|
42
|
+
deleteProduct({ ctx: rawContext, productId, }: UpdateProductMessageData): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Updates the search index only for the affected product.
|
|
45
|
+
*/
|
|
46
|
+
assignProductToChannel({ ctx: rawContext, productId, channelId, }: ProductChannelMessageData): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Updates the search index only for the affected product.
|
|
49
|
+
*/
|
|
50
|
+
removeProductFromChannel({ ctx: rawContext, productId, channelId, }: ProductChannelMessageData): Promise<boolean>;
|
|
51
|
+
assignVariantToChannel({ ctx: rawContext, productVariantId, channelId, }: VariantChannelMessageData): Promise<boolean>;
|
|
52
|
+
removeVariantFromChannel({ ctx: rawContext, productVariantId, channelId, }: VariantChannelMessageData): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* Updates the search index only for the affected entities.
|
|
55
|
+
*/
|
|
56
|
+
updateVariants({ ctx: rawContext, variantIds, }: UpdateVariantMessageData): Promise<boolean>;
|
|
57
|
+
deleteVariants({ ctx: rawContext, variantIds, }: UpdateVariantMessageData): Promise<boolean>;
|
|
58
|
+
updateVariantsById({ ctx: rawContext, ids, }: UpdateVariantsByIdMessageData): Observable<ReindexMessageResponse>;
|
|
59
|
+
reindex({ ctx: rawContext, }: ReindexMessageData): Observable<ReindexMessageResponse>;
|
|
60
|
+
executeBulkOperationsByChunks(chunkSize: number, operations: BulkVariantOperation[], index?: string): Promise<void>;
|
|
61
|
+
updateAsset(data: UpdateAssetMessageData): Promise<boolean>;
|
|
62
|
+
deleteAsset(data: UpdateAssetMessageData): Promise<boolean>;
|
|
63
|
+
private updateAssetFocalPointForIndex;
|
|
64
|
+
private deleteAssetForIndex;
|
|
65
|
+
private updateAssetForIndex;
|
|
66
|
+
private updateProductsInternal;
|
|
67
|
+
private switchAlias;
|
|
68
|
+
private updateProductsOperationsOnly;
|
|
69
|
+
private updateProductsOperations;
|
|
70
|
+
/**
|
|
71
|
+
* Takes the default relations, and combines them with any extra relations specified in the
|
|
72
|
+
* `hydrateProductRelations` and `hydrateProductVariantRelations`. This method also ensures
|
|
73
|
+
* that the relation values are unique and that paths are fully expanded.
|
|
74
|
+
*
|
|
75
|
+
* This means that if a `hydrateProductRelations` value of `['assets.asset']` is specified,
|
|
76
|
+
* this method will also add `['assets']` to the relations array, otherwise TypeORM would
|
|
77
|
+
* throw an error trying to join a 2nd-level deep relation without the first level also
|
|
78
|
+
* being joined.
|
|
79
|
+
*/
|
|
80
|
+
private getReindexRelations;
|
|
81
|
+
private deleteProductOperations;
|
|
82
|
+
private deleteVariantsInternalOperations;
|
|
83
|
+
private getProductIdsByVariantIds;
|
|
84
|
+
private executeBulkOperations;
|
|
85
|
+
private runBulkOperationsOnIndex;
|
|
86
|
+
private createVariantIndexItem;
|
|
87
|
+
private getProductInStockValue;
|
|
88
|
+
/**
|
|
89
|
+
* If a Product has no variants, we create a synthetic variant for the purposes
|
|
90
|
+
* of making that product visible via the search query.
|
|
91
|
+
*/
|
|
92
|
+
private createSyntheticProductIndexItem;
|
|
93
|
+
private getTranslation;
|
|
94
|
+
private getFacetIds;
|
|
95
|
+
private getFacetValueIds;
|
|
96
|
+
private static getId;
|
|
97
|
+
}
|
|
98
|
+
export {};
|