Update Prisma and harden tests
This commit is contained in:
parent
a2f9d4bd1a
commit
d8eb38fe52
17 changed files with 171 additions and 119 deletions
|
|
@ -92,20 +92,25 @@ export const { signIn, signOut, useSession } = authClient
|
|||
export function AuthProvider({ children }: { children: React.ReactNode }) {
|
||||
const devBypass = process.env.NODE_ENV !== "production" && process.env.NEXT_PUBLIC_DEV_BYPASS_AUTH === "1"
|
||||
const { data: baseSession, isPending } = useSession()
|
||||
const session: AppSession | null = baseSession ?? (devBypass
|
||||
? {
|
||||
session: { id: "dev-session", expiresAt: Date.now() + 1000 * 60 * 60 },
|
||||
user: {
|
||||
id: "dev-user",
|
||||
name: "Dev Admin",
|
||||
email: "admin@sistema.dev",
|
||||
role: "admin",
|
||||
tenantId: "tenant-atlas",
|
||||
avatarUrl: null,
|
||||
machinePersona: null,
|
||||
},
|
||||
}
|
||||
: null)
|
||||
const session = useMemo<AppSession | null>(
|
||||
() =>
|
||||
baseSession ??
|
||||
(devBypass
|
||||
? {
|
||||
session: { id: "dev-session", expiresAt: Date.now() + 1000 * 60 * 60 },
|
||||
user: {
|
||||
id: "dev-user",
|
||||
name: "Dev Admin",
|
||||
email: "admin@sistema.dev",
|
||||
role: "admin",
|
||||
tenantId: "tenant-atlas",
|
||||
avatarUrl: null,
|
||||
machinePersona: null,
|
||||
},
|
||||
}
|
||||
: null),
|
||||
[baseSession, devBypass]
|
||||
)
|
||||
const ensureUser = useMutation(api.users.ensureUser)
|
||||
const [convexUserId, setConvexUserId] = useState<string | null>(null)
|
||||
const [machineContext, setMachineContext] = useState<MachineContext | null>(null)
|
||||
|
|
|
|||
|
|
@ -64,6 +64,5 @@ if (process.env.NODE_ENV !== "production") {
|
|||
|
||||
if (process.env.NODE_ENV !== "production") {
|
||||
// Helps detect mismatched DB path during dev server bootstrap
|
||||
// eslint-disable-next-line no-console
|
||||
console.log("[prisma] Using database:", resolvedDatabaseUrl)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import { toast } from "sonner"
|
|||
|
||||
const METHODS = ["success", "error", "info", "warning", "message", "loading"] as const
|
||||
const TRAILING_PUNCTUATION_REGEX = /[\s!?.…,;:]+$/u
|
||||
const toastAny = toast as unknown as Record<string, (...args: any[]) => unknown> & { __punctuationPatched?: boolean }
|
||||
const toastAny = toast as typeof toast & { __punctuationPatched?: boolean }
|
||||
type ToastMethodKey = (typeof METHODS)[number]
|
||||
|
||||
function stripTrailingPunctuation(value: string): string {
|
||||
const trimmed = value.trimEnd()
|
||||
|
|
@ -19,49 +20,50 @@ function sanitizeContent<T>(value: T): T {
|
|||
return value
|
||||
}
|
||||
|
||||
function sanitizeOptions(options: unknown): unknown {
|
||||
function sanitizeOptions<T>(options: T): T {
|
||||
if (!options || typeof options !== "object") return options
|
||||
if ("description" in options && typeof (options as { description?: unknown }).description === "string") {
|
||||
return {
|
||||
...(options as Record<string, unknown>),
|
||||
description: stripTrailingPunctuation((options as { description: string }).description),
|
||||
}
|
||||
} as T
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
function wrapSimpleMethod(method: (typeof METHODS)[number]) {
|
||||
const original = toastAny[method]
|
||||
function wrapSimpleMethod<K extends ToastMethodKey>(method: K) {
|
||||
const original = toastAny[method] as typeof toast[K]
|
||||
if (typeof original !== "function") return
|
||||
toastAny[method] = (message: unknown, options?: unknown, ...rest: unknown[]) => {
|
||||
return original(sanitizeContent(message), sanitizeOptions(options), ...rest)
|
||||
}
|
||||
const patched = ((...args: Parameters<typeof toast[K]>) => {
|
||||
const nextArgs = args.slice() as Parameters<typeof toast[K]>
|
||||
if (nextArgs.length > 0) {
|
||||
nextArgs[0] = sanitizeContent(nextArgs[0])
|
||||
}
|
||||
if (nextArgs.length > 1) {
|
||||
nextArgs[1] = sanitizeOptions(nextArgs[1])
|
||||
}
|
||||
return original.apply(null, nextArgs as Parameters<typeof toast[K]>)
|
||||
}) as typeof toast[K]
|
||||
toastAny[method] = patched
|
||||
}
|
||||
|
||||
function wrapPromise() {
|
||||
const originalPromise = toastAny.promise
|
||||
if (typeof originalPromise !== "function") return
|
||||
toastAny.promise = (promise: Promise<unknown>, messages: Record<string, unknown>, options?: unknown) => {
|
||||
const wrapMessage = (value: unknown) => {
|
||||
if (typeof value === "function") {
|
||||
return (...args: unknown[]) => sanitizeContent((value as (...args: unknown[]) => unknown)(...args))
|
||||
}
|
||||
return sanitizeContent(value)
|
||||
}
|
||||
|
||||
toastAny.promise = ((promise, messages) => {
|
||||
const normalizedMessages =
|
||||
messages && typeof messages === "object"
|
||||
? {
|
||||
? ({
|
||||
...messages,
|
||||
loading: wrapMessage(messages.loading),
|
||||
success: wrapMessage(messages.success),
|
||||
error: wrapMessage(messages.error),
|
||||
finally: wrapMessage((messages as { finally?: unknown }).finally),
|
||||
}
|
||||
loading: sanitizeContent(messages.loading),
|
||||
success: sanitizeContent(messages.success),
|
||||
error: sanitizeContent(messages.error),
|
||||
description: sanitizeContent(messages.description),
|
||||
} satisfies typeof messages)
|
||||
: messages
|
||||
|
||||
return originalPromise(promise, normalizedMessages, sanitizeOptions(options))
|
||||
}
|
||||
return originalPromise(promise, normalizedMessages)
|
||||
}) as typeof toast.promise
|
||||
}
|
||||
|
||||
if (!toastAny.__punctuationPatched) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue