@atscript/moost-mongo 0.0.25 → 0.0.26
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.cjs +25 -8
- package/dist/index.d.ts +18 -1
- package/dist/index.mjs +25 -8
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -226,16 +226,20 @@ var AsMongoController = class {
|
|
|
226
226
|
};
|
|
227
227
|
}
|
|
228
228
|
/**
|
|
229
|
-
* Prepares a MongoDB $search stage for
|
|
229
|
+
* Prepares a MongoDB $search stage for vector-based searching.
|
|
230
230
|
*
|
|
231
231
|
* @param searchTerm - The text string to search for. If not provided, no search is performed.
|
|
232
232
|
* @param indexName - The name of the Atlas Search index to use. If not provided, the default index is used.
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
233
|
+
*/ async prepareVectorSearch(searchTerm, indexName) {
|
|
234
|
+
return `Embeddings for ${indexName} are not supported`;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Prepares a MongoDB $search stage for text-based searching.
|
|
238
|
+
*
|
|
239
|
+
* @param searchTerm - The text string to search for. If not provided, no search is performed.
|
|
240
|
+
* @param index - The Atlas Search index definition.
|
|
241
|
+
* @returns A $search pipeline stage.
|
|
242
|
+
*/ prepareTextSearch(searchTerm, index) {
|
|
239
243
|
return { $search: {
|
|
240
244
|
index: index.key,
|
|
241
245
|
text: {
|
|
@@ -245,6 +249,19 @@ var AsMongoController = class {
|
|
|
245
249
|
} };
|
|
246
250
|
}
|
|
247
251
|
/**
|
|
252
|
+
* Prepares a MongoDB $search stage for text-based searching.
|
|
253
|
+
*
|
|
254
|
+
* @param searchTerm - The text string to search for. If not provided, no search is performed.
|
|
255
|
+
* @param indexName - The name of the Atlas Search index to use. If not provided, the default index is used.
|
|
256
|
+
* @returns A $search pipeline stage or an error string if the index is not found. Returns undefined if no searchTerm is provided.
|
|
257
|
+
*/ async prepareSearch(searchTerm, indexName) {
|
|
258
|
+
if (!searchTerm) return undefined;
|
|
259
|
+
const index = this.asCollection.getSearchIndex(indexName);
|
|
260
|
+
if (!index) return indexName ? `Search index "${indexName}" does not exist` : "No search index found";
|
|
261
|
+
if (!index.key) return `Invalid index definition: missing index key`;
|
|
262
|
+
return index.type === "vector" ? await this.prepareVectorSearch(searchTerm, indexName) : this.prepareTextSearch(searchTerm, index);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
248
265
|
* **GET /query** – returns an array of documents or a count depending on
|
|
249
266
|
* presence of `$count` control.
|
|
250
267
|
*
|
|
@@ -256,7 +273,7 @@ var AsMongoController = class {
|
|
|
256
273
|
const error = await this.validateUrlql(parsed, "query");
|
|
257
274
|
if (error) return error;
|
|
258
275
|
if (parsed.controls.$count) return this.asCollection.collection.countDocuments(parsed.filter);
|
|
259
|
-
const search = this.prepareSearch(parsed.controls.$search, parsed.controls.$index);
|
|
276
|
+
const search = await this.prepareSearch(parsed.controls.$search, parsed.controls.$index);
|
|
260
277
|
if (typeof search === "string") return new __moostjs_event_http.HttpError(400, search);
|
|
261
278
|
const { projection, sort, limit, skip } = this.prepareQueryOptions(parsed.controls);
|
|
262
279
|
const pipeline = [];
|
package/dist/index.d.ts
CHANGED
|
@@ -124,6 +124,23 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
|
|
|
124
124
|
limit: number | undefined;
|
|
125
125
|
skip: number | undefined;
|
|
126
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* Prepares a MongoDB $search stage for vector-based searching.
|
|
129
|
+
*
|
|
130
|
+
* @param searchTerm - The text string to search for. If not provided, no search is performed.
|
|
131
|
+
* @param indexName - The name of the Atlas Search index to use. If not provided, the default index is used.
|
|
132
|
+
*/
|
|
133
|
+
protected prepareVectorSearch(searchTerm: string, indexName?: string): Promise<string | undefined | Document>;
|
|
134
|
+
/**
|
|
135
|
+
* Prepares a MongoDB $search stage for text-based searching.
|
|
136
|
+
*
|
|
137
|
+
* @param searchTerm - The text string to search for. If not provided, no search is performed.
|
|
138
|
+
* @param index - The Atlas Search index definition.
|
|
139
|
+
* @returns A $search pipeline stage.
|
|
140
|
+
*/
|
|
141
|
+
protected prepareTextSearch(searchTerm: string, index: {
|
|
142
|
+
key: string;
|
|
143
|
+
}): Document;
|
|
127
144
|
/**
|
|
128
145
|
* Prepares a MongoDB $search stage for text-based searching.
|
|
129
146
|
*
|
|
@@ -131,7 +148,7 @@ declare class AsMongoController<T extends TAtscriptAnnotatedTypeConstructor> {
|
|
|
131
148
|
* @param indexName - The name of the Atlas Search index to use. If not provided, the default index is used.
|
|
132
149
|
* @returns A $search pipeline stage or an error string if the index is not found. Returns undefined if no searchTerm is provided.
|
|
133
150
|
*/
|
|
134
|
-
protected prepareSearch(searchTerm?: string, indexName?: string): string | undefined | Document
|
|
151
|
+
protected prepareSearch(searchTerm?: string, indexName?: string): Promise<string | undefined | Document>;
|
|
135
152
|
/**
|
|
136
153
|
* **GET /query** – returns an array of documents or a count depending on
|
|
137
154
|
* presence of `$count` control.
|
package/dist/index.mjs
CHANGED
|
@@ -202,16 +202,20 @@ var AsMongoController = class {
|
|
|
202
202
|
};
|
|
203
203
|
}
|
|
204
204
|
/**
|
|
205
|
-
* Prepares a MongoDB $search stage for
|
|
205
|
+
* Prepares a MongoDB $search stage for vector-based searching.
|
|
206
206
|
*
|
|
207
207
|
* @param searchTerm - The text string to search for. If not provided, no search is performed.
|
|
208
208
|
* @param indexName - The name of the Atlas Search index to use. If not provided, the default index is used.
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
209
|
+
*/ async prepareVectorSearch(searchTerm, indexName) {
|
|
210
|
+
return `Embeddings for ${indexName} are not supported`;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Prepares a MongoDB $search stage for text-based searching.
|
|
214
|
+
*
|
|
215
|
+
* @param searchTerm - The text string to search for. If not provided, no search is performed.
|
|
216
|
+
* @param index - The Atlas Search index definition.
|
|
217
|
+
* @returns A $search pipeline stage.
|
|
218
|
+
*/ prepareTextSearch(searchTerm, index) {
|
|
215
219
|
return { $search: {
|
|
216
220
|
index: index.key,
|
|
217
221
|
text: {
|
|
@@ -221,6 +225,19 @@ var AsMongoController = class {
|
|
|
221
225
|
} };
|
|
222
226
|
}
|
|
223
227
|
/**
|
|
228
|
+
* Prepares a MongoDB $search stage for text-based searching.
|
|
229
|
+
*
|
|
230
|
+
* @param searchTerm - The text string to search for. If not provided, no search is performed.
|
|
231
|
+
* @param indexName - The name of the Atlas Search index to use. If not provided, the default index is used.
|
|
232
|
+
* @returns A $search pipeline stage or an error string if the index is not found. Returns undefined if no searchTerm is provided.
|
|
233
|
+
*/ async prepareSearch(searchTerm, indexName) {
|
|
234
|
+
if (!searchTerm) return undefined;
|
|
235
|
+
const index = this.asCollection.getSearchIndex(indexName);
|
|
236
|
+
if (!index) return indexName ? `Search index "${indexName}" does not exist` : "No search index found";
|
|
237
|
+
if (!index.key) return `Invalid index definition: missing index key`;
|
|
238
|
+
return index.type === "vector" ? await this.prepareVectorSearch(searchTerm, indexName) : this.prepareTextSearch(searchTerm, index);
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
224
241
|
* **GET /query** – returns an array of documents or a count depending on
|
|
225
242
|
* presence of `$count` control.
|
|
226
243
|
*
|
|
@@ -232,7 +249,7 @@ var AsMongoController = class {
|
|
|
232
249
|
const error = await this.validateUrlql(parsed, "query");
|
|
233
250
|
if (error) return error;
|
|
234
251
|
if (parsed.controls.$count) return this.asCollection.collection.countDocuments(parsed.filter);
|
|
235
|
-
const search = this.prepareSearch(parsed.controls.$search, parsed.controls.$index);
|
|
252
|
+
const search = await this.prepareSearch(parsed.controls.$search, parsed.controls.$index);
|
|
236
253
|
if (typeof search === "string") return new HttpError(400, search);
|
|
237
254
|
const { projection, sort, limit, skip } = this.prepareQueryOptions(parsed.controls);
|
|
238
255
|
const pipeline = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atscript/moost-mongo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.26",
|
|
4
4
|
"description": "Atscript Mongo for Moost.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"@moostjs/event-http": "^0.5.32",
|
|
45
45
|
"mongodb": "^6.17.0",
|
|
46
46
|
"moost": "^0.5.32",
|
|
47
|
-
"@atscript/mongo": "^0.0.
|
|
48
|
-
"@atscript/typescript": "^0.0.
|
|
47
|
+
"@atscript/mongo": "^0.0.26",
|
|
48
|
+
"@atscript/typescript": "^0.0.26"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"pub": "pnpm publish --access public",
|