langchain 0.0.174 → 0.0.176

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.
Files changed (69) hide show
  1. package/dist/chat_models/googlevertexai/common.cjs +46 -7
  2. package/dist/chat_models/googlevertexai/common.d.ts +7 -2
  3. package/dist/chat_models/googlevertexai/common.js +47 -8
  4. package/dist/chat_models/googlevertexai/index.cjs +4 -3
  5. package/dist/chat_models/googlevertexai/index.js +4 -3
  6. package/dist/chat_models/googlevertexai/web.cjs +2 -1
  7. package/dist/chat_models/googlevertexai/web.js +2 -1
  8. package/dist/embeddings/googlevertexai.cjs +1 -1
  9. package/dist/embeddings/googlevertexai.js +1 -1
  10. package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +2 -2
  11. package/dist/experimental/multimodal_embeddings/googlevertexai.cjs +1 -1
  12. package/dist/experimental/multimodal_embeddings/googlevertexai.d.ts +2 -1
  13. package/dist/experimental/multimodal_embeddings/googlevertexai.js +2 -2
  14. package/dist/experimental/plan_and_execute/agent_executor.cjs +7 -4
  15. package/dist/experimental/plan_and_execute/agent_executor.d.ts +4 -3
  16. package/dist/experimental/plan_and_execute/agent_executor.js +8 -5
  17. package/dist/experimental/plan_and_execute/prompt.cjs +25 -9
  18. package/dist/experimental/plan_and_execute/prompt.d.ts +9 -1
  19. package/dist/experimental/plan_and_execute/prompt.js +23 -8
  20. package/dist/llms/googlevertexai/common.cjs +46 -13
  21. package/dist/llms/googlevertexai/common.d.ts +8 -3
  22. package/dist/llms/googlevertexai/common.js +46 -13
  23. package/dist/llms/googlevertexai/index.cjs +4 -3
  24. package/dist/llms/googlevertexai/index.js +4 -3
  25. package/dist/llms/googlevertexai/web.cjs +2 -1
  26. package/dist/llms/googlevertexai/web.js +2 -1
  27. package/dist/load/import_constants.cjs +4 -0
  28. package/dist/load/import_constants.js +4 -0
  29. package/dist/storage/convex.cjs +145 -0
  30. package/dist/storage/convex.d.ts +85 -0
  31. package/dist/storage/convex.js +141 -0
  32. package/dist/stores/message/convex.cjs +120 -0
  33. package/dist/stores/message/convex.d.ts +60 -0
  34. package/dist/stores/message/convex.js +116 -0
  35. package/dist/types/googlevertexai-types.d.ts +12 -10
  36. package/dist/util/convex.cjs +77 -0
  37. package/dist/util/convex.d.ts +26 -0
  38. package/dist/util/convex.js +74 -0
  39. package/dist/util/googlevertexai-connection.cjs +298 -10
  40. package/dist/util/googlevertexai-connection.d.ts +76 -7
  41. package/dist/util/googlevertexai-connection.js +294 -9
  42. package/dist/util/googlevertexai-gauth.cjs +36 -0
  43. package/dist/util/googlevertexai-gauth.d.ts +8 -0
  44. package/dist/util/googlevertexai-gauth.js +32 -0
  45. package/dist/util/googlevertexai-webauth.cjs +38 -2
  46. package/dist/util/googlevertexai-webauth.d.ts +2 -6
  47. package/dist/util/googlevertexai-webauth.js +38 -2
  48. package/dist/vectorstores/convex.cjs +177 -0
  49. package/dist/vectorstores/convex.d.ts +113 -0
  50. package/dist/vectorstores/convex.js +173 -0
  51. package/dist/vectorstores/googlevertexai.d.ts +4 -4
  52. package/dist/vectorstores/milvus.cjs +4 -2
  53. package/dist/vectorstores/milvus.js +4 -2
  54. package/dist/vectorstores/vercel_postgres.cjs +29 -7
  55. package/dist/vectorstores/vercel_postgres.d.ts +1 -1
  56. package/dist/vectorstores/vercel_postgres.js +29 -7
  57. package/package.json +38 -1
  58. package/storage/convex.cjs +1 -0
  59. package/storage/convex.d.ts +1 -0
  60. package/storage/convex.js +1 -0
  61. package/stores/message/convex.cjs +1 -0
  62. package/stores/message/convex.d.ts +1 -0
  63. package/stores/message/convex.js +1 -0
  64. package/util/convex.cjs +1 -0
  65. package/util/convex.d.ts +1 -0
  66. package/util/convex.js +1 -0
  67. package/vectorstores/convex.cjs +1 -0
  68. package/vectorstores/convex.d.ts +1 -0
  69. package/vectorstores/convex.js +1 -0
