@extravirgin/payload-plugin-meilisearch 0.0.1 → 0.0.3

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 (51) hide show
  1. package/dist/index.d.ts +2 -0
  2. package/dist/index.js.map +1 -0
  3. package/dist/indexCollections.d.ts +3 -0
  4. package/dist/indexCollections.js +395 -0
  5. package/dist/indexCollections.js.map +1 -0
  6. package/dist/mocks/mockFile.d.ts +1 -0
  7. package/dist/mocks/mockFile.js +3 -0
  8. package/dist/mocks/mockFile.js.map +1 -0
  9. package/dist/onInitExtension.d.ts +3 -0
  10. package/dist/onInitExtension.js +17 -0
  11. package/dist/onInitExtension.js.map +1 -0
  12. package/dist/plugin.d.ts +3 -0
  13. package/dist/plugin.js +103 -0
  14. package/dist/plugin.js.map +1 -0
  15. package/dist/types.d.ts +18 -0
  16. package/dist/types.js +3 -0
  17. package/dist/types.js.map +1 -0
  18. package/dist/webpack.d.ts +3 -0
  19. package/dist/webpack.js +32 -0
  20. package/dist/webpack.js.map +1 -0
  21. package/package.json +6 -2
  22. package/.editorconfig +0 -10
  23. package/.eslintrc.js +0 -17
  24. package/.github/workflows/test.yml +0 -19
  25. package/.prettierrc.js +0 -8
  26. package/dev/.env.example +0 -2
  27. package/dev/Dockerfile +0 -27
  28. package/dev/docker-compose.yml +0 -31
  29. package/dev/jest.config.js +0 -12
  30. package/dev/nodemon.json +0 -6
  31. package/dev/package.json +0 -35
  32. package/dev/plugin.spec.ts +0 -30
  33. package/dev/src/collections/Examples.ts +0 -17
  34. package/dev/src/collections/Users.ts +0 -15
  35. package/dev/src/mocks/fileStub.js +0 -1
  36. package/dev/src/payload.config.ts +0 -44
  37. package/dev/src/server.ts +0 -29
  38. package/dev/tsconfig.json +0 -34
  39. package/eslint-config/index.js +0 -15
  40. package/eslint-config/rules/import.js +0 -38
  41. package/eslint-config/rules/prettier.js +0 -7
  42. package/eslint-config/rules/style.js +0 -21
  43. package/eslint-config/rules/typescript.js +0 -628
  44. package/src/index.ts +0 -2
  45. package/src/indexCollections.ts +0 -155
  46. package/src/mocks/mockFile.js +0 -1
  47. package/src/onInitExtension.ts +0 -16
  48. package/src/plugin.ts +0 -67
  49. package/src/types.ts +0 -20
  50. package/src/webpack.ts +0 -28
  51. package/tsconfig.json +0 -23
