@stacksjs/search-engine 0.75.432 → 0.75.443

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.
@@ -0,0 +1,268 @@
1
+ import type { SearchEngineDriver } from '@stacksjs/types';
2
+ /**
3
+ * Configure Algolia client
4
+ */
5
+ export declare function configure(options: AlgoliaConfig): void;
6
+ /**
7
+ * Search an index
8
+ */
9
+ export declare function search(indexName: string, params?: AlgoliaSearchParams): Promise<AlgoliaSearchResponse>;
10
+ /**
11
+ * Multi-index search
12
+ */
13
+ export declare function multiSearch(queries: Array<{ indexName: string, params?: AlgoliaSearchParams }>): Promise<{ results: AlgoliaSearchResponse[] }>;
14
+ /**
15
+ * Add or update a single object
16
+ */
17
+ export declare function saveObject(indexName: string, object: Record<string, any>, objectID?: string): Promise<AlgoliaTask>;
18
+ /**
19
+ * Add or update multiple objects
20
+ */
21
+ export declare function saveObjects(indexName: string, objects: Array<Record<string, any>>): Promise<AlgoliaTask>;
22
+ /**
23
+ * Partially update an object
24
+ */
25
+ export declare function partialUpdateObject(indexName: string, objectID: string, attributes: Record<string, any>, createIfNotExists?: boolean): Promise<AlgoliaTask>;
26
+ /**
27
+ * Delete an object
28
+ */
29
+ export declare function deleteObject(indexName: string, objectID: string): Promise<AlgoliaTask>;
30
+ /**
31
+ * Delete multiple objects
32
+ */
33
+ export declare function deleteObjects(indexName: string, objectIDs: string[]): Promise<AlgoliaTask>;
34
+ /**
35
+ * Delete objects matching a filter
36
+ */
37
+ export declare function deleteBy(indexName: string, filters: string): Promise<AlgoliaTask>;
38
+ /**
39
+ * Get an object by ID
40
+ */
41
+ export declare function getObject(indexName: string, objectID: string, attributesToRetrieve?: string[]): Promise<AlgoliaHit>;
42
+ /**
43
+ * Get multiple objects by IDs
44
+ */
45
+ export declare function getObjects(indexName: string, objectIDs: string[], attributesToRetrieve?: string[]): Promise<{ results: AlgoliaHit[] }>;
46
+ /**
47
+ * Clear all objects from an index
48
+ */
49
+ export declare function clearObjects(indexName: string): Promise<AlgoliaTask>;
50
+ /**
51
+ * Get index settings
52
+ */
53
+ export declare function getSettings(indexName: string): Promise<AlgoliaIndexSettings>;
54
+ /**
55
+ * Update index settings
56
+ */
57
+ export declare function setSettings(indexName: string, settings: AlgoliaIndexSettings, forwardToReplicas?: boolean): Promise<AlgoliaTask>;
58
+ /**
59
+ * List all indices
60
+ */
61
+ export declare function listIndices(): Promise<{
62
+ items: Array<{
63
+ name: string
64
+ createdAt: string
65
+ updatedAt: string
66
+ entries: number
67
+ dataSize: number
68
+ fileSize: number
69
+ lastBuildTimeS: number
70
+ numberOfPendingTasks: number
71
+ pendingTask: boolean
72
+ primary?: string
73
+ replicas?: string[]
74
+ }>
75
+ }>;
76
+ /**
77
+ * Copy an index
78
+ */
79
+ export declare function copyIndex(srcIndexName: string, dstIndexName: string, scope?: Array<'settings' | 'synonyms' | 'rules'>): Promise<AlgoliaTask>;
80
+ /**
81
+ * Move an index
82
+ */
83
+ export declare function moveIndex(srcIndexName: string, dstIndexName: string): Promise<AlgoliaTask>;
84
+ /**
85
+ * Delete an index
86
+ */
87
+ export declare function deleteIndex(indexName: string): Promise<AlgoliaTask>;
88
+ /**
89
+ * Check if an index exists
90
+ */
91
+ export declare function indexExists(indexName: string): Promise<boolean>;
92
+ /**
93
+ * Wait for a task to complete
94
+ */
95
+ export declare function waitTask(indexName: string, taskID: number, timeoutMs?: number, intervalMs?: number): Promise<{ status: 'published' | 'notPublished' }>;
96
+ /**
97
+ * Add a synonym
98
+ */
99
+ export declare function saveSynonym(indexName: string, synonym: {
100
+ objectID: string
101
+ type: 'synonym' | 'oneWaySynonym' | 'altCorrection1' | 'altCorrection2' | 'placeholder'
102
+ synonyms?: string[]
103
+ input?: string
104
+ word?: string
105
+ corrections?: string[]
106
+ placeholder?: string
107
+ replacements?: string[]
108
+ }, forwardToReplicas?: boolean): Promise<AlgoliaTask>;
109
+ /**
110
+ * Search synonyms
111
+ */
112
+ export declare function searchSynonyms(indexName: string, query?: string, type?: string, page?: number, hitsPerPage?: number): Promise<{ hits: any[], nbHits: number }>;
113
+ /**
114
+ * Clear all synonyms
115
+ */
116
+ export declare function clearSynonyms(indexName: string, forwardToReplicas?: boolean): Promise<AlgoliaTask>;
117
+ /**
118
+ * Add a rule
119
+ */
120
+ export declare function saveRule(indexName: string, rule: {
121
+ objectID: string
122
+ conditions?: Array<{
123
+ pattern?: string
124
+ anchoring?: 'is' | 'startsWith' | 'endsWith' | 'contains'
125
+ context?: string
126
+ }>
127
+ consequence: {
128
+ params?: Record<string, any>
129
+ promote?: Array<{ objectID: string, position: number }>
130
+ hide?: Array<{ objectID: string }>
131
+ userData?: Record<string, any>
132
+ }
133
+ description?: string
134
+ enabled?: boolean
135
+ validity?: Array<{ from: number, until: number }>
136
+ }, forwardToReplicas?: boolean): Promise<AlgoliaTask>;
137
+ /**
138
+ * Search rules
139
+ */
140
+ export declare function searchRules(indexName: string, query?: string, anchoring?: string, context?: string, page?: number, hitsPerPage?: number): Promise<{ hits: any[], nbHits: number }>;
141
+ /**
142
+ * Clear all rules
143
+ */
144
+ export declare function clearRules(indexName: string, forwardToReplicas?: boolean): Promise<AlgoliaTask>;
145
+ /**
146
+ * Browse all records in an index
147
+ */
148
+ export declare function browse(indexName: string, params?: AlgoliaSearchParams): AsyncGenerator<AlgoliaHit>;
149
+ /**
150
+ * The raw REST wrappers, in Algolia's own terms. The driver is the default
151
+ * export.
152
+ */
153
+ export declare const algolia: {
154
+ configure: typeof configure;
155
+ search: typeof search;
156
+ multiSearch: typeof multiSearch;
157
+ saveObject: typeof saveObject;
158
+ saveObjects: typeof saveObjects;
159
+ partialUpdateObject: typeof partialUpdateObject;
160
+ deleteObject: typeof deleteObject;
161
+ deleteObjects: typeof deleteObjects;
162
+ deleteBy: typeof deleteBy;
163
+ getObject: typeof getObject;
164
+ getObjects: typeof getObjects;
165
+ clearObjects: typeof clearObjects;
166
+ getSettings: typeof getSettings;
167
+ setSettings: typeof setSettings;
168
+ listIndices: typeof listIndices;
169
+ copyIndex: typeof copyIndex;
170
+ moveIndex: typeof moveIndex;
171
+ deleteIndex: typeof deleteIndex;
172
+ indexExists: typeof indexExists;
173
+ waitTask: typeof waitTask;
174
+ saveSynonym: typeof saveSynonym;
175
+ searchSynonyms: typeof searchSynonyms;
176
+ clearSynonyms: typeof clearSynonyms;
177
+ saveRule: typeof saveRule;
178
+ searchRules: typeof searchRules;
179
+ clearRules: typeof clearRules;
180
+ browse: typeof browse
181
+ };
182
+ declare const algoliaDriver: SearchEngineDriver;
183
+ export declare interface AlgoliaConfig {
184
+ appId: string
185
+ apiKey: string
186
+ searchOnlyApiKey?: string
187
+ }
188
+ export declare interface AlgoliaSearchParams {
189
+ query?: string
190
+ page?: number
191
+ hitsPerPage?: number
192
+ filters?: string
193
+ facets?: string[]
194
+ attributesToRetrieve?: string[]
195
+ attributesToHighlight?: string[]
196
+ attributesToSnippet?: string[]
197
+ sortBy?: string
198
+ }
199
+ export declare interface AlgoliaHit {
200
+ objectID: string
201
+ [key: string]: any
202
+ }
203
+ export declare interface AlgoliaSearchResponse {
204
+ hits: AlgoliaHit[]
205
+ nbHits: number
206
+ page: number
207
+ nbPages: number
208
+ hitsPerPage: number
209
+ processingTimeMS: number
210
+ query: string
211
+ params: string
212
+ facets?: Record<string, Record<string, number>>
213
+ }
214
+ export declare interface AlgoliaIndexSettings {
215
+ searchableAttributes?: string[]
216
+ attributesForFaceting?: string[]
217
+ unretrievableAttributes?: string[]
218
+ attributesToRetrieve?: string[]
219
+ ranking?: string[]
220
+ customRanking?: string[]
221
+ replicas?: string[]
222
+ maxValuesPerFacet?: number
223
+ sortFacetValuesBy?: 'count' | 'alpha'
224
+ attributesToHighlight?: string[]
225
+ attributesToSnippet?: string[]
226
+ highlightPreTag?: string
227
+ highlightPostTag?: string
228
+ snippetEllipsisText?: string
229
+ restrictHighlightAndSnippetArrays?: boolean
230
+ minWordSizefor1Typo?: number
231
+ minWordSizefor2Typos?: number
232
+ typoTolerance?: boolean | 'min' | 'strict'
233
+ allowTyposOnNumericTokens?: boolean
234
+ disableTypoToleranceOnAttributes?: string[]
235
+ disableTypoToleranceOnWords?: string[]
236
+ ignorePlurals?: boolean | string[]
237
+ removeStopWords?: boolean | string[]
238
+ separatorsToIndex?: string
239
+ queryType?: 'prefixLast' | 'prefixAll' | 'prefixNone'
240
+ removeWordsIfNoResults?: 'none' | 'lastWords' | 'firstWords' | 'allOptional'
241
+ advancedSyntax?: boolean
242
+ optionalWords?: string[]
243
+ disablePrefixOnAttributes?: string[]
244
+ disableExactOnAttributes?: string[]
245
+ exactOnSingleWordQuery?: 'attribute' | 'none' | 'word'
246
+ alternativesAsExact?: Array<'ignorePlurals' | 'singleWordSynonym' | 'multiWordsSynonym'>
247
+ numericAttributesForFiltering?: string[]
248
+ allowCompressionOfIntegerArray?: boolean
249
+ attributeForDistinct?: string
250
+ distinct?: boolean | number
251
+ replaceSynonymsInHighlight?: boolean
252
+ minProximity?: number
253
+ responseFields?: string[]
254
+ maxFacetHits?: number
255
+ paginationLimitedTo?: number
256
+ }
257
+ export declare interface AlgoliaTask {
258
+ taskID: number
259
+ objectID?: string
260
+ objectIDs?: string[]
261
+ createdAt?: string
262
+ updatedAt?: string
263
+ }
264
+ export declare class AlgoliaRequestError extends Error {
265
+ public status: number;
266
+ constructor(status: number, message: string);
267
+ }
268
+ export default algoliaDriver;
@@ -0,0 +1,3 @@
1
+ import type { SearchEngineDriver } from '@stacksjs/types';
2
+ declare const meilisearch: SearchEngineDriver;
3
+ export default meilisearch;
@@ -0,0 +1,7 @@
1
+ import type { SearchEngineDriver } from '@stacksjs/types';
2
+ declare const opensearch: SearchEngineDriver;
3
+ declare class OpenSearchRequestError extends Error {
4
+ public status: number;
5
+ constructor(status: number, method: string, path: string, detail: string);
6
+ }
7
+ export default opensearch;
@@ -0,0 +1,38 @@
1
+ import type { SearchEngineDriver } from '@stacksjs/types';
2
+ declare const typesense: SearchEngineDriver;
3
+ declare interface TypesenseField {
4
+ name: string
5
+ type: string
6
+ facet?: boolean
7
+ sort?: boolean
8
+ optional?: boolean
9
+ [key: string]: unknown
10
+ }
11
+ declare type TypesenseConfig = {
12
+ host: string
13
+ port: number
14
+ protocol: string
15
+ apiKey: string
16
+ }
17
+ /**
18
+ * The PATCH that brings an existing collection in line with the settings and
19
+ * with the documents about to be written.
20
+ *
21
+ * A field whose facet or sort flag has to change is dropped and re-added in the
22
+ * same request, which is how Typesense alters a field. A document field the
23
+ * schema lacks is added, typed from the documents. A declared attribute no
24
+ * document has carried yet is left out, because nothing yet says its type.
25
+ */
26
+ declare type FieldChange = TypesenseField | { name: string, drop: true }
27
+ declare class TypesenseRequestError extends Error {
28
+ public status: number;
29
+ constructor(status: number, method: string, path: string, detail: string);
30
+ }
31
+ /** A bulk import Typesense accepted with HTTP 200 and then refused, line by line. */
32
+ export declare class TypesenseImportError extends Error {
33
+ public indexName: string;
34
+ public failures: Array<{ id: unknown, error: string }>;
35
+ public total: number;
36
+ constructor(indexName: string, failures: Array<{ id: unknown, error: string }>, total: number);
37
+ }
38
+ export default typesense;
@@ -0,0 +1,31 @@
1
+ import type { SearchEngineSearchParams, SearchFilter, SearchSort } from '@stacksjs/types';
2
+ export declare function resolveSearchParams(params: SearchEngineSearchParams | string | undefined, defaultLimit?: number): ResolvedSearchParams;
3
+ /** An object filter: `{ field: value }`, as opposed to engine syntax. */
4
+ export declare function isObjectFilter(filter: unknown): filter is Record<string, unknown>;
5
+ export declare function assertSafeField(driver: string, field: string): void;
6
+ /** `{ price: 'desc', name: 'asc' }` as `['price:desc', 'name:asc']`; strings pass through. */
7
+ export declare function sortToList(driver: string, sort: SearchSort | undefined): string[];
8
+ export declare const DEFAULT_SEARCH_LIMIT: 20;
9
+ /**
10
+ * Field names go into a filter DSL as identifiers, so only identifier
11
+ * characters (plus `.` for nested paths) are accepted. Without the check a key
12
+ * like `"category';TRUNCATE INDEX;'"` closes the clause and injects its own.
13
+ */
14
+ export declare const SAFE_FILTER_FIELD: RegExp;
15
+ /**
16
+ * The search parameters every driver reads, resolved once.
17
+ *
18
+ * Each driver used to read its own subset of names. The ORM's builder sends
19
+ * `{ q, limit, offset, filter }`; Meilisearch read `query`, `page` and
20
+ * `perPage`, found none of them, and searched for nothing - so
21
+ * `Product.search('widget').get()` returned the first twenty documents in the
22
+ * index, and `.paginate(10, 3)` returned page one every time. Resolving the
23
+ * contract here, once, is what keeps the drivers from drifting apart again.
24
+ */
25
+ export declare interface ResolvedSearchParams {
26
+ query: string
27
+ limit: number
28
+ offset: number
29
+ filter?: SearchFilter
30
+ sort?: SearchSort
31
+ }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@stacksjs/search-engine",
3
3
  "type": "module",
