@crombolo/data 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.
- package/package.json +3 -2
- package/src/audit.ts +164 -134
- package/src/change-report.ts +66 -43
- package/src/cluster.ts +119 -59
- package/src/content-query.ts +205 -200
- package/src/{bundle-tables → custom-tables}/builder.ts +104 -12
- package/src/custom-tables/chain.ts +150 -0
- package/src/custom-tables/ddl.ts +159 -0
- package/src/custom-tables/handle.ts +141 -0
- package/src/{bundle-tables → custom-tables}/index.ts +3 -2
- package/src/custom-tables/names.ts +94 -0
- package/src/custom-tables/owners.ts +299 -0
- package/src/{bundle-tables → custom-tables}/schema.ts +263 -90
- package/src/custom-tables/values.ts +181 -0
- package/src/database.ts +40 -5
- package/src/dialect.ts +43 -16
- package/src/index.ts +9 -1
- package/src/migrations.ts +130 -88
- package/src/query.ts +158 -0
- package/src/relations.ts +49 -28
- package/src/repositories/approvals.ts +130 -89
- package/src/repositories/bundle-grants.ts +105 -0
- package/src/repositories/bundles.ts +85 -76
- package/src/repositories/content-applied.ts +47 -28
- package/src/repositories/content-events.ts +114 -67
- package/src/repositories/content-notifications.ts +102 -74
- package/src/repositories/content-types.ts +449 -320
- package/src/repositories/data-types.ts +105 -56
- package/src/repositories/delivery-member-tokens.ts +37 -28
- package/src/repositories/dictionary.ts +77 -58
- package/src/repositories/documents.ts +956 -580
- package/src/repositories/domains.ts +28 -16
- package/src/repositories/dynamic-roots.ts +32 -17
- package/src/repositories/external-logins.ts +38 -24
- package/src/repositories/folders.ts +7 -4
- package/src/repositories/form-entries.ts +120 -103
- package/src/repositories/form-workflows.ts +87 -62
- package/src/repositories/jobs.ts +296 -0
- package/src/repositories/languages.ts +51 -38
- package/src/repositories/log-searches.ts +7 -5
- package/src/repositories/media-access.ts +173 -123
- package/src/repositories/media-listing.ts +155 -92
- package/src/repositories/members.ts +189 -162
- package/src/repositories/nodes.ts +227 -181
- package/src/repositories/notifications.ts +22 -17
- package/src/repositories/public-access.ts +77 -61
- package/src/repositories/redirects.ts +113 -70
- package/src/repositories/references.ts +55 -44
- package/src/repositories/remote-jobs.ts +45 -35
- package/src/repositories/tags.ts +11 -10
- package/src/repositories/templates.ts +24 -14
- package/src/repositories/transfer-answers.ts +58 -50
- package/src/repositories/transfer-runs.ts +93 -75
- package/src/repositories/two-factor.ts +74 -55
- package/src/repositories/user-data.ts +54 -36
- package/src/repositories/users.ts +345 -300
- package/src/repositories/webhooks.ts +196 -137
- package/src/schema/bundle-grants.ts +32 -0
- package/src/schema/bundles-disabled.ts +29 -0
- package/src/schema/jobs.ts +56 -0
- package/src/schema/plan.ts +6 -0
- package/src/schema-ops.ts +15 -12
- package/src/schema-state.ts +53 -38
- package/src/search.ts +175 -129
- package/src/setup.ts +17 -13
- package/src/site-search.ts +134 -83
- package/src/table-types.ts +152 -0
- package/src/tables.gen.ts +861 -0
- package/src/tree-invariants.ts +21 -12
- package/src/url-options.ts +17 -13
- package/src/workflow-store.ts +17 -13
- package/src/bundle-tables/capability.ts +0 -377
- package/src/bundle-tables/chain.ts +0 -105
- package/src/bundle-tables/ddl.ts +0 -124
- package/src/bundle-tables/guard.ts +0 -116
- package/src/bundle-tables/names.ts +0 -58
|
@@ -94,7 +94,7 @@ const scheduleFrom = (json: string): ApprovalScheduleEntry[] =>
|
|
|
94
94
|
}))
|
|
95
95
|
|
|
96
96
|
/** States a request is still open in: it holds the page until it ends. */
|
|
97
|
-
const OPEN =
|
|
97
|
+
const OPEN = ['waiting', 'scheduled']
|
|
98
98
|
|
|
99
99
|
const requestFrom = (row: Record<string, unknown>): ApprovalRequest => ({
|
|
100
100
|
id: Number(row.id),
|
|
@@ -157,96 +157,127 @@ export class ApprovalRepository {
|
|
|
157
157
|
schedule?: ApprovalScheduleEntry[] | null
|
|
158
158
|
}): Promise<ApprovalRequest> {
|
|
159
159
|
const key = crypto.randomUUID()
|
|
160
|
-
await this.#db.
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 'waiting', ?, ?, ?)`,
|
|
164
|
-
[
|
|
160
|
+
await this.#db.q
|
|
161
|
+
.insertInto('approval_request')
|
|
162
|
+
.values({
|
|
165
163
|
key,
|
|
166
|
-
normaliseUuid(input.nodeKey),
|
|
167
|
-
input.cultures ? JSON.stringify(input.cultures) : null,
|
|
168
|
-
input.action,
|
|
169
|
-
input.eventId,
|
|
170
|
-
workflowIdentity(input.workflow),
|
|
171
|
-
input.workflowVersion,
|
|
172
|
-
JSON.stringify(input.workflow),
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
164
|
+
node_key: normaliseUuid(input.nodeKey),
|
|
165
|
+
cultures: input.cultures ? JSON.stringify(input.cultures) : null,
|
|
166
|
+
action: input.action,
|
|
167
|
+
event_id: input.eventId,
|
|
168
|
+
workflow_key: workflowIdentity(input.workflow),
|
|
169
|
+
workflow_version: input.workflowVersion,
|
|
170
|
+
workflow: JSON.stringify(input.workflow),
|
|
171
|
+
state: 'waiting',
|
|
172
|
+
requested_by: normaliseUuid(input.requestedBy),
|
|
173
|
+
requested_at: DbDate.toDb(new Date()),
|
|
174
|
+
schedule: input.schedule?.length ? JSON.stringify(input.schedule) : null,
|
|
175
|
+
})
|
|
176
|
+
.execute()
|
|
178
177
|
return (await this.byKey(key)) as ApprovalRequest
|
|
179
178
|
}
|
|
180
179
|
|
|
181
180
|
async byKey(key: string): Promise<ApprovalRequest | undefined> {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
181
|
+
const row = await this.#db.q
|
|
182
|
+
.selectFrom('approval_request')
|
|
183
|
+
.selectAll()
|
|
184
|
+
.where('key', '=', normaliseUuid(key))
|
|
185
|
+
.executeTakeFirst()
|
|
186
|
+
return row ? requestFrom(row) : undefined
|
|
186
187
|
}
|
|
187
188
|
|
|
188
189
|
/** The request a page is waiting on or scheduled under, if any: at most one at a time. */
|
|
189
190
|
async openFor(nodeKey: string): Promise<ApprovalRequest | undefined> {
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
191
|
+
const row = await this.#db.q
|
|
192
|
+
.selectFrom('approval_request')
|
|
193
|
+
.selectAll()
|
|
194
|
+
.where('node_key', '=', normaliseUuid(nodeKey))
|
|
195
|
+
.where('state', 'in', OPEN)
|
|
196
|
+
.orderBy('id', 'desc')
|
|
197
|
+
.executeTakeFirst()
|
|
198
|
+
return row ? requestFrom(row) : undefined
|
|
195
199
|
}
|
|
196
200
|
|
|
197
201
|
/** A page's requests, newest first. */
|
|
198
202
|
async forNode(nodeKey: string, limit = 20): Promise<ApprovalRequest[]> {
|
|
199
|
-
const rows = await this.#db.
|
|
200
|
-
'
|
|
201
|
-
|
|
202
|
-
|
|
203
|
+
const rows = await this.#db.q
|
|
204
|
+
.selectFrom('approval_request')
|
|
205
|
+
.selectAll()
|
|
206
|
+
.where('node_key', '=', normaliseUuid(nodeKey))
|
|
207
|
+
.orderBy('id', 'desc')
|
|
208
|
+
.limit(limit)
|
|
209
|
+
.execute()
|
|
203
210
|
return rows.map(requestFrom)
|
|
204
211
|
}
|
|
205
212
|
|
|
206
213
|
/** Every request still open (waiting or scheduled), oldest first. */
|
|
207
214
|
async open(): Promise<ApprovalRequest[]> {
|
|
208
|
-
const rows = await this.#db.
|
|
215
|
+
const rows = await this.#db.q
|
|
216
|
+
.selectFrom('approval_request')
|
|
217
|
+
.selectAll()
|
|
218
|
+
.where('state', 'in', OPEN)
|
|
219
|
+
.orderBy('id')
|
|
220
|
+
.execute()
|
|
209
221
|
return rows.map(requestFrom)
|
|
210
222
|
}
|
|
211
223
|
|
|
212
224
|
/** Every request approved and waiting for its time, oldest first. */
|
|
213
225
|
async scheduled(): Promise<ApprovalRequest[]> {
|
|
214
|
-
const rows = await this.#db.
|
|
215
|
-
|
|
216
|
-
|
|
226
|
+
const rows = await this.#db.q
|
|
227
|
+
.selectFrom('approval_request')
|
|
228
|
+
.selectAll()
|
|
229
|
+
.where('state', '=', 'scheduled')
|
|
230
|
+
.orderBy('id')
|
|
231
|
+
.execute()
|
|
217
232
|
return rows.map(requestFrom)
|
|
218
233
|
}
|
|
219
234
|
|
|
220
235
|
/** Requests that have finished, newest first. */
|
|
221
236
|
async finished(skip: number, take: number): Promise<{ total: number; items: ApprovalRequest[] }> {
|
|
222
|
-
const counted = await this.#db.
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
237
|
+
const counted = await this.#db.q
|
|
238
|
+
.selectFrom('approval_request')
|
|
239
|
+
.select((eb) => eb.fn.countAll<number>().as('n'))
|
|
240
|
+
.where('state', 'not in', OPEN)
|
|
241
|
+
.executeTakeFirst()
|
|
242
|
+
const rows = await this.#db.q
|
|
243
|
+
.selectFrom('approval_request')
|
|
244
|
+
.selectAll()
|
|
245
|
+
.where('state', 'not in', OPEN)
|
|
246
|
+
.orderBy('id', 'desc')
|
|
247
|
+
.limit(take)
|
|
248
|
+
.offset(skip)
|
|
249
|
+
.execute()
|
|
250
|
+
return { total: Number(counted?.n ?? 0), items: rows.map(requestFrom) }
|
|
230
251
|
}
|
|
231
252
|
|
|
232
253
|
async waitingUnder(workflowKey: string): Promise<ApprovalRequest[]> {
|
|
233
|
-
const rows = await this.#db.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
254
|
+
const rows = await this.#db.q
|
|
255
|
+
.selectFrom('approval_request')
|
|
256
|
+
.selectAll()
|
|
257
|
+
.where('workflow_key', '=', workflowKey)
|
|
258
|
+
.where('state', '=', 'waiting')
|
|
259
|
+
.orderBy('id')
|
|
260
|
+
.execute()
|
|
237
261
|
return rows.map(requestFrom)
|
|
238
262
|
}
|
|
239
263
|
|
|
240
264
|
async setState(id: number, state: ApprovalState): Promise<void> {
|
|
241
|
-
await this.#db.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
265
|
+
await this.#db.q
|
|
266
|
+
.updateTable('approval_request')
|
|
267
|
+
.set({
|
|
268
|
+
state,
|
|
269
|
+
finished_at: state === 'waiting' || state === 'scheduled' ? null : DbDate.toDb(new Date()),
|
|
270
|
+
})
|
|
271
|
+
.where('id', '=', id)
|
|
272
|
+
.execute()
|
|
246
273
|
}
|
|
247
274
|
|
|
248
275
|
async setEvent(id: number, eventId: number | null): Promise<void> {
|
|
249
|
-
await this.#db.
|
|
276
|
+
await this.#db.q
|
|
277
|
+
.updateTable('approval_request')
|
|
278
|
+
.set({ event_id: eventId })
|
|
279
|
+
.where('id', '=', id)
|
|
280
|
+
.execute()
|
|
250
281
|
}
|
|
251
282
|
|
|
252
283
|
/**
|
|
@@ -254,35 +285,44 @@ export class ApprovalRepository {
|
|
|
254
285
|
* stage visits are cleared, and its history keeps what happened.
|
|
255
286
|
*/
|
|
256
287
|
async rebase(id: number, workflow: SchemaWorkflow, version: string): Promise<void> {
|
|
257
|
-
await this.#db.
|
|
258
|
-
'
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
288
|
+
await this.#db.q
|
|
289
|
+
.updateTable('approval_request')
|
|
290
|
+
.set({ workflow: JSON.stringify(workflow), workflow_version: version })
|
|
291
|
+
.where('id', '=', id)
|
|
292
|
+
.execute()
|
|
293
|
+
await this.#db.q.deleteFrom('approval_step').where('request_id', '=', id).execute()
|
|
262
294
|
}
|
|
263
295
|
|
|
264
296
|
async steps(requestId: number): Promise<ApprovalStep[]> {
|
|
265
|
-
const rows = await this.#db.
|
|
266
|
-
'
|
|
267
|
-
|
|
268
|
-
|
|
297
|
+
const rows = await this.#db.q
|
|
298
|
+
.selectFrom('approval_step')
|
|
299
|
+
.selectAll()
|
|
300
|
+
.where('request_id', '=', requestId)
|
|
301
|
+
.orderBy('id')
|
|
302
|
+
.execute()
|
|
269
303
|
return rows.map(stepFrom)
|
|
270
304
|
}
|
|
271
305
|
|
|
272
306
|
async addStep(requestId: number, stage: string): Promise<number> {
|
|
273
|
-
const
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
307
|
+
const row = await this.#db.q
|
|
308
|
+
.insertInto('approval_step')
|
|
309
|
+
.values({
|
|
310
|
+
request_id: requestId,
|
|
311
|
+
stage,
|
|
312
|
+
state: 'waiting',
|
|
313
|
+
reached_at: DbDate.toDb(new Date()),
|
|
314
|
+
})
|
|
315
|
+
.returning('id')
|
|
316
|
+
.executeTakeFirst()
|
|
317
|
+
return Number(row?.id)
|
|
278
318
|
}
|
|
279
319
|
|
|
280
320
|
async setStepState(id: number, state: ApprovalStepState): Promise<void> {
|
|
281
|
-
await this.#db.
|
|
282
|
-
|
|
283
|
-
state === 'waiting' ? null : DbDate.toDb(new Date())
|
|
284
|
-
id,
|
|
285
|
-
|
|
321
|
+
await this.#db.q
|
|
322
|
+
.updateTable('approval_step')
|
|
323
|
+
.set({ state, done_at: state === 'waiting' ? null : DbDate.toDb(new Date()) })
|
|
324
|
+
.where('id', '=', id)
|
|
325
|
+
.execute()
|
|
286
326
|
}
|
|
287
327
|
|
|
288
328
|
async record(
|
|
@@ -295,26 +335,27 @@ export class ApprovalRepository {
|
|
|
295
335
|
comment?: string | null
|
|
296
336
|
},
|
|
297
337
|
): Promise<void> {
|
|
298
|
-
await this.#db.
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
entry.
|
|
304
|
-
entry.
|
|
305
|
-
entry.
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
)
|
|
338
|
+
await this.#db.q
|
|
339
|
+
.insertInto('approval_history')
|
|
340
|
+
.values({
|
|
341
|
+
request_id: requestId,
|
|
342
|
+
step_id: entry.stepId ?? null,
|
|
343
|
+
stage: entry.stage ?? null,
|
|
344
|
+
kind: entry.kind,
|
|
345
|
+
user_key: entry.userKey ? normaliseUuid(entry.userKey) : null,
|
|
346
|
+
comment: entry.comment ?? null,
|
|
347
|
+
create_date: DbDate.toDb(new Date()),
|
|
348
|
+
})
|
|
349
|
+
.execute()
|
|
311
350
|
}
|
|
312
351
|
|
|
313
352
|
async history(requestId: number): Promise<ApprovalHistoryEntry[]> {
|
|
314
|
-
const rows = await this.#db.
|
|
315
|
-
'
|
|
316
|
-
|
|
317
|
-
|
|
353
|
+
const rows = await this.#db.q
|
|
354
|
+
.selectFrom('approval_history')
|
|
355
|
+
.selectAll()
|
|
356
|
+
.where('request_id', '=', requestId)
|
|
357
|
+
.orderBy('id')
|
|
358
|
+
.execute()
|
|
318
359
|
return rows.map(historyFrom)
|
|
319
360
|
}
|
|
320
361
|
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What each bundle was approved for (stories 222 and 225): one row per bundle,
|
|
3
|
+
* its approval replaced as it changes, and whether an administrator disabled
|
|
4
|
+
* it. docs/bundles.md, "Permissions".
|
|
5
|
+
*/
|
|
6
|
+
import type { Db } from '../database.ts'
|
|
7
|
+
import { DbDate } from '../dialect.ts'
|
|
8
|
+
|
|
9
|
+
export interface BundleGrant {
|
|
10
|
+
bundleId: string
|
|
11
|
+
packageName: string
|
|
12
|
+
version: string
|
|
13
|
+
permissions: string[]
|
|
14
|
+
grantedBy: string | null
|
|
15
|
+
grantedAt: Date
|
|
16
|
+
/** Who disabled the bundle, and when; null while it may run. */
|
|
17
|
+
disabledBy: string | null
|
|
18
|
+
disabledAt: Date | null
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const permissionsOf = (value: unknown): string[] => {
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(String(value)) as unknown
|
|
24
|
+
return Array.isArray(parsed) ? parsed.filter((p): p is string => typeof p === 'string') : []
|
|
25
|
+
} catch {
|
|
26
|
+
return []
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export class BundleGrantRepository {
|
|
31
|
+
constructor(private readonly db: Db) {}
|
|
32
|
+
|
|
33
|
+
async all(): Promise<BundleGrant[]> {
|
|
34
|
+
const rows = await this.db.q
|
|
35
|
+
.selectFrom('bundle_grant')
|
|
36
|
+
.selectAll()
|
|
37
|
+
.orderBy('bundle_id')
|
|
38
|
+
.execute()
|
|
39
|
+
return rows.map((row) => ({
|
|
40
|
+
bundleId: row.bundle_id,
|
|
41
|
+
packageName: row.package_name,
|
|
42
|
+
version: row.version,
|
|
43
|
+
permissions: permissionsOf(row.permissions),
|
|
44
|
+
grantedBy: row.granted_by ?? null,
|
|
45
|
+
grantedAt: DbDate.fromDb(row.granted_at) ?? new Date(0),
|
|
46
|
+
disabledBy: row.disabled_by ?? null,
|
|
47
|
+
disabledAt: row.disabled_at ? (DbDate.fromDb(row.disabled_at) ?? null) : null,
|
|
48
|
+
}))
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async get(bundleId: string): Promise<BundleGrant | undefined> {
|
|
52
|
+
return (await this.all()).find((grant) => grant.bundleId === bundleId)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Records what a bundle is approved for, keeping whether it is disabled. */
|
|
56
|
+
async grant(grant: Omit<BundleGrant, 'grantedAt' | 'disabledBy' | 'disabledAt'>): Promise<void> {
|
|
57
|
+
const values = {
|
|
58
|
+
package_name: grant.packageName,
|
|
59
|
+
version: grant.version,
|
|
60
|
+
permissions: JSON.stringify(grant.permissions),
|
|
61
|
+
granted_by: grant.grantedBy,
|
|
62
|
+
granted_at: DbDate.toDb(new Date()),
|
|
63
|
+
}
|
|
64
|
+
await this.db.q
|
|
65
|
+
.insertInto('bundle_grant')
|
|
66
|
+
.values({ bundle_id: grant.bundleId, ...values })
|
|
67
|
+
.onConflict((conflict) => conflict.column('bundle_id').doUpdateSet(values))
|
|
68
|
+
.execute()
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Disables a bundle, recording its package as it stands when it has no row
|
|
73
|
+
* yet; it stays disabled until `enable`.
|
|
74
|
+
*/
|
|
75
|
+
async disable(
|
|
76
|
+
bundle: Pick<BundleGrant, 'bundleId' | 'packageName' | 'version'>,
|
|
77
|
+
by: string | null,
|
|
78
|
+
): Promise<void> {
|
|
79
|
+
const disabled = { disabled_by: by, disabled_at: DbDate.toDb(new Date()) }
|
|
80
|
+
await this.db.q
|
|
81
|
+
.insertInto('bundle_grant')
|
|
82
|
+
.values({
|
|
83
|
+
bundle_id: bundle.bundleId,
|
|
84
|
+
package_name: bundle.packageName,
|
|
85
|
+
version: bundle.version,
|
|
86
|
+
permissions: JSON.stringify([]),
|
|
87
|
+
granted_by: null,
|
|
88
|
+
granted_at: DbDate.toDb(new Date()),
|
|
89
|
+
...disabled,
|
|
90
|
+
})
|
|
91
|
+
.onConflict((conflict) => conflict.column('bundle_id').doUpdateSet(disabled))
|
|
92
|
+
.execute()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** Lets a disabled bundle run again; true when it was disabled. */
|
|
96
|
+
async enable(bundleId: string): Promise<boolean> {
|
|
97
|
+
const before = await this.get(bundleId)
|
|
98
|
+
await this.db.q
|
|
99
|
+
.updateTable('bundle_grant')
|
|
100
|
+
.set({ disabled_by: null, disabled_at: null })
|
|
101
|
+
.where('bundle_id', '=', bundleId)
|
|
102
|
+
.execute()
|
|
103
|
+
return before?.disabledAt != null
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { randomUUID } from 'node:crypto'
|
|
10
10
|
import type { Db } from '../database.ts'
|
|
11
11
|
import { DbDate, fromDbBool } from '../dialect.ts'
|
|
12
|
+
import { sql } from '../query.ts'
|
|
12
13
|
|
|
13
14
|
export interface Bundle {
|
|
14
15
|
id: string
|
|
@@ -64,12 +65,45 @@ interface Row {
|
|
|
64
65
|
update_date: unknown
|
|
65
66
|
}
|
|
66
67
|
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
68
|
+
const COLUMNS = [
|
|
69
|
+
'id',
|
|
70
|
+
'name',
|
|
71
|
+
'content_node_id',
|
|
72
|
+
'content_load_child_nodes',
|
|
73
|
+
'media_load_child_nodes',
|
|
74
|
+
'media_ids',
|
|
75
|
+
'element_ids',
|
|
76
|
+
'content_types',
|
|
77
|
+
'media_types',
|
|
78
|
+
'data_types',
|
|
79
|
+
'components',
|
|
80
|
+
'stylesheets',
|
|
81
|
+
'scripts',
|
|
82
|
+
'languages',
|
|
83
|
+
'dictionary_items',
|
|
84
|
+
'package_name',
|
|
85
|
+
'package_version',
|
|
86
|
+
'create_date',
|
|
87
|
+
'update_date',
|
|
88
|
+
] as const
|
|
89
|
+
|
|
90
|
+
/** The selection lists as stored: JSON text, one column each. */
|
|
91
|
+
const selections = (db: Db, input: BundleInput) => ({
|
|
92
|
+
name: input.name,
|
|
93
|
+
content_node_id: input.contentNodeId,
|
|
94
|
+
content_load_child_nodes: db.dialect.boolValue(input.contentLoadChildNodes),
|
|
95
|
+
media_load_child_nodes: db.dialect.boolValue(input.mediaLoadChildNodes),
|
|
96
|
+
media_ids: JSON.stringify(input.mediaIds),
|
|
97
|
+
element_ids: input.elementIds === null ? null : JSON.stringify(input.elementIds),
|
|
98
|
+
content_types: JSON.stringify(input.contentTypes),
|
|
99
|
+
media_types: JSON.stringify(input.mediaTypes),
|
|
100
|
+
data_types: JSON.stringify(input.dataTypes),
|
|
101
|
+
components: JSON.stringify(input.components),
|
|
102
|
+
stylesheets: JSON.stringify(input.stylesheets),
|
|
103
|
+
scripts: JSON.stringify(input.scripts),
|
|
104
|
+
languages: JSON.stringify(input.languages),
|
|
105
|
+
dictionary_items: JSON.stringify(input.dictionaryItems),
|
|
106
|
+
})
|
|
73
107
|
|
|
74
108
|
const list = (value: string | null): string[] => {
|
|
75
109
|
if (!value) return []
|
|
@@ -115,57 +149,49 @@ export class BundleRepository {
|
|
|
115
149
|
async list(
|
|
116
150
|
options: { skip?: number; take?: number } = {},
|
|
117
151
|
): Promise<{ total: number; items: Bundle[] }> {
|
|
118
|
-
const counted = await this.#db.
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
152
|
+
const counted = await this.#db.q
|
|
153
|
+
.selectFrom('bundle')
|
|
154
|
+
.select(sql<number>`count(*)`.as('total'))
|
|
155
|
+
.executeTakeFirst()
|
|
156
|
+
const rows = await this.#db.q
|
|
157
|
+
.selectFrom('bundle')
|
|
158
|
+
.select(COLUMNS)
|
|
159
|
+
.orderBy('name')
|
|
160
|
+
.limit(options.take ?? 100)
|
|
161
|
+
.offset(options.skip ?? 0)
|
|
162
|
+
.execute()
|
|
163
|
+
return { total: Number(counted?.total ?? 0), items: rows.map(hydrate) }
|
|
124
164
|
}
|
|
125
165
|
|
|
126
166
|
async byId(id: string): Promise<Bundle | undefined> {
|
|
127
|
-
const
|
|
128
|
-
|
|
167
|
+
const row = await this.#db.q
|
|
168
|
+
.selectFrom('bundle')
|
|
169
|
+
.select(COLUMNS)
|
|
170
|
+
.where('id', '=', id)
|
|
171
|
+
.executeTakeFirst()
|
|
129
172
|
return row ? hydrate(row) : undefined
|
|
130
173
|
}
|
|
131
174
|
|
|
132
175
|
async byName(name: string): Promise<Bundle | undefined> {
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
176
|
+
const row = await this.#db.q
|
|
177
|
+
.selectFrom('bundle')
|
|
178
|
+
.select(COLUMNS)
|
|
179
|
+
.where((eb) => eb(eb.fn('lower', ['name']), '=', name.trim().toLowerCase()))
|
|
180
|
+
.executeTakeFirst()
|
|
137
181
|
return row ? hydrate(row) : undefined
|
|
138
182
|
}
|
|
139
183
|
|
|
140
184
|
async create(input: BundleInput, id: string = randomUUID()): Promise<Bundle> {
|
|
141
185
|
const now = new Date()
|
|
142
|
-
await this.#db.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
media_ids, element_ids, content_types, media_types, data_types, components,
|
|
146
|
-
stylesheets, scripts, languages, dictionary_items,
|
|
147
|
-
create_date, update_date)
|
|
148
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
149
|
-
[
|
|
186
|
+
await this.#db.q
|
|
187
|
+
.insertInto('bundle')
|
|
188
|
+
.values({
|
|
150
189
|
id,
|
|
151
|
-
input
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
input.elementIds === null ? null : JSON.stringify(input.elementIds),
|
|
157
|
-
JSON.stringify(input.contentTypes),
|
|
158
|
-
JSON.stringify(input.mediaTypes),
|
|
159
|
-
JSON.stringify(input.dataTypes),
|
|
160
|
-
JSON.stringify(input.components),
|
|
161
|
-
JSON.stringify(input.stylesheets),
|
|
162
|
-
JSON.stringify(input.scripts),
|
|
163
|
-
JSON.stringify(input.languages),
|
|
164
|
-
JSON.stringify(input.dictionaryItems),
|
|
165
|
-
DbDate.toDb(now),
|
|
166
|
-
DbDate.toDb(now),
|
|
167
|
-
],
|
|
168
|
-
)
|
|
190
|
+
...selections(this.#db, input),
|
|
191
|
+
create_date: DbDate.toDb(now),
|
|
192
|
+
update_date: DbDate.toDb(now),
|
|
193
|
+
})
|
|
194
|
+
.execute()
|
|
169
195
|
return {
|
|
170
196
|
...input,
|
|
171
197
|
id,
|
|
@@ -177,33 +203,11 @@ export class BundleRepository {
|
|
|
177
203
|
}
|
|
178
204
|
|
|
179
205
|
async update(id: string, input: BundleInput): Promise<void> {
|
|
180
|
-
await this.#db.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
stylesheets = ?, scripts = ?, languages = ?,
|
|
186
|
-
dictionary_items = ?, update_date = ?
|
|
187
|
-
WHERE id = ?`,
|
|
188
|
-
[
|
|
189
|
-
input.name,
|
|
190
|
-
input.contentNodeId,
|
|
191
|
-
this.#db.dialect.boolValue(input.contentLoadChildNodes),
|
|
192
|
-
this.#db.dialect.boolValue(input.mediaLoadChildNodes),
|
|
193
|
-
JSON.stringify(input.mediaIds),
|
|
194
|
-
input.elementIds === null ? null : JSON.stringify(input.elementIds),
|
|
195
|
-
JSON.stringify(input.contentTypes),
|
|
196
|
-
JSON.stringify(input.mediaTypes),
|
|
197
|
-
JSON.stringify(input.dataTypes),
|
|
198
|
-
JSON.stringify(input.components),
|
|
199
|
-
JSON.stringify(input.stylesheets),
|
|
200
|
-
JSON.stringify(input.scripts),
|
|
201
|
-
JSON.stringify(input.languages),
|
|
202
|
-
JSON.stringify(input.dictionaryItems),
|
|
203
|
-
DbDate.toDb(new Date()),
|
|
204
|
-
id,
|
|
205
|
-
],
|
|
206
|
-
)
|
|
206
|
+
await this.#db.q
|
|
207
|
+
.updateTable('bundle')
|
|
208
|
+
.set({ ...selections(this.#db, input), update_date: DbDate.toDb(new Date()) })
|
|
209
|
+
.where('id', '=', id)
|
|
210
|
+
.execute()
|
|
207
211
|
}
|
|
208
212
|
|
|
209
213
|
/** The npm package a definition is built as; null clears a value back to its default. */
|
|
@@ -211,13 +215,18 @@ export class BundleRepository {
|
|
|
211
215
|
id: string,
|
|
212
216
|
pkg: { name: string | null; version: string | null },
|
|
213
217
|
): Promise<void> {
|
|
214
|
-
await this.#db.
|
|
215
|
-
'
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
await this.#db.q
|
|
219
|
+
.updateTable('bundle')
|
|
220
|
+
.set({
|
|
221
|
+
package_name: pkg.name,
|
|
222
|
+
package_version: pkg.version,
|
|
223
|
+
update_date: DbDate.toDb(new Date()),
|
|
224
|
+
})
|
|
225
|
+
.where('id', '=', id)
|
|
226
|
+
.execute()
|
|
218
227
|
}
|
|
219
228
|
|
|
220
229
|
async delete(id: string): Promise<void> {
|
|
221
|
-
await this.#db.
|
|
230
|
+
await this.#db.q.deleteFrom('bundle').where('id', '=', id).execute()
|
|
222
231
|
}
|
|
223
232
|
}
|