strapi-plugin-meilisearch 0.16.3 → 0.16.4
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/dist/_chunks/{App-BhTI1IHq.js → App-DN63hpzO.js} +1 -1
- package/dist/_chunks/{App-uVIng0zb.mjs → App-DsNeH1hv.mjs} +1 -1
- package/dist/_chunks/{index-BZdIA7-s.js → index-CAsW5hZR.js} +2 -2
- package/dist/_chunks/{index-BD6Pkv3X.mjs → index-L3fjpmC9.mjs} +2 -2
- package/dist/admin/index.js +1 -1
- package/dist/admin/index.mjs +1 -1
- package/dist/server/index.js +115 -199
- package/dist/server/index.mjs +115 -199
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const reactRouterDom = require("react-router-dom");
|
|
6
6
|
const admin = require("@strapi/strapi/admin");
|
|
7
|
-
const index = require("./index-
|
|
7
|
+
const index = require("./index-CAsW5hZR.js");
|
|
8
8
|
const designSystem = require("@strapi/design-system");
|
|
9
9
|
function _interopNamespace(e) {
|
|
10
10
|
if (e && e.__esModule) return e;
|
|
@@ -3,7 +3,7 @@ import * as React from "react";
|
|
|
3
3
|
import { useState, useEffect, memo } from "react";
|
|
4
4
|
import { Routes, Route } from "react-router-dom";
|
|
5
5
|
import { useNotification, useFetchClient, useRBAC, private_useAutoReloadOverlayBlocker, private_AutoReloadOverlayBlockerProvider, Page, Layouts, BackButton } from "@strapi/strapi/admin";
|
|
6
|
-
import { p as pluginId, P as PERMISSIONS } from "./index-
|
|
6
|
+
import { p as pluginId, P as PERMISSIONS } from "./index-L3fjpmC9.mjs";
|
|
7
7
|
import { Tr, Td, Checkbox, Typography, Flex, Box, Button, Thead, Th, VisuallyHidden, Table, Tbody, Field, Link, Tabs } from "@strapi/design-system";
|
|
8
8
|
var __assign = function() {
|
|
9
9
|
__assign = Object.assign || function __assign2(t) {
|
|
@@ -19,7 +19,7 @@ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
const name$1 = "strapi-plugin-meilisearch";
|
|
22
|
-
const version = "0.16.
|
|
22
|
+
const version = "0.16.4";
|
|
23
23
|
const description = "Synchronise and search in your Strapi content-types with Meilisearch";
|
|
24
24
|
const scripts = {
|
|
25
25
|
build: "strapi-plugin build",
|
|
@@ -216,7 +216,7 @@ const index = {
|
|
|
216
216
|
defaultMessage: name
|
|
217
217
|
},
|
|
218
218
|
Component: async () => {
|
|
219
|
-
const { App } = await Promise.resolve().then(() => require("./App-
|
|
219
|
+
const { App } = await Promise.resolve().then(() => require("./App-DN63hpzO.js"));
|
|
220
220
|
return App;
|
|
221
221
|
},
|
|
222
222
|
permissions: PERMISSIONS.main
|
|
@@ -18,7 +18,7 @@ const __variableDynamicImportRuntimeHelper = (glob, path, segs) => {
|
|
|
18
18
|
});
|
|
19
19
|
};
|
|
20
20
|
const name$1 = "strapi-plugin-meilisearch";
|
|
21
|
-
const version = "0.16.
|
|
21
|
+
const version = "0.16.4";
|
|
22
22
|
const description = "Synchronise and search in your Strapi content-types with Meilisearch";
|
|
23
23
|
const scripts = {
|
|
24
24
|
build: "strapi-plugin build",
|
|
@@ -215,7 +215,7 @@ const index = {
|
|
|
215
215
|
defaultMessage: name
|
|
216
216
|
},
|
|
217
217
|
Component: async () => {
|
|
218
|
-
const { App } = await import("./App-
|
|
218
|
+
const { App } = await import("./App-DsNeH1hv.mjs");
|
|
219
219
|
return App;
|
|
220
220
|
},
|
|
221
221
|
permissions: PERMISSIONS.main
|
package/dist/admin/index.js
CHANGED
package/dist/admin/index.mjs
CHANGED
package/dist/server/index.js
CHANGED
|
@@ -395,20 +395,12 @@ const rankStrapiEntryCandidates = (candidates) => {
|
|
|
395
395
|
const getActionLocale = (actionParams) => {
|
|
396
396
|
return typeof actionParams?.locale === "string" && actionParams.locale.length > 0 ? actionParams.locale : null;
|
|
397
397
|
};
|
|
398
|
-
const
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
}
|
|
403
|
-
const syncLocale = typeof syncQuery?.locale === "string" && syncQuery.locale.length > 0 ? syncQuery.locale : null;
|
|
404
|
-
if (syncLocale && !isWildcardLocale(syncLocale)) {
|
|
405
|
-
return syncLocale;
|
|
406
|
-
}
|
|
407
|
-
return null;
|
|
408
|
-
};
|
|
409
|
-
const resolveLocaleScopedReadQuery = ({ syncQuery, actionParams }) => {
|
|
398
|
+
const resolveLocaleScopedRefetchQuery = ({
|
|
399
|
+
indexingQuery,
|
|
400
|
+
actionParams
|
|
401
|
+
}) => {
|
|
410
402
|
const actionLocale = getActionLocale(actionParams);
|
|
411
|
-
const baseQuery = { ...
|
|
403
|
+
const baseQuery = { ...indexingQuery || {} };
|
|
412
404
|
if (!isWildcardLocale(baseQuery.locale) || actionLocale == null) {
|
|
413
405
|
return baseQuery;
|
|
414
406
|
}
|
|
@@ -435,25 +427,6 @@ const resolveLocaleCodesToRemoveFromIndex = ({
|
|
|
435
427
|
)
|
|
436
428
|
];
|
|
437
429
|
};
|
|
438
|
-
const resolveLocaleCodesToRemoveFromActionResult = ({
|
|
439
|
-
actionParams,
|
|
440
|
-
resultCandidates,
|
|
441
|
-
result,
|
|
442
|
-
documentId
|
|
443
|
-
}) => {
|
|
444
|
-
const entriesForDocument = (resultCandidates || []).map((candidate) => candidate?.data).filter((entry) => entry?.documentId === documentId);
|
|
445
|
-
const localeVariants = entriesForDocument.filter(
|
|
446
|
-
(entry) => typeof entry?.locale === "string" && entry.locale.length > 0
|
|
447
|
-
).map((entry) => ({ documentId: entry.documentId, locale: entry.locale }));
|
|
448
|
-
const preDeleteStrapiEntry = entriesForDocument.find(
|
|
449
|
-
(entry) => typeof entry?.locale === "string" && entry.locale.length > 0
|
|
450
|
-
) ?? (typeof result?.locale === "string" && result.locale.length > 0 ? result : entriesForDocument[0] ?? null);
|
|
451
|
-
return resolveLocaleCodesToRemoveFromIndex({
|
|
452
|
-
actionParams,
|
|
453
|
-
preDeleteStrapiEntry,
|
|
454
|
-
localeVariants
|
|
455
|
-
});
|
|
456
|
-
};
|
|
457
430
|
const collectLocaleCodesFromEntries = (entries) => {
|
|
458
431
|
return [
|
|
459
432
|
...new Set(
|
|
@@ -461,44 +434,6 @@ const collectLocaleCodesFromEntries = (entries) => {
|
|
|
461
434
|
)
|
|
462
435
|
];
|
|
463
436
|
};
|
|
464
|
-
const selectStrapiEntryToIndexFromResult = ({
|
|
465
|
-
resultCandidates,
|
|
466
|
-
documentId,
|
|
467
|
-
syncQuery,
|
|
468
|
-
actionParams
|
|
469
|
-
}) => {
|
|
470
|
-
const strapiDocumentEntryCandidates = (resultCandidates || []).filter(
|
|
471
|
-
(candidate) => candidate?.data?.documentId === documentId
|
|
472
|
-
);
|
|
473
|
-
if (strapiDocumentEntryCandidates.length === 0) return null;
|
|
474
|
-
const rankedEntryCandidates = rankStrapiEntryCandidates(
|
|
475
|
-
strapiDocumentEntryCandidates
|
|
476
|
-
);
|
|
477
|
-
const preferredConcreteLocale = resolvePreferredConcreteLocale({
|
|
478
|
-
syncQuery,
|
|
479
|
-
actionParams
|
|
480
|
-
});
|
|
481
|
-
const localeScopedEntryCandidate = preferredConcreteLocale ? rankedEntryCandidates.find(
|
|
482
|
-
(candidate) => candidate?.data?.locale === preferredConcreteLocale
|
|
483
|
-
) : null;
|
|
484
|
-
if (syncQuery?.status === "draft") {
|
|
485
|
-
const isIndexableDraftEntryCandidate = (candidate) => candidate?.data?.id != null && !isPublishedStrapiEntry(candidate.data);
|
|
486
|
-
if (preferredConcreteLocale) {
|
|
487
|
-
return localeScopedEntryCandidate && isIndexableDraftEntryCandidate(localeScopedEntryCandidate) ? localeScopedEntryCandidate.data : null;
|
|
488
|
-
}
|
|
489
|
-
const draftEntryCandidate = rankedEntryCandidates.find(
|
|
490
|
-
isIndexableDraftEntryCandidate
|
|
491
|
-
);
|
|
492
|
-
return draftEntryCandidate?.data || null;
|
|
493
|
-
}
|
|
494
|
-
if (preferredConcreteLocale) {
|
|
495
|
-
return localeScopedEntryCandidate && isPublishedStrapiEntry(localeScopedEntryCandidate.data) ? localeScopedEntryCandidate.data : null;
|
|
496
|
-
}
|
|
497
|
-
const publishedEntryCandidate = rankedEntryCandidates.find(
|
|
498
|
-
(candidate) => isPublishedStrapiEntry(candidate.data)
|
|
499
|
-
);
|
|
500
|
-
return publishedEntryCandidate?.data || null;
|
|
501
|
-
};
|
|
502
437
|
const selectDraftEntriesForDiscardDraftResult = ({
|
|
503
438
|
resultCandidates,
|
|
504
439
|
documentId,
|
|
@@ -534,51 +469,18 @@ const selectDraftEntriesForDiscardDraftResult = ({
|
|
|
534
469
|
rankedLocalizedDraftEntryCandidates[0]?.data || rankedDraftEntryCandidates[0].data
|
|
535
470
|
];
|
|
536
471
|
};
|
|
537
|
-
const
|
|
538
|
-
resultCandidates,
|
|
539
|
-
documentId,
|
|
540
|
-
actionParams,
|
|
541
|
-
syncQuery
|
|
542
|
-
}) => {
|
|
543
|
-
const actionLocale = getActionLocale(actionParams);
|
|
544
|
-
const syncLocale = syncQuery?.locale;
|
|
545
|
-
const syncStatusScope = syncQuery?.status;
|
|
546
|
-
const syncAllowsPublishedEntries = syncStatusScope == null || syncStatusScope !== "draft";
|
|
547
|
-
if (!actionLocale || !isWildcardLocale(actionLocale) || !isWildcardLocale(syncLocale) || !syncAllowsPublishedEntries) {
|
|
548
|
-
return [];
|
|
549
|
-
}
|
|
550
|
-
const rankedPublishedEntryCandidates = rankStrapiEntryCandidates(
|
|
551
|
-
(resultCandidates || []).filter(
|
|
552
|
-
(candidate) => candidate?.data?.documentId === documentId && isPublishedStrapiEntry(candidate.data)
|
|
553
|
-
)
|
|
554
|
-
);
|
|
555
|
-
if (rankedPublishedEntryCandidates.length === 0) return [];
|
|
556
|
-
const selectedEntries = [];
|
|
557
|
-
const seenKeys = /* @__PURE__ */ new Set();
|
|
558
|
-
rankedPublishedEntryCandidates.forEach((candidate) => {
|
|
559
|
-
const strapiEntry = candidate?.data;
|
|
560
|
-
if (!strapiEntry || typeof strapiEntry !== "object") return;
|
|
561
|
-
const localeKey = typeof strapiEntry.locale === "string" && strapiEntry.locale.length > 0 ? `locale:${strapiEntry.locale}` : null;
|
|
562
|
-
const idKey = strapiEntry.id != null ? `id:${strapiEntry.id}` : null;
|
|
563
|
-
const dedupeKey = localeKey || idKey;
|
|
564
|
-
if (!dedupeKey || seenKeys.has(dedupeKey)) return;
|
|
565
|
-
seenKeys.add(dedupeKey);
|
|
566
|
-
selectedEntries.push(strapiEntry);
|
|
567
|
-
});
|
|
568
|
-
return selectedEntries;
|
|
569
|
-
};
|
|
570
|
-
const getStrapiEntryAfterTransaction = ({
|
|
472
|
+
const fetchSingleEntryAfterTransaction = ({
|
|
571
473
|
contentTypeService: contentTypeService2,
|
|
572
474
|
contentType: contentType2,
|
|
573
475
|
documentId,
|
|
574
|
-
|
|
476
|
+
indexingQuery
|
|
575
477
|
}) => new Promise((resolve, reject) => {
|
|
576
478
|
setImmediate(async () => {
|
|
577
479
|
try {
|
|
578
480
|
const strapiEntry = await contentTypeService2.getEntry({
|
|
579
481
|
contentType: contentType2,
|
|
580
482
|
documentId,
|
|
581
|
-
entriesQuery: { ...
|
|
483
|
+
entriesQuery: { ...indexingQuery || {} }
|
|
582
484
|
});
|
|
583
485
|
resolve(strapiEntry);
|
|
584
486
|
} catch (error2) {
|
|
@@ -586,30 +488,47 @@ const getStrapiEntryAfterTransaction = ({
|
|
|
586
488
|
}
|
|
587
489
|
});
|
|
588
490
|
});
|
|
491
|
+
const fetchWildcardLocaleEntriesForIndexing = ({
|
|
492
|
+
contentTypeService: contentTypeService2,
|
|
493
|
+
contentType: contentType2,
|
|
494
|
+
documentId,
|
|
495
|
+
indexingQuery
|
|
496
|
+
}) => {
|
|
497
|
+
const baseIndexingQuery = indexingQuery || {};
|
|
498
|
+
return contentTypeService2.getEntries({
|
|
499
|
+
contentType: contentType2,
|
|
500
|
+
...baseIndexingQuery,
|
|
501
|
+
locale: "*",
|
|
502
|
+
filters: {
|
|
503
|
+
...baseIndexingQuery.filters || {},
|
|
504
|
+
documentId
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
};
|
|
589
508
|
const buildPreActionSnapshot = async ({
|
|
590
509
|
contentTypeService: contentTypeService2,
|
|
591
510
|
contentType: contentType2,
|
|
592
511
|
documentId,
|
|
593
|
-
|
|
512
|
+
indexingStatusFilter,
|
|
594
513
|
actionParams,
|
|
595
|
-
|
|
514
|
+
indexingQueryUsesWildcardLocale
|
|
596
515
|
}) => {
|
|
597
516
|
const preDeleteStrapiEntry = await contentTypeService2.getEntry({
|
|
598
517
|
contentType: contentType2,
|
|
599
518
|
documentId,
|
|
600
|
-
entriesQuery: { ...
|
|
519
|
+
entriesQuery: { ...indexingStatusFilter || {} }
|
|
601
520
|
});
|
|
602
|
-
const shouldFetchLocaleVariants =
|
|
521
|
+
const shouldFetchLocaleVariants = indexingQueryUsesWildcardLocale && isWildcardLocale(actionParams?.locale);
|
|
603
522
|
const localeVariants = shouldFetchLocaleVariants ? await contentTypeService2.getEntries({
|
|
604
523
|
contentType: contentType2,
|
|
605
524
|
fields: ["documentId", "locale"],
|
|
606
525
|
locale: "*",
|
|
607
|
-
...
|
|
526
|
+
...indexingStatusFilter || {},
|
|
608
527
|
filters: {
|
|
609
528
|
documentId
|
|
610
529
|
}
|
|
611
530
|
}) : [];
|
|
612
|
-
const localeCodesToRemove =
|
|
531
|
+
const localeCodesToRemove = indexingQueryUsesWildcardLocale ? resolveLocaleCodesToRemoveFromIndex({
|
|
613
532
|
actionParams,
|
|
614
533
|
preDeleteStrapiEntry,
|
|
615
534
|
localeVariants
|
|
@@ -625,9 +544,9 @@ const collectPreActionSnapshots = async ({
|
|
|
625
544
|
documentIds,
|
|
626
545
|
contentTypeService: contentTypeService2,
|
|
627
546
|
contentType: contentType2,
|
|
628
|
-
|
|
547
|
+
indexingStatusFilter,
|
|
629
548
|
actionParams,
|
|
630
|
-
|
|
549
|
+
indexingQueryUsesWildcardLocale
|
|
631
550
|
}) => {
|
|
632
551
|
return Promise.all(
|
|
633
552
|
documentIds.map(
|
|
@@ -635,9 +554,9 @@ const collectPreActionSnapshots = async ({
|
|
|
635
554
|
contentTypeService: contentTypeService2,
|
|
636
555
|
contentType: contentType2,
|
|
637
556
|
documentId,
|
|
638
|
-
|
|
557
|
+
indexingStatusFilter,
|
|
639
558
|
actionParams,
|
|
640
|
-
|
|
559
|
+
indexingQueryUsesWildcardLocale
|
|
641
560
|
})
|
|
642
561
|
)
|
|
643
562
|
);
|
|
@@ -652,8 +571,8 @@ const normalizeLocaleCodes = (localeCodes) => {
|
|
|
652
571
|
const dispatchDeleteTargets = async ({
|
|
653
572
|
meilisearch: meilisearch2,
|
|
654
573
|
contentType: contentType2,
|
|
655
|
-
|
|
656
|
-
|
|
574
|
+
indexingQuery,
|
|
575
|
+
indexingQueryUsesWildcardLocale,
|
|
657
576
|
targets
|
|
658
577
|
}) => {
|
|
659
578
|
const validTargets = (targets || []).filter(
|
|
@@ -662,7 +581,7 @@ const dispatchDeleteTargets = async ({
|
|
|
662
581
|
if (validTargets.length === 0) return;
|
|
663
582
|
const groupedTargets = /* @__PURE__ */ new Map();
|
|
664
583
|
validTargets.forEach((target) => {
|
|
665
|
-
const localeCodes =
|
|
584
|
+
const localeCodes = indexingQueryUsesWildcardLocale ? normalizeLocaleCodes(target.localeCodes) : [];
|
|
666
585
|
const groupKey = localeCodes.length > 0 ? [...localeCodes].sort().join("|") : "__no-locales__";
|
|
667
586
|
const currentGroup = groupedTargets.get(groupKey);
|
|
668
587
|
if (currentGroup) {
|
|
@@ -678,8 +597,8 @@ const dispatchDeleteTargets = async ({
|
|
|
678
597
|
await meilisearch2.deleteEntriesFromMeiliSearch({
|
|
679
598
|
contentType: contentType2,
|
|
680
599
|
documentIds: [...new Set(group.documentIds)],
|
|
681
|
-
entriesQuery:
|
|
682
|
-
locales:
|
|
600
|
+
entriesQuery: indexingQuery,
|
|
601
|
+
locales: indexingQueryUsesWildcardLocale && group.localeCodes.length > 0 ? group.localeCodes : void 0
|
|
683
602
|
});
|
|
684
603
|
}
|
|
685
604
|
};
|
|
@@ -708,26 +627,28 @@ async function registerDocumentMiddleware({ strapi: strapi2 }) {
|
|
|
708
627
|
"unpublish",
|
|
709
628
|
"discardDraft"
|
|
710
629
|
];
|
|
711
|
-
const
|
|
712
|
-
const
|
|
713
|
-
|
|
714
|
-
|
|
630
|
+
const indexingQuery = meilisearch2.entriesQuery({ contentType: contentType2 });
|
|
631
|
+
const indexingQueryUsesWildcardLocale = isWildcardLocale(
|
|
632
|
+
indexingQuery.locale
|
|
633
|
+
);
|
|
634
|
+
const { status } = indexingQuery || {};
|
|
635
|
+
const indexingStatusFilter = typeof status === "string" && status.length > 0 ? { status } : {};
|
|
715
636
|
const isDraftIndex = status === "draft";
|
|
716
637
|
const isPublishedIndex = status === "published";
|
|
717
638
|
const shouldSkipDeleteAction = ctx.action === "unpublish" && isDraftIndex || ctx.action === "discardDraft" && isPublishedIndex;
|
|
718
|
-
const
|
|
719
|
-
const
|
|
639
|
+
const shouldProcessAsRefetchFirstIndexingAction = updateActions.includes(ctx.action) || ctx.action === "discardDraft" && isDraftIndex;
|
|
640
|
+
const shouldProcessAsDeleteAction = deleteActions.includes(ctx.action) && !shouldProcessAsRefetchFirstIndexingAction && !shouldSkipDeleteAction;
|
|
720
641
|
const preActionDocumentIds = resolveDocumentIdsFromActionParams(
|
|
721
642
|
ctx?.params
|
|
722
643
|
);
|
|
723
|
-
const shouldCollectPreActionSnapshots =
|
|
644
|
+
const shouldCollectPreActionSnapshots = shouldProcessAsDeleteAction || ctx.action === "discardDraft" && isDraftIndex;
|
|
724
645
|
const preActionSnapshots = shouldCollectPreActionSnapshots ? await collectPreActionSnapshots({
|
|
725
646
|
documentIds: preActionDocumentIds,
|
|
726
647
|
contentTypeService: contentTypeService2,
|
|
727
648
|
contentType: contentType2,
|
|
728
|
-
|
|
649
|
+
indexingStatusFilter,
|
|
729
650
|
actionParams: ctx?.params,
|
|
730
|
-
|
|
651
|
+
indexingQueryUsesWildcardLocale
|
|
731
652
|
}) : [];
|
|
732
653
|
const preActionSnapshotsByDocumentId = new Map(
|
|
733
654
|
preActionSnapshots.map((snapshot) => [snapshot.documentId, snapshot])
|
|
@@ -738,60 +659,60 @@ async function registerDocumentMiddleware({ strapi: strapi2 }) {
|
|
|
738
659
|
result,
|
|
739
660
|
preActionSnapshots
|
|
740
661
|
});
|
|
741
|
-
if (
|
|
742
|
-
const
|
|
743
|
-
const
|
|
662
|
+
if (shouldProcessAsRefetchFirstIndexingAction && documentIds.length > 0) {
|
|
663
|
+
const actionResultCandidates = extractStrapiEntryCandidates(result);
|
|
664
|
+
const entriesToIndex = [];
|
|
744
665
|
const deleteTargets = [];
|
|
745
666
|
for (const documentId of documentIds) {
|
|
746
667
|
if (ctx.action === "discardDraft" && isDraftIndex) {
|
|
747
668
|
const preActionSnapshot = preActionSnapshotsByDocumentId.get(documentId) || null;
|
|
748
|
-
const
|
|
749
|
-
const shouldLoadDraftEntriesAcrossLocales =
|
|
750
|
-
const
|
|
751
|
-
resultCandidates,
|
|
669
|
+
const actionLocale2 = getActionLocale(ctx?.params);
|
|
670
|
+
const shouldLoadDraftEntriesAcrossLocales = indexingQueryUsesWildcardLocale && isWildcardLocale(actionLocale2);
|
|
671
|
+
const draftEntriesFromActionResult = selectDraftEntriesForDiscardDraftResult({
|
|
672
|
+
resultCandidates: actionResultCandidates,
|
|
752
673
|
documentId,
|
|
753
674
|
actionParams: ctx?.params
|
|
754
675
|
});
|
|
755
|
-
let
|
|
676
|
+
let draftEntriesToIndex = shouldLoadDraftEntriesAcrossLocales ? await contentTypeService2.getEntries({
|
|
756
677
|
contentType: contentType2,
|
|
757
678
|
locale: "*",
|
|
758
|
-
...
|
|
679
|
+
...indexingStatusFilter,
|
|
759
680
|
filters: {
|
|
760
681
|
documentId
|
|
761
682
|
}
|
|
762
|
-
}) :
|
|
763
|
-
|
|
683
|
+
}) : draftEntriesFromActionResult;
|
|
684
|
+
draftEntriesToIndex = (draftEntriesToIndex || []).filter(
|
|
764
685
|
(entry) => entry && !isPublishedStrapiEntry(entry)
|
|
765
686
|
);
|
|
766
|
-
if (
|
|
767
|
-
|
|
687
|
+
if (draftEntriesToIndex.length === 0 && shouldLoadDraftEntriesAcrossLocales) {
|
|
688
|
+
draftEntriesToIndex = draftEntriesFromActionResult;
|
|
768
689
|
}
|
|
769
|
-
if (
|
|
770
|
-
const
|
|
690
|
+
if (draftEntriesToIndex.length === 0 && !shouldLoadDraftEntriesAcrossLocales) {
|
|
691
|
+
const refetchedDraftEntry = await fetchSingleEntryAfterTransaction({
|
|
771
692
|
contentTypeService: contentTypeService2,
|
|
772
693
|
contentType: contentType2,
|
|
773
694
|
documentId,
|
|
774
|
-
|
|
775
|
-
|
|
695
|
+
indexingQuery: resolveLocaleScopedRefetchQuery({
|
|
696
|
+
indexingQuery,
|
|
776
697
|
actionParams: ctx?.params
|
|
777
698
|
})
|
|
778
699
|
});
|
|
779
|
-
if (
|
|
780
|
-
|
|
700
|
+
if (refetchedDraftEntry && !isPublishedStrapiEntry(refetchedDraftEntry)) {
|
|
701
|
+
draftEntriesToIndex = [refetchedDraftEntry];
|
|
781
702
|
}
|
|
782
703
|
}
|
|
783
|
-
if (
|
|
784
|
-
const normalizedDraftEntries =
|
|
704
|
+
if (draftEntriesToIndex.length > 0) {
|
|
705
|
+
const normalizedDraftEntries = draftEntriesToIndex.map(
|
|
785
706
|
(entry) => entry.documentId === documentId ? entry : { ...entry, documentId }
|
|
786
707
|
);
|
|
787
|
-
|
|
708
|
+
entriesToIndex.push(...normalizedDraftEntries);
|
|
788
709
|
}
|
|
789
710
|
const preActionLocaleCodes = resolveLocaleCodesToRemoveFromIndex({
|
|
790
711
|
actionParams: ctx?.params,
|
|
791
712
|
preDeleteStrapiEntry: preActionSnapshot?.preDeleteStrapiEntry || null,
|
|
792
713
|
localeVariants: preActionSnapshot?.localeVariants || []
|
|
793
714
|
});
|
|
794
|
-
const remainingLocaleCodes = collectLocaleCodesFromEntries(
|
|
715
|
+
const remainingLocaleCodes = collectLocaleCodesFromEntries(draftEntriesToIndex);
|
|
795
716
|
const localeCodesToDelete = preActionLocaleCodes.filter(
|
|
796
717
|
(localeCode) => !remainingLocaleCodes.includes(localeCode)
|
|
797
718
|
);
|
|
@@ -803,80 +724,75 @@ async function registerDocumentMiddleware({ strapi: strapi2 }) {
|
|
|
803
724
|
}
|
|
804
725
|
continue;
|
|
805
726
|
}
|
|
806
|
-
let
|
|
807
|
-
const
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
actionParams: ctx?.params,
|
|
811
|
-
syncQuery
|
|
812
|
-
});
|
|
813
|
-
if (publishedEntriesFromWildcardPublish.length > 0) {
|
|
814
|
-
entriesForDocument = publishedEntriesFromWildcardPublish;
|
|
815
|
-
}
|
|
816
|
-
let strapiEntry = selectStrapiEntryToIndexFromResult({
|
|
817
|
-
resultCandidates,
|
|
818
|
-
documentId,
|
|
819
|
-
syncQuery,
|
|
727
|
+
let refetchedEntriesForDocument = [];
|
|
728
|
+
const actionLocale = getActionLocale(ctx?.params);
|
|
729
|
+
const localeScopedRefetchQuery = resolveLocaleScopedRefetchQuery({
|
|
730
|
+
indexingQuery,
|
|
820
731
|
actionParams: ctx?.params
|
|
821
732
|
});
|
|
822
|
-
|
|
823
|
-
|
|
733
|
+
const indexingQueryStoresDrafts = indexingQuery?.status === "draft";
|
|
734
|
+
const shouldRefetchAllLocales = indexingQueryUsesWildcardLocale && isWildcardLocale(actionLocale) && isWildcardLocale(indexingQuery?.locale) && !indexingQueryStoresDrafts;
|
|
735
|
+
if (shouldRefetchAllLocales) {
|
|
736
|
+
refetchedEntriesForDocument = await fetchWildcardLocaleEntriesForIndexing({
|
|
824
737
|
contentTypeService: contentTypeService2,
|
|
825
738
|
contentType: contentType2,
|
|
826
739
|
documentId,
|
|
827
|
-
|
|
828
|
-
syncQuery,
|
|
829
|
-
actionParams: ctx?.params
|
|
830
|
-
})
|
|
740
|
+
indexingQuery
|
|
831
741
|
});
|
|
742
|
+
} else {
|
|
743
|
+
const refetchedStrapiEntry = await fetchSingleEntryAfterTransaction(
|
|
744
|
+
{
|
|
745
|
+
contentTypeService: contentTypeService2,
|
|
746
|
+
contentType: contentType2,
|
|
747
|
+
documentId,
|
|
748
|
+
indexingQuery: localeScopedRefetchQuery
|
|
749
|
+
}
|
|
750
|
+
);
|
|
751
|
+
if (refetchedStrapiEntry) {
|
|
752
|
+
refetchedEntriesForDocument = [refetchedStrapiEntry];
|
|
753
|
+
}
|
|
832
754
|
}
|
|
833
|
-
if (
|
|
834
|
-
|
|
835
|
-
}
|
|
836
|
-
if (entriesForDocument.length > 0) {
|
|
837
|
-
const normalizedEntries = entriesForDocument.map(
|
|
755
|
+
if (refetchedEntriesForDocument.length > 0) {
|
|
756
|
+
const normalizedEntries = refetchedEntriesForDocument.map(
|
|
838
757
|
(entry) => entry.documentId === documentId ? entry : { ...entry, documentId }
|
|
839
758
|
);
|
|
840
|
-
|
|
759
|
+
entriesToIndex.push(...normalizedEntries);
|
|
841
760
|
} else if (ctx.action === "create" || ctx.action === "publish") {
|
|
842
|
-
const createPublishLocaleCodesToRemove =
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
documentId,
|
|
850
|
-
localeCodes: createPublishLocaleCodesToRemove
|
|
851
|
-
});
|
|
761
|
+
const createPublishLocaleCodesToRemove = indexingQueryUsesWildcardLocale && typeof localeScopedRefetchQuery?.locale === "string" && localeScopedRefetchQuery.locale.length > 0 && !isWildcardLocale(localeScopedRefetchQuery.locale) ? [localeScopedRefetchQuery.locale] : [];
|
|
762
|
+
if (createPublishLocaleCodesToRemove.length > 0) {
|
|
763
|
+
deleteTargets.push({
|
|
764
|
+
documentId,
|
|
765
|
+
localeCodes: createPublishLocaleCodesToRemove
|
|
766
|
+
});
|
|
767
|
+
}
|
|
852
768
|
} else {
|
|
853
769
|
strapi2.log.info(
|
|
854
|
-
`Meilisearch document middleware skipped indexing ${contentType2} documentId=${documentId} for action ${ctx.action}: no indexable Strapi entry
|
|
770
|
+
`Meilisearch document middleware skipped indexing ${contentType2} documentId=${documentId} for action ${ctx.action}: no indexable Strapi entry after refetch`
|
|
855
771
|
);
|
|
856
772
|
}
|
|
857
773
|
}
|
|
858
|
-
if (
|
|
774
|
+
if (entriesToIndex.length > 0) {
|
|
859
775
|
await meilisearch2.updateEntriesInMeilisearch({
|
|
860
776
|
contentType: contentType2,
|
|
861
|
-
entries:
|
|
777
|
+
entries: entriesToIndex
|
|
862
778
|
});
|
|
863
779
|
}
|
|
864
780
|
if (deleteTargets.length > 0) {
|
|
865
781
|
await dispatchDeleteTargets({
|
|
866
782
|
meilisearch: meilisearch2,
|
|
867
783
|
contentType: contentType2,
|
|
868
|
-
|
|
869
|
-
|
|
784
|
+
indexingQuery,
|
|
785
|
+
indexingQueryUsesWildcardLocale,
|
|
870
786
|
targets: deleteTargets
|
|
871
787
|
});
|
|
872
788
|
}
|
|
873
|
-
} else if (
|
|
789
|
+
} else if (shouldProcessAsDeleteAction) {
|
|
874
790
|
if (documentIds.length > 0) {
|
|
875
791
|
const deleteTargets = documentIds.map((documentId) => {
|
|
876
792
|
const preActionSnapshot = preActionSnapshotsByDocumentId.get(documentId) || null;
|
|
877
793
|
return {
|
|
878
794
|
documentId,
|
|
879
|
-
localeCodes:
|
|
795
|
+
localeCodes: indexingQueryUsesWildcardLocale ? preActionSnapshot?.localeCodesToRemove || [] : []
|
|
880
796
|
};
|
|
881
797
|
});
|
|
882
798
|
strapi2.log.info(
|
|
@@ -885,8 +801,8 @@ async function registerDocumentMiddleware({ strapi: strapi2 }) {
|
|
|
885
801
|
await dispatchDeleteTargets({
|
|
886
802
|
meilisearch: meilisearch2,
|
|
887
803
|
contentType: contentType2,
|
|
888
|
-
|
|
889
|
-
|
|
804
|
+
indexingQuery,
|
|
805
|
+
indexingQueryUsesWildcardLocale,
|
|
890
806
|
targets: deleteTargets
|
|
891
807
|
});
|
|
892
808
|
} else {
|
|
@@ -2022,7 +1938,7 @@ const store = ({ strapi: strapi2 }) => {
|
|
|
2022
1938
|
...createStoreConnector({ strapi: strapi2 })
|
|
2023
1939
|
};
|
|
2024
1940
|
};
|
|
2025
|
-
const version = "0.16.
|
|
1941
|
+
const version = "0.16.4";
|
|
2026
1942
|
const Meilisearch = (config2) => {
|
|
2027
1943
|
return new meilisearch$1.MeiliSearch({
|
|
2028
1944
|
...config2,
|
package/dist/server/index.mjs
CHANGED
|
@@ -394,20 +394,12 @@ const rankStrapiEntryCandidates = (candidates) => {
|
|
|
394
394
|
const getActionLocale = (actionParams) => {
|
|
395
395
|
return typeof actionParams?.locale === "string" && actionParams.locale.length > 0 ? actionParams.locale : null;
|
|
396
396
|
};
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
}
|
|
402
|
-
const syncLocale = typeof syncQuery?.locale === "string" && syncQuery.locale.length > 0 ? syncQuery.locale : null;
|
|
403
|
-
if (syncLocale && !isWildcardLocale(syncLocale)) {
|
|
404
|
-
return syncLocale;
|
|
405
|
-
}
|
|
406
|
-
return null;
|
|
407
|
-
};
|
|
408
|
-
const resolveLocaleScopedReadQuery = ({ syncQuery, actionParams }) => {
|
|
397
|
+
const resolveLocaleScopedRefetchQuery = ({
|
|
398
|
+
indexingQuery,
|
|
399
|
+
actionParams
|
|
400
|
+
}) => {
|
|
409
401
|
const actionLocale = getActionLocale(actionParams);
|
|
410
|
-
const baseQuery = { ...
|
|
402
|
+
const baseQuery = { ...indexingQuery || {} };
|
|
411
403
|
if (!isWildcardLocale(baseQuery.locale) || actionLocale == null) {
|
|
412
404
|
return baseQuery;
|
|
413
405
|
}
|
|
@@ -434,25 +426,6 @@ const resolveLocaleCodesToRemoveFromIndex = ({
|
|
|
434
426
|
)
|
|
435
427
|
];
|
|
436
428
|
};
|
|
437
|
-
const resolveLocaleCodesToRemoveFromActionResult = ({
|
|
438
|
-
actionParams,
|
|
439
|
-
resultCandidates,
|
|
440
|
-
result,
|
|
441
|
-
documentId
|
|
442
|
-
}) => {
|
|
443
|
-
const entriesForDocument = (resultCandidates || []).map((candidate) => candidate?.data).filter((entry) => entry?.documentId === documentId);
|
|
444
|
-
const localeVariants = entriesForDocument.filter(
|
|
445
|
-
(entry) => typeof entry?.locale === "string" && entry.locale.length > 0
|
|
446
|
-
).map((entry) => ({ documentId: entry.documentId, locale: entry.locale }));
|
|
447
|
-
const preDeleteStrapiEntry = entriesForDocument.find(
|
|
448
|
-
(entry) => typeof entry?.locale === "string" && entry.locale.length > 0
|
|
449
|
-
) ?? (typeof result?.locale === "string" && result.locale.length > 0 ? result : entriesForDocument[0] ?? null);
|
|
450
|
-
return resolveLocaleCodesToRemoveFromIndex({
|
|
451
|
-
actionParams,
|
|
452
|
-
preDeleteStrapiEntry,
|
|
453
|
-
localeVariants
|
|
454
|
-
});
|
|
455
|
-
};
|
|
456
429
|
const collectLocaleCodesFromEntries = (entries) => {
|
|
457
430
|
return [
|
|
458
431
|
...new Set(
|
|
@@ -460,44 +433,6 @@ const collectLocaleCodesFromEntries = (entries) => {
|
|
|
460
433
|
)
|
|
461
434
|
];
|
|
462
435
|
};
|
|
463
|
-
const selectStrapiEntryToIndexFromResult = ({
|
|
464
|
-
resultCandidates,
|
|
465
|
-
documentId,
|
|
466
|
-
syncQuery,
|
|
467
|
-
actionParams
|
|
468
|
-
}) => {
|
|
469
|
-
const strapiDocumentEntryCandidates = (resultCandidates || []).filter(
|
|
470
|
-
(candidate) => candidate?.data?.documentId === documentId
|
|
471
|
-
);
|
|
472
|
-
if (strapiDocumentEntryCandidates.length === 0) return null;
|
|
473
|
-
const rankedEntryCandidates = rankStrapiEntryCandidates(
|
|
474
|
-
strapiDocumentEntryCandidates
|
|
475
|
-
);
|
|
476
|
-
const preferredConcreteLocale = resolvePreferredConcreteLocale({
|
|
477
|
-
syncQuery,
|
|
478
|
-
actionParams
|
|
479
|
-
});
|
|
480
|
-
const localeScopedEntryCandidate = preferredConcreteLocale ? rankedEntryCandidates.find(
|
|
481
|
-
(candidate) => candidate?.data?.locale === preferredConcreteLocale
|
|
482
|
-
) : null;
|
|
483
|
-
if (syncQuery?.status === "draft") {
|
|
484
|
-
const isIndexableDraftEntryCandidate = (candidate) => candidate?.data?.id != null && !isPublishedStrapiEntry(candidate.data);
|
|
485
|
-
if (preferredConcreteLocale) {
|
|
486
|
-
return localeScopedEntryCandidate && isIndexableDraftEntryCandidate(localeScopedEntryCandidate) ? localeScopedEntryCandidate.data : null;
|
|
487
|
-
}
|
|
488
|
-
const draftEntryCandidate = rankedEntryCandidates.find(
|
|
489
|
-
isIndexableDraftEntryCandidate
|
|
490
|
-
);
|
|
491
|
-
return draftEntryCandidate?.data || null;
|
|
492
|
-
}
|
|
493
|
-
if (preferredConcreteLocale) {
|
|
494
|
-
return localeScopedEntryCandidate && isPublishedStrapiEntry(localeScopedEntryCandidate.data) ? localeScopedEntryCandidate.data : null;
|
|
495
|
-
}
|
|
496
|
-
const publishedEntryCandidate = rankedEntryCandidates.find(
|
|
497
|
-
(candidate) => isPublishedStrapiEntry(candidate.data)
|
|
498
|
-
);
|
|
499
|
-
return publishedEntryCandidate?.data || null;
|
|
500
|
-
};
|
|
501
436
|
const selectDraftEntriesForDiscardDraftResult = ({
|
|
502
437
|
resultCandidates,
|
|
503
438
|
documentId,
|
|
@@ -533,51 +468,18 @@ const selectDraftEntriesForDiscardDraftResult = ({
|
|
|
533
468
|
rankedLocalizedDraftEntryCandidates[0]?.data || rankedDraftEntryCandidates[0].data
|
|
534
469
|
];
|
|
535
470
|
};
|
|
536
|
-
const
|
|
537
|
-
resultCandidates,
|
|
538
|
-
documentId,
|
|
539
|
-
actionParams,
|
|
540
|
-
syncQuery
|
|
541
|
-
}) => {
|
|
542
|
-
const actionLocale = getActionLocale(actionParams);
|
|
543
|
-
const syncLocale = syncQuery?.locale;
|
|
544
|
-
const syncStatusScope = syncQuery?.status;
|
|
545
|
-
const syncAllowsPublishedEntries = syncStatusScope == null || syncStatusScope !== "draft";
|
|
546
|
-
if (!actionLocale || !isWildcardLocale(actionLocale) || !isWildcardLocale(syncLocale) || !syncAllowsPublishedEntries) {
|
|
547
|
-
return [];
|
|
548
|
-
}
|
|
549
|
-
const rankedPublishedEntryCandidates = rankStrapiEntryCandidates(
|
|
550
|
-
(resultCandidates || []).filter(
|
|
551
|
-
(candidate) => candidate?.data?.documentId === documentId && isPublishedStrapiEntry(candidate.data)
|
|
552
|
-
)
|
|
553
|
-
);
|
|
554
|
-
if (rankedPublishedEntryCandidates.length === 0) return [];
|
|
555
|
-
const selectedEntries = [];
|
|
556
|
-
const seenKeys = /* @__PURE__ */ new Set();
|
|
557
|
-
rankedPublishedEntryCandidates.forEach((candidate) => {
|
|
558
|
-
const strapiEntry = candidate?.data;
|
|
559
|
-
if (!strapiEntry || typeof strapiEntry !== "object") return;
|
|
560
|
-
const localeKey = typeof strapiEntry.locale === "string" && strapiEntry.locale.length > 0 ? `locale:${strapiEntry.locale}` : null;
|
|
561
|
-
const idKey = strapiEntry.id != null ? `id:${strapiEntry.id}` : null;
|
|
562
|
-
const dedupeKey = localeKey || idKey;
|
|
563
|
-
if (!dedupeKey || seenKeys.has(dedupeKey)) return;
|
|
564
|
-
seenKeys.add(dedupeKey);
|
|
565
|
-
selectedEntries.push(strapiEntry);
|
|
566
|
-
});
|
|
567
|
-
return selectedEntries;
|
|
568
|
-
};
|
|
569
|
-
const getStrapiEntryAfterTransaction = ({
|
|
471
|
+
const fetchSingleEntryAfterTransaction = ({
|
|
570
472
|
contentTypeService: contentTypeService2,
|
|
571
473
|
contentType: contentType2,
|
|
572
474
|
documentId,
|
|
573
|
-
|
|
475
|
+
indexingQuery
|
|
574
476
|
}) => new Promise((resolve, reject) => {
|
|
575
477
|
setImmediate(async () => {
|
|
576
478
|
try {
|
|
577
479
|
const strapiEntry = await contentTypeService2.getEntry({
|
|
578
480
|
contentType: contentType2,
|
|
579
481
|
documentId,
|
|
580
|
-
entriesQuery: { ...
|
|
482
|
+
entriesQuery: { ...indexingQuery || {} }
|
|
581
483
|
});
|
|
582
484
|
resolve(strapiEntry);
|
|
583
485
|
} catch (error2) {
|
|
@@ -585,30 +487,47 @@ const getStrapiEntryAfterTransaction = ({
|
|
|
585
487
|
}
|
|
586
488
|
});
|
|
587
489
|
});
|
|
490
|
+
const fetchWildcardLocaleEntriesForIndexing = ({
|
|
491
|
+
contentTypeService: contentTypeService2,
|
|
492
|
+
contentType: contentType2,
|
|
493
|
+
documentId,
|
|
494
|
+
indexingQuery
|
|
495
|
+
}) => {
|
|
496
|
+
const baseIndexingQuery = indexingQuery || {};
|
|
497
|
+
return contentTypeService2.getEntries({
|
|
498
|
+
contentType: contentType2,
|
|
499
|
+
...baseIndexingQuery,
|
|
500
|
+
locale: "*",
|
|
501
|
+
filters: {
|
|
502
|
+
...baseIndexingQuery.filters || {},
|
|
503
|
+
documentId
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
};
|
|
588
507
|
const buildPreActionSnapshot = async ({
|
|
589
508
|
contentTypeService: contentTypeService2,
|
|
590
509
|
contentType: contentType2,
|
|
591
510
|
documentId,
|
|
592
|
-
|
|
511
|
+
indexingStatusFilter,
|
|
593
512
|
actionParams,
|
|
594
|
-
|
|
513
|
+
indexingQueryUsesWildcardLocale
|
|
595
514
|
}) => {
|
|
596
515
|
const preDeleteStrapiEntry = await contentTypeService2.getEntry({
|
|
597
516
|
contentType: contentType2,
|
|
598
517
|
documentId,
|
|
599
|
-
entriesQuery: { ...
|
|
518
|
+
entriesQuery: { ...indexingStatusFilter || {} }
|
|
600
519
|
});
|
|
601
|
-
const shouldFetchLocaleVariants =
|
|
520
|
+
const shouldFetchLocaleVariants = indexingQueryUsesWildcardLocale && isWildcardLocale(actionParams?.locale);
|
|
602
521
|
const localeVariants = shouldFetchLocaleVariants ? await contentTypeService2.getEntries({
|
|
603
522
|
contentType: contentType2,
|
|
604
523
|
fields: ["documentId", "locale"],
|
|
605
524
|
locale: "*",
|
|
606
|
-
...
|
|
525
|
+
...indexingStatusFilter || {},
|
|
607
526
|
filters: {
|
|
608
527
|
documentId
|
|
609
528
|
}
|
|
610
529
|
}) : [];
|
|
611
|
-
const localeCodesToRemove =
|
|
530
|
+
const localeCodesToRemove = indexingQueryUsesWildcardLocale ? resolveLocaleCodesToRemoveFromIndex({
|
|
612
531
|
actionParams,
|
|
613
532
|
preDeleteStrapiEntry,
|
|
614
533
|
localeVariants
|
|
@@ -624,9 +543,9 @@ const collectPreActionSnapshots = async ({
|
|
|
624
543
|
documentIds,
|
|
625
544
|
contentTypeService: contentTypeService2,
|
|
626
545
|
contentType: contentType2,
|
|
627
|
-
|
|
546
|
+
indexingStatusFilter,
|
|
628
547
|
actionParams,
|
|
629
|
-
|
|
548
|
+
indexingQueryUsesWildcardLocale
|
|
630
549
|
}) => {
|
|
631
550
|
return Promise.all(
|
|
632
551
|
documentIds.map(
|
|
@@ -634,9 +553,9 @@ const collectPreActionSnapshots = async ({
|
|
|
634
553
|
contentTypeService: contentTypeService2,
|
|
635
554
|
contentType: contentType2,
|
|
636
555
|
documentId,
|
|
637
|
-
|
|
556
|
+
indexingStatusFilter,
|
|
638
557
|
actionParams,
|
|
639
|
-
|
|
558
|
+
indexingQueryUsesWildcardLocale
|
|
640
559
|
})
|
|
641
560
|
)
|
|
642
561
|
);
|
|
@@ -651,8 +570,8 @@ const normalizeLocaleCodes = (localeCodes) => {
|
|
|
651
570
|
const dispatchDeleteTargets = async ({
|
|
652
571
|
meilisearch: meilisearch2,
|
|
653
572
|
contentType: contentType2,
|
|
654
|
-
|
|
655
|
-
|
|
573
|
+
indexingQuery,
|
|
574
|
+
indexingQueryUsesWildcardLocale,
|
|
656
575
|
targets
|
|
657
576
|
}) => {
|
|
658
577
|
const validTargets = (targets || []).filter(
|
|
@@ -661,7 +580,7 @@ const dispatchDeleteTargets = async ({
|
|
|
661
580
|
if (validTargets.length === 0) return;
|
|
662
581
|
const groupedTargets = /* @__PURE__ */ new Map();
|
|
663
582
|
validTargets.forEach((target) => {
|
|
664
|
-
const localeCodes =
|
|
583
|
+
const localeCodes = indexingQueryUsesWildcardLocale ? normalizeLocaleCodes(target.localeCodes) : [];
|
|
665
584
|
const groupKey = localeCodes.length > 0 ? [...localeCodes].sort().join("|") : "__no-locales__";
|
|
666
585
|
const currentGroup = groupedTargets.get(groupKey);
|
|
667
586
|
if (currentGroup) {
|
|
@@ -677,8 +596,8 @@ const dispatchDeleteTargets = async ({
|
|
|
677
596
|
await meilisearch2.deleteEntriesFromMeiliSearch({
|
|
678
597
|
contentType: contentType2,
|
|
679
598
|
documentIds: [...new Set(group.documentIds)],
|
|
680
|
-
entriesQuery:
|
|
681
|
-
locales:
|
|
599
|
+
entriesQuery: indexingQuery,
|
|
600
|
+
locales: indexingQueryUsesWildcardLocale && group.localeCodes.length > 0 ? group.localeCodes : void 0
|
|
682
601
|
});
|
|
683
602
|
}
|
|
684
603
|
};
|
|
@@ -707,26 +626,28 @@ async function registerDocumentMiddleware({ strapi: strapi2 }) {
|
|
|
707
626
|
"unpublish",
|
|
708
627
|
"discardDraft"
|
|
709
628
|
];
|
|
710
|
-
const
|
|
711
|
-
const
|
|
712
|
-
|
|
713
|
-
|
|
629
|
+
const indexingQuery = meilisearch2.entriesQuery({ contentType: contentType2 });
|
|
630
|
+
const indexingQueryUsesWildcardLocale = isWildcardLocale(
|
|
631
|
+
indexingQuery.locale
|
|
632
|
+
);
|
|
633
|
+
const { status } = indexingQuery || {};
|
|
634
|
+
const indexingStatusFilter = typeof status === "string" && status.length > 0 ? { status } : {};
|
|
714
635
|
const isDraftIndex = status === "draft";
|
|
715
636
|
const isPublishedIndex = status === "published";
|
|
716
637
|
const shouldSkipDeleteAction = ctx.action === "unpublish" && isDraftIndex || ctx.action === "discardDraft" && isPublishedIndex;
|
|
717
|
-
const
|
|
718
|
-
const
|
|
638
|
+
const shouldProcessAsRefetchFirstIndexingAction = updateActions.includes(ctx.action) || ctx.action === "discardDraft" && isDraftIndex;
|
|
639
|
+
const shouldProcessAsDeleteAction = deleteActions.includes(ctx.action) && !shouldProcessAsRefetchFirstIndexingAction && !shouldSkipDeleteAction;
|
|
719
640
|
const preActionDocumentIds = resolveDocumentIdsFromActionParams(
|
|
720
641
|
ctx?.params
|
|
721
642
|
);
|
|
722
|
-
const shouldCollectPreActionSnapshots =
|
|
643
|
+
const shouldCollectPreActionSnapshots = shouldProcessAsDeleteAction || ctx.action === "discardDraft" && isDraftIndex;
|
|
723
644
|
const preActionSnapshots = shouldCollectPreActionSnapshots ? await collectPreActionSnapshots({
|
|
724
645
|
documentIds: preActionDocumentIds,
|
|
725
646
|
contentTypeService: contentTypeService2,
|
|
726
647
|
contentType: contentType2,
|
|
727
|
-
|
|
648
|
+
indexingStatusFilter,
|
|
728
649
|
actionParams: ctx?.params,
|
|
729
|
-
|
|
650
|
+
indexingQueryUsesWildcardLocale
|
|
730
651
|
}) : [];
|
|
731
652
|
const preActionSnapshotsByDocumentId = new Map(
|
|
732
653
|
preActionSnapshots.map((snapshot) => [snapshot.documentId, snapshot])
|
|
@@ -737,60 +658,60 @@ async function registerDocumentMiddleware({ strapi: strapi2 }) {
|
|
|
737
658
|
result,
|
|
738
659
|
preActionSnapshots
|
|
739
660
|
});
|
|
740
|
-
if (
|
|
741
|
-
const
|
|
742
|
-
const
|
|
661
|
+
if (shouldProcessAsRefetchFirstIndexingAction && documentIds.length > 0) {
|
|
662
|
+
const actionResultCandidates = extractStrapiEntryCandidates(result);
|
|
663
|
+
const entriesToIndex = [];
|
|
743
664
|
const deleteTargets = [];
|
|
744
665
|
for (const documentId of documentIds) {
|
|
745
666
|
if (ctx.action === "discardDraft" && isDraftIndex) {
|
|
746
667
|
const preActionSnapshot = preActionSnapshotsByDocumentId.get(documentId) || null;
|
|
747
|
-
const
|
|
748
|
-
const shouldLoadDraftEntriesAcrossLocales =
|
|
749
|
-
const
|
|
750
|
-
resultCandidates,
|
|
668
|
+
const actionLocale2 = getActionLocale(ctx?.params);
|
|
669
|
+
const shouldLoadDraftEntriesAcrossLocales = indexingQueryUsesWildcardLocale && isWildcardLocale(actionLocale2);
|
|
670
|
+
const draftEntriesFromActionResult = selectDraftEntriesForDiscardDraftResult({
|
|
671
|
+
resultCandidates: actionResultCandidates,
|
|
751
672
|
documentId,
|
|
752
673
|
actionParams: ctx?.params
|
|
753
674
|
});
|
|
754
|
-
let
|
|
675
|
+
let draftEntriesToIndex = shouldLoadDraftEntriesAcrossLocales ? await contentTypeService2.getEntries({
|
|
755
676
|
contentType: contentType2,
|
|
756
677
|
locale: "*",
|
|
757
|
-
...
|
|
678
|
+
...indexingStatusFilter,
|
|
758
679
|
filters: {
|
|
759
680
|
documentId
|
|
760
681
|
}
|
|
761
|
-
}) :
|
|
762
|
-
|
|
682
|
+
}) : draftEntriesFromActionResult;
|
|
683
|
+
draftEntriesToIndex = (draftEntriesToIndex || []).filter(
|
|
763
684
|
(entry) => entry && !isPublishedStrapiEntry(entry)
|
|
764
685
|
);
|
|
765
|
-
if (
|
|
766
|
-
|
|
686
|
+
if (draftEntriesToIndex.length === 0 && shouldLoadDraftEntriesAcrossLocales) {
|
|
687
|
+
draftEntriesToIndex = draftEntriesFromActionResult;
|
|
767
688
|
}
|
|
768
|
-
if (
|
|
769
|
-
const
|
|
689
|
+
if (draftEntriesToIndex.length === 0 && !shouldLoadDraftEntriesAcrossLocales) {
|
|
690
|
+
const refetchedDraftEntry = await fetchSingleEntryAfterTransaction({
|
|
770
691
|
contentTypeService: contentTypeService2,
|
|
771
692
|
contentType: contentType2,
|
|
772
693
|
documentId,
|
|
773
|
-
|
|
774
|
-
|
|
694
|
+
indexingQuery: resolveLocaleScopedRefetchQuery({
|
|
695
|
+
indexingQuery,
|
|
775
696
|
actionParams: ctx?.params
|
|
776
697
|
})
|
|
777
698
|
});
|
|
778
|
-
if (
|
|
779
|
-
|
|
699
|
+
if (refetchedDraftEntry && !isPublishedStrapiEntry(refetchedDraftEntry)) {
|
|
700
|
+
draftEntriesToIndex = [refetchedDraftEntry];
|
|
780
701
|
}
|
|
781
702
|
}
|
|
782
|
-
if (
|
|
783
|
-
const normalizedDraftEntries =
|
|
703
|
+
if (draftEntriesToIndex.length > 0) {
|
|
704
|
+
const normalizedDraftEntries = draftEntriesToIndex.map(
|
|
784
705
|
(entry) => entry.documentId === documentId ? entry : { ...entry, documentId }
|
|
785
706
|
);
|
|
786
|
-
|
|
707
|
+
entriesToIndex.push(...normalizedDraftEntries);
|
|
787
708
|
}
|
|
788
709
|
const preActionLocaleCodes = resolveLocaleCodesToRemoveFromIndex({
|
|
789
710
|
actionParams: ctx?.params,
|
|
790
711
|
preDeleteStrapiEntry: preActionSnapshot?.preDeleteStrapiEntry || null,
|
|
791
712
|
localeVariants: preActionSnapshot?.localeVariants || []
|
|
792
713
|
});
|
|
793
|
-
const remainingLocaleCodes = collectLocaleCodesFromEntries(
|
|
714
|
+
const remainingLocaleCodes = collectLocaleCodesFromEntries(draftEntriesToIndex);
|
|
794
715
|
const localeCodesToDelete = preActionLocaleCodes.filter(
|
|
795
716
|
(localeCode) => !remainingLocaleCodes.includes(localeCode)
|
|
796
717
|
);
|
|
@@ -802,80 +723,75 @@ async function registerDocumentMiddleware({ strapi: strapi2 }) {
|
|
|
802
723
|
}
|
|
803
724
|
continue;
|
|
804
725
|
}
|
|
805
|
-
let
|
|
806
|
-
const
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
actionParams: ctx?.params,
|
|
810
|
-
syncQuery
|
|
811
|
-
});
|
|
812
|
-
if (publishedEntriesFromWildcardPublish.length > 0) {
|
|
813
|
-
entriesForDocument = publishedEntriesFromWildcardPublish;
|
|
814
|
-
}
|
|
815
|
-
let strapiEntry = selectStrapiEntryToIndexFromResult({
|
|
816
|
-
resultCandidates,
|
|
817
|
-
documentId,
|
|
818
|
-
syncQuery,
|
|
726
|
+
let refetchedEntriesForDocument = [];
|
|
727
|
+
const actionLocale = getActionLocale(ctx?.params);
|
|
728
|
+
const localeScopedRefetchQuery = resolveLocaleScopedRefetchQuery({
|
|
729
|
+
indexingQuery,
|
|
819
730
|
actionParams: ctx?.params
|
|
820
731
|
});
|
|
821
|
-
|
|
822
|
-
|
|
732
|
+
const indexingQueryStoresDrafts = indexingQuery?.status === "draft";
|
|
733
|
+
const shouldRefetchAllLocales = indexingQueryUsesWildcardLocale && isWildcardLocale(actionLocale) && isWildcardLocale(indexingQuery?.locale) && !indexingQueryStoresDrafts;
|
|
734
|
+
if (shouldRefetchAllLocales) {
|
|
735
|
+
refetchedEntriesForDocument = await fetchWildcardLocaleEntriesForIndexing({
|
|
823
736
|
contentTypeService: contentTypeService2,
|
|
824
737
|
contentType: contentType2,
|
|
825
738
|
documentId,
|
|
826
|
-
|
|
827
|
-
syncQuery,
|
|
828
|
-
actionParams: ctx?.params
|
|
829
|
-
})
|
|
739
|
+
indexingQuery
|
|
830
740
|
});
|
|
741
|
+
} else {
|
|
742
|
+
const refetchedStrapiEntry = await fetchSingleEntryAfterTransaction(
|
|
743
|
+
{
|
|
744
|
+
contentTypeService: contentTypeService2,
|
|
745
|
+
contentType: contentType2,
|
|
746
|
+
documentId,
|
|
747
|
+
indexingQuery: localeScopedRefetchQuery
|
|
748
|
+
}
|
|
749
|
+
);
|
|
750
|
+
if (refetchedStrapiEntry) {
|
|
751
|
+
refetchedEntriesForDocument = [refetchedStrapiEntry];
|
|
752
|
+
}
|
|
831
753
|
}
|
|
832
|
-
if (
|
|
833
|
-
|
|
834
|
-
}
|
|
835
|
-
if (entriesForDocument.length > 0) {
|
|
836
|
-
const normalizedEntries = entriesForDocument.map(
|
|
754
|
+
if (refetchedEntriesForDocument.length > 0) {
|
|
755
|
+
const normalizedEntries = refetchedEntriesForDocument.map(
|
|
837
756
|
(entry) => entry.documentId === documentId ? entry : { ...entry, documentId }
|
|
838
757
|
);
|
|
839
|
-
|
|
758
|
+
entriesToIndex.push(...normalizedEntries);
|
|
840
759
|
} else if (ctx.action === "create" || ctx.action === "publish") {
|
|
841
|
-
const createPublishLocaleCodesToRemove =
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
documentId,
|
|
849
|
-
localeCodes: createPublishLocaleCodesToRemove
|
|
850
|
-
});
|
|
760
|
+
const createPublishLocaleCodesToRemove = indexingQueryUsesWildcardLocale && typeof localeScopedRefetchQuery?.locale === "string" && localeScopedRefetchQuery.locale.length > 0 && !isWildcardLocale(localeScopedRefetchQuery.locale) ? [localeScopedRefetchQuery.locale] : [];
|
|
761
|
+
if (createPublishLocaleCodesToRemove.length > 0) {
|
|
762
|
+
deleteTargets.push({
|
|
763
|
+
documentId,
|
|
764
|
+
localeCodes: createPublishLocaleCodesToRemove
|
|
765
|
+
});
|
|
766
|
+
}
|
|
851
767
|
} else {
|
|
852
768
|
strapi2.log.info(
|
|
853
|
-
`Meilisearch document middleware skipped indexing ${contentType2} documentId=${documentId} for action ${ctx.action}: no indexable Strapi entry
|
|
769
|
+
`Meilisearch document middleware skipped indexing ${contentType2} documentId=${documentId} for action ${ctx.action}: no indexable Strapi entry after refetch`
|
|
854
770
|
);
|
|
855
771
|
}
|
|
856
772
|
}
|
|
857
|
-
if (
|
|
773
|
+
if (entriesToIndex.length > 0) {
|
|
858
774
|
await meilisearch2.updateEntriesInMeilisearch({
|
|
859
775
|
contentType: contentType2,
|
|
860
|
-
entries:
|
|
776
|
+
entries: entriesToIndex
|
|
861
777
|
});
|
|
862
778
|
}
|
|
863
779
|
if (deleteTargets.length > 0) {
|
|
864
780
|
await dispatchDeleteTargets({
|
|
865
781
|
meilisearch: meilisearch2,
|
|
866
782
|
contentType: contentType2,
|
|
867
|
-
|
|
868
|
-
|
|
783
|
+
indexingQuery,
|
|
784
|
+
indexingQueryUsesWildcardLocale,
|
|
869
785
|
targets: deleteTargets
|
|
870
786
|
});
|
|
871
787
|
}
|
|
872
|
-
} else if (
|
|
788
|
+
} else if (shouldProcessAsDeleteAction) {
|
|
873
789
|
if (documentIds.length > 0) {
|
|
874
790
|
const deleteTargets = documentIds.map((documentId) => {
|
|
875
791
|
const preActionSnapshot = preActionSnapshotsByDocumentId.get(documentId) || null;
|
|
876
792
|
return {
|
|
877
793
|
documentId,
|
|
878
|
-
localeCodes:
|
|
794
|
+
localeCodes: indexingQueryUsesWildcardLocale ? preActionSnapshot?.localeCodesToRemove || [] : []
|
|
879
795
|
};
|
|
880
796
|
});
|
|
881
797
|
strapi2.log.info(
|
|
@@ -884,8 +800,8 @@ async function registerDocumentMiddleware({ strapi: strapi2 }) {
|
|
|
884
800
|
await dispatchDeleteTargets({
|
|
885
801
|
meilisearch: meilisearch2,
|
|
886
802
|
contentType: contentType2,
|
|
887
|
-
|
|
888
|
-
|
|
803
|
+
indexingQuery,
|
|
804
|
+
indexingQueryUsesWildcardLocale,
|
|
889
805
|
targets: deleteTargets
|
|
890
806
|
});
|
|
891
807
|
} else {
|
|
@@ -2021,7 +1937,7 @@ const store = ({ strapi: strapi2 }) => {
|
|
|
2021
1937
|
...createStoreConnector({ strapi: strapi2 })
|
|
2022
1938
|
};
|
|
2023
1939
|
};
|
|
2024
|
-
const version = "0.16.
|
|
1940
|
+
const version = "0.16.4";
|
|
2025
1941
|
const Meilisearch = (config2) => {
|
|
2026
1942
|
return new MeiliSearch({
|
|
2027
1943
|
...config2,
|