@otwdesign/db-core 1.2.0 → 1.3.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.
Files changed (49) hide show
  1. package/dist/backup/api.d.ts +55 -0
  2. package/dist/backup/api.js +441 -0
  3. package/dist/backup/api.js.map +1 -0
  4. package/dist/backup/catalog.d.ts +47 -0
  5. package/dist/backup/catalog.js +348 -0
  6. package/dist/backup/catalog.js.map +1 -0
  7. package/dist/backup/dump.d.ts +48 -0
  8. package/dist/backup/dump.js +860 -0
  9. package/dist/backup/dump.js.map +1 -0
  10. package/dist/backup/format.d.ts +38 -0
  11. package/dist/backup/format.js +70 -0
  12. package/dist/backup/format.js.map +1 -0
  13. package/dist/backup/pg-tools.d.ts +29 -0
  14. package/dist/backup/pg-tools.js +154 -0
  15. package/dist/backup/pg-tools.js.map +1 -0
  16. package/dist/backup/restore.d.ts +41 -0
  17. package/dist/backup/restore.js +196 -0
  18. package/dist/backup/restore.js.map +1 -0
  19. package/dist/backup/split.d.ts +18 -0
  20. package/dist/backup/split.js +316 -0
  21. package/dist/backup/split.js.map +1 -0
  22. package/dist/backup/staging.d.ts +29 -0
  23. package/dist/backup/staging.js +96 -0
  24. package/dist/backup/staging.js.map +1 -0
  25. package/dist/browser.d.ts +5 -0
  26. package/dist/drivers/pglite.js +57 -0
  27. package/dist/drivers/pglite.js.map +1 -1
  28. package/dist/drivers/postgres.js +45 -0
  29. package/dist/drivers/postgres.js.map +1 -1
  30. package/dist/handler.d.ts +5 -0
  31. package/dist/handler.js +48 -1
  32. package/dist/handler.js.map +1 -1
  33. package/dist/index.d.ts +5 -0
  34. package/dist/types.d.ts +30 -1
  35. package/package.json +2 -2
  36. package/src/backup/api.ts +543 -0
  37. package/src/backup/catalog.ts +381 -0
  38. package/src/backup/dump.ts +1102 -0
  39. package/src/backup/format.ts +114 -0
  40. package/src/backup/pg-tools.ts +185 -0
  41. package/src/backup/restore.ts +270 -0
  42. package/src/backup/split.ts +300 -0
  43. package/src/backup/staging.ts +143 -0
  44. package/src/browser.ts +5 -0
  45. package/src/drivers/pglite.ts +55 -0
  46. package/src/drivers/postgres.ts +46 -0
  47. package/src/handler.ts +56 -1
  48. package/src/index.ts +6 -0
  49. package/src/types.ts +29 -1