@@ -0,0 +1,141 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+ import { makeFunctionReference, } from "convex/server";
3
+ import { BaseStore } from "../schema/storage.js";
4
+ /**
5
+ * Class that extends the BaseStore class to interact with a Convex
6
+ * database. It provides methods for getting, setting, and deleting key value pairs,
7
+ * as well as yielding keys from the database.
8
+ */
9
+ export class ConvexKVStore extends BaseStore {
10
+ constructor(config) {
11
+ super(config);
12
+ Object.defineProperty(this, "lc_namespace", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: ["langchain", "storage", "convex"]
17
+ });
18
+ Object.defineProperty(this, "ctx", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "table", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ Object.defineProperty(this, "index", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "keyField", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "valueField", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ Object.defineProperty(this, "upsert", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ Object.defineProperty(this, "lookup", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
60
+ Object.defineProperty(this, "deleteMany", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: void 0
65
+ });
66
+ this.ctx = config.ctx;
67
+ this.table = config.table ?? "cache";
68
+ this.index = config.index ?? "byKey";
69
+ this.keyField = config.keyField ?? "key";
70
+ this.valueField = config.valueField ?? "value";
71
+ this.upsert =
72
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
+ config.upsert ?? makeFunctionReference("langchain/db:upsert");
74
+ this.lookup =
75
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
76
+ config.lookup ?? makeFunctionReference("langchain/db:lookup");
77
+ this.deleteMany =
78
+ config.deleteMany ??
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ makeFunctionReference("langchain/db:deleteMany");
81
+ }
82
+ /**
83
+ * Gets multiple keys from the Convex database.
84
+ * @param keys Array of keys to be retrieved.
85
+ * @returns An array of retrieved values.
86
+ */
87
+ async mget(keys) {
88
+ return (await Promise.all(keys.map(async (key) => {
89
+ const found = (await this.ctx.runQuery(this.lookup, {
90
+ table: this.table,
91
+ index: this.index,
92
+ keyField: this.keyField,
93
+ key,
94
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
95
+ }));
96
+ return found.length > 0 ? found[0][this.valueField] : undefined;
97
+ })));
98
+ }
99
+ /**
100
+ * Sets multiple keys in the Convex database.
101
+ * @param keyValuePairs Array of key-value pairs to be set.
102
+ * @returns Promise that resolves when all keys have been set.
103
+ */
104
+ async mset(keyValuePairs) {
105
+ // TODO: Remove chunking when Convex handles the concurrent requests correctly
106
+ const PAGE_SIZE = 16;
107
+ for (let i = 0; i < keyValuePairs.length; i += PAGE_SIZE) {
108
+ await Promise.all(keyValuePairs.slice(i, i + PAGE_SIZE).map(([key, value]) => this.ctx.runMutation(this.upsert, {
109
+ table: this.table,
110
+ index: this.index,
111
+ keyField: this.keyField,
112
+ key,
113
+ document: { [this.keyField]: key, [this.valueField]: value },
114
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
+ })));
116
+ }
117
+ }
118
+ /**
119
+ * Deletes multiple keys from the Convex database.
120
+ * @param keys Array of keys to be deleted.
121
+ * @returns Promise that resolves when all keys have been deleted.
122
+ */
123
+ async mdelete(keys) {
124
+ await Promise.all(keys.map((key) => this.ctx.runMutation(this.deleteMany, {
125
+ table: this.table,
126
+ index: this.index,
127
+ keyField: this.keyField,
128
+ key,
129
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
130
+ })));
131
+ }
132
+ /**
133
+ * Yields keys from the Convex database.
134
+ * @param prefix Optional prefix to filter the keys.
135
+ * @returns An AsyncGenerator that yields keys from the Convex database.
136
+ */
137
+ // eslint-disable-next-line require-yield
138
+ async *yieldKeys(_prefix) {
139
+ throw new Error("yieldKeys not implemented yet for ConvexKVStore");
140
+ }
141
+ }
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.ConvexChatMessageHistory = void 0;
5
+ // eslint-disable-next-line import/no-extraneous-dependencies
6
+ const server_1 = require("convex/server");
7
+ const index_js_1 = require("../../schema/index.cjs");
8
+ const utils_js_1 = require("./utils.cjs");
9
+ class ConvexChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
10
+ constructor(config) {
11
+ super();
12
+ Object.defineProperty(this, "lc_namespace", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: ["langchain", "stores", "message", "convex"]
17
+ });
18
+ Object.defineProperty(this, "ctx", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "sessionId", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ Object.defineProperty(this, "table", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: void 0
35
+ });
36
+ Object.defineProperty(this, "index", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "sessionIdField", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ Object.defineProperty(this, "messageTextFieldName", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ Object.defineProperty(this, "insert", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
60
+ Object.defineProperty(this, "lookup", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: void 0
65
+ });
66
+ Object.defineProperty(this, "deleteMany", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
72
+ this.ctx = config.ctx;
73
+ this.sessionId = config.sessionId;
74
+ this.table = config.table ?? "messages";
75
+ this.index = config.index ?? "bySessionId";
76
+ this.sessionIdField =
77
+ config.sessionIdField ?? "sessionId";
78
+ this.messageTextFieldName =
79
+ config.messageTextFieldName ?? "message";
80
+ this.insert =
81
+ config.insert ?? (0, server_1.makeFunctionReference)("langchain/db:insert");
82
+ this.lookup =
83
+ config.lookup ?? (0, server_1.makeFunctionReference)("langchain/db:lookup");
84
+ this.deleteMany =
85
+ config.deleteMany ??
86
+ (0, server_1.makeFunctionReference)("langchain/db:deleteMany");
87
+ }
88
+ async getMessages() {
89
+ const convexDocuments = await this.ctx.runQuery(this.lookup, {
90
+ table: this.table,
91
+ index: this.index,
92
+ keyField: this.sessionIdField,
93
+ key: this.sessionId,
94
+ });
95
+ return (0, utils_js_1.mapStoredMessagesToChatMessages)(convexDocuments.map((doc) => doc[this.messageTextFieldName]));
96
+ }
97
+ async addMessage(message) {
98
+ const messages = (0, utils_js_1.mapChatMessagesToStoredMessages)([message]);
99
+ // TODO: Remove chunking when Convex handles the concurrent requests correctly
100
+ const PAGE_SIZE = 16;
101
+ for (let i = 0; i < messages.length; i += PAGE_SIZE) {
102
+ await Promise.all(messages.slice(i, i + PAGE_SIZE).map((message) => this.ctx.runMutation(this.insert, {
103
+ table: this.table,
104
+ document: {
105
+ [this.sessionIdField]: this.sessionId,
106
+ [this.messageTextFieldName]: message,
107
+ },
108
+ })));
109
+ }
110
+ }
111
+ async clear() {
112
+ await this.ctx.runMutation(this.deleteMany, {
113
+ table: this.table,
114
+ index: this.index,
115
+ keyField: this.sessionIdField,
116
+ key: this.sessionId,
117
+ });
118
+ }
119
+ }
120
+ exports.ConvexChatMessageHistory = ConvexChatMessageHistory;
@@ -0,0 +1,60 @@
1
+ import { DocumentByName, FieldPaths, FunctionReference, GenericActionCtx, GenericDataModel, NamedTableInfo, TableNamesInDataModel, VectorIndexNames } from "convex/server";
2
+ import { BaseMessage, BaseListChatMessageHistory } from "../../schema/index.js";
3
+ /**
4
+ * Type that defines the config required to initialize the
5
+ * ConvexChatMessageHistory class. At minimum it needs a sessionId
6
+ * and an ActionCtx.
7
+ */
8
+ export type ConvexChatMessageHistoryInput<DataModel extends GenericDataModel, TableName extends TableNamesInDataModel<DataModel> = "messages", IndexName extends VectorIndexNames<NamedTableInfo<DataModel, TableName>> = "bySessionId", SessionIdFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>> = "sessionId", MessageTextFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>> = "message", InsertMutation extends FunctionReference<"mutation", "internal", {
9
+ table: string;
10
+ document: object;
11
+ }> = any, LookupQuery extends FunctionReference<"query", "internal", {
12
+ table: string;
13
+ index: string;
14
+ keyField: string;
15
+ key: string;
16
+ }, object[]> = any, DeleteManyMutation extends FunctionReference<"mutation", "internal", {
17
+ table: string;
18
+ index: string;
19
+ keyField: string;
20
+ key: string;
21
+ }> = any> = {
22
+ readonly ctx: GenericActionCtx<DataModel>;
23
+ readonly sessionId: DocumentByName<DataModel, TableName>[SessionIdFieldName];
24
+ readonly table?: TableName;
25
+ readonly index?: IndexName;
26
+ readonly sessionIdField?: SessionIdFieldName;
27
+ readonly messageTextFieldName?: MessageTextFieldName;
28
+ readonly insert?: InsertMutation;
29
+ readonly lookup?: LookupQuery;
30
+ readonly deleteMany?: DeleteManyMutation;
31
+ };
32
+ export declare class ConvexChatMessageHistory<DataModel extends GenericDataModel, SessionIdFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>> = "sessionId", TableName extends TableNamesInDataModel<DataModel> = "messages", IndexName extends VectorIndexNames<NamedTableInfo<DataModel, TableName>> = "bySessionId", MessageTextFieldName extends FieldPaths<NamedTableInfo<DataModel, TableName>> = "message", InsertMutation extends FunctionReference<"mutation", "internal", {
33
+ table: string;
34
+ document: object;
35
+ }> = any, LookupQuery extends FunctionReference<"query", "internal", {
36
+ table: string;
37
+ index: string;
38
+ keyField: string;
39
+ key: string;
40
+ }, object[]> = any, DeleteManyMutation extends FunctionReference<"mutation", "internal", {
41
+ table: string;
42
+ index: string;
43
+ keyField: string;
44
+ key: string;
45
+ }> = any> extends BaseListChatMessageHistory {
46
+ lc_namespace: string[];
47
+ private readonly ctx;
48
+ private readonly sessionId;
49
+ private readonly table;
50
+ private readonly index;
51
+ private readonly sessionIdField;
52
+ private readonly messageTextFieldName;
53
+ private readonly insert;
54
+ private readonly lookup;
55
+ private readonly deleteMany;
56
+ constructor(config: ConvexChatMessageHistoryInput<DataModel, TableName, IndexName, SessionIdFieldName, MessageTextFieldName, InsertMutation, LookupQuery, DeleteManyMutation>);
57
+ getMessages(): Promise<BaseMessage[]>;
58
+ addMessage(message: BaseMessage): Promise<void>;
59
+ clear(): Promise<void>;
60
+ }
@@ -0,0 +1,116 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import { makeFunctionReference, } from "convex/server";
4
+ import { BaseListChatMessageHistory } from "../../schema/index.js";
5
+ import { mapChatMessagesToStoredMessages, mapStoredMessagesToChatMessages, } from "./utils.js";
6
+ export class ConvexChatMessageHistory extends BaseListChatMessageHistory {
7
+ constructor(config) {
8
+ super();
9
+ Object.defineProperty(this, "lc_namespace", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: ["langchain", "stores", "message", "convex"]
14
+ });
15
+ Object.defineProperty(this, "ctx", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ Object.defineProperty(this, "sessionId", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+ Object.defineProperty(this, "table", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: void 0
32
+ });
33
+ Object.defineProperty(this, "index", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ Object.defineProperty(this, "sessionIdField", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ Object.defineProperty(this, "messageTextFieldName", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ Object.defineProperty(this, "insert", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ Object.defineProperty(this, "lookup", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: void 0
62
+ });
63
+ Object.defineProperty(this, "deleteMany", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: void 0
68
+ });
69
+ this.ctx = config.ctx;
70
+ this.sessionId = config.sessionId;
71
+ this.table = config.table ?? "messages";
72
+ this.index = config.index ?? "bySessionId";
73
+ this.sessionIdField =
74
+ config.sessionIdField ?? "sessionId";
75
+ this.messageTextFieldName =
76
+ config.messageTextFieldName ?? "message";
77
+ this.insert =
78
+ config.insert ?? makeFunctionReference("langchain/db:insert");
79
+ this.lookup =
80
+ config.lookup ?? makeFunctionReference("langchain/db:lookup");
81
+ this.deleteMany =
82
+ config.deleteMany ??
83
+ makeFunctionReference("langchain/db:deleteMany");
84
+ }
85
+ async getMessages() {
86
+ const convexDocuments = await this.ctx.runQuery(this.lookup, {
87
+ table: this.table,
88
+ index: this.index,
89
+ keyField: this.sessionIdField,
90
+ key: this.sessionId,
91
+ });
92
+ return mapStoredMessagesToChatMessages(convexDocuments.map((doc) => doc[this.messageTextFieldName]));
93
+ }
94
+ async addMessage(message) {
95
+ const messages = mapChatMessagesToStoredMessages([message]);
96
+ // TODO: Remove chunking when Convex handles the concurrent requests correctly
97
+ const PAGE_SIZE = 16;
98
+ for (let i = 0; i < messages.length; i += PAGE_SIZE) {
99
+ await Promise.all(messages.slice(i, i + PAGE_SIZE).map((message) => this.ctx.runMutation(this.insert, {
100
+ table: this.table,
101
+ document: {
102
+ [this.sessionIdField]: this.sessionId,
103
+ [this.messageTextFieldName]: message,
104
+ },
105
+ })));
106
+ }
107
+ }
108
+ async clear() {
109
+ await this.ctx.runMutation(this.deleteMany, {
110
+ table: this.table,
111
+ index: this.index,
112
+ keyField: this.sessionIdField,
113
+ key: this.sessionId,
114
+ });
115
+ }
116
+ }
@@ -45,19 +45,21 @@ export interface GoogleVertexAIBaseLLMInput<AuthOptions> extends BaseLLMParams,
45
45
  export interface GoogleResponse {
46
46
  data: any;
47
47
  }
48
- export interface GoogleVertexAIBasePrediction extends GoogleResponse {
48
+ export interface GoogleVertexAIBasePrediction {
49
49
  safetyAttributes?: any;
50
50
  }
51
- export interface GoogleVertexAILLMResponse<PredictionType extends GoogleVertexAIBasePrediction> {
52
- data: {
53
- predictions: PredictionType[];
54
- };
51
+ export interface GoogleVertexAILLMPredictions<PredictionType extends GoogleVertexAIBasePrediction> {
52
+ predictions: PredictionType[];
55
53
  }
54
+ export type GoogleAbstractedClientOpsMethod = "GET" | "POST";
55
+ export type GoogleAbstractedClientOpsResponseType = "json" | "stream";
56
+ export type GoogleAbstractedClientOps = {
57
+ url?: string;
58
+ method?: GoogleAbstractedClientOpsMethod;
59
+ data?: unknown;
60
+ responseType?: GoogleAbstractedClientOpsResponseType;
61
+ };
56
62
  export interface GoogleAbstractedClient {
57
- request: (opts: {
58
- url?: string;
59
- method?: "GET" | "POST";
60
- data?: unknown;
61
- }) => unknown;
63
+ request: (opts: GoogleAbstractedClientOps) => unknown;
62
64
  getProjectId: () => Promise<string>;
63
65
  }
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ /* eslint-disable spaced-comment */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.deleteMany = exports.upsert = exports.lookup = exports.insert = exports.get = void 0;
5
+ // eslint-disable-next-line import/no-extraneous-dependencies
6
+ const server_1 = require("convex/server");
7
+ // eslint-disable-next-line import/no-extraneous-dependencies
8
+ const values_1 = require("convex/values");
9
+ exports.get = (0, server_1.internalQueryGeneric)({
10
+ args: {
11
+ id: /*#__PURE__*/ values_1.v.string(),
12
+ },
13
+ handler: async (ctx, args) => {
14
+ const result = await ctx.db.get(args.id);
15
+ return result;
16
+ },
17
+ });
18
+ exports.insert = (0, server_1.internalMutationGeneric)({
19
+ args: {
20
+ table: /*#__PURE__*/ values_1.v.string(),
21
+ document: /*#__PURE__*/ values_1.v.any(),
22
+ },
23
+ handler: async (ctx, args) => {
24
+ await ctx.db.insert(args.table, args.document);
25
+ },
26
+ });
27
+ exports.lookup = (0, server_1.internalQueryGeneric)({
28
+ args: {
29
+ table: /*#__PURE__*/ values_1.v.string(),
30
+ index: /*#__PURE__*/ values_1.v.string(),
31
+ keyField: /*#__PURE__*/ values_1.v.string(),
32
+ key: /*#__PURE__*/ values_1.v.string(),
33
+ },
34
+ handler: async (ctx, args) => {
35
+ const result = await ctx.db
36
+ .query(args.table)
37
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
38
+ .collect();
39
+ return result;
40
+ },
41
+ });
42
+ exports.upsert = (0, server_1.internalMutationGeneric)({
43
+ args: {
44
+ table: /*#__PURE__*/ values_1.v.string(),
45
+ index: /*#__PURE__*/ values_1.v.string(),
46
+ keyField: /*#__PURE__*/ values_1.v.string(),
47
+ key: /*#__PURE__*/ values_1.v.string(),
48
+ document: /*#__PURE__*/ values_1.v.any(),
49
+ },
50
+ handler: async (ctx, args) => {
51
+ const existing = await ctx.db
52
+ .query(args.table)
53
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
54
+ .unique();
55
+ if (existing !== null) {
56
+ await ctx.db.replace(existing._id, args.document);
57
+ }
58
+ else {
59
+ await ctx.db.insert(args.table, args.document);
60
+ }
61
+ },
62
+ });
63
+ exports.deleteMany = (0, server_1.internalMutationGeneric)({
64
+ args: {
65
+ table: /*#__PURE__*/ values_1.v.string(),
66
+ index: /*#__PURE__*/ values_1.v.string(),
67
+ keyField: /*#__PURE__*/ values_1.v.string(),
68
+ key: /*#__PURE__*/ values_1.v.string(),
69
+ },
70
+ handler: async (ctx, args) => {
71
+ const existing = await ctx.db
72
+ .query(args.table)
73
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
74
+ .collect();
75
+ await Promise.all(existing.map((doc) => ctx.db.delete(doc._id)));
76
+ },
77
+ });
@@ -0,0 +1,26 @@
1
+ export declare const get: import("convex/server").RegisteredQuery<"internal", {
2
+ id: string;
3
+ }, Promise<any>>;
4
+ export declare const insert: import("convex/server").RegisteredMutation<"internal", {
5
+ document: any;
6
+ table: string;
7
+ }, Promise<void>>;
8
+ export declare const lookup: import("convex/server").RegisteredQuery<"internal", {
9
+ key: string;
10
+ index: string;
11
+ table: string;
12
+ keyField: string;
13
+ }, Promise<any[]>>;
14
+ export declare const upsert: import("convex/server").RegisteredMutation<"internal", {
15
+ key: string;
16
+ index: string;
17
+ document: any;
18
+ table: string;
19
+ keyField: string;
20
+ }, Promise<void>>;
21
+ export declare const deleteMany: import("convex/server").RegisteredMutation<"internal", {
22
+ key: string;
23
+ index: string;
24
+ table: string;
25
+ keyField: string;
26
+ }, Promise<void>>;
@@ -0,0 +1,74 @@
1
+ /* eslint-disable spaced-comment */
2
+ // eslint-disable-next-line import/no-extraneous-dependencies
3
+ import { internalQueryGeneric as internalQuery, internalMutationGeneric as internalMutation, } from "convex/server";
4
+ // eslint-disable-next-line import/no-extraneous-dependencies
5
+ import { v } from "convex/values";
6
+ export const get = /*#__PURE__*/ internalQuery({
7
+ args: {
8
+ id: /*#__PURE__*/ v.string(),
9
+ },
10
+ handler: async (ctx, args) => {
11
+ const result = await ctx.db.get(args.id);
12
+ return result;
13
+ },
14
+ });
15
+ export const insert = /*#__PURE__*/ internalMutation({
16
+ args: {
17
+ table: /*#__PURE__*/ v.string(),
18
+ document: /*#__PURE__*/ v.any(),
19
+ },
20
+ handler: async (ctx, args) => {
21
+ await ctx.db.insert(args.table, args.document);
22
+ },
23
+ });
24
+ export const lookup = /*#__PURE__*/ internalQuery({
25
+ args: {
26
+ table: /*#__PURE__*/ v.string(),
27
+ index: /*#__PURE__*/ v.string(),
28
+ keyField: /*#__PURE__*/ v.string(),
29
+ key: /*#__PURE__*/ v.string(),
30
+ },
31
+ handler: async (ctx, args) => {
32
+ const result = await ctx.db
33
+ .query(args.table)
34
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
35
+ .collect();
36
+ return result;
37
+ },
38
+ });
39
+ export const upsert = /*#__PURE__*/ internalMutation({
40
+ args: {
41
+ table: /*#__PURE__*/ v.string(),
42
+ index: /*#__PURE__*/ v.string(),
43
+ keyField: /*#__PURE__*/ v.string(),
44
+ key: /*#__PURE__*/ v.string(),
45
+ document: /*#__PURE__*/ v.any(),
46
+ },
47
+ handler: async (ctx, args) => {
48
+ const existing = await ctx.db
49
+ .query(args.table)
50
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
51
+ .unique();
52
+ if (existing !== null) {
53
+ await ctx.db.replace(existing._id, args.document);
54
+ }
55
+ else {
56
+ await ctx.db.insert(args.table, args.document);
57
+ }
58
+ },
59
+ });
60
+ export const deleteMany = /*#__PURE__*/ internalMutation({
61
+ args: {
62
+ table: /*#__PURE__*/ v.string(),
63
+ index: /*#__PURE__*/ v.string(),
64
+ keyField: /*#__PURE__*/ v.string(),
65
+ key: /*#__PURE__*/ v.string(),
66
+ },
67
+ handler: async (ctx, args) => {
68
+ const existing = await ctx.db
69
+ .query(args.table)
70
+ .withIndex(args.index, (q) => q.eq(args.keyField, args.key))
71
+ .collect();
72
+ await Promise.all(existing.map((doc) => ctx.db.delete(doc._id)));
73
+ },
74
+ });