@convex-dev/static-hosting 0.1.2-beta.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/README.md +333 -0
- package/dist/cli/deploy.d.ts +16 -0
- package/dist/cli/deploy.d.ts.map +1 -0
- package/dist/cli/deploy.js +324 -0
- package/dist/cli/deploy.js.map +1 -0
- package/dist/cli/index.d.ts +15 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +95 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +9 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +181 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/next-build.d.ts +24 -0
- package/dist/cli/next-build.d.ts.map +1 -0
- package/dist/cli/next-build.js +569 -0
- package/dist/cli/next-build.js.map +1 -0
- package/dist/cli/setup.d.ts +9 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +157 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/upload.d.ts +15 -0
- package/dist/cli/upload.d.ts.map +1 -0
- package/dist/cli/upload.js +436 -0
- package/dist/cli/upload.js.map +1 -0
- package/dist/client/_generated/_ignore.d.ts +1 -0
- package/dist/client/_generated/_ignore.d.ts.map +1 -0
- package/dist/client/_generated/_ignore.js +3 -0
- package/dist/client/_generated/_ignore.js.map +1 -0
- package/dist/client/index.d.ts +142 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +475 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/next.d.ts +38 -0
- package/dist/client/next.d.ts.map +1 -0
- package/dist/client/next.js +175 -0
- package/dist/client/next.js.map +1 -0
- package/dist/client/nextAdapter.d.ts +4 -0
- package/dist/client/nextAdapter.d.ts.map +1 -0
- package/dist/client/nextAdapter.js +9 -0
- package/dist/client/nextAdapter.js.map +1 -0
- package/dist/component/_generated/api.d.ts +34 -0
- package/dist/component/_generated/api.d.ts.map +1 -0
- package/dist/component/_generated/api.js +31 -0
- package/dist/component/_generated/api.js.map +1 -0
- package/dist/component/_generated/component.d.ts +73 -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 +46 -0
- 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 +121 -0
- package/dist/component/_generated/server.d.ts.map +1 -0
- package/dist/component/_generated/server.js +78 -0
- package/dist/component/_generated/server.js.map +1 -0
- package/dist/component/convex.config.d.ts +3 -0
- package/dist/component/convex.config.d.ts.map +1 -0
- package/dist/component/convex.config.js +3 -0
- package/dist/component/convex.config.js.map +1 -0
- package/dist/component/lib.d.ts +88 -0
- package/dist/component/lib.d.ts.map +1 -0
- package/dist/component/lib.js +210 -0
- package/dist/component/lib.js.map +1 -0
- package/dist/component/schema.d.ts +27 -0
- package/dist/component/schema.d.ts.map +1 -0
- package/dist/component/schema.js +20 -0
- package/dist/component/schema.js.map +1 -0
- package/dist/react/index.d.ts +80 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +138 -0
- package/dist/react/index.js.map +1 -0
- package/package.json +120 -0
- package/src/cli/deploy.ts +375 -0
- package/src/cli/index.ts +104 -0
- package/src/cli/init.ts +181 -0
- package/src/cli/next-build.ts +707 -0
- package/src/cli/setup.ts +190 -0
- package/src/cli/upload.ts +521 -0
- package/src/client/_generated/_ignore.ts +1 -0
- package/src/client/index.test.ts +67 -0
- package/src/client/index.ts +553 -0
- package/src/client/next.ts +223 -0
- package/src/client/nextAdapter.ts +17 -0
- package/src/client/setup.test.ts +26 -0
- package/src/component/_generated/api.ts +50 -0
- package/src/component/_generated/component.ts +104 -0
- package/src/component/_generated/dataModel.ts +60 -0
- package/src/component/_generated/server.ts +161 -0
- package/src/component/convex.config.ts +3 -0
- package/src/component/lib.test.ts +110 -0
- package/src/component/lib.ts +228 -0
- package/src/component/schema.ts +21 -0
- package/src/component/setup.test.ts +11 -0
- package/src/react/index.tsx +184 -0
- package/src/test.ts +18 -0
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { httpActionGeneric } from "convex/server";
|
|
2
|
+
import type { FunctionReference, HttpRouter } from "convex/server";
|
|
3
|
+
import type { ComponentApi } from "../component/_generated/component.js";
|
|
4
|
+
|
|
5
|
+
// MIME type mapping for Next.js static assets
|
|
6
|
+
const MIME_TYPES: Record<string, string> = {
|
|
7
|
+
".js": "application/javascript; charset=utf-8",
|
|
8
|
+
".css": "text/css; charset=utf-8",
|
|
9
|
+
".json": "application/json; charset=utf-8",
|
|
10
|
+
".png": "image/png",
|
|
11
|
+
".jpg": "image/jpeg",
|
|
12
|
+
".jpeg": "image/jpeg",
|
|
13
|
+
".gif": "image/gif",
|
|
14
|
+
".svg": "image/svg+xml",
|
|
15
|
+
".ico": "image/x-icon",
|
|
16
|
+
".webp": "image/webp",
|
|
17
|
+
".woff": "font/woff",
|
|
18
|
+
".woff2": "font/woff2",
|
|
19
|
+
".ttf": "font/ttf",
|
|
20
|
+
".map": "application/json",
|
|
21
|
+
".txt": "text/plain; charset=utf-8",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Register HTTP routes for serving a Next.js app via Convex HTTP actions.
|
|
26
|
+
*
|
|
27
|
+
* Static assets (`/_next/static/*`) are served directly from Convex storage
|
|
28
|
+
* (V8 runtime, instant). All other requests are forwarded to a Node.js action
|
|
29
|
+
* that runs NextServer.
|
|
30
|
+
*
|
|
31
|
+
* @param http - The HTTP router to register routes on
|
|
32
|
+
* @param component - The component API reference (for storage lookups)
|
|
33
|
+
* @param actionRef - Reference to the generated `handle` action
|
|
34
|
+
* @param options - Configuration options
|
|
35
|
+
* @param options.pathPrefix - URL prefix (default: "/")
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // convex/http.ts
|
|
40
|
+
* import { httpRouter } from "convex/server";
|
|
41
|
+
* import { registerNextRoutes } from "@convex-dev/static-hosting/next";
|
|
42
|
+
* import { components, internal } from "./_generated/api";
|
|
43
|
+
*
|
|
44
|
+
* const http = httpRouter();
|
|
45
|
+
* registerNextRoutes(http, components.staticHosting, internal._generatedNextServer.handle);
|
|
46
|
+
* export default http;
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export function registerNextRoutes(
|
|
50
|
+
http: HttpRouter,
|
|
51
|
+
component: ComponentApi,
|
|
52
|
+
actionRef: FunctionReference<"action", "internal", Record<string, unknown>, unknown>,
|
|
53
|
+
{
|
|
54
|
+
pathPrefix = "/",
|
|
55
|
+
warmup = true,
|
|
56
|
+
}: {
|
|
57
|
+
pathPrefix?: string;
|
|
58
|
+
/** Inject a warmup script into static HTML pages to pre-boot the Node.js
|
|
59
|
+
* NextServer in the background. Defaults to true. */
|
|
60
|
+
warmup?: boolean;
|
|
61
|
+
} = {},
|
|
62
|
+
) {
|
|
63
|
+
const normalizedPrefix =
|
|
64
|
+
pathPrefix === "/" ? "" : pathPrefix.replace(/\/$/, "");
|
|
65
|
+
|
|
66
|
+
// Hop-by-hop headers that must not be forwarded through proxies
|
|
67
|
+
const hopByHopHeaders = new Set([
|
|
68
|
+
"transfer-encoding",
|
|
69
|
+
"connection",
|
|
70
|
+
"keep-alive",
|
|
71
|
+
"upgrade",
|
|
72
|
+
"proxy-authenticate",
|
|
73
|
+
"proxy-authorization",
|
|
74
|
+
"te",
|
|
75
|
+
"trailer",
|
|
76
|
+
]);
|
|
77
|
+
|
|
78
|
+
const handler = httpActionGeneric(async (ctx, request) => {
|
|
79
|
+
const url = new URL(request.url);
|
|
80
|
+
let path = url.pathname;
|
|
81
|
+
|
|
82
|
+
// Remove prefix if present
|
|
83
|
+
if (normalizedPrefix && path.startsWith(normalizedPrefix)) {
|
|
84
|
+
path = path.slice(normalizedPrefix.length) || "/";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Warmup endpoint: boots the Node.js action in the background
|
|
88
|
+
if (warmup && path === "/__warmup") {
|
|
89
|
+
try {
|
|
90
|
+
await (ctx as { runAction: (ref: typeof actionRef, args: Record<string, unknown>) => Promise<unknown> }).runAction(actionRef, {
|
|
91
|
+
url: `${url.origin}/`,
|
|
92
|
+
method: "GET",
|
|
93
|
+
headers: [],
|
|
94
|
+
});
|
|
95
|
+
} catch {
|
|
96
|
+
// Warmup failure is non-critical
|
|
97
|
+
}
|
|
98
|
+
return new Response(null, { status: 204 });
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Serve /_next/static/* from Convex storage (fast, V8 runtime)
|
|
102
|
+
if (path.startsWith("/_next/static/")) {
|
|
103
|
+
type AssetDoc = {
|
|
104
|
+
storageId?: string;
|
|
105
|
+
contentType: string;
|
|
106
|
+
} | null;
|
|
107
|
+
|
|
108
|
+
const asset: AssetDoc = await ctx.runQuery(component.lib.getByPath, {
|
|
109
|
+
path,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (asset?.storageId) {
|
|
113
|
+
const blob = await ctx.storage.get(asset.storageId);
|
|
114
|
+
if (blob) {
|
|
115
|
+
return new Response(blob, {
|
|
116
|
+
status: 200,
|
|
117
|
+
headers: {
|
|
118
|
+
"Content-Type": asset.contentType,
|
|
119
|
+
"Cache-Control": "public, max-age=31536000, immutable",
|
|
120
|
+
"X-Content-Type-Options": "nosniff",
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Fall through to Node action if not in storage
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Forward everything else to the Node.js action
|
|
130
|
+
try {
|
|
131
|
+
const method = request.method;
|
|
132
|
+
const headers: string[][] = [];
|
|
133
|
+
request.headers.forEach((value, key) => {
|
|
134
|
+
headers.push([key, value]);
|
|
135
|
+
});
|
|
136
|
+
const body =
|
|
137
|
+
!["GET", "HEAD"].includes(method)
|
|
138
|
+
? await request.arrayBuffer()
|
|
139
|
+
: undefined;
|
|
140
|
+
|
|
141
|
+
const result = (await (ctx as { runAction: (ref: typeof actionRef, args: Record<string, unknown>) => Promise<unknown> }).runAction(actionRef, {
|
|
142
|
+
url: request.url,
|
|
143
|
+
method,
|
|
144
|
+
headers,
|
|
145
|
+
body: body ? body : undefined,
|
|
146
|
+
})) as {
|
|
147
|
+
status: number;
|
|
148
|
+
headers: string[][];
|
|
149
|
+
body: ArrayBuffer;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// Filter out hop-by-hop headers
|
|
153
|
+
const filteredHeaders = result.headers.filter(
|
|
154
|
+
([key]) => !hopByHopHeaders.has(key.toLowerCase()),
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
let responseBody: ArrayBuffer | string | null =
|
|
158
|
+
result.body.byteLength > 0 ? result.body : null;
|
|
159
|
+
|
|
160
|
+
// Inject warmup script into HTML responses so subsequent pages
|
|
161
|
+
// don't need to wait for a cold start
|
|
162
|
+
if (warmup && responseBody) {
|
|
163
|
+
const contentType = filteredHeaders.find(
|
|
164
|
+
([k]) => k.toLowerCase() === "content-type",
|
|
165
|
+
);
|
|
166
|
+
if (contentType && contentType[1].includes("text/html")) {
|
|
167
|
+
const html = new TextDecoder().decode(result.body);
|
|
168
|
+
const warmupUrl = normalizedPrefix
|
|
169
|
+
? `${normalizedPrefix}/__warmup`
|
|
170
|
+
: "/__warmup";
|
|
171
|
+
const script = `<script>fetch("${warmupUrl}").catch(()=>{})</script>`;
|
|
172
|
+
responseBody = html.replace("</head>", `${script}</head>`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return new Response(responseBody, {
|
|
177
|
+
status: result.status,
|
|
178
|
+
headers: filteredHeaders as [string, string][],
|
|
179
|
+
});
|
|
180
|
+
} catch (error) {
|
|
181
|
+
const message =
|
|
182
|
+
error instanceof Error ? error.message : "Internal Server Error";
|
|
183
|
+
console.error("Next.js handler error:", error);
|
|
184
|
+
return new Response(message, {
|
|
185
|
+
status: 500,
|
|
186
|
+
headers: { "Content-Type": "text/plain" },
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const methods = [
|
|
192
|
+
"GET",
|
|
193
|
+
"POST",
|
|
194
|
+
"PUT",
|
|
195
|
+
"DELETE",
|
|
196
|
+
"PATCH",
|
|
197
|
+
"OPTIONS",
|
|
198
|
+
] as const;
|
|
199
|
+
|
|
200
|
+
for (const method of methods) {
|
|
201
|
+
http.route({
|
|
202
|
+
pathPrefix: pathPrefix === "/" ? "/" : `${normalizedPrefix}/`,
|
|
203
|
+
method,
|
|
204
|
+
handler,
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
if (normalizedPrefix) {
|
|
208
|
+
http.route({
|
|
209
|
+
path: normalizedPrefix,
|
|
210
|
+
method,
|
|
211
|
+
handler,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Get the MIME type for a file path.
|
|
219
|
+
*/
|
|
220
|
+
export function getNextMimeType(filePath: string): string {
|
|
221
|
+
const ext = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
|
|
222
|
+
return MIME_TYPES[ext] || "application/octet-stream";
|
|
223
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { toReqRes, toFetchResponse } from "fetch-to-node";
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
3
|
+
|
|
4
|
+
export type NodeRequestHandler = (
|
|
5
|
+
req: IncomingMessage,
|
|
6
|
+
res: ServerResponse,
|
|
7
|
+
) => Promise<void>;
|
|
8
|
+
|
|
9
|
+
export async function handleWithNodeHandler(
|
|
10
|
+
request: Request,
|
|
11
|
+
handler: NodeRequestHandler,
|
|
12
|
+
): Promise<Response> {
|
|
13
|
+
const { req, res } = toReqRes(request);
|
|
14
|
+
await handler(req, res);
|
|
15
|
+
if (!res.writableEnded) res.end();
|
|
16
|
+
return await toFetchResponse(res);
|
|
17
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
import { test } from "vitest";
|
|
3
|
+
import { convexTest } from "convex-test";
|
|
4
|
+
export const modules = import.meta.glob("./**/*.*s");
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
defineSchema,
|
|
8
|
+
type GenericSchema,
|
|
9
|
+
type SchemaDefinition,
|
|
10
|
+
} from "convex/server";
|
|
11
|
+
import { type ComponentApi } from "../component/_generated/component.js";
|
|
12
|
+
import { componentsGeneric } from "convex/server";
|
|
13
|
+
import { register } from "../test.js";
|
|
14
|
+
|
|
15
|
+
export function initConvexTest<
|
|
16
|
+
Schema extends SchemaDefinition<GenericSchema, boolean>,
|
|
17
|
+
>(schema?: Schema) {
|
|
18
|
+
const t = convexTest(schema ?? defineSchema({}), modules);
|
|
19
|
+
register(t);
|
|
20
|
+
return t;
|
|
21
|
+
}
|
|
22
|
+
export const components = componentsGeneric() as unknown as {
|
|
23
|
+
staticHosting: ComponentApi;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
test("setup", () => {});
|
|
@@ -0,0 +1,50 @@
|
|
|
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 lib from "../lib.js";
|
|
12
|
+
|
|
13
|
+
import type {
|
|
14
|
+
ApiFromModules,
|
|
15
|
+
FilterApi,
|
|
16
|
+
FunctionReference,
|
|
17
|
+
} from "convex/server";
|
|
18
|
+
import { anyApi, componentsGeneric } from "convex/server";
|
|
19
|
+
|
|
20
|
+
const fullApi: ApiFromModules<{
|
|
21
|
+
lib: typeof lib;
|
|
22
|
+
}> = anyApi as any;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A utility for referencing Convex functions in your app's public API.
|
|
26
|
+
*
|
|
27
|
+
* Usage:
|
|
28
|
+
* ```js
|
|
29
|
+
* const myFunctionReference = api.myModule.myFunction;
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export const api: FilterApi<
|
|
33
|
+
typeof fullApi,
|
|
34
|
+
FunctionReference<any, "public">
|
|
35
|
+
> = anyApi as any;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A utility for referencing Convex functions in your app's internal API.
|
|
39
|
+
*
|
|
40
|
+
* Usage:
|
|
41
|
+
* ```js
|
|
42
|
+
* const myFunctionReference = internal.myModule.myFunction;
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export const internal: FilterApi<
|
|
46
|
+
typeof fullApi,
|
|
47
|
+
FunctionReference<any, "internal">
|
|
48
|
+
> = anyApi as any;
|
|
49
|
+
|
|
50
|
+
export const components = componentsGeneric() as unknown as {};
|
|
@@ -0,0 +1,104 @@
|
|
|
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
|
+
lib: {
|
|
27
|
+
gcOldAssets: FunctionReference<
|
|
28
|
+
"mutation",
|
|
29
|
+
"internal",
|
|
30
|
+
{ currentDeploymentId: string },
|
|
31
|
+
{ blobIds: Array<string>; storageIds: Array<string> },
|
|
32
|
+
Name
|
|
33
|
+
>;
|
|
34
|
+
generateUploadUrl: FunctionReference<
|
|
35
|
+
"mutation",
|
|
36
|
+
"internal",
|
|
37
|
+
{},
|
|
38
|
+
string,
|
|
39
|
+
Name
|
|
40
|
+
>;
|
|
41
|
+
getByPath: FunctionReference<
|
|
42
|
+
"query",
|
|
43
|
+
"internal",
|
|
44
|
+
{ path: string },
|
|
45
|
+
{
|
|
46
|
+
_creationTime: number;
|
|
47
|
+
_id: string;
|
|
48
|
+
blobId?: string;
|
|
49
|
+
contentType: string;
|
|
50
|
+
deploymentId: string;
|
|
51
|
+
path: string;
|
|
52
|
+
storageId?: string;
|
|
53
|
+
} | null,
|
|
54
|
+
Name
|
|
55
|
+
>;
|
|
56
|
+
getCurrentDeployment: FunctionReference<
|
|
57
|
+
"query",
|
|
58
|
+
"internal",
|
|
59
|
+
{},
|
|
60
|
+
{
|
|
61
|
+
_creationTime: number;
|
|
62
|
+
_id: string;
|
|
63
|
+
currentDeploymentId: string;
|
|
64
|
+
deployedAt: number;
|
|
65
|
+
} | null,
|
|
66
|
+
Name
|
|
67
|
+
>;
|
|
68
|
+
listAssets: FunctionReference<
|
|
69
|
+
"query",
|
|
70
|
+
"internal",
|
|
71
|
+
{ limit?: number },
|
|
72
|
+
Array<{
|
|
73
|
+
_creationTime: number;
|
|
74
|
+
_id: string;
|
|
75
|
+
blobId?: string;
|
|
76
|
+
contentType: string;
|
|
77
|
+
deploymentId: string;
|
|
78
|
+
path: string;
|
|
79
|
+
storageId?: string;
|
|
80
|
+
}>,
|
|
81
|
+
Name
|
|
82
|
+
>;
|
|
83
|
+
recordAsset: FunctionReference<
|
|
84
|
+
"mutation",
|
|
85
|
+
"internal",
|
|
86
|
+
{
|
|
87
|
+
blobId?: string;
|
|
88
|
+
contentType: string;
|
|
89
|
+
deploymentId: string;
|
|
90
|
+
path: string;
|
|
91
|
+
storageId?: string;
|
|
92
|
+
},
|
|
93
|
+
{ oldBlobId: string | null; oldStorageId: string | null },
|
|
94
|
+
Name
|
|
95
|
+
>;
|
|
96
|
+
setCurrentDeployment: FunctionReference<
|
|
97
|
+
"mutation",
|
|
98
|
+
"internal",
|
|
99
|
+
{ deploymentId: string },
|
|
100
|
+
null,
|
|
101
|
+
Name
|
|
102
|
+
>;
|
|
103
|
+
};
|
|
104
|
+
};
|
|
@@ -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(tableName, 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,161 @@
|
|
|
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 type {
|
|
12
|
+
ActionBuilder,
|
|
13
|
+
HttpActionBuilder,
|
|
14
|
+
MutationBuilder,
|
|
15
|
+
QueryBuilder,
|
|
16
|
+
GenericActionCtx,
|
|
17
|
+
GenericMutationCtx,
|
|
18
|
+
GenericQueryCtx,
|
|
19
|
+
GenericDatabaseReader,
|
|
20
|
+
GenericDatabaseWriter,
|
|
21
|
+
} from "convex/server";
|
|
22
|
+
import {
|
|
23
|
+
actionGeneric,
|
|
24
|
+
httpActionGeneric,
|
|
25
|
+
queryGeneric,
|
|
26
|
+
mutationGeneric,
|
|
27
|
+
internalActionGeneric,
|
|
28
|
+
internalMutationGeneric,
|
|
29
|
+
internalQueryGeneric,
|
|
30
|
+
} from "convex/server";
|
|
31
|
+
import type { DataModel } from "./dataModel.js";
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Define a query in this Convex app's public API.
|
|
35
|
+
*
|
|
36
|
+
* This function will be allowed to read your Convex database and will be accessible from the client.
|
|
37
|
+
*
|
|
38
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
39
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
40
|
+
*/
|
|
41
|
+
export const query: QueryBuilder<DataModel, "public"> = queryGeneric;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Define a query that is only accessible from other Convex functions (but not from the client).
|
|
45
|
+
*
|
|
46
|
+
* This function will be allowed to read from your Convex database. It will not be accessible from the client.
|
|
47
|
+
*
|
|
48
|
+
* @param func - The query function. It receives a {@link QueryCtx} as its first argument.
|
|
49
|
+
* @returns The wrapped query. Include this as an `export` to name it and make it accessible.
|
|
50
|
+
*/
|
|
51
|
+
export const internalQuery: QueryBuilder<DataModel, "internal"> =
|
|
52
|
+
internalQueryGeneric;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Define a mutation in this Convex app's public API.
|
|
56
|
+
*
|
|
57
|
+
* This function will be allowed to modify your Convex database and will be accessible from the client.
|
|
58
|
+
*
|
|
59
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
60
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
61
|
+
*/
|
|
62
|
+
export const mutation: MutationBuilder<DataModel, "public"> = mutationGeneric;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Define a mutation that is only accessible from other Convex functions (but not from the client).
|
|
66
|
+
*
|
|
67
|
+
* This function will be allowed to modify your Convex database. It will not be accessible from the client.
|
|
68
|
+
*
|
|
69
|
+
* @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
|
|
70
|
+
* @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
|
|
71
|
+
*/
|
|
72
|
+
export const internalMutation: MutationBuilder<DataModel, "internal"> =
|
|
73
|
+
internalMutationGeneric;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Define an action in this Convex app's public API.
|
|
77
|
+
*
|
|
78
|
+
* An action is a function which can execute any JavaScript code, including non-deterministic
|
|
79
|
+
* code and code with side-effects, like calling third-party services.
|
|
80
|
+
* They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
|
|
81
|
+
* They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
|
|
82
|
+
*
|
|
83
|
+
* @param func - The action. It receives an {@link ActionCtx} as its first argument.
|
|
84
|
+
* @returns The wrapped action. Include this as an `export` to name it and make it accessible.
|
|
85
|
+
*/
|
|
86
|
+
export const action: ActionBuilder<DataModel, "public"> = actionGeneric;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Define an action that is only accessible from other Convex functions (but not from the client).
|
|
90
|
+
*
|
|
91
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument.
|
|
92
|
+
* @returns The wrapped function. Include this as an `export` to name it and make it accessible.
|
|
93
|
+
*/
|
|
94
|
+
export const internalAction: ActionBuilder<DataModel, "internal"> =
|
|
95
|
+
internalActionGeneric;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Define an HTTP action.
|
|
99
|
+
*
|
|
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`.
|
|
103
|
+
*
|
|
104
|
+
* @param func - The function. It receives an {@link ActionCtx} as its first argument
|
|
105
|
+
* and a Fetch API `Request` object as its second.
|
|
106
|
+
* @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
|
|
107
|
+
*/
|
|
108
|
+
export const httpAction: HttpActionBuilder = httpActionGeneric;
|
|
109
|
+
|
|
110
|
+
type GenericCtx =
|
|
111
|
+
| GenericActionCtx<DataModel>
|
|
112
|
+
| GenericMutationCtx<DataModel>
|
|
113
|
+
| GenericQueryCtx<DataModel>;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* A set of services for use within Convex query functions.
|
|
117
|
+
*
|
|
118
|
+
* The query context is passed as the first argument to any Convex query
|
|
119
|
+
* function run on the server.
|
|
120
|
+
*
|
|
121
|
+
* If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
|
|
122
|
+
*/
|
|
123
|
+
export type QueryCtx = GenericQueryCtx<DataModel>;
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* A set of services for use within Convex mutation functions.
|
|
127
|
+
*
|
|
128
|
+
* The mutation context is passed as the first argument to any Convex mutation
|
|
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.
|
|
132
|
+
*/
|
|
133
|
+
export type MutationCtx = GenericMutationCtx<DataModel>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A set of services for use within Convex action functions.
|
|
137
|
+
*
|
|
138
|
+
* The action context is passed as the first argument to any Convex action
|
|
139
|
+
* function run on the server.
|
|
140
|
+
*/
|
|
141
|
+
export type ActionCtx = GenericActionCtx<DataModel>;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* An interface to read from the database within Convex query functions.
|
|
145
|
+
*
|
|
146
|
+
* The two entry points are {@link DatabaseReader.get}, which fetches a single
|
|
147
|
+
* document by its {@link Id}, or {@link DatabaseReader.query}, which starts
|
|
148
|
+
* building a query.
|
|
149
|
+
*/
|
|
150
|
+
export type DatabaseReader = GenericDatabaseReader<DataModel>;
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* An interface to read from and write to the database within Convex mutation
|
|
154
|
+
* functions.
|
|
155
|
+
*
|
|
156
|
+
* Convex guarantees that all writes within a single mutation are
|
|
157
|
+
* executed atomically, so you never have to worry about partial writes leaving
|
|
158
|
+
* your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
|
|
159
|
+
* for the guarantees Convex provides your functions.
|
|
160
|
+
*/
|
|
161
|
+
export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
|