@@ -0,0 +1,543 @@
1
+ import { createWriteStream } from 'node:fs'
2
+ import { mkdtemp, rm } from 'node:fs/promises'
3
+ import { tmpdir } from 'node:os'
4
+ import { join } from 'node:path'
5
+ import { pipeline } from 'node:stream/promises'
6
+ import { Readable } from 'node:stream'
7
+ import { createGzip } from 'node:zlib'
8
+ import { DbAdminError, QueryError } from '../errors.ts'
9
+ import type { Access, AuditEvent, ConnectionConfig, Driver, Session, Viewer } from '../types.ts'
10
+ import {
11
+ backupSql,
12
+ notIncluded,
13
+ prepare,
14
+ schemaChoices,
15
+ type SchemaChoice,
16
+ type Server,
17
+ } from './dump.ts'
18
+ import {
19
+ backupFileName,
20
+ HEADER_PREFIX,
21
+ readHeader,
22
+ STAGING_SCHEMA,
23
+ type BackupHeader,
24
+ } from './format.ts'
25
+ import { pgTool, runDump, runRestore, type PgTool } from './pg-tools.ts'
26
+ import { refuseBlocked, restorePlan, restoreSql, type RestorePlan } from './restore.ts'
27
+ import * as staging from './staging.ts'
28
+
29
+ /*
30
+ * The backup and restore endpoints, loaded on their first use: a host that never backs up never
31
+ * loads this.
32
+ */
33
+
34
+ /** What an endpoint gets from the handler: the connection it reached, and who asks. */
35
+ export interface BackupContext {
36
+ connection: ConnectionConfig
37
+ access: Access
38
+ db: Driver
39
+ database?: string
40
+ viewer: Viewer
41
+ record(event: Omit<AuditEvent, 'at'>): Promise<void>
42
+ maxRestoreBytes: number
43
+ }
44
+
45
+ /** What the Back up and Restore dialog shows. */
46
+ export interface BackupOptions {
47
+ database: string
48
+ server: string
49
+ /** The database runs in the host's process (PGlite): it waits while a backup or restore runs. */
50
+ exclusive: boolean
51
+ schemas: SchemaChoice[]
52
+ notIncluded: { schema: string | null; what: string }[]
53
+ pgDump: PgTool
54
+ pgRestore: PgTool
55
+ restore: { allowed: boolean; chunkBytes: number; maxBytes: number }
56
+ }
57
+
58
+ const NOT_A_SERVER: PgTool = {
59
+ available: false,
60
+ reason: 'This database runs inside the site, where pg_dump and pg_restore can’t reach it.',
61
+ }
62
+
63
+ export async function options(ctx: BackupContext): Promise<BackupOptions> {
64
+ const session = await open(ctx, 'snapshot')
65
+ try {
66
+ const server = await prepare(session)
67
+ const schemas = await schemaChoices(session)
68
+ const missing = await notIncluded(
69
+ session,
70
+ schemas.map((s) => s.name),
71
+ )
72
+ const tools = ctx.db.pgUrl
73
+ ? await Promise.all([pgTool('pg_dump', server.version), pgTool('pg_restore', server.version)])
74
+ : [NOT_A_SERVER, NOT_A_SERVER]
75
+ return {
76
+ database: server.database,
77
+ server: server.server,
78
+ exclusive: session.exclusive,
79
+ schemas,
80
+ notIncluded: missing,
81
+ pgDump: tools[0]!,
82
+ pgRestore: tools[1]!,
83
+ restore: {
84
+ allowed: ctx.access === 'write',
85
+ chunkBytes: staging.CHUNK_BYTES,
86
+ maxBytes: ctx.maxRestoreBytes,
87
+ },
88
+ }
89
+ } finally {
90
+ await session.end(false)
91
+ }
92
+ }
93
+
94
+ /** The backup as a download: SQL, gzipped, or pg_dump's archive. */
95
+ export async function download(
96
+ ctx: BackupContext,
97
+ body: Record<string, unknown>,
98
+ ): Promise<Response> {
99
+ const schemas = schemaList(body.schemas)
100
+ const format = body.format === 'pg_dump' ? 'pg_dump' : body.format === 'sql' ? 'sql' : null
101
+ if (!format) throw bad('"format" is "sql" or "pg_dump".')
102
+ const started = performance.now()
103
+ const now = new Date()
104
+ const audit = (rows: number | undefined, error?: Error) =>
105
+ void ctx.record({
106
+ viewer: ctx.viewer.id,
107
+ connection: ctx.connection.name,
108
+ ...(ctx.database ? { database: ctx.database } : {}),
109
+ action: 'backup',
110
+ statement: `backup of ${schemas.join(', ')} as ${format}`,
111
+ durationMs: Math.round(performance.now() - started),
112
+ ...(rows === undefined ? {} : { rows }),
113
+ ...(error ? { error: error.message } : {}),
114
+ })
115
+ const session = await open(ctx, 'snapshot')
116
+ let server: Server
117
+ try {
118
+ server = await prepare(session)
119
+ const known = new Set((await schemaChoices(session)).map((s) => s.name))
120
+ const unknown = schemas.filter((s) => !known.has(s))
121
+ if (unknown.length)
122
+ throw bad(`There's no schema ${unknown.map((s) => `"${s}"`).join(', ')} to back up.`)
123
+ } catch (error) {
124
+ await session.end(false)
125
+ throw error
126
+ }
127
+ const name = (extension: 'sql.gz' | 'dump') =>
128
+ backupFileName(ctx.connection.name, server.database, now, extension)
129
+ if (format === 'pg_dump') {
130
+ await session.end(false)
131
+ if (!ctx.db.pgUrl) throw bad(NOT_A_SERVER.reason!)
132
+ const tool = await pgTool('pg_dump', server.version)
133
+ if (!tool.available) throw bad(tool.reason!)
134
+ const archive = await runDump(ctx.db.pgUrl, schemas)
135
+ return file(counted(archive, audit), name('dump'), 'application/octet-stream')
136
+ }
137
+ const summary = { tables: 0, rows: 0 }
138
+ const pieces = backupSql(session, server, schemas, now, summary)
139
+ let ended = false
140
+ const end = async () => {
141
+ if (ended) return
142
+ ended = true
143
+ await session
144
+ .end(false)
145
+ .catch((error: unknown) =>
146
+ console.error('otw-db: could not end the backup’s transaction', error),
147
+ )
148
+ }
149
+ if (session.exclusive) {
150
+ // The host waits while this session is open: read it all now, rather than at the pace of
151
+ // the download.
152
+ try {
153
+ const gz = await gzipAll(pieces)
154
+ audit(summary.rows)
155
+ return file(new Blob([gz as BlobPart]).stream(), name('sql.gz'), 'application/gzip')
156
+ } catch (error) {
157
+ audit(undefined, error as Error)
158
+ throw error
159
+ } finally {
160
+ await end()
161
+ }
162
+ }
163
+ // Read the first piece before answering, so a failure is an error rather than a broken file.
164
+ let pending: IteratorResult<string> | null
165
+ try {
166
+ pending = await pieces.next()
167
+ } catch (error) {
168
+ await end()
169
+ throw error
170
+ }
171
+ const encoder = new TextEncoder()
172
+ const text = new ReadableStream<Uint8Array>({
173
+ async pull(controller) {
174
+ try {
175
+ const next = pending ?? (await pieces.next())
176
+ pending = null
177
+ if (next.done) {
178
+ await end()
179
+ audit(summary.rows)
180
+ controller.close()
181
+ } else controller.enqueue(encoder.encode(next.value))
182
+ } catch (error) {
183
+ await end()
184
+ audit(undefined, error as Error)
185
+ controller.error(error)
186
+ }
187
+ },
188
+ async cancel() {
189
+ await pieces.return(undefined)
190
+ await end()
191
+ audit(summary.rows, new Error('The download stopped before the end.'))
192
+ },
193
+ })
194
+ // TypeScript's DOM types take a CompressionStream's input as any BufferSource; bytes it is.
195
+ const gzip = new CompressionStream('gzip') as unknown as TransformStream<Uint8Array, Uint8Array>
196
+ return file(text.pipeThrough(gzip), name('sql.gz'), 'application/gzip')
197
+ }
198
+
199
+ /** What restoring the backup with `header` would replace, and what stops it. */
200
+ export async function plan(
201
+ ctx: BackupContext,
202
+ body: Record<string, unknown>,
203
+ ): Promise<RestorePlan> {
204
+ mayRestore(ctx)
205
+ const header = headerOf(body.header)
206
+ const session = await open(ctx, 'snapshot')
207
+ try {
208
+ return await restorePlan(session, header)
209
+ } finally {
210
+ await session.end(false)
211
+ }
212
+ }
213
+
214
+ export async function start(
215
+ ctx: BackupContext,
216
+ body: Record<string, unknown>,
217
+ ): Promise<{ upload: string; chunkBytes: number }> {
218
+ mayRestore(ctx)
219
+ const size = body.size
220
+ if (typeof size !== 'number' || !Number.isInteger(size) || size < 1) {
221
+ throw bad('"size" is the backup’s size in bytes.')
222
+ }
223
+ if (size > ctx.maxRestoreBytes) {
224
+ throw new DbAdminError(
225
+ `The backup is ${megabytes(size)}; this tool restores ${megabytes(ctx.maxRestoreBytes)} at most. Restore it with psql or pg_restore instead.`,
226
+ 413,
227
+ 'too-large',
228
+ )
229
+ }
230
+ const kind = body.kind === 'pg_dump' ? 'pg_dump' : body.kind === 'sql' ? 'sql' : null
231
+ if (!kind) throw bad('"kind" is "sql" or "pg_dump".')
232
+ if (kind === 'pg_dump') await restoreTool(ctx)
233
+ const name = typeof body.name === 'string' ? body.name : 'backup'
234
+ const upload = await write(ctx, (s) =>
235
+ staging.startUpload(s, { viewer: ctx.viewer.id, kind, size, name }),
236
+ )
237
+ return { upload, chunkBytes: staging.CHUNK_BYTES }
238
+ }
239
+
240
+ /** One piece of an upload, as the request's body. */
241
+ export async function chunk(ctx: BackupContext, request: Request): Promise<{ received: number }> {
242
+ mayRestore(ctx)
243
+ const params = new URL(request.url).searchParams
244
+ const seq = Number(params.get('seq'))
245
+ const data = await bytes(request, staging.CHUNK_BYTES)
246
+ if (!data.byteLength) throw bad('The piece is empty.')
247
+ await write(ctx, async (s) => {
248
+ const upload = await staging.findUpload(s, String(params.get('upload')), ctx.viewer.id)
249
+ await staging.putChunk(s, upload, seq, data)
250
+ })
251
+ return { received: data.byteLength }
252
+ }
253
+
254
+ /**
255
+ * Runs the restore, answering with a line of JSON as it goes: `progress`, then `done` or
256
+ * `error`. The upload is checked first, so a missing one is a plain error.
257
+ */
258
+ export async function run(ctx: BackupContext, body: Record<string, unknown>): Promise<Response> {
259
+ mayRestore(ctx)
260
+ const id = String(body.upload)
261
+ const started = performance.now()
262
+ const session = await open(ctx, 'write')
263
+ let upload: staging.Upload
264
+ try {
265
+ upload = await staging.findUpload(session, id, ctx.viewer.id)
266
+ staging.complete(upload)
267
+ } catch (error) {
268
+ await session.end(false)
269
+ throw error
270
+ }
271
+ let header: BackupHeader | null = null
272
+ const audit = (result: { statements?: number; rows?: number }, error?: Error) =>
273
+ void ctx.record({
274
+ viewer: ctx.viewer.id,
275
+ connection: ctx.connection.name,
276
+ ...(ctx.database ? { database: ctx.database } : {}),
277
+ action: 'restore',
278
+ statement: `restore of ${header ? header.schemas.join(', ') : 'a backup'} (${upload.kind}, ${upload.size} bytes)`,
279
+ durationMs: Math.round(performance.now() - started),
280
+ ...(result.rows === undefined ? {} : { rows: result.rows }),
281
+ ...(error ? { error: error.message } : {}),
282
+ })
283
+ const encoder = new TextEncoder()
284
+ const stream = new ReadableStream<Uint8Array>({
285
+ async start(controller) {
286
+ const send = (line: unknown) =>
287
+ controller.enqueue(encoder.encode(`${JSON.stringify(line)}\n`))
288
+ try {
289
+ const result =
290
+ upload.kind === 'sql'
291
+ ? await restoreInSession(
292
+ session,
293
+ upload,
294
+ (h) => (header = h),
295
+ (p) => send({ type: 'progress', ...p }),
296
+ )
297
+ : await restoreArchive(ctx, session, upload, () =>
298
+ send({ type: 'progress', statements: 0, bytes: upload.size }),
299
+ )
300
+ audit(result)
301
+ send({ type: 'done', ...result, durationMs: Math.round(performance.now() - started) })
302
+ } catch (error) {
303
+ const failure =
304
+ error instanceof DbAdminError
305
+ ? error
306
+ : new DbAdminError(
307
+ `The restore failed: ${(error as Error).message}`,
308
+ 500,
309
+ 'restore-failed',
310
+ )
311
+ audit({}, failure)
312
+ send({ type: 'error', error: { code: failure.code, message: failure.message } })
313
+ // A failed restore's upload goes too: it would only fail again.
314
+ await write(ctx, (s) => staging.discard(s, id)).catch((e: unknown) =>
315
+ console.error('otw-db: could not remove a restore’s upload', e),
316
+ )
317
+ } finally {
318
+ controller.close()
319
+ }
320
+ },
321
+ })
322
+ return new Response(stream, {
323
+ headers: {
324
+ 'content-type': 'application/x-ndjson; charset=utf-8',
325
+ 'cache-control': 'no-store',
326
+ 'x-content-type-options': 'nosniff',
327
+ },
328
+ })
329
+ }
330
+
331
+ /** Drops an upload that won't be restored. */
332
+ export async function discard(
333
+ ctx: BackupContext,
334
+ body: Record<string, unknown>,
335
+ ): Promise<{ discarded: true }> {
336
+ mayRestore(ctx)
337
+ const id = String(body.upload)
338
+ await write(ctx, async (s) => {
339
+ await staging.findUpload(s, id, ctx.viewer.id)
340
+ await staging.discard(s, id)
341
+ })
342
+ return { discarded: true }
343
+ }
344
+
345
+ async function restoreInSession(
346
+ session: Session,
347
+ upload: staging.Upload,
348
+ onHeader: (header: BackupHeader) => void,
349
+ onProgress: (progress: { statements: number; bytes: number }) => void,
350
+ ): Promise<{ statements: number; tables: number; rows: number }> {
351
+ try {
352
+ // A table the site is using makes DROP wait; better to fail soon and say why.
353
+ if (!session.exclusive) await session.query(`SET LOCAL lock_timeout = '10s'`)
354
+ const result = await restoreSql(session, staging.chunks(session, upload), {
355
+ async check(header) {
356
+ onHeader(header)
357
+ refuseBlocked(header, await restorePlan(session, header))
358
+ },
359
+ onProgress,
360
+ })
361
+ await staging.discard(session, upload.id)
362
+ await session.end(true)
363
+ return result
364
+ } catch (error) {
365
+ await session.end(false).catch(() => {})
366
+ if (error instanceof QueryError && error.sqlState === '55P03') {
367
+ throw new DbAdminError(
368
+ 'The database is busy: something is using a table the restore replaces. Nothing changed; try again in a moment.',
369
+ 409,
370
+ 'busy',
371
+ )
372
+ }
373
+ throw error
374
+ }
375
+ }
376
+
377
+ /** pg_dump's archive, put in a file for pg_restore, which restores it in one transaction. */
378
+ async function restoreArchive(
379
+ ctx: BackupContext,
380
+ session: Session,
381
+ upload: staging.Upload,
382
+ onStart: () => void,
383
+ ): Promise<{ statements: number; tables: number; rows: number }> {
384
+ const dir = await mkdtemp(join(tmpdir(), 'otw-db-restore-'))
385
+ const path = join(dir, 'backup.dump')
386
+ try {
387
+ try {
388
+ await pipeline(Readable.from(staging.chunks(session, upload)), createWriteStream(path))
389
+ } finally {
390
+ await session.end(false)
391
+ }
392
+ await restoreTool(ctx)
393
+ onStart()
394
+ await runRestore(ctx.db.pgUrl!, path)
395
+ await write(ctx, (s) => staging.discard(s, upload.id))
396
+ return { statements: 0, tables: 0, rows: 0 }
397
+ } finally {
398
+ await rm(dir, { recursive: true, force: true })
399
+ }
400
+ }
401
+
402
+ async function restoreTool(ctx: BackupContext): Promise<void> {
403
+ if (!ctx.db.pgUrl) throw bad(NOT_A_SERVER.reason!)
404
+ const session = await open(ctx, 'snapshot')
405
+ let version
406
+ try {
407
+ version = (await prepare(session)).version
408
+ } finally {
409
+ await session.end(false)
410
+ }
411
+ const tool = await pgTool('pg_restore', version)
412
+ if (!tool.available) throw bad(tool.reason!)
413
+ }
414
+
415
+ function mayRestore(ctx: BackupContext): void {
416
+ if (ctx.access !== 'write') {
417
+ throw new DbAdminError(
418
+ `Restoring needs write access, and connection "${ctx.connection.name}" is read-only.`,
419
+ 403,
420
+ 'read-only',
421
+ )
422
+ }
423
+ }
424
+
425
+ function open(ctx: BackupContext, mode: 'snapshot' | 'write'): Promise<Session> {
426
+ if (typeof ctx.db.session !== 'function') {
427
+ throw new DbAdminError(
428
+ `Connection "${ctx.connection.name}" can't be backed up here: backups are for PostgreSQL.`,
429
+ 400,
430
+ 'no-backups',
431
+ )
432
+ }
433
+ return ctx.db.session(mode)
434
+ }
435
+
436
+ /** `work` in a write session of its own, committed if it succeeds. */
437
+ async function write<T>(ctx: BackupContext, work: (session: Session) => Promise<T>): Promise<T> {
438
+ const session = await open(ctx, 'write')
439
+ try {
440
+ const result = await work(session)
441
+ await session.end(true)
442
+ return result
443
+ } catch (error) {
444
+ await session.end(false).catch(() => {})
445
+ throw error
446
+ }
447
+ }
448
+
449
+ function schemaList(value: unknown): string[] {
450
+ if (!Array.isArray(value) || !value.length || value.length > 500) {
451
+ throw bad('"schemas" lists the schemas to back up.')
452
+ }
453
+ const names = value.map((name) => {
454
+ if (typeof name !== 'string' || !name || new TextEncoder().encode(name).length > 63) {
455
+ throw bad('"schemas" lists the schemas to back up, by name.')
456
+ }
457
+ if (name === STAGING_SCHEMA)
458
+ throw bad(`${STAGING_SCHEMA} is where restores wait: it isn't backed up.`)
459
+ return name
460
+ })
461
+ return [...new Set(names)]
462
+ }
463
+
464
+ /** A header the browser read from the file, checked as the file's own would be. */
465
+ function headerOf(value: unknown): BackupHeader {
466
+ if (!value || typeof value !== 'object') throw bad('"header" is the backup’s first line, read.')
467
+ return readHeader(`${HEADER_PREFIX}${JSON.stringify(value)}`)
468
+ }
469
+
470
+ /** The request's body, refused past `max` bytes. */
471
+ async function bytes(request: Request, max: number): Promise<Uint8Array> {
472
+ const tooBig = () =>
473
+ new DbAdminError(`A piece of an upload is ${megabytes(max)} at most.`, 413, 'too-large')
474
+ if (Number(request.headers.get('content-length') ?? 0) > max) throw tooBig()
475
+ const reader = request.body?.getReader()
476
+ if (!reader) return new Uint8Array()
477
+ const parts: Uint8Array[] = []
478
+ let size = 0
479
+ for (;;) {
480
+ const { done, value } = await reader.read()
481
+ if (done) break
482
+ size += value.byteLength
483
+ if (size > max) {
484
+ await reader.cancel()
485
+ throw tooBig()
486
+ }
487
+ parts.push(value)
488
+ }
489
+ const all = new Uint8Array(size)
490
+ let at = 0
491
+ for (const part of parts) {
492
+ all.set(part, at)
493
+ at += part.byteLength
494
+ }
495
+ return all
496
+ }
497
+
498
+ async function gzipAll(pieces: AsyncIterable<string>): Promise<Buffer> {
499
+ const gzip = createGzip()
500
+ const out: Buffer[] = []
501
+ gzip.on('data', (data: Buffer) => out.push(data))
502
+ const done = new Promise<void>((resolve, reject) => {
503
+ gzip.on('end', resolve)
504
+ gzip.on('error', reject)
505
+ })
506
+ for await (const piece of pieces) {
507
+ if (!gzip.write(piece)) await new Promise((resolve) => gzip.once('drain', resolve))
508
+ }
509
+ gzip.end()
510
+ await done
511
+ return Buffer.concat(out)
512
+ }
513
+
514
+ /** `stream`, with `audit` told its end: its bytes, or why it stopped. */
515
+ function counted(
516
+ stream: ReadableStream<Uint8Array>,
517
+ audit: (rows: number | undefined, error?: Error) => void,
518
+ ): ReadableStream<Uint8Array> {
519
+ return stream.pipeThrough(
520
+ new TransformStream<Uint8Array, Uint8Array>({
521
+ flush: () => audit(undefined),
522
+ }),
523
+ )
524
+ }
525
+
526
+ function file(body: ReadableStream<Uint8Array>, name: string, type: string): Response {
527
+ return new Response(body, {
528
+ headers: {
529
+ 'content-type': type,
530
+ 'content-disposition': `attachment; filename="${name}"`,
531
+ 'cache-control': 'no-store',
532
+ 'x-content-type-options': 'nosniff',
533
+ },
534
+ })
535
+ }
536
+
537
+ function megabytes(bytes: number): string {
538
+ return `${(bytes / 1_048_576).toLocaleString('en', { maximumFractionDigits: 1 })} MB`
539
+ }
540
+
541
+ function bad(message: string): DbAdminError {
542
+ return new DbAdminError(message, 400, 'bad-request')
543
+ }