@vegan-friendly/strapi-plugin-elasticsearch 0.1.0-alpha.3 → 0.2.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.
Files changed (109) hide show
  1. package/dist/admin/index.js +4 -4
  2. package/dist/admin/pluginId.js +1 -1
  3. package/dist/admin/src/components/Initializer/index.js +2 -1
  4. package/dist/admin/src/components/SubNavigation/index.js +10 -8
  5. package/dist/admin/src/pages/ConfigureCollectionList/index.js +40 -28
  6. package/dist/admin/src/pages/Homepage/index.js +20 -21
  7. package/dist/admin/src/pluginId.d.ts +1 -1
  8. package/dist/admin/src/utils/apiUrls.js +1 -0
  9. package/dist/admin/src/utils/axiosInstance.js +3 -4
  10. package/dist/package.json +64 -0
  11. package/dist/server/bootstrap.d.ts +4 -0
  12. package/dist/server/bootstrap.js +31 -5
  13. package/dist/server/config/index.d.ts +5 -0
  14. package/dist/server/config/index.js +2 -1
  15. package/dist/server/content-types/index.d.ts +83 -2
  16. package/dist/server/content-types/index.js +9 -5
  17. package/dist/server/content-types/indexing-logs.d.ts +32 -0
  18. package/dist/server/content-types/indexing-logs.js +22 -24
  19. package/dist/server/content-types/tasks.d.ts +46 -0
  20. package/dist/server/content-types/tasks.js +33 -38
  21. package/dist/server/controllers/configure-indexing.d.ts +11 -0
  22. package/dist/server/controllers/configure-indexing.js +3 -2
  23. package/dist/server/controllers/index.d.ts +33 -5
  24. package/dist/server/controllers/index.js +15 -11
  25. package/dist/server/controllers/log-indexing.d.ts +6 -0
  26. package/dist/server/controllers/log-indexing.js +3 -2
  27. package/dist/server/controllers/perform-indexing.d.ts +8 -0
  28. package/dist/server/controllers/perform-indexing.js +3 -2
  29. package/dist/server/controllers/perform-search.d.ts +4 -1
  30. package/dist/server/controllers/perform-search.js +11 -8
  31. package/dist/server/controllers/setup-info.d.ts +6 -0
  32. package/dist/server/controllers/setup-info.js +2 -1
  33. package/dist/server/destroy.d.ts +4 -0
  34. package/dist/server/destroy.js +2 -1
  35. package/dist/server/index.d.ts +296 -10
  36. package/dist/server/index.js +40 -21
  37. package/dist/server/middlewares/index.d.ts +2 -0
  38. package/dist/server/middlewares/index.js +2 -1
  39. package/dist/server/policies/index.d.ts +2 -0
  40. package/dist/server/policies/index.js +2 -1
  41. package/dist/server/register.d.ts +4 -0
  42. package/dist/server/register.js +2 -1
  43. package/dist/server/routes/configure-indexing.d.ts +12 -0
  44. package/dist/server/routes/configure-indexing.js +2 -1
  45. package/dist/server/routes/index.d.ts +58 -5
  46. package/dist/server/routes/index.js +15 -11
  47. package/dist/server/routes/perform-indexing.d.ts +12 -0
  48. package/dist/server/routes/perform-indexing.js +2 -1
  49. package/dist/server/routes/perform-search.d.ts +12 -0
  50. package/dist/server/routes/perform-search.js +4 -3
  51. package/dist/server/routes/run-log.d.ts +12 -0
  52. package/dist/server/routes/run-log.js +3 -2
  53. package/dist/server/routes/setup-info.d.ts +12 -0
  54. package/dist/server/routes/setup-info.js +3 -2
  55. package/dist/server/services/configure-indexing.d.ts +23 -23
  56. package/dist/server/services/configure-indexing.js +32 -20
  57. package/dist/server/services/es-interface.d.ts +5 -4
  58. package/dist/server/services/es-interface.js +19 -20
  59. package/dist/server/services/helper.d.ts +34 -33
  60. package/dist/server/services/helper.js +65 -61
  61. package/dist/server/services/index.d.ts +107 -7
  62. package/dist/server/services/index.js +23 -15
  63. package/dist/server/services/log-indexing.d.ts +8 -0
  64. package/dist/server/services/log-indexing.js +8 -7
  65. package/dist/server/services/perform-indexing.d.ts +8 -0
  66. package/dist/server/services/perform-indexing.js +35 -17
  67. package/dist/server/services/schedule-indexing.d.ts +19 -0
  68. package/dist/server/services/schedule-indexing.js +13 -12
  69. package/dist/server/services/transform-content.d.ts +7 -2
  70. package/dist/server/services/transform-content.js +4 -3
  71. package/dist/server/services/virtual-collections-indexer.d.ts +8 -0
  72. package/dist/server/services/virtual-collections-indexer.js +142 -0
  73. package/dist/server/services/virtual-collections-registry.d.ts +8 -0
  74. package/dist/server/services/virtual-collections-registry.js +32 -0
  75. package/dist/server/types/esInterface.type.d.ts +70 -0
  76. package/dist/server/types/esInterface.type.js +2 -0
  77. package/dist/server/types/index.d.ts +2 -0
  78. package/dist/server/types/index.js +18 -0
  79. package/dist/server/types/virtual-collections.d.ts +30 -0
  80. package/dist/server/types/virtual-collections.js +2 -0
  81. package/dist/server/types/virtual-collections.type.d.ts +57 -0
  82. package/dist/server/types/virtual-collections.type.js +2 -0
  83. package/package.json +6 -3
  84. package/dist/admin/components/Initializer/index.d.ts +0 -15
  85. package/dist/admin/components/Initializer/index.js +0 -25
  86. package/dist/admin/components/PluginIcon/index.d.ts +0 -8
  87. package/dist/admin/components/PluginIcon/index.js +0 -14
  88. package/dist/admin/components/SubNavigation/index.d.ts +0 -4
  89. package/dist/admin/components/SubNavigation/index.js +0 -40
  90. package/dist/admin/pages/App/index.d.ts +0 -9
  91. package/dist/admin/pages/App/index.js +0 -29
  92. package/dist/admin/pages/ConfigureCollection/index.d.ts +0 -3
  93. package/dist/admin/pages/ConfigureCollection/index.js +0 -193
  94. package/dist/admin/pages/ConfigureCollectionList/index.d.ts +0 -3
  95. package/dist/admin/pages/ConfigureCollectionList/index.js +0 -228
  96. package/dist/admin/pages/Homepage/index.d.ts +0 -3
  97. package/dist/admin/pages/Homepage/index.js +0 -155
  98. package/dist/admin/pages/ViewIndexingRunLog/index.d.ts +0 -3
  99. package/dist/admin/pages/ViewIndexingRunLog/index.js +0 -125
  100. package/dist/admin/utils/apiUrls.d.ts +0 -10
  101. package/dist/admin/utils/apiUrls.js +0 -20
  102. package/dist/admin/utils/axiosInstance.d.ts +0 -5
  103. package/dist/admin/utils/axiosInstance.js +0 -33
  104. package/dist/admin/utils/getTrad.d.ts +0 -2
  105. package/dist/admin/utils/getTrad.js +0 -8
  106. package/dist/strapi-admin.d.ts +0 -0
  107. package/dist/strapi-admin.js +0 -2
  108. package/dist/strapi-server.d.ts +0 -0
  109. package/dist/strapi-server.js +0 -2
