@naisys/hub-database 3.0.0-beta.4 → 3.0.0-beta.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/dbConfig.js +1 -1
  2. package/dist/generated/prisma/browser.js +4 -4
  3. package/dist/generated/prisma/client.js +5 -5
  4. package/dist/generated/prisma/commonInputTypes.js +1 -1
  5. package/dist/generated/prisma/enums.js +34 -34
  6. package/dist/generated/prisma/internal/class.js +36 -28
  7. package/dist/generated/prisma/internal/prismaNamespace.js +150 -147
  8. package/dist/generated/prisma/internal/prismaNamespaceBrowser.js +142 -142
  9. package/dist/hubDatabaseService.js +30 -30
  10. package/dist/hubSessionService.js +59 -71
  11. package/dist/index.js +10 -2
  12. package/dist/prismaClient.js +12 -12
  13. package/package.json +6 -4
  14. package/dist/dbConfig.d.ts +0 -2
  15. package/dist/generated/prisma/browser.d.ts +0 -80
  16. package/dist/generated/prisma/client.d.ts +0 -99
  17. package/dist/generated/prisma/commonInputTypes.d.ts +0 -758
  18. package/dist/generated/prisma/enums.d.ts +0 -57
  19. package/dist/generated/prisma/internal/class.d.ts +0 -285
  20. package/dist/generated/prisma/internal/prismaNamespace.d.ts +0 -1777
  21. package/dist/generated/prisma/internal/prismaNamespaceBrowser.d.ts +0 -223
  22. package/dist/generated/prisma/models/attachments.d.ts +0 -1624
  23. package/dist/generated/prisma/models/config_revisions.d.ts +0 -1320
  24. package/dist/generated/prisma/models/context_log.d.ts +0 -1889
  25. package/dist/generated/prisma/models/costs.d.ts +0 -1834
  26. package/dist/generated/prisma/models/hosts.d.ts +0 -1892
  27. package/dist/generated/prisma/models/mail_attachments.d.ts +0 -1244
  28. package/dist/generated/prisma/models/mail_messages.d.ts +0 -1721
  29. package/dist/generated/prisma/models/mail_recipients.d.ts +0 -1409
  30. package/dist/generated/prisma/models/models.d.ts +0 -1175
  31. package/dist/generated/prisma/models/run_session.d.ts +0 -1894
  32. package/dist/generated/prisma/models/schema_version.d.ts +0 -984
  33. package/dist/generated/prisma/models/user_hosts.d.ts +0 -1244
  34. package/dist/generated/prisma/models/user_notifications.d.ts +0 -1543
  35. package/dist/generated/prisma/models/users.d.ts +0 -3229
  36. package/dist/generated/prisma/models/variables.d.ts +0 -1052
  37. package/dist/generated/prisma/models.d.ts +0 -17
  38. package/dist/hubDatabaseService.d.ts +0 -7
  39. package/dist/hubSessionService.d.ts +0 -41
  40. package/dist/index.d.ts +0 -8
  41. package/dist/prismaClient.d.ts +0 -7
@@ -1,7 +1,7 @@
1
1
  /* !!! This is code generated by Prisma. Do not edit directly. !!! */
2
2
  /* eslint-disable */
3
3
  // biome-ignore-all lint: generated file
4
- // @ts-nocheck
4
+ // @ts-nocheck
5
5
  /*
6
6
  * WARNING: This is an internal file that is subject to change!
7
7
  *
@@ -16,9 +16,9 @@
16
16
  import * as runtime from "@prisma/client/runtime/index-browser";
17
17
  export const Decimal = runtime.Decimal;
18
18
  export const NullTypes = {
19
- DbNull: runtime.NullTypes.DbNull,
20
- JsonNull: runtime.NullTypes.JsonNull,
21
- AnyNull: runtime.NullTypes.AnyNull,
19
+ DbNull: runtime.NullTypes.DbNull,
20
+ JsonNull: runtime.NullTypes.JsonNull,
21
+ AnyNull: runtime.NullTypes.AnyNull,
22
22
  };
23
23
  /**
24
24
  * Helper for filtering JSON entries that have `null` on the database (empty on the db)
@@ -39,181 +39,181 @@ export const JsonNull = runtime.JsonNull;
39
39
  */
