@crombolo/server 0.37.0 → 0.39.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 (80) hide show
  1. package/package.json +15 -14
  2. package/src/access.ts +29 -27
  3. package/src/adapters/audit.ts +1 -1
  4. package/src/adapters/blueprints.ts +22 -13
  5. package/src/adapters/content.ts +1 -1
  6. package/src/adapters/dictionary.ts +1 -1
  7. package/src/adapters/documents.ts +17 -10
  8. package/src/adapters/elements.ts +47 -37
  9. package/src/adapters/file-system.ts +1 -1
  10. package/src/adapters/health.ts +10 -5
  11. package/src/adapters/media.ts +12 -8
  12. package/src/adapters/member-groups.ts +8 -6
  13. package/src/adapters/members.ts +6 -4
  14. package/src/adapters/public-access.ts +7 -5
  15. package/src/adapters/redirects.ts +1 -1
  16. package/src/adapters/references.ts +1 -1
  17. package/src/adapters/relations.ts +1 -1
  18. package/src/adapters/schema-files.ts +33 -1
  19. package/src/adapters/search-index.ts +1 -1
  20. package/src/adapters/template-query.ts +1 -1
  21. package/src/adapters/users.ts +13 -13
  22. package/src/adapters/webhooks.ts +1 -1
  23. package/src/anonymise-rules.ts +83 -0
  24. package/src/approvals-api.ts +1 -1
  25. package/src/approvals.ts +75 -38
  26. package/src/back-office-url.ts +20 -0
  27. package/src/backup.ts +26 -2
  28. package/src/bundle-code.ts +1 -1
  29. package/src/bundle-grants.ts +250 -0
  30. package/src/bundle-install.ts +13 -2
  31. package/src/bundle-media.ts +12 -11
  32. package/src/bundles.ts +131 -43
  33. package/src/component-snippets.ts +1 -1
  34. package/src/components.ts +6 -1
  35. package/src/config.ts +61 -3
  36. package/src/content-notifications.ts +13 -9
  37. package/src/content-operations.ts +23 -65
  38. package/src/content-query.ts +1 -1
  39. package/src/core.ts +675 -0
  40. package/src/cron.ts +139 -0
  41. package/src/custom-tables.ts +274 -0
  42. package/src/database.ts +22 -14
  43. package/src/dictionary-transfer.ts +1 -1
  44. package/src/git-routes.ts +1 -1
  45. package/src/identity-provider-overrides.ts +18 -16
  46. package/src/imaging.ts +65 -15
  47. package/src/index.ts +10 -1
  48. package/src/job-wake.ts +23 -0
  49. package/src/live-reload.ts +195 -0
  50. package/src/log-viewer.ts +6 -1
  51. package/src/marketplace.ts +82 -10
  52. package/src/media-access.ts +12 -9
  53. package/src/member-auth.ts +6 -4
  54. package/src/models-builder.ts +1 -1
  55. package/src/node-operations.ts +122 -0
  56. package/src/owner-jobs.ts +428 -0
  57. package/src/ports.ts +36 -154
  58. package/src/preview-tokens.ts +6 -12
  59. package/src/remote.ts +3 -1
  60. package/src/routes.ts +18 -1
  61. package/src/schema.ts +8 -3
  62. package/src/seed/compile.ts +7 -5
  63. package/src/seed/export.ts +6 -4
  64. package/src/seo.ts +2 -2
  65. package/src/server.ts +328 -452
  66. package/src/settings.ts +18 -2
  67. package/src/site-data.ts +195 -0
  68. package/src/site-file.ts +30 -4
  69. package/src/site-queries.ts +140 -0
  70. package/src/site-replace.ts +25 -19
  71. package/src/site-sections.ts +1 -1
  72. package/src/site-services.ts +23 -6
  73. package/src/status-pages.ts +19 -5
  74. package/src/status.ts +11 -9
  75. package/src/url-settings.ts +1 -2
  76. package/src/webhook-files.ts +1 -1
  77. package/src/webhooks.ts +31 -23
  78. package/src/worker-watch.ts +73 -0
  79. package/src/worker.ts +138 -0
  80. package/src/bundle-tables.ts +0 -161
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/server",
3
- "version": "0.37.0",
3
+ "version": "0.39.0",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. The crombolo HTTP server: routing, configuration, media stores and background jobs.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -20,7 +20,8 @@
20
20
  "exports": {
21
21
  ".": "./src/index.ts",
22
22
  "./remote-credentials": "./src/remote-credentials.ts",
23
- "./atomic-write": "./src/atomic-write.ts"
23
+ "./atomic-write": "./src/atomic-write.ts",
24
+ "./worker": "./src/worker.ts"
24
25
  },