@@ -1,7 +1,107 @@
1
- declare const configureIndexing: any;
2
- declare const scheduleIndexing: any;
3
- declare const esInterface: any;
4
- declare const indexer: any;
5
- declare const logIndexing: any;
6
- declare const helper: any;
7
- declare const transformContent: any;
1
+ declare const _default: {
2
+ configureIndexing: ({ strapi }: {
3
+ strapi: any;
4
+ }) => {
5
+ initializeStrapiElasticsearch(): Promise<void>;
6
+ markInitialized(): Promise<void>;
7
+ isInitialized(): any;
8
+ cacheConfig(): Promise<void>;
9
+ getCollectionConfig({ collectionName }: {
10
+ collectionName: any;
11
+ }): Promise<{} | null>;
12
+ getCollectionsConfiguredForIndexing(): Promise<string[]>;
13
+ isCollectionConfiguredToBeIndexed({ collectionName }: {
14
+ collectionName: any;
15
+ }): Promise<boolean>;
16
+ getContentConfig(): Promise<any>;
17
+ importContentConfig({ config }: {
18
+ config: any;
19
+ }): Promise<any>;
20
+ setContentConfig({ collection, config }: {
21
+ collection: any;
22
+ config: any;
23
+ }): Promise<any>;
24
+ };
25
+ scheduleIndexing: ({ strapi }: {
26
+ strapi: any;
27
+ }) => {
28
+ addFullSiteIndexingTask(): Promise<any>;
29
+ addCollectionToIndex({ collectionUid }: {
30
+ collectionUid: any;
31
+ }): Promise<any>;
32
+ addItemToIndex({ collectionUid, recordId }: {
33
+ collectionUid: any;
34
+ recordId: any;
35
+ }): Promise<any>;
36
+ removeItemFromIndex({ collectionUid, recordId }: {
37
+ collectionUid: any;
38
+ recordId: any;
39
+ }): Promise<void>;
40
+ getItemsPendingToBeIndexed(): Promise<any>;
41
+ markIndexingTaskComplete(recId: any): Promise<void>;
42
+ };
43
+ esInterface: ({ strapi }: {
44
+ strapi: any;
45
+ }) => import("..").EsInterfaceService;
46
+ indexer: ({ strapi }: {
47
+ strapi: any;
48
+ }) => {
49
+ rebuildIndex(): Promise<boolean>;
50
+ indexCollection(collectionName: any, indexName?: null): Promise<boolean>;
51
+ indexPendingData(): Promise<boolean>;
52
+ };
53
+ logIndexing: ({ strapi }: {
54
+ strapi: any;
55
+ }) => {
56
+ recordIndexingPass(message: any): Promise<void>;
57
+ recordIndexingFail(message: any): Promise<void>;
58
+ fetchIndexingLogs(count?: number): Promise<any>;
59
+ };
60
+ helper: ({ strapi }: {
61
+ strapi: any;
62
+ }) => {
63
+ getElasticsearchInfo(): Promise<{
64
+ indexingCronSchedule: any;
65
+ elasticHost: any;
66
+ elasticUserName: any;
67
+ elasticCertificate: any;
68
+ elasticIndexAlias: any;
69
+ connected: any;
70
+ initialized: any;
71
+ }>;
72
+ isCollectionDraftPublish({ collectionName }: {
73
+ collectionName: any;
74
+ }): boolean;
75
+ getPopulateAttribute({ collectionName }: {
76
+ collectionName: any;
77
+ }): true | {
78
+ populate: never;
79
+ } | undefined;
80
+ getIndexItemId({ collectionName, itemId }: {
81
+ collectionName: any;
82
+ itemId: any;
83
+ }): string;
84
+ getCurrentIndexName(): Promise<string>;
85
+ getIncrementedIndexName(): Promise<string>;
86
+ storeCurrentIndexName(indexName: any): Promise<void>;
87
+ modifySubfieldsConfigForExtractor(collectionConfig: any): any;
88
+ extractDataToIndex({ collectionName, data, collectionConfig }: {
89
+ collectionName: any;
90
+ data: any;
91
+ collectionConfig: any;
92
+ }): {};
93
+ };
94
+ transformContent: {
95
+ transform({ content, from }: {
96
+ content: any;
97
+ from: any;
98
+ }): any;
99
+ };
100
+ virtualCollectionsRegistry: ({ strapi }: {
101
+ strapi: any;
102
+ }) => import("..").VirtualCollectionsRegistryService;
103
+ virtualCollectionsIndexer: ({ strapi }: {
104
+ strapi: any;
105
+ }) => import("..").VirtualCollectionsIndexerService;
106
+ };
107
+ export default _default;
@@ -1,17 +1,25 @@
1
1
  'use strict';
