@vinetechke/next-error-logger 0.1.0-beta.1
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/LICENSE +21 -0
- package/README.md +442 -0
- package/dist/adapters/drizzle.cjs +123 -0
- package/dist/adapters/drizzle.cjs.map +1 -0
- package/dist/adapters/drizzle.d.cts +76 -0
- package/dist/adapters/drizzle.d.ts +76 -0
- package/dist/adapters/drizzle.js +99 -0
- package/dist/adapters/drizzle.js.map +1 -0
- package/dist/adapters/prisma.cjs +120 -0
- package/dist/adapters/prisma.cjs.map +1 -0
- package/dist/adapters/prisma.d.cts +75 -0
- package/dist/adapters/prisma.d.ts +75 -0
- package/dist/adapters/prisma.js +96 -0
- package/dist/adapters/prisma.js.map +1 -0
- package/dist/adapters/sql.cjs +206 -0
- package/dist/adapters/sql.cjs.map +1 -0
- package/dist/adapters/sql.d.cts +111 -0
- package/dist/adapters/sql.d.ts +111 -0
- package/dist/adapters/sql.js +182 -0
- package/dist/adapters/sql.js.map +1 -0
- package/dist/api/index.cjs +257 -0
- package/dist/api/index.cjs.map +1 -0
- package/dist/api/index.d.cts +137 -0
- package/dist/api/index.d.ts +137 -0
- package/dist/api/index.js +231 -0
- package/dist/api/index.js.map +1 -0
- package/dist/auth/clerk.cjs +60 -0
- package/dist/auth/clerk.cjs.map +1 -0
- package/dist/auth/clerk.d.cts +83 -0
- package/dist/auth/clerk.d.ts +83 -0
- package/dist/auth/clerk.js +36 -0
- package/dist/auth/clerk.js.map +1 -0
- package/dist/auth/next-auth.cjs +50 -0
- package/dist/auth/next-auth.cjs.map +1 -0
- package/dist/auth/next-auth.d.cts +53 -0
- package/dist/auth/next-auth.d.ts +53 -0
- package/dist/auth/next-auth.js +26 -0
- package/dist/auth/next-auth.js.map +1 -0
- package/dist/components/index.cjs +1175 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.d.cts +141 -0
- package/dist/components/index.d.ts +141 -0
- package/dist/components/index.js +1147 -0
- package/dist/components/index.js.map +1 -0
- package/dist/index.cjs +241 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +109 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +212 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas/drizzle.cjs +100 -0
- package/dist/schemas/drizzle.cjs.map +1 -0
- package/dist/schemas/drizzle.d.cts +32 -0
- package/dist/schemas/drizzle.d.ts +32 -0
- package/dist/schemas/drizzle.js +74 -0
- package/dist/schemas/drizzle.js.map +1 -0
- package/dist/types-C3x_Ry2e.d.cts +195 -0
- package/dist/types-C3x_Ry2e.d.ts +195 -0
- package/package.json +128 -0
- package/schemas/prisma.prisma +23 -0
- package/schemas/schema.sql +75 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { R as RequestContext, L as LogResult, E as ErrorLoggerConfig } from './types-C3x_Ry2e.js';
|
|
2
|
+
export { A as AuthAdapter, D as DatabaseAdapter, a as ErrorLogEntry, b as LogLevel, c as LogViewerProps, d as LogViewerTheme, Q as QueryOptions } from './types-C3x_Ry2e.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Initialize the error logger with your configuration
|
|
6
|
+
* Must be called before using errorLogger
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { initErrorLogger } from '@vinetechke/next-error-logger'
|
|
11
|
+
* import { createPrismaAdapter } from '@vinetechke/next-error-logger/adapters/prisma'
|
|
12
|
+
* import { createNextAuthAdapter } from '@vinetechke/next-error-logger/auth/next-auth'
|
|
13
|
+
* import { prisma } from '@/lib/prisma'
|
|
14
|
+
* import { auth } from '@/auth'
|
|
15
|
+
*
|
|
16
|
+
* initErrorLogger({
|
|
17
|
+
* adapter: createPrismaAdapter(prisma),
|
|
18
|
+
* authAdapter: createNextAuthAdapter(auth),
|
|
19
|
+
* retentionDays: 30,
|
|
20
|
+
* })
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
declare function initErrorLogger(cfg: ErrorLoggerConfig): void;
|
|
24
|
+
/**
|
|
25
|
+
* Get the current logger configuration
|
|
26
|
+
* @throws Error if logger is not initialized
|
|
27
|
+
*/
|
|
28
|
+
declare function getConfig(): ErrorLoggerConfig;
|
|
29
|
+
/**
|
|
30
|
+
* Check if logger is initialized
|
|
31
|
+
*/
|
|
32
|
+
declare function isInitialized(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Main error logger instance
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* // Simple logging
|
|
39
|
+
* await errorLogger.error('Something went wrong', error)
|
|
40
|
+
* await errorLogger.warn('Deprecated API used')
|
|
41
|
+
* await errorLogger.info('User completed checkout')
|
|
42
|
+
*
|
|
43
|
+
* // With request context (in API routes)
|
|
44
|
+
* const log = errorLogger.fromRequest(request)
|
|
45
|
+
* await log.error('API failed', error, { orderId: '123' })
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare const errorLogger: {
|
|
49
|
+
/**
|
|
50
|
+
* Log an error with optional Error object and context
|
|
51
|
+
*/
|
|
52
|
+
error: (message: string, error?: Error, context?: RequestContext) => Promise<LogResult>;
|
|
53
|
+
/**
|
|
54
|
+
* Log a warning with optional Error object and context
|
|
55
|
+
*/
|
|
56
|
+
warn: (message: string, error?: Error, context?: RequestContext) => Promise<LogResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Log an info message with optional context
|
|
59
|
+
*/
|
|
60
|
+
info: (message: string, context?: RequestContext) => Promise<LogResult>;
|
|
61
|
+
/**
|
|
62
|
+
* Log a debug message with optional context
|
|
63
|
+
*/
|
|
64
|
+
debug: (message: string, context?: RequestContext) => Promise<LogResult>;
|
|
65
|
+
/**
|
|
66
|
+
* Create a logger instance bound to a specific request
|
|
67
|
+
* Automatically extracts path, method, user agent, and IP
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```ts
|
|
71
|
+
* export async function POST(request: Request) {
|
|
72
|
+
* const log = errorLogger.fromRequest(request)
|
|
73
|
+
*
|
|
74
|
+
* try {
|
|
75
|
+
* // ... your code
|
|
76
|
+
* } catch (error) {
|
|
77
|
+
* await log.error('Failed to process', error as Error, { orderId: '123' })
|
|
78
|
+
* return new Response('Error', { status: 500 })
|
|
79
|
+
* }
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
fromRequest: (request: Request) => {
|
|
84
|
+
error: (message: string, error?: Error, metadata?: Record<string, unknown>) => Promise<LogResult>;
|
|
85
|
+
warn: (message: string, metadata?: Record<string, unknown>) => Promise<LogResult>;
|
|
86
|
+
info: (message: string, metadata?: Record<string, unknown>) => Promise<LogResult>;
|
|
87
|
+
debug: (message: string, metadata?: Record<string, unknown>) => Promise<LogResult>;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Log with explicit user context (when auth adapter is not available)
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```ts
|
|
94
|
+
* await errorLogger.withUser({ id: 'user-123', email: 'user@example.com' })
|
|
95
|
+
* .error('User action failed', error)
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
withUser: (user: {
|
|
99
|
+
id: string;
|
|
100
|
+
email?: string;
|
|
101
|
+
name?: string;
|
|
102
|
+
}) => {
|
|
103
|
+
error: (message: string, error?: Error, context?: RequestContext) => Promise<LogResult>;
|
|
104
|
+
warn: (message: string, context?: RequestContext) => Promise<LogResult>;
|
|
105
|
+
info: (message: string, context?: RequestContext) => Promise<LogResult>;
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export { ErrorLoggerConfig, LogResult, RequestContext, errorLogger, getConfig, initErrorLogger, isInitialized };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/logger.ts
|
|
4
|
+
var config = null;
|
|
5
|
+
function initErrorLogger(cfg) {
|
|
6
|
+
config = {
|
|
7
|
+
consoleInDev: true,
|
|
8
|
+
retentionDays: 30,
|
|
9
|
+
...cfg
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function getConfig() {
|
|
13
|
+
if (!config) {
|
|
14
|
+
throw new Error(
|
|
15
|
+
"[@vinetechke/next-error-logger] Logger not initialized. Call initErrorLogger() first."
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return config;
|
|
19
|
+
}
|
|
20
|
+
function isInitialized() {
|
|
21
|
+
return config !== null;
|
|
22
|
+
}
|
|
23
|
+
async function log(level, message, error, context) {
|
|
24
|
+
try {
|
|
25
|
+
const cfg = getConfig();
|
|
26
|
+
if (cfg.levels && !cfg.levels.includes(level)) {
|
|
27
|
+
return { success: true };
|
|
28
|
+
}
|
|
29
|
+
if (cfg.consoleInDev && process.env.NODE_ENV === "development") {
|
|
30
|
+
const consoleMethod = level === "error" ? "error" : level === "warn" ? "warn" : "log";
|
|
31
|
+
console[consoleMethod](
|
|
32
|
+
`[${level.toUpperCase()}]`,
|
|
33
|
+
message,
|
|
34
|
+
error || "",
|
|
35
|
+
context || ""
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
let user = null;
|
|
39
|
+
if (cfg.authAdapter) {
|
|
40
|
+
try {
|
|
41
|
+
user = await cfg.authAdapter.getUser();
|
|
42
|
+
} catch {
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const entry = await cfg.adapter.create({
|
|
46
|
+
level,
|
|
47
|
+
message,
|
|
48
|
+
stack: error?.stack || null,
|
|
49
|
+
userId: user?.id || null,
|
|
50
|
+
userEmail: user?.email || null,
|
|
51
|
+
userName: user?.name || null,
|
|
52
|
+
path: context?.path || null,
|
|
53
|
+
method: context?.method || null,
|
|
54
|
+
userAgent: context?.userAgent || null,
|
|
55
|
+
ip: context?.ip || null,
|
|
56
|
+
metadata: context?.metadata || null
|
|
57
|
+
});
|
|
58
|
+
return { success: true, entry };
|
|
59
|
+
} catch (err) {
|
|
60
|
+
console.error("[@vinetechke/next-error-logger] Failed to log:", err);
|
|
61
|
+
return {
|
|
62
|
+
success: false,
|
|
63
|
+
error: err instanceof Error ? err.message : "Unknown error"
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function extractRequestContext(request) {
|
|
68
|
+
const url = new URL(request.url);
|
|
69
|
+
return {
|
|
70
|
+
path: url.pathname,
|
|
71
|
+
method: request.method,
|
|
72
|
+
userAgent: request.headers.get("user-agent") || void 0,
|
|
73
|
+
ip: request.headers.get("x-forwarded-for")?.split(",")[0]?.trim() || request.headers.get("x-real-ip") || void 0
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
var errorLogger = {
|
|
77
|
+
/**
|
|
78
|
+
* Log an error with optional Error object and context
|
|
79
|
+
*/
|
|
80
|
+
error: (message, error, context) => log("error", message, error, context),
|
|
81
|
+
/**
|
|
82
|
+
* Log a warning with optional Error object and context
|
|
83
|
+
*/
|
|
84
|
+
warn: (message, error, context) => log("warn", message, error, context),
|
|
85
|
+
/**
|
|
86
|
+
* Log an info message with optional context
|
|
87
|
+
*/
|
|
88
|
+
info: (message, context) => log("info", message, null, context),
|
|
89
|
+
/**
|
|
90
|
+
* Log a debug message with optional context
|
|
91
|
+
*/
|
|
92
|
+
debug: (message, context) => log("debug", message, null, context),
|
|
93
|
+
/**
|
|
94
|
+
* Create a logger instance bound to a specific request
|
|
95
|
+
* Automatically extracts path, method, user agent, and IP
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* export async function POST(request: Request) {
|
|
100
|
+
* const log = errorLogger.fromRequest(request)
|
|
101
|
+
*
|
|
102
|
+
* try {
|
|
103
|
+
* // ... your code
|
|
104
|
+
* } catch (error) {
|
|
105
|
+
* await log.error('Failed to process', error as Error, { orderId: '123' })
|
|
106
|
+
* return new Response('Error', { status: 500 })
|
|
107
|
+
* }
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
fromRequest: (request) => {
|
|
112
|
+
const baseContext = extractRequestContext(request);
|
|
113
|
+
return {
|
|
114
|
+
error: (message, error, metadata) => log("error", message, error, { ...baseContext, metadata }),
|
|
115
|
+
warn: (message, metadata) => log("warn", message, null, { ...baseContext, metadata }),
|
|
116
|
+
info: (message, metadata) => log("info", message, null, { ...baseContext, metadata }),
|
|
117
|
+
debug: (message, metadata) => log("debug", message, null, { ...baseContext, metadata })
|
|
118
|
+
};
|
|
119
|
+
},
|
|
120
|
+
/**
|
|
121
|
+
* Log with explicit user context (when auth adapter is not available)
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* await errorLogger.withUser({ id: 'user-123', email: 'user@example.com' })
|
|
126
|
+
* .error('User action failed', error)
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
withUser: (user) => {
|
|
130
|
+
return {
|
|
131
|
+
error: async (message, error, context) => {
|
|
132
|
+
const cfg = getConfig();
|
|
133
|
+
try {
|
|
134
|
+
const entry = await cfg.adapter.create({
|
|
135
|
+
level: "error",
|
|
136
|
+
message,
|
|
137
|
+
stack: error?.stack || null,
|
|
138
|
+
userId: user.id,
|
|
139
|
+
userEmail: user.email || null,
|
|
140
|
+
userName: user.name || null,
|
|
141
|
+
path: context?.path || null,
|
|
142
|
+
method: context?.method || null,
|
|
143
|
+
userAgent: context?.userAgent || null,
|
|
144
|
+
ip: context?.ip || null,
|
|
145
|
+
metadata: context?.metadata || null
|
|
146
|
+
});
|
|
147
|
+
return { success: true, entry };
|
|
148
|
+
} catch (err) {
|
|
149
|
+
return {
|
|
150
|
+
success: false,
|
|
151
|
+
error: err instanceof Error ? err.message : "Unknown error"
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
warn: async (message, context) => {
|
|
156
|
+
const cfg = getConfig();
|
|
157
|
+
try {
|
|
158
|
+
const entry = await cfg.adapter.create({
|
|
159
|
+
level: "warn",
|
|
160
|
+
message,
|
|
161
|
+
stack: null,
|
|
162
|
+
userId: user.id,
|
|
163
|
+
userEmail: user.email || null,
|
|
164
|
+
userName: user.name || null,
|
|
165
|
+
path: context?.path || null,
|
|
166
|
+
method: context?.method || null,
|
|
167
|
+
userAgent: context?.userAgent || null,
|
|
168
|
+
ip: context?.ip || null,
|
|
169
|
+
metadata: context?.metadata || null
|
|
170
|
+
});
|
|
171
|
+
return { success: true, entry };
|
|
172
|
+
} catch (err) {
|
|
173
|
+
return {
|
|
174
|
+
success: false,
|
|
175
|
+
error: err instanceof Error ? err.message : "Unknown error"
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
info: async (message, context) => {
|
|
180
|
+
const cfg = getConfig();
|
|
181
|
+
try {
|
|
182
|
+
const entry = await cfg.adapter.create({
|
|
183
|
+
level: "info",
|
|
184
|
+
message,
|
|
185
|
+
stack: null,
|
|
186
|
+
userId: user.id,
|
|
187
|
+
userEmail: user.email || null,
|
|
188
|
+
userName: user.name || null,
|
|
189
|
+
path: context?.path || null,
|
|
190
|
+
method: context?.method || null,
|
|
191
|
+
userAgent: context?.userAgent || null,
|
|
192
|
+
ip: context?.ip || null,
|
|
193
|
+
metadata: context?.metadata || null
|
|
194
|
+
});
|
|
195
|
+
return { success: true, entry };
|
|
196
|
+
} catch (err) {
|
|
197
|
+
return {
|
|
198
|
+
success: false,
|
|
199
|
+
error: err instanceof Error ? err.message : "Unknown error"
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
export {
|
|
207
|
+
errorLogger,
|
|
208
|
+
getConfig,
|
|
209
|
+
initErrorLogger,
|
|
210
|
+
isInitialized
|
|
211
|
+
};
|
|
212
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logger.ts"],"sourcesContent":["import type {\n ErrorLoggerConfig,\n LogLevel,\n ErrorLogEntry,\n RequestContext,\n LogResult,\n} from './types'\n\nlet config: ErrorLoggerConfig | null = null\n\n/**\n * Initialize the error logger with your configuration\n * Must be called before using errorLogger\n *\n * @example\n * ```ts\n * import { initErrorLogger } from '@vinetechke/next-error-logger'\n * import { createPrismaAdapter } from '@vinetechke/next-error-logger/adapters/prisma'\n * import { createNextAuthAdapter } from '@vinetechke/next-error-logger/auth/next-auth'\n * import { prisma } from '@/lib/prisma'\n * import { auth } from '@/auth'\n *\n * initErrorLogger({\n * adapter: createPrismaAdapter(prisma),\n * authAdapter: createNextAuthAdapter(auth),\n * retentionDays: 30,\n * })\n * ```\n */\nexport function initErrorLogger(cfg: ErrorLoggerConfig): void {\n config = {\n consoleInDev: true,\n retentionDays: 30,\n ...cfg,\n }\n}\n\n/**\n * Get the current logger configuration\n * @throws Error if logger is not initialized\n */\nexport function getConfig(): ErrorLoggerConfig {\n if (!config) {\n throw new Error(\n '[@vinetechke/next-error-logger] Logger not initialized. Call initErrorLogger() first.',\n )\n }\n return config\n}\n\n/**\n * Check if logger is initialized\n */\nexport function isInitialized(): boolean {\n return config !== null\n}\n\n/**\n * Internal logging function\n */\nasync function log(\n level: LogLevel,\n message: string,\n error?: Error | null,\n context?: RequestContext,\n): Promise<LogResult> {\n try {\n const cfg = getConfig()\n\n // Check if this level should be captured\n if (cfg.levels && !cfg.levels.includes(level)) {\n return { success: true }\n }\n\n // Console output in development\n if (cfg.consoleInDev && process.env.NODE_ENV === 'development') {\n const consoleMethod =\n level === 'error' ? 'error' : level === 'warn' ? 'warn' : 'log'\n console[consoleMethod](\n `[${level.toUpperCase()}]`,\n message,\n error || '',\n context || '',\n )\n }\n\n // Get user context if auth adapter is provided\n let user: { id: string; email?: string; name?: string } | null = null\n if (cfg.authAdapter) {\n try {\n user = await cfg.authAdapter.getUser()\n } catch {\n // Silently ignore auth errors - user context is optional\n }\n }\n\n // Create the log entry\n const entry = await cfg.adapter.create({\n level,\n message,\n stack: error?.stack || null,\n userId: user?.id || null,\n userEmail: user?.email || null,\n userName: user?.name || null,\n path: context?.path || null,\n method: context?.method || null,\n userAgent: context?.userAgent || null,\n ip: context?.ip || null,\n metadata: context?.metadata || null,\n })\n\n return { success: true, entry }\n } catch (err) {\n // Don't throw on logging failures - just return error result\n console.error('[@vinetechke/next-error-logger] Failed to log:', err)\n return {\n success: false,\n error: err instanceof Error ? err.message : 'Unknown error',\n }\n }\n}\n\n/**\n * Extract request context from a Next.js Request object\n */\nfunction extractRequestContext(request: Request): RequestContext {\n const url = new URL(request.url)\n return {\n path: url.pathname,\n method: request.method,\n userAgent: request.headers.get('user-agent') || undefined,\n ip:\n request.headers.get('x-forwarded-for')?.split(',')[0]?.trim() ||\n request.headers.get('x-real-ip') ||\n undefined,\n }\n}\n\n/**\n * Main error logger instance\n *\n * @example\n * ```ts\n * // Simple logging\n * await errorLogger.error('Something went wrong', error)\n * await errorLogger.warn('Deprecated API used')\n * await errorLogger.info('User completed checkout')\n *\n * // With request context (in API routes)\n * const log = errorLogger.fromRequest(request)\n * await log.error('API failed', error, { orderId: '123' })\n * ```\n */\nexport const errorLogger = {\n /**\n * Log an error with optional Error object and context\n */\n error: (\n message: string,\n error?: Error,\n context?: RequestContext,\n ): Promise<LogResult> => log('error', message, error, context),\n\n /**\n * Log a warning with optional Error object and context\n */\n warn: (\n message: string,\n error?: Error,\n context?: RequestContext,\n ): Promise<LogResult> => log('warn', message, error, context),\n\n /**\n * Log an info message with optional context\n */\n info: (message: string, context?: RequestContext): Promise<LogResult> =>\n log('info', message, null, context),\n\n /**\n * Log a debug message with optional context\n */\n debug: (message: string, context?: RequestContext): Promise<LogResult> =>\n log('debug', message, null, context),\n\n /**\n * Create a logger instance bound to a specific request\n * Automatically extracts path, method, user agent, and IP\n *\n * @example\n * ```ts\n * export async function POST(request: Request) {\n * const log = errorLogger.fromRequest(request)\n *\n * try {\n * // ... your code\n * } catch (error) {\n * await log.error('Failed to process', error as Error, { orderId: '123' })\n * return new Response('Error', { status: 500 })\n * }\n * }\n * ```\n */\n fromRequest: (request: Request) => {\n const baseContext = extractRequestContext(request)\n\n return {\n error: (\n message: string,\n error?: Error,\n metadata?: Record<string, unknown>,\n ): Promise<LogResult> =>\n log('error', message, error, { ...baseContext, metadata }),\n\n warn: (\n message: string,\n metadata?: Record<string, unknown>,\n ): Promise<LogResult> =>\n log('warn', message, null, { ...baseContext, metadata }),\n\n info: (\n message: string,\n metadata?: Record<string, unknown>,\n ): Promise<LogResult> =>\n log('info', message, null, { ...baseContext, metadata }),\n\n debug: (\n message: string,\n metadata?: Record<string, unknown>,\n ): Promise<LogResult> =>\n log('debug', message, null, { ...baseContext, metadata }),\n }\n },\n\n /**\n * Log with explicit user context (when auth adapter is not available)\n *\n * @example\n * ```ts\n * await errorLogger.withUser({ id: 'user-123', email: 'user@example.com' })\n * .error('User action failed', error)\n * ```\n */\n withUser: (user: { id: string; email?: string; name?: string }) => {\n return {\n error: async (\n message: string,\n error?: Error,\n context?: RequestContext,\n ): Promise<LogResult> => {\n const cfg = getConfig()\n try {\n const entry = await cfg.adapter.create({\n level: 'error',\n message,\n stack: error?.stack || null,\n userId: user.id,\n userEmail: user.email || null,\n userName: user.name || null,\n path: context?.path || null,\n method: context?.method || null,\n userAgent: context?.userAgent || null,\n ip: context?.ip || null,\n metadata: context?.metadata || null,\n })\n return { success: true, entry }\n } catch (err) {\n return {\n success: false,\n error:\n err instanceof Error\n ? err.message\n : 'Unknown error',\n }\n }\n },\n\n warn: async (\n message: string,\n context?: RequestContext,\n ): Promise<LogResult> => {\n const cfg = getConfig()\n try {\n const entry = await cfg.adapter.create({\n level: 'warn',\n message,\n stack: null,\n userId: user.id,\n userEmail: user.email || null,\n userName: user.name || null,\n path: context?.path || null,\n method: context?.method || null,\n userAgent: context?.userAgent || null,\n ip: context?.ip || null,\n metadata: context?.metadata || null,\n })\n return { success: true, entry }\n } catch (err) {\n return {\n success: false,\n error:\n err instanceof Error\n ? err.message\n : 'Unknown error',\n }\n }\n },\n\n info: async (\n message: string,\n context?: RequestContext,\n ): Promise<LogResult> => {\n const cfg = getConfig()\n try {\n const entry = await cfg.adapter.create({\n level: 'info',\n message,\n stack: null,\n userId: user.id,\n userEmail: user.email || null,\n userName: user.name || null,\n path: context?.path || null,\n method: context?.method || null,\n userAgent: context?.userAgent || null,\n ip: context?.ip || null,\n metadata: context?.metadata || null,\n })\n return { success: true, entry }\n } catch (err) {\n return {\n success: false,\n error:\n err instanceof Error\n ? err.message\n : 'Unknown error',\n }\n }\n },\n }\n },\n}\n"],"mappings":";;;AAQA,IAAI,SAAmC;AAqBhC,SAAS,gBAAgB,KAA8B;AAC1D,WAAS;AAAA,IACL,cAAc;AAAA,IACd,eAAe;AAAA,IACf,GAAG;AAAA,EACP;AACJ;AAMO,SAAS,YAA+B;AAC3C,MAAI,CAAC,QAAQ;AACT,UAAM,IAAI;AAAA,MACN;AAAA,IACJ;AAAA,EACJ;AACA,SAAO;AACX;AAKO,SAAS,gBAAyB;AACrC,SAAO,WAAW;AACtB;AAKA,eAAe,IACX,OACA,SACA,OACA,SACkB;AAClB,MAAI;AACA,UAAM,MAAM,UAAU;AAGtB,QAAI,IAAI,UAAU,CAAC,IAAI,OAAO,SAAS,KAAK,GAAG;AAC3C,aAAO,EAAE,SAAS,KAAK;AAAA,IAC3B;AAGA,QAAI,IAAI,gBAAgB,QAAQ,IAAI,aAAa,eAAe;AAC5D,YAAM,gBACF,UAAU,UAAU,UAAU,UAAU,SAAS,SAAS;AAC9D,cAAQ,aAAa;AAAA,QACjB,IAAI,MAAM,YAAY,CAAC;AAAA,QACvB;AAAA,QACA,SAAS;AAAA,QACT,WAAW;AAAA,MACf;AAAA,IACJ;AAGA,QAAI,OAA6D;AACjE,QAAI,IAAI,aAAa;AACjB,UAAI;AACA,eAAO,MAAM,IAAI,YAAY,QAAQ;AAAA,MACzC,QAAQ;AAAA,MAER;AAAA,IACJ;AAGA,UAAM,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J;","names":[]}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/schemas/drizzle.ts
|
|
22
|
+
var drizzle_exports = {};
|
|
23
|
+
__export(drizzle_exports, {
|
|
24
|
+
mysqlSchema: () => mysqlSchema,
|
|
25
|
+
postgresSchema: () => postgresSchema,
|
|
26
|
+
sqliteSchema: () => sqliteSchema
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(drizzle_exports);
|
|
29
|
+
var postgresSchema = `
|
|
30
|
+
import { pgTable, text, timestamp, json, index } from 'drizzle-orm/pg-core'
|
|
31
|
+
|
|
32
|
+
export const errorLogs = pgTable('error_logs', {
|
|
33
|
+
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
34
|
+
level: text('level').notNull(),
|
|
35
|
+
message: text('message').notNull(),
|
|
36
|
+
stack: text('stack'),
|
|
37
|
+
userId: text('user_id'),
|
|
38
|
+
userEmail: text('user_email'),
|
|
39
|
+
userName: text('user_name'),
|
|
40
|
+
path: text('path'),
|
|
41
|
+
method: text('method'),
|
|
42
|
+
userAgent: text('user_agent'),
|
|
43
|
+
ip: text('ip'),
|
|
44
|
+
metadata: json('metadata'),
|
|
45
|
+
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
46
|
+
}, (table) => ({
|
|
47
|
+
levelIdx: index('error_logs_level_idx').on(table.level),
|
|
48
|
+
userIdIdx: index('error_logs_user_id_idx').on(table.userId),
|
|
49
|
+
createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),
|
|
50
|
+
}))
|
|
51
|
+
`;
|
|
52
|
+
var mysqlSchema = `
|
|
53
|
+
import { mysqlTable, text, varchar, timestamp, json, index } from 'drizzle-orm/mysql-core'
|
|
54
|
+
|
|
55
|
+
export const errorLogs = mysqlTable('error_logs', {
|
|
56
|
+
id: varchar('id', { length: 36 }).primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
57
|
+
level: varchar('level', { length: 10 }).notNull(),
|
|
58
|
+
message: text('message').notNull(),
|
|
59
|
+
stack: text('stack'),
|
|
60
|
+
userId: varchar('user_id', { length: 255 }),
|
|
61
|
+
userEmail: varchar('user_email', { length: 255 }),
|
|
62
|
+
userName: varchar('user_name', { length: 255 }),
|
|
63
|
+
path: varchar('path', { length: 500 }),
|
|
64
|
+
method: varchar('method', { length: 10 }),
|
|
65
|
+
userAgent: text('user_agent'),
|
|
66
|
+
ip: varchar('ip', { length: 45 }),
|
|
67
|
+
metadata: json('metadata'),
|
|
68
|
+
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
69
|
+
}, (table) => ({
|
|
70
|
+
levelIdx: index('error_logs_level_idx').on(table.level),
|
|
71
|
+
userIdIdx: index('error_logs_user_id_idx').on(table.userId),
|
|
72
|
+
createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),
|
|
73
|
+
}))
|
|
74
|
+
`;
|
|
75
|
+
var sqliteSchema = `
|
|
76
|
+
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'
|
|
77
|
+
|
|
78
|
+
export const errorLogs = sqliteTable('error_logs', {
|
|
79
|
+
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
80
|
+
level: text('level').notNull(),
|
|
81
|
+
message: text('message').notNull(),
|
|
82
|
+
stack: text('stack'),
|
|
83
|
+
userId: text('user_id'),
|
|
84
|
+
userEmail: text('user_email'),
|
|
85
|
+
userName: text('user_name'),
|
|
86
|
+
path: text('path'),
|
|
87
|
+
method: text('method'),
|
|
88
|
+
userAgent: text('user_agent'),
|
|
89
|
+
ip: text('ip'),
|
|
90
|
+
metadata: text('metadata', { mode: 'json' }),
|
|
91
|
+
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
|
92
|
+
})
|
|
93
|
+
`;
|
|
94
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
95
|
+
0 && (module.exports = {
|
|
96
|
+
mysqlSchema,
|
|
97
|
+
postgresSchema,
|
|
98
|
+
sqliteSchema
|
|
99
|
+
});
|
|
100
|
+
//# sourceMappingURL=drizzle.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schemas/drizzle.ts"],"sourcesContent":["/**\n * Example Drizzle schema for the error_logs table\n *\n * Copy this to your project and adjust as needed.\n *\n * @example\n * ```ts\n * // lib/schema.ts\n * import { pgTable, text, timestamp, json } from 'drizzle-orm/pg-core'\n *\n * export const errorLogs = pgTable('error_logs', {\n * id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),\n * level: text('level').notNull(),\n * message: text('message').notNull(),\n * stack: text('stack'),\n * userId: text('user_id'),\n * userEmail: text('user_email'),\n * userName: text('user_name'),\n * path: text('path'),\n * method: text('method'),\n * userAgent: text('user_agent'),\n * ip: text('ip'),\n * metadata: json('metadata'),\n * createdAt: timestamp('created_at').defaultNow().notNull(),\n * })\n * ```\n */\n\n// PostgreSQL schema (using drizzle-orm/pg-core)\nexport const postgresSchema = `\nimport { pgTable, text, timestamp, json, index } from 'drizzle-orm/pg-core'\n\nexport const errorLogs = pgTable('error_logs', {\n id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: text('level').notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: text('user_id'),\n userEmail: text('user_email'),\n userName: text('user_name'),\n path: text('path'),\n method: text('method'),\n userAgent: text('user_agent'),\n ip: text('ip'),\n metadata: json('metadata'),\n createdAt: timestamp('created_at').defaultNow().notNull(),\n}, (table) => ({\n levelIdx: index('error_logs_level_idx').on(table.level),\n userIdIdx: index('error_logs_user_id_idx').on(table.userId),\n createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),\n}))\n`\n\n// MySQL schema (using drizzle-orm/mysql-core)\nexport const mysqlSchema = `\nimport { mysqlTable, text, varchar, timestamp, json, index } from 'drizzle-orm/mysql-core'\n\nexport const errorLogs = mysqlTable('error_logs', {\n id: varchar('id', { length: 36 }).primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: varchar('level', { length: 10 }).notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: varchar('user_id', { length: 255 }),\n userEmail: varchar('user_email', { length: 255 }),\n userName: varchar('user_name', { length: 255 }),\n path: varchar('path', { length: 500 }),\n method: varchar('method', { length: 10 }),\n userAgent: text('user_agent'),\n ip: varchar('ip', { length: 45 }),\n metadata: json('metadata'),\n createdAt: timestamp('created_at').defaultNow().notNull(),\n}, (table) => ({\n levelIdx: index('error_logs_level_idx').on(table.level),\n userIdIdx: index('error_logs_user_id_idx').on(table.userId),\n createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),\n}))\n`\n\n// SQLite schema (using drizzle-orm/sqlite-core)\nexport const sqliteSchema = `\nimport { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'\n\nexport const errorLogs = sqliteTable('error_logs', {\n id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: text('level').notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: text('user_id'),\n userEmail: text('user_email'),\n userName: text('user_name'),\n path: text('path'),\n method: text('method'),\n userAgent: text('user_agent'),\n ip: text('ip'),\n metadata: text('metadata', { mode: 'json' }),\n createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),\n})\n`\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6BO,IAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBvB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBpB,IAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example Drizzle schema for the error_logs table
|
|
3
|
+
*
|
|
4
|
+
* Copy this to your project and adjust as needed.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* // lib/schema.ts
|
|
9
|
+
* import { pgTable, text, timestamp, json } from 'drizzle-orm/pg-core'
|
|
10
|
+
*
|
|
11
|
+
* export const errorLogs = pgTable('error_logs', {
|
|
12
|
+
* id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
13
|
+
* level: text('level').notNull(),
|
|
14
|
+
* message: text('message').notNull(),
|
|
15
|
+
* stack: text('stack'),
|
|
16
|
+
* userId: text('user_id'),
|
|
17
|
+
* userEmail: text('user_email'),
|
|
18
|
+
* userName: text('user_name'),
|
|
19
|
+
* path: text('path'),
|
|
20
|
+
* method: text('method'),
|
|
21
|
+
* userAgent: text('user_agent'),
|
|
22
|
+
* ip: text('ip'),
|
|
23
|
+
* metadata: json('metadata'),
|
|
24
|
+
* createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare const postgresSchema = "\nimport { pgTable, text, timestamp, json, index } from 'drizzle-orm/pg-core'\n\nexport const errorLogs = pgTable('error_logs', {\n id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: text('level').notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: text('user_id'),\n userEmail: text('user_email'),\n userName: text('user_name'),\n path: text('path'),\n method: text('method'),\n userAgent: text('user_agent'),\n ip: text('ip'),\n metadata: json('metadata'),\n createdAt: timestamp('created_at').defaultNow().notNull(),\n}, (table) => ({\n levelIdx: index('error_logs_level_idx').on(table.level),\n userIdIdx: index('error_logs_user_id_idx').on(table.userId),\n createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),\n}))\n";
|
|
29
|
+
declare const mysqlSchema = "\nimport { mysqlTable, text, varchar, timestamp, json, index } from 'drizzle-orm/mysql-core'\n\nexport const errorLogs = mysqlTable('error_logs', {\n id: varchar('id', { length: 36 }).primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: varchar('level', { length: 10 }).notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: varchar('user_id', { length: 255 }),\n userEmail: varchar('user_email', { length: 255 }),\n userName: varchar('user_name', { length: 255 }),\n path: varchar('path', { length: 500 }),\n method: varchar('method', { length: 10 }),\n userAgent: text('user_agent'),\n ip: varchar('ip', { length: 45 }),\n metadata: json('metadata'),\n createdAt: timestamp('created_at').defaultNow().notNull(),\n}, (table) => ({\n levelIdx: index('error_logs_level_idx').on(table.level),\n userIdIdx: index('error_logs_user_id_idx').on(table.userId),\n createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),\n}))\n";
|
|
30
|
+
declare const sqliteSchema = "\nimport { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'\n\nexport const errorLogs = sqliteTable('error_logs', {\n id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: text('level').notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: text('user_id'),\n userEmail: text('user_email'),\n userName: text('user_name'),\n path: text('path'),\n method: text('method'),\n userAgent: text('user_agent'),\n ip: text('ip'),\n metadata: text('metadata', { mode: 'json' }),\n createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),\n})\n";
|
|
31
|
+
|
|
32
|
+
export { mysqlSchema, postgresSchema, sqliteSchema };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example Drizzle schema for the error_logs table
|
|
3
|
+
*
|
|
4
|
+
* Copy this to your project and adjust as needed.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* // lib/schema.ts
|
|
9
|
+
* import { pgTable, text, timestamp, json } from 'drizzle-orm/pg-core'
|
|
10
|
+
*
|
|
11
|
+
* export const errorLogs = pgTable('error_logs', {
|
|
12
|
+
* id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
13
|
+
* level: text('level').notNull(),
|
|
14
|
+
* message: text('message').notNull(),
|
|
15
|
+
* stack: text('stack'),
|
|
16
|
+
* userId: text('user_id'),
|
|
17
|
+
* userEmail: text('user_email'),
|
|
18
|
+
* userName: text('user_name'),
|
|
19
|
+
* path: text('path'),
|
|
20
|
+
* method: text('method'),
|
|
21
|
+
* userAgent: text('user_agent'),
|
|
22
|
+
* ip: text('ip'),
|
|
23
|
+
* metadata: json('metadata'),
|
|
24
|
+
* createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
declare const postgresSchema = "\nimport { pgTable, text, timestamp, json, index } from 'drizzle-orm/pg-core'\n\nexport const errorLogs = pgTable('error_logs', {\n id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: text('level').notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: text('user_id'),\n userEmail: text('user_email'),\n userName: text('user_name'),\n path: text('path'),\n method: text('method'),\n userAgent: text('user_agent'),\n ip: text('ip'),\n metadata: json('metadata'),\n createdAt: timestamp('created_at').defaultNow().notNull(),\n}, (table) => ({\n levelIdx: index('error_logs_level_idx').on(table.level),\n userIdIdx: index('error_logs_user_id_idx').on(table.userId),\n createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),\n}))\n";
|
|
29
|
+
declare const mysqlSchema = "\nimport { mysqlTable, text, varchar, timestamp, json, index } from 'drizzle-orm/mysql-core'\n\nexport const errorLogs = mysqlTable('error_logs', {\n id: varchar('id', { length: 36 }).primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: varchar('level', { length: 10 }).notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: varchar('user_id', { length: 255 }),\n userEmail: varchar('user_email', { length: 255 }),\n userName: varchar('user_name', { length: 255 }),\n path: varchar('path', { length: 500 }),\n method: varchar('method', { length: 10 }),\n userAgent: text('user_agent'),\n ip: varchar('ip', { length: 45 }),\n metadata: json('metadata'),\n createdAt: timestamp('created_at').defaultNow().notNull(),\n}, (table) => ({\n levelIdx: index('error_logs_level_idx').on(table.level),\n userIdIdx: index('error_logs_user_id_idx').on(table.userId),\n createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),\n}))\n";
|
|
30
|
+
declare const sqliteSchema = "\nimport { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'\n\nexport const errorLogs = sqliteTable('error_logs', {\n id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: text('level').notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: text('user_id'),\n userEmail: text('user_email'),\n userName: text('user_name'),\n path: text('path'),\n method: text('method'),\n userAgent: text('user_agent'),\n ip: text('ip'),\n metadata: text('metadata', { mode: 'json' }),\n createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),\n})\n";
|
|
31
|
+
|
|
32
|
+
export { mysqlSchema, postgresSchema, sqliteSchema };
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/schemas/drizzle.ts
|
|
4
|
+
var postgresSchema = `
|
|
5
|
+
import { pgTable, text, timestamp, json, index } from 'drizzle-orm/pg-core'
|
|
6
|
+
|
|
7
|
+
export const errorLogs = pgTable('error_logs', {
|
|
8
|
+
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
9
|
+
level: text('level').notNull(),
|
|
10
|
+
message: text('message').notNull(),
|
|
11
|
+
stack: text('stack'),
|
|
12
|
+
userId: text('user_id'),
|
|
13
|
+
userEmail: text('user_email'),
|
|
14
|
+
userName: text('user_name'),
|
|
15
|
+
path: text('path'),
|
|
16
|
+
method: text('method'),
|
|
17
|
+
userAgent: text('user_agent'),
|
|
18
|
+
ip: text('ip'),
|
|
19
|
+
metadata: json('metadata'),
|
|
20
|
+
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
21
|
+
}, (table) => ({
|
|
22
|
+
levelIdx: index('error_logs_level_idx').on(table.level),
|
|
23
|
+
userIdIdx: index('error_logs_user_id_idx').on(table.userId),
|
|
24
|
+
createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),
|
|
25
|
+
}))
|
|
26
|
+
`;
|
|
27
|
+
var mysqlSchema = `
|
|
28
|
+
import { mysqlTable, text, varchar, timestamp, json, index } from 'drizzle-orm/mysql-core'
|
|
29
|
+
|
|
30
|
+
export const errorLogs = mysqlTable('error_logs', {
|
|
31
|
+
id: varchar('id', { length: 36 }).primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
32
|
+
level: varchar('level', { length: 10 }).notNull(),
|
|
33
|
+
message: text('message').notNull(),
|
|
34
|
+
stack: text('stack'),
|
|
35
|
+
userId: varchar('user_id', { length: 255 }),
|
|
36
|
+
userEmail: varchar('user_email', { length: 255 }),
|
|
37
|
+
userName: varchar('user_name', { length: 255 }),
|
|
38
|
+
path: varchar('path', { length: 500 }),
|
|
39
|
+
method: varchar('method', { length: 10 }),
|
|
40
|
+
userAgent: text('user_agent'),
|
|
41
|
+
ip: varchar('ip', { length: 45 }),
|
|
42
|
+
metadata: json('metadata'),
|
|
43
|
+
createdAt: timestamp('created_at').defaultNow().notNull(),
|
|
44
|
+
}, (table) => ({
|
|
45
|
+
levelIdx: index('error_logs_level_idx').on(table.level),
|
|
46
|
+
userIdIdx: index('error_logs_user_id_idx').on(table.userId),
|
|
47
|
+
createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),
|
|
48
|
+
}))
|
|
49
|
+
`;
|
|
50
|
+
var sqliteSchema = `
|
|
51
|
+
import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'
|
|
52
|
+
|
|
53
|
+
export const errorLogs = sqliteTable('error_logs', {
|
|
54
|
+
id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),
|
|
55
|
+
level: text('level').notNull(),
|
|
56
|
+
message: text('message').notNull(),
|
|
57
|
+
stack: text('stack'),
|
|
58
|
+
userId: text('user_id'),
|
|
59
|
+
userEmail: text('user_email'),
|
|
60
|
+
userName: text('user_name'),
|
|
61
|
+
path: text('path'),
|
|
62
|
+
method: text('method'),
|
|
63
|
+
userAgent: text('user_agent'),
|
|
64
|
+
ip: text('ip'),
|
|
65
|
+
metadata: text('metadata', { mode: 'json' }),
|
|
66
|
+
createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),
|
|
67
|
+
})
|
|
68
|
+
`;
|
|
69
|
+
export {
|
|
70
|
+
mysqlSchema,
|
|
71
|
+
postgresSchema,
|
|
72
|
+
sqliteSchema
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=drizzle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/schemas/drizzle.ts"],"sourcesContent":["/**\n * Example Drizzle schema for the error_logs table\n *\n * Copy this to your project and adjust as needed.\n *\n * @example\n * ```ts\n * // lib/schema.ts\n * import { pgTable, text, timestamp, json } from 'drizzle-orm/pg-core'\n *\n * export const errorLogs = pgTable('error_logs', {\n * id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),\n * level: text('level').notNull(),\n * message: text('message').notNull(),\n * stack: text('stack'),\n * userId: text('user_id'),\n * userEmail: text('user_email'),\n * userName: text('user_name'),\n * path: text('path'),\n * method: text('method'),\n * userAgent: text('user_agent'),\n * ip: text('ip'),\n * metadata: json('metadata'),\n * createdAt: timestamp('created_at').defaultNow().notNull(),\n * })\n * ```\n */\n\n// PostgreSQL schema (using drizzle-orm/pg-core)\nexport const postgresSchema = `\nimport { pgTable, text, timestamp, json, index } from 'drizzle-orm/pg-core'\n\nexport const errorLogs = pgTable('error_logs', {\n id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: text('level').notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: text('user_id'),\n userEmail: text('user_email'),\n userName: text('user_name'),\n path: text('path'),\n method: text('method'),\n userAgent: text('user_agent'),\n ip: text('ip'),\n metadata: json('metadata'),\n createdAt: timestamp('created_at').defaultNow().notNull(),\n}, (table) => ({\n levelIdx: index('error_logs_level_idx').on(table.level),\n userIdIdx: index('error_logs_user_id_idx').on(table.userId),\n createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),\n}))\n`\n\n// MySQL schema (using drizzle-orm/mysql-core)\nexport const mysqlSchema = `\nimport { mysqlTable, text, varchar, timestamp, json, index } from 'drizzle-orm/mysql-core'\n\nexport const errorLogs = mysqlTable('error_logs', {\n id: varchar('id', { length: 36 }).primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: varchar('level', { length: 10 }).notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: varchar('user_id', { length: 255 }),\n userEmail: varchar('user_email', { length: 255 }),\n userName: varchar('user_name', { length: 255 }),\n path: varchar('path', { length: 500 }),\n method: varchar('method', { length: 10 }),\n userAgent: text('user_agent'),\n ip: varchar('ip', { length: 45 }),\n metadata: json('metadata'),\n createdAt: timestamp('created_at').defaultNow().notNull(),\n}, (table) => ({\n levelIdx: index('error_logs_level_idx').on(table.level),\n userIdIdx: index('error_logs_user_id_idx').on(table.userId),\n createdAtIdx: index('error_logs_created_at_idx').on(table.createdAt),\n}))\n`\n\n// SQLite schema (using drizzle-orm/sqlite-core)\nexport const sqliteSchema = `\nimport { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'\n\nexport const errorLogs = sqliteTable('error_logs', {\n id: text('id').primaryKey().$defaultFn(() => crypto.randomUUID()),\n level: text('level').notNull(),\n message: text('message').notNull(),\n stack: text('stack'),\n userId: text('user_id'),\n userEmail: text('user_email'),\n userName: text('user_name'),\n path: text('path'),\n method: text('method'),\n userAgent: text('user_agent'),\n ip: text('ip'),\n metadata: text('metadata', { mode: 'json' }),\n createdAt: integer('created_at', { mode: 'timestamp' }).notNull().$defaultFn(() => new Date()),\n})\n`\n"],"mappings":";;;AA6BO,IAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBvB,IAAM,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBpB,IAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
|