@trestleinc/replicate 0.1.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/LICENSE +201 -0
- package/LICENSE.package +201 -0
- package/README.md +871 -0
- package/dist/client/collection.d.ts +94 -0
- package/dist/client/index.d.ts +18 -0
- package/dist/client/logger.d.ts +3 -0
- package/dist/client/storage.d.ts +143 -0
- package/dist/component/_generated/api.js +5 -0
- package/dist/component/_generated/server.js +9 -0
- package/dist/component/convex.config.d.ts +2 -0
- package/dist/component/convex.config.js +3 -0
- package/dist/component/public.d.ts +99 -0
- package/dist/component/public.js +135 -0
- package/dist/component/schema.d.ts +22 -0
- package/dist/component/schema.js +22 -0
- package/dist/index.js +375 -0
- package/dist/server/index.d.ts +17 -0
- package/dist/server/replication.d.ts +122 -0
- package/dist/server/schema.d.ts +73 -0
- package/dist/server/ssr.d.ts +79 -0
- package/dist/server.js +96 -0
- package/dist/ssr.js +19 -0
- package/package.json +108 -0
- package/src/client/collection.ts +550 -0
- package/src/client/index.ts +31 -0
- package/src/client/logger.ts +31 -0
- package/src/client/storage.ts +206 -0
- package/src/component/_generated/api.d.ts +95 -0
- package/src/component/_generated/api.js +23 -0
- package/src/component/_generated/dataModel.d.ts +60 -0
- package/src/component/_generated/server.d.ts +149 -0
- package/src/component/_generated/server.js +90 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/public.ts +212 -0
- package/src/component/schema.ts +16 -0
- package/src/server/index.ts +26 -0
- package/src/server/replication.ts +244 -0
- package/src/server/schema.ts +97 -0
- package/src/server/ssr.ts +106 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Expand,
|
|
3
|
+
FunctionReference,
|
|
4
|
+
GenericDataModel,
|
|
5
|
+
GenericMutationCtx,
|
|
6
|
+
GenericQueryCtx,
|
|
7
|
+
} from 'convex/server';
|
|
8
|
+
import type { GenericId } from 'convex/values';
|
|
9
|
+
import { api } from '../component/_generated/api';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A client API for interacting with the Convex Replicate storage component.
|
|
13
|
+
*
|
|
14
|
+
* This class provides a type-safe, scoped interface for storing and retrieving
|
|
15
|
+
* CRDT document data from the replicate component. Each instance is scoped to
|
|
16
|
+
* a specific collection name, eliminating the need to pass collectionName to
|
|
17
|
+
* every method call.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* import { components } from "./_generated/api";
|
|
22
|
+
* import { ReplicateStorage } from "@trestleinc/convex-replicate-component";
|
|
23
|
+
*
|
|
24
|
+
* // Create a storage instance for the "tasks" collection
|
|
25
|
+
* const tasksStorage = new ReplicateStorage(components.replicate, "tasks");
|
|
26
|
+
*
|
|
27
|
+
* export const submitTask = mutation({
|
|
28
|
+
* handler: async (ctx, args) => {
|
|
29
|
+
* return await tasksStorage.submitDocument(
|
|
30
|
+
* ctx,
|
|
31
|
+
* args.id,
|
|
32
|
+
* args.document,
|
|
33
|
+
* args.version
|
|
34
|
+
* );
|
|
35
|
+
* }
|
|
36
|
+
* });
|
|
37
|
+
*
|
|
38
|
+
* export const getTasks = query({
|
|
39
|
+
* handler: async (ctx, args) => {
|
|
40
|
+
* return await tasksStorage.stream(ctx, args.checkpoint, args.limit);
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* @template TDocument - The document type being stored (must have an id field)
|
|
46
|
+
*/
|
|
47
|
+
export class ReplicateStorage<_TDocument extends { id: string } = { id: string }> {
|
|
48
|
+
/**
|
|
49
|
+
* Create a new ReplicateStorage instance scoped to a specific collection.
|
|
50
|
+
*
|
|
51
|
+
* @param component - The replicate component from your generated API
|
|
52
|
+
* @param collectionName - The name of the collection to interact with
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```typescript
|
|
56
|
+
* const tasksStorage = new ReplicateStorage(
|
|
57
|
+
* components.replicate,
|
|
58
|
+
* "tasks"
|
|
59
|
+
* );
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
constructor(
|
|
63
|
+
private component: UseApi<typeof api>,
|
|
64
|
+
private collectionName: string
|
|
65
|
+
) {}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Insert a new document into the replicate component storage.
|
|
69
|
+
*
|
|
70
|
+
* This stores the CRDT bytes in the component's internal storage table.
|
|
71
|
+
*
|
|
72
|
+
* @param ctx - Convex mutation context
|
|
73
|
+
* @param documentId - Unique identifier for the document
|
|
74
|
+
* @param crdtBytes - The CRDT binary data (from Automerge.save())
|
|
75
|
+
* @param version - Version number for conflict resolution
|
|
76
|
+
* @returns Success indicator
|
|
77
|
+
*/
|
|
78
|
+
async insertDocument(
|
|
79
|
+
ctx: RunMutationCtx,
|
|
80
|
+
documentId: string,
|
|
81
|
+
crdtBytes: ArrayBuffer,
|
|
82
|
+
version: number
|
|
83
|
+
): Promise<{ success: boolean }> {
|
|
84
|
+
return ctx.runMutation(this.component.public.insertDocument, {
|
|
85
|
+
collectionName: this.collectionName,
|
|
86
|
+
documentId,
|
|
87
|
+
crdtBytes,
|
|
88
|
+
version,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Update an existing document in the replicate component storage.
|
|
94
|
+
*
|
|
95
|
+
* @param ctx - Convex mutation context
|
|
96
|
+
* @param documentId - Unique identifier for the document
|
|
97
|
+
* @param crdtBytes - The CRDT binary data (from Automerge.save())
|
|
98
|
+
* @param version - Version number for conflict resolution
|
|
99
|
+
* @returns Success indicator
|
|
100
|
+
*/
|
|
101
|
+
async updateDocument(
|
|
102
|
+
ctx: RunMutationCtx,
|
|
103
|
+
documentId: string,
|
|
104
|
+
crdtBytes: ArrayBuffer,
|
|
105
|
+
version: number
|
|
106
|
+
): Promise<{ success: boolean }> {
|
|
107
|
+
return ctx.runMutation(this.component.public.updateDocument, {
|
|
108
|
+
collectionName: this.collectionName,
|
|
109
|
+
documentId,
|
|
110
|
+
crdtBytes,
|
|
111
|
+
version,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Delete a document from the replicate component storage.
|
|
117
|
+
* Appends deletion delta to event log.
|
|
118
|
+
*
|
|
119
|
+
* @param ctx - Convex mutation context
|
|
120
|
+
* @param documentId - Unique identifier for the document
|
|
121
|
+
* @param crdtBytes - Yjs deletion delta
|
|
122
|
+
* @param version - CRDT version number
|
|
123
|
+
* @returns Success indicator
|
|
124
|
+
*/
|
|
125
|
+
async deleteDocument(
|
|
126
|
+
ctx: RunMutationCtx,
|
|
127
|
+
documentId: string,
|
|
128
|
+
crdtBytes: ArrayBuffer,
|
|
129
|
+
version: number
|
|
130
|
+
): Promise<{ success: boolean }> {
|
|
131
|
+
return ctx.runMutation(this.component.public.deleteDocument, {
|
|
132
|
+
collectionName: this.collectionName,
|
|
133
|
+
documentId,
|
|
134
|
+
crdtBytes,
|
|
135
|
+
version,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Stream CRDT changes for incremental replication.
|
|
141
|
+
*
|
|
142
|
+
* Retrieves CRDT bytes for documents that have been modified since the
|
|
143
|
+
* provided checkpoint, enabling incremental replication.
|
|
144
|
+
* Can be used for both polling (awaitReplication) and subscriptions (live updates).
|
|
145
|
+
*
|
|
146
|
+
* @param ctx - Convex query context
|
|
147
|
+
* @param checkpoint - Last known modification timestamp
|
|
148
|
+
* @param limit - Maximum number of changes to retrieve (default: 100)
|
|
149
|
+
* @returns Array of changes with updated checkpoint
|
|
150
|
+
*/
|
|
151
|
+
async stream(
|
|
152
|
+
ctx: RunQueryCtx,
|
|
153
|
+
checkpoint: { lastModified: number },
|
|
154
|
+
limit?: number
|
|
155
|
+
): Promise<{
|
|
156
|
+
changes: Array<{
|
|
157
|
+
documentId: string;
|
|
158
|
+
crdtBytes: ArrayBuffer;
|
|
159
|
+
version: number;
|
|
160
|
+
timestamp: number;
|
|
161
|
+
}>;
|
|
162
|
+
checkpoint: { lastModified: number };
|
|
163
|
+
hasMore: boolean;
|
|
164
|
+
}> {
|
|
165
|
+
return ctx.runQuery(this.component.public.stream, {
|
|
166
|
+
collectionName: this.collectionName,
|
|
167
|
+
checkpoint,
|
|
168
|
+
limit,
|
|
169
|
+
}) as any;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Re-export the component API for direct access if needed.
|
|
175
|
+
*/
|
|
176
|
+
export { api };
|
|
177
|
+
|
|
178
|
+
/* Type utilities */
|
|
179
|
+
|
|
180
|
+
type RunQueryCtx = {
|
|
181
|
+
runQuery: GenericQueryCtx<GenericDataModel>['runQuery'];
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
type RunMutationCtx = {
|
|
185
|
+
runMutation: GenericMutationCtx<GenericDataModel>['runMutation'];
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
export type OpaqueIds<T> = T extends GenericId<infer _T>
|
|
189
|
+
? string
|
|
190
|
+
: T extends (infer U)[]
|
|
191
|
+
? OpaqueIds<U>[]
|
|
192
|
+
: T extends object
|
|
193
|
+
? { [K in keyof T]: OpaqueIds<T[K]> }
|
|
194
|
+
: T;
|
|
195
|
+
|
|
196
|
+
export type UseApi<API> = Expand<{
|
|
197
|
+
[mod in keyof API]: API[mod] extends FunctionReference<
|
|
198
|
+
infer FType,
|
|
199
|
+
'public',
|
|
200
|
+
infer FArgs,
|
|
201
|
+
infer FReturnType,
|
|
202
|
+
infer FComponentPath
|
|
203
|
+
>
|
|
204
|
+
? FunctionReference<FType, 'internal', OpaqueIds<FArgs>, OpaqueIds<FReturnType>, FComponentPath>
|
|
205
|
+
: UseApi<API[mod]>;
|
|
206
|
+
}>;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `api` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type * as public_ from "../public.js";
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
ApiFromModules,
|
|
15
|
+
FilterApi,
|
|
16
|
+
FunctionReference,
|
|
17
|
+
} from "convex/server";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A utility for referencing Convex functions in your app's API.
|
|
21
|
+
*
|
|
22
|
+
* Usage:
|
|
23
|
+
* ```js
|
|
24
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const fullApi: ApiFromModules<{
|
|
28
|
+
public: typeof public_;
|
|
29
|
+
}>;
|
|
30
|
+
export type Mounts = {
|
|
31
|
+
public: {
|
|
32
|
+
deleteDocument: FunctionReference<
|
|
33
|
+
"mutation",
|
|
34
|
+
"public",
|
|
35
|
+
{ collectionName: string; documentId: string },
|
|
36
|
+
{ success: boolean }
|
|
37
|
+
>;
|
|
38
|
+
insertDocument: FunctionReference<
|
|
39
|
+
"mutation",
|
|
40
|
+
"public",
|
|
41
|
+
{
|
|
42
|
+
collectionName: string;
|
|
43
|
+
crdtBytes: ArrayBuffer;
|
|
44
|
+
documentId: string;
|
|
45
|
+
version: number;
|
|
46
|
+
},
|
|
47
|
+
{ success: boolean }
|
|
48
|
+
>;
|
|
49
|
+
stream: FunctionReference<
|
|
50
|
+
"query",
|
|
51
|
+
"public",
|
|
52
|
+
{
|
|
53
|
+
checkpoint: { lastModified: number };
|
|
54
|
+
collectionName: string;
|
|
55
|
+
limit?: number;
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
changes: Array<{
|
|
59
|
+
crdtBytes: ArrayBuffer;
|
|
60
|
+
documentId: string;
|
|
61
|
+
timestamp: number;
|
|
62
|
+
version: number;
|
|
63
|
+
}>;
|
|
64
|
+
checkpoint: { lastModified: number };
|
|
65
|
+
hasMore: boolean;
|
|
66
|
+
}
|
|
67
|
+
>;
|
|
68
|
+
updateDocument: FunctionReference<
|
|
69
|
+
"mutation",
|
|
70
|
+
"public",
|
|
71
|
+
{
|
|
72
|
+
collectionName: string;
|
|
73
|
+
crdtBytes: ArrayBuffer;
|
|
74
|
+
documentId: string;
|
|
75
|
+
version: number;
|
|
76
|
+
},
|
|
77
|
+
{ success: boolean }
|
|
78
|
+
>;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
// For now fullApiWithMounts is only fullApi which provides
|
|
82
|
+
// jump-to-definition in component client code.
|
|
83
|
+
// Use Mounts for the same type without the inference.
|
|
84
|
+
declare const fullApiWithMounts: typeof fullApi;
|
|
85
|
+
|
|
86
|
+
export declare const api: FilterApi<
|
|
87
|
+
typeof fullApiWithMounts,
|
|
88
|
+
FunctionReference<any, "public">
|
|
89
|
+
>;
|
|
90
|
+
export declare const internal: FilterApi<
|
|
91
|
+
typeof fullApiWithMounts,
|
|
92
|
+
FunctionReference<any, "internal">
|
|
93
|
+
>;
|
|
94
|
+
|
|
95
|
+
export declare const components: {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated `api` utility.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A utility for referencing Convex functions in your app's API.
|
|
15
|
+
*
|
|
16
|
+
* Usage:
|
|
17
|
+
* ```js
|
|
18
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const api = anyApi;
|
|
22
|
+
export const internal = anyApi;
|
|
23
|
+
export const components = componentsGeneric();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated data model types.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type {
|
|
12
|
+
DataModelFromSchemaDefinition,
|
|
13
|
+
DocumentByName,
|
|
14
|
+
TableNamesInDataModel,
|
|
15
|
+
SystemTableNames,
|
|
16
|
+
} from "convex/server";
|
|
17
|
+
import type { GenericId } from "convex/values";
|
|
18
|
+
import schema from "../schema.js";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The names of all of your Convex tables.
|
|
22
|
+
*/
|
|
23
|
+
export type TableNames = TableNamesInDataModel<DataModel>;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The type of a document stored in Convex.
|
|
27
|
+
*
|
|
28
|
+
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
29
|
+
*/
|
|
30
|
+
export type Doc<TableName extends TableNames> = DocumentByName<
|
|
31
|
+
DataModel,
|
|
32
|
+
TableName
|
|
33
|
+
>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* An identifier for a document in Convex.
|
|
37
|
+
*
|
|
38
|
+
* Convex documents are uniquely identified by their `Id`, which is accessible
|
|
39
|
+
* on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
|
|
40
|
+
*
|
|
41
|
+
* Documents can be loaded using `db.get(id)` in query and mutation functions.
|
|
42
|
+
*
|
|
43
|
+
* IDs are just strings at runtime, but this type can be used to distinguish them from other
|
|
44
|
+
* strings when type checking.
|
|
45
|
+
*
|
|
46
|
+
* @typeParam TableName - A string literal type of the table name (like "users").
|
|
47
|
+
*/
|
|
48
|
+
export type Id<TableName extends TableNames | SystemTableNames> =
|
|
49
|
+
GenericId<TableName>;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* A type describing your Convex data model.
|
|
53
|
+
*
|
|
54
|
+
* This type includes information about what tables you have, the type of
|
|
55
|
+
* documents stored in those tables, and the indexes defined on them.
|
|
56
|
+
*
|
|
57
|
+
* This type is used to parameterize methods like `queryGeneric` and
|
|
58
|
+
* `mutationGeneric` to make them type-safe.
|
|
59
|
+
*/
|
|
60
|
+
export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
ActionBuilder,
|
|
13
|
+
AnyComponents,
|
|
14
|
+
HttpActionBuilder,
|
|
15
|
+
MutationBuilder,
|
|
16
|
+
QueryBuilder,
|
|
17
|
+
GenericActionCtx,
|
|
18
|
+
GenericMutationCtx,
|
|
19
|
+
GenericQueryCtx,
|
|
20
|
+
GenericDatabaseReader,
|
|
21
|
+
GenericDatabaseWriter,
|
|
22
|
+
FunctionReference,
|
|
23
|
+
} from "convex/server";
|
|
24
|
+
import type { DataModel } from "./dataModel.js";
|
|
25
|
+
|
|
26
|
+
type GenericCtx =
|
|
27
|
+
| GenericActionCtx<DataModel>
|
|
28
|
+
| GenericMutationCtx<DataModel>
|
|
29
|
+
| GenericQueryCtx<DataModel>;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Define a query in this Convex app's public API.
|
|
33
|
+
*
|
|
34
|
+
* This function will be allowed to read your Convex database and will be accessible from the client.
|
|
35
|
+
*
|
|
36
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
37
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
38
|
+
*/
|
|
39
|
+
export declare const query: QueryBuilder<DataModel, "public">;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
43
|
+
*
|
|
44
|
+
* This function will be allowed to read from your Convex database. It will not be accessible from the client.
|
|
45
|
+
*
|
|
46
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
47
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
48
|
+
*/
|
|
49
|
+
export declare const internalQuery: QueryBuilder<DataModel, "internal">;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Define a mutation in this Convex app's public API.
|
|
53
|
+
*
|
|
54
|
+
* This function will be allowed to modify your Convex database and will be accessible from the client.
|
|
55
|
+
*
|
|
56
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
57
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
58
|
+
*/
|
|
59
|
+
export declare const mutation: MutationBuilder<DataModel, "public">;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
63
|
+
*
|
|
64
|
+
* This function will be allowed to modify your Convex database. It will not be accessible from the client.
|
|
65
|
+
*
|
|
66
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
67
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
68
|
+
*/
|
|
69
|
+
export declare const internalMutation: MutationBuilder<DataModel, "internal">;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Define an action in this Convex app's public API.
|
|
73
|
+
*
|
|
74
|
+
* An action is a function which can execute any JavaScript code, including non-deterministic
|
|
75
|
+
* code and code with side-effects, like calling third-party services.
|
|
76
|
+
* They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
|
|
77
|
+
* They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
|
|
78
|
+
*
|
|
79
|
+
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
80
|
+
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
81
|
+
*/
|
|
82
|
+
export declare const action: ActionBuilder<DataModel, "public">;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
86
|
+
*
|
|
87
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
88
|
+
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
89
|
+
*/
|
|
90
|
+
export declare const internalAction: ActionBuilder<DataModel, "internal">;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Define an HTTP action.
|
|
94
|
+
*
|
|
95
|
+
* This function will be used to respond to HTTP requests received by a Convex
|
|
96
|
+
* deployment if the requests matches the path and method where this action
|
|
97
|
+
* is routed. Be sure to route your action in `convex/http.js`.
|
|
98
|
+
*
|
|
99
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
100
|
+
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
101
|
+
*/
|
|
102
|
+
export declare const httpAction: HttpActionBuilder;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A set of services for use within Convex query functions.
|
|
106
|
+
*
|
|
107
|
+
* The query context is passed as the first argument to any Convex query
|
|
108
|
+
* function run on the server.
|
|
109
|
+
*
|
|
110
|
+
* This differs from the {@link MutationCtx} because all of the services are
|
|
111
|
+
* read-only.
|
|
112
|
+
*/
|
|
113
|
+
export type QueryCtx = GenericQueryCtx<DataModel>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* A set of services for use within Convex mutation functions.
|
|
117
|
+
*
|
|
118
|
+
* The mutation context is passed as the first argument to any Convex mutation
|
|
119
|
+
* function run on the server.
|
|
120
|
+
*/
|
|
121
|
+
export type MutationCtx = GenericMutationCtx<DataModel>;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* A set of services for use within Convex action functions.
|
|
125
|
+
*
|
|
126
|
+
* The action context is passed as the first argument to any Convex action
|
|
127
|
+
* function run on the server.
|
|
128
|
+
*/
|
|
129
|
+
export type ActionCtx = GenericActionCtx<DataModel>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* An interface to read from the database within Convex query functions.
|
|
133
|
+
*
|
|
134
|
+
* The two entry points are {@link DatabaseReader.get}, which fetches a single
|
|
135
|
+
* document by its {@link Id}, or {@link DatabaseReader.query}, which starts
|
|
136
|
+
* building a query.
|
|
137
|
+
*/
|
|
138
|
+
export type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* An interface to read from and write to the database within Convex mutation
|
|
142
|
+
* functions.
|
|
143
|
+
*
|
|
144
|
+
* Convex guarantees that all writes within a single mutation are
|
|
145
|
+
* executed atomically, so you never have to worry about partial writes leaving
|
|
146
|
+
* your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
|
|
147
|
+
* for the guarantees Convex provides your functions.
|
|
148
|
+
*/
|
|
149
|
+
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
/**
|
|
3
|
+
* Generated utilities for implementing server-side Convex query and mutation functions.
|
|
4
|
+
*
|
|
5
|
+
* THIS CODE IS AUTOMATICALLY GENERATED.
|
|
6
|
+
*
|
|
7
|
+
* To regenerate, run `npx convex dev`.
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
actionGeneric,
|
|
13
|
+
httpActionGeneric,
|
|
14
|
+
queryGeneric,
|
|
15
|
+
mutationGeneric,
|
|
16
|
+
internalActionGeneric,
|
|
17
|
+
internalMutationGeneric,
|
|
18
|
+
internalQueryGeneric,
|
|
19
|
+
componentsGeneric,
|
|
20
|
+
} from "convex/server";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Define a query in this Convex app's public API.
|
|
24
|
+
*
|
|
25
|
+
* This function will be allowed to read your Convex database and will be accessible from the client.
|
|
26
|
+
*
|
|
27
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
28
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
29
|
+
*/
|
|
30
|
+
export const query = queryGeneric;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
34
|
+
*
|
|
35
|
+
* This function will be allowed to read from your Convex database. It will not be accessible from the client.
|
|
36
|
+
*
|
|
37
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
38
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
39
|
+
*/
|
|
40
|
+
export const internalQuery = internalQueryGeneric;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Define a mutation in this Convex app's public API.
|
|
44
|
+
*
|
|
45
|
+
* This function will be allowed to modify your Convex database and will be accessible from the client.
|
|
46
|
+
*
|
|
47
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
48
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
49
|
+
*/
|
|
50
|
+
export const mutation = mutationGeneric;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
54
|
+
*
|
|
55
|
+
* This function will be allowed to modify your Convex database. It will not be accessible from the client.
|
|
56
|
+
*
|
|
57
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
58
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
59
|
+
*/
|
|
60
|
+
export const internalMutation = internalMutationGeneric;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Define an action in this Convex app's public API.
|
|
64
|
+
*
|
|
65
|
+
* An action is a function which can execute any JavaScript code, including non-deterministic
|
|
66
|
+
* code and code with side-effects, like calling third-party services.
|
|
67
|
+
* They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
|
|
68
|
+
* They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
|
|
69
|
+
*
|
|
70
|
+
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
71
|
+
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
72
|
+
*/
|
|
73
|
+
export const action = actionGeneric;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
77
|
+
*
|
|
78
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
79
|
+
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
80
|
+
*/
|
|
81
|
+
export const internalAction = internalActionGeneric;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Define a Convex HTTP action.
|
|
85
|
+
*
|
|
86
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument, and a `Request` object
|
|
87
|
+
* as its second.
|
|
88
|
+
* @returns The wrapped endpoint function. Route a URL path to this function in `convex/http.js`.
|
|
89
|
+
*/
|
|
90
|
+
export const httpAction = httpActionGeneric;
|