@convex-dev/rag 0.5.4 → 0.6.1
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 +89 -82
- package/dist/client/index.d.ts +30 -26
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +2 -2
- package/dist/client/index.js.map +1 -1
- package/dist/component/_generated/api.d.ts +25 -482
- package/dist/component/_generated/api.d.ts.map +1 -1
- package/dist/component/_generated/api.js +10 -1
- package/dist/component/_generated/api.js.map +1 -1
- package/dist/component/_generated/component.d.ts +380 -0
- package/dist/component/_generated/component.d.ts.map +1 -0
- package/dist/component/_generated/component.js +11 -0
- package/dist/component/_generated/component.js.map +1 -0
- package/dist/component/_generated/dataModel.d.ts +4 -18
- package/dist/component/_generated/dataModel.d.ts.map +1 -0
- package/dist/component/_generated/dataModel.js +11 -0
- package/dist/component/_generated/dataModel.js.map +1 -0
- package/dist/component/_generated/server.d.ts +10 -38
- package/dist/component/_generated/server.d.ts.map +1 -1
- package/dist/component/_generated/server.js +9 -5
- package/dist/component/_generated/server.js.map +1 -1
- package/dist/component/chunks.d.ts +5 -5
- package/dist/component/chunks.d.ts.map +1 -1
- package/dist/component/chunks.js +21 -51
- package/dist/component/chunks.js.map +1 -1
- package/dist/component/embeddings/tables.d.ts +4 -5
- package/dist/component/embeddings/tables.d.ts.map +1 -1
- package/dist/component/embeddings/tables.js.map +1 -1
- package/dist/component/entries.d.ts +6 -6
- package/dist/component/namespaces.d.ts +8 -8
- package/dist/component/namespaces.d.ts.map +1 -1
- package/dist/component/namespaces.js +2 -2
- package/dist/component/namespaces.js.map +1 -1
- package/dist/component/schema.d.ts +185 -224
- package/dist/component/schema.d.ts.map +1 -1
- package/dist/component/search.d.ts +4 -3
- package/dist/component/search.d.ts.map +1 -1
- package/dist/component/search.js +1 -1
- package/dist/component/search.js.map +1 -1
- package/dist/shared.d.ts +9 -4
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +1 -4
- package/dist/shared.js.map +1 -1
- package/package.json +72 -44
- package/src/client/defaultChunker.test.ts +1 -1
- package/src/client/defaultChunker.ts +7 -7
- package/src/client/fileUtils.ts +3 -3
- package/src/client/hybridRank.ts +1 -1
- package/src/client/index.test.ts +18 -18
- package/src/client/index.ts +104 -84
- package/src/client/setup.test.ts +2 -2
- package/src/component/_generated/api.ts +66 -0
- package/src/component/_generated/component.ts +442 -0
- package/src/component/_generated/{server.d.ts → server.ts} +33 -21
- package/src/component/chunks.test.ts +14 -14
- package/src/component/chunks.ts +59 -88
- package/src/component/embeddings/importance.test.ts +4 -4
- package/src/component/embeddings/importance.ts +1 -1
- package/src/component/embeddings/index.test.ts +3 -4
- package/src/component/embeddings/index.ts +6 -6
- package/src/component/embeddings/tables.ts +9 -8
- package/src/component/entries.test.ts +10 -10
- package/src/component/entries.ts +29 -29
- package/src/component/filters.ts +8 -8
- package/src/component/namespaces.ts +31 -34
- package/src/component/schema.ts +2 -2
- package/src/component/search.test.ts +5 -5
- package/src/component/search.ts +8 -9
- package/src/component/setup.test.ts +2 -8
- package/src/shared.ts +47 -45
- package/src/test.ts +20 -0
- package/dist/client/types.d.ts +0 -29
- package/dist/client/types.d.ts.map +0 -1
- package/dist/client/types.js +0 -2
- package/dist/client/types.js.map +0 -1
- package/dist/package.json +0 -3
- package/src/client/types.ts +0 -69
- package/src/component/_generated/api.d.ts +0 -507
- package/src/component/_generated/api.js +0 -23
- package/src/component/_generated/server.js +0 -90
- package/src/vitest.config.ts +0 -7
- /package/src/component/_generated/{dataModel.d.ts → dataModel.ts} +0 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `ComponentApi` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { FunctionReference } from "convex/server";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A utility for referencing a Convex component's exposed API.
|
|
15
|
+
*
|
|
16
|
+
* Useful when expecting a parameter like `components.myComponent`.
|
|
17
|
+
* Usage:
|
|
18
|
+
* ```ts
|
|
19
|
+
* async function myFunction(ctx: QueryCtx, component: ComponentApi) {
|
|
20
|
+
* return ctx.runQuery(component.someFile.someQuery, { ...args });
|
|
21
|
+
* }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export type ComponentApi<Name extends string | undefined = string | undefined> =
|
|
25
|
+
{
|
|
26
|
+
chunks: {
|
|
27
|
+
insert: FunctionReference<
|
|
28
|
+
"mutation",
|
|
29
|
+
"internal",
|
|
30
|
+
{
|
|
31
|
+
chunks: Array<{
|
|
32
|
+
content: { metadata?: Record<string, any>; text: string };
|
|
33
|
+
embedding: Array<number>;
|
|
34
|
+
searchableText?: string;
|
|
35
|
+
}>;
|
|
36
|
+
entryId: string;
|
|
37
|
+
startOrder: number;
|
|
38
|
+
},
|
|
39
|
+
{ status: "pending" | "ready" | "replaced" },
|
|
40
|
+
Name
|
|
41
|
+
>;
|
|
42
|
+
list: FunctionReference<
|
|
43
|
+
"query",
|
|
44
|
+
"internal",
|
|
45
|
+
{
|
|
46
|
+
entryId: string;
|
|
47
|
+
order: "desc" | "asc";
|
|
48
|
+
paginationOpts: {
|
|
49
|
+
cursor: string | null;
|
|
50
|
+
endCursor?: string | null;
|
|
51
|
+
id?: number;
|
|
52
|
+
maximumBytesRead?: number;
|
|
53
|
+
maximumRowsRead?: number;
|
|
54
|
+
numItems: number;
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
continueCursor: string;
|
|
59
|
+
isDone: boolean;
|
|
60
|
+
page: Array<{
|
|
61
|
+
metadata?: Record<string, any>;
|
|
62
|
+
order: number;
|
|
63
|
+
state: "pending" | "ready" | "replaced";
|
|
64
|
+
text: string;
|
|
65
|
+
}>;
|
|
66
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
67
|
+
splitCursor?: string | null;
|
|
68
|
+
},
|
|
69
|
+
Name
|
|
70
|
+
>;
|
|
71
|
+
replaceChunksPage: FunctionReference<
|
|
72
|
+
"mutation",
|
|
73
|
+
"internal",
|
|
74
|
+
{ entryId: string; startOrder: number },
|
|
75
|
+
{ nextStartOrder: number; status: "pending" | "ready" | "replaced" },
|
|
76
|
+
Name
|
|
77
|
+
>;
|
|
78
|
+
};
|
|
79
|
+
entries: {
|
|
80
|
+
add: FunctionReference<
|
|
81
|
+
"mutation",
|
|
82
|
+
"internal",
|
|
83
|
+
{
|
|
84
|
+
allChunks?: Array<{
|
|
85
|
+
content: { metadata?: Record<string, any>; text: string };
|
|
86
|
+
embedding: Array<number>;
|
|
87
|
+
searchableText?: string;
|
|
88
|
+
}>;
|
|
89
|
+
entry: {
|
|
90
|
+
contentHash?: string;
|
|
91
|
+
filterValues: Array<{ name: string; value: any }>;
|
|
92
|
+
importance: number;
|
|
93
|
+
key?: string;
|
|
94
|
+
metadata?: Record<string, any>;
|
|
95
|
+
namespaceId: string;
|
|
96
|
+
title?: string;
|
|
97
|
+
};
|
|
98
|
+
onComplete?: string;
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
created: boolean;
|
|
102
|
+
entryId: string;
|
|
103
|
+
status: "pending" | "ready" | "replaced";
|
|
104
|
+
},
|
|
105
|
+
Name
|
|
106
|
+
>;
|
|
107
|
+
addAsync: FunctionReference<
|
|
108
|
+
"mutation",
|
|
109
|
+
"internal",
|
|
110
|
+
{
|
|
111
|
+
chunker: string;
|
|
112
|
+
entry: {
|
|
113
|
+
contentHash?: string;
|
|
114
|
+
filterValues: Array<{ name: string; value: any }>;
|
|
115
|
+
importance: number;
|
|
116
|
+
key?: string;
|
|
117
|
+
metadata?: Record<string, any>;
|
|
118
|
+
namespaceId: string;
|
|
119
|
+
title?: string;
|
|
120
|
+
};
|
|
121
|
+
onComplete?: string;
|
|
122
|
+
},
|
|
123
|
+
{ created: boolean; entryId: string; status: "pending" | "ready" },
|
|
124
|
+
Name
|
|
125
|
+
>;
|
|
126
|
+
deleteAsync: FunctionReference<
|
|
127
|
+
"mutation",
|
|
128
|
+
"internal",
|
|
129
|
+
{ entryId: string; startOrder: number },
|
|
130
|
+
null,
|
|
131
|
+
Name
|
|
132
|
+
>;
|
|
133
|
+
deleteByKeyAsync: FunctionReference<
|
|
134
|
+
"mutation",
|
|
135
|
+
"internal",
|
|
136
|
+
{ beforeVersion?: number; key: string; namespaceId: string },
|
|
137
|
+
null,
|
|
138
|
+
Name
|
|
139
|
+
>;
|
|
140
|
+
deleteByKeySync: FunctionReference<
|
|
141
|
+
"action",
|
|
142
|
+
"internal",
|
|
143
|
+
{ key: string; namespaceId: string },
|
|
144
|
+
null,
|
|
145
|
+
Name
|
|
146
|
+
>;
|
|
147
|
+
deleteSync: FunctionReference<
|
|
148
|
+
"action",
|
|
149
|
+
"internal",
|
|
150
|
+
{ entryId: string },
|
|
151
|
+
null,
|
|
152
|
+
Name
|
|
153
|
+
>;
|
|
154
|
+
findByContentHash: FunctionReference<
|
|
155
|
+
"query",
|
|
156
|
+
"internal",
|
|
157
|
+
{
|
|
158
|
+
contentHash: string;
|
|
159
|
+
dimension: number;
|
|
160
|
+
filterNames: Array<string>;
|
|
161
|
+
key: string;
|
|
162
|
+
modelId: string;
|
|
163
|
+
namespace: string;
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
contentHash?: string;
|
|
167
|
+
entryId: string;
|
|
168
|
+
filterValues: Array<{ name: string; value: any }>;
|
|
169
|
+
importance: number;
|
|
170
|
+
key?: string;
|
|
171
|
+
metadata?: Record<string, any>;
|
|
172
|
+
replacedAt?: number;
|
|
173
|
+
status: "pending" | "ready" | "replaced";
|
|
174
|
+
title?: string;
|
|
175
|
+
} | null,
|
|
176
|
+
Name
|
|
177
|
+
>;
|
|
178
|
+
get: FunctionReference<
|
|
179
|
+
"query",
|
|
180
|
+
"internal",
|
|
181
|
+
{ entryId: string },
|
|
182
|
+
{
|
|
183
|
+
contentHash?: string;
|
|
184
|
+
entryId: string;
|
|
185
|
+
filterValues: Array<{ name: string; value: any }>;
|
|
186
|
+
importance: number;
|
|
187
|
+
key?: string;
|
|
188
|
+
metadata?: Record<string, any>;
|
|
189
|
+
replacedAt?: number;
|
|
190
|
+
status: "pending" | "ready" | "replaced";
|
|
191
|
+
title?: string;
|
|
192
|
+
} | null,
|
|
193
|
+
Name
|
|
194
|
+
>;
|
|
195
|
+
list: FunctionReference<
|
|
196
|
+
"query",
|
|
197
|
+
"internal",
|
|
198
|
+
{
|
|
199
|
+
namespaceId?: string;
|
|
200
|
+
order?: "desc" | "asc";
|
|
201
|
+
paginationOpts: {
|
|
202
|
+
cursor: string | null;
|
|
203
|
+
endCursor?: string | null;
|
|
204
|
+
id?: number;
|
|
205
|
+
maximumBytesRead?: number;
|
|
206
|
+
maximumRowsRead?: number;
|
|
207
|
+
numItems: number;
|
|
208
|
+
};
|
|
209
|
+
status: "pending" | "ready" | "replaced";
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
continueCursor: string;
|
|
213
|
+
isDone: boolean;
|
|
214
|
+
page: Array<{
|
|
215
|
+
contentHash?: string;
|
|
216
|
+
entryId: string;
|
|
217
|
+
filterValues: Array<{ name: string; value: any }>;
|
|
218
|
+
importance: number;
|
|
219
|
+
key?: string;
|
|
220
|
+
metadata?: Record<string, any>;
|
|
221
|
+
replacedAt?: number;
|
|
222
|
+
status: "pending" | "ready" | "replaced";
|
|
223
|
+
title?: string;
|
|
224
|
+
}>;
|
|
225
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
226
|
+
splitCursor?: string | null;
|
|
227
|
+
},
|
|
228
|
+
Name
|
|
229
|
+
>;
|
|
230
|
+
promoteToReady: FunctionReference<
|
|
231
|
+
"mutation",
|
|
232
|
+
"internal",
|
|
233
|
+
{ entryId: string },
|
|
234
|
+
{
|
|
235
|
+
replacedEntry: {
|
|
236
|
+
contentHash?: string;
|
|
237
|
+
entryId: string;
|
|
238
|
+
filterValues: Array<{ name: string; value: any }>;
|
|
239
|
+
importance: number;
|
|
240
|
+
key?: string;
|
|
241
|
+
metadata?: Record<string, any>;
|
|
242
|
+
replacedAt?: number;
|
|
243
|
+
status: "pending" | "ready" | "replaced";
|
|
244
|
+
title?: string;
|
|
245
|
+
} | null;
|
|
246
|
+
},
|
|
247
|
+
Name
|
|
248
|
+
>;
|
|
249
|
+
};
|
|
250
|
+
namespaces: {
|
|
251
|
+
deleteNamespace: FunctionReference<
|
|
252
|
+
"mutation",
|
|
253
|
+
"internal",
|
|
254
|
+
{ namespaceId: string },
|
|
255
|
+
{
|
|
256
|
+
deletedNamespace: null | {
|
|
257
|
+
createdAt: number;
|
|
258
|
+
dimension: number;
|
|
259
|
+
filterNames: Array<string>;
|
|
260
|
+
modelId: string;
|
|
261
|
+
namespace: string;
|
|
262
|
+
namespaceId: string;
|
|
263
|
+
status: "pending" | "ready" | "replaced";
|
|
264
|
+
version: number;
|
|
265
|
+
};
|
|
266
|
+
},
|
|
267
|
+
Name
|
|
268
|
+
>;
|
|
269
|
+
deleteNamespaceSync: FunctionReference<
|
|
270
|
+
"action",
|
|
271
|
+
"internal",
|
|
272
|
+
{ namespaceId: string },
|
|
273
|
+
null,
|
|
274
|
+
Name
|
|
275
|
+
>;
|
|
276
|
+
get: FunctionReference<
|
|
277
|
+
"query",
|
|
278
|
+
"internal",
|
|
279
|
+
{
|
|
280
|
+
dimension: number;
|
|
281
|
+
filterNames: Array<string>;
|
|
282
|
+
modelId: string;
|
|
283
|
+
namespace: string;
|
|
284
|
+
},
|
|
285
|
+
null | {
|
|
286
|
+
createdAt: number;
|
|
287
|
+
dimension: number;
|
|
288
|
+
filterNames: Array<string>;
|
|
289
|
+
modelId: string;
|
|
290
|
+
namespace: string;
|
|
291
|
+
namespaceId: string;
|
|
292
|
+
status: "pending" | "ready" | "replaced";
|
|
293
|
+
version: number;
|
|
294
|
+
},
|
|
295
|
+
Name
|
|
296
|
+
>;
|
|
297
|
+
getOrCreate: FunctionReference<
|
|
298
|
+
"mutation",
|
|
299
|
+
"internal",
|
|
300
|
+
{
|
|
301
|
+
dimension: number;
|
|
302
|
+
filterNames: Array<string>;
|
|
303
|
+
modelId: string;
|
|
304
|
+
namespace: string;
|
|
305
|
+
onComplete?: string;
|
|
306
|
+
status: "pending" | "ready";
|
|
307
|
+
},
|
|
308
|
+
{ namespaceId: string; status: "pending" | "ready" },
|
|
309
|
+
Name
|
|
310
|
+
>;
|
|
311
|
+
list: FunctionReference<
|
|
312
|
+
"query",
|
|
313
|
+
"internal",
|
|
314
|
+
{
|
|
315
|
+
paginationOpts: {
|
|
316
|
+
cursor: string | null;
|
|
317
|
+
endCursor?: string | null;
|
|
318
|
+
id?: number;
|
|
319
|
+
maximumBytesRead?: number;
|
|
320
|
+
maximumRowsRead?: number;
|
|
321
|
+
numItems: number;
|
|
322
|
+
};
|
|
323
|
+
status: "pending" | "ready" | "replaced";
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
continueCursor: string;
|
|
327
|
+
isDone: boolean;
|
|
328
|
+
page: Array<{
|
|
329
|
+
createdAt: number;
|
|
330
|
+
dimension: number;
|
|
331
|
+
filterNames: Array<string>;
|
|
332
|
+
modelId: string;
|
|
333
|
+
namespace: string;
|
|
334
|
+
namespaceId: string;
|
|
335
|
+
status: "pending" | "ready" | "replaced";
|
|
336
|
+
version: number;
|
|
337
|
+
}>;
|
|
338
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
339
|
+
splitCursor?: string | null;
|
|
340
|
+
},
|
|
341
|
+
Name
|
|
342
|
+
>;
|
|
343
|
+
listNamespaceVersions: FunctionReference<
|
|
344
|
+
"query",
|
|
345
|
+
"internal",
|
|
346
|
+
{
|
|
347
|
+
namespace: string;
|
|
348
|
+
paginationOpts: {
|
|
349
|
+
cursor: string | null;
|
|
350
|
+
endCursor?: string | null;
|
|
351
|
+
id?: number;
|
|
352
|
+
maximumBytesRead?: number;
|
|
353
|
+
maximumRowsRead?: number;
|
|
354
|
+
numItems: number;
|
|
355
|
+
};
|
|
356
|
+
},
|
|
357
|
+
{
|
|
358
|
+
continueCursor: string;
|
|
359
|
+
isDone: boolean;
|
|
360
|
+
page: Array<{
|
|
361
|
+
createdAt: number;
|
|
362
|
+
dimension: number;
|
|
363
|
+
filterNames: Array<string>;
|
|
364
|
+
modelId: string;
|
|
365
|
+
namespace: string;
|
|
366
|
+
namespaceId: string;
|
|
367
|
+
status: "pending" | "ready" | "replaced";
|
|
368
|
+
version: number;
|
|
369
|
+
}>;
|
|
370
|
+
pageStatus?: "SplitRecommended" | "SplitRequired" | null;
|
|
371
|
+
splitCursor?: string | null;
|
|
372
|
+
},
|
|
373
|
+
Name
|
|
374
|
+
>;
|
|
375
|
+
lookup: FunctionReference<
|
|
376
|
+
"query",
|
|
377
|
+
"internal",
|
|
378
|
+
{
|
|
379
|
+
dimension: number;
|
|
380
|
+
filterNames: Array<string>;
|
|
381
|
+
modelId: string;
|
|
382
|
+
namespace: string;
|
|
383
|
+
},
|
|
384
|
+
null | string,
|
|
385
|
+
Name
|
|
386
|
+
>;
|
|
387
|
+
promoteToReady: FunctionReference<
|
|
388
|
+
"mutation",
|
|
389
|
+
"internal",
|
|
390
|
+
{ namespaceId: string },
|
|
391
|
+
{
|
|
392
|
+
replacedNamespace: null | {
|
|
393
|
+
createdAt: number;
|
|
394
|
+
dimension: number;
|
|
395
|
+
filterNames: Array<string>;
|
|
396
|
+
modelId: string;
|
|
397
|
+
namespace: string;
|
|
398
|
+
namespaceId: string;
|
|
399
|
+
status: "pending" | "ready" | "replaced";
|
|
400
|
+
version: number;
|
|
401
|
+
};
|
|
402
|
+
},
|
|
403
|
+
Name
|
|
404
|
+
>;
|
|
405
|
+
};
|
|
406
|
+
search: {
|
|
407
|
+
search: FunctionReference<
|
|
408
|
+
"action",
|
|
409
|
+
"internal",
|
|
410
|
+
{
|
|
411
|
+
chunkContext?: { after: number; before: number };
|
|
412
|
+
embedding: Array<number>;
|
|
413
|
+
filters: Array<{ name: string; value: any }>;
|
|
414
|
+
limit: number;
|
|
415
|
+
modelId: string;
|
|
416
|
+
namespace: string;
|
|
417
|
+
vectorScoreThreshold?: number;
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
entries: Array<{
|
|
421
|
+
contentHash?: string;
|
|
422
|
+
entryId: string;
|
|
423
|
+
filterValues: Array<{ name: string; value: any }>;
|
|
424
|
+
importance: number;
|
|
425
|
+
key?: string;
|
|
426
|
+
metadata?: Record<string, any>;
|
|
427
|
+
replacedAt?: number;
|
|
428
|
+
status: "pending" | "ready" | "replaced";
|
|
429
|
+
title?: string;
|
|
430
|
+
}>;
|
|
431
|
+
results: Array<{
|
|
432
|
+
content: Array<{ metadata?: Record<string, any>; text: string }>;
|
|
433
|
+
entryId: string;
|
|
434
|
+
order: number;
|
|
435
|
+
score: number;
|
|
436
|
+
startOrder: number;
|
|
437
|
+
}>;
|
|
438
|
+
},
|
|
439
|
+
Name
|
|
440
|
+
>;
|
|
441
|
+
};
|
|
442
|
+
};
|
|
@@ -8,9 +8,8 @@
|
|
|
8
8
|
* @module
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import type {
|
|
12
12
|
ActionBuilder,
|
|
13
|
-
AnyComponents,
|
|
14
13
|
HttpActionBuilder,
|
|
15
14
|
MutationBuilder,
|
|
16
15
|
QueryBuilder,
|
|
@@ -19,15 +18,18 @@ import {
|
|
|
19
18
|
GenericQueryCtx,
|
|
20
19
|
GenericDatabaseReader,
|
|
21
20
|
GenericDatabaseWriter,
|
|
22
|
-
|
|
21
|
+
} from "convex/server";
|
|
22
|
+
import {
|
|
23
|
+
actionGeneric,
|
|
24
|
+
httpActionGeneric,
|
|
25
|
+
queryGeneric,
|
|
26
|
+
mutationGeneric,
|
|
27
|
+
internalActionGeneric,
|
|
28
|
+
internalMutationGeneric,
|
|
29
|
+
internalQueryGeneric,
|
|
23
30
|
} from "convex/server";
|
|
24
31
|
import type { DataModel } from "./dataModel.js";
|
|
25
32
|
|
|
26
|
-
type GenericCtx =
|
|
27
|
-
| GenericActionCtx<DataModel>
|
|
28
|
-
| GenericMutationCtx<DataModel>
|
|
29
|
-
| GenericQueryCtx<DataModel>;
|
|
30
|
-
|
|
31
33
|
/**
|
|
32
34
|
* Define a query in this Convex app's public API.
|
|
33
35
|
*
|
|
@@ -36,7 +38,7 @@ type GenericCtx =
|
|
|
36
38
|
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
37
39
|
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
38
40
|
*/
|
|
39
|
-
export
|
|
41
|
+
export const query: QueryBuilder<DataModel, "public"> = queryGeneric;
|
|
40
42
|
|
|
41
43
|
/**
|
|
42
44
|
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
@@ -46,7 +48,8 @@ export declare const query: QueryBuilder<DataModel, "public">;
|
|
|
46
48
|
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
47
49
|
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
48
50
|
*/
|
|
49
|
-
export
|
|
51
|
+
export const internalQuery: QueryBuilder<DataModel, "internal"> =
|
|
52
|
+
internalQueryGeneric;
|
|
50
53
|
|
|
51
54
|
/**
|
|
52
55
|
* Define a mutation in this Convex app's public API.
|
|
@@ -56,7 +59,7 @@ export declare const internalQuery: QueryBuilder<DataModel, "internal">;
|
|
|
56
59
|
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
57
60
|
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
58
61
|
*/
|
|
59
|
-
export
|
|
62
|
+
export const mutation: MutationBuilder<DataModel, "public"> = mutationGeneric;
|
|
60
63
|
|
|
61
64
|
/**
|
|
62
65
|
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
@@ -66,7 +69,8 @@ export declare const mutation: MutationBuilder<DataModel, "public">;
|
|
|
66
69
|
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
67
70
|
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
68
71
|
*/
|
|
69
|
-
export
|
|
72
|
+
export const internalMutation: MutationBuilder<DataModel, "internal"> =
|
|
73
|
+
internalMutationGeneric;
|
|
70
74
|
|
|
71
75
|
/**
|
|
72
76
|
* Define an action in this Convex app's public API.
|
|
@@ -79,7 +83,7 @@ export declare const internalMutation: MutationBuilder<DataModel, "internal">;
|
|
|
79
83
|
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
80
84
|
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
81
85
|
*/
|
|
82
|
-
export
|
|
86
|
+
export const action: ActionBuilder<DataModel, "public"> = actionGeneric;
|
|
83
87
|
|
|
84
88
|
/**
|
|
85
89
|
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
@@ -87,19 +91,26 @@ export declare const action: ActionBuilder<DataModel, "public">;
|
|
|
87
91
|
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
88
92
|
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
89
93
|
*/
|
|
90
|
-
export
|
|
94
|
+
export const internalAction: ActionBuilder<DataModel, "internal"> =
|
|
95
|
+
internalActionGeneric;
|
|
91
96
|
|
|
92
97
|
/**
|
|
93
98
|
* Define an HTTP action.
|
|
94
99
|
*
|
|
95
|
-
*
|
|
96
|
-
* deployment if the requests matches the path and method where
|
|
97
|
-
* is routed. Be sure to route your
|
|
100
|
+
* The wrapped function will be used to respond to HTTP requests received
|
|
101
|
+
* by a Convex deployment if the requests matches the path and method where
|
|
102
|
+
* this action is routed. Be sure to route your httpAction in `convex/http.js`.
|
|
98
103
|
*
|
|
99
|
-
* @param func - The function. It receives an {@link ActionCtx} as its first argument
|
|
104
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument
|
|
105
|
+
* and a Fetch API `Request` object as its second.
|
|
100
106
|
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
101
107
|
*/
|
|
102
|
-
export
|
|
108
|
+
export const httpAction: HttpActionBuilder = httpActionGeneric;
|
|
109
|
+
|
|
110
|
+
type GenericCtx =
|
|
111
|
+
| GenericActionCtx<DataModel>
|
|
112
|
+
| GenericMutationCtx<DataModel>
|
|
113
|
+
| GenericQueryCtx<DataModel>;
|
|
103
114
|
|
|
104
115
|
/**
|
|
105
116
|
* A set of services for use within Convex query functions.
|
|
@@ -107,8 +118,7 @@ export declare const httpAction: HttpActionBuilder;
|
|
|
107
118
|
* The query context is passed as the first argument to any Convex query
|
|
108
119
|
* function run on the server.
|
|
109
120
|
*
|
|
110
|
-
*
|
|
111
|
-
* read-only.
|
|
121
|
+
* If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
|
|
112
122
|
*/
|
|
113
123
|
export type QueryCtx = GenericQueryCtx<DataModel>;
|
|
114
124
|
|
|
@@ -117,6 +127,8 @@ export type QueryCtx = GenericQueryCtx<DataModel>;
|
|
|
117
127
|
*
|
|
118
128
|
* The mutation context is passed as the first argument to any Convex mutation
|
|
119
129
|
* function run on the server.
|
|
130
|
+
*
|
|
131
|
+
* If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
|
|
120
132
|
*/
|
|
121
133
|
export type MutationCtx = GenericMutationCtx<DataModel>;
|
|
122
134
|
|
|
@@ -30,7 +30,7 @@ describe("chunks", () => {
|
|
|
30
30
|
namespaceId: Id<"namespaces">,
|
|
31
31
|
key = "test-entry",
|
|
32
32
|
version = 0,
|
|
33
|
-
status: "ready" | "pending" = "ready"
|
|
33
|
+
status: "ready" | "pending" = "ready",
|
|
34
34
|
) {
|
|
35
35
|
return await t.run(async (ctx) => {
|
|
36
36
|
return ctx.db.insert("entries", {
|
|
@@ -70,7 +70,7 @@ describe("chunks", () => {
|
|
|
70
70
|
startOrder: 0,
|
|
71
71
|
chunks,
|
|
72
72
|
});
|
|
73
|
-
})
|
|
73
|
+
}),
|
|
74
74
|
).rejects.toThrow(`Entry ${nonExistentDocId} not found`);
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -141,10 +141,10 @@ describe("chunks", () => {
|
|
|
141
141
|
expect(overwrittenChunk2).toBeDefined();
|
|
142
142
|
|
|
143
143
|
const content1 = await t.run(async (ctx) =>
|
|
144
|
-
ctx.db.get(overwrittenChunk1!.contentId)
|
|
144
|
+
ctx.db.get(overwrittenChunk1!.contentId),
|
|
145
145
|
);
|
|
146
146
|
const content2 = await t.run(async (ctx) =>
|
|
147
|
-
ctx.db.get(overwrittenChunk2!.contentId)
|
|
147
|
+
ctx.db.get(overwrittenChunk2!.contentId),
|
|
148
148
|
);
|
|
149
149
|
|
|
150
150
|
expect(content1!.text).toBe("Overwritten chunk 1 content");
|
|
@@ -176,7 +176,7 @@ describe("chunks", () => {
|
|
|
176
176
|
namespaceId,
|
|
177
177
|
"versioned-entry",
|
|
178
178
|
2,
|
|
179
|
-
"pending"
|
|
179
|
+
"pending",
|
|
180
180
|
);
|
|
181
181
|
|
|
182
182
|
// Insert chunks in version 2 (this should mark v1 chunks as replaced)
|
|
@@ -279,10 +279,10 @@ describe("chunks", () => {
|
|
|
279
279
|
|
|
280
280
|
// Verify chunk content
|
|
281
281
|
const doc1Content0 = await t.run(async (ctx) =>
|
|
282
|
-
ctx.db.get(doc1ChunksList[0].contentId)
|
|
282
|
+
ctx.db.get(doc1ChunksList[0].contentId),
|
|
283
283
|
);
|
|
284
284
|
const doc2Content0 = await t.run(async (ctx) =>
|
|
285
|
-
ctx.db.get(doc2ChunksList[0].contentId)
|
|
285
|
+
ctx.db.get(doc2ChunksList[0].contentId),
|
|
286
286
|
);
|
|
287
287
|
|
|
288
288
|
expect(doc1Content0!.text).toBe("Test chunk content 1");
|
|
@@ -309,7 +309,7 @@ describe("chunks", () => {
|
|
|
309
309
|
return ctx.db
|
|
310
310
|
.query("chunks")
|
|
311
311
|
.withIndex("entryId_order", (q) =>
|
|
312
|
-
q.eq("entryId", entryId).eq("order", 2)
|
|
312
|
+
q.eq("entryId", entryId).eq("order", 2),
|
|
313
313
|
)
|
|
314
314
|
.first();
|
|
315
315
|
});
|
|
@@ -319,7 +319,7 @@ describe("chunks", () => {
|
|
|
319
319
|
|
|
320
320
|
// Verify content
|
|
321
321
|
const content = await t.run(async (ctx) =>
|
|
322
|
-
ctx.db.get(singleChunk!.contentId)
|
|
322
|
+
ctx.db.get(singleChunk!.contentId),
|
|
323
323
|
);
|
|
324
324
|
expect(content!.text).toBe("Test chunk content 3");
|
|
325
325
|
});
|
|
@@ -467,7 +467,7 @@ describe("chunks", () => {
|
|
|
467
467
|
{
|
|
468
468
|
embeddingIds: [chunkDocs[2].state.embeddingId],
|
|
469
469
|
chunkContext: { before: 1, after: 2 },
|
|
470
|
-
}
|
|
470
|
+
},
|
|
471
471
|
);
|
|
472
472
|
expect(entries).toHaveLength(1);
|
|
473
473
|
expect(entries[0].entryId).toBe(entryId);
|
|
@@ -532,7 +532,7 @@ describe("chunks", () => {
|
|
|
532
532
|
doc2ChunkDocs[2].state.embeddingId, // doc2, chunk at order 2
|
|
533
533
|
],
|
|
534
534
|
chunkContext: { before: 1, after: 1 },
|
|
535
|
-
}
|
|
535
|
+
},
|
|
536
536
|
);
|
|
537
537
|
|
|
538
538
|
expect(entries).toHaveLength(2);
|
|
@@ -562,7 +562,7 @@ describe("chunks", () => {
|
|
|
562
562
|
namespaceId,
|
|
563
563
|
"versioned-entry",
|
|
564
564
|
1,
|
|
565
|
-
"ready"
|
|
565
|
+
"ready",
|
|
566
566
|
);
|
|
567
567
|
|
|
568
568
|
// Insert chunks in version 1
|
|
@@ -580,7 +580,7 @@ describe("chunks", () => {
|
|
|
580
580
|
namespaceId,
|
|
581
581
|
"versioned-entry",
|
|
582
582
|
2,
|
|
583
|
-
"pending"
|
|
583
|
+
"pending",
|
|
584
584
|
);
|
|
585
585
|
|
|
586
586
|
// Insert chunks in version 2
|
|
@@ -631,7 +631,7 @@ describe("chunks", () => {
|
|
|
631
631
|
v2ChunkDocs[1].state.embeddingId, // v2, chunk at order 1
|
|
632
632
|
],
|
|
633
633
|
chunkContext: { before: 1, after: 1 },
|
|
634
|
-
}
|
|
634
|
+
},
|
|
635
635
|
);
|
|
636
636
|
|
|
637
637
|
expect(entries).toHaveLength(2);
|