@@ -0,0 +1,2 @@
1
+ export { meilisearchPlugin } from './plugin';
2
+ export type { PluginTypes } from './types';
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA4C;AAAnC,2GAAA,iBAAiB,OAAA"}
@@ -0,0 +1,3 @@
1
+ import { CollectionConfig } from "payload/dist/exports/types";
2
+ import { PluginTypes } from "./types";
3
+ export declare const indexCollections: (collections: CollectionConfig[], config: PluginTypes) => CollectionConfig[];
@@ -0,0 +1,395 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.indexCollections = void 0;
60
+ var meilisearch_1 = require("meilisearch");
61
+ var html_to_text_1 = require("html-to-text");
62
+ var richtext_lexical_1 = require("@payloadcms/richtext-lexical");
63
+ var getIndexName = function (config, collectionSlug) { var _a; return "".concat((_a = config === null || config === void 0 ? void 0 : config.indexPrefix) !== null && _a !== void 0 ? _a : '').concat(collectionSlug); };
64
+ function handleAfterChange(_a) {
65
+ var _b, _c, _d, _e, _f, _g;
66
+ var doc = _a.doc, previousDoc = _a.previousDoc, req = _a.req, collection = _a.collection, config = _a.config;
67
+ return __awaiter(this, void 0, void 0, function () {
68
+ var baseDoc, collectionConfig, payload, client, index, documents, _h, locales, defaultLocale, fallback, _i, locales_1, locale, localizedDoc, _j, documentId, shouldIndex, transformedDoc, _k, documentId, shouldIndex, transformedDoc, _l, error_1;
69
+ return __generator(this, function (_m) {
70
+ switch (_m.label) {
71
+ case 0:
72
+ _m.trys.push([0, 19, , 20]);
73
+ baseDoc = doc;
74
+ collectionConfig = config.collections && (config === null || config === void 0 ? void 0 : config.collections.find(function (c) { return c.slug === collection.slug; }));
75
+ payload = req.payload;
76
+ client = getMeilisearchClient(config);
77
+ return [4 /*yield*/, upsertIndex(client, getIndexName(config, collection.slug))];
78
+ case 1:
79
+ _m.sent();
80
+ index = client.index(getIndexName(config, collection.slug));
81
+ documents = [];
82
+ if (!(((_b = payload.config) === null || _b === void 0 ? void 0 : _b.localization) && ((_c = payload.config.localization.locales) === null || _c === void 0 ? void 0 : _c.length) > 0)) return [3 /*break*/, 13];
83
+ _h = payload.config.localization, locales = _h.locales, defaultLocale = _h.defaultLocale, fallback = _h.fallback;
84
+ _i = 0, locales_1 = locales;
85
+ _m.label = 2;
86
+ case 2:
87
+ if (!(_i < locales_1.length)) return [3 /*break*/, 10];
88
+ locale = locales_1[_i];
89
+ if (!(req.locale === locale.code)) return [3 /*break*/, 3];
90
+ _j = doc;
91
+ return [3 /*break*/, 5];
92
+ case 3: return [4 /*yield*/, req.payload.findByID({
93
+ collection: collection.slug,
94
+ id: doc.id,
95
+ locale: locale,
96
+ fallbackLocale: locale.fallbackLocale || defaultLocale,
97
+ })];
98
+ case 4:
99
+ _j = _m.sent();
100
+ _m.label = 5;
101
+ case 5:
102
+ localizedDoc = _j;
103
+ documentId = doc.id + "_".concat(locale.code);
104
+ shouldIndex = (_e = (_d = collectionConfig === null || collectionConfig === void 0 ? void 0 : collectionConfig.shouldIndex) === null || _d === void 0 ? void 0 : _d.call(collectionConfig, localizedDoc, previousDoc, locale.code)) !== null && _e !== void 0 ? _e : 'index';
105
+ if (!(shouldIndex === 'index')) return [3 /*break*/, 7];
106
+ _k = [{}];
107
+ return [4 /*yield*/, transformDocumentForMeilisearch(localizedDoc, collection.fields, req)];
108
+ case 6:
109
+ transformedDoc = __assign.apply(void 0, [__assign.apply(void 0, _k.concat([_m.sent()])), { id: documentId, documentId: doc.id, locale: locale.code }]);
110
+ documents.push(transformedDoc);
111
+ return [3 /*break*/, 9];
112
+ case 7:
113
+ if (!(shouldIndex === 'delete')) return [3 /*break*/, 9];
114
+ return [4 /*yield*/, index.deleteDocument(documentId)];
115
+ case 8:
116
+ _m.sent();
117
+ _m.label = 9;
118
+ case 9:
119
+ _i++;
120
+ return [3 /*break*/, 2];
121
+ case 10:
122
+ if (!(documents.length > 0)) return [3 /*break*/, 12];
123
+ return [4 /*yield*/, index.addDocuments(documents)];
124
+ case 11:
125
+ _m.sent();
126
+ _m.label = 12;
127
+ case 12: return [3 /*break*/, 18];
128
+ case 13:
129
+ documentId = doc.id;
130
+ shouldIndex = (_g = (_f = collectionConfig === null || collectionConfig === void 0 ? void 0 : collectionConfig.shouldIndex) === null || _f === void 0 ? void 0 : _f.call(collectionConfig, doc, previousDoc)) !== null && _g !== void 0 ? _g : 'index';
131
+ if (!(shouldIndex === 'index')) return [3 /*break*/, 16];
132
+ _l = [{}];
133
+ return [4 /*yield*/, transformDocumentForMeilisearch(doc, collection.fields, req)];
134
+ case 14:
135
+ transformedDoc = __assign.apply(void 0, [__assign.apply(void 0, _l.concat([_m.sent()])), { id: documentId, documentId: doc.id }]);
136
+ return [4 /*yield*/, index.addDocuments([transformedDoc])];
137
+ case 15:
138
+ _m.sent();
139
+ return [3 /*break*/, 18];
140
+ case 16:
141
+ if (!(shouldIndex === 'delete')) return [3 /*break*/, 18];
142
+ return [4 /*yield*/, index.deleteDocument(documentId)];
143
+ case 17:
144
+ _m.sent();
145
+ _m.label = 18;
146
+ case 18: return [3 /*break*/, 20];
147
+ case 19:
148
+ error_1 = _m.sent();
149
+ console.error('Meilisearch indexing error:', error_1);
150
+ return [3 /*break*/, 20];
151
+ case 20: return [2 /*return*/];
152
+ }
153
+ });
154
+ });
155
+ }
156
+ var indexCollections = function (collections, config) {
157
+ return collections.map(function (collection) {
158
+ var _a, _b;
159
+ var collectionConfig = config.collections && (config === null || config === void 0 ? void 0 : config.collections.find(function (c) { return c.slug === collection.slug; }));
160
+ if (!collectionConfig) {
161
+ return collection;
162
+ }
163
+ return __assign(__assign({}, collection), { hooks: __assign(__assign({}, (collection.hooks || {})), { afterChange: __spreadArray(__spreadArray([], (((_a = collection.hooks) === null || _a === void 0 ? void 0 : _a.afterChange) || []), true), [
164
+ function (_a) {
165
+ var doc = _a.doc, previousDoc = _a.previousDoc, req = _a.req;
166
+ handleAfterChange({ doc: doc, previousDoc: previousDoc, req: req, collection: collection, config: config });
167
+ },
168
+ ], false), afterDelete: __spreadArray(__spreadArray([], (((_b = collection.hooks) === null || _b === void 0 ? void 0 : _b.afterDelete) || []), true), [
169
+ function (_a) {
170
+ var doc = _a.doc, req = _a.req;
171
+ return __awaiter(void 0, void 0, void 0, function () {
172
+ var payload, localization, client, index, locales, _i, locales_2, locale, documentId, error_2;
173
+ var _b, _c;
174
+ return __generator(this, function (_d) {
175
+ switch (_d.label) {
176
+ case 0:
177
+ _d.trys.push([0, 9, , 10]);
178
+ payload = req.payload;
179
+ localization = (_b = payload.config) === null || _b === void 0 ? void 0 : _b.localization;
180
+ client = getMeilisearchClient(config);
181
+ return [4 /*yield*/, upsertIndex(client, getIndexName(config, collection.slug))];
182
+ case 1:
183
+ _d.sent();
184
+ index = client.index(getIndexName(config, collection.slug));
185
+ if (!(localization && ((_c = localization.locales) === null || _c === void 0 ? void 0 : _c.length) > 0)) return [3 /*break*/, 6];
186
+ locales = localization.locales;
187
+ _i = 0, locales_2 = locales;
188
+ _d.label = 2;
189
+ case 2:
190
+ if (!(_i < locales_2.length)) return [3 /*break*/, 5];
191
+ locale = locales_2[_i];
192
+ documentId = doc.id + "_".concat(locale.code);
193
+ return [4 /*yield*/, index.deleteDocument(documentId)];
194
+ case 3:
195
+ _d.sent();
196
+ _d.label = 4;
197
+ case 4:
198
+ _i++;
199
+ return [3 /*break*/, 2];
200
+ case 5: return [3 /*break*/, 8];
201
+ case 6: return [4 /*yield*/, index.deleteDocument(doc.id)];
202
+ case 7:
203
+ _d.sent();
204
+ _d.label = 8;
205
+ case 8: return [3 /*break*/, 10];
206
+ case 9:
207
+ error_2 = _d.sent();
208
+ console.error('Meilisearch indexing error:', error_2);
209
+ return [3 /*break*/, 10];
210
+ case 10: return [2 /*return*/];
211
+ }
212
+ });
213
+ });
214
+ },
215
+ ], false) }) });
216
+ });
217
+ };
218
+ exports.indexCollections = indexCollections;
219
+ var meilisearch;
220
+ function getMeilisearchClient(config) {
221
+ if (!meilisearch) {
222
+ meilisearch = new meilisearch_1.MeiliSearch({
223
+ host: config.host,
224
+ apiKey: config.apiKey,
225
+ });
226
+ }
227
+ return meilisearch;
228
+ }
229
+ function upsertIndex(client, indexUID) {
230
+ var _a;
231
+ return __awaiter(this, void 0, void 0, function () {
232
+ var error_3;
233
+ return __generator(this, function (_b) {
234
+ switch (_b.label) {
235
+ case 0:
236
+ _b.trys.push([0, 2, , 6]);
237
+ // Attempt to retrieve the index
238
+ return [4 /*yield*/, client.getIndex(indexUID)];
239
+ case 1:
240
+ // Attempt to retrieve the index
241
+ _b.sent();
242
+ return [3 /*break*/, 6];
243
+ case 2:
244
+ error_3 = _b.sent();
245
+ if (!(((_a = error_3 === null || error_3 === void 0 ? void 0 : error_3.cause) === null || _a === void 0 ? void 0 : _a.code) === 'index_not_found')) return [3 /*break*/, 4];
246
+ // Index doesn't exist; create it
247
+ return [4 /*yield*/, client.createIndex(indexUID, {
248
+ primaryKey: 'id',
249
+ })];
250
+ case 3:
251
+ // Index doesn't exist; create it
252
+ _b.sent();
253
+ console.log("Index '".concat(indexUID, "' has been created."));
254
+ return [3 /*break*/, 5];
255
+ case 4:
256
+ // Rethrow any other errors
257
+ throw error_3;
258
+ case 5: return [3 /*break*/, 6];
259
+ case 6: return [2 /*return*/];
260
+ }
261
+ });
262
+ });
263
+ }
264
+ var options = {
265
+ wordwrap: 130,
266
+ // ...
267
+ };
268
+ var compiledConvert = (0, html_to_text_1.compile)(options);
269
+ // Helper function to extract text from HTML in nodejs
270
+ function extractTextFromHTML(html) {
271
+ return compiledConvert(html);
272
+ }
273
+ // Helper function to transform a document for Meilisearch indexing
274
+ function transformDocumentForMeilisearch(doc, fields, req) {
275
+ return __awaiter(this, void 0, void 0, function () {
276
+ var transformedDoc;
277
+ var _this = this;
278
+ return __generator(this, function (_a) {
279
+ switch (_a.label) {
280
+ case 0:
281
+ transformedDoc = {};
282
+ return [4 /*yield*/, Promise.all(fields.map(function (field) { return __awaiter(_this, void 0, void 0, function () {
283
+ var lexicalAdapter, sanitizedServerEditorConfig, html, _a, _b, _c, _d, _e, _f;
284
+ var _this = this;
285
+ var _g;
286
+ return __generator(this, function (_h) {
287
+ switch (_h.label) {
288
+ case 0:
289
+ if (!(field.type === 'richText')) return [3 /*break*/, 2];
290
+ lexicalAdapter = field.editor;
291
+ sanitizedServerEditorConfig = lexicalAdapter.editorConfig;
292
+ return [4 /*yield*/, (0, richtext_lexical_1.convertLexicalToHTML)({
293
+ converters: (0, richtext_lexical_1.consolidateHTMLConverters)({ editorConfig: sanitizedServerEditorConfig }),
294
+ data: doc[field.name],
295
+ })];
296
+ case 1:
297
+ html = _h.sent();
298
+ transformedDoc[field.name] = extractTextFromHTML(html);
299
+ return [3 /*break*/, 11];
300
+ case 2:
301
+ if (!(field.type === 'array' && field.fields)) return [3 /*break*/, 4];
302
+ // For array fields, transform each item
303
+ _a = transformedDoc;
304
+ _b = field.name;
305
+ return [4 /*yield*/, Promise.all((doc[field.name] || []).map(function (item) {
306
+ return transformDocumentForMeilisearch(item, field.fields, req);
307
+ }))];
308
+ case 3:
309
+ // For array fields, transform each item
310
+ _a[_b] = _h.sent();
311
+ return [3 /*break*/, 11];
312
+ case 4:
313
+ if (!(field.type === 'tabs')) return [3 /*break*/, 6];
314
+ return [4 /*yield*/, Promise.all(field.tabs.map(function (tab, index) { return __awaiter(_this, void 0, void 0, function () {
315
+ return __generator(this, function (_a) {
316
+ switch (_a.label) {
317
+ case 0: return [4 /*yield*/, transformDocumentForMeilisearch(doc, tab.fields, req)];
318
+ case 1: return [2 /*return*/, _a.sent()];
319
+ }
320
+ });
321
+ }); }))];
322
+ case 5:
323
+ // For tab fields, transform each tab
324
+ (_h.sent()).forEach(function (t) { return Object.assign(transformedDoc, t); });
325
+ return [3 /*break*/, 11];
326
+ case 6:
327
+ if (!(field.type === 'blocks')) return [3 /*break*/, 8];
328
+ // For block fields, transform each block
329
+ _c = transformedDoc;
330
+ _d = field.name;
331
+ return [4 /*yield*/, Promise.all((doc[field.name] || []).map(function (block) { return __awaiter(_this, void 0, void 0, function () {
332
+ var fields;
333
+ var _a;
334
+ var _b;
335
+ return __generator(this, function (_c) {
336
+ switch (_c.label) {
337
+ case 0:
338
+ fields = (_b = field.blocks.find(function (b) { return b.slug === block.blockType; })) === null || _b === void 0 ? void 0 : _b.fields;
339
+ if (!fields) {
340
+ return [2 /*return*/, {
341
+ type: block.blockType,
342
+ data: "",
343
+ }];
344
+ }
345
+ _a = {
346
+ type: block.blockType
347
+ };
348
+ return [4 /*yield*/, transformDocumentForMeilisearch(block, fields, req)];
349
+ case 1: return [2 /*return*/, (_a.data = _c.sent(),
350
+ _a)];
351
+ }
352
+ });
353
+ }); }))];
354
+ case 7:
355
+ // For block fields, transform each block
356
+ _c[_d] = _h.sent();
357
+ return [3 /*break*/, 11];
358
+ case 8:
359
+ if (!(field.type === 'group' && field.fields)) return [3 /*break*/, 10];
360
+ // For group fields, transform the nested fields
361
+ _e = transformedDoc;
362
+ _f = field.name;
363
+ return [4 /*yield*/, transformDocumentForMeilisearch(doc[field.name], field.fields, req)];
364
+ case 9:
365
+ // For group fields, transform the nested fields
366
+ _e[_f] = _h.sent();
367
+ return [3 /*break*/, 11];
368
+ case 10:
369
+ if (field.type === 'relationship' || field.type === 'upload') {
370
+ // For relationship and upload fields, just include the ID
371
+ transformedDoc[field.name] = ((_g = doc[field.name]) === null || _g === void 0 ? void 0 : _g.id) || doc[field.name];
372
+ }
373
+ else {
374
+ // For other field types, include as-is
375
+ try {
376
+ // @ts-ignore
377
+ transformedDoc[field.name] = doc[field.name];
378
+ }
379
+ catch (err) {
380
+ console.log(err, field, doc);
381
+ }
382
+ }
383
+ _h.label = 11;
384
+ case 11: return [2 /*return*/];
385
+ }
386
+ });
387
+ }); }))];
388
+ case 1:
389
+ _a.sent();
390
+ return [2 /*return*/, transformedDoc];
391
+ }
392
+ });
393
+ });
394
+ }
395
+ //# sourceMappingURL=indexCollections.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indexCollections.js","sourceRoot":"","sources":["../src/indexCollections.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,2CAA0C;AAC1C,6CAAwC;AACxC,iEAIsC;AAItC,IAAM,YAAY,GAAG,UAAC,MAAmB,EAAE,cAAsB,YAAK,OAAA,UAAG,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,WAAW,mCAAI,EAAE,SAAG,cAAc,CAAE,CAAA,EAAA,CAAC;AAEtH,SAAe,iBAAiB,CAAC,EAAiJ;;QAAhJ,GAAG,SAAA,EAAE,WAAW,iBAAA,EAAE,GAAG,S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D;wCAChD,MAA0B,GAAG,SAAyE,CAAC;;;wCAClG,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE;4CACnE,0DAA0D;4CAC1D,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAA,MAAA,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,0CAAE,EAAE,KAAI,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;yCACrE;6CAAM;4CACL,uCAAuC;4CACvC,IAAI;gDACF,aAAa;gDACb,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;6CAC9C;4CAAC,OAAM,GAAG,EAAE;gDACX,OAAO,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,GAAG,CAAC,CAAA;6CAC7B;yCACF;;;;;6BACF,CAAC,CAAC,EAAA;;oBAlEH,SAkEG,CAAC;oBAEJ,sBAAO,cAAc,EAAC;;;;CACvB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ module.exports = {};
3
+ //# sourceMappingURL=mockFile.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mockFile.js","sourceRoot":"","sources":["../../src/mocks/mockFile.js"],"names":[],"mappings":";AAAA,MAAM,CAAC,OAAO,GAAG,EAAE,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { Payload } from 'payload/dist/payload';
2
+ import type { PluginTypes } from './types';
3
+ export declare const onInitExtension: (pluginOptions: PluginTypes, payload: Payload) => void;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.onInitExtension = void 0;
4
+ var onInitExtension = function (pluginOptions, payload) {
5
+ var app = payload.express;
6
+ if (!app)
7
+ return;
8
+ try {
9
+ // You can use the existing express app here to add middleware, routes, etc.
10
+ // app.use(...)
11
+ }
12
+ catch (err) {
13
+ payload.logger.error({ msg: 'Error in onInitExtension', err: err });
14
+ }
15
+ };
16
+ exports.onInitExtension = onInitExtension;
17
+ //# sourceMappingURL=onInitExtension.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"onInitExtension.js","sourceRoot":"","sources":["../src/onInitExtension.ts"],"names":[],"mappings":";;;AAIO,IAAM,eAAe,GAAG,UAAC,aAA0B,EAAE,OAAgB;IAClE,IAAS,GAAG,GAAK,OAAO,QAAZ,CAAY;IAEhC,IAAI,CAAC,GAAG;QAAE,OAAM;IAEhB,IAAI;QACF,4EAA4E;QAC5E,eAAe;KAChB;IAAC,OAAO,GAAY,EAAE;QACrB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,0BAA0B,EAAE,GAAG,KAAA,EAAE,CAAC,CAAA;KAC/D;AACH,CAAC,CAAA;AAXY,QAAA,eAAe,mBAW3B"}
@@ -0,0 +1,3 @@
1
+ import type { Plugin } from 'payload/config';
2
+ import type { PluginTypes } from './types';
3
+ export declare const meilisearchPlugin: (pluginOptions: PluginTypes) => Plugin;
package/dist/plugin.js ADDED
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
50
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
51
+ if (ar || !(i in from)) {
52
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
53
+ ar[i] = from[i];
54
+ }
55
+ }
56
+ return to.concat(ar || Array.prototype.slice.call(from));
57
+ };
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.meilisearchPlugin = void 0;
60
+ var onInitExtension_1 = require("./onInitExtension");
61
+ var webpack_1 = require("./webpack");
62
+ var indexCollections_1 = require("./indexCollections");
63
+ var meilisearchPlugin = function (pluginOptions) {
64
+ return function (incomingConfig) {
65
+ var config = __assign({}, incomingConfig);
66
+ // If you need to add a webpack alias, use this function to extend the webpack config
67
+ var webpack = (0, webpack_1.extendWebpackConfig)(incomingConfig);
68
+ config.admin = __assign(__assign({}, (config.admin || {})), {
69
+ // If you extended the webpack config, add it back in here
70
+ // If you did not extend the webpack config, you can remove this line
71
+ webpack: webpack });
72
+ // If the plugin is disabled, return the config without modifying it
73
+ // The order of this check is important, we still want any webpack extensions to be applied even if the plugin is disabled
74
+ if (pluginOptions.enabled === false) {
75
+ return config;
76
+ }
77
+ config.collections = __spreadArray([], ((0, indexCollections_1.indexCollections)(config.collections || [], pluginOptions)), true);
78
+ config.endpoints = __spreadArray([], (config.endpoints || []), true);
79
+ config.globals = __spreadArray([], (config.globals || []), true);
80
+ config.hooks = __assign({}, (config.hooks || {}));
81
+ config.onInit = function (payload) { return __awaiter(void 0, void 0, void 0, function () {
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
84
+ case 0:
85
+ if (!incomingConfig.onInit) return [3 /*break*/, 2];
86
+ return [4 /*yield*/, incomingConfig.onInit(payload)
87
+ // Add additional onInit code by using the onInitExtension function
88
+ ];
89
+ case 1:
90
+ _a.sent();
91
+ _a.label = 2;
92
+ case 2:
93
+ // Add additional onInit code by using the onInitExtension function
94
+ (0, onInitExtension_1.onInitExtension)(pluginOptions, payload);
95
+ return [2 /*return*/];
96
+ }
97
+ });
98
+ }); };
99
+ return config;
100
+ };
101
+ };
102
+ exports.meilisearchPlugin = meilisearchP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wBACnE,IAAA,iCAAe,EAAC,aAAa,EAAE,OAAO,CAAC,CAAA;;;;aACxC,CAAA;QAED,OAAO,MAAM,CAAA;IACf,CAAC;AAvDD,CAuDC,CAAA;AAzDQ,QAAA,iBAAiB,qBAyDzB"}
@@ -0,0 +1,18 @@
1
+ export interface PluginTypes {
2
+ /**
3
+ * Enable or disable plugin
4
+ * @default false
5
+ */
6
+ enabled?: boolean;
7
+ host: string;
8
+ apiKey: string;
9
+ indexPrefix?: string;
10
+ collections?: PluginCollectionConfig[];
11
+ }
12
+ export interface PluginCollectionConfig {
13
+ slug: string;
14
+ shouldIndex?: (doc: any, previousDoc: any, locale?: string) => 'index' | 'delete' | 'ignore';
15
+ }
16
+ export interface NewCollectionTypes {
17
+ title: string;
18
+ }
package/dist/types.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ import type { Config } from 'payload/config';
2
+ import type { Configuration as WebpackConfig } from 'webpack';
3
+ export declare const extendWebpackConfig: (config: Config) => (webpackConfig: WebpackConfig) => WebpackConfig;
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.extendWebpackConfig = void 0;
18
+ var path_1 = __importDefault(require("path"));
19
+ var extendWebpackConfig = function (config) {
20
+ return function (webpackConfig) {
21
+ var _a;
22
+ var _b, _c;
23
+ var existingWebpackConfig = typeof ((_b = config.admin) === null || _b === void 0 ? void 0 : _b.webpack) === 'function'
24
+ ? config.admin.webpack(webpackConfig)
25
+ : webpackConfig;
26
+ var mockModulePath = path_1.default.resolve(__dirname, './mocks/mockFile.js');
27
+ var newWebpack = __assign(__assign({}, existingWebpackConfig), { resolve: __assign(__assign({}, (existingWebpackConfig.resolve || {})), { alias: __assign(__assign({}, (((_c = existingWebpackConfig.resolve) === null || _c === void 0 ? void 0 : _c.alias) ? existingWebpackConfig.resolve.alias : {})), (_a = {}, _a[path_1.default.resolve(__dirname, './yourFileHere')] = mockModulePath, _a)) }) });
28
+ return newWebpack;
29
+ };
30
+ };
31
+ exports.extendWebpackConfig = extendWebpackConfig;
32
+ //# sourceMappingURL=webpack.js.map