40
40
  export const AnyNull = runtime.AnyNull;
41
41
  export const ModelName = {
42
- context_log: 'context_log',
43
- costs: 'costs',
44
- mail_messages: 'mail_messages',
45
- attachments: 'attachments',
46
- mail_attachments: 'mail_attachments',
47
- mail_recipients: 'mail_recipients',
48
- users: 'users',
49
- user_notifications: 'user_notifications',
50
- user_hosts: 'user_hosts',
51
- run_session: 'run_session',
52
- schema_version: 'schema_version',
53
- hosts: 'hosts',
54
- config_revisions: 'config_revisions',
55
- variables: 'variables',
56
- models: 'models'
42
+ context_log: "context_log",
43
+ costs: "costs",
44
+ mail_messages: "mail_messages",
45
+ attachments: "attachments",
46
+ mail_attachments: "mail_attachments",
47
+ mail_recipients: "mail_recipients",
48
+ users: "users",
49
+ user_notifications: "user_notifications",
50
+ user_hosts: "user_hosts",
51
+ run_session: "run_session",
52
+ schema_version: "schema_version",
53
+ hosts: "hosts",
54
+ config_revisions: "config_revisions",
55
+ variables: "variables",
56
+ models: "models",
57
57
  };
58
58
  /*
59
59
  * Enums
60
60
  */
61
61
  export const TransactionIsolationLevel = runtime.makeStrictEnum({
62
- Serializable: 'Serializable'
62
+ Serializable: "Serializable",
63
63
  });
64
64
  export const Context_logScalarFieldEnum = {
65
- id: 'id',
66
- user_id: 'user_id',
67
- run_id: 'run_id',
68
- session_id: 'session_id',
69
- host_id: 'host_id',
70
- role: 'role',
71
- source: 'source',
72
- type: 'type',
73
- message: 'message',
74
- attachment_id: 'attachment_id',
75
- created_at: 'created_at'
65
+ id: "id",
66
+ user_id: "user_id",
67
+ run_id: "run_id",
68
+ session_id: "session_id",
69
+ host_id: "host_id",
70
+ role: "role",
71
+ source: "source",
72
+ type: "type",
73
+ message: "message",
74
+ attachment_id: "attachment_id",
75
+ created_at: "created_at",
76
76
  };
77
77
  export const CostsScalarFieldEnum = {
78
- id: 'id',
79
- user_id: 'user_id',
80
- run_id: 'run_id',
81
- session_id: 'session_id',
82
- host_id: 'host_id',
83
- source: 'source',
84
- model: 'model',
85
- cost: 'cost',
86
- input_tokens: 'input_tokens',
87
- output_tokens: 'output_tokens',
88
- cache_write_tokens: 'cache_write_tokens',
89
- cache_read_tokens: 'cache_read_tokens',
90
- created_at: 'created_at'
78
+ id: "id",
79
+ user_id: "user_id",
80
+ run_id: "run_id",
81
+ session_id: "session_id",
82
+ host_id: "host_id",
83
+ source: "source",
84
+ model: "model",
85
+ cost: "cost",
86
+ input_tokens: "input_tokens",
87
+ output_tokens: "output_tokens",
88
+ cache_write_tokens: "cache_write_tokens",
89
+ cache_read_tokens: "cache_read_tokens",
90
+ created_at: "created_at",
91
91
  };
