@samebase/convex-hosting 0.3.2 → 0.4.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.
Files changed (193) hide show
  1. package/CHANGELOG.md +17 -132
  2. package/README.md +188 -406
  3. package/dist/cli/convex.d.ts +63 -0
  4. package/dist/cli/convex.js +108 -0
  5. package/dist/cli/convex.js.map +1 -0
  6. package/dist/cli/files.d.ts +18 -0
  7. package/dist/cli/files.js +106 -0
  8. package/dist/cli/files.js.map +1 -0
  9. package/dist/cli/index.d.ts +1 -11
  10. package/dist/cli/index.js +3 -58
  11. package/dist/cli/index.js.map +1 -1
  12. package/dist/cli/main.d.ts +5 -0
  13. package/dist/cli/main.js +377 -0
  14. package/dist/cli/main.js.map +1 -0
  15. package/dist/client/index.d.ts +8 -115
  16. package/dist/client/index.js +65 -242
  17. package/dist/client/index.js.map +1 -1
  18. package/dist/client/types.d.ts +5 -0
  19. package/dist/client/version-module.d.ts +6 -0
  20. package/dist/component/_generated/api.d.ts +0 -5
  21. package/dist/component/_generated/api.js.map +1 -1
  22. package/dist/component/_generated/component.d.ts +20 -18
  23. package/dist/component/_generated/dataModel.d.ts +0 -1
  24. package/dist/component/_generated/server.d.ts +12 -1
  25. package/dist/component/_generated/server.js +2 -0
  26. package/dist/component/_generated/server.js.map +1 -1
  27. package/dist/component/convex.config.d.ts +0 -1
  28. package/dist/component/lib.d.ts +175 -156
  29. package/dist/component/lib.js +396 -710
  30. package/dist/component/lib.js.map +1 -1
  31. package/dist/component/schema.d.ts +76 -72
  32. package/dist/component/schema.js +35 -59
  33. package/dist/component/schema.js.map +1 -1
  34. package/dist/workers-shared/asset-worker/src/analytics.d.ts +39 -0
  35. package/dist/workers-shared/asset-worker/src/analytics.js +86 -0
  36. package/dist/workers-shared/asset-worker/src/analytics.js.map +1 -0
  37. package/dist/workers-shared/asset-worker/src/compatibility-flags.d.ts +19 -0
  38. package/dist/workers-shared/asset-worker/src/compatibility-flags.js +29 -0
  39. package/dist/workers-shared/asset-worker/src/compatibility-flags.js.map +1 -0
  40. package/dist/workers-shared/asset-worker/src/configuration.d.ts +3 -0
  41. package/dist/workers-shared/asset-worker/src/configuration.js +30 -0
  42. package/dist/workers-shared/asset-worker/src/configuration.js.map +1 -0
  43. package/dist/workers-shared/asset-worker/src/constants.d.ts +1 -0
  44. package/dist/workers-shared/asset-worker/src/constants.js +3 -0
  45. package/dist/workers-shared/asset-worker/src/constants.js.map +1 -0
  46. package/dist/workers-shared/asset-worker/src/handler.d.ts +28 -0
  47. package/dist/workers-shared/asset-worker/src/handler.js +717 -0
  48. package/dist/workers-shared/asset-worker/src/handler.js.map +1 -0
  49. package/dist/workers-shared/asset-worker/src/types.d.ts +13 -0
  50. package/dist/workers-shared/asset-worker/src/types.js +2 -0
  51. package/dist/workers-shared/asset-worker/src/types.js.map +1 -0
  52. package/dist/workers-shared/asset-worker/src/utils/base-path.d.ts +29 -0
  53. package/dist/workers-shared/asset-worker/src/utils/base-path.js +56 -0
  54. package/dist/workers-shared/asset-worker/src/utils/base-path.js.map +1 -0
  55. package/dist/workers-shared/asset-worker/src/utils/headers.d.ts +11 -0
  56. package/dist/workers-shared/asset-worker/src/utils/headers.js +77 -0
  57. package/dist/workers-shared/asset-worker/src/utils/headers.js.map +1 -0
  58. package/dist/workers-shared/asset-worker/src/utils/rules-engine.d.ts +23 -0
  59. package/dist/workers-shared/asset-worker/src/utils/rules-engine.js +133 -0
  60. package/dist/workers-shared/asset-worker/src/utils/rules-engine.js.map +1 -0
  61. package/dist/workers-shared/asset-worker/src/worker.d.ts +14 -0
  62. package/dist/workers-shared/asset-worker/src/worker.js +12 -0
  63. package/dist/workers-shared/asset-worker/src/worker.js.map +1 -0
  64. package/dist/workers-shared/utils/base-path.d.ts +32 -0
  65. package/dist/workers-shared/utils/base-path.js +94 -0
  66. package/dist/workers-shared/utils/base-path.js.map +1 -0
  67. package/dist/workers-shared/utils/configuration/constants.d.ts +15 -0
  68. package/dist/workers-shared/utils/configuration/constants.js +16 -0
  69. package/dist/workers-shared/utils/configuration/constants.js.map +1 -0
  70. package/dist/workers-shared/utils/configuration/constructConfiguration.d.ts +12 -0
  71. package/dist/workers-shared/utils/configuration/constructConfiguration.js +103 -0
  72. package/dist/workers-shared/utils/configuration/constructConfiguration.js.map +1 -0
  73. package/dist/workers-shared/utils/configuration/parseHeaders.d.ts +5 -0
  74. package/dist/workers-shared/utils/configuration/parseHeaders.js +181 -0
  75. package/dist/workers-shared/utils/configuration/parseHeaders.js.map +1 -0
  76. package/dist/workers-shared/utils/configuration/parseRedirects.d.ts +8 -0
  77. package/dist/workers-shared/utils/configuration/parseRedirects.js +129 -0
  78. package/dist/workers-shared/utils/configuration/parseRedirects.js.map +1 -0
  79. package/dist/workers-shared/utils/configuration/parseStaticRouting.d.ts +2 -0
  80. package/dist/workers-shared/utils/configuration/parseStaticRouting.js +94 -0
  81. package/dist/workers-shared/utils/configuration/parseStaticRouting.js.map +1 -0
  82. package/dist/workers-shared/utils/configuration/types.d.ts +38 -0
  83. package/dist/workers-shared/utils/configuration/types.js +2 -0
  84. package/dist/workers-shared/utils/configuration/types.js.map +1 -0
  85. package/dist/workers-shared/utils/configuration/validateURL.d.ts +3 -0
  86. package/dist/workers-shared/utils/configuration/validateURL.js +56 -0
  87. package/dist/workers-shared/utils/configuration/validateURL.js.map +1 -0
  88. package/dist/workers-shared/utils/constants.d.ts +28 -0
  89. package/dist/workers-shared/utils/constants.js +34 -0
  90. package/dist/workers-shared/utils/constants.js.map +1 -0
  91. package/dist/workers-shared/utils/helpers.d.ts +22 -0
  92. package/dist/workers-shared/utils/helpers.js +73 -0
  93. package/dist/workers-shared/utils/helpers.js.map +1 -0
  94. package/dist/workers-shared/utils/responses.d.ts +43 -0
  95. package/dist/workers-shared/utils/responses.js +125 -0
  96. package/dist/workers-shared/utils/responses.js.map +1 -0
  97. package/dist/workers-shared/utils/tracing.d.ts +3 -0
  98. package/dist/workers-shared/utils/tracing.js +29 -0
  99. package/dist/workers-shared/utils/tracing.js.map +1 -0
  100. package/dist/workers-shared/utils/types.d.ts +131 -0
  101. package/dist/workers-shared/utils/types.js +72 -0
  102. package/dist/workers-shared/utils/types.js.map +1 -0
  103. package/package.json +21 -37
  104. package/INTEGRATION.md +0 -399
  105. package/dist/cli/args.d.ts +0 -28
  106. package/dist/cli/args.d.ts.map +0 -1
  107. package/dist/cli/args.js +0 -148
  108. package/dist/cli/args.js.map +0 -1
  109. package/dist/cli/argumentChunks.d.ts +0 -3
  110. package/dist/cli/argumentChunks.d.ts.map +0 -1
  111. package/dist/cli/argumentChunks.js +0 -29
  112. package/dist/cli/argumentChunks.js.map +0 -1
  113. package/dist/cli/collectFiles.d.ts +0 -10
  114. package/dist/cli/collectFiles.d.ts.map +0 -1
  115. package/dist/cli/collectFiles.js +0 -53
  116. package/dist/cli/collectFiles.js.map +0 -1
  117. package/dist/cli/commands.d.ts +0 -8
  118. package/dist/cli/commands.d.ts.map +0 -1
  119. package/dist/cli/commands.js +0 -56
  120. package/dist/cli/commands.js.map +0 -1
  121. package/dist/cli/componentName.d.ts +0 -32
  122. package/dist/cli/componentName.d.ts.map +0 -1
  123. package/dist/cli/componentName.js +0 -43
  124. package/dist/cli/componentName.js.map +0 -1
  125. package/dist/cli/deploy.d.ts +0 -16
  126. package/dist/cli/deploy.d.ts.map +0 -1
  127. package/dist/cli/deploy.js +0 -283
  128. package/dist/cli/deploy.js.map +0 -1
  129. package/dist/cli/deployEnvironment.d.ts +0 -10
  130. package/dist/cli/deployEnvironment.d.ts.map +0 -1
  131. package/dist/cli/deployEnvironment.js +0 -12
  132. package/dist/cli/deployEnvironment.js.map +0 -1
  133. package/dist/cli/index.d.ts.map +0 -1
  134. package/dist/cli/upload.d.ts +0 -22
  135. package/dist/cli/upload.d.ts.map +0 -1
  136. package/dist/cli/upload.js +0 -630
  137. package/dist/cli/upload.js.map +0 -1
  138. package/dist/client/_generated/_ignore.d.ts +0 -1
  139. package/dist/client/_generated/_ignore.d.ts.map +0 -1
  140. package/dist/client/_generated/_ignore.js +0 -3
  141. package/dist/client/_generated/_ignore.js.map +0 -1
  142. package/dist/client/index.d.ts.map +0 -1
  143. package/dist/component/_generated/api.d.ts.map +0 -1
  144. package/dist/component/_generated/component.d.ts.map +0 -1
  145. package/dist/component/_generated/dataModel.d.ts.map +0 -1
  146. package/dist/component/_generated/server.d.ts.map +0 -1
  147. package/dist/component/convex.config.d.ts.map +0 -1
  148. package/dist/component/http.d.ts +0 -4
  149. package/dist/component/http.d.ts.map +0 -1
  150. package/dist/component/http.js +0 -113
  151. package/dist/component/http.js.map +0 -1
  152. package/dist/component/lib.d.ts.map +0 -1
  153. package/dist/component/schema.d.ts.map +0 -1
  154. package/dist/component/serving.d.ts +0 -23
  155. package/dist/component/serving.d.ts.map +0 -1
  156. package/dist/component/serving.js +0 -161
  157. package/dist/component/serving.js.map +0 -1
  158. package/dist/react/index.d.ts +0 -59
  159. package/dist/react/index.d.ts.map +0 -1
  160. package/dist/react/index.js +0 -137
  161. package/dist/react/index.js.map +0 -1
  162. package/src/cli/args.test.ts +0 -79
  163. package/src/cli/args.ts +0 -153
  164. package/src/cli/argumentChunks.test.ts +0 -27
  165. package/src/cli/argumentChunks.ts +0 -40
  166. package/src/cli/collectFiles.test.ts +0 -26
  167. package/src/cli/collectFiles.ts +0 -59
  168. package/src/cli/commands.ts +0 -68
  169. package/src/cli/componentName.test.ts +0 -41
  170. package/src/cli/componentName.ts +0 -46
  171. package/src/cli/deploy.ts +0 -336
  172. package/src/cli/deployEnvironment.test.ts +0 -27
  173. package/src/cli/deployEnvironment.ts +0 -17
  174. package/src/cli/index.ts +0 -65
  175. package/src/cli/upload.ts +0 -837
  176. package/src/client/_generated/_ignore.ts +0 -1
  177. package/src/client/index.test.ts +0 -549
  178. package/src/client/index.ts +0 -344
  179. package/src/client/setup.test.ts +0 -22
  180. package/src/component/_generated/api.ts +0 -54
  181. package/src/component/_generated/component.ts +0 -55
  182. package/src/component/_generated/dataModel.ts +0 -60
  183. package/src/component/_generated/server.ts +0 -156
  184. package/src/component/convex.config.ts +0 -3
  185. package/src/component/http.test.ts +0 -254
  186. package/src/component/http.ts +0 -133
  187. package/src/component/lib.test.ts +0 -1007
  188. package/src/component/lib.ts +0 -862
  189. package/src/component/schema.ts +0 -75
  190. package/src/component/serving.ts +0 -170
  191. package/src/component/setup.test.ts +0 -11
  192. package/src/react/index.tsx +0 -197
  193. package/src/test.ts +0 -23
