better-convex 0.6.0 → 0.6.2

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.
@@ -1098,6 +1098,29 @@ const getHeaders = async (ctx, session) => {
1098
1098
  });
1099
1099
  };
1100
1100
 
1101
+ //#endregion
1102
+ //#region src/auth/error-response.ts
1103
+ const isApiErrorLike = (error) => !!error && typeof error === "object" && (error.name === "APIError" && "statusCode" in error || typeof error.statusCode === "number");
1104
+ const toResponseInit = (error) => {
1105
+ const init = {
1106
+ headers: new Headers(error.headers ?? {}),
1107
+ status: typeof error.statusCode === "number" ? error.statusCode : 500
1108
+ };
1109
+ if (typeof error.status === "string") init.statusText = error.status;
1110
+ return init;
1111
+ };
1112
+ const toAuthErrorResponse = (error) => {
1113
+ if (!isApiErrorLike(error)) return null;
1114
+ const init = toResponseInit(error);
1115
+ const { body } = error;
1116
+ if (body === void 0) return new Response(null, init);
1117
+ if (typeof body === "string") {
1118
+ if (init.headers instanceof Headers && !init.headers.has("content-type")) init.headers.set("content-type", "text/plain");
1119
+ return new Response(body, init);
1120
+ }
1121
+ return Response.json(body, init);
1122
+ };
1123
+
1101
1124
  //#endregion
1102
1125
  //#region src/auth/middleware.ts
1103
1126
  /**
@@ -1123,7 +1146,15 @@ function authMiddleware(getAuth, opts = {}) {
1123
1146
  if (c.req.path === "/.well-known/openid-configuration") return c.redirect(`${process.env.CONVEX_SITE_URL}${basePath}/convex/.well-known/openid-configuration`);
1124
1147
  if (c.req.path.startsWith(basePath)) {
1125
1148
  if (opts.verbose) console.log("request headers", c.req.raw.headers);
1126
- const response = await getAuth(c.env).handler(c.req.raw);
1149
+ const auth = getAuth(c.env);
1150
+ let response;
1151
+ try {
1152
+ response = await auth.handler(c.req.raw);
1153
+ } catch (error) {
1154
+ const errorResponse = toAuthErrorResponse(error);
1155
+ if (errorResponse) return errorResponse;
1156
+ throw error;
1157
+ }
1127
1158
  if (opts.verbose) console.log("response headers", response.headers);
1128
1159
  return response;
1129
1160
  }
@@ -1395,7 +1426,15 @@ const registerRoutes = (http, getAuth, opts = {}) => {
1395
1426
  console.log("options.baseURL", staticAuth.options.baseURL);
1396
1427
  console.log("request headers", request.headers);
1397
1428
  }
1398
- const response = await getAuth(ctx).handler(request);
1429
+ const auth = getAuth(ctx);
1430
+ let response;
1431
+ try {
1432
+ response = await auth.handler(request);
1433
+ } catch (error) {
1434
+ const errorResponse = toAuthErrorResponse(error);
1435
+ if (errorResponse) return errorResponse;
1436
+ throw error;
1437
+ }
1399
1438
  if (opts?.verbose) console.log("response headers", response.headers);
1400
1439
  return response;
1401
1440
  });
@@ -1,6 +1,6 @@
1
1
  import { a as ReturnTypeOrValue, i as KnownKeysOnly, o as Simplify, t as Assume } from "../types-jftzhhuc.js";
2
2
  import { DefineSchemaOptions, DefineSchemaOptions as DefineSchemaOptions$1, FilterExpression as FilterExpression$1, GenericDatabaseReader, GenericDatabaseWriter, GenericIndexFields, GenericSchema, GenericSchema as GenericSchema$1, GenericTableIndexes, GenericTableSearchIndexes, GenericTableVectorIndexes, IndexRange, IndexRangeBuilder, SchedulableFunctionReference, Scheduler, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, TableDefinition, VectorFilterBuilder, internalMutationGeneric } from "convex/server";
3
- import * as convex_values69 from "convex/values";
3
+ import * as convex_values63 from "convex/values";
4
4
  import { GenericId, Validator, Value } from "convex/values";
5
5
 
6
6
  //#region src/orm/builders/column-builder.d.ts
@@ -94,6 +94,15 @@ interface DrizzleEntity {
94
94
  interface ColumnBuilderBase<T extends ColumnBuilderBaseConfig<ColumnDataType, string> = ColumnBuilderBaseConfig<ColumnDataType, string>, TTypeConfig extends object = object> {
95
95
  _: ColumnBuilderTypeConfig<T, TTypeConfig>;
96
96
  }
97
+ /**
98
+ * Use as the return type for self-referencing `.references()` callbacks.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * parentId: text().references((): AnyColumn => commentsTable.id, { onDelete: 'cascade' })
103
+ * ```
104
+ */
105
+ type AnyColumn = ColumnBuilderBase;
97
106
  /**
98
107
  * Base ColumnBuilder abstract class
99
108
  *
@@ -381,7 +390,7 @@ declare function custom<TName extends string, TValidator extends AnyValidator>(n
381
390
  *
382
391
  * Note: This is Convex JSON (runtime `v.any()`), not SQL JSON/JSONB.
383
392
  */
384
- declare function json<T = Value>(): $Type<ConvexCustomBuilderInitial<"", convex_values69.VAny<any, "required", string>>, T>;
393
+ declare function json<T = Value>(): $Type<ConvexCustomBuilderInitial<"", convex_values63.VAny<any, "required", string>>, T>;
385
394
  //#endregion
