better-convex 0.6.3 → 0.7.0

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 (47) hide show
  1. package/dist/aggregate/index.d.ts +388 -0
  2. package/dist/aggregate/index.js +37 -0
  3. package/dist/{auth-client → auth/client}/index.js +1 -1
  4. package/dist/auth/http/index.d.ts +63 -0
  5. package/dist/auth/http/index.js +429 -0
  6. package/dist/auth/index.d.ts +19001 -185
  7. package/dist/auth/index.js +373 -686
  8. package/dist/{auth-nextjs → auth/nextjs}/index.d.ts +3 -4
  9. package/dist/{auth-nextjs → auth/nextjs}/index.js +3 -5
  10. package/dist/{caller-factory-B1FvYSKr.js → caller-factory-Dmgv8MLS.js} +15 -12
  11. package/dist/cli.mjs +2601 -13
  12. package/dist/codegen-Cz1idI3-.mjs +969 -0
  13. package/dist/{create-schema-orm-DplxTtYj.js → create-schema-orm-69VF4CFV.js} +4 -3
  14. package/dist/crpc/index.d.ts +2 -2
  15. package/dist/crpc/index.js +3 -3
  16. package/dist/{http-types-BRLY10NX.d.ts → http-types-BCf2wCgp.d.ts} +25 -25
  17. package/dist/meta-utils-DDVYp9Xf.js +117 -0
  18. package/dist/orm/index.d.ts +4 -3012
  19. package/dist/orm/index.js +9631 -2
  20. package/dist/{index-BQkhP2ny.d.ts → procedure-caller-CcjtUFvL.d.ts} +211 -74
  21. package/dist/query-context-BDSis9rT.js +1518 -0
  22. package/dist/query-context-DGExXZIV.d.ts +42 -0
  23. package/dist/react/index.d.ts +31 -35
  24. package/dist/react/index.js +145 -58
  25. package/dist/rsc/index.d.ts +4 -7
  26. package/dist/rsc/index.js +14 -10
  27. package/dist/runtime-B9xQFY8W.js +2280 -0
  28. package/dist/server/index.d.ts +3 -4
  29. package/dist/server/index.js +384 -10
  30. package/dist/{types-o-5rYcTr.d.ts → types-CIBGEYXq.d.ts} +4 -3
  31. package/dist/types-DgwvxKbT.d.ts +4 -0
  32. package/dist/watcher.mjs +8 -8
  33. package/dist/where-clause-compiler-CRP-i1Qa.d.ts +3463 -0
  34. package/package.json +14 -10
  35. package/dist/codegen-DkpPBVPn.mjs +0 -189
  36. package/dist/context-utils-DSuX99Da.d.ts +0 -17
  37. package/dist/meta-utils-DCpLSBWB.js +0 -41
  38. package/dist/orm-CleikBIV.js +0 -8820
  39. /package/dist/{auth-client → auth/client}/index.d.ts +0 -0
  40. /package/dist/{auth-config → auth/config}/index.d.ts +0 -0
  41. /package/dist/{auth-config → auth/config}/index.js +0 -0
  42. /package/dist/{create-schema-DhWXOhnU.js → create-schema-BdZOL6ns.js} +0 -0
  43. /package/dist/{customFunctions-C1okqCzL.js → customFunctions-CZnCwoR3.js} +0 -0
  44. /package/dist/{error-BZUhlhYz.js → error-Be4OcwwD.js} +0 -0
  45. /package/dist/{query-options-BL1Q0X7q.js → query-options-B0c1b6pZ.js} +0 -0
  46. /package/dist/{transformer-CTNSPjwp.js → transformer-Dh0w2py0.js} +0 -0
  47. /package/dist/{types-jftzhhuc.d.ts → types-DwGkkq2s.d.ts} +0 -0
@@ -1,5 +1,6 @@
1
- import { g as LazyCaller, m as ConvexContext, v as CallerMeta } from "../index-BQkhP2ny.js";
2
- import "../http-types-BRLY10NX.js";
1
+ import { B as ConvexContext, H as LazyCaller } from "../../procedure-caller-CcjtUFvL.js";
2
+ import "../../http-types-BCf2wCgp.js";
3
+ import "../../server/index.js";
3
4
  import { GetTokenOptions } from "@convex-dev/better-auth/utils";
4
5
 
5
6
  //#region src/auth-nextjs/index.d.ts
@@ -13,7 +14,6 @@ type ConvexBetterAuthOptions<TApi> = Omit<GetTokenOptions, 'jwtCache'> & {
13
14
  api: TApi;
14
15
  convexSiteUrl: string; /** Auth options. JWT caching is enabled by default (set `auth.jwtCache: false` to disable). */
15
16
  auth?: AuthOptions;
16
- meta: CallerMeta;
17
17
  };
