Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion template-component/convex.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"functions": "example/convex"
"$schema": "https://raw.githubusercontent.com/get-convex/convex-backend/refs/heads/main/npm-packages/convex/schemas/convex.schema.json",
"functions": "example/convex",
"codegen": {
"staticApi": true
}
}
38 changes: 18 additions & 20 deletions template-component/example/convex/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,33 @@
* @module
*/

import type * as example from "../example.js";

import type {
ApiFromModules,
FilterApi,
FunctionReference,
} from "convex/server";
import type { FunctionReference } from "convex/server";

/**
* A utility for referencing Convex functions in your app's API.
* A utility for referencing Convex functions in your app's public API.
*
* Usage:
* ```js
* const myFunctionReference = api.myModule.myFunction;
* ```
*/
declare const fullApi: ApiFromModules<{
example: typeof example;
}>;
declare const fullApiWithMounts: typeof fullApi;
export declare const api: {
example: {
addOne: FunctionReference<"mutation", "public", {}, any>;
add: FunctionReference<"mutation", "public", { name: string }, any>;
count: FunctionReference<"query", "public", { name: string }, any>;
};
};

export declare const api: FilterApi<
typeof fullApiWithMounts,
FunctionReference<any, "public">
>;
export declare const internal: FilterApi<
typeof fullApiWithMounts,
FunctionReference<any, "internal">
>;
/**
* A utility for referencing Convex functions in your app's internal API.
*
* Usage:
* ```js
* const myFunctionReference = internal.myModule.myFunction;
* ```
*/
export declare const internal: {};

export declare const components: {
shardedCounter: {
Expand Down
4 changes: 2 additions & 2 deletions template-component/src/client/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { mutationGeneric, queryGeneric } from "convex/server";
import { v } from "convex/values";
import type { Mounts } from "../component/_generated/api.js";
import type { api } from "../component/_generated/api.js";
import type { UseApi, RunMutationCtx, RunQueryCtx } from "./types.js";

// UseApi<typeof api> is an alternative that has jump-to-definition but is
// less stable and reliant on types within the component files, which can cause
// issues where passing `components.foo` doesn't match the argument
export type ShardedCounterComponent = UseApi<Mounts>;
export type ShardedCounterComponent = UseApi<typeof api>;

export class ShardedCounter<Shards extends Record<string, number>> {
constructor(
Expand Down
36 changes: 12 additions & 24 deletions template-component/src/component/_generated/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,17 @@
* @module
*/

import type * as lib from "../lib.js";

import type {
ApiFromModules,
FilterApi,
FunctionReference,
} from "convex/server";
import type { FunctionReference } from "convex/server";

/**
* A utility for referencing Convex functions in your app's API.
* A utility for referencing Convex functions in your app's public API.
*
* Usage:
* ```js
* const myFunctionReference = api.myModule.myFunction;
* ```
*/
declare const fullApi: ApiFromModules<{
lib: typeof lib;
}>;
export type Mounts = {
export declare const api: {
lib: {
add: FunctionReference<
"mutation",
Expand All @@ -38,18 +29,15 @@ export type Mounts = {
count: FunctionReference<"query", "public", { name: string }, number>;
};
};
// For now fullApiWithMounts is only fullApi which provides
// jump-to-definition in component client code.
// Use Mounts for the same type without the inference.
declare const fullApiWithMounts: typeof fullApi;

export declare const api: FilterApi<
typeof fullApiWithMounts,
FunctionReference<any, "public">
>;
export declare const internal: FilterApi<
typeof fullApiWithMounts,
FunctionReference<any, "internal">
>;
/**
* A utility for referencing Convex functions in your app's internal API.
*
* Usage:
* ```js
* const myFunctionReference = internal.myModule.myFunction;
* ```
*/
export declare const internal: {};

export declare const components: {};