386
395
  //#region src/orm/builders/date.d.ts
387
396
  type ConvexDateMode = 'string' | 'date';
@@ -514,12 +523,12 @@ declare class ConvexSystemIdBuilder<_TTableName extends string> extends ColumnBu
514
523
  static readonly [entityKind]: string;
515
524
  readonly [entityKind]: string;
516
525
  constructor();
517
- build(): convex_values69.VString<string, "required">;
526
+ build(): convex_values63.VString<string, "required">;
518
527
  /**
519
528
  * Convex validator - runtime access
520
529
  * System fields use v.string() for _id
521
530
  */
522
- get convexValidator(): convex_values69.VString<string, "required">;
531
+ get convexValidator(): convex_values63.VString<string, "required">;
523
532
  }
524
533
  type ConvexSystemCreatedAtConfig = ColumnBuilderBaseConfig<'number', 'ConvexSystemCreatedAt'> & {
525
534
  data: number;
@@ -532,8 +541,8 @@ declare class ConvexSystemCreatedAtBuilder extends ColumnBuilder<ConvexSystemCre
532
541
  static readonly [entityKind]: string;
533
542
  readonly [entityKind]: string;
534
543
  constructor();
535
- build(): convex_values69.VFloat64<number, "required">;
536
- get convexValidator(): convex_values69.VFloat64<number, "required">;
544
+ build(): convex_values63.VFloat64<number, "required">;
545
+ get convexValidator(): convex_values63.VFloat64<number, "required">;
537
546
  }
538
547
  /**
539
548
  * Create system field builders for a table
@@ -2974,4 +2983,4 @@ interface IndexLike {
2974
2983
  indexFields: string[];
2975
2984
  }
2976
2985
  //#endregion
2977
- export { type BinaryExpression, Brand, type BuildQueryResult, type BuildRelationResult, type ColumnBuilder, type ColumnBuilderBaseConfig, type ColumnBuilderRuntimeConfig, type ColumnBuilderTypeConfig, type ColumnBuilderWithTableName, type ColumnDataType, Columns, 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 ConvexLifecycleBuilder, type ConvexNumberBuilder, type ConvexNumberBuilderInitial, 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 CreateOrmOptions, type DBQueryConfig, type DatabaseWithMutations, type DatabaseWithQuery, type DefineSchemaOptions, 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 ManyConfig, type MutationAsyncConfig, 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 OrmClientBase, type OrmClientWithApi, type OrmFunctions, type OrmLifecycleChange, type OrmLifecycleConfig, type OrmLifecycleHandler, type OrmLifecycleOperation, OrmNotFoundError, type OrmReader, type OrmReaderCtx, type OrmTriggerLike, type OrmWriter, type OrmWriterCtx, type PaginatedResult, type PredicateWhereIndexConfig, 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, and, asc, between, bigint, boolean, bytes, check, contains, convexTable, createOrm, custom, date, defineRelations, defineRelationsPart, defineSchema, deletion, desc, endsWith, eq, extractRelationsConfig, fieldRef, foreignKey, getTableColumns, getTableConfig, gt, gte, id, ilike, inArray, index, integer, isFieldReference, isNotNull, isNull, json, like, lt, lte, ne, not, notBetween, notInArray, onChange, onDelete, onInsert, onUpdate, or, rlsPolicy, rlsRole, scheduledDeleteFactory, scheduledMutationBatchFactory, searchIndex, startsWith, text, textEnum, timestamp, unique, uniqueIndex, unsetToken, vector, vectorIndex };
2986
+ export { type AnyColumn, type BinaryExpression, Brand, type BuildQueryResult, type BuildRelationResult, type ColumnBuilder, type ColumnBuilderBaseConfig, type ColumnBuilderRuntimeConfig, type ColumnBuilderTypeConfig, type ColumnBuilderWithTableName, type ColumnDataType, Columns, 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 ConvexLifecycleBuilder, type ConvexNumberBuilder, type ConvexNumberBuilderInitial, 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 CreateOrmOptions, type DBQueryConfig, type DatabaseWithMutations, type DatabaseWithQuery, type DefineSchemaOptions, 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 ManyConfig, type MutationAsyncConfig, 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 OrmClientBase, type OrmClientWithApi, type OrmFunctions, type OrmLifecycleChange, type OrmLifecycleConfig, type OrmLifecycleHandler, type OrmLifecycleOperation, OrmNotFoundError, type OrmReader, type OrmReaderCtx, type OrmTriggerLike, type OrmWriter, type OrmWriterCtx, type PaginatedResult, type PredicateWhereIndexConfig, 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, and, asc, between, bigint, boolean, bytes, check, contains, convexTable, createOrm, custom, date, defineRelations, defineRelationsPart, defineSchema, deletion, desc, endsWith, eq, extractRelationsConfig, fieldRef, foreignKey, getTableColumns, getTableConfig, gt, gte, id, ilike, inArray, index, integer, isFieldReference, isNotNull, isNull, json, like, lt, lte, ne, not, notBetween, notInArray, onChange, onDelete, onInsert, onUpdate, or, rlsPolicy, rlsRole, scheduledDeleteFactory, scheduledMutationBatchFactory, searchIndex, startsWith, text, textEnum, timestamp, unique, uniqueIndex, unsetToken, vector, vectorIndex };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "better-convex",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "description": "Better Convex - React Query integration and CLI tools for Convex",
5
5
  "keywords": [
6
6
  "convex",