Skip to content
Merged
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
75 changes: 41 additions & 34 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,8 @@
"vitest": "4.1.4"
},
"types": "./dist/client/index.d.ts",
"module": "./dist/client/index.js"
"module": "./dist/client/index.js",
"dependencies": {
"convex-helpers": "^0.1.119"
}
}
2 changes: 2 additions & 0 deletions src/component/_generated/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @module
*/

import type * as functions from "../functions.js";
import type * as future from "../future.js";
import type * as kick from "../kick.js";
import type * as lib from "../lib.js";
Expand All @@ -24,6 +25,7 @@ import type {
import { anyApi, componentsGeneric } from "convex/server";

const fullApi: ApiFromModules<{
functions: typeof functions;
future: typeof future;
kick: typeof kick;
lib: typeof lib;
Expand Down
36 changes: 36 additions & 0 deletions src/component/functions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
customCtx,
customMutation,
customQuery,
} from "convex-helpers/server/customFunctions";
import {
env,
internalMutation as baseInternalMutation,
internalQuery as baseInternalQuery,
mutation as baseMutation,
query as baseQuery,
type MutationCtx as BaseMutationCtx,
type QueryCtx as BaseQueryCtx,
} from "./_generated/server.js";
import { createLogger, type Logger } from "./logging.js";

/**
* Function builders that read `LOG_LEVEL` from env once at the start of each
* call and expose a level-aware logger as `ctx.log`. Use these in place of the
* raw `_generated/server` builders so handlers (and the helpers they call) can
* just reach for `ctx.log.debug(...)` instead of constructing their own logger.
*/
const withLogger = customCtx(() => ({ log: createLogger(env.LOG_LEVEL) }));

export const query = customQuery(baseQuery, withLogger);
export const internalQuery = customQuery(baseInternalQuery, withLogger);
export const mutation = customMutation(baseMutation, withLogger);
export const internalMutation = customMutation(baseInternalMutation, withLogger);

/**
* Ctx types for this component's functions: the generated ctx augmented with
* the `log` logger injected by the builders above. Import these (not the
* `_generated/server` ones) everywhere so every handler and helper has `ctx.log`.
*/
export type QueryCtx = BaseQueryCtx & { log: Logger };
export type MutationCtx = BaseMutationCtx & { log: Logger };
Loading
Loading