4
4
  "sideEffects": false,
5
- "version": "0.75.432",
5
+ "version": "0.75.443",
6
6
  "description": "The Stacks search engine integrations.",
7
7
  "author": "Chris Breuer",
8
8
  "contributors": [
@@ -64,14 +64,14 @@
64
64
  "prepublishOnly": "bun run build"
65
65
  },
66
66
  "dependencies": {
67
- "@stacksjs/config": "0.75.432",
68
- "@stacksjs/database": "0.75.432",
69
- "@stacksjs/error-handling": "0.75.432",
70
- "@stacksjs/logging": "0.75.432",
71
- "@stacksjs/orm": "0.75.432",
72
- "@stacksjs/path": "0.75.432",
73
- "@stacksjs/storage": "0.75.432",
74
- "@stacksjs/strings": "0.75.432"
67
+ "@stacksjs/config": "0.75.443",
68
+ "@stacksjs/database": "0.75.443",
69
+ "@stacksjs/error-handling": "0.75.443",
70
+ "@stacksjs/logging": "0.75.443",
71
+ "@stacksjs/orm": "0.75.443",
72
+ "@stacksjs/path": "0.75.443",
73
+ "@stacksjs/storage": "0.75.443",
74
+ "@stacksjs/strings": "0.75.443"
75
75
  },
76
76
  "peerDependencies": {
77
77
  "meilisearch": "^0.62.0"