Skip to content

Commit 88758be

Browse files
committed
component api
1 parent 50d5db5 commit 88758be

File tree

18 files changed

+315
-312
lines changed

18 files changed

+315
-312
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ node_modules
1212

1313
# npm pack output
1414
*.tgz
15+
*.tsbuildinfo

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const response = await fetch(url);
2929
- [Create a Cloudflare account](https://cloudflare.com)
3030
- [Create an R2 bucket](https://developers.cloudflare.com/r2/buckets/create-buckets/)
3131
- Set the bucket name as an environment variable `R2_BUCKET` in your Convex
32-
deployment
32+
deployment via `npx convex env set R2_BUCKET <bucket-name>`.
3333
- [Add a CORS policy](https://developers.cloudflare.com/r2/buckets/cors/#add-cors-policies-from-the-dashboard) to the bucket allowing GET and PUT requests from your
3434
Convex app. You can also use '\*' to allow all origins (use with caution).
3535
```json
@@ -117,12 +117,12 @@ File uploads to R2 typically use signed urls. The R2 component provides hooks fo
117117
// const user = await userFromAuth(ctx);
118118
// ...validate that the user can upload to this bucket
119119
},
120-
onUpload: async (ctx, bucket, key) => {
121-
// ...do something with the key
122-
// This technically runs in the `syncMetadata` mutation, as the upload
123-
// is performed from the client side. Will run if using the `useUploadFile`
124-
// hook, or if `syncMetadata` function is called directly. Runs after the
125-
// `checkUpload` callback.
120+
onUpload: async (ctx, bucket, key) => {
121+
// ...do something with the key
122+
// This technically runs in the `syncMetadata` mutation, as the upload
123+
// is performed from the client side. Will run if using the `useUploadFile`
124+
// hook, or if `syncMetadata` function is called directly. Runs after the
125+
// `checkUpload` callback.
126126
},
127127
});
128128
```

commonjs.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

convex.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "./node_modules/convex/schemas/convex.schema.json",
3+
"functions": "example/convex"
4+
}

eslint.config.js

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,45 @@
11
import globals from "globals";
22
import pluginJs from "@eslint/js";
33
import tseslint from "typescript-eslint";
4+
import reactHooks from "eslint-plugin-react-hooks";
5+
import reactRefresh from "eslint-plugin-react-refresh";
46

57
export default [
6-
{ files: ["src/**/*.{js,mjs,cjs,ts,tsx}"] },
78
{
89
ignores: [
910
"dist/**",
1011
"eslint.config.js",
12+
"vitest.config.ts",
1113
"**/_generated/",
1214
"node10stubs.mjs",
1315
],
1416
},
1517
{
18+
files: ["src/**/*.{js,mjs,cjs,ts,tsx}", "example/**/*.{js,mjs,cjs,ts,tsx}"],
1619
languageOptions: {
17-
globals: globals.worker,
1820
parser: tseslint.parser,
19-
2021
parserOptions: {
21-
project: true,
22-
tsconfigRootDir: ".",
22+
project: [
23+
"./tsconfig.json",
24+
"./example/tsconfig.json",
25+
"./example/convex/tsconfig.json",
26+
],
27+
tsconfigRootDir: import.meta.dirname,
2328
},
2429
},
2530
},
2631
pluginJs.configs.recommended,
2732
...tseslint.configs.recommended,
33+
// Convex code - Worker environment
2834
{
35+
files: ["src/**/*.{ts,tsx}", "example/convex/**/*.{ts,tsx}"],
36+
ignores: ["src/react/**"],
37+
languageOptions: {
38+
globals: globals.worker,
39+
},
2940
rules: {
3041
"@typescript-eslint/no-floating-promises": "error",
31-
"eslint-comments/no-unused-disable": "off",
32-
33-
// allow (_arg: number) => {} and const _foo = 1;
42+
"@typescript-eslint/no-explicit-any": "off",
3443
"no-unused-vars": "off",
3544
"@typescript-eslint/no-unused-vars": [
3645
"warn",
@@ -39,6 +48,52 @@ export default [
3948
varsIgnorePattern: "^_",
4049
},
4150
],
51+
"@typescript-eslint/no-unused-expressions": [
52+
"error",
53+
{
54+
allowShortCircuit: true,
55+
allowTernary: true,
56+
allowTaggedTemplates: true,
57+
},
58+
],
59+
},
60+
},
61+
// React app code - Browser environment
62+
{
63+
files: ["src/react/**/*.{ts,tsx}", "example/src/**/*.{ts,tsx}"],
64+
languageOptions: {
65+
ecmaVersion: 2020,
66+
globals: globals.browser,
67+
},
68+
plugins: {
69+
"react-hooks": reactHooks,
70+
"react-refresh": reactRefresh,
71+
},
72+
rules: {
73+
...reactHooks.configs.recommended.rules,
74+
"react-refresh/only-export-components": [
75+
"warn",
76+
{ allowConstantExport: true },
77+
],
78+
"@typescript-eslint/no-explicit-any": "off",
79+
"no-unused-vars": "off",
80+
"@typescript-eslint/no-unused-vars": [
81+
"warn",
82+
{
83+
argsIgnorePattern: "^_",
84+
varsIgnorePattern: "^_",
85+
},
86+
],
87+
},
88+
},
89+
// Example config files (vite.config.ts, etc.) - Node environment
90+
{
91+
files: ["example/vite.config.ts", "example/**/*.config.{js,ts}"],
92+
languageOptions: {
93+
globals: {
94+
...globals.node,
95+
...globals.browser,
96+
},
4297
},
4398
},
4499
];

esm.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

example/convex/_generated/api.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
FilterApi,
1616
FunctionReference,
1717
} from "convex/server";
18+
1819
/**
1920
* A utility for referencing Convex functions in your app's API.
2021
*
@@ -26,14 +27,13 @@ import type {
2627
declare const fullApi: ApiFromModules<{
2728
example: typeof example;
2829
}>;
29-
declare const fullApiWithMounts: typeof fullApi;
3030

3131
export declare const api: FilterApi<
32-
typeof fullApiWithMounts,
32+
typeof fullApi,
3333
FunctionReference<any, "public">
3434
>;
3535
export declare const internal: FilterApi<
36-
typeof fullApiWithMounts,
36+
typeof fullApi,
3737
FunctionReference<any, "internal">
3838
>;
3939

example/convex/tsconfig.json

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,19 @@
11
{
2-
/* This TypeScript project config describes the environment that
3-
* Convex functions run in and is used to typecheck them.
4-
* You can modify it, but some settings required to use Convex.
5-
*/
62
"compilerOptions": {
7-
/* These settings are not required by Convex and can be modified. */
83
"allowJs": true,
94
"strict": true,
105
"skipLibCheck": true,
11-
12-
/* These compiler options are required by Convex */
136
"target": "ESNext",
14-
"lib": ["ES2021", "dom", "ESNext.Array"],
7+
"lib": ["ES2021", "dom", "DOM.Iterable", "ESNext.Array"],
158
"forceConsistentCasingInFileNames": true,
169
"allowSyntheticDefaultImports": true,
10+
"verbatimModuleSyntax": true,
1711
"module": "ESNext",
1812
"moduleResolution": "Bundler",
1913
"isolatedModules": true,
2014
"noEmit": true,
21-
22-
/* This should only be used in this example. Real apps should not attempt
23-
* to compile TypeScript because differences between tsconfig.json files can
24-
* cause the code to be compiled differently.
25-
*/
26-
"customConditions": ["@convex-dev/component-source"]
15+
"jsx": "react-jsx"
2716
},
28-
"include": ["./**/*"],
17+
"include": [".*"],
2918
"exclude": ["./_generated"]
3019
}

example/eslint.config.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

example/tsconfig.json

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,13 @@
99
"module": "ESNext",
1010
"moduleResolution": "Bundler",
1111
"resolveJsonModule": true,
12+
"exactOptionalPropertyTypes": true,
1213
"isolatedModules": true,
13-
"allowImportingTsExtensions": true,
14-
"noEmit": true,
1514
"jsx": "react-jsx",
16-
17-
/* Import paths */
1815
"paths": {
1916
"@/*": ["./src/*"]
2017
},
21-
22-
/* This should only be used in this example. Real apps should not attempt
23-
* to compile TypeScript because differences between tsconfig.json files can
24-
* cause the code to be compiled differently.
25-
*/
26-
"customConditions": ["@convex-dev/component-source"]
18+
"noEmit": true
2719
},
2820
"include": ["./src", "vite.config.ts"]
2921
}

0 commit comments

Comments
 (0)