2
- const configureIndexing = require('./configure-indexing');
3
- const scheduleIndexing = require('./schedule-indexing');
4
- const esInterface = require('./es-interface');
5
- const indexer = require('./perform-indexing');
6
- const logIndexing = require('./log-indexing');
7
- const helper = require('./helper');
8
- const transformContent = require('./transform-content');
9
- module.exports = {
10
- configureIndexing,
11
- scheduleIndexing,
12
- esInterface,
13
- indexer,
14
- logIndexing,
15
- helper,
16
- transformContent
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const configure_indexing_1 = __importDefault(require("./configure-indexing"));
7
+ const schedule_indexing_1 = __importDefault(require("./schedule-indexing"));
8
+ const es_interface_1 = __importDefault(require("./es-interface"));
9
+ const perform_indexing_1 = __importDefault(require("./perform-indexing"));
10
+ const log_indexing_1 = __importDefault(require("./log-indexing"));
11
+ const helper_1 = __importDefault(require("./helper"));
12
+ const transform_content_1 = __importDefault(require("./transform-content"));
13
+ const virtual_collections_registry_1 = __importDefault(require("./virtual-collections-registry"));
14
+ const virtual_collections_indexer_1 = __importDefault(require("./virtual-collections-indexer"));
15
+ exports.default = {
16
+ configureIndexing: configure_indexing_1.default,
17
+ scheduleIndexing: schedule_indexing_1.default,
18
+ esInterface: es_interface_1.default,
19
+ indexer: perform_indexing_1.default,
20
+ logIndexing: log_indexing_1.default,
21
+ helper: helper_1.default,
22
+ transformContent: transform_content_1.default,
23
+ virtualCollectionsRegistry: virtual_collections_registry_1.default,
24
+ virtualCollectionsIndexer: virtual_collections_indexer_1.default,
17
25
  };
@@ -0,0 +1,8 @@
1
+ declare const _default: ({ strapi }: {
2
+ strapi: any;
3
+ }) => {
4
+ recordIndexingPass(message: any): Promise<void>;
5
+ recordIndexingFail(message: any): Promise<void>;
6
+ fetchIndexingLogs(count?: number): Promise<any>;
7
+ };
8
+ export default _default;
@@ -1,27 +1,28 @@
1
1
  "use strict";
2
- module.exports = ({ strapi }) => ({
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = ({ strapi }) => ({
3
4
  async recordIndexingPass(message) {
4
5
  const entry = await strapi.entityService.create('plugin::elasticsearch.indexing-log', {
5
6
  data: {
6
7
  status: 'pass',
7
- details: message
8
- }
8
+ details: message,
9
+ },
9
10
  });
10
11
  },
11
12
  async recordIndexingFail(message) {
12
13
  const entry = await strapi.entityService.create('plugin::elasticsearch.indexing-log', {
13
14
  data: {
14
15
  status: 'fail',
15
- details: String(message)
16
- }
16
+ details: String(message),
17
+ },
17
18
  });
18
19
  },
19
20
  async fetchIndexingLogs(count = 50) {
20
21
  const records = await strapi.entityService.findMany('plugin::elasticsearch.indexing-log', {
21
22
  sort: { createdAt: 'DESC' },
22
23
  start: 0,
23
- limit: count
24
+ limit: count,
24
25
  });
25
26
  return records;
26
- }
27
+ },
27
28
  });
