@basaltkit/search 1.2.0 → 1.3.0
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/index.d.ts +4 -1
- package/dist/index.js +16 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -106,6 +106,9 @@ declare class MeilisearchError extends BasaltError {
|
|
|
106
106
|
declare class SearchFilterFieldError extends BasaltError {
|
|
107
107
|
constructor(field: string);
|
|
108
108
|
}
|
|
109
|
+
declare class SearchIndexNameError extends BasaltError {
|
|
110
|
+
constructor(name: string);
|
|
111
|
+
}
|
|
109
112
|
interface MeilisearchDriverOptions {
|
|
110
113
|
host: string;
|
|
111
114
|
apiKey?: string;
|
|
@@ -169,4 +172,4 @@ interface SearchPluginOptions {
|
|
|
169
172
|
}
|
|
170
173
|
declare function searchPlugin(options?: SearchPluginOptions): _basaltkit_core.BasaltPlugin<unknown>;
|
|
171
174
|
|
|
172
|
-
export { type IndexDefinition, MeilisearchDriver, type MeilisearchDriverOptions, MeilisearchError, MemorySearchDriver, SEARCH, Search, type SearchDocument, type SearchDriver, SearchFilterFieldError, type SearchHit, type SearchOptions, type SearchPluginOptions, type SearchQuery, type SearchResult, type SyncRule, TenantRequiredError, defineIndex, searchPlugin, syncRule };
|
|
175
|
+
export { type IndexDefinition, MeilisearchDriver, type MeilisearchDriverOptions, MeilisearchError, MemorySearchDriver, SEARCH, Search, type SearchDocument, type SearchDriver, SearchFilterFieldError, type SearchHit, SearchIndexNameError, type SearchOptions, type SearchPluginOptions, type SearchQuery, type SearchResult, type SyncRule, TenantRequiredError, defineIndex, searchPlugin, syncRule };
|
package/dist/index.js
CHANGED
|
@@ -133,6 +133,16 @@ var SearchFilterFieldError = class extends BasaltError2 {
|
|
|
133
133
|
super("SEARCH_INVALID_FILTER_FIELD", `Invalid filter field name: ${JSON.stringify(field)}.`);
|
|
134
134
|
}
|
|
135
135
|
};
|
|
136
|
+
var SearchIndexNameError = class extends BasaltError2 {
|
|
137
|
+
constructor(name) {
|
|
138
|
+
super("SEARCH_INVALID_INDEX_NAME", `Invalid index name: ${JSON.stringify(name)}.`);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
var SAFE_INDEX_NAME = /^[A-Za-z0-9_-]+$/;
|
|
142
|
+
var assertValidIndexName = (name) => {
|
|
143
|
+
if (!SAFE_INDEX_NAME.test(name)) throw new SearchIndexNameError(name);
|
|
144
|
+
return name;
|
|
145
|
+
};
|
|
136
146
|
var SAFE_FILTER_FIELD = /^[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$/;
|
|
137
147
|
var primaryKey = (tenantId, id) => Buffer.from(`${tenantId}::${id}`).toString("base64url");
|
|
138
148
|
var quote = (value) => JSON.stringify(value);
|
|
@@ -144,6 +154,7 @@ var MeilisearchDriver = class {
|
|
|
144
154
|
options;
|
|
145
155
|
fetch;
|
|
146
156
|
async register(index) {
|
|
157
|
+
assertValidIndexName(index.name);
|
|
147
158
|
try {
|
|
148
159
|
await this.request("POST", "/indexes", { uid: index.name, primaryKey: "_pk" });
|
|
149
160
|
} catch {
|
|
@@ -157,16 +168,20 @@ var MeilisearchDriver = class {
|
|
|
157
168
|
await this.bulk(indexName, [document]);
|
|
158
169
|
}
|
|
159
170
|
async bulk(indexName, documents) {
|
|
171
|
+
assertValidIndexName(indexName);
|
|
160
172
|
const withPk = documents.map((d) => ({ ...d, _pk: primaryKey(d.tenantId, d.id) }));
|
|
161
173
|
await this.request("PUT", `/indexes/${indexName}/documents`, withPk);
|
|
162
174
|
}
|
|
163
175
|
async remove(indexName, tenantId, id) {
|
|
176
|
+
assertValidIndexName(indexName);
|
|
164
177
|
await this.request("DELETE", `/indexes/${indexName}/documents/${primaryKey(tenantId, id)}`);
|
|
165
178
|
}
|
|
166
179
|
async clear(indexName) {
|
|
180
|
+
assertValidIndexName(indexName);
|
|
167
181
|
await this.request("DELETE", `/indexes/${indexName}/documents`);
|
|
168
182
|
}
|
|
169
183
|
async search(indexName, query) {
|
|
184
|
+
assertValidIndexName(indexName);
|
|
170
185
|
const result = await this.request("POST", `/indexes/${indexName}/search`, {
|
|
171
186
|
q: query.q,
|
|
172
187
|
filter: this.buildFilter(query.tenantId, query.filters),
|
|
@@ -262,6 +277,7 @@ export {
|
|
|
262
277
|
SEARCH,
|
|
263
278
|
Search,
|
|
264
279
|
SearchFilterFieldError,
|
|
280
|
+
SearchIndexNameError,
|
|
265
281
|
TenantRequiredError,
|
|
266
282
|
defineIndex,
|
|
267
283
|
searchPlugin,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basaltkit/search",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Full-text search for Basalt: tenant-scoped indexing and querying with a pluggable driver (in-memory for dev/test, Meilisearch for production) and automatic sync from domain events.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|