@rubixstudios/payload-typesense 1.1.1 → 1.1.2
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/README.md +1 -17
- package/dist/components/HeadlessSearchInput.d.ts +2 -92
- package/dist/components/HeadlessSearchInput.d.ts.map +1 -1
- package/dist/components/HeadlessSearchInput.js +23 -140
- package/dist/components/ThemeProvider.d.ts +3 -2
- package/dist/components/ThemeProvider.d.ts.map +1 -1
- package/dist/components/ThemeProvider.js +1 -1
- package/dist/components/index.d.ts +5 -5
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +3 -3
- package/dist/components/themes/hooks.d.ts +5 -5
- package/dist/components/themes/hooks.d.ts.map +1 -1
- package/dist/components/themes/hooks.js +16 -16
- package/dist/components/themes/index.d.ts +4 -4
- package/dist/components/themes/index.js +4 -4
- package/dist/components/themes/themes.d.ts +1 -1
- package/dist/components/themes/themes.d.ts.map +1 -1
- package/dist/components/themes/themes.js +109 -109
- package/dist/components/themes/types.d.ts.map +1 -1
- package/dist/components/themes/utils.d.ts +1 -1
- package/dist/components/themes/utils.d.ts.map +1 -1
- package/dist/components/themes/utils.js +140 -140
- package/dist/endpoints/handler/createAdvancedSearch.d.ts +5 -0
- package/dist/endpoints/handler/createAdvancedSearch.d.ts.map +1 -0
- package/dist/endpoints/handler/createAdvancedSearch.js +40 -0
- package/dist/endpoints/handler/createCollections.d.ts +4 -0
- package/dist/endpoints/handler/createCollections.d.ts.map +1 -0
- package/dist/endpoints/handler/createCollections.js +23 -0
- package/dist/endpoints/handler/createSearch.d.ts +5 -0
- package/dist/endpoints/handler/createSearch.d.ts.map +1 -0
- package/dist/endpoints/handler/createSearch.js +119 -0
- package/dist/endpoints/handler/createSuggest.d.ts +5 -0
- package/dist/endpoints/handler/createSuggest.d.ts.map +1 -0
- package/dist/endpoints/handler/createSuggest.js +50 -0
- package/dist/endpoints/health.d.ts +4 -10
- package/dist/endpoints/health.d.ts.map +1 -1
- package/dist/endpoints/health.js +45 -103
- package/dist/endpoints/search.d.ts +4 -5
- package/dist/endpoints/search.d.ts.map +1 -1
- package/dist/endpoints/search.js +26 -355
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -101
- package/dist/lib/cache.d.ts +6 -27
- package/dist/lib/cache.d.ts.map +1 -1
- package/dist/lib/cache.js +11 -29
- package/dist/lib/client.d.ts +4 -0
- package/dist/lib/client.d.ts.map +1 -0
- package/dist/lib/{typesense-client.js → client.js} +10 -18
- package/dist/lib/headlessSearch.d.ts +89 -0
- package/dist/lib/headlessSearch.d.ts.map +1 -0
- package/dist/lib/headlessSearch.js +2 -0
- package/dist/lib/hooks.d.ts +12 -3
- package/dist/lib/hooks.d.ts.map +1 -1
- package/dist/lib/hooks.js +37 -37
- package/dist/lib/initialization.d.ts +3 -3
- package/dist/lib/initialization.d.ts.map +1 -1
- package/dist/lib/initialization.js +36 -49
- package/dist/lib/schema-mapper.d.ts +17 -7
- package/dist/lib/schema-mapper.d.ts.map +1 -1
- package/dist/lib/schema-mapper.js +53 -89
- package/dist/lib/{config-validation.d.ts → validation.d.ts} +18 -22
- package/dist/lib/validation.d.ts.map +1 -0
- package/dist/lib/{config-validation.js → validation.js} +32 -49
- package/dist/{lib/types.d.ts → types.d.ts} +22 -5
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/buildError.d.ts +2 -0
- package/dist/utils/buildError.d.ts.map +1 -0
- package/dist/utils/buildError.js +10 -0
- package/dist/utils/ensureCollection.d.ts +3 -0
- package/dist/utils/ensureCollection.d.ts.map +1 -0
- package/dist/utils/ensureCollection.js +13 -0
- package/dist/utils/extractText.d.ts +2 -0
- package/dist/utils/extractText.d.ts.map +1 -0
- package/dist/utils/extractText.js +20 -0
- package/dist/utils/getAllCollections.d.ts +9 -0
- package/dist/utils/getAllCollections.d.ts.map +1 -0
- package/dist/utils/getAllCollections.js +84 -0
- package/dist/utils/getCacheStats.d.ts +6 -0
- package/dist/utils/getCacheStats.d.ts.map +1 -0
- package/dist/utils/getCacheStats.js +9 -0
- package/dist/utils/getCollectionInfo.d.ts +3 -0
- package/dist/utils/getCollectionInfo.d.ts.map +1 -0
- package/dist/utils/getCollectionInfo.js +8 -0
- package/dist/utils/keyboard.d.ts +8 -0
- package/dist/utils/keyboard.d.ts.map +1 -0
- package/dist/utils/keyboard.js +41 -0
- package/dist/utils/testConnection.d.ts +3 -0
- package/dist/utils/testConnection.d.ts.map +1 -0
- package/dist/utils/testConnection.js +8 -0
- package/dist/utils/useDebounce.d.ts +2 -0
- package/dist/utils/useDebounce.d.ts.map +1 -0
- package/dist/utils/useDebounce.js +15 -0
- package/dist/utils/useSearch.d.ts +17 -0
- package/dist/utils/useSearch.d.ts.map +1 -0
- package/dist/utils/useSearch.js +78 -0
- package/package.json +12 -9
- package/dist/lib/config-validation.d.ts.map +0 -1
- package/dist/lib/types.d.ts.map +0 -1
- package/dist/lib/typesense-client.d.ts +0 -5
- package/dist/lib/typesense-client.d.ts.map +0 -1
- /package/dist/{lib/types.js → types.js} +0 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { searchCache } from '../../lib/cache.js';
|
|
2
|
+
import { getValidationErrors, validateSearchParams } from '../../lib/validation.js';
|
|
3
|
+
import { getAllCollections } from '../../utils/getAllCollections.js';
|
|
4
|
+
export const createSearch = (typesenseClient, pluginOptions)=>{
|
|
5
|
+
return async (request)=>{
|
|
6
|
+
try {
|
|
7
|
+
if (!request.url) {
|
|
8
|
+
return Response.json({
|
|
9
|
+
error: 'Request URL missing'
|
|
10
|
+
}, {
|
|
11
|
+
status: 400
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
const url = new URL(request.url);
|
|
15
|
+
const parts = url.pathname.split('/');
|
|
16
|
+
const searchIndex = parts.indexOf('search');
|
|
17
|
+
const collectionName = searchIndex >= 0 ? parts[searchIndex + 1] : '';
|
|
18
|
+
const collection = String(collectionName || '');
|
|
19
|
+
const q = url.searchParams.get('q') || '';
|
|
20
|
+
const page = Number(url.searchParams.get('page') || 1);
|
|
21
|
+
const per_page = Number(url.searchParams.get('per_page') || 10);
|
|
22
|
+
const sort_by = url.searchParams.get('sort_by') || undefined;
|
|
23
|
+
if (isNaN(page) || page < 1) {
|
|
24
|
+
return Response.json({
|
|
25
|
+
error: 'Invalid page parameter'
|
|
26
|
+
}, {
|
|
27
|
+
status: 400
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (isNaN(per_page) || per_page < 1 || per_page > 250) {
|
|
31
|
+
return Response.json({
|
|
32
|
+
error: 'Invalid per_page parameter'
|
|
33
|
+
}, {
|
|
34
|
+
status: 400
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const validation = validateSearchParams({
|
|
38
|
+
page,
|
|
39
|
+
per_page,
|
|
40
|
+
q,
|
|
41
|
+
sort_by
|
|
42
|
+
});
|
|
43
|
+
if (!validation.success) {
|
|
44
|
+
return Response.json({
|
|
45
|
+
details: getValidationErrors(validation.errors || []),
|
|
46
|
+
error: 'Invalid search parameters'
|
|
47
|
+
}, {
|
|
48
|
+
status: 400
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
if (!collection) {
|
|
52
|
+
if (!q.trim()) {
|
|
53
|
+
return Response.json({
|
|
54
|
+
details: 'Use /api/search?q=keyword',
|
|
55
|
+
error: 'Query parameter "q" is required'
|
|
56
|
+
}, {
|
|
57
|
+
status: 400
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return getAllCollections(typesenseClient, pluginOptions, q, {
|
|
61
|
+
filters: {},
|
|
62
|
+
page,
|
|
63
|
+
per_page,
|
|
64
|
+
sort_by
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
if (!pluginOptions.collections?.[collection]?.enabled) {
|
|
68
|
+
return Response.json({
|
|
69
|
+
error: 'Collection not enabled for search'
|
|
70
|
+
}, {
|
|
71
|
+
status: 400
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (!q.trim()) {
|
|
75
|
+
return Response.json({
|
|
76
|
+
error: 'Query parameter "q" is required'
|
|
77
|
+
}, {
|
|
78
|
+
status: 400
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
const fields = pluginOptions.collections?.[collection]?.searchFields?.join(',') || 'title,content';
|
|
82
|
+
const searchParams = {
|
|
83
|
+
highlight_full_fields: fields,
|
|
84
|
+
num_typos: 0,
|
|
85
|
+
page,
|
|
86
|
+
per_page,
|
|
87
|
+
q,
|
|
88
|
+
query_by: fields,
|
|
89
|
+
snippet_threshold: 30,
|
|
90
|
+
typo_tokens_threshold: 1,
|
|
91
|
+
...sort_by ? {
|
|
92
|
+
sort_by
|
|
93
|
+
} : {}
|
|
94
|
+
};
|
|
95
|
+
const cached = searchCache.get(q, collection, {
|
|
96
|
+
page,
|
|
97
|
+
per_page,
|
|
98
|
+
sort_by
|
|
99
|
+
});
|
|
100
|
+
if (cached) {
|
|
101
|
+
return Response.json(cached);
|
|
102
|
+
}
|
|
103
|
+
const results = await typesenseClient.collections(collection).documents().search(searchParams);
|
|
104
|
+
searchCache.set(q, results, collection, {
|
|
105
|
+
page,
|
|
106
|
+
per_page,
|
|
107
|
+
sort_by
|
|
108
|
+
});
|
|
109
|
+
return Response.json(results);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
return Response.json({
|
|
112
|
+
details: error instanceof Error ? error.message : 'Unknown error',
|
|
113
|
+
error: 'Search handler failed'
|
|
114
|
+
}, {
|
|
115
|
+
status: 500
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type Typesense from 'typesense';
|
|
2
|
+
import { type PayloadHandler } from 'payload';
|
|
3
|
+
import { type TypesenseSearchConfig } from '../../index.js';
|
|
4
|
+
export declare const createSuggest: (typesenseClient: Typesense.Client, pluginOptions: TypesenseSearchConfig) => PayloadHandler;
|
|
5
|
+
//# sourceMappingURL=createSuggest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createSuggest.d.ts","sourceRoot":"","sources":["../../../src/endpoints/handler/createSuggest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAEtC,OAAO,EAAE,KAAK,cAAc,EAAuB,MAAM,SAAS,CAAA;AAElE,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,gBAAgB,CAAA;AAE3D,eAAO,MAAM,aAAa,GACxB,iBAAiB,SAAS,CAAC,MAAM,EACjC,eAAe,qBAAqB,KACnC,cA0CF,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export const createSuggest = (typesenseClient, pluginOptions)=>{
|
|
2
|
+
return async (request)=>{
|
|
3
|
+
if (!request.url) {
|
|
4
|
+
return Response.json({
|
|
5
|
+
error: 'Request URL missing'
|
|
6
|
+
}, {
|
|
7
|
+
status: 400
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
const url = new URL(request.url);
|
|
11
|
+
const parts = url.pathname.split('/');
|
|
12
|
+
const searchIndex = parts.indexOf('search');
|
|
13
|
+
const collectionName = searchIndex >= 0 ? parts[searchIndex + 1] : '';
|
|
14
|
+
const collection = String(collectionName || '');
|
|
15
|
+
if (!collection || !pluginOptions.collections?.[collection]?.enabled) {
|
|
16
|
+
return Response.json({
|
|
17
|
+
error: 'Collection not enabled for search'
|
|
18
|
+
}, {
|
|
19
|
+
status: 400
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
const q = url.searchParams.get('q');
|
|
23
|
+
const limitStr = url.searchParams.get('limit');
|
|
24
|
+
const limit = Number(limitStr ?? 5);
|
|
25
|
+
if (!q) {
|
|
26
|
+
return Response.json({
|
|
27
|
+
error: 'Query parameter "q" is required'
|
|
28
|
+
}, {
|
|
29
|
+
status: 400
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const fields = pluginOptions.collections?.[collection]?.searchFields?.join(',') || 'title,content';
|
|
33
|
+
try {
|
|
34
|
+
const suggestResults = await typesenseClient.collections(collection).documents().search({
|
|
35
|
+
highlight_full_fields: fields,
|
|
36
|
+
per_page: limit,
|
|
37
|
+
q,
|
|
38
|
+
query_by: fields,
|
|
39
|
+
snippet_threshold: 30
|
|
40
|
+
});
|
|
41
|
+
return Response.json(suggestResults);
|
|
42
|
+
} catch {
|
|
43
|
+
return Response.json({
|
|
44
|
+
error: 'Suggest failed'
|
|
45
|
+
}, {
|
|
46
|
+
status: 500
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import type { PayloadHandler } from 'payload';
|
|
2
1
|
import type Typesense from 'typesense';
|
|
3
|
-
import type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare const createHealthCheckHandler: (typesenseClient: Typesense.Client, pluginOptions: TypesenseSearchConfig, lastSyncTime?: number) => PayloadHandler;
|
|
8
|
-
/**
|
|
9
|
-
* Create detailed health check handler with more information
|
|
10
|
-
*/
|
|
11
|
-
export declare const createDetailedHealthCheckHandler: (typesenseClient: Typesense.Client, pluginOptions: TypesenseSearchConfig, lastSyncTime?: number) => PayloadHandler;
|
|
2
|
+
import { type PayloadHandler } from 'payload';
|
|
3
|
+
import { type TypesenseSearchConfig } from '../index.js';
|
|
4
|
+
export declare const createHealthCheck: (typesenseClient: Typesense.Client, _pluginOptions: TypesenseSearchConfig, lastSyncTime?: number) => PayloadHandler;
|
|
5
|
+
export declare const createDetailedHealthCheck: (typesenseClient: Typesense.Client, pluginOptions: TypesenseSearchConfig, lastSyncTime?: number) => PayloadHandler;
|
|
12
6
|
//# sourceMappingURL=health.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/endpoints/health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/endpoints/health.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAEtC,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,SAAS,CAAA;AAG7C,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAOxD,eAAO,MAAM,iBAAiB,GAC5B,iBAAiB,SAAS,CAAC,MAAM,EACjC,gBAAgB,qBAAqB,EACrC,eAAe,MAAM,KACpB,cAsCF,CAAA;AAED,eAAO,MAAM,yBAAyB,GACpC,iBAAiB,SAAS,CAAC,MAAM,EACjC,eAAe,qBAAqB,EACpC,eAAe,MAAM,KACpB,cAsFF,CAAA"}
|
package/dist/endpoints/health.js
CHANGED
|
@@ -1,88 +1,43 @@
|
|
|
1
1
|
import pkg from '../../package.json';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const health = await typesenseClient.health.retrieve();
|
|
8
|
-
return health.ok === true;
|
|
9
|
-
} catch (_error) {
|
|
10
|
-
// Handle health check error
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Get collection information
|
|
16
|
-
*/ const getCollectionInfo = async (typesenseClient)=>{
|
|
17
|
-
try {
|
|
18
|
-
const collections = await typesenseClient.collections().retrieve();
|
|
19
|
-
return collections.map((col)=>col.name);
|
|
20
|
-
} catch (_error) {
|
|
21
|
-
// Handle collections retrieval error
|
|
22
|
-
return [];
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* Get cache statistics
|
|
27
|
-
*/ const getCacheStats = ()=>{
|
|
28
|
-
const stats = searchCache.getStats();
|
|
29
|
-
return {
|
|
30
|
-
hitRate: stats.hitRate || 0,
|
|
31
|
-
maxSize: stats.maxSize,
|
|
32
|
-
size: stats.size
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Create health check handler
|
|
37
|
-
*/ export const createHealthCheckHandler = (typesenseClient, pluginOptions, lastSyncTime)=>{
|
|
2
|
+
import { buildError } from '../utils/buildError.js';
|
|
3
|
+
import { getCacheStats } from '../utils/getCacheStats.js';
|
|
4
|
+
import { getCollectionInfo } from '../utils/getCollectionInfo.js';
|
|
5
|
+
import { testConnection } from '../utils/testConnection.js';
|
|
6
|
+
export const createHealthCheck = (typesenseClient, _pluginOptions, lastSyncTime)=>{
|
|
38
7
|
return async ()=>{
|
|
8
|
+
const start = Date.now();
|
|
39
9
|
try {
|
|
40
|
-
const
|
|
41
|
-
// Test Typesense connection
|
|
42
|
-
const isTypesenseHealthy = await testTypesenseConnection(typesenseClient);
|
|
43
|
-
const typesenseInfo = isTypesenseHealthy ? {
|
|
44
|
-
ok: true,
|
|
45
|
-
version: 'unknown'
|
|
46
|
-
} : {
|
|
47
|
-
ok: false
|
|
48
|
-
};
|
|
49
|
-
// Get collection information
|
|
10
|
+
const isTypesenseHealthy = await testConnection(typesenseClient);
|
|
50
11
|
const collections = isTypesenseHealthy ? await getCollectionInfo(typesenseClient) : [];
|
|
51
|
-
// Get cache statistics
|
|
52
12
|
const cacheStats = getCacheStats();
|
|
53
|
-
// Determine overall health status
|
|
54
13
|
const isHealthy = isTypesenseHealthy && collections.length > 0;
|
|
55
|
-
const
|
|
14
|
+
const base = {
|
|
56
15
|
cache: cacheStats,
|
|
57
16
|
collections,
|
|
17
|
+
status: isHealthy ? 'healthy' : 'unhealthy',
|
|
18
|
+
typesense: {
|
|
19
|
+
ok: isTypesenseHealthy,
|
|
20
|
+
version: 'unknown'
|
|
21
|
+
},
|
|
58
22
|
...lastSyncTime !== undefined && {
|
|
59
23
|
lastSync: lastSyncTime
|
|
60
|
-
},
|
|
61
|
-
status: isHealthy ? 'healthy' : 'unhealthy',
|
|
62
|
-
typesense: typesenseInfo
|
|
63
|
-
};
|
|
64
|
-
// Add error details if unhealthy
|
|
65
|
-
if (!isHealthy) {
|
|
66
|
-
const errors = [];
|
|
67
|
-
if (!isTypesenseHealthy) {
|
|
68
|
-
errors.push('Typesense connection failed');
|
|
69
|
-
}
|
|
70
|
-
if (collections.length === 0) {
|
|
71
|
-
errors.push('No collections available');
|
|
72
24
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const responseTime = Date.now() -
|
|
25
|
+
};
|
|
26
|
+
const error = buildError(isTypesenseHealthy, collections.length > 0);
|
|
27
|
+
const responseTime = Date.now() - start;
|
|
76
28
|
return Response.json({
|
|
77
|
-
...
|
|
29
|
+
...base,
|
|
30
|
+
...error && {
|
|
31
|
+
error
|
|
32
|
+
},
|
|
78
33
|
responseTime,
|
|
79
34
|
timestamp: new Date().toISOString(),
|
|
80
35
|
version: pkg.version
|
|
81
36
|
});
|
|
82
|
-
} catch (
|
|
37
|
+
} catch (err) {
|
|
83
38
|
const errorResponse = {
|
|
84
39
|
cache: getCacheStats(),
|
|
85
|
-
error:
|
|
40
|
+
error: err instanceof Error ? err.message : 'Unknown error',
|
|
86
41
|
status: 'unhealthy'
|
|
87
42
|
};
|
|
88
43
|
return Response.json(errorResponse, {
|
|
@@ -91,32 +46,27 @@ import { searchCache } from '../lib/cache.js';
|
|
|
91
46
|
}
|
|
92
47
|
};
|
|
93
48
|
};
|
|
94
|
-
|
|
95
|
-
* Create detailed health check handler with more information
|
|
96
|
-
*/ export const createDetailedHealthCheckHandler = (typesenseClient, pluginOptions, lastSyncTime)=>{
|
|
49
|
+
export const createDetailedHealthCheck = (typesenseClient, pluginOptions, lastSyncTime)=>{
|
|
97
50
|
return async ()=>{
|
|
51
|
+
const start = Date.now();
|
|
98
52
|
try {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
const isTypesenseHealthy = await testTypesenseConnection(typesenseClient);
|
|
102
|
-
// Get detailed collection information
|
|
103
|
-
let collections = [];
|
|
53
|
+
const isTypesenseHealthy = await testConnection(typesenseClient);
|
|
54
|
+
let collectionDetails = [];
|
|
104
55
|
if (isTypesenseHealthy) {
|
|
105
56
|
try {
|
|
106
57
|
const collectionsData = await typesenseClient.collections().retrieve();
|
|
107
|
-
|
|
58
|
+
collectionDetails = collectionsData.map((col)=>({
|
|
108
59
|
name: col.name,
|
|
109
60
|
createdAt: col.created_at,
|
|
110
61
|
fields: col.fields?.length || 0,
|
|
111
62
|
numDocuments: col.num_documents
|
|
112
63
|
}));
|
|
113
|
-
} catch
|
|
114
|
-
//
|
|
64
|
+
} catch {
|
|
65
|
+
// ignore detailed retrieval error
|
|
115
66
|
}
|
|
116
67
|
}
|
|
117
|
-
|
|
68
|
+
const collections = collectionDetails.map((c)=>c.name);
|
|
118
69
|
const cacheStats = getCacheStats();
|
|
119
|
-
// Get plugin configuration info
|
|
120
70
|
const configInfo = {
|
|
121
71
|
enabledCollections: Object.entries(pluginOptions.collections || {}).filter(([_, config])=>config?.enabled).map(([name, config])=>({
|
|
122
72
|
name,
|
|
@@ -127,45 +77,37 @@ import { searchCache } from '../lib/cache.js';
|
|
|
127
77
|
settings: pluginOptions.settings,
|
|
128
78
|
totalCollections: Object.keys(pluginOptions.collections || {}).length
|
|
129
79
|
};
|
|
130
|
-
|
|
131
|
-
const isHealthy = isTypesenseHealthy && collections.length > 0;
|
|
80
|
+
const isHealthy = isTypesenseHealthy && collectionDetails.length > 0;
|
|
132
81
|
const response = {
|
|
133
82
|
cache: cacheStats,
|
|
134
|
-
collectionDetails
|
|
135
|
-
collections
|
|
83
|
+
collectionDetails,
|
|
84
|
+
collections,
|
|
136
85
|
config: configInfo,
|
|
137
86
|
lastSync: lastSyncTime,
|
|
138
|
-
responseTime: Date.now() -
|
|
87
|
+
responseTime: Date.now() - start,
|
|
139
88
|
status: isHealthy ? 'healthy' : 'unhealthy',
|
|
140
89
|
timestamp: new Date().toISOString(),
|
|
141
90
|
typesense: {
|
|
142
91
|
ok: isTypesenseHealthy,
|
|
143
92
|
version: 'unknown'
|
|
144
93
|
},
|
|
145
|
-
version: pkg.version
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
errors.push('Typesense connection failed');
|
|
94
|
+
version: pkg.version,
|
|
95
|
+
...isHealthy ? {} : {
|
|
96
|
+
error: [
|
|
97
|
+
!isTypesenseHealthy && 'Typesense connection failed',
|
|
98
|
+
collectionDetails.length === 0 && 'No collections available'
|
|
99
|
+
].filter(Boolean).join(', ')
|
|
152
100
|
}
|
|
153
|
-
|
|
154
|
-
errors.push('No collections available');
|
|
155
|
-
}
|
|
156
|
-
response.error = errors.join(', ');
|
|
157
|
-
}
|
|
101
|
+
};
|
|
158
102
|
return Response.json(response);
|
|
159
|
-
} catch (
|
|
160
|
-
|
|
161
|
-
const errorResponse = {
|
|
103
|
+
} catch (error) {
|
|
104
|
+
return Response.json({
|
|
162
105
|
cache: getCacheStats(),
|
|
163
|
-
error:
|
|
106
|
+
error: error instanceof Error ? error.message : 'Unknown error',
|
|
164
107
|
status: 'unhealthy',
|
|
165
108
|
timestamp: new Date().toISOString(),
|
|
166
109
|
version: pkg.version
|
|
167
|
-
}
|
|
168
|
-
return Response.json(errorResponse, {
|
|
110
|
+
}, {
|
|
169
111
|
status: 500
|
|
170
112
|
});
|
|
171
113
|
}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
import type { TypesenseSearchConfig } from "../index.js";
|
|
1
|
+
import type Typesense from 'typesense';
|
|
2
|
+
import { type TypesenseSearchConfig } from '../index.js';
|
|
4
3
|
export declare const createSearchEndpoints: (typesenseClient: Typesense.Client, pluginOptions: TypesenseSearchConfig, lastSyncTime?: number) => ({
|
|
5
|
-
handler: PayloadHandler;
|
|
4
|
+
handler: import("payload").PayloadHandler;
|
|
6
5
|
method: "get";
|
|
7
6
|
path: string;
|
|
8
7
|
} | {
|
|
9
|
-
handler: PayloadHandler;
|
|
8
|
+
handler: import("payload").PayloadHandler;
|
|
10
9
|
method: "post";
|
|
11
10
|
path: string;
|
|
12
11
|
})[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/endpoints/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/endpoints/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,WAAW,CAAA;AAEtC,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAOxD,eAAO,MAAM,qBAAqB,GAChC,iBAAiB,SAAS,CAAC,MAAM,EACjC,eAAe,qBAAqB,EACpC,eAAe,MAAM;;;;;;;;IAuCtB,CAAA"}
|