@@ -0,0 +1,8 @@
1
+ declare const _default: ({ strapi }: {
2
+ strapi: any;
3
+ }) => {
4
+ rebuildIndex(): Promise<boolean>;
5
+ indexCollection(collectionName: any, indexName?: null): Promise<boolean>;
6
+ indexPendingData(): Promise<boolean>;
7
+ };
8
+ export default _default;
@@ -1,11 +1,13 @@
1
1
  "use strict";
2
- module.exports = ({ strapi }) => ({
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = ({ strapi }) => ({
3
4
  async rebuildIndex() {
4
5
  const helper = strapi.plugins['elasticsearch'].services.helper;
5
6
  const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
6
7
  const scheduleIndexingService = strapi.plugins['elasticsearch'].services.scheduleIndexing;
7
8
  const configureIndexingService = strapi.plugins['elasticsearch'].services.configureIndexing;
8
9
  const logIndexingService = strapi.plugins['elasticsearch'].services.logIndexing;
10
+ const virtualCollectionsIndexer = strapi.plugins['elasticsearch'].services['virtualCollectionsIndexer'];
9
11
  try {
10
12
  console.log('strapi-plugin-elasticsearch : Request to rebuild the index received.');
11
13
  const oldIndexName = await helper.getCurrentIndexName();
@@ -21,11 +23,13 @@ module.exports = ({ strapi }) => ({
21
23
  const cols = await configureIndexingService.getCollectionsConfiguredForIndexing();
22
24
  for (let r = 0; r < cols.length; r++)
23
25
  await this.indexCollection(cols[r], newIndexName);
26
+ // Indexing the virtual collections
27
+ console.log('strapi-plugin-elasticsearch : Starting to index virtual collections.');
28
+ const totalIndexed = await virtualCollectionsIndexer.reindexAll(newIndexName);
24
29
  await scheduleIndexingService.markIndexingTaskComplete(item.id);
25
30
  console.log('strapi-plugin-elasticsearch : Indexing of data into the new index complete.');
26
31
  //Step 4 : Move the alias to this new index
27
32
  await esInterface.attachAliasToIndex(newIndexName);
28
- ;
29
33
  console.log('strapi-plugin-elasticsearch : Attaching the newly created index to the alias.');
30
34
  //Step 3 : Update the search-indexing-name
31
35
  await helper.storeCurrentIndexName(newIndexName);
@@ -44,6 +48,7 @@ module.exports = ({ strapi }) => ({
44
48
  console.log('strapi-plugin-elasticsearch : searchController : An error was encountered while re-indexing.');
45
49
  console.log(err);
46
50
  await logIndexingService.recordIndexingFail(err);
51
+ throw err;
47
52
  }
48
53
  },
49
54
  async indexCollection(collectionName, indexName = null) {
@@ -54,16 +59,16 @@ module.exports = ({ strapi }) => ({
54
59
  const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
55
60
  if (indexName === null)
56
61
  indexName = await helper.getCurrentIndexName();
57
- let entries = [];
62
+ let entries = []; //TODO: strapi should provide a type for this
58
63
  if (isCollectionDraftPublish) {
59
64
  entries = await strapi.entityService.findMany(collectionName, {
60
65
  sort: { createdAt: 'DESC' },
61
66
  populate: populateAttrib['populate'],
62
67
  filters: {
63
68
  publishedAt: {
64
- $notNull: true
65
- }
66
- }
69
+ $notNull: true,
70
+ },
71
+ },
67
72
  });
68
73
  }
69
74
  else {
@@ -75,10 +80,17 @@ module.exports = ({ strapi }) => ({
75
80
  if (entries) {
76
81
  for (let s = 0; s < entries.length; s++) {
77
82
  const item = entries[s];
78
- const indexItemId = helper.getIndexItemId({ collectionName: collectionName, itemId: item.id });
79
- const collectionConfig = await configureIndexingService.getCollectionConfig({ collectionName });
83
+ const indexItemId = helper.getIndexItemId({
84
+ collectionName: collectionName,
85
+ itemId: item.id,
86
+ });
87
+ const collectionConfig = await configureIndexingService.getCollectionConfig({
88
+ collectionName,
89
+ });
80
90
  const dataToIndex = await helper.extractDataToIndex({
81
- collectionName, data: item, collectionConfig
91
+ collectionName,
92
+ data: item,
93
+ collectionConfig,
82
94
  });
83
95
  await esInterface.indexDataToSpecificIndex({ itemId: indexItemId, itemData: dataToIndex }, indexName);
84
96
  }
@@ -92,7 +104,7 @@ module.exports = ({ strapi }) => ({
92
104
  const esInterface = strapi.plugins['elasticsearch'].services.esInterface;
93
105
  const helper = strapi.plugins['elasticsearch'].services.helper;
94
106
  const recs = await scheduleIndexingService.getItemsPendingToBeIndexed();
95
- const fullSiteIndexing = recs.filter(r => r.full_site_indexing === true).length > 0;
107
+ const fullSiteIndexing = recs.filter((r) => r.full_site_indexing === true).length > 0;
96
108
  if (fullSiteIndexing) {
97
109
  await this.rebuildIndex();
98
110
  for (let r = 0; r < recs.length; r++)
@@ -108,24 +120,30 @@ module.exports = ({ strapi }) => ({
108
120
  if (recs[r].indexing_type !== 'remove-from-index') {
109
121
  const populateAttrib = helper.getPopulateAttribute({ collectionName: col });
110
122
  const item = await strapi.entityService.findOne(col, recs[r].item_id, {
111
- populate: populateAttrib['populate']
123
+ populate: populateAttrib['populate'],
112
124
  });
113
125
  const indexItemId = helper.getIndexItemId({ collectionName: col, itemId: item.id });
114
- const collectionConfig = await configureIndexingService.getCollectionConfig({ collectionName: col });
126
+ const collectionConfig = await configureIndexingService.getCollectionConfig({
127
+ collectionName: col,
128
+ });
115
129
  const dataToIndex = await helper.extractDataToIndex({
116
- collectionName: col, data: item, collectionConfig
130
+ collectionName: col,
131
+ data: item,
132
+ collectionConfig,
117
133
  });
118
134
  await esInterface.indexData({ itemId: indexItemId, itemData: dataToIndex });
119
135
  await scheduleIndexingService.markIndexingTaskComplete(recs[r].id);
120
136
  }
121
137
  else {
122
- const indexItemId = helper.getIndexItemId({ collectionName: col, itemId: recs[r].item_id });
138
+ const indexItemId = helper.getIndexItemId({
139
+ collectionName: col,
140
+ itemId: recs[r].item_id,
141
+ });
123
142
  await esInterface.removeItemFromIndex({ itemId: indexItemId });
124
143
  await scheduleIndexingService.markIndexingTaskComplete(recs[r].id);
125
144
  }
126
- }
127
- else //index the entire collection
128
- {
145
+ } //index the entire collection
146
+ else {
129
147
  //PENDING : Index an entire collection
130
148
  await this.indexCollection(col);
131
149
  await scheduleIndexingService.markIndexingTaskComplete(recs[r].id);
@@ -0,0 +1,19 @@
1
+ declare const _default: ({ strapi }: {
2
+ strapi: any;
3
+ }) => {
4
+ addFullSiteIndexingTask(): Promise<any>;
5
+ addCollectionToIndex({ collectionUid }: {
6
+ collectionUid: any;
7
+ }): Promise<any>;
8
+ addItemToIndex({ collectionUid, recordId }: {
9
+ collectionUid: any;
10
+ recordId: any;
11
+ }): Promise<any>;
12
+ removeItemFromIndex({ collectionUid, recordId }: {
13
+ collectionUid: any;
14
+ recordId: any;
15
+ }): Promise<void>;
16
+ getItemsPendingToBeIndexed(): Promise<any>;
17
+ markIndexingTaskComplete(recId: any): Promise<void>;
18
+ };
19
+ export default _default;
@@ -1,13 +1,14 @@
1
1
  "use strict";
2
- module.exports = ({ strapi }) => ({
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = ({ strapi }) => ({
3
4
  async addFullSiteIndexingTask() {
4
5
  const data = await strapi.entityService.create('plugin::elasticsearch.task', {
5
6
  data: {
6
7
  collection_name: '',
7
8
  indexing_status: 'to-be-done',
8
9
  full_site_indexing: true,
9
- indexing_type: "add-to-index"
10
- }
10
+ indexing_type: 'add-to-index',
11
+ },
11
12
  });
12
13
  return data;
13
14
  },
@@ -17,8 +18,8 @@ module.exports = ({ strapi }) => ({
17
18
  collection_name: collectionUid,
18
19
  indexing_status: 'to-be-done',
19
20
  full_site_indexing: false,
20
- indexing_type: "add-to-index"
21
- }
21
+ indexing_type: 'add-to-index',
22
+ },
22
23
  });
23
24
  return data;
24
25
  },
@@ -29,8 +30,8 @@ module.exports = ({ strapi }) => ({
29
30
  collection_name: collectionUid,
30
31
  indexing_status: 'to-be-done',
31
32
  full_site_indexing: false,
32
- indexing_type: "add-to-index"
33
- }
33
+ indexing_type: 'add-to-index',
34
+ },
34
35
  });
35
36
  return data;
36
37
  },
@@ -41,8 +42,8 @@ module.exports = ({ strapi }) => ({
41
42
  collection_name: collectionUid,
42
43
  indexing_status: 'to-be-done',
43
44
  full_site_indexing: false,
44
- indexing_type: "remove-from-index"
45
- }
45
+ indexing_type: 'remove-from-index',
46
+ },
46
47
  });
47
48
  },
48
49
  async getItemsPendingToBeIndexed() {
@@ -54,8 +55,8 @@ module.exports = ({ strapi }) => ({
54
55
  async markIndexingTaskComplete(recId) {
55
56
  const entries = await strapi.entityService.update('plugin::elasticsearch.task', recId, {
56
57
  data: {
57
- 'indexing_status': 'done'
58
- }
58
+ indexing_status: 'done',
59
+ },
59
60
  });
60
- }
61
+ },
61
62
  });
@@ -1,2 +1,7 @@
1
- declare const markdownToTxt: any;
2
- declare function transformMarkdownToText(md: any): any;
1
+ declare const _default: {
2
+ transform({ content, from }: {
3
+ content: any;
4
+ from: any;
5
+ }): any;
6
+ };
7
+ export default _default;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
- const { markdownToTxt } = require('markdown-to-txt');
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const markdown_to_txt_1 = require("markdown-to-txt");
3
4
  function transformMarkdownToText(md) {
4
5
  let text = md;
5
6
  try {
6
- text = markdownToTxt(md);
7
+ text = (0, markdown_to_txt_1.markdownToTxt)(md);
7
8
  }
8
9
  catch (err) {
9
10
  console.error('strapi-plugin-elasticsearch : Error while transforming markdown to text.');
@@ -11,7 +12,7 @@ function transformMarkdownToText(md) {
11
12
  }
12
13
  return text;
13
14
  }
14
- module.exports = {
15
+ exports.default = {
15
16
  transform({ content, from }) {
16
17
  if (from === 'markdown')
17
18
  return transformMarkdownToText(content);
@@ -0,0 +1,8 @@
1
+ import { VirtualCollectionsIndexerService } from '../types';
2
+ /**
3
+ * Service to handle indexing of virtual collections
4
+ */
5
+ declare const _default: ({ strapi }: {
6
+ strapi: any;
7
+ }) => VirtualCollectionsIndexerService;
8
+ export default _default;
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const pretty_ms_1 = __importDefault(require("pretty-ms"));
7
+ /**
8
+ * Service to handle indexing of virtual collections
9
+ */
10
+ exports.default = ({ strapi }) => {
11
+ const getElasticsearchService = () => strapi.plugin('elasticsearch').service('esInterface');
12
+ const getRegistryService = () => strapi.service('plugin::elasticsearch.virtualCollectionsRegistry');
13
+ const getHelperService = () => strapi.plugins['elasticsearch'].services.helper;
14
+ return {
15
+ /**
16
+ * Index a single item from a virtual collection
17
+ */
18
+ async indexItem(collectionName, itemId) {
19
+ const registry = getRegistryService();
20
+ const collection = registry.get(collectionName);
21
+ if (!collection) {
22
+ throw new Error(`Virtual collection not found: ${collectionName}`);
23
+ }
24
+ try {
25
+ const results = await collection.extractById([itemId]);
26
+ if (!results || !Array.isArray(results) || results.length === 0) {
27
+ strapi.log.warn(`No data extracted for ${collectionName} with ID ${itemId}`);
28
+ return null;
29
+ }
30
+ const data = results[0];
31
+ const indexData = collection.mapToIndex ? data : data;
32
+ const esService = getElasticsearchService();
33
+ const helper = getHelperService();
34
+ const indexItemId = helper.getIndexItemId(collectionName, itemId);
35
+ await esService.indexDataToSpecificIndex({ itemId: indexItemId, itemData: indexData }, collection.indexName);
36
+ strapi.log.debug(`Indexed virtual item: ${collectionName}:${itemId}`);
37
+ return indexData;
38
+ }
39
+ catch (error) {
40
+ strapi.log.error(`Error indexing ${collectionName}:${itemId}: ${error?.message}`);
41
+ throw error;
42
+ }
43
+ },
44
+ async reindexAll(indexName) {
45
+ const registry = getRegistryService();
46
+ const collections = registry.getAll();
47
+ let totalIndexed = 0;
48
+ for (const collection of collections) {
49
+ totalIndexed += await this.reindex(collection.collectionName, indexName);
50
+ }
51
+ console.log(`strapi-plugin-elasticsearch : Reindexed ${totalIndexed} items across all ${collections.length} virtual collections`);
52
+ return totalIndexed;
53
+ },
54
+ /**
55
+ * Reindex all items in a virtual collection
56
+ */
57
+ async reindex(collectionName, indexName) {
58
+ const registry = getRegistryService();
59
+ const collection = registry.get(collectionName);
60
+ if (!collection) {
61
+ throw new Error(`Virtual collection not found: ${collectionName}`);
62
+ }
63
+ const timestamp = Date.now();
64
+ try {
65
+ const esService = getElasticsearchService();
66
+ const helper = getHelperService();
67
+ // await esService.createIndex(tempIndexName);
68
+ let page = 0;
69
+ let hasMoreData = true;
70
+ let totalIndexed = 0;
71
+ while (hasMoreData) {
72
+ const pageData = await collection.extractData(page);
73
+ if (!Array.isArray(pageData) || pageData.length === 0) {
74
+ hasMoreData = false;
75
+ break;
76
+ }
77
+ const operations = [];
78
+ for (const item of pageData) {
79
+ const itemId = helper.getIndexItemId({ collectionName, itemId: item.id });
80
+ const itemData = collection.mapToIndex ? item : item;
81
+ operations.push({ itemId, itemData });
82
+ }
83
+ if (operations.length > 0) {
84
+ await Promise.all(operations.map((op) => esService.indexDataToSpecificIndex(op, indexName)));
85
+ }
86
+ totalIndexed += pageData.length;
87
+ page++;
88
+ }
89
+ strapi.log.info(`Reindexed ${totalIndexed} items for virtual collection: ${collectionName}. took ${(0, pretty_ms_1.default)(Date.now() - timestamp)}`);
90
+ return totalIndexed;
91
+ }
92
+ catch (error) {
93
+ strapi.log.error(`Error reindexing ${collectionName}: ${error?.message} after ${(0, pretty_ms_1.default)(Date.now() - timestamp)}`);
94
+ throw error;
95
+ }
96
+ },
97
+ /**
98
+ * Handle a trigger event from a collection
99
+ */
100
+ async handleTriggerEvent(event) {
101
+ const { model, result } = event;
102
+ const registry = getRegistryService();
103
+ // Find virtual collections that should be triggered by this model
104
+ const affectedCollections = registry.findTriggersByCollection(model);
105
+ for (const collection of affectedCollections) {
106
+ // Find the specific trigger for this collection
107
+ const trigger = collection.triggers.find((t) => t.collection === model);
108
+ if (trigger && trigger.getIdsToReindex) {
109
+ // Get IDs that need to be reindexed
110
+ const idsToReindex = await trigger.getIdsToReindex(result);
111
+ // Reindex each item
112
+ for (const id of idsToReindex) {
113
+ await this.indexItem(collection.collectionName, id);
114
+ }
115
+ }
116
+ }
117
+ },
118
+ /**
119
+ * Delete an item from a virtual collection index
120
+ */
121
+ async deleteItem(collectionName, itemId) {
122
+ const registry = getRegistryService();
123
+ const collection = registry.get(collectionName);
124
+ if (!collection) {
125
+ throw new Error(`Virtual collection not found: ${collectionName}`);
126
+ }
127
+ try {
128
+ const esService = getElasticsearchService();
129
+ await esService.removeItemFromIndex({ itemId });
130
+ strapi.log.debug(`Deleted indexed item: ${collectionName}:${itemId}`);
131
+ return true;
132
+ }
133
+ catch (error) {
134
+ if (error?.meta?.statusCode === 404) {
135
+ return false;
136
+ }
137
+ strapi.log.error(`Error deleting ${collectionName}:${itemId}: ${error.message}`);
138
+ throw error;
139
+ }
140
+ },
141
+ };
142
+ };
@@ -0,0 +1,8 @@
1
+ import { VirtualCollectionsRegistryService } from '../types';
2
+ /**
3
+ * Service to handle indexing of virtual collections
4
+ */
5
+ declare const _default: ({ strapi }: {
6
+ strapi: any;
7
+ }) => VirtualCollectionsRegistryService;
8
+ export default _default;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /**
4
+ * Service to handle indexing of virtual collections
5
+ */
6
+ exports.default = ({ strapi }) => {
7
+ // const getElasticsearchService = () => strapi.plugin('elasticsearch').service('esInterface');
8
+ // const getAll = () => {
9
+ // const config = strapi.plugin('elasticsearch').config('virtualCollections');
10
+ // return config || [];
11
+ // };
12
+ // const get = (collectionName) => {
13
+ // return getAll().find((collection) => collection.collectionName === collectionName);
14
+ // };
15
+ return {
16
+ getAll() {
17
+ const config = strapi.plugin('elasticsearch').config('virtualCollections');
18
+ return config || [];
19
+ },
20
+ get(collectionName) {
21
+ return this.getAll().find((collection) => collection.collectionName === collectionName) ?? null;
22
+ },
23
+ register: function (config) {
24
+ throw new Error('Function not implemented.');
25
+ },
26
+ findTriggersByCollection: function (collectionUID) {
27
+ return this.getAll().filter((collection) => {
28
+ return collection.triggers.some((trigger) => trigger.collection === collectionUID);
29
+ });
30
+ },
31
+ };
32
+ };