@payloadcms/plugin-search 3.0.0-beta.11 → 3.0.0-beta.12
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/package.json +5 -5
- package/src/index.ts +0 -65
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-search",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.12",
|
|
4
4
|
"homepage:": "https://payloadcms.com",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,18 +24,18 @@
|
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
27
|
-
"payload": "3.0.0-beta.
|
|
27
|
+
"payload": "3.0.0-beta.12"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"deepmerge": "4.3.1",
|
|
31
|
-
"@payloadcms/ui": "3.0.0-beta.
|
|
31
|
+
"@payloadcms/ui": "3.0.0-beta.12"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/express": "^4.17.9",
|
|
35
35
|
"@types/react": "18.2.74",
|
|
36
36
|
"react": "^18.0.0",
|
|
37
|
-
"
|
|
38
|
-
"
|
|
37
|
+
"payload": "3.0.0-beta.12",
|
|
38
|
+
"@payloadcms/eslint-config": "1.1.1"
|
|
39
39
|
},
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|
package/src/index.ts
DELETED
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import type { Config } from 'payload/config'
|
|
2
|
-
|
|
3
|
-
import type { SearchConfig } from './types.js'
|
|
4
|
-
|
|
5
|
-
import deleteFromSearch from './Search/hooks/deleteFromSearch.js'
|
|
6
|
-
import syncWithSearch from './Search/hooks/syncWithSearch.js'
|
|
7
|
-
import { generateSearchCollection } from './Search/index.js'
|
|
8
|
-
|
|
9
|
-
const Search =
|
|
10
|
-
(incomingSearchConfig: SearchConfig) =>
|
|
11
|
-
(config: Config): Config => {
|
|
12
|
-
const { collections } = config
|
|
13
|
-
|
|
14
|
-
if (collections) {
|
|
15
|
-
const searchConfig: SearchConfig = {
|
|
16
|
-
...incomingSearchConfig,
|
|
17
|
-
deleteDrafts: true,
|
|
18
|
-
syncDrafts: false,
|
|
19
|
-
// write any config defaults here
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// add afterChange and afterDelete hooks to every search-enabled collection
|
|
23
|
-
const collectionsWithSearchHooks = config?.collections
|
|
24
|
-
?.map((collection) => {
|
|
25
|
-
const { hooks: existingHooks } = collection
|
|
26
|
-
|
|
27
|
-
const enabledCollections = searchConfig.collections || []
|
|
28
|
-
const isEnabled = enabledCollections.indexOf(collection.slug) > -1
|
|
29
|
-
if (isEnabled) {
|
|
30
|
-
return {
|
|
31
|
-
...collection,
|
|
32
|
-
hooks: {
|
|
33
|
-
...collection.hooks,
|
|
34
|
-
afterChange: [
|
|
35
|
-
...(existingHooks?.afterChange || []),
|
|
36
|
-
async (args: any) => {
|
|
37
|
-
await syncWithSearch({
|
|
38
|
-
...args,
|
|
39
|
-
collection: collection.slug,
|
|
40
|
-
searchConfig,
|
|
41
|
-
})
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
afterDelete: [...(existingHooks?.afterDelete || []), deleteFromSearch],
|
|
45
|
-
},
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return collection
|
|
50
|
-
})
|
|
51
|
-
.filter(Boolean)
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
...config,
|
|
55
|
-
collections: [
|
|
56
|
-
...(collectionsWithSearchHooks || []),
|
|
57
|
-
generateSearchCollection(searchConfig),
|
|
58
|
-
],
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return config
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default Search
|