92
92
  export const Mail_messagesScalarFieldEnum = {
93
- id: 'id',
94
- from_user_id: 'from_user_id',
95
- host_id: 'host_id',
96
- kind: 'kind',
97
- participants: 'participants',
98
- subject: 'subject',
99
- body: 'body',
100
- created_at: 'created_at'
93
+ id: "id",
94
+ from_user_id: "from_user_id",
95
+ host_id: "host_id",
96
+ kind: "kind",
97
+ participants: "participants",
98
+ subject: "subject",
99
+ body: "body",
100
+ created_at: "created_at",
101
101
  };
102
102
  export const AttachmentsScalarFieldEnum = {
103
- id: 'id',
104
- public_id: 'public_id',
105
- filepath: 'filepath',
106
- filename: 'filename',
107
- file_size: 'file_size',
108
- file_hash: 'file_hash',
109
- purpose: 'purpose',
110
- uploaded_by: 'uploaded_by',
111
- created_at: 'created_at'
103
+ id: "id",
104
+ public_id: "public_id",
105
+ filepath: "filepath",
106
+ filename: "filename",
107
+ file_size: "file_size",
108
+ file_hash: "file_hash",
109
+ purpose: "purpose",
110
+ uploaded_by: "uploaded_by",
111
+ created_at: "created_at",
112
112
  };
113
113
  export const Mail_attachmentsScalarFieldEnum = {
114
- message_id: 'message_id',
115
- attachment_id: 'attachment_id',
116
- created_at: 'created_at'
114
+ message_id: "message_id",
115
+ attachment_id: "attachment_id",
116
+ created_at: "created_at",
117
117
  };
118
118
  export const Mail_recipientsScalarFieldEnum = {
119
- id: 'id',
120
- message_id: 'message_id',
121
- user_id: 'user_id',
122
- type: 'type',
123
- read_at: 'read_at',
124
- archived_at: 'archived_at',
125
- created_at: 'created_at'
119
+ id: "id",
120
+ message_id: "message_id",
121
+ user_id: "user_id",
122
+ type: "type",
123
+ read_at: "read_at",
124
+ archived_at: "archived_at",
125
+ created_at: "created_at",
126
126
  };
127
127
  export const UsersScalarFieldEnum = {
128
- id: 'id',
129
- uuid: 'uuid',
130
- username: 'username',
131
- title: 'title',
132
- api_key: 'api_key',
133
- lead_user_id: 'lead_user_id',
134
- config: 'config',
135
- created_at: 'created_at',
136
- updated_at: 'updated_at',
137
- enabled: 'enabled',
138
- archived: 'archived'
128
+ id: "id",
129
+ uuid: "uuid",
130
+ username: "username",
131
+ title: "title",
132
+ api_key: "api_key",
133
+ lead_user_id: "lead_user_id",
134
+ config: "config",
135
+ created_at: "created_at",
136
+ updated_at: "updated_at",
137
+ enabled: "enabled",
138
+ archived: "archived",
139
139
  };
140
140
  export const User_notificationsScalarFieldEnum = {
141
- user_id: 'user_id',
142
- latest_host_id: 'latest_host_id',
143
- latest_log_id: 'latest_log_id',
144
- latest_mail_id: 'latest_mail_id',
145
- latest_chat_id: 'latest_chat_id',
146
- last_active: 'last_active',
147
- cost_suspended_reason: 'cost_suspended_reason',
148
- spend_limit_reset_at: 'spend_limit_reset_at',
149
- budget_left: 'budget_left',
150
- updated_at: 'updated_at'
141
+ user_id: "user_id",
142
+ latest_host_id: "latest_host_id",
143
+ latest_log_id: "latest_log_id",
144
+ latest_mail_id: "latest_mail_id",
145
+ latest_chat_id: "latest_chat_id",
146
+ last_active: "last_active",
147
+ cost_suspended_reason: "cost_suspended_reason",
148
+ spend_limit_reset_at: "spend_limit_reset_at",
149
+ budget_left: "budget_left",
150
+ updated_at: "updated_at",
151
151
  };
