Skip to content

Commit afdbeb4

Browse files
committed
component api
1 parent 29969fa commit afdbeb4

File tree

14 files changed

+532
-405
lines changed

14 files changed

+532
-405
lines changed

.cursor/rules/convex_rules.mdc

Lines changed: 195 additions & 179 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ node_modules
1414
react/package.json
1515
# npm pack output
1616
*.tgz
17+
*.tsbuildinfo

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: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,81 @@
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",
11-
"example/eslint.config.js",
12+
"vitest.config.ts",
1213
"**/_generated/",
1314
"node10stubs.mjs",
1415
],
1516
},
1617
{
18+
files: ["src/**/*.{js,mjs,cjs,ts,tsx}", "example/**/*.{js,mjs,cjs,ts,tsx}"],
1719
languageOptions: {
18-
globals: globals.worker,
1920
parser: tseslint.parser,
20-
2121
parserOptions: {
22-
project: ["./tsconfig.json", "./example/tsconfig.json"],
23-
tsconfigRootDir: ".",
22+
project: [
23+
"./tsconfig.json",
24+
"./example/tsconfig.json",
25+
"./example/convex/tsconfig.json",
26+
],
27+
tsconfigRootDir: import.meta.dirname,
2428
},
2529
},
2630
},
2731
pluginJs.configs.recommended,
2832
...tseslint.configs.recommended,
33+
// Convex code - Worker environment
2934
{
35+
files: ["src/**/*.{ts,tsx}", "example/convex/**/*.{ts,tsx}"],
36+
ignores: ["src/react/**"],
37+
languageOptions: {
38+
globals: globals.worker,
39+
},
3040
rules: {
3141
"@typescript-eslint/no-floating-promises": "error",
32-
"@typescript-eslint/consistent-type-imports": [
42+
"@typescript-eslint/no-explicit-any": "off",
43+
"no-unused-vars": "off",
44+
"@typescript-eslint/no-unused-vars": [
45+
"warn",
46+
{
47+
argsIgnorePattern: "^_",
48+
varsIgnorePattern: "^_",
49+
},
50+
],
51+
"@typescript-eslint/no-unused-expressions": [
3352
"error",
3453
{
35-
prefer: "type-imports",
36-
fixStyle: "separate-type-imports",
37-
disallowTypeAnnotations: false,
54+
allowShortCircuit: true,
55+
allowTernary: true,
56+
allowTaggedTemplates: true,
3857
},
3958
],
40-
"eslint-comments/no-unused-disable": "off",
41-
42-
// allow (_arg: number) => {} and const _foo = 1;
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",
4379
"no-unused-vars": "off",
4480
"@typescript-eslint/no-unused-vars": [
4581
"warn",
@@ -50,4 +86,14 @@ export default [
5086
],
5187
},
5288
},
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+
},
97+
},
98+
},
5399
];

example/convex/_generated/api.d.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,35 @@ import type {
1818
FunctionReference,
1919
} from "convex/server";
2020

21+
declare const fullApi: ApiFromModules<{
22+
crons: typeof crons;
23+
example: typeof example;
24+
http: typeof http;
25+
}>;
26+
2127
/**
22-
* A utility for referencing Convex functions in your app's API.
28+
* A utility for referencing Convex functions in your app's public API.
2329
*
2430
* Usage:
2531
* ```js
2632
* const myFunctionReference = api.myModule.myFunction;
2733
* ```
2834
*/
29-
declare const fullApi: ApiFromModules<{
30-
crons: typeof crons;
31-
example: typeof example;
32-
http: typeof http;
33-
}>;
34-
declare const fullApiWithMounts: typeof fullApi;
35-
3635
export declare const api: FilterApi<
37-
typeof fullApiWithMounts,
36+
typeof fullApi,
3837
FunctionReference<any, "public">
3938
>;
39+
40+
/**
41+
* A utility for referencing Convex functions in your app's internal API.
42+
*
43+
* Usage:
44+
* ```js
45+
* const myFunctionReference = internal.myModule.myFunction;
46+
* ```
47+
*/
4048
export declare const internal: FilterApi<
41-
typeof fullApiWithMounts,
49+
typeof fullApi,
4250
FunctionReference<any, "internal">
4351
>;
4452

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 & 28 deletions
This file was deleted.

example/tsconfig.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"module": "ESNext",
1010
"moduleResolution": "Bundler",
1111
"resolveJsonModule": true,
12+
"exactOptionalPropertyTypes": true,
1213
"isolatedModules": true,
13-
"allowImportingTsExtensions": true,
14-
"noEmit": true,
15-
"jsx": "react-jsx"
14+
"jsx": "react-jsx",
15+
"noEmit": true
1616
},
17-
"include": ["./src", "vite.config.ts", "./convex"]
17+
"include": ["./src", "vite.config.ts"]
1818
}

package-lock.json