25
26
  "files": [
26
27
  "src",
@@ -30,18 +31,18 @@
30
31
  "access": "public"
31
32
  },
32
33
  "dependencies": {
33
- "@crombolo/api-delivery": "0.37.0",
34
- "@crombolo/api-management": "0.37.0",
35
- "@crombolo/auth": "0.37.0",
36
- "@crombolo/backoffice-host": "0.37.0",
37
- "@crombolo/common": "0.37.0",
38
- "@crombolo/content": "0.37.0",
39
- "@crombolo/contracts": "0.37.0",
40
- "@crombolo/core": "0.37.0",
41
- "@crombolo/data": "0.37.0",
42
- "@crombolo/render": "0.37.0",
43
- "@crombolo/schema": "0.37.0",
44
- "@crombolo/transfer": "0.37.0",
34
+ "@crombolo/api-delivery": "0.39.0",
35
+ "@crombolo/api-management": "0.39.0",
36
+ "@crombolo/auth": "0.39.0",
37
+ "@crombolo/backoffice-host": "0.39.0",
38
+ "@crombolo/common": "0.39.0",
39
+ "@crombolo/content": "0.39.0",
40
+ "@crombolo/contracts": "0.39.0",
41
+ "@crombolo/core": "0.39.0",
42
+ "@crombolo/data": "0.39.0",
43
+ "@crombolo/render": "0.39.0",
44
+ "@crombolo/schema": "0.39.0",
45
+ "@crombolo/transfer": "0.39.0",
45
46
  "@logtape/logtape": "^2.3.8",
46
47
  "jose": "^6.2.12"
47
48
  }
package/src/access.ts CHANGED
@@ -2,12 +2,10 @@
2
2
  * What authorization needs from the database: where nodes sit in their trees,
3
3
  * and each signed-in user's combined start nodes, group verbs and languages.
4
4
  */
5
- import type { NodeChain, NodeLookup, Principal } from '@crombolo/api-management'
5
+ import type { NodeChain, NodeLookup, Principal } from '@crombolo/api-management/domain'
6
6
  import { combineStartNodes, normaliseUuid, ObjectTypes } from '@crombolo/core'
7
7
  import { type Db, fromDbBool, UserRepository } from '@crombolo/data'
8
8
 