152
152
  export const User_hostsScalarFieldEnum = {
153
- user_id: 'user_id',
154
- host_id: 'host_id',
155
- created_at: 'created_at'
153
+ user_id: "user_id",
154
+ host_id: "host_id",
155
+ created_at: "created_at",
156
156
  };
157
157
  export const Run_sessionScalarFieldEnum = {
158
- user_id: 'user_id',
159
- run_id: 'run_id',
160
- session_id: 'session_id',
161
- host_id: 'host_id',
162
- last_active: 'last_active',
163
- model_name: 'model_name',
164
- latest_log_id: 'latest_log_id',
165
- total_lines: 'total_lines',
166
- total_cost: 'total_cost',
167
- created_at: 'created_at',
168
- updated_at: 'updated_at'
158
+ user_id: "user_id",
159
+ run_id: "run_id",
160
+ session_id: "session_id",
161
+ host_id: "host_id",
162
+ last_active: "last_active",
163
+ model_name: "model_name",
164
+ latest_log_id: "latest_log_id",
165
+ total_lines: "total_lines",
166
+ total_cost: "total_cost",
167
+ created_at: "created_at",
168
+ updated_at: "updated_at",
169
169
  };
170
170
  export const Schema_versionScalarFieldEnum = {
171
- id: 'id',
172
- version: 'version',
173
- updated: 'updated'
171
+ id: "id",
172
+ version: "version",
173
+ updated: "updated",
174
174
  };
175
175
  export const HostsScalarFieldEnum = {
176
- id: 'id',
177
- name: 'name',
178
- restricted: 'restricted',
179
- host_type: 'host_type',
180
- last_ip: 'last_ip',
181
- last_active: 'last_active',
182
- created_at: 'created_at'
176
+ id: "id",
177
+ name: "name",
178
+ restricted: "restricted",
179
+ host_type: "host_type",
180
+ last_ip: "last_ip",
181
+ last_active: "last_active",
182
+ created_at: "created_at",
183
183
  };
184
184
  export const Config_revisionsScalarFieldEnum = {
185
- id: 'id',
186
- user_id: 'user_id',
187
- config: 'config',
188
- changed_by_id: 'changed_by_id',
189
- created_at: 'created_at'
185
+ id: "id",
186
+ user_id: "user_id",
187
+ config: "config",
188
+ changed_by_id: "changed_by_id",
189
+ created_at: "created_at",
190
190
  };
191
191
  export const VariablesScalarFieldEnum = {
192
- key: 'key',
193
- value: 'value',
194
- export_to_shell: 'export_to_shell',
195
- created_by: 'created_by',
196
- updated_by: 'updated_by',
197
- created_at: 'created_at',
198
- updated_at: 'updated_at'
192
+ key: "key",
193
+ value: "value",
194
+ export_to_shell: "export_to_shell",
195
+ created_by: "created_by",
196
+ updated_by: "updated_by",
197
+ created_at: "created_at",
198
+ updated_at: "updated_at",
199
199
  };
200
200
  export const ModelsScalarFieldEnum = {
201
- id: 'id',
202
- key: 'key',
203
- type: 'type',
204
- label: 'label',
205
- version_name: 'version_name',
206
- is_builtin: 'is_builtin',
207
- is_custom: 'is_custom',
208
- meta: 'meta',
209
- created_at: 'created_at',
210
- updated_at: 'updated_at'
201
+ id: "id",
202
+ key: "key",
203
+ type: "type",
204
+ label: "label",
205
+ version_name: "version_name",
206
+ is_builtin: "is_builtin",
207
+ is_custom: "is_custom",
208
+ meta: "meta",
209
+ created_at: "created_at",
210
+ updated_at: "updated_at",
211
211
  };
212
212
  export const SortOrder = {
213
- asc: 'asc',
214
- desc: 'desc'
213
+ asc: "asc",
214
+ desc: "desc",
215
215
  };