Lines changed: 17 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,51 +15,58 @@
1515
],
1616
"type": "module",
1717
"scripts": {
18-
"example": "cd example && npm run dev",
19-
"dev": "run-p -r 'example' 'build:watch'",
20-
"dashboard": "cd example && npx convex dashboard",
21-
"all": "run-p -r 'example' 'build:watch' 'test:watch'",
22-
"setup": "npm i && npm run build && cd example && npm i && npx convex dev --once --live-component-sources --typecheck-components",
23-
"build:watch": "npx chokidar 'tsconfig*.json' 'src/**/*.ts' -c 'npm run build' --initial",
24-
"build": "tsc --project ./tsconfig.build.json && tsc-alias -p tsconfig.build.json",
25-
"alpha": "npm run clean && npm run build && run-p test lint typecheck && npm version prerelease --preid alpha && npm publish --tag alpha && git push --tags",
26-
"release": "npm run clean && npm run build && run-p test lint typecheck && npm version patch && npm publish && git push --tags",
27-
"clean": "rm -rf dist tsconfig.build.tsbuildinfo",
28-
"typecheck": "tsc --noEmit",
29-
"prepare": "npm run build",
30-
"prepack": "node node10stubs.mjs",
31-
"postpack": "node node10stubs.mjs --cleanup",
32-
"test": "vitest run --typecheck --config ./src/vitest.config.ts",
33-
"test:watch": "vitest --typecheck --config ./src/vitest.config.ts",
34-
"test:debug": "vitest --inspect-brk --no-file-parallelism --config ./src/vitest.config.ts",
18+
"dev": "run-p -r 'dev:*'",
19+
"dev:backend": "convex dev --typecheck-components",
20+
"dev:frontend": "cd example && vite --clearScreen false",
21+
"dev:build": "npx chokidar 'tsconfig*.json' 'src/**/*.ts' -i '**/*.test.ts' -c 'npx convex codegen --component ./src/component && npm run build' --initial",
22+
"predev": "npm run dev:backend -- --until-success",
23+
"clean": "rm -rf dist *.tsbuildinfo",
24+
"build": "tsc --project ./tsconfig.build.json",
25+
"typecheck": "tsc --noEmit && tsc -p example && tsc -p example/convex",
26+
"lint": "eslint src && eslint example",
27+
"all": "run-p -r 'dev:*' 'test:watch'",
28+
"test": "vitest run --typecheck",
29+
"test:watch": "vitest --typecheck --clearScreen false",
30+
"test:debug": "vitest --inspect-brk --no-file-parallelism",
3531
"test:coverage": "vitest run --coverage --coverage.reporter=text",
36-
"lint": "eslint src"
32+
"attw": "attw $(npm pack -s) --exclude-entrypoints ./convex.config --profile esm-only",
33+
"prepare": "npm run build",
34+
"alpha": "npm run clean && npm ci && run-p test lint typecheck attw && npm version prerelease --preid alpha && npm publish --tag alpha && git push --tags",
35+
"release": "npm run clean && npm ci && run-p test lint typecheck attw && npm version patch && npm publish && git push --tags",
36+
"version": "pbcopy <<<$npm_package_version; vim CHANGELOG.md && prettier -w CHANGELOG.md && git add CHANGELOG.md"
3737
},
3838
"files": [
3939
"dist",
40-
"src",
41-
"react"
40+
"src"
4241
],
4342
"exports": {
4443
"./package.json": "./package.json",
4544
".": {
4645
"types": "./dist/client/index.d.ts",
4746
"default": "./dist/client/index.js"
4847
},
48+
"./react": {
49+
"types": "./dist/react/index.d.ts",
50+
"default": "./dist/react/index.js"
51+
},
52+
"./test": "./src/test.ts",
53+
"./_generated/component.js": {
54+
"types": "./dist/component/_generated/component.d.ts"
55+
},
4956
"./convex.config": {
5057
"types": "./dist/component/convex.config.d.ts",
5158
"default": "./dist/component/convex.config.js"
5259
}
5360
},
5461
"peerDependencies": {
55-
"convex": "^1.23.0",
62+
"convex": "^1.24.8",
5663
"convex-helpers": "^0.1.99"
5764
},
5865
"devDependencies": {
5966
"@edge-runtime/vm": "^5.0.0",
6067
"@eslint/eslintrc": "^3.3.1",
6168
"@eslint/js": "^9.38.0",
62-
"@types/node": "^22.18.13",
69+
"@types/node": "20.19.24",
6370
"chokidar-cli": "^3.0.0",
6471
"convex": "1.25.4",
6572
"convex-test": "^0.0.33",
@@ -76,7 +83,6 @@
7683
"typescript-eslint": "^8.46.2",
7784
"vitest": "^3.2.4"
7885
},
79-
"main": "./dist/client/index.js",
8086
"types": "./dist/client/index.d.ts",
8187
"module": "./dist/client/index.js",
8288
"dependencies": {

0 commit comments

Comments
 (0)