@payloadcms/plugin-search 3.0.0-beta.2 → 3.0.0-beta.21
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/types.d.ts +2 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +28 -23
- package/src/index.ts +0 -65
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Payload } from 'payload';
|
|
2
|
-
import type { CollectionAfterChangeHook, CollectionConfig,
|
|
2
|
+
import type { CollectionAfterChangeHook, CollectionConfig, PayloadRequestWithData } from 'payload/types';
|
|
3
3
|
export interface DocToSync {
|
|
4
4
|
[key: string]: any;
|
|
5
5
|
doc: {
|
|
@@ -13,7 +13,7 @@ export type BeforeSync = (args: {
|
|
|
13
13
|
[key: string]: any;
|
|
14
14
|
};
|
|
15
15
|
payload: Payload;
|
|
16
|
-
req:
|
|
16
|
+
req: PayloadRequestWithData;
|
|
17
17
|
searchDoc: DocToSync;
|
|
18
18
|
}) => DocToSync | Promise<DocToSync>;
|
|
19
19
|
export interface SearchConfig {
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAChB,sBAAsB,EACvB,MAAM,eAAe,CAAA;AAEtB,MAAM,WAAW,SAAS;IACxB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;IAClB,GAAG,EAAE;QACH,UAAU,EAAE,MAAM,CAAA;QAClB,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,MAAM,UAAU,GAAG,CAAC,IAAI,EAAE;IAC9B,WAAW,EAAE;QACX,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KACnB,CAAA;IACD,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,sBAAsB,CAAA;IAC3B,SAAS,EAAE,SAAS,CAAA;CACrB,KAAK,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAAA;AAEpC,MAAM,WAAW,YAAY;IAC3B,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;IACtB,iBAAiB,CAAC,EAAE;QAClB,CAAC,UAAU,EAAE,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,KAAK,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,MAAM,CAAA;KACxE,CAAA;IACD,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAC3C,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAID,MAAM,MAAM,cAAc,GAAG,CAC3B,IAAI,EAAE,IAAI,CAAC,UAAU,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,GAAG;IACnE,UAAU,EAAE,MAAM,CAAA;CACnB,KACE,UAAU,CAAC,yBAAyB,CAAC,CAAA"}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type {
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Payload } from 'payload'\nimport type {\n CollectionAfterChangeHook,\n CollectionConfig,\n PayloadRequestWithData,\n} from 'payload/types'\n\nexport interface DocToSync {\n [key: string]: any\n doc: {\n relationTo: string\n value: string\n }\n title: string\n}\n\nexport type BeforeSync = (args: {\n originalDoc: {\n [key: string]: any\n }\n payload: Payload\n req: PayloadRequestWithData\n searchDoc: DocToSync\n}) => DocToSync | Promise<DocToSync>\n\nexport interface SearchConfig {\n beforeSync?: BeforeSync\n collections?: string[]\n defaultPriorities?: {\n [collection: string]: ((doc: any) => Promise<number> | number) | number\n }\n deleteDrafts?: boolean\n searchOverrides?: Partial<CollectionConfig>\n syncDrafts?: boolean\n}\n\n// Extend the `CollectionAfterChangeHook` with more function args\n// Convert the `collection` arg from `SanitizedCollectionConfig` to a string\nexport type SyncWithSearch = (\n Args: Omit<Parameters<CollectionAfterChangeHook>[0], 'collection'> & {\n collection: string\n },\n) => ReturnType<CollectionAfterChangeHook>\n"],"names":[],"rangeMappings":";;","mappings":"AAoCA,iEAAiE;AACjE,4EAA4E;AAC5E,WAI0C"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/plugin-search",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
4
|
-
"homepage:": "https://payloadcms.com",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "https://github.com/payloadcms/payload.git",
|
|
8
|
-
"directory": "packages/plugin-search"
|
|
9
|
-
},
|
|
3
|
+
"version": "3.0.0-beta.21",
|
|
10
4
|
"description": "Search plugin for Payload",
|
|
11
|
-
"main": "./dist/index.js",
|
|
12
|
-
"types": "./dist/index.d.ts",
|
|
13
|
-
"type": "module",
|
|
14
5
|
"keywords": [
|
|
15
6
|
"payload",
|
|
16
7
|
"cms",
|
|
@@ -20,32 +11,46 @@
|
|
|
20
11
|
"search",
|
|
21
12
|
"algolia"
|
|
22
13
|
],
|
|
23
|
-
"
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "https://github.com/payloadcms/payload.git",
|
|
17
|
+
"directory": "packages/plugin-search"
|
|
18
|
+
},
|
|
24
19
|
"license": "MIT",
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
"author": "dev@trbl.design",
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"import": "./dist/index.js",
|
|
25
|
+
"require": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts"
|
|
27
|
+
}
|
|
28
28
|
},
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"files": [
|
|
32
|
+
"dist",
|
|
33
|
+
"types.js",
|
|
34
|
+
"types.d.ts"
|
|
35
|
+
],
|
|
29
36
|
"dependencies": {
|
|
30
37
|
"deepmerge": "4.3.1",
|
|
31
|
-
"@payloadcms/ui": "3.0.0-beta.
|
|
38
|
+
"@payloadcms/ui": "3.0.0-beta.21"
|
|
32
39
|
},
|
|
33
40
|
"devDependencies": {
|
|
34
41
|
"@types/express": "^4.17.9",
|
|
35
42
|
"@types/react": "18.2.74",
|
|
36
|
-
"react": "^18.0.0",
|
|
37
43
|
"@payloadcms/eslint-config": "1.1.1",
|
|
38
|
-
"payload": "3.0.0-beta.
|
|
44
|
+
"payload": "3.0.0-beta.21"
|
|
45
|
+
},
|
|
46
|
+
"peerDependencies": {
|
|
47
|
+
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
48
|
+
"payload": "3.0.0-beta.21"
|
|
39
49
|
},
|
|
40
|
-
"exports": null,
|
|
41
50
|
"publishConfig": {
|
|
42
51
|
"registry": "https://registry.npmjs.org/"
|
|
43
52
|
},
|
|
44
|
-
"
|
|
45
|
-
"dist",
|
|
46
|
-
"types.js",
|
|
47
|
-
"types.d.ts"
|
|
48
|
-
],
|
|
53
|
+
"homepage:": "https://payloadcms.com",
|
|
49
54
|
"scripts": {
|
|
50
55
|
"build": "pnpm build:swc && pnpm build:types",
|
|
51
56
|
"build:swc": "swc ./src -d ./dist --config-file .swcrc",
|
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
|