216
216
  export const NullsOrder = {
217
- first: 'first',
218
- last: 'last'
217
+ first: "first",
218
+ last: "last",
219
219
  };
@@ -5,34 +5,34 @@ import { fileURLToPath } from "url";
5
5
  import { hubDbPath } from "./dbConfig.js";
6
6
  import { createPrismaClient } from "./prismaClient.js";
7
7
  export async function createHubDatabaseService() {
8
- /** We run migration scripts if this is greater than what's in the schema_version table */
9
- const HUB_DB_VERSION = 34;
10
- const dbPath = hubDbPath();
11
- // Ensure database directory exists
12
- const databaseDir = dirname(dbPath);
13
- if (!existsSync(databaseDir)) {
14
- mkdirSync(databaseDir, { recursive: true });
15
- }
16
- await runMigrations();
17
- const prisma = await createPrismaClient(dbPath);
18
- async function runMigrations() {
19
- const currentFilePath = fileURLToPath(import.meta.url);
20
- const databasePackageDir = dirname(dirname(currentFilePath));
21
- await deployPrismaMigrations({
22
- packageDir: databasePackageDir,
23
- databasePath: dbPath,
24
- expectedVersion: HUB_DB_VERSION,
25
- });
26
- }
27
- function getSchemaVersion() {
28
- return HUB_DB_VERSION;
29
- }
30
- async function disconnect() {
31
- await prisma.$disconnect();
32
- }
33
- return {
34
- hubDb: prisma,
35
- getSchemaVersion,
36
- disconnect,
37
- };
8
+ /** We run migration scripts if this is greater than what's in the schema_version table */
9
+ const HUB_DB_VERSION = 34;
10
+ const dbPath = hubDbPath();
11
+ // Ensure database directory exists
12
+ const databaseDir = dirname(dbPath);
13
+ if (!existsSync(databaseDir)) {
14
+ mkdirSync(databaseDir, { recursive: true });
15
+ }
16
+ await runMigrations();
17
+ const prisma = await createPrismaClient(dbPath);
18
+ async function runMigrations() {
19
+ const currentFilePath = fileURLToPath(import.meta.url);
20
+ const databasePackageDir = dirname(dirname(currentFilePath));
21
+ await deployPrismaMigrations({
22
+ packageDir: databasePackageDir,
23
+ databasePath: dbPath,
24
+ expectedVersion: HUB_DB_VERSION,
25
+ });
26
+ }
27
+ function getSchemaVersion() {
28
+ return HUB_DB_VERSION;
29
+ }
30
+ async function disconnect() {
31
+ await prisma.$disconnect();
32
+ }
33
+ return {
34
+ hubDb: prisma,
35
+ getSchemaVersion,
36
+ disconnect,
37
+ };
38
38
  }
@@ -8,105 +8,93 @@ let prisma = null;
8
8
  * No-ops gracefully if NAISYS_FOLDER is unset or the database doesn't exist.
9
9
  */
10
10
  export async function createHubDatabaseClient() {
11
- if (prisma)
12
- return true;
13
- const dbPath = hubDbPath();
14
- if (!existsSync(dbPath))
15
- return false;
16
- prisma = await createPrismaClient(dbPath);
17
- return true;
11
+ if (prisma) return true;
12
+ const dbPath = hubDbPath();
13
+ if (!existsSync(dbPath)) return false;
14
+ prisma = await createPrismaClient(dbPath);
15
+ return true;
18
16
  }
19
17
  /**
20
18
  * Find an agent (from the hub `users` table) by API key.
21
19
  */
22
20
  export async function findAgentByApiKey(apiKey) {
23
- if (!prisma)
24
- return null;
25
- const user = await prisma.users.findUnique({
26
- where: { api_key: apiKey },
27
- select: { uuid: true, username: true },
28
- });
29
- return user;
21
+ if (!prisma) return null;
22
+ const user = await prisma.users.findUnique({
23
+ where: { api_key: apiKey },
24
+ select: { uuid: true, username: true },
25
+ });
26
+ return user;
30
27
  }