9
- const inList = (values: readonly unknown[]) => values.map(() => '?').join(', ')
10
-
11
9
  async function chains(
12
10
  db: Db,
13
11
  rows: Array<{ id: number; unique_id: string; path: string; trashed: unknown }>,
@@ -24,10 +22,11 @@ async function chains(
24
22
  ]
25
23
  const keys = new Map<number, string>()
26
24
  if (ids.length > 0)
27
- for (const row of await db.query<{ id: number; unique_id: string }>(
28
- `SELECT id, unique_id FROM node WHERE id IN (${inList(ids)})`,
29
- ids,
30
- ))
25
+ for (const row of await db.q
26
+ .selectFrom('node')
27
+ .select(['id', 'unique_id'])
28
+ .where('id', 'in', ids)
29
+ .execute())
31
30
  keys.set(Number(row.id), normaliseUuid(String(row.unique_id)))
32
31
  return new Map(
33
32
  rows.map((row) => [
@@ -53,31 +52,34 @@ export function createNodeLookup(db: Db): NodeLookup {
53
52
  if (wanted.length === 0) return new Map<string, NodeChain>()
54
53
  return chains(
55
54
  db,
56
- await db.query(
57
- `SELECT id, unique_id, path, trashed FROM node
58
- WHERE node_object_type = ? AND unique_id IN (${inList(wanted)})`,
59
- [objectType, ...wanted],
60
- ),
55
+ await db.q
56
+ .selectFrom('node')
57
+ .select(['id', 'unique_id', 'path', 'trashed'])
58
+ .where('node_object_type', '=', objectType)
59
+ .where('unique_id', 'in', wanted)
60
+ .execute(),
61
61
  )
62
62
  }
63
63
  return {
64
64
  documents: (keys) => byKeys(ObjectTypes.Document, keys),
65
65
  media: (keys) => byKeys(ObjectTypes.Media, keys),
66
66
  async documentDescendants(key) {
67
- const node = (
68
- await db.query<{ path: string }>('SELECT path FROM node WHERE unique_id = ?', [
69
- normaliseUuid(key),
70
- ])
71
- )[0]
67
+ const node = await db.q
68
+ .selectFrom('node')
69
+ .select('path')
70
+ .where('unique_id', '=', normaliseUuid(key))
71
+ .executeTakeFirst()
72
72
  if (!node) return []
73
73
  return [
74
74
  ...(
75
75
  await chains(
76
76
  db,
77
- await db.query(
78
- 'SELECT id, unique_id, path, trashed FROM node WHERE node_object_type = ? AND path LIKE ?',
79
- [ObjectTypes.Document, `${node.path},%`],
80
- ),
77
+ await db.q
78
+ .selectFrom('node')
79
+ .select(['id', 'unique_id', 'path', 'trashed'])
80
+ .where('node_object_type', '=', ObjectTypes.Document)
81
+ .where('path', 'like', `${node.path},%`)
82
+ .execute(),
81
83
  )
82
84
  ).values(),
83
85
  ]
@@ -85,12 +87,12 @@ export function createNodeLookup(db: Db): NodeLookup {
85
87
  async versionDocument(versionId) {
86
88
  const id = Number(versionId)
87
89
  if (!Number.isInteger(id)) return undefined
88
- const row = (
89
- await db.query<{ unique_id: string }>(
90
- 'SELECT n.unique_id FROM content_version cv JOIN node n ON n.id = cv.node_id WHERE cv.id = ?',
91
- [id],
92
- )
93
- )[0]
90
+ const row = await db.q
91
+ .selectFrom('content_version as cv')
92
+ .innerJoin('node as n', 'n.id', 'cv.node_id')
93
+ .select('n.unique_id')
94
+ .where('cv.id', '=', id)
95
+ .executeTakeFirst()
94
96
  return row ? normaliseUuid(String(row.unique_id)) : undefined
95
97
  },
96
98
  }
@@ -2,7 +2,7 @@
2
2
  * The audit log's ports: where the router writes, what an item's Info tab reads,
3
3
  * and the Settings dashboard's endpoint. docs/audit-log.md.
4
4
  */
5
- import type { AuditHistoryPort, AuditSink } from '@crombolo/api-management'
5
+ import type { AuditHistoryPort, AuditSink } from '@crombolo/api-management/domain'
6
6
  import {
7
7
  AUDIT_CATEGORIES,
8
8
  type AuditCategory,
@@ -3,7 +3,7 @@
3
3
  * Blueprint" on a page): stored as documents of their own object type in their
4
4
  * own folder tree, never published.
5
5
  */
6
- import type { BlueprintPort, Principal } from '@crombolo/api-management'
6
+ import type { BlueprintPort, Principal } from '@crombolo/api-management/domain'
7
7
  import { ObjectTypes, type TreeItem } from '@crombolo/core'
8
8
  import {
9
9
  type Db,
@@ -36,9 +36,11 @@ export function createBlueprintPort(
36
36
  const tree = createSettingsTree(repo.nodes, container, ObjectTypes.DocumentBlueprint, decorate)
37
37
 
38
38
  const userIdOf = async (principal: Principal): Promise<number | undefined> => {
39
- const rows = await db.query<{ id: number }>('SELECT id FROM user_account WHERE key = ?', [
40
- principal.id,
41
- ])
39
+ const rows = await db.q
40
+ .selectFrom('user_account')
41
+ .select('id')
42
+ .where('key', '=', principal.id)
43
+ .execute()
42
44
  return rows[0] ? Number(rows[0].id) : undefined
43
45
  }
44
46
  const failure = (error: unknown) => {
@@ -115,19 +117,26 @@ export function createBlueprintPort(
115
117
 
116
118
  versions: (key) => repo.versions(key),
117
119
  async systemUserKey() {
118
- const rows = await db.query<{ key: string }>(
119
- 'SELECT key FROM user_account ORDER BY id LIMIT 1',
120
- )
120
+ const rows = await db.q
121
+ .selectFrom('user_account')
122
+ .select('key')
123
+ .orderBy('id')
124
+ .limit(1)
125
+ .execute()
121
126
  return rows[0] ? String(rows[0].key).toLowerCase() : null
122
127
  },
123
128
 
124
129
  async forContentType(contentTypeKey, paging) {
125
- const rows = await db.query(
126
- `SELECT n.unique_id, n.text FROM node n JOIN content c ON c.node_id = n.id
127
- JOIN node t ON t.id = c.content_type_id
128
- WHERE n.node_object_type = ? AND t.unique_id = ? ORDER BY n.text, n.id`,
129
- [ObjectTypes.DocumentBlueprint, contentTypeKey.toLowerCase()],
130
- )
130
+ const rows = await db.q
131
+ .selectFrom('node as n')
132
+ .innerJoin('content as c', 'c.node_id', 'n.id')
133
+ .innerJoin('node as t', 't.id', 'c.content_type_id')
134
+ .select(['n.unique_id', 'n.text'])
135
+ .where('n.node_object_type', '=', ObjectTypes.DocumentBlueprint)
136
+ .where('t.unique_id', '=', contentTypeKey.toLowerCase())
137
+ .orderBy('n.text')
138
+ .orderBy('n.id')
139
+ .execute()
131
140
  const all = rows.map((row) => ({
132
141
  key: String(row.unique_id).toLowerCase(),
133
142
  name: String(row.text ?? ''),
@@ -13,7 +13,7 @@ import type {
13
13
  SkipTake,
14
14
  TemplatePort,
15
15
  TreePage,
16
- } from '@crombolo/api-management'
16
+ } from '@crombolo/api-management/domain'
17
17
  import {
18
18
  type ComponentModel,
19
19
  type ContentTypeAggregate,
@@ -1,5 +1,5 @@
1
1
  /** The dictionary port over the repository, with `.udt` import and export. */
2
- import type { DictionaryPort } from '@crombolo/api-management'
2
+ import type { DictionaryPort } from '@crombolo/api-management/domain'
3
3
  import { appendCacheInstruction, type Db, DictionaryRepository } from '@crombolo/data'
4
4
  import { importDictionaryUdt } from '../dictionary-transfer.ts'
5
5
  import type { MediaFileStore } from '../media-files.ts'
@@ -5,7 +5,7 @@ import type {
5
5
  Principal,
6
6
  SaveDocument,
7
7
  SkipTake,
8
- } from '@crombolo/api-management'
8
+ } from '@crombolo/api-management/domain'
9
9
  import {
10
10
  type DocumentAggregate,
11
11
  normaliseUuid,
@@ -92,9 +92,11 @@ export function createDocumentPort(
92
92
  /** The signed-in user's row id, which versions record as their author. */
93
93
  const userIdOf = async (principal: Principal | undefined): Promise<number | undefined> => {
94
94
  if (!principal) return undefined
95
- const rows = await db.query<{ id: number }>('SELECT id FROM user_account WHERE key = ?', [
96
- principal.id,
97
- ])
95
+ const rows = await db.q
96
+ .selectFrom('user_account')
97
+ .select('id')
98
+ .where('key', '=', principal.id)
99
+ .execute()
98
100
  return rows[0] ? Number(rows[0].id) : undefined
99
101
  }
100
102
 
@@ -437,9 +439,12 @@ export function createDocumentPort(
437
439
 
438
440
  versions: (key) => repo.versions(key),
439
441
  async systemUserKey() {
440
- const rows = await db.query<{ key: string }>(
441
- 'SELECT key FROM user_account ORDER BY id LIMIT 1',
442
- )
442
+ const rows = await db.q
443
+ .selectFrom('user_account')
444
+ .select('key')
445
+ .orderBy('id')
446
+ .limit(1)
447
+ .execute()
443
448
  return rows[0] ? normaliseUuid(String(rows[0].key)) : null
444
449
  },
445
450
 
@@ -661,9 +666,11 @@ export async function loadDraftNode(
661
666
  const template = draft.componentKey ? await repo.nodes.byKey(draft.componentKey) : undefined
662
667
  const componentAlias = template
663
668
  ? ((
664
- await db.query<{ alias: string }>('SELECT alias FROM template WHERE node_id = ?', [
665
- template.id,
666
- ])
669
+ await db.q
670
+ .selectFrom('template')
671
+ .select('alias')
672
+ .where('node_id', '=', template.id)
673
+ .execute()
667
674
  )[0]?.alias ?? null)
668
675
  : null
669
676
  const invariant = draft.variants.find((v) => v.culture === null) ?? draft.variants[0]
@@ -11,7 +11,7 @@
11
11
  * by the generic folder repository, which is why they worked before elements
12
12
  * themselves did.
13
13
  */
14
- import type { ElementPort, Principal } from '@crombolo/api-management'
14
+ import type { ElementPort, Principal } from '@crombolo/api-management/domain'
15
15
  import {
16
16
  type ElementTreeItem,
17
17
  MENU_ALIAS_PROPERTY,
@@ -62,9 +62,11 @@ export function createElementPort(
62
62
  const tree = createSettingsTree(nodes, ObjectTypes.ElementContainer, ObjectTypes.Element, changed)
63
63
 
64
64
  const userIdOf = async (principal: Principal): Promise<number | undefined> => {
65
- const rows = await db.query<{ id: number }>('SELECT id FROM user_account WHERE key = ?', [
66
- principal.id,
67
- ])
65
+ const rows = await db.q
66
+ .selectFrom('user_account')
67
+ .select('id')
68
+ .where('key', '=', principal.id)
69
+ .execute()
68
70
  return rows[0] ? Number(rows[0].id) : undefined
69
71
  }
70
72
  const notFound = (reason = 'The element could not be found.') => ({
@@ -87,22 +89,23 @@ export function createElementPort(
87
89
 
88
90
  /** Whether another menu, not in the bin, already answers to `alias`. */
89
91
  const menuAliasTaken = async (alias: string, key: string | undefined): Promise<boolean> => {
90
- const rows = await db.query<{ unique_id: string }>(
91
- `SELECT n.unique_id FROM property_value pv
92
- JOIN property_type p ON p.id = pv.property_type_id
93
- JOIN node n ON n.id = pv.node_id
94
- JOIN content c ON c.node_id = n.id
95
- JOIN node ct ON ct.id = c.content_type_id
96
- WHERE p.alias = ? AND pv.is_current = ? AND n.trashed = ? AND ct.unique_id = ?
97
- AND LOWER(COALESCE(pv.varchar_value, pv.text_value)) = ?`,
98
- [
99
- MENU_ALIAS_PROPERTY,
100
- db.dialect.boolValue(true),
101
- db.dialect.boolValue(false),
102
- SYSTEM_CONTENT_TYPE_KEYS.Menu,
92
+ const rows = await db.q
93
+ .selectFrom('property_value as pv')
94
+ .innerJoin('property_type as p', 'p.id', 'pv.property_type_id')
95
+ .innerJoin('node as n', 'n.id', 'pv.node_id')
96
+ .innerJoin('content as c', 'c.node_id', 'n.id')
97
+ .innerJoin('node as ct', 'ct.id', 'c.content_type_id')
98
+ .select('n.unique_id')
99
+ .where('p.alias', '=', MENU_ALIAS_PROPERTY)
100
+ .where('pv.is_current', '=', db.dialect.boolValue(true) as boolean)
101
+ .where('n.trashed', '=', db.dialect.boolValue(false) as boolean)
102
+ .where('ct.unique_id', '=', SYSTEM_CONTENT_TYPE_KEYS.Menu)
103
+ .where(
104
+ (eb) => eb.fn('lower', [eb.fn.coalesce('pv.varchar_value', 'pv.text_value')]),
105
+ '=',
103
106
  alias.toLowerCase(),
104
- ],
105
- )
107
+ )
108
+ .execute()
106
109
  return rows.some((row) => normaliseUuid(String(row.unique_id)) !== key?.toLowerCase())
107
110
  }
108
111
 
@@ -404,21 +407,25 @@ export function createElementPort(
404
407
  // The whole branch is trashed, elements inside it included, and an element
405
408
  // stays unpublished while it is in the bin.
406
409
  const moved = await nodes.byKey(key)
407
- await db.exec('UPDATE node SET trashed = ? WHERE id = ? OR path LIKE ?', [
408
- db.dialect.boolValue(true),
409
- node.id,
410
- `${moved?.path ?? node.path},%`,
411
- ])
412
- await db.exec(
413
- `UPDATE document SET published = ?, edited = ?
414
- WHERE node_id IN (SELECT id FROM node WHERE id = ? OR path LIKE ?)`,
415
- [
416
- db.dialect.boolValue(false),
417
- db.dialect.boolValue(true),
418
- node.id,
419
- `${moved?.path ?? node.path},%`,
420
- ],
421
- )
410
+ const branch = `${moved?.path ?? node.path},%`
411
+ await db.q
412
+ .updateTable('node')
413
+ .set({ trashed: db.dialect.boolValue(true) as boolean })
414
+ .where((eb) => eb.or([eb('id', '=', node.id), eb('path', 'like', branch)]))
415
+ .execute()
416
+ await db.q
417
+ .updateTable('document')
418
+ .set({
419
+ published: db.dialect.boolValue(false) as boolean,
420
+ edited: db.dialect.boolValue(true) as boolean,
421
+ })
422
+ .where('node_id', 'in', (eb) =>
423
+ eb
424
+ .selectFrom('node')
425
+ .select('id')
426
+ .where((w) => w.or([w('id', '=', node.id), w('path', 'like', branch)])),
427
+ )
428
+ .execute()
422
429
  await changed()
423
430
  return true
424
431
  },
@@ -430,9 +437,12 @@ export function createElementPort(
430
437
  )
431
438
  },
432
439
  async systemUserKey() {
433
- const rows = await db.query<{ key: string }>(
434
- 'SELECT key FROM user_account ORDER BY id LIMIT 1',
435
- )
440
+ const rows = await db.q
441
+ .selectFrom('user_account')
442
+ .select('key')
443
+ .orderBy('id')
444
+ .limit(1)
445
+ .execute()
436
446
  return rows[0] ? normaliseUuid(String(rows[0].key)) : null
437
447
  },
438
448
  }
@@ -6,7 +6,7 @@
6
6
  import { existsSync } from 'node:fs'
7
7
  import { mkdir, readdir, readFile, rename, rm, rmdir, stat, writeFile } from 'node:fs/promises'
8
8
  import { join } from 'node:path'
9
- import type { FileEntry, FileResult, FileSystemPort } from '@crombolo/api-management'
9
+ import type { FileEntry, FileResult, FileSystemPort } from '@crombolo/api-management/domain'
10
10
 
11
11
  export interface FileAreaOptions {
12
12
  /** The extension files are stored with, e.g. `.css`. */
@@ -2,7 +2,11 @@
2
2
  * The diagnostics port: health checks for what actually goes wrong on a site,
3
3
  * the troubleshooting report and the upgrade check. docs/diagnostics.md.
4
4
  */
5
- import type { DiagnosticsPort, HealthCheckGroup, HealthCheckResult } from '@crombolo/api-management'
5
+ import type {
6
+ DiagnosticsPort,
7
+ HealthCheckGroup,
8
+ HealthCheckResult,
9
+ } from '@crombolo/api-management/domain'
6
10
  import {
7
11
  changedSince,
8
12
  compareStates,
@@ -16,9 +20,10 @@ import {
16
20
  pendingMigrations,
17
21
  type QueueCounts,
18
22
  queueCounts,
23
+ sql,
19
24
  } from '@crombolo/data'
20
- import { BundleConfigurationError, bundleChainsFor, pendingBundleSteps } from '../bundle-tables.ts'
21
25
  import { type CromboloConfig, describeDatabase, VERSION } from '../config.ts'
26
+ import { BundleConfigurationError, pendingTablesSteps, tablesChainsFor } from '../custom-tables.ts'
22
27
  import { type EmailPort, emailAvailability } from '../email.ts'
23
28
  import type { MediaStore } from '../media-store.ts'
24
29
  import { backofficeVersion } from '../status.ts'
@@ -199,7 +204,7 @@ export function createDiagnosticsPort(options: HealthCheckOptions): DiagnosticsP
199
204
  async function database(): Promise<HealthCheckResult[]> {
200
205
  const dialect = db.dialect.name === 'postgres' ? 'PostgreSQL' : 'SQLite'
201
206
  try {
202
- await db.query('SELECT 1 AS ok')
207
+ await db.q.selectNoFrom(sql<number>`1`.as('ok')).execute()
203
208
  return [result('Success', `${dialect} is answering (${describeDatabase(config)}).`)]
204
209
  } catch (error) {
205
210
  return [result('Error', `${dialect} is not answering: ${failure(error)}`)]
@@ -218,12 +223,12 @@ export function createDiagnosticsPort(options: HealthCheckOptions): DiagnosticsP
218
223
  `${pending.length} database upgrade(s) for Crombolo ${VERSION} have not run yet: ${pending.map((m) => m.name).join(', ')}. Run \`crombolo upgrade\`.`,
219
224
  ),
220
225
  )
221
- for (const bundle of await pendingBundleSteps(db, bundleChainsFor(config)))
226
+ for (const bundle of await pendingTablesSteps(db, tablesChainsFor(config)))
222
227
  if (bundle.pending.length > 0)
223
228
  results.push(
224
229
  result(
225
230
  'Error',
226
- `The bundle "${bundle.name}" has ${bundle.pending.length} upgrade step(s) that have not run yet. Run \`crombolo upgrade\`.`,
231
+ `${bundle.id === 'site' ? "The site's own tables have" : `The bundle "${bundle.name}" has`} ${bundle.pending.length} upgrade step(s) that have not run yet. Run \`crombolo upgrade\`.`,
227
232
  ),
228
233
  )
229
234
  if (options.nodeState) {
@@ -3,7 +3,7 @@
3
3
  * repository takes a kind), never published. An item's file is the path its
4
4
  * `umbracoFile` holds, served from the media root.
5
5
  */
6
- import type { MediaPort } from '@crombolo/api-management'
6
+ import type { MediaPort } from '@crombolo/api-management/domain'
7
7
  import {
8
8
  type ContentTypeAggregate,
9
9
  DEFAULT_UPLOAD_SETTINGS,
@@ -72,9 +72,12 @@ export function createMediaPort(
72
72
  originalParent: (key) => repo.originalParent(key),
73
73
  versions: (key) => repo.versions(key),
74
74
  async systemUserKey() {
75
- const rows = await db.query<{ key: string }>(
76
- 'SELECT key FROM user_account ORDER BY id LIMIT 1',
77
- )
75
+ const rows = await db.q
76
+ .selectFrom('user_account')
77
+ .select('key')
78
+ .orderBy('id')
79
+ .limit(1)
80
+ .execute()
78
81
  return rows[0] ? normaliseUuid(String(rows[0].key)) : null
79
82
  },
80
83
 
@@ -118,10 +121,11 @@ export function createMediaPort(
118
121
  const latest = (await repo.versions(node.key))[0]
119
122
  const creator = latest?.userKey
120
123
  ? ((
121
- await db.query<{ user_name: string }>(
122
- 'SELECT user_name FROM user_account WHERE key = ?',
123
- [latest.userKey],
124
- )
124
+ await db.q
125
+ .selectFrom('user_account')
126
+ .select('user_name')
127
+ .where('key', '=', latest.userKey)
128
+ .execute()
125
129
  )[0]?.user_name ?? null)
126
130
  : null
127
131
  loaded.push({ ...media, sortOrder: node.sortOrder, creator })
@@ -3,7 +3,7 @@
3
3
  * table of their own, so this is the node repository with a name-uniqueness
4
4
  * rule on top, as Umbraco's `MemberGroupService` has.
5
5
  */
6
- import type { MemberGroupPort, MemberGroupStatus } from '@crombolo/api-management'
6
+ import type { MemberGroupPort, MemberGroupStatus } from '@crombolo/api-management/domain'
7
7
  import { ObjectTypes, type Page, SystemNodes } from '@crombolo/core'
8
8
  import { type Db, NodeRepository } from '@crombolo/data'
9
9
 
@@ -13,10 +13,12 @@ export function createMemberGroupPort(db: Db): MemberGroupPort {
13
13
  const nodes = new NodeRepository(db)
14
14
 
15
15
  const named = async (name: string): Promise<{ key: string } | undefined> => {
16
- const rows = await db.query<{ unique_id: string }>(
17
- 'SELECT n.unique_id FROM node n WHERE n.node_object_type = ? AND n.text = ?',
18
- [TYPE, name],
19
- )
16
+ const rows = await db.q
17
+ .selectFrom('node as n')
18
+ .select('n.unique_id')
19
+ .where('n.node_object_type', '=', TYPE)
20
+ .where('n.text', '=', name)
21
+ .execute()
20
22
  const key = rows[0]?.unique_id
21
23
  return key ? { key: String(key) } : undefined
22
24
  }
@@ -82,7 +84,7 @@ export function createMemberGroupPort(db: Db): MemberGroupPort {
82
84
  async remove(key): Promise<MemberGroupStatus> {
83
85
  const node = await nodes.byKey(key)
84
86
  if (!node || node.objectType !== TYPE) return 'not-found'
85
- await db.exec('DELETE FROM member_group_member WHERE member_group_id = ?', [node.id])
87
+ await db.q.deleteFrom('member_group_member').where('member_group_id', '=', node.id).execute()
86
88
  await nodes.delete(node.id)
87
89
  return 'ok'
88
90
  },
@@ -23,7 +23,7 @@ import type {
23
23
  MemberResponse,
24
24
  Principal,
25
25
  SaveMember,
26
- } from '@crombolo/api-management'
26
+ } from '@crombolo/api-management/domain'
27
27
  import { hashPassword, passwordConfigJson, verifyPassword } from '@crombolo/auth'
28
28
  import {
29
29
  type ContentTypeAggregate,
@@ -75,9 +75,11 @@ export function createMemberPort(db: Db, options: MemberPortOptions = {}): Membe
75
75
  const twoFactor = new TwoFactorRepository(db)
76
76
 
77
77
  const userIdOf = async (principal: Principal): Promise<number | undefined> => {
78
- const rows = await db.query<{ id: number }>('SELECT id FROM user_account WHERE key = ?', [
79
- principal.id,
80
- ])
78
+ const rows = await db.q
79
+ .selectFrom('user_account')
80
+ .select('id')
81
+ .where('key', '=', principal.id)
82
+ .execute()
81
83
  return rows[0] ? Number(rows[0].id) : undefined
82
84
  }
83
85
 
@@ -14,7 +14,7 @@ import type {
14
14
  PublicAccessPort,
15
15
  PublicAccessResponse,
16
16
  PublicAccessStatus,
17
- } from '@crombolo/api-management'
17
+ } from '@crombolo/api-management/domain'
18
18
  import { ObjectTypes } from '@crombolo/core'
19
19
  import {
20
20
  type Db,
@@ -40,10 +40,12 @@ export function createPublicAccessPort(
40
40
  const groupsNamed = async (names: readonly string[]): Promise<MemberGroupItem[]> => {
41
41
  const found: MemberGroupItem[] = []
42
42
  for (const name of names) {
43
- const rows = await db.query<{ unique_id: string; text: string | null }>(
44
- 'SELECT unique_id, text FROM node WHERE node_object_type = ? AND text = ?',
45
- [ObjectTypes.MemberGroup, name],
46
- )
43
+ const rows = await db.q
44
+ .selectFrom('node')
45
+ .select(['unique_id', 'text'])
46
+ .where('node_object_type', '=', ObjectTypes.MemberGroup)
47
+ .where('text', '=', name)
48
+ .execute()
47
49
  const row = rows[0]
48
50
  if (row) found.push({ id: String(row.unique_id), name: String(row.text ?? ''), flags: [] })
49
51
  }
@@ -7,7 +7,7 @@
7
7
  * config file owns it, and the next boot would put it back.
8
8
  */
9
9
 
10
- import type { RedirectListing, RedirectPort } from '@crombolo/api-management'
10
+ import type { RedirectListing, RedirectPort } from '@crombolo/api-management/domain'
11
11
  import type { Page } from '@crombolo/core'
12
12
  import {
13
13
  appendCacheInstruction,
@@ -3,7 +3,7 @@
3
3
  * `$type`, so a referencing node becomes a document, a media item, or the
4
4
  * default shape when it is neither.
5
5
  */
6
- import type { ReferencePort } from '@crombolo/api-management'
6
+ import type { ReferencePort } from '@crombolo/api-management/domain'
7
7
  import { ObjectTypes } from '@crombolo/core'
8
8
  import { type Db, ReferenceRepository, type ReferencingNode } from '@crombolo/data'
9
9
 
@@ -1,5 +1,5 @@
1
1
  /** Relation types and their derived relations, shaped for the wire. */
2
- import type { RelationPort, RelationTypeView } from '@crombolo/api-management'
2
+ import type { RelationPort, RelationTypeView } from '@crombolo/api-management/domain'
3
3
  import { ObjectTypes } from '@crombolo/core'
4
4
  import { type Db, RELATION_TYPES, RelationRepository, relationTypeByKey } from '@crombolo/data'
5
5