18
18
  /**
19
19
  * Create Convex caller factory with Better Auth integration for Next.js.
@@ -24,7 +24,6 @@ type ConvexBetterAuthOptions<TApi> = Omit<GetTokenOptions, 'jwtCache'> & {
24
24
  * export const { createContext, createCaller, handler } = convexBetterAuth({
25
25
  * api,
26
26
  * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
27
- * meta,
28
27
  * }); // JWT caching enabled by default
29
28
  *
30
29
  * // rsc.tsx
@@ -1,5 +1,5 @@
1
- import { n as defaultIsUnauthorized } from "../error-BZUhlhYz.js";
2
- import { t as createCallerFactory } from "../caller-factory-B1FvYSKr.js";
1
+ import { n as defaultIsUnauthorized } from "../../error-Be4OcwwD.js";
2
+ import { t as createCallerFactory } from "../../caller-factory-Dmgv8MLS.js";
3
3
  import { getToken } from "@convex-dev/better-auth/utils";
4
4
 
5
5
  //#region src/auth-nextjs/index.ts
@@ -32,7 +32,6 @@ const nextJsHandler = (siteUrl) => ({
32
32
  * export const { createContext, createCaller, handler } = convexBetterAuth({
33
33
  * api,
34
34
  * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
35
- * meta,
36
35
  * }); // JWT caching enabled by default
37
36
  *
38
37
  * // rsc.tsx
@@ -62,8 +61,7 @@ function convexBetterAuth(opts) {
62
61
  }
63
62
  }),
64
63
  isUnauthorized: auth.isUnauthorized ?? defaultIsUnauthorized
65
- } : void 0,
66
- meta: opts.meta
64
+ } : void 0
67
65
  });
68
66
  return {
69
67
  createContext,
@@ -1,5 +1,5 @@
1
- import { s as getTransformer } from "./transformer-CTNSPjwp.js";
2
- import { r as getFunctionType, t as getFuncRef$1 } from "./meta-utils-DCpLSBWB.js";
1
+ import { i as getFunctionType, n as getFuncRef, t as buildMetaIndex } from "./meta-utils-DDVYp9Xf.js";
2
+ import { s as getTransformer } from "./transformer-Dh0w2py0.js";
3
3
  import { fetchAction, fetchMutation, fetchQuery } from "convex/nextjs";
4
4
 
5
5
  //#region src/server/caller.ts
@@ -11,7 +11,7 @@ function createRecursiveProxy(api, path, createOpts) {
11
11
  return createRecursiveProxy(api, [...path, prop], createOpts);
12
12
  },
13
13
  apply(_target, _thisArg, argsList) {
14
- const funcRef = getFuncRef$1(api, path);
14
+ const funcRef = getFuncRef(api, path);
15
15
  const args = createOpts.transformer.input.serialize(argsList[0] ?? {});
16
16
  const callerOpts = argsList[1];
17
17
  const fnType = getFunctionType(path, createOpts.meta);
@@ -49,12 +49,10 @@ function createServerCaller(api, opts) {
49
49
 
50
50
  //#endregion
51
51
  //#region src/server/lazy-caller.ts
52
- function getFuncRef(api, path) {
53
- let current = api;
54
- for (const key of path) if (current && typeof current === "object") current = current[key];
55
- else throw new Error(`Invalid caller path: ${path.join(".")}`);
56
- return current;
57
- }
52
+ /**
53
+ * Lazy caller that creates context on each procedure invocation.
54
+ * Matches tRPC's appRouter.createCaller(createTRPCContext) pattern.
55
+ */
58
56
  function traverseCaller(caller, path) {
59
57
  let target = caller;
60
58
  for (const key of path) target = target[key];
@@ -77,7 +75,12 @@ function createRecursiveProxyWithLazyContext(api, path, createContext) {
77
75
  return createRecursiveProxyWithLazyContext(api, [...path, prop], createContext);
78
76
  },
79
77
  async apply(_target, _thisArg, argsList) {
80
- getFuncRef(api, path);
78
+ try {
79
+ getFuncRef(api, path);
80
+ } catch (error) {
81
+ const displayPath = path.length > 0 ? path.join(".") : "<root>";
82
+ throw new Error(`Invalid caller path: ${displayPath}`, { cause: error });
83
+ }
81
84
  return traverseCaller((await createContext()).caller, path)(argsList[0] ?? {}, argsList[1]);
82
85
  }
83
86
  });
@@ -128,7 +131,6 @@ const parseConvexSiteUrl = (url) => {
128
131
  * api,
129
132
  * convexSiteUrl: env.NEXT_PUBLIC_CONVEX_SITE_URL,
130
133
  * auth: { getToken },
131
- * meta,
132
134
  * });
133
135
  * ```
134
136
  */
@@ -137,6 +139,7 @@ function createCallerFactory(opts) {
137
139
  const siteUrl = parseConvexSiteUrl(opts.convexSiteUrl);
138
140
  const getToken = opts.auth?.getToken ?? noAuthGetToken;
139
141
  const isUnauthorized = opts.auth?.isUnauthorized;
142
+ const crpcMeta = buildMetaIndex(opts.api);
140
143
  const callWithTokenAndRetry = async (fn, tokenResult, headers) => {
141
144
  try {
142
145
  return await fn(tokenResult.token);
@@ -185,7 +188,7 @@ function createCallerFactory(opts) {
185
188
  fetchQuery: fetchAuthQuery,
186
189
  fetchMutation: fetchAuthMutation,
187
190
  fetchAction: fetchAuthAction,
188
- meta: opts.meta,
191
+ meta: crpcMeta,
189
192
  transformer: opts.transformer
190
193
  })
191
194
  };