31
28
  /**
32
29
  * Find a hub agent by its numeric ID.
33
30
  */
34
31
  export async function getHubAgentById(id) {
35
- if (!prisma)
36
- return null;
37
- return prisma.users.findUnique({
38
- where: { id },
39
- select: { id: true, uuid: true, username: true },
40
- });
32
+ if (!prisma) return null;
33
+ return prisma.users.findUnique({
34
+ where: { id },
35
+ select: { id: true, uuid: true, username: true },
36
+ });
41
37
  }
42
38
  /**
43
39
  * Look up an agent's API key by UUID.
44
40
  */
45
41
  export async function getAgentApiKeyByUuid(uuid) {
46
- if (!prisma)
47
- return null;
48
- const user = await prisma.users.findFirst({
49
- where: { uuid },
50
- select: { api_key: true },
51
- });
52
- return user?.api_key ?? null;
42
+ if (!prisma) return null;
43
+ const user = await prisma.users.findFirst({
44
+ where: { uuid },
45
+ select: { api_key: true },
46
+ });
47
+ return user?.api_key ?? null;
53
48
  }
54
49
  /**
55
50
  * Get the latest run_id and current session start time for a hub user by UUID.
56
51
  */
57
52
  export async function getLatestRunInfoByUuid(uuid) {
58
- if (!prisma)
59
- return null;
60
- const user = await prisma.users.findFirst({
61
- where: { uuid },
62
- select: { id: true },
63
- });
64
- if (!user)
65
- return null;
66
- const latest = await prisma.run_session.findFirst({
67
- where: { user_id: user.id },
68
- orderBy: [{ run_id: "desc" }, { session_id: "desc" }],
69
- select: { run_id: true, created_at: true },
70
- });
71
- if (!latest)
72
- return null;
73
- return { runId: latest.run_id, sessionStart: latest.created_at };
53
+ if (!prisma) return null;
54
+ const user = await prisma.users.findFirst({
55
+ where: { uuid },
56
+ select: { id: true },
57
+ });
58
+ if (!user) return null;
59
+ const latest = await prisma.run_session.findFirst({
60
+ where: { user_id: user.id },
61
+ orderBy: [{ run_id: "desc" }, { session_id: "desc" }],
62
+ select: { run_id: true, created_at: true },
63
+ });
64
+ if (!latest) return null;
65
+ return { runId: latest.run_id, sessionStart: latest.created_at };
74
66
  }
75
67
  /**
76
68
  * Sum the cost of all cost entries for a hub user (by UUID) within a time range.
77
69
  */
78
70
  export async function sumCostsByUuid(uuid, from, to) {
79
- if (!prisma)
80
- return 0;
81
- const user = await prisma.users.findFirst({
82
- where: { uuid },
83
- select: { id: true },
84
- });
85
- if (!user)
86
- return 0;
87
- const result = await prisma.costs.aggregate({
88
- _sum: { cost: true },
89
- where: {
90
- user_id: user.id,
91
- created_at: { gte: from, lte: to },
92
- },
93
- });
94
- return result._sum.cost ?? 0;
71
+ if (!prisma) return 0;
72
+ const user = await prisma.users.findFirst({
73
+ where: { uuid },
74
+ select: { id: true },
75
+ });
76
+ if (!user) return 0;
77
+ const result = await prisma.costs.aggregate({
78
+ _sum: { cost: true },
79
+ where: {
80
+ user_id: user.id,
81
+ created_at: { gte: from, lte: to },
82
+ },
83
+ });
84
+ return result._sum.cost ?? 0;
95
85
  }
96
86
  /**
97
87
  * Rotate an agent's API key by UUID.
98
88
  */
