better-convex 0.9.1 → 0.10.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.
- package/dist/aggregate/index.d.ts +4 -1
- package/dist/auth/index.d.ts +12 -11
- package/dist/auth/index.js +27 -18
- package/dist/auth/nextjs/index.d.ts +5 -3
- package/dist/auth/nextjs/index.js +5 -4
- package/dist/{caller-factory-CCsm4Dut.js → caller-factory-C1uAqm5w.js} +20 -11
- package/dist/crpc/index.d.ts +34 -5
- package/dist/crpc/index.js +142 -1
- package/dist/orm/index.d.ts +1 -1
- package/dist/orm/index.js +8 -1
- package/dist/plugins/index.d.ts +4 -4
- package/dist/plugins/ratelimit/index.d.ts +4 -1
- package/dist/{procedure-caller-DYjpq7rG.d.ts → procedure-caller-kZJx_hmP.d.ts} +7 -2
- package/dist/react/index.d.ts +48 -59
- package/dist/react/index.js +119 -101
- package/dist/rsc/index.d.ts +99 -22
- package/dist/rsc/index.js +1 -1
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +1 -1
- package/dist/solid/index.d.ts +1221 -0
- package/dist/solid/index.js +2930 -0
- package/dist/types-7bF_8IjP.d.ts +213 -0
- package/dist/{where-clause-compiler-UavDdMUX.d.ts → where-clause-compiler-DjFwXrQn.d.ts} +4 -1
- package/package.json +15 -1
- package/dist/types-f53SgpBL.d.ts +0 -221
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../validators-BcQFm1oY.js";
|
|
2
|
+
import { Jn as ConvexTextBuilderInitial, Ot as ConvexCustomBuilderInitial, in as ConvexTableWithColumns, vt as ConvexNumberBuilderInitial, xt as ConvexIdBuilderInitial } from "../where-clause-compiler-DjFwXrQn.js";
|
|
3
|
+
import "../query-context-ji7By8u0.js";
|
|
4
|
+
import "../orm/index.js";
|
|
2
5
|
import * as convex_values0 from "convex/values";
|
|
3
6
|
import { GenericId, Infer, Value } from "convex/values";
|
|
4
7
|
import { DocumentByName, GenericDataModel, GenericDatabaseReader, GenericDatabaseWriter, TableNamesInDataModel } from "convex/server";
|
package/dist/auth/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import "../validators-BcQFm1oY.js";
|
|
1
2
|
import { a as QueryCtxWithPreferredOrmQueryTable, n as LookupByIdResultByCtx, t as DocByCtx } from "../query-context-ji7By8u0.js";
|
|
2
3
|
import { t as GetAuth } from "../types-CM67ko7K.js";
|
|
3
|
-
import { A as GenericCtx } from "../procedure-caller-
|
|
4
|
+
import { A as GenericCtx } from "../procedure-caller-kZJx_hmP.js";
|
|
4
5
|
import "../http-types-BK7FuIcR.js";
|
|
5
6
|
import "../server/index.js";
|
|
6
7
|
import * as convex_values0 from "convex/values";
|
|
@@ -196,8 +197,8 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
196
197
|
select?: string[] | undefined;
|
|
197
198
|
offset?: number | undefined;
|
|
198
199
|
sortBy?: {
|
|
199
|
-
direction: "asc" | "desc";
|
|
200
200
|
field: string;
|
|
201
|
+
direction: "asc" | "desc";
|
|
201
202
|
} | undefined;
|
|
202
203
|
where?: {
|
|
203
204
|
connector?: "AND" | "OR" | undefined;
|
|
@@ -212,12 +213,12 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
212
213
|
offset: convex_values0.VFloat64<number | undefined, "optional">;
|
|
213
214
|
select: convex_values0.VArray<string[] | undefined, convex_values0.VString<string, "required">, "optional">;
|
|
214
215
|
sortBy: convex_values0.VObject<{
|
|
215
|
-
direction: "asc" | "desc";
|
|
216
216
|
field: string;
|
|
217
|
+
direction: "asc" | "desc";
|
|
217
218
|
} | undefined, {
|
|
218
219
|
direction: convex_values0.VUnion<"asc" | "desc", [convex_values0.VLiteral<"asc", "required">, convex_values0.VLiteral<"desc", "required">], "required", never>;
|
|
219
220
|
field: convex_values0.VString<string, "required">;
|
|
220
|
-
}, "optional", "
|
|
221
|
+
}, "optional", "field" | "direction">;
|
|
221
222
|
where: convex_values0.VArray<{
|
|
222
223
|
connector?: "AND" | "OR" | undefined;
|
|
223
224
|
operator?: "in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined;
|
|
@@ -234,7 +235,7 @@ declare const adapterArgsValidator: convex_values0.VObject<{
|
|
|
234
235
|
operator: convex_values0.VUnion<"in" | "lt" | "lte" | "gt" | "gte" | "eq" | "not_in" | "ne" | "contains" | "starts_with" | "ends_with" | undefined, [convex_values0.VLiteral<"lt", "required">, convex_values0.VLiteral<"lte", "required">, convex_values0.VLiteral<"gt", "required">, convex_values0.VLiteral<"gte", "required">, convex_values0.VLiteral<"eq", "required">, convex_values0.VLiteral<"in", "required">, convex_values0.VLiteral<"not_in", "required">, convex_values0.VLiteral<"ne", "required">, convex_values0.VLiteral<"contains", "required">, convex_values0.VLiteral<"starts_with", "required">, convex_values0.VLiteral<"ends_with", "required">], "optional", never>;
|
|
235
236
|
value: convex_values0.VUnion<string | number | boolean | string[] | number[] | null, [convex_values0.VString<string, "required">, convex_values0.VFloat64<number, "required">, convex_values0.VBoolean<boolean, "required">, convex_values0.VArray<string[], convex_values0.VString<string, "required">, "required">, convex_values0.VArray<number[], convex_values0.VFloat64<number, "required">, "required">, convex_values0.VNull<null, "required">], "required", never>;
|
|
236
237
|
}, "required", "value" | "connector" | "field" | "operator">, "optional">;
|
|
237
|
-
}, "required", "limit" | "model" | "select" | "offset" | "sortBy" | "where" | "sortBy.
|
|
238
|
+
}, "required", "limit" | "model" | "select" | "offset" | "sortBy" | "where" | "sortBy.field" | "sortBy.direction">;
|
|
238
239
|
declare const hasUniqueFields: (betterAuthSchema: BetterAuthDBSchema, model: string, input: Record<string, any>) => boolean;
|
|
239
240
|
declare const checkUniqueFields: <Schema extends SchemaDefinition<any, any>>(ctx: GenericQueryCtx<GenericDataModel>, schema: Schema, betterAuthSchema: BetterAuthDBSchema, table: string, input: Record<string, any>, doc?: Record<string, any>) => Promise<void>;
|
|
240
241
|
declare const selectFields: <T extends TableNamesInDataModel<GenericDataModel>, D extends DocumentByName<GenericDataModel, T>>(doc: D | null, select?: string[]) => Promise<D | null>;
|
|
@@ -406,8 +407,8 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
406
407
|
join?: any;
|
|
407
408
|
offset?: number | undefined;
|
|
408
409
|
sortBy?: {
|
|
409
|
-
direction: "asc" | "desc";
|
|
410
410
|
field: string;
|
|
411
|
+
direction: "asc" | "desc";
|
|
411
412
|
} | undefined;
|
|
412
413
|
where?: {
|
|
413
414
|
connector?: "AND" | "OR" | undefined;
|
|
@@ -436,6 +437,8 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
436
437
|
}[] | undefined;
|
|
437
438
|
model: string;
|
|
438
439
|
}, Promise<convex_server0.GenericDocument | null>>;
|
|
440
|
+
getLatestJwks: convex_server0.RegisteredAction<"internal", {}, Promise<unknown>>;
|
|
441
|
+
rotateKeys: convex_server0.RegisteredAction<"internal", {}, Promise<unknown>>;
|
|
439
442
|
updateMany: convex_server0.RegisteredMutation<"internal", {
|
|
440
443
|
input: {
|
|
441
444
|
where?: {
|
|
@@ -491,8 +494,6 @@ declare const createApi: <Schema extends SchemaDefinition<any, any>, DataModel e
|
|
|
491
494
|
model: string;
|
|
492
495
|
};
|
|
493
496
|
}, Promise<any>>;
|
|
494
|
-
getLatestJwks: convex_server0.RegisteredAction<"internal", {}, Promise<unknown>>;
|
|
495
|
-
rotateKeys: convex_server0.RegisteredAction<"internal", {}, Promise<unknown>>;
|
|
496
497
|
};
|
|
497
498
|
//#endregion
|
|
498
499
|
//#region ../../node_modules/kysely/dist/esm/operation-node/operation-node.d.ts
|
|
@@ -19202,8 +19203,8 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19202
19203
|
join?: any;
|
|
19203
19204
|
offset?: number | undefined;
|
|
19204
19205
|
sortBy?: {
|
|
19205
|
-
direction: "asc" | "desc";
|
|
19206
19206
|
field: string;
|
|
19207
|
+
direction: "asc" | "desc";
|
|
19207
19208
|
} | undefined;
|
|
19208
19209
|
where?: {
|
|
19209
19210
|
connector?: "AND" | "OR" | undefined;
|
|
@@ -19232,6 +19233,8 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19232
19233
|
}[] | undefined;
|
|
19233
19234
|
model: string;
|
|
19234
19235
|
}, Promise<convex_server0.GenericDocument | null>>;
|
|
19236
|
+
getLatestJwks: convex_server0.RegisteredAction<"internal", {}, Promise<unknown>>;
|
|
19237
|
+
rotateKeys: convex_server0.RegisteredAction<"internal", {}, Promise<unknown>>;
|
|
19235
19238
|
updateMany: convex_server0.RegisteredMutation<"internal", {
|
|
19236
19239
|
input: {
|
|
19237
19240
|
where?: {
|
|
@@ -19287,8 +19290,6 @@ declare const createAuthRuntime: <DataModel extends GenericDataModel, Schema ext
|
|
|
19287
19290
|
model: string;
|
|
19288
19291
|
};
|
|
19289
19292
|
}, Promise<any>>;
|
|
19290
|
-
getLatestJwks: convex_server0.RegisteredAction<"internal", {}, Promise<unknown>>;
|
|
19291
|
-
rotateKeys: convex_server0.RegisteredAction<"internal", {}, Promise<unknown>>;
|
|
19292
19293
|
authEnabled: true;
|
|
19293
19294
|
authClient: {
|
|
19294
19295
|
authFunctions: AuthFunctions;
|
package/dist/auth/index.js
CHANGED
|
@@ -315,7 +315,7 @@ const resolveOrmTable = (ctx, schema, betterAuthSchema, model) => {
|
|
|
315
315
|
const tableName = resolveSchemaTableName(schema, betterAuthSchema, model);
|
|
316
316
|
if (!tableName) return;
|
|
317
317
|
const table = schema.tables[tableName];
|
|
318
|
-
if (!table
|
|
318
|
+
if (!table?._id) return;
|
|
319
319
|
return {
|
|
320
320
|
table,
|
|
321
321
|
tableName
|
|
@@ -409,10 +409,19 @@ const serializeDatesForConvex = (value) => {
|
|
|
409
409
|
return serialized ?? value;
|
|
410
410
|
};
|
|
411
411
|
const toConvexSafe = (value) => serializeDatesForConvex(value);
|
|
412
|
+
const withAuthTimestamps = (data) => {
|
|
413
|
+
if (data.createdAt !== void 0) return data;
|
|
414
|
+
const now = Date.now();
|
|
415
|
+
return {
|
|
416
|
+
...data,
|
|
417
|
+
createdAt: now,
|
|
418
|
+
...data.updatedAt === void 0 ? { updatedAt: now } : {}
|
|
419
|
+
};
|
|
420
|
+
};
|
|
412
421
|
const createHandler = async (ctx, args, schema, betterAuthSchema) => {
|
|
413
422
|
const triggerCtx = args.triggerCtx ?? ctx;
|
|
414
423
|
const tableTriggers = args.tableTriggers;
|
|
415
|
-
const data = serializeDatesForConvex(await applyBeforeHook(args.input.model, "create", args.input.data, tableTriggers?.create?.before, triggerCtx));
|
|
424
|
+
const data = serializeDatesForConvex(withAuthTimestamps(await applyBeforeHook(args.input.model, "create", args.input.data, tableTriggers?.create?.before, triggerCtx)));
|
|
416
425
|
await checkUniqueFields(ctx, schema, betterAuthSchema, args.input.model, data);
|
|
417
426
|
const ormTable = resolveOrmTable(ctx, schema, betterAuthSchema, args.input.model);
|
|
418
427
|
const doc = ormTable ? await ormInsert(ctx, ormTable.table, data) : await (async () => {
|
|
@@ -639,6 +648,7 @@ const createApi = (schema, getAuth, options) => {
|
|
|
639
648
|
}),
|
|
640
649
|
findMany: internalQueryGeneric({
|
|
641
650
|
args: {
|
|
651
|
+
join: v.optional(v.any()),
|
|
642
652
|
limit: v.optional(v.number()),
|
|
643
653
|
model: modelValidator,
|
|
644
654
|
offset: v.optional(v.number()),
|
|
@@ -647,20 +657,31 @@ const createApi = (schema, getAuth, options) => {
|
|
|
647
657
|
direction: v.union(v.literal("asc"), v.literal("desc")),
|
|
648
658
|
field: v.string()
|
|
649
659
|
})),
|
|
650
|
-
where: v.optional(v.array(adapterWhereValidator))
|
|
651
|
-
join: v.optional(v.any())
|
|
660
|
+
where: v.optional(v.array(adapterWhereValidator))
|
|
652
661
|
},
|
|
653
662
|
handler: async (ctx, args) => findManyHandler(ctx, args, schema, getBetterAuthSchema())
|
|
654
663
|
}),
|
|
655
664
|
findOne: internalQueryGeneric({
|
|
656
665
|
args: {
|
|
666
|
+
join: v.optional(v.any()),
|
|
657
667
|
model: modelValidator,
|
|
658
668
|
select: v.optional(v.array(v.string())),
|
|
659
|
-
where: v.optional(v.array(adapterWhereValidator))
|
|
660
|
-
join: v.optional(v.any())
|
|
669
|
+
where: v.optional(v.array(adapterWhereValidator))
|
|
661
670
|
},
|
|
662
671
|
handler: async (ctx, args) => findOneHandler(ctx, args, schema, getBetterAuthSchema())
|
|
663
672
|
}),
|
|
673
|
+
getLatestJwks: internalActionGeneric({
|
|
674
|
+
args: {},
|
|
675
|
+
handler: async (ctx) => {
|
|
676
|
+
return getAuth(ctx).api.getLatestJwks();
|
|
677
|
+
}
|
|
678
|
+
}),
|
|
679
|
+
rotateKeys: internalActionGeneric({
|
|
680
|
+
args: {},
|
|
681
|
+
handler: async (ctx) => {
|
|
682
|
+
return getAuth(ctx).api.rotateKeys();
|
|
683
|
+
}
|
|
684
|
+
}),
|
|
664
685
|
updateMany: mutationBuilder({
|
|
665
686
|
args: {
|
|
666
687
|
input: updateInput,
|
|
@@ -686,18 +707,6 @@ const createApi = (schema, getAuth, options) => {
|
|
|
686
707
|
triggerCtx
|
|
687
708
|
}, schema, getBetterAuthSchema());
|
|
688
709
|
}
|
|
689
|
-
}),
|
|
690
|
-
getLatestJwks: internalActionGeneric({
|
|
691
|
-
args: {},
|
|
692
|
-
handler: async (ctx) => {
|
|
693
|
-
return getAuth(ctx).api.getLatestJwks();
|
|
694
|
-
}
|
|
695
|
-
}),
|
|
696
|
-
rotateKeys: internalActionGeneric({
|
|
697
|
-
args: {},
|
|
698
|
-
handler: async (ctx) => {
|
|
699
|
-
return getAuth(ctx).api.rotateKeys();
|
|
700
|
-
}
|
|
701
710
|
})
|
|
702
711
|
};
|
|
703
712
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../validators-BcQFm1oY.js";
|
|
2
|
+
import { B as ConvexContext, H as LazyCaller } from "../../procedure-caller-kZJx_hmP.js";
|
|
2
3
|
import "../../http-types-BK7FuIcR.js";
|
|
3
4
|
import "../../server/index.js";
|
|
4
5
|
import { GetTokenOptions } from "@convex-dev/better-auth/utils";
|
|
@@ -12,7 +13,8 @@ type AuthOptions = {
|
|
|
12
13
|
};
|
|
13
14
|
type ConvexBetterAuthOptions<TApi> = Omit<GetTokenOptions, 'jwtCache'> & {
|
|
14
15
|
api: TApi;
|
|
15
|
-
convexSiteUrl: string;
|
|
16
|
+
convexSiteUrl: string;
|
|
17
|
+
convexUrl?: string; /** Auth options. JWT caching is enabled by default (set `auth.jwtCache: false` to disable). */
|
|
16
18
|
auth?: AuthOptions;
|
|
17
19
|
};
|
|
18
20
|
/**
|
|
@@ -38,10 +40,10 @@ type ConvexBetterAuthOptions<TApi> = Omit<GetTokenOptions, 'jwtCache'> & {
|
|
|
38
40
|
* ```
|
|
39
41
|
*/
|
|
40
42
|
declare function convexBetterAuth<TApi extends Record<string, unknown>>(opts: ConvexBetterAuthOptions<TApi>): {
|
|
43
|
+
createCaller: (ctxFn: () => Promise<ConvexContext<TApi>>) => LazyCaller<TApi>;
|
|
41
44
|
createContext: (reqOpts: {
|
|
42
45
|
headers: Headers;
|
|
43
46
|
}) => Promise<ConvexContext<TApi>>;
|
|
44
|
-
createCaller: (ctxFn: () => Promise<ConvexContext<TApi>>) => LazyCaller<TApi>;
|
|
45
47
|
handler: {
|
|
46
48
|
GET: (request: Request) => Promise<Response>;
|
|
47
49
|
POST: (request: Request) => Promise<Response>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as defaultIsUnauthorized } from "../../error-CAGGSN5H.js";
|
|
2
|
-
import { t as createCallerFactory } from "../../caller-factory-
|
|
2
|
+
import { t as createCallerFactory } from "../../caller-factory-C1uAqm5w.js";
|
|
3
3
|
import { getToken } from "@convex-dev/better-auth/utils";
|
|
4
4
|
|
|
5
5
|
//#region src/auth-nextjs/index.ts
|
|
@@ -50,7 +50,6 @@ function convexBetterAuth(opts) {
|
|
|
50
50
|
const jwtCacheEnabled = auth.jwtCache !== false;
|
|
51
51
|
const { createContext, createCaller } = createCallerFactory({
|
|
52
52
|
api: opts.api,
|
|
53
|
-
convexSiteUrl: opts.convexSiteUrl,
|
|
54
53
|
auth: jwtCacheEnabled ? {
|
|
55
54
|
getToken: (siteUrl, headers, getTokenOpts) => {
|
|
56
55
|
const mutableHeaders = new Headers(headers);
|
|
@@ -66,11 +65,13 @@ function convexBetterAuth(opts) {
|
|
|
66
65
|
});
|
|
67
66
|
},
|
|
68
67
|
isUnauthorized: auth.isUnauthorized ?? defaultIsUnauthorized
|
|
69
|
-
} : void 0
|
|
68
|
+
} : void 0,
|
|
69
|
+
convexSiteUrl: opts.convexSiteUrl,
|
|
70
|
+
convexUrl: opts.convexUrl
|
|
70
71
|
});
|
|
71
72
|
return {
|
|
72
|
-
createContext,
|
|
73
73
|
createCaller,
|
|
74
|
+
createContext,
|
|
74
75
|
handler: nextJsHandler(opts.convexSiteUrl)
|
|
75
76
|
};
|
|
76
77
|
}
|
|
@@ -116,12 +116,20 @@ function createLazyCaller(api, createContext) {
|
|
|
116
116
|
* Framework-agnostic caller factory.
|
|
117
117
|
* getToken is passed as a parameter - decoupled from @convex-dev/better-auth.
|
|
118
118
|
*/
|
|
119
|
-
const
|
|
119
|
+
const CONVEX_SITE_URL_RE = /\.convex\.site(?=\/|$)/;
|
|
120
|
+
const getArgsAndOptions = (args, token, url) => [args[0], {
|
|
121
|
+
token,
|
|
122
|
+
url
|
|
123
|
+
}];
|
|
120
124
|
const parseConvexSiteUrl = (url) => {
|
|
121
125
|
if (!url) throw new Error("CONVEX_SITE_URL is not set. This must be set in the environment.");
|
|
122
126
|
if (url.endsWith(".convex.cloud")) throw new Error(`CONVEX_SITE_URL should end in .convex.site, not .convex.cloud. Currently set to ${url}.`);
|
|
123
127
|
return url;
|
|
124
128
|
};
|
|
129
|
+
const getConvexUrl = (siteUrl, convexUrl) => {
|
|
130
|
+
if (convexUrl) return convexUrl;
|
|
131
|
+
return siteUrl.replace(CONVEX_SITE_URL_RE, ".convex.cloud");
|
|
132
|
+
};
|
|
125
133
|
/**
|
|
126
134
|
* Framework-agnostic caller factory.
|
|
127
135
|
*
|
|
@@ -137,6 +145,7 @@ const parseConvexSiteUrl = (url) => {
|
|
|
137
145
|
const noAuthGetToken = () => Promise.resolve({ token: void 0 });
|
|
138
146
|
function createCallerFactory(opts) {
|
|
139
147
|
const siteUrl = parseConvexSiteUrl(opts.convexSiteUrl);
|
|
148
|
+
const convexUrl = getConvexUrl(siteUrl, opts.convexUrl);
|
|
140
149
|
const getToken = opts.auth?.getToken ?? noAuthGetToken;
|
|
141
150
|
const isUnauthorized = opts.auth?.isUnauthorized;
|
|
142
151
|
const crpcMeta = buildMetaIndex(opts.api);
|
|
@@ -166,40 +175,40 @@ function createCallerFactory(opts) {
|
|
|
166
175
|
const fetchAuthQuery = async (query, args, callerOpts) => {
|
|
167
176
|
if (callerOpts?.skipUnauth && !tokenResult.token) return null;
|
|
168
177
|
return callWithTokenAndRetry((token) => {
|
|
169
|
-
const argsAndOptions = getArgsAndOptions([args], token);
|
|
178
|
+
const argsAndOptions = getArgsAndOptions([args], token, convexUrl);
|
|
170
179
|
return fetchQuery(query, argsAndOptions[0], argsAndOptions[1]);
|
|
171
180
|
}, tokenResult, reqOpts.headers);
|
|
172
181
|
};
|
|
173
182
|
const fetchAuthMutation = async (mutation, args, callerOpts) => {
|
|
174
183
|
if (callerOpts?.skipUnauth && !tokenResult.token) return null;
|
|
175
184
|
return callWithTokenAndRetry((token) => {
|
|
176
|
-
const argsAndOptions = getArgsAndOptions([args], token);
|
|
185
|
+
const argsAndOptions = getArgsAndOptions([args], token, convexUrl);
|
|
177
186
|
return fetchMutation(mutation, argsAndOptions[0], argsAndOptions[1]);
|
|
178
187
|
}, tokenResult, reqOpts.headers);
|
|
179
188
|
};
|
|
180
189
|
const fetchAuthAction = async (action, args, callerOpts) => {
|
|
181
190
|
if (callerOpts?.skipUnauth && !tokenResult.token) return null;
|
|
182
191
|
return callWithTokenAndRetry((token) => {
|
|
183
|
-
const argsAndOptions = getArgsAndOptions([args], token);
|
|
192
|
+
const argsAndOptions = getArgsAndOptions([args], token, convexUrl);
|
|
184
193
|
return fetchAction(action, argsAndOptions[0], argsAndOptions[1]);
|
|
185
194
|
}, tokenResult, reqOpts.headers);
|
|
186
195
|
};
|
|
187
196
|
return {
|
|
188
|
-
token: tokenResult.token,
|
|
189
|
-
isAuthenticated: !!tokenResult.token,
|
|
190
197
|
caller: createServerCaller(opts.api, {
|
|
191
|
-
fetchQuery: fetchAuthQuery,
|
|
192
|
-
fetchMutation: fetchAuthMutation,
|
|
193
198
|
fetchAction: fetchAuthAction,
|
|
199
|
+
fetchMutation: fetchAuthMutation,
|
|
200
|
+
fetchQuery: fetchAuthQuery,
|
|
194
201
|
meta: crpcMeta,
|
|
195
202
|
transformer: opts.transformer
|
|
196
|
-
})
|
|
203
|
+
}),
|
|
204
|
+
isAuthenticated: !!tokenResult.token,
|
|
205
|
+
token: tokenResult.token
|
|
197
206
|
};
|
|
198
207
|
};
|
|
199
208
|
const createCaller = (ctxFn) => createLazyCaller(opts.api, ctxFn);
|
|
200
209
|
return {
|
|
201
|
-
|
|
202
|
-
|
|
210
|
+
createCaller,
|
|
211
|
+
createContext
|
|
203
212
|
};
|
|
204
213
|
}
|
|
205
214
|
|
package/dist/crpc/index.d.ts
CHANGED
|
@@ -1,7 +1,36 @@
|
|
|
1
1
|
import { $ as identityTransformer, G as DataTransformerOptions, H as CombinedDataTransformer, J as dateWireCodec, K as WireCodec, Q as getTransformer, U as DATE_CODEC_TAG, W as DataTransformer, X as defaultCRPCTransformer, Y as decodeWire, Z as encodeWire, a as HttpProcedureCall, c as InferHttpInput, i as HttpErrorCode, l as InferHttpOutput, n as HttpClientError, o as HttpRouteInfo, q as createTaggedTransformer, r as HttpClientFromRouter, s as HttpRouteMap, t as HttpClient, u as isHttpClientError } from "../http-types-BK7FuIcR.js";
|
|
2
|
-
import { C as
|
|
2
|
+
import { A as HttpInputArgs, C as ReservedMutationOptions, D as VanillaMutation, E as VanillaAction, F as replaceUrlParam, M as RESERVED_KEYS, N as buildSearchParams, O as HttpClientOptions, P as executeHttpRequest, S as ReservedInfiniteQueryOptions, T as StaticQueryOptsParam, _ as IsPaginated, a as BaseInfiniteQueryOptsParam, b as PaginatedFnMeta, c as ConvexMutationKey, d as ConvexQueryMeta, f as EmptyObject, g as InfiniteQueryInput, h as FnMeta, i as BaseConvexQueryOptions, j as HttpProxyBaseOptions, k as HttpFormValue, l as ConvexQueryHookOptions, m as FUNC_REF_SYMBOL, n as BaseConvexActionOptions, o as ConvexActionKey, p as ExtractPaginatedItem, r as BaseConvexInfiniteQueryOptions, s as ConvexInfiniteQueryMeta, t as AuthType, u as ConvexQueryKey, v as Meta, w as ReservedQueryOptions, x as PaginationOpts, y as MutationVariables } from "../types-7bF_8IjP.js";
|
|
3
3
|
import { FunctionArgs, FunctionReference } from "convex/server";
|
|
4
4
|
|
|
5
|
+
//#region src/crpc/auth-error.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Auth Mutation Error
|
|
8
|
+
*
|
|
9
|
+
* Framework-agnostic error class for Better Auth mutations.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when a Better Auth mutation fails.
|
|
13
|
+
* Contains the original error details from Better Auth.
|
|
14
|
+
*/
|
|
15
|
+
declare class AuthMutationError extends Error {
|
|
16
|
+
/** Error code from Better Auth (e.g., 'INVALID_PASSWORD', 'EMAIL_ALREADY_REGISTERED') */
|
|
17
|
+
code?: string;
|
|
18
|
+
/** HTTP status code */
|
|
19
|
+
status: number;
|
|
20
|
+
/** HTTP status text */
|
|
21
|
+
statusText: string;
|
|
22
|
+
constructor(authError: {
|
|
23
|
+
message?: string;
|
|
24
|
+
status: number;
|
|
25
|
+
statusText: string;
|
|
26
|
+
code?: string;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Type guard to check if an error is an AuthMutationError.
|
|
31
|
+
*/
|
|
32
|
+
declare function isAuthMutationError(error: unknown): error is AuthMutationError;
|
|
33
|
+
//#endregion
|
|
5
34
|
//#region src/crpc/error.d.ts
|
|
6
35
|
/**
|
|
7
36
|
* Client error codes (subset of CRPC codes for client-side use)
|
|
@@ -40,7 +69,7 @@ declare const defaultIsUnauthorized: (error: unknown) => boolean;
|
|
|
40
69
|
*/
|
|
41
70
|
declare function convexQuery<T extends FunctionReference<'query'>>(funcRef: T, args?: FunctionArgs<T> | 'skip', meta?: Meta, opts?: {
|
|
42
71
|
skipUnauth?: boolean;
|
|
43
|
-
}):
|
|
72
|
+
}): BaseConvexQueryOptions<T> & {
|
|
44
73
|
meta: ConvexQueryMeta;
|
|
45
74
|
};
|
|
46
75
|
/**
|
|
@@ -62,7 +91,7 @@ declare function convexQuery<T extends FunctionReference<'query'>>(funcRef: T, a
|
|
|
62
91
|
*/
|
|
63
92
|
declare function convexAction<T extends FunctionReference<'action'>>(funcRef: T, args?: FunctionArgs<T> | 'skip', meta?: Meta, opts?: {
|
|
64
93
|
skipUnauth?: boolean;
|
|
65
|
-
}):
|
|
94
|
+
}): BaseConvexActionOptions<T> & {
|
|
66
95
|
meta: ConvexQueryMeta;
|
|
67
96
|
};
|
|
68
97
|
/**
|
|
@@ -71,6 +100,6 @@ declare function convexAction<T extends FunctionReference<'action'>>(funcRef: T,
|
|
|
71
100
|
*
|
|
72
101
|
* Uses flat { cursor, limit } input like tRPC.
|
|
73
102
|
*/
|
|
74
|
-
declare function convexInfiniteQueryOptions<T extends FunctionReference<'query'>>(funcRef: T, args: Record<string, unknown> | 'skip', opts?:
|
|
103
|
+
declare function convexInfiniteQueryOptions<T extends FunctionReference<'query'>>(funcRef: T, args: Record<string, unknown> | 'skip', opts?: BaseInfiniteQueryOptsParam<T> & Record<string, unknown>, meta?: Meta): BaseConvexInfiniteQueryOptions<T> & Record<string, unknown>;
|
|
75
104
|
//#endregion
|
|
76
|
-
export { AuthType,
|
|
105
|
+
export { AuthMutationError, AuthType, BaseConvexActionOptions, BaseConvexInfiniteQueryOptions, BaseConvexQueryOptions, BaseInfiniteQueryOptsParam, CRPCClientError, CombinedDataTransformer, ConvexActionKey, ConvexInfiniteQueryMeta, ConvexMutationKey, ConvexQueryHookOptions, ConvexQueryKey, ConvexQueryMeta, DATE_CODEC_TAG, DataTransformer, DataTransformerOptions, EmptyObject, ExtractPaginatedItem, FUNC_REF_SYMBOL, FnMeta, HttpClient, HttpClientError, HttpClientFromRouter, HttpClientOptions, HttpErrorCode, HttpFormValue, HttpInputArgs, HttpProcedureCall, HttpProxyBaseOptions, HttpRouteInfo, HttpRouteMap, InferHttpInput, InferHttpOutput, InfiniteQueryInput, IsPaginated, Meta, MutationVariables, PaginatedFnMeta, PaginationOpts, RESERVED_KEYS, ReservedInfiniteQueryOptions, ReservedMutationOptions, ReservedQueryOptions, StaticQueryOptsParam, VanillaAction, VanillaMutation, WireCodec, buildSearchParams, convexAction, convexInfiniteQueryOptions, convexQuery, createTaggedTransformer, dateWireCodec, decodeWire, defaultCRPCTransformer, defaultIsUnauthorized, encodeWire, executeHttpRequest, getTransformer, identityTransformer, isAuthMutationError, isCRPCClientError, isCRPCError, isCRPCErrorCode, isHttpClientError, replaceUrlParam };
|
package/dist/crpc/index.js
CHANGED
|
@@ -2,6 +2,39 @@ import { a as isCRPCErrorCode, i as isCRPCError, n as defaultIsUnauthorized, r a
|
|
|
2
2
|
import { a as defaultCRPCTransformer, c as identityTransformer, i as decodeWire, n as createTaggedTransformer, o as encodeWire, r as dateWireCodec, s as getTransformer, t as DATE_CODEC_TAG } from "../transformer-ogg-4d78.js";
|
|
3
3
|
import { n as convexInfiniteQueryOptions, r as convexQuery, t as convexAction } from "../query-options-CSCmKYdJ.js";
|
|
4
4
|
|
|
5
|
+
//#region src/crpc/auth-error.ts
|
|
6
|
+
/**
|
|
7
|
+
* Auth Mutation Error
|
|
8
|
+
*
|
|
9
|
+
* Framework-agnostic error class for Better Auth mutations.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Error thrown when a Better Auth mutation fails.
|
|
13
|
+
* Contains the original error details from Better Auth.
|
|
14
|
+
*/
|
|
15
|
+
var AuthMutationError = class extends Error {
|
|
16
|
+
/** Error code from Better Auth (e.g., 'INVALID_PASSWORD', 'EMAIL_ALREADY_REGISTERED') */
|
|
17
|
+
code;
|
|
18
|
+
/** HTTP status code */
|
|
19
|
+
status;
|
|
20
|
+
/** HTTP status text */
|
|
21
|
+
statusText;
|
|
22
|
+
constructor(authError) {
|
|
23
|
+
super(authError.message || authError.statusText);
|
|
24
|
+
this.name = "AuthMutationError";
|
|
25
|
+
this.code = authError.code;
|
|
26
|
+
this.status = authError.status;
|
|
27
|
+
this.statusText = authError.statusText;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Type guard to check if an error is an AuthMutationError.
|
|
32
|
+
*/
|
|
33
|
+
function isAuthMutationError(error) {
|
|
34
|
+
return error instanceof AuthMutationError;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
//#endregion
|
|
5
38
|
//#region src/crpc/http-types.ts
|
|
6
39
|
/** HTTP client error */
|
|
7
40
|
var HttpClientError = class extends Error {
|
|
@@ -19,10 +52,118 @@ var HttpClientError = class extends Error {
|
|
|
19
52
|
/** Type guard for HttpClientError */
|
|
20
53
|
const isHttpClientError = (error) => error instanceof HttpClientError;
|
|
21
54
|
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/crpc/http-client.ts
|
|
57
|
+
/**
|
|
58
|
+
* HTTP Client Helpers
|
|
59
|
+
*
|
|
60
|
+
* Framework-agnostic utilities for executing HTTP requests
|
|
61
|
+
* against Convex HTTP endpoints.
|
|
62
|
+
*/
|
|
63
|
+
/** Reserved keys that are not part of JSON body */
|
|
64
|
+
const RESERVED_KEYS = new Set([
|
|
65
|
+
"params",
|
|
66
|
+
"searchParams",
|
|
67
|
+
"form",
|
|
68
|
+
"fetch",
|
|
69
|
+
"init",
|
|
70
|
+
"headers"
|
|
71
|
+
]);
|
|
72
|
+
/**
|
|
73
|
+
* Replace URL path parameters with actual values.
|
|
74
|
+
* e.g., '/users/:id' with { id: '123' } -> '/users/123'
|
|
75
|
+
*/
|
|
76
|
+
function replaceUrlParam(url, params) {
|
|
77
|
+
return url.replace(/:(\w+)/g, (_, key) => {
|
|
78
|
+
const value = params[key];
|
|
79
|
+
return value !== void 0 ? encodeURIComponent(value) : `:${key}`;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Build URLSearchParams from query object.
|
|
84
|
+
* Handles array values as multiple params with same key (like Hono).
|
|
85
|
+
*/
|
|
86
|
+
function buildSearchParams(query) {
|
|
87
|
+
const params = new URLSearchParams();
|
|
88
|
+
for (const [key, value] of Object.entries(query)) if (Array.isArray(value)) for (const v of value) params.append(key, v);
|
|
89
|
+
else if (value !== void 0 && value !== null) params.append(key, value);
|
|
90
|
+
return params;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Hono-style HTTP request executor.
|
|
94
|
+
* Processes args in the same way as Hono's ClientRequestImpl.fetch().
|
|
95
|
+
*/
|
|
96
|
+
async function executeHttpRequest(opts) {
|
|
97
|
+
const { method, path } = opts.route;
|
|
98
|
+
const args = opts.args ?? {};
|
|
99
|
+
let rBody;
|
|
100
|
+
let cType;
|
|
101
|
+
if (args.form) {
|
|
102
|
+
const form = new FormData();
|
|
103
|
+
for (const [k, v] of Object.entries(args.form)) if (Array.isArray(v)) for (const v2 of v) form.append(k, v2);
|
|
104
|
+
else form.append(k, v);
|
|
105
|
+
rBody = form;
|
|
106
|
+
} else {
|
|
107
|
+
const jsonBody = {};
|
|
108
|
+
for (const [key, value] of Object.entries(args)) if (!RESERVED_KEYS.has(key) && value !== void 0) jsonBody[key] = value;
|
|
109
|
+
if (Object.keys(jsonBody).length > 0) {
|
|
110
|
+
rBody = JSON.stringify(opts.transformer.input.serialize(jsonBody));
|
|
111
|
+
cType = "application/json";
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
const argsClientOpts = {};
|
|
115
|
+
if (args.fetch) argsClientOpts.fetch = args.fetch;
|
|
116
|
+
if (args.init) argsClientOpts.init = args.init;
|
|
117
|
+
if (args.headers) argsClientOpts.headers = args.headers;
|
|
118
|
+
const mergedClientOpts = {
|
|
119
|
+
...opts.clientOpts,
|
|
120
|
+
...argsClientOpts
|
|
121
|
+
};
|
|
122
|
+
const resolvedBaseHeaders = typeof opts.baseHeaders === "function" ? await opts.baseHeaders() : opts.baseHeaders;
|
|
123
|
+
const headerValues = { ...typeof mergedClientOpts.headers === "function" ? await mergedClientOpts.headers() : mergedClientOpts.headers };
|
|
124
|
+
if (cType) headerValues["Content-Type"] = cType;
|
|
125
|
+
const finalHeaders = {};
|
|
126
|
+
if (resolvedBaseHeaders) {
|
|
127
|
+
for (const [key, value] of Object.entries(resolvedBaseHeaders)) if (value !== void 0) finalHeaders[key] = value;
|
|
128
|
+
}
|
|
129
|
+
Object.assign(finalHeaders, headerValues);
|
|
130
|
+
let url = opts.convexSiteUrl + path;
|
|
131
|
+
if (args.params) url = opts.convexSiteUrl + replaceUrlParam(path, args.params);
|
|
132
|
+
if (args.searchParams) {
|
|
133
|
+
const queryString = buildSearchParams(args.searchParams).toString();
|
|
134
|
+
if (queryString) url = `${url}?${queryString}`;
|
|
135
|
+
}
|
|
136
|
+
const methodUpperCase = method.toUpperCase();
|
|
137
|
+
const setBody = !(methodUpperCase === "GET" || methodUpperCase === "HEAD");
|
|
138
|
+
const response = await (mergedClientOpts.fetch ?? opts.baseFetch ?? globalThis.fetch)(url, {
|
|
139
|
+
body: setBody ? rBody : void 0,
|
|
140
|
+
method: methodUpperCase,
|
|
141
|
+
headers: finalHeaders,
|
|
142
|
+
...mergedClientOpts.init
|
|
143
|
+
});
|
|
144
|
+
if (!response.ok) {
|
|
145
|
+
const errorData = await response.json().catch(() => ({ error: {
|
|
146
|
+
code: "UNKNOWN",
|
|
147
|
+
message: response.statusText
|
|
148
|
+
} }));
|
|
149
|
+
const errorCode = errorData?.error?.code || "UNKNOWN";
|
|
150
|
+
const errorMessage = errorData?.error?.message || response.statusText;
|
|
151
|
+
throw new HttpClientError({
|
|
152
|
+
code: errorCode,
|
|
153
|
+
status: response.status,
|
|
154
|
+
procedureName: opts.procedureName,
|
|
155
|
+
message: errorMessage
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
if (response.headers.get("content-length") === "0" || response.status === 204) return;
|
|
159
|
+
if ((response.headers.get("content-type") || "").includes("application/json")) return opts.transformer.output.deserialize(await response.json());
|
|
160
|
+
return response.text();
|
|
161
|
+
}
|
|
162
|
+
|
|
22
163
|
//#endregion
|
|
23
164
|
//#region src/crpc/types.ts
|
|
24
165
|
/** Symbol key for attaching FunctionReference to options (non-serializable) */
|
|
25
166
|
const FUNC_REF_SYMBOL = Symbol.for("convex.funcRef");
|
|
26
167
|
|
|
27
168
|
//#endregion
|
|
28
|
-
export { CRPCClientError, DATE_CODEC_TAG, FUNC_REF_SYMBOL, HttpClientError, convexAction, convexInfiniteQueryOptions, convexQuery, createTaggedTransformer, dateWireCodec, decodeWire, defaultCRPCTransformer, defaultIsUnauthorized, encodeWire, getTransformer, identityTransformer, isCRPCClientError, isCRPCError, isCRPCErrorCode, isHttpClientError };
|
|
169
|
+
export { AuthMutationError, CRPCClientError, DATE_CODEC_TAG, FUNC_REF_SYMBOL, HttpClientError, RESERVED_KEYS, buildSearchParams, convexAction, convexInfiniteQueryOptions, convexQuery, createTaggedTransformer, dateWireCodec, decodeWire, defaultCRPCTransformer, defaultIsUnauthorized, encodeWire, executeHttpRequest, getTransformer, identityTransformer, isAuthMutationError, isCRPCClientError, isCRPCError, isCRPCErrorCode, isHttpClientError, replaceUrlParam };
|
package/dist/orm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as pretendRequired, n as deprecated, r as pretend } from "../validators-BcQFm1oY.js";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as DatabaseWithMutations, $n as BuildQueryResult, $r as notBetween, $t as defineRelations, A as MigrationCancelArgs, An as ConvexVectorIndexConfig, Ar as ExpressionVisitor, At as custom, B as MigrationManifestEntry, Bn as ConvexForeignKeyConfig, Br as fieldRef, Bt as ConvexBigIntBuilderInitial, C as OrmBeforeResult, Cn as ConvexRankIndexBuilder, Cr as ReturningResult, Ct as ConvexDateBuilder, D as OrmTriggers, Dn as ConvexSearchIndexConfig, Dr as VectorSearchProvider, Dt as ConvexCustomBuilder, E as OrmTriggerContext, En as ConvexSearchIndexBuilderOn, Er as VectorQueryConfig, Et as date, F as MigrationDefinition, Fn as uniqueIndex, Fr as and, Ft as bytes, G as MigrationStateMap, Gn as foreignKey, Gr as isFieldReference, Gt as ExtractTablesWithRelations, H as MigrationPlan, Hn as ConvexUniqueConstraintBuilderOn, Hr as gte, Ht as CountBackfillChunkArgs, I as MigrationDirection, In as vectorIndex, Ir as between, It as ConvexBooleanBuilder, J as MigrationWriteMode, Jn as ConvexTextBuilderInitial, Jr as like, Jt as RelationsBuilder, K as MigrationStep, Kn as unique, Kr as isNotNull, Kt as ManyConfig, L as MigrationDoc, Ln as ConvexCheckBuilder, Lr as contains, Lt as ConvexBooleanBuilderInitial, M as MigrationRunChunkArgs, Mn as index, Mr as FilterExpression, Mt as objectOf, N as MigrationStatusArgs, Nn as rankIndex, Nr as LogicalExpression, Nt as ConvexBytesBuilder, O as defineTriggers, On as ConvexVectorIndexBuilder, Or as unsetToken, Ot as ConvexCustomBuilderInitial, P as MigrationAppliedState, Pn as searchIndex, Pr as UnaryExpression, Pt as ConvexBytesBuilderInitial, Q as detectMigrationDrift, Qn as AggregateResult, Qr as not, Qt as TablesRelationalConfig, R as MigrationDocContext, Rn as ConvexCheckConfig, Rr as endsWith, Rt as boolean, S as scheduledDeleteFactory, Sn as ConvexIndexBuilderOn, Sr as ReturningAll, St as id, T as OrmTriggerChange, Tn as ConvexSearchIndexBuilder, Tr as UpdateSet, Tt as ConvexDateMode, U as MigrationRunStatus, Un as ConvexUniqueConstraintConfig, Ur as ilike, Ut as CountBackfillKickoffArgs, V as MigrationMigrateOne, Vn as ConvexUniqueConstraintBuilder, Vr as gt, Vt as bigint, W as MigrationSet, Wn as check, Wr as inArray, Wt as CountBackfillStatusArgs, X as defineMigration, Xn as AggregateConfig, Xr as lte, Xt as RelationsBuilderColumnConfig, Y as buildMigrationPlan, Yn as text, Yr as lt, Yt as RelationsBuilderColumnBase, Z as defineMigrationSet, Zn as AggregateFieldValue, Zr as ne, Zt as TableRelationalConfig, _ as OrmWriterCtx, _i as HasDefault, _n as RlsRoleConfig, _r as MutationRunMode, _t as ConvexNumberBuilder, a as TableConfigResult, ai as OrmSchemaPlugin, an as DiscriminatorBuilderConfig, ar as GetColumnData, at as EdgeMetadata, b as scheduledMutationBatchFactory, bi as NotNull, bn as ConvexAggregateIndexBuilderOn, br as PaginatedResult, bt as ConvexIdBuilder, c as OrmNotFoundError, ci as SystemFields, cn as TableConfig, cr as InferSelectModel, ct as ConvexVectorBuilderInitial, d as GenericOrmCtx, di as ColumnBuilderBaseConfig, dn as discriminator, dr as MutationExecuteResult, dt as ConvexTimestampBuilderInitial, ei as notInArray, en as defineRelationsPart, er as BuildRelationResult, et as DatabaseWithQuery, f as OrmApiResult, fi as ColumnBuilderRuntimeConfig, fn as RlsPolicy, fr as MutationExecutionMode, ft as ConvexTimestampMode, g as OrmReaderCtx, gi as DrizzleEntity, gn as RlsRole, gr as MutationReturning, gt as textEnum, h as OrmFunctions, hi as ColumnDataType, hn as rlsPolicy, hr as MutationResult, ht as ConvexTextEnumBuilderInitial, i as desc, ii as Columns, ir as FilterOperators, it as RlsMode, j as MigrationRunArgs, jn as aggregateIndex, jr as FieldReference, jt as json, kn as ConvexVectorIndexBuilderOn, kr as BinaryExpression, kt as arrayOf, l as CreateOrmOptions, li as AnyColumn, ln as convexTable, lr as InsertValue, lt as vector, m as OrmClientWithApi, mi as ColumnBuilderWithTableName, mn as RlsPolicyToOption, mr as MutationPaginatedResult, mt as ConvexTextEnumBuilder, n as defineSchema, ni as startsWith, nn as ConvexDeletionConfig, nr as CountResult, nt as OrmWriter, o as getTableColumns, oi as OrmSchemaPluginTables, on as OrmLifecycleChange, or as InferInsertModel, ot as extractRelationsConfig, p as OrmClientBase, pi as ColumnBuilderTypeConfig, pn as RlsPolicyConfig, pr as MutationPaginateConfig, pt as timestamp, q as MigrationTableName, qn as ConvexTextBuilder, qr as isNull, qt as OneConfig, r as asc, ri as Brand, rn as ConvexTable, rr as DBQueryConfig, rt as RlsContext, s as getTableConfig, si as TableName, sn as OrmLifecycleOperation, sr as InferModelFromColumns, st as ConvexVectorBuilder, t as WhereClauseResult, ti as or, tn as ConvexDeletionBuilder, tr as CountConfig, tt as OrmReader, u as GenericOrm, ui as ColumnBuilder, un as deletion, ur as MutationExecuteConfig, ut as ConvexTimestampBuilder, v as createOrm, vi as IsPrimaryKey, vn as rlsRole, vr as OrderByClause, vt as ConvexNumberBuilderInitial, w as OrmTableTriggers, wn as ConvexRankIndexBuilderOn, wr as ReturningSelection, wt as ConvexDateBuilderInitial, x as ScheduledDeleteArgs, xn as ConvexIndexBuilder, xr as PredicateWhereIndexConfig, xt as ConvexIdBuilderInitial, y as ScheduledMutationBatchArgs, yi as IsUnique, yn as ConvexAggregateIndexBuilder, yr as OrderDirection, yt as integer, z as MigrationDriftIssue, zn as ConvexForeignKeyBuilder, zr as eq, zt as ConvexBigIntBuilder } from "../where-clause-compiler-DjFwXrQn.js";
|
|
3
3
|
import { a as QueryCtxWithPreferredOrmQueryTable, i as QueryCtxWithOrmQueryTable, n as LookupByIdResultByCtx, o as getByIdWithOrmQueryFallback, r as QueryCtxWithOptionalOrmQueryTable, t as DocByCtx } from "../query-context-ji7By8u0.js";
|
|
4
4
|
import { DefineSchemaOptions, GenericSchema, SchemaDefinition } from "convex/server";
|
|
5
5
|
export { type AggregateConfig, type AggregateFieldValue, type AggregateResult, type AnyColumn, type BinaryExpression, Brand, type BuildQueryResult, type BuildRelationResult, type ColumnBuilder, type ColumnBuilderBaseConfig, type ColumnBuilderRuntimeConfig, type ColumnBuilderTypeConfig, type ColumnBuilderWithTableName, type ColumnDataType, Columns, type ConvexAggregateIndexBuilder, type ConvexAggregateIndexBuilderOn, type ConvexBigIntBuilder, type ConvexBigIntBuilderInitial, type ConvexBooleanBuilder, type ConvexBooleanBuilderInitial, type ConvexBytesBuilder, type ConvexBytesBuilderInitial, type ConvexCheckBuilder, type ConvexCheckConfig, type ConvexCustomBuilder, type ConvexCustomBuilderInitial, type ConvexDateBuilder, type ConvexDateBuilderInitial, type ConvexDateMode, type ConvexDeletionBuilder, type ConvexDeletionConfig, type ConvexForeignKeyBuilder, type ConvexForeignKeyConfig, type ConvexIdBuilder, type ConvexIdBuilderInitial, type ConvexIndexBuilder, type ConvexIndexBuilderOn, type ConvexNumberBuilder, type ConvexNumberBuilderInitial, type ConvexRankIndexBuilder, type ConvexRankIndexBuilderOn, type ConvexSearchIndexBuilder, type ConvexSearchIndexBuilderOn, type ConvexSearchIndexConfig, type ConvexTable, type ConvexTextBuilder, type ConvexTextBuilderInitial, type ConvexTextEnumBuilder, type ConvexTextEnumBuilderInitial, type ConvexTimestampBuilder, type ConvexTimestampBuilderInitial, type ConvexTimestampMode, type ConvexUniqueConstraintBuilder, type ConvexUniqueConstraintBuilderOn, type ConvexUniqueConstraintConfig, type ConvexVectorBuilder, type ConvexVectorBuilderInitial, type ConvexVectorIndexBuilder, type ConvexVectorIndexBuilderOn, type ConvexVectorIndexConfig, type CountBackfillChunkArgs, type CountBackfillKickoffArgs, type CountBackfillStatusArgs, type CountConfig, type CountResult, type CreateOrmOptions, type DBQueryConfig, type DatabaseWithMutations, type DatabaseWithQuery, type DefineSchemaOptions, type DiscriminatorBuilderConfig, type DocByCtx, type DrizzleEntity, type EdgeMetadata, type ExpressionVisitor, type ExtractTablesWithRelations, type FieldReference, type FilterExpression, type FilterOperators, type GenericOrm, type GenericOrmCtx, type GenericSchema, type GetColumnData, type HasDefault, type InferInsertModel, type InferModelFromColumns, type InferSelectModel, type InsertValue, type IsPrimaryKey, type IsUnique, type LogicalExpression, type LookupByIdResultByCtx, type ManyConfig, type MigrationAppliedState, type MigrationCancelArgs, type MigrationDefinition, type MigrationDirection, type MigrationDoc, type MigrationDocContext, type MigrationDriftIssue, type MigrationManifestEntry, type MigrationMigrateOne, type MigrationPlan, type MigrationRunArgs, type MigrationRunChunkArgs, type MigrationRunStatus, type MigrationSet, type MigrationStateMap, type MigrationStatusArgs, type MigrationStep, type MigrationTableName, type MigrationWriteMode, type MutationExecuteConfig, type MutationExecuteResult, type MutationExecutionMode, type MutationPaginateConfig, type MutationPaginatedResult, type MutationResult, type MutationReturning, type MutationRunMode, type NotNull, type OneConfig, type OrderByClause, type OrderDirection, type OrmApiResult, type OrmBeforeResult, type OrmClientBase, type OrmClientWithApi, type OrmFunctions, type OrmLifecycleChange, type OrmLifecycleOperation, OrmNotFoundError, type OrmReader, type OrmReaderCtx, type OrmSchemaPlugin, OrmSchemaPluginTables, type OrmTableTriggers, type OrmTriggerChange, type OrmTriggerContext, type OrmTriggers, type OrmWriter, type OrmWriterCtx, type PaginatedResult, type PredicateWhereIndexConfig, type QueryCtxWithOptionalOrmQueryTable, type QueryCtxWithOrmQueryTable, type QueryCtxWithPreferredOrmQueryTable, type RelationsBuilder, type RelationsBuilderColumnBase, type RelationsBuilderColumnConfig, type ReturningAll, type ReturningResult, type ReturningSelection, type RlsContext, type RlsMode, RlsPolicy, type RlsPolicyConfig, type RlsPolicyToOption, RlsRole, type RlsRoleConfig, type ScheduledDeleteArgs, type ScheduledMutationBatchArgs, type SchemaDefinition, type SystemFields, type TableConfig, type TableConfigResult, TableName, type TableRelationalConfig, type TablesRelationalConfig, type UnaryExpression, type UpdateSet, type VectorQueryConfig, type VectorSearchProvider, type WhereClauseResult, aggregateIndex, and, arrayOf, asc, between, bigint, boolean, buildMigrationPlan, bytes, check, contains, convexTable, createOrm, custom, date, defineMigration, defineMigrationSet, defineRelations, defineRelationsPart, defineSchema, defineTriggers, deletion, deprecated, desc, detectMigrationDrift, discriminator, endsWith, eq, extractRelationsConfig, fieldRef, foreignKey, getByIdWithOrmQueryFallback, getTableColumns, getTableConfig, gt, gte, id, ilike, inArray, index, integer, isFieldReference, isNotNull, isNull, json, like, lt, lte, ne, not, notBetween, notInArray, objectOf, or, pretend, pretendRequired, rankIndex, rlsPolicy, rlsRole, scheduledDeleteFactory, scheduledMutationBatchFactory, searchIndex, startsWith, text, textEnum, timestamp, unique, uniqueIndex, unsetToken, vector, vectorIndex };
|
package/dist/orm/index.js
CHANGED
|
@@ -2075,6 +2075,12 @@ function findRelationIndex(table, columns, relationName, targetTableName, strict
|
|
|
2075
2075
|
const PUBLIC_CREATED_AT_FIELD = "createdAt";
|
|
2076
2076
|
const INTERNAL_CREATION_TIME_FIELD = "_creationTime";
|
|
2077
2077
|
const CREATED_AT_MIGRATION_MESSAGE = "`_creationTime` is no longer public. Use `createdAt` instead.";
|
|
2078
|
+
const hasUserCreatedAtColumn = (table) => {
|
|
2079
|
+
if (!table || typeof table !== "object") return false;
|
|
2080
|
+
const columns = table[Columns];
|
|
2081
|
+
if (!columns || typeof columns !== "object") return false;
|
|
2082
|
+
return Object.hasOwn(columns, PUBLIC_CREATED_AT_FIELD);
|
|
2083
|
+
};
|
|
2078
2084
|
const usesSystemCreatedAtAlias = (_table) => true;
|
|
2079
2085
|
|
|
2080
2086
|
//#endregion
|
|
@@ -2176,10 +2182,11 @@ const normalizePublicSystemFields = (value, options) => {
|
|
|
2176
2182
|
};
|
|
2177
2183
|
const normalizeDateFieldsForWrite = (table, value) => {
|
|
2178
2184
|
const useSystemCreatedAt = usesSystemCreatedAtAlias(table);
|
|
2185
|
+
const hasUserCreatedAt = hasUserCreatedAtColumn(table);
|
|
2179
2186
|
const temporalColumns = getTemporalColumnDescriptors(table);
|
|
2180
2187
|
const result = { ...value };
|
|
2181
2188
|
if (Object.hasOwn(result, INTERNAL_CREATION_TIME_FIELD)) throw new Error(CREATED_AT_MIGRATION_MESSAGE);
|
|
2182
|
-
if (useSystemCreatedAt && Object.hasOwn(result, PUBLIC_CREATED_AT_FIELD)) delete result[PUBLIC_CREATED_AT_FIELD];
|
|
2189
|
+
if (useSystemCreatedAt && !hasUserCreatedAt && Object.hasOwn(result, PUBLIC_CREATED_AT_FIELD)) delete result[PUBLIC_CREATED_AT_FIELD];
|
|
2183
2190
|
for (const [name, descriptor] of temporalColumns.entries()) {
|
|
2184
2191
|
if (!Object.hasOwn(result, name)) continue;
|
|
2185
2192
|
result[name] = normalizeTemporalWriteValue(descriptor, result[name]);
|