@@ -1,344 +0,0 @@
1
- import {
2
- httpActionGeneric,
3
- queryGeneric,
4
- type GenericActionCtx,
5
- type GenericDataModel,
6
- type HttpRouter,
7
- } from "convex/server";
8
- import { v, type GenericId } from "convex/values";
9
- import type { ComponentApi } from "../component/_generated/component.js";
10
- import {
11
- cacheControlFor,
12
- decodeRequestPath,
13
- errorResponse,
14
- etagMatches,
15
- getMimeType,
16
- getSetupHtml,
17
- isHtmlContentType,
18
- } from "../component/serving.js";
19
-
20
- const deploymentInfoValidator = v.object({
21
- _id: v.string(),
22
- _creationTime: v.number(),
23
- currentDeploymentId: v.string(),
24
- deployedAt: v.number(),
25
- spaFallback: v.optional(v.boolean()),
26
- });
27
-
28
- type CdnBaseUrl = string | ((request: Request) => string);
29
-
30
- /** The parts of an action context needed to serve a static file. */
31
- type AssetServingCtx = Pick<GenericActionCtx<GenericDataModel>, "runQuery" | "storage">;
32
-
33
- /**
34
- * Register app-owned HTTP routes for the hosted site.
35
- *
36
- * Prefer mounting the component's own HTTP routes when it can own the URL
37
- * prefix. Use this compatibility mode when existing app HTTP routes must stay
38
- * at the same root. Exact app routes take precedence over this catch-all.
39
- * Assets and deployment state still live in the component.
40
- *
41
- * @example
42
- * ```typescript
43
- * // convex/convex.config.ts
44
- * const app = defineApp();
45
- * app.use(hosting); // no httpPrefix: the app owns HTTP routing
46
- *
47
- * // convex/http.ts
48
- * const http = httpRouter();
49
- * auth.addHttpRoutes(http);
50
- * registerStaticRoutes(http, components.hosting);
51
- * export default http;
52
- * ```
53
- */
54
- export function registerStaticRoutes(
55
- http: HttpRouter,
56
- component: ComponentApi,
57
- {
58
- pathPrefix = "/",
59
- spaFallback,
60
- cdnBaseUrl,
61
- }: {
62
- /** URL prefix where the app should serve static files. */
63
- pathPrefix?: string;
64
- /** Override the deployment's SPA fallback setting. */
65
- spaFallback?: boolean;
66
- /** Optional custom base URL for convex-fs blob redirects. */
67
- cdnBaseUrl?: CdnBaseUrl;
68
- } = {},
69
- ) {
70
- if (!pathPrefix.startsWith("/")) {
71
- throw new Error("pathPrefix must start with /");
72
- }
73
-
74
- const normalizedPrefix = pathPrefix === "/" ? "" : pathPrefix.replace(/\/$/, "");
75
-
76
- const serveStaticFile = httpActionGeneric(async (ctx, request) => {
77
- const decodedPath = decodeRequestPath(new URL(request.url).pathname);
78
- if (decodedPath === null) {
79
- return errorResponse(400, "Bad Request");
80
- }
81
- let path = decodedPath;
82
-
83
- if (normalizedPrefix && path.startsWith(normalizedPrefix)) {
84
- path = path.slice(normalizedPrefix.length) || "/";
85
- }
86
- if (path === "" || path === "/") {
87
- path = "/index.html";
88
- }
89
-
90
- const response = await serveAsset(ctx, component, request, path, {
91
- spaFallback,
92
- cdnBaseUrl,
93
- });
94
- if (response) return response;
95
-
96
- if (path === "/index.html") {
97
- return new Response(getSetupHtml(), {
98
- status: 503,
99
- headers: {
100
- "Content-Type": "text/html; charset=utf-8",
101
- "Cache-Control": "no-store",
102
- "Retry-After": "5",
103
- },
104
- });
105
- }
106
- return errorResponse(404, "Not Found");
107
- });
108
-
109
- http.route({
110
- pathPrefix: pathPrefix === "/" ? "/" : `${normalizedPrefix}/`,
111
- method: "GET",
112
- handler: serveStaticFile,
113
- });
114
-
115
- if (normalizedPrefix) {
116
- http.route({
117
- path: normalizedPrefix,
118
- method: "GET",
119
- handler: serveStaticFile,
120
- });
121
- }
122
- }
123
-
124
- /**
125
- * Serve an uploaded static file from your own HTTP action, or return null when
126
- * no file matches so the action can continue with its own routing: server
127
- * rendering, prerendered pages, redirects.
128
- *
129
- * Found files get the same response as `registerStaticRoutes`: content type,
130
- * cache headers, ETag revalidation, and legacy CDN redirects. A found file
131
- * whose storage can't be read gets a 500 response. A request path with
132
- * malformed percent-encoding matches no file, so it returns null.
133
- *
134
- * The lookup is exact by default. `/` is not mapped to `/index.html`, and there
135
- * is no SPA fallback, so the SPA shell never answers for a route your action
136
- * handles. To serve the shell, pass `{ path: "/index.html" }`. When your route
137
- * has a prefix, pass `path` with the prefix removed.
138
- *
139
- * @example
140
- * ```typescript
141
- * // convex/http.ts
142
- * const http = httpRouter();
143
- * http.route({
144
- * pathPrefix: "/",
145
- * method: "GET",
146
- * handler: httpAction(async (ctx, request) => {
147
- * const file = await serveStaticAsset(ctx, components.hosting, request);
148
- * if (file) return file;
149
- * return await renderPage(request);
150
- * }),
151
- * });
152
- * export default http;
153
- * ```
154
- */
155
- export async function serveStaticAsset(
156
- ctx: AssetServingCtx,
157
- component: ComponentApi,
158
- request: Request,
159
- {
160
- path,
161
- spaFallback = false,
162
- cdnBaseUrl,
163
- }: {
164
- /**
165
- * Decoded file path to look up, starting with `/`, such as
166
- * `/about/index.html`. Defaults to the decoded request path.
167
- */
168
- path?: string;
169
- /** Serve `/index.html` for a missing path without a file extension. */
170
- spaFallback?: boolean;
171
- /** Optional custom base URL for convex-fs blob redirects. */
172
- cdnBaseUrl?: CdnBaseUrl;
173
- } = {},
174
- ): Promise<Response | null> {
175
- if (path !== undefined && !path.startsWith("/")) {
176
- throw new Error("path must start with /");
177
- }
178
- const filePath = path ?? decodeRequestPath(new URL(request.url).pathname);
179
- if (filePath === null) return null;
180
- return await serveAsset(ctx, component, request, filePath, {
181
- spaFallback,
182
- cdnBaseUrl,
183
- });
184
- }
185
-
186
- export { decodeRequestPath };
187
-
188
- /**
189
- * Serve the uploaded file at `path` (decoded, relative to the mount prefix),
190
- * or return null when no file matches. An undefined `spaFallback` uses the
191
- * deployment's stored setting.
192
- */
193
- async function serveAsset(
194
- ctx: AssetServingCtx,
195
- component: ComponentApi,
196
- request: Request,
197
- path: string,
198
- {
199
- spaFallback,
200
- cdnBaseUrl,
201
- }: {
202
- spaFallback: boolean | undefined;
203
- cdnBaseUrl: CdnBaseUrl | undefined;
204
- },
205
- ): Promise<Response | null> {
206
- const asset = await ctx.runQuery(component.lib.resolveAssetForHttp, {
207
- path,
208
- ...(spaFallback === undefined ? {} : { spaFallback }),
209
- });
210
- if (!asset) return null;
211
-
212
- const contentType = asset.contentType || getMimeType(path);
213
- const cacheControl = cacheControlFor(path);
214
-
215
- if (asset.blobId && !isHtmlContentType(contentType)) {
216
- const configuredBase = typeof cdnBaseUrl === "function" ? cdnBaseUrl(request) : cdnBaseUrl;
217
- const baseUrl = configuredBase ?? `${new URL(request.url).origin}/fs/blobs`;
218
- return new Response(null, {
219
- status: 302,
220
- headers: {
221
- Location: `${baseUrl.replace(/\/$/, "")}/${asset.blobId}`,
222
- "Cache-Control": cacheControl,
223
- },
224
- });
225
- }
226
-
227
- // TODO(remove in a future major): v1→v2 transitional path. The file still
228
- // lives in the app's own storage (a same-name migration inherited the v1
229
- // row; see the component's resolveAssetForHttp). Serve it directly from app
230
- // storage so the site stays up during migration with no re-upload. Once v1
231
- // app-storage assets are no longer supported, delete this branch.
232
- if (asset.appStorageId) {
233
- if (asset.etag && etagMatches(request.headers.get("If-None-Match"), asset.etag)) {
234
- return new Response(null, {
235
- status: 304,
236
- headers: { ETag: asset.etag, "Cache-Control": cacheControl },
237
- });
238
- }
239
- const blob = await ctx.storage.get(asset.appStorageId as GenericId<"_storage">);
240
- if (!blob) {
241
- // The component surfaces appStorageId whenever it can't resolve a
242
- // storage URL, which also covers a genuinely deleted file (the two are
243
- // indistinguishable from the component). If it isn't in app storage
244
- // either, treat it as missing, like an empty deployment, rather than
245
- // erroring.
246
- return null;
247
- }
248
- return new Response(blob, {
249
- status: 200,
250
- headers: {
251
- "Content-Type": contentType,
252
- "Cache-Control": cacheControl,
253
- ...(asset.etag ? { ETag: asset.etag } : {}),
254
- "X-Content-Type-Options": "nosniff",
255
- },
256
- });
257
- }
258
-
259
- if (!asset.storageUrl) {
260
- return errorResponse(500, "Asset not available");
261
- }
262
-
263
- if (asset.etag && etagMatches(request.headers.get("If-None-Match"), asset.etag)) {
264
- return new Response(null, {
265
- status: 304,
266
- headers: { ETag: asset.etag, "Cache-Control": cacheControl },
267
- });
268
- }
269
-
270
- const storageResponse = await fetch(asset.storageUrl);
271
- if (!storageResponse.ok || !storageResponse.body) {
272
- return errorResponse(500, "Storage error");
273
- }
274
-
275
- return new Response(storageResponse.body, {
276
- status: 200,
277
- headers: {
278
- "Content-Type": contentType,
279
- "Cache-Control": cacheControl,
280
- ...(asset.etag ? { ETag: asset.etag } : {}),
281
- "X-Content-Type-Options": "nosniff",
282
- },
283
- });
284
- }
285
-
286
- /**
287
- * Expose a query that clients can subscribe to for live reload on deploy.
288
- * This is only needed if you use `UpdateBanner` / `useDeploymentUpdates` from
289
- * `@samebase/convex-hosting/react`. If you don't surface deployment updates
290
- * in your app, you don't need to call this.
291
- *
292
- * @example
293
- * ```typescript
294
- * // convex/hosting.ts
295
- * import { exposeDeploymentQuery } from "@samebase/convex-hosting";
296
- * import { components } from "./_generated/api";
297
- *
298
- * export const { getCurrentDeployment } = exposeDeploymentQuery(
299
- * components.hosting,
300
- * );
301
- * ```
302
- */
303
- export function exposeDeploymentQuery(component: ComponentApi) {
304
- return {
305
- getCurrentDeployment: queryGeneric({
306
- args: {},
307
- returns: v.union(deploymentInfoValidator, v.null()),
308
- handler: async (ctx) => {
309
- const deployment = await ctx.runQuery(component.lib.getCurrentDeployment, {});
310
- if (!deployment) return null;
311
- // Cleanup accounting is private component state. Returning it through
312
- // this public wrapper would fail the narrower response validator.
313
- const deploymentWithCleanup = deployment as typeof deployment & {
314
- pendingBlobCleanupCount?: number;
315
- };
316
- const { pendingBlobCleanupCount: _pending, ...publicDeployment } = deploymentWithCleanup;
317
- return publicDeployment;
318
- },
319
- }),
320
- };
321
- }
322
-
323
- /**
324
- * Derive the Convex cloud URL from a `.convex.site` hostname.
325
- * Useful when your frontend is served by this component and needs
326
- * to connect to its own Convex backend without an explicit env var.
327
- *
328
- * @example
329
- * ```typescript
330
- * import { getConvexUrl } from "@samebase/convex-hosting";
331
- *
332
- * const convexUrl = import.meta.env.VITE_CONVEX_URL ?? getConvexUrl();
333
- * const convex = new ConvexReactClient(convexUrl);
334
- * ```
335
- */
336
- export function getConvexUrl(): string {
337
- if (typeof window === "undefined") {
338
- throw new Error("getConvexUrl() can only be called in a browser context");
339
- }
340
- if (window.location.hostname.endsWith(".convex.site")) {
341
- return `https://${window.location.hostname.replace(".convex.site", ".convex.cloud")}`;
342
- }
343
- throw new Error("Unable to derive Convex URL. Please set VITE_CONVEX_URL environment variable.");
344
- }
@@ -1,22 +0,0 @@
1
- /// <reference types="vite/client" />
2
- import { test } from "vite-plus/test";
3
- import { convexTest } from "convex-test";
4
- export const modules = import.meta.glob("./**/*.*s");
5
-
6
- import { defineSchema, type GenericSchema, type SchemaDefinition } from "convex/server";
7
- import { type ComponentApi } from "../component/_generated/component.js";
8
- import { componentsGeneric } from "convex/server";
9
- import { register } from "../test.js";
10
-
11
- export function initConvexTest<Schema extends SchemaDefinition<GenericSchema, boolean>>(
12
- schema?: Schema,
13
- ) {
14
- const t = convexTest(schema ?? defineSchema({}), modules);
15
- register(t);
16
- return t;
17
- }
18
- export const components = componentsGeneric() as unknown as {
19
- hosting: ComponentApi;
20
- };
21
-
22
- test("setup", () => {});
@@ -1,54 +0,0 @@
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 http from "../http.js";
12
- import type * as lib from "../lib.js";
13
- import type * as serving from "../serving.js";
14
-
15
- import type {
16
- ApiFromModules,
17
- FilterApi,
18
- FunctionReference,
19
- } from "convex/server";
20
- import { anyApi, componentsGeneric } from "convex/server";
21
-
22
- const fullApi: ApiFromModules<{
23
- http: typeof http;
24
- lib: typeof lib;
25
- serving: typeof serving;
26
- }> = anyApi as any;
27
-
28
- /**
29
- * A utility for referencing Convex functions in your app's public API.
30
- *
31
- * Usage:
32
- * ```js
33
- * const myFunctionReference = api.myModule.myFunction;
34
- * ```
35
- */
36
- export const api: FilterApi<
37
- typeof fullApi,
38
- FunctionReference<any, "public">
39
- > = anyApi as any;
40
-
41
- /**
42
- * A utility for referencing Convex functions in your app's internal API.
43
- *
44
- * Usage:
45
- * ```js
46
- * const myFunctionReference = internal.myModule.myFunction;
47
- * ```
48
- */
49
- export const internal: FilterApi<
50
- typeof fullApi,
51
- FunctionReference<any, "internal">
52
- > = anyApi as any;
53
-
54
- export const components = componentsGeneric() as unknown as {};
@@ -1,55 +0,0 @@
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
- getCurrentDeployment: FunctionReference<
28
- "query",
29
- "internal",
30
- {},
31
- {
32
- _creationTime: number;
33
- _id: string;
34
- currentDeploymentId: string;
35
- deployedAt: number;
36
- pendingBlobCleanupCount?: number;
37
- spaFallback?: boolean;
38
- } | null,
39
- Name
40
- >;
41
- resolveAssetForHttp: FunctionReference<
42
- "query",
43
- "internal",
44
- { path: string; spaFallback?: boolean },
45
- {
46
- appStorageId?: string;
47
- blobId?: string;
48
- contentType: string;
49
- etag?: string;
50
- storageUrl?: string;
51
- } | null,
52
- Name
53
- >;
54
- };
55
- };
@@ -1,60 +0,0 @@
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>;
@@ -1,156 +0,0 @@
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
- /**
111
- * A set of services for use within Convex query functions.
112
- *
113
- * The query context is passed as the first argument to any Convex query
114
- * function run on the server.
115
- *
116
- * If you're using code generation, use the `QueryCtx` type in `convex/_generated/server.d.ts` instead.
117
- */
118
- export type QueryCtx = GenericQueryCtx<DataModel>;
119
-
120
- /**
121
- * A set of services for use within Convex mutation functions.
122
- *
123
- * The mutation context is passed as the first argument to any Convex mutation
124
- * function run on the server.
125
- *
126
- * If you're using code generation, use the `MutationCtx` type in `convex/_generated/server.d.ts` instead.
127
- */
128
- export type MutationCtx = GenericMutationCtx<DataModel>;
129
-
130
- /**
131
- * A set of services for use within Convex action functions.
132
- *
133
- * The action context is passed as the first argument to any Convex action
134
- * function run on the server.
135
- */
136
- export type ActionCtx = GenericActionCtx<DataModel>;
137
-
138
- /**
139
- * An interface to read from the database within Convex query functions.
140
- *
141
- * The two entry points are {@link DatabaseReader.get}, which fetches a single
142
- * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
143
- * building a query.
144
- */
145
- export type DatabaseReader = GenericDatabaseReader<DataModel>;
146
-
147
- /**
148
- * An interface to read from and write to the database within Convex mutation
149
- * functions.
150
- *
151
- * Convex guarantees that all writes within a single mutation are
152
- * executed atomically, so you never have to worry about partial writes leaving
153
- * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
154
- * for the guarantees Convex provides your functions.
155
- */
156
- export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
@@ -1,3 +0,0 @@
1
- import { defineComponent } from "convex/server";
2
-
3
- export default defineComponent("hosting");