99
89
  export async function rotateAgentApiKeyByUuid(uuid, newKey) {
100
- if (!prisma)
101
- throw new Error("Hub database not initialized");
102
- const user = await prisma.users.findFirst({
103
- where: { uuid },
104
- select: { id: true },
105
- });
106
- if (!user)
107
- throw new Error("Agent not found in hub database");
108
- await prisma.users.update({
109
- where: { id: user.id },
110
- data: { api_key: newKey },
111
- });
90
+ if (!prisma) throw new Error("Hub database not initialized");
91
+ const user = await prisma.users.findFirst({
92
+ where: { uuid },
93
+ select: { id: true },
94
+ });
95
+ if (!user) throw new Error("Agent not found in hub database");
96
+ await prisma.users.update({
97
+ where: { id: user.id },
98
+ data: { api_key: newKey },
99
+ });
112
100
  }
package/dist/index.js CHANGED
@@ -1,9 +1,17 @@
1
1
  // Re-export Database Service
2
- export { createHubDatabaseService, } from "./hubDatabaseService.js";
2
+ export { createHubDatabaseService } from "./hubDatabaseService.js";
3
3
  // Re-export Migration Helper
4
4
  export { deployPrismaMigrations } from "@naisys/common-node";
5
5
  // Re-export Hub Session Service
6
- export { createHubDatabaseClient, findAgentByApiKey, getAgentApiKeyByUuid, getHubAgentById, getLatestRunInfoByUuid, rotateAgentApiKeyByUuid, sumCostsByUuid, } from "./hubSessionService.js";
6
+ export {
7
+ createHubDatabaseClient,
8
+ findAgentByApiKey,
9
+ getAgentApiKeyByUuid,
10
+ getHubAgentById,
11
+ getLatestRunInfoByUuid,
12
+ rotateAgentApiKeyByUuid,
13
+ sumCostsByUuid,
14
+ } from "./hubSessionService.js";
7
15
  // Re-export Prisma Client and all generated types
8
16
  export * from "./generated/prisma/client.js";
9
17
  export { PrismaClient } from "./generated/prisma/client.js";
@@ -6,16 +6,16 @@ import { PrismaClient } from "./generated/prisma/client.js";
6
6
  * @returns Configured PrismaClient instance
7
7
  */
8
8
  export async function createPrismaClient(databasePath) {
9
- const adapter = new PrismaBetterSqlite3({
10
- url: `file:${databasePath}`,
11
- timeout: 10_000, // Wait up to 10s for SQLite lock to be released
12
- });
13
- const prisma = new PrismaClient({ adapter });
14
- // Enable WAL mode for better concurrent read/write performance
15
- await prisma.$executeRawUnsafe("PRAGMA journal_mode=WAL");
16
- // NORMAL is safe with WAL and avoids an extra fsync per commit
17
- await prisma.$executeRawUnsafe("PRAGMA synchronous=NORMAL");
18
- // SQLite doesn't enforce foreign keys by default — must be enabled per connection
19
- await prisma.$executeRawUnsafe("PRAGMA foreign_keys=ON");
20
- return prisma;
9
+ const adapter = new PrismaBetterSqlite3({
10
+ url: `file:${databasePath}`,
11
+ timeout: 10_000, // Wait up to 10s for SQLite lock to be released
12
+ });
13
+ const prisma = new PrismaClient({ adapter });
14
+ // Enable WAL mode for better concurrent read/write performance
15
+ await prisma.$executeRawUnsafe("PRAGMA journal_mode=WAL");
16
+ // NORMAL is safe with WAL and avoids an extra fsync per commit
17
+ await prisma.$executeRawUnsafe("PRAGMA synchronous=NORMAL");
18
+ // SQLite doesn't enforce foreign keys by default — must be enabled per connection
19
+ await prisma.$executeRawUnsafe("PRAGMA foreign_keys=ON");
20
+ return prisma;
21
21
  }