@crombolo/data 0.37.0 → 0.38.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/audit.ts +163 -133
- 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 +8 -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 +74 -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/jobs.ts +56 -0
- package/src/schema/plan.ts +4 -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 +859 -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
|
@@ -38,15 +38,18 @@ const GROUP_TYPE_NAMES = ['Group', 'Tab'] as const
|
|
|
38
38
|
* settings, and whether the type is in site search: what its items are indexed by.
|
|
39
39
|
*/
|
|
40
40
|
async function propertySignature(db: Db, contentTypeNodeId: number): Promise<string> {
|
|
41
|
-
const rows = await db.
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
const rows = await db.q
|
|
42
|
+
.selectFrom('property_type as p')
|
|
43
|
+
.select(['p.id', 'p.alias', 'p.variations', 'p.data_type_id', 'p.searchable', 'p.site_search'])
|
|
44
|
+
.where('p.content_type_id', '=', contentTypeNodeId)
|
|
45
|
+
.where('p.retired_at', 'is', null)
|
|
46
|
+
.orderBy('p.id')
|
|
47
|
+
.execute()
|
|
48
|
+
const [type] = await db.q
|
|
49
|
+
.selectFrom('content_type')
|
|
50
|
+
.select('site_search')
|
|
51
|
+
.where('node_id', '=', contentTypeNodeId)
|
|
52
|
+
.execute()
|
|
50
53
|
return [
|
|
51
54
|
`site:${type ? fromDbBool(type.site_search) : true}`,
|
|
52
55
|
...rows.map(
|
|
@@ -145,22 +148,27 @@ export class ContentTypeRepository {
|
|
|
145
148
|
alias: string,
|
|
146
149
|
options: { includeRetired?: boolean } = {},
|
|
147
150
|
): Promise<ContentTypeAggregate | undefined> {
|
|
148
|
-
const rows = await this.#db.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
151
|
+
const rows = await this.#db.q
|
|
152
|
+
.selectFrom('content_type as ct')
|
|
153
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
154
|
+
.select('n.unique_id')
|
|
155
|
+
.where('ct.alias', '=', alias)
|
|
156
|
+
.where('n.node_object_type', '=', this.#objectType)
|
|
157
|
+
.$if(!options.includeRetired, (q) => q.where('ct.retired_at', 'is', null))
|
|
158
|
+
.execute()
|
|
153
159
|
return rows[0] ? this.byKey(String(rows[0].unique_id)) : undefined
|
|
154
160
|
}
|
|
155
161
|
|
|
156
162
|
async aliasExists(alias: string, exceptKey?: string): Promise<boolean> {
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
163
|
+
const rows = await this.#db.q
|
|
164
|
+
.selectFrom('content_type as ct')
|
|
165
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
166
|
+
.select((eb) => eb.fn.countAll().as('n'))
|
|
167
|
+
.where('ct.alias', '=', alias)
|
|
168
|
+
.$if(Boolean(exceptKey), (q) =>
|
|
169
|
+
q.where('n.unique_id', '<>', normaliseUuid(exceptKey as string)),
|
|
170
|
+
)
|
|
171
|
+
.execute()
|
|
164
172
|
return Number(rows[0]?.n ?? 0) > 0
|
|
165
173
|
}
|
|
166
174
|
|
|
@@ -169,17 +177,19 @@ export class ContentTypeRepository {
|
|
|
169
177
|
skip: number,
|
|
170
178
|
take: number,
|
|
171
179
|
): Promise<{ total: number; items: ContentTypeAggregate[] }> {
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
const matching = this.#db.q
|
|
181
|
+
.selectFrom('content_type as ct')
|
|
182
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
183
|
+
.where('ct.allow_at_root', '=', this.#db.dialect.boolValue(true))
|
|
184
|
+
.where('ct.retired_at', 'is', null)
|
|
185
|
+
.where('n.node_object_type', '=', this.#objectType)
|
|
186
|
+
const totals = await matching.select((eb) => eb.fn.countAll().as('n')).execute()
|
|
187
|
+
const rows = await matching
|
|
188
|
+
.select('n.unique_id')
|
|
189
|
+
.orderBy('n.text')
|
|
190
|
+
.limit(take)
|
|
191
|
+
.offset(skip)
|
|
192
|
+
.execute()
|
|
183
193
|
const items: ContentTypeAggregate[] = []
|
|
184
194
|
let hidden = 0
|
|
185
195
|
for (const row of rows) {
|
|
@@ -200,22 +210,20 @@ export class ContentTypeRepository {
|
|
|
200
210
|
skip: number,
|
|
201
211
|
take: number,
|
|
202
212
|
): Promise<{ total: number; items: ContentTypeAggregate[] }> {
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
this.#db.dialect.boolValue(true)
|
|
207
|
-
this.#db.dialect.boolValue(true)
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
const totals = await
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
[...params, take, skip],
|
|
218
|
-
)
|
|
213
|
+
const matching = this.#db.q
|
|
214
|
+
.selectFrom('content_type as ct')
|
|
215
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
216
|
+
.where('ct.is_element', '=', this.#db.dialect.boolValue(true))
|
|
217
|
+
.where('ct.allow_in_library', '=', this.#db.dialect.boolValue(true))
|
|
218
|
+
.where('ct.retired_at', 'is', null)
|
|
219
|
+
.where('n.node_object_type', '=', this.#objectType)
|
|
220
|
+
const totals = await matching.select((eb) => eb.fn.countAll().as('n')).execute()
|
|
221
|
+
const rows = await matching
|
|
222
|
+
.select('n.unique_id')
|
|
223
|
+
.orderBy('n.text')
|
|
224
|
+
.limit(take)
|
|
225
|
+
.offset(skip)
|
|
226
|
+
.execute()
|
|
219
227
|
const items: ContentTypeAggregate[] = []
|
|
220
228
|
let hidden = 0
|
|
221
229
|
for (const row of rows) {
|
|
@@ -232,11 +240,12 @@ export class ContentTypeRepository {
|
|
|
232
240
|
* level), as its parent's type allows children; nothing when it may.
|
|
233
241
|
*/
|
|
234
242
|
async placementRefusal(typeKey: string, parentKey: string | null): Promise<string | undefined> {
|
|
235
|
-
const types = await this.#db.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
[
|
|
239
|
-
|
|
243
|
+
const types = await this.#db.q
|
|
244
|
+
.selectFrom('node as n')
|
|
245
|
+
.innerJoin('content_type as ct', 'ct.node_id', 'n.id')
|
|
246
|
+
.select(['n.id', 'n.text', 'ct.allow_at_root'])
|
|
247
|
+
.where('n.unique_id', '=', normaliseUuid(typeKey))
|
|
248
|
+
.execute()
|
|
240
249
|
const type = types[0]
|
|
241
250
|
if (!type) return undefined
|
|
242
251
|
const typeName = String(type.text ?? typeKey)
|
|
@@ -244,18 +253,20 @@ export class ContentTypeRepository {
|
|
|
244
253
|
return fromDbBool(type.allow_at_root)
|
|
245
254
|
? undefined
|
|
246
255
|
: `"${typeName}" isn't allowed at the top level.`
|
|
247
|
-
const parents = await this.#db.
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
[
|
|
251
|
-
|
|
256
|
+
const parents = await this.#db.q
|
|
257
|
+
.selectFrom('node as n')
|
|
258
|
+
.innerJoin('content as c', 'c.node_id', 'n.id')
|
|
259
|
+
.select(['n.text', 'c.content_type_id'])
|
|
260
|
+
.where('n.unique_id', '=', normaliseUuid(parentKey))
|
|
261
|
+
.execute()
|
|
252
262
|
const parent = parents[0]
|
|
253
263
|
if (!parent) return undefined
|
|
254
|
-
const allowed = await this.#db.
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
264
|
+
const allowed = await this.#db.q
|
|
265
|
+
.selectFrom('content_type_allowed_child')
|
|
266
|
+
.select((eb) => eb.fn.countAll().as('n'))
|
|
267
|
+
.where('content_type_id', '=', parent.content_type_id)
|
|
268
|
+
.where('allowed_content_type_id', '=', type.id)
|
|
269
|
+
.execute()
|
|
259
270
|
return Number(allowed[0]?.n ?? 0) > 0
|
|
260
271
|
? undefined
|
|
261
272
|
: `"${typeName}" isn't allowed under "${parent.text ?? parentKey}".`
|
|
@@ -268,12 +279,13 @@ export class ContentTypeRepository {
|
|
|
268
279
|
): Promise<{ total: number; items: ContentTypeAggregate[] }> {
|
|
269
280
|
const node = await this.#nodes.byKey(key)
|
|
270
281
|
if (!node) return { total: 0, items: [] }
|
|
271
|
-
const rows = await this.#db.
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
282
|
+
const rows = await this.#db.q
|
|
283
|
+
.selectFrom('content_type_allowed_child as ac')
|
|
284
|
+
.innerJoin('node as child', 'child.id', 'ac.allowed_content_type_id')
|
|
285
|
+
.select('child.unique_id')
|
|
286
|
+
.where('ac.content_type_id', '=', node.id)
|
|
287
|
+
.orderBy('ac.sort_order')
|
|
288
|
+
.execute()
|
|
277
289
|
const items: ContentTypeAggregate[] = []
|
|
278
290
|
for (const row of rows.slice(skip, skip + take)) {
|
|
279
291
|
const aggregate = await this.byKey(String(row.unique_id))
|
|
@@ -316,76 +328,92 @@ export class ContentTypeRepository {
|
|
|
316
328
|
}
|
|
317
329
|
|
|
318
330
|
const variations = variationFlags(aggregate.variesByCulture, aggregate.variesBySegment)
|
|
319
|
-
const typeValues =
|
|
320
|
-
aggregate.alias,
|
|
321
|
-
aggregate.icon,
|
|
322
|
-
aggregate.description,
|
|
323
|
-
aggregate.collectionKey,
|
|
324
|
-
bool(aggregate.isElement),
|
|
325
|
-
bool(aggregate.allowedInLibrary),
|
|
326
|
-
bool(aggregate.allowedAsRoot),
|
|
331
|
+
const typeValues = {
|
|
332
|
+
alias: aggregate.alias,
|
|
333
|
+
icon: aggregate.icon ?? null,
|
|
334
|
+
description: aggregate.description ?? null,
|
|
335
|
+
list_view: aggregate.collectionKey ?? null,
|
|
336
|
+
is_element: bool(aggregate.isElement),
|
|
337
|
+
allow_in_library: bool(aggregate.allowedInLibrary),
|
|
338
|
+
allow_at_root: bool(aggregate.allowedAsRoot),
|
|
327
339
|
variations,
|
|
328
|
-
bool(aggregate.cleanup.preventCleanup),
|
|
329
|
-
aggregate.cleanup.keepAllVersionsNewerThanDays,
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
340
|
+
prevent_cleanup: bool(aggregate.cleanup.preventCleanup),
|
|
341
|
+
keep_all_versions_newer_than_days: aggregate.cleanup.keepAllVersionsNewerThanDays ?? null,
|
|
342
|
+
keep_latest_version_per_day_for_days:
|
|
343
|
+
aggregate.cleanup.keepLatestVersionPerDayForDays ?? null,
|
|
344
|
+
since_version: aggregate.sinceVersion ?? null,
|
|
345
|
+
}
|
|
333
346
|
if (existing) {
|
|
334
|
-
await tx.
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
[...typeValues, nodeId],
|
|
340
|
-
)
|
|
347
|
+
await tx.q
|
|
348
|
+
.updateTable('content_type')
|
|
349
|
+
.set({ ...typeValues, retired_at: null })
|
|
350
|
+
.where('node_id', '=', nodeId)
|
|
351
|
+
.execute()
|
|
341
352
|
} else {
|
|
342
|
-
await tx.
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
353
|
+
await tx.q
|
|
354
|
+
.insertInto('content_type')
|
|
355
|
+
.values({
|
|
356
|
+
node_id: nodeId,
|
|
357
|
+
...typeValues,
|
|
358
|
+
thumbnail: 'folder.png',
|
|
359
|
+
since_state_id: options.sinceStateId ?? null,
|
|
360
|
+
})
|
|
361
|
+
.execute()
|
|
349
362
|
}
|
|
350
363
|
// As for a property's flags: only a schema sync says.
|
|
351
364
|
if (aggregate.siteSearch !== undefined)
|
|
352
|
-
await tx.
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
365
|
+
await tx.q
|
|
366
|
+
.updateTable('content_type')
|
|
367
|
+
.set({ site_search: bool(aggregate.siteSearch) })
|
|
368
|
+
.where('node_id', '=', nodeId)
|
|
369
|
+
.execute()
|
|
356
370
|
|
|
357
371
|
// ---- groups: upsert by key
|
|
358
372
|
const groupIdByKey = new Map<string, number>()
|
|
359
373
|
for (const container of aggregate.containers) {
|
|
360
374
|
const type = container.type === 'Tab' ? PropertyGroupType.Tab : PropertyGroupType.Group
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
375
|
+
const groupId = () =>
|
|
376
|
+
tx.q
|
|
377
|
+
.selectFrom('property_type_group')
|
|
378
|
+
.select('id')
|
|
379
|
+
.where('unique_id', '=', container.key)
|
|
380
|
+
.execute()
|
|
381
|
+
const found = await groupId()
|
|
365
382
|
if (found[0]) {
|
|
366
|
-
await tx.
|
|
367
|
-
'
|
|
368
|
-
|
|
369
|
-
|
|
383
|
+
await tx.q
|
|
384
|
+
.updateTable('property_type_group')
|
|
385
|
+
.set({
|
|
386
|
+
type,
|
|
387
|
+
text: container.name ?? null,
|
|
388
|
+
alias: container.alias ?? null,
|
|
389
|
+
sort_order: container.sortOrder,
|
|
390
|
+
})
|
|
391
|
+
.where('id', '=', Number(found[0].id))
|
|
392
|
+
.execute()
|
|
370
393
|
groupIdByKey.set(container.key, Number(found[0].id))
|
|
371
394
|
} else {
|
|
372
|
-
await tx.
|
|
373
|
-
'
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
395
|
+
await tx.q
|
|
396
|
+
.insertInto('property_type_group')
|
|
397
|
+
.values({
|
|
398
|
+
unique_id: container.key,
|
|
399
|
+
content_type_node_id: nodeId,
|
|
400
|
+
type,
|
|
401
|
+
text: container.name ?? null,
|
|
402
|
+
alias: container.alias ?? null,
|
|
403
|
+
sort_order: container.sortOrder,
|
|
404
|
+
})
|
|
405
|
+
.execute()
|
|
406
|
+
const created = await groupId()
|
|
380
407
|
groupIdByKey.set(container.key, Number(created[0]?.id))
|
|
381
408
|
}
|
|
382
409
|
}
|
|
383
410
|
for (const container of aggregate.containers) {
|
|
384
411
|
const parent = container.parentKey ? groupIdByKey.get(container.parentKey) : undefined
|
|
385
|
-
await tx.
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
412
|
+
await tx.q
|
|
413
|
+
.updateTable('property_type_group')
|
|
414
|
+
.set({ parent_id: parent ?? null })
|
|
415
|
+
.where('unique_id', '=', container.key)
|
|
416
|
+
.execute()
|
|
389
417
|
}
|
|
390
418
|
|
|
391
419
|
// ---- properties: upsert by key; retire the absent; revive the returning
|
|
@@ -399,151 +427,177 @@ export class ContentTypeRepository {
|
|
|
399
427
|
// A key the type has never had, but an alias it has (live or retired), is
|
|
400
428
|
// that property coming back: reuse the row, so its values return with it.
|
|
401
429
|
let key = normaliseUuid(property.key)
|
|
402
|
-
const byKey = await tx.
|
|
430
|
+
const byKey = await tx.q
|
|
431
|
+
.selectFrom('property_type')
|
|
432
|
+
.select('id')
|
|
433
|
+
.where('unique_id', '=', key)
|
|
434
|
+
.execute()
|
|
403
435
|
if (byKey.length === 0) {
|
|
404
|
-
const sameAlias = await tx.
|
|
405
|
-
'
|
|
406
|
-
|
|
407
|
-
|
|
436
|
+
const sameAlias = await tx.q
|
|
437
|
+
.selectFrom('property_type')
|
|
438
|
+
.select('unique_id')
|
|
439
|
+
.where('content_type_id', '=', nodeId)
|
|
440
|
+
.where('alias', '=', property.alias)
|
|
441
|
+
.execute()
|
|
408
442
|
if (sameAlias[0]) key = normaliseUuid(String(sameAlias[0].unique_id))
|
|
409
443
|
}
|
|
410
444
|
kept.add(key)
|
|
411
445
|
const groupId = property.containerKey
|
|
412
446
|
? (groupIdByKey.get(property.containerKey) ?? null)
|
|
413
447
|
: null
|
|
414
|
-
const columns =
|
|
415
|
-
dataTypeNode.id,
|
|
416
|
-
groupId,
|
|
417
|
-
property.alias,
|
|
418
|
-
property.name,
|
|
419
|
-
property.description,
|
|
420
|
-
property.sortOrder,
|
|
421
|
-
bool(property.mandatory),
|
|
422
|
-
property.mandatoryMessage,
|
|
423
|
-
property.regEx,
|
|
424
|
-
property.regExMessage,
|
|
425
|
-
bool(property.labelOnTop),
|
|
426
|
-
variationFlags(property.variesByCulture, property.variesBySegment),
|
|
427
|
-
property.sinceVersion ?? null,
|
|
428
|
-
|
|
429
|
-
const found = await tx.
|
|
430
|
-
'
|
|
431
|
-
|
|
432
|
-
|
|
448
|
+
const columns = {
|
|
449
|
+
data_type_id: dataTypeNode.id,
|
|
450
|
+
property_type_group_id: groupId,
|
|
451
|
+
alias: property.alias,
|
|
452
|
+
name: property.name,
|
|
453
|
+
description: property.description ?? null,
|
|
454
|
+
sort_order: property.sortOrder,
|
|
455
|
+
mandatory: bool(property.mandatory),
|
|
456
|
+
mandatory_message: property.mandatoryMessage ?? null,
|
|
457
|
+
validation_reg_exp: property.regEx ?? null,
|
|
458
|
+
validation_reg_exp_message: property.regExMessage ?? null,
|
|
459
|
+
label_on_top: bool(property.labelOnTop),
|
|
460
|
+
variations: variationFlags(property.variesByCulture, property.variesBySegment),
|
|
461
|
+
since_version: property.sinceVersion ?? null,
|
|
462
|
+
}
|
|
463
|
+
const found = await tx.q
|
|
464
|
+
.selectFrom('property_type')
|
|
465
|
+
.select('id')
|
|
466
|
+
.where('unique_id', '=', key)
|
|
467
|
+
.execute()
|
|
433
468
|
if (found[0]) {
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
)
|
|
469
|
+
const id = Number(found[0].id)
|
|
470
|
+
await tx.q
|
|
471
|
+
.updateTable('property_type')
|
|
472
|
+
.set({ ...columns, retired_at: null })
|
|
473
|
+
.where('id', '=', id)
|
|
474
|
+
.execute()
|
|
441
475
|
// Only a schema sync says; a backoffice save leaves it as it was.
|
|
442
476
|
if (property.searchable !== undefined)
|
|
443
|
-
await tx.
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
477
|
+
await tx.q
|
|
478
|
+
.updateTable('property_type')
|
|
479
|
+
.set({ searchable: bool(property.searchable) })
|
|
480
|
+
.where('id', '=', id)
|
|
481
|
+
.execute()
|
|
447
482
|
if (property.siteSearch !== undefined)
|
|
448
|
-
await tx.
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
483
|
+
await tx.q
|
|
484
|
+
.updateTable('property_type')
|
|
485
|
+
.set({ site_search: siteSearchColumn(property.siteSearch) })
|
|
486
|
+
.where('id', '=', id)
|
|
487
|
+
.execute()
|
|
452
488
|
} else {
|
|
453
|
-
await tx.
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
[
|
|
459
|
-
key,
|
|
460
|
-
nodeId,
|
|
489
|
+
await tx.q
|
|
490
|
+
.insertInto('property_type')
|
|
491
|
+
.values({
|
|
492
|
+
unique_id: key,
|
|
493
|
+
content_type_id: nodeId,
|
|
461
494
|
...columns,
|
|
462
|
-
options.sinceStateId ?? null,
|
|
463
|
-
bool(property.searchable !== false),
|
|
464
|
-
siteSearchColumn(property.siteSearch),
|
|
465
|
-
|
|
466
|
-
|
|
495
|
+
since_state_id: options.sinceStateId ?? null,
|
|
496
|
+
searchable: bool(property.searchable !== false),
|
|
497
|
+
site_search: siteSearchColumn(property.siteSearch),
|
|
498
|
+
})
|
|
499
|
+
.execute()
|
|
467
500
|
}
|
|
468
501
|
}
|
|
469
502
|
if (this.#kind === 'member') {
|
|
470
503
|
const bool = (v: boolean) => tx.dialect.boolValue(v)
|
|
471
504
|
for (const property of aggregate.properties) {
|
|
472
505
|
// By alias: the row may have been reused under its old key above.
|
|
473
|
-
const row = await tx.
|
|
474
|
-
'
|
|
475
|
-
|
|
476
|
-
|
|
506
|
+
const row = await tx.q
|
|
507
|
+
.selectFrom('property_type')
|
|
508
|
+
.select('id')
|
|
509
|
+
.where('content_type_id', '=', nodeId)
|
|
510
|
+
.where('alias', '=', property.alias)
|
|
511
|
+
.execute()
|
|
477
512
|
const id = Number(row[0]?.id)
|
|
478
513
|
if (!id) continue
|
|
479
|
-
await tx.
|
|
480
|
-
await tx.
|
|
481
|
-
'
|
|
482
|
-
|
|
483
|
-
id,
|
|
484
|
-
bool(property.memberCanEdit === true),
|
|
485
|
-
bool(property.memberCanView === true),
|
|
486
|
-
bool(property.isSensitive === true),
|
|
487
|
-
|
|
488
|
-
|
|
514
|
+
await tx.q.deleteFrom('member_property_type').where('property_type_id', '=', id).execute()
|
|
515
|
+
await tx.q
|
|
516
|
+
.insertInto('member_property_type')
|
|
517
|
+
.values({
|
|
518
|
+
property_type_id: id,
|
|
519
|
+
member_can_edit: bool(property.memberCanEdit === true),
|
|
520
|
+
member_can_view: bool(property.memberCanView === true),
|
|
521
|
+
is_sensitive: bool(property.isSensitive === true),
|
|
522
|
+
})
|
|
523
|
+
.execute()
|
|
489
524
|
}
|
|
490
525
|
}
|
|
491
|
-
const present = await tx.
|
|
492
|
-
'
|
|
493
|
-
[
|
|
494
|
-
|
|
526
|
+
const present = await tx.q
|
|
527
|
+
.selectFrom('property_type')
|
|
528
|
+
.select(['id', 'unique_id', 'retired_at'])
|
|
529
|
+
.where('content_type_id', '=', nodeId)
|
|
530
|
+
.execute()
|
|
495
531
|
for (const row of present) {
|
|
496
532
|
if (kept.has(normaliseUuid(String(row.unique_id)))) continue
|
|
497
533
|
if (row.retired_at !== null && row.retired_at !== undefined) continue
|
|
498
534
|
// Retired: hidden and detached from its group; every value stays.
|
|
499
|
-
await tx.
|
|
500
|
-
'
|
|
501
|
-
|
|
502
|
-
|
|
535
|
+
await tx.q
|
|
536
|
+
.updateTable('property_type')
|
|
537
|
+
.set({ retired_at: now, property_type_group_id: null })
|
|
538
|
+
.where('id', '=', Number(row.id))
|
|
539
|
+
.execute()
|
|
503
540
|
}
|
|
504
541
|
const containerKeys = new Set(aggregate.containers.map((c) => c.key))
|
|
505
|
-
for (const group of await tx.
|
|
506
|
-
'
|
|
507
|
-
[
|
|
508
|
-
|
|
542
|
+
for (const group of await tx.q
|
|
543
|
+
.selectFrom('property_type_group')
|
|
544
|
+
.select(['id', 'unique_id'])
|
|
545
|
+
.where('content_type_node_id', '=', nodeId)
|
|
546
|
+
.execute()) {
|
|
509
547
|
if (containerKeys.has(String(group.unique_id))) continue
|
|
510
|
-
const inUse = await tx.
|
|
511
|
-
'
|
|
512
|
-
|
|
513
|
-
|
|
548
|
+
const inUse = await tx.q
|
|
549
|
+
.selectFrom('property_type')
|
|
550
|
+
.select((eb) => eb.fn.countAll().as('n'))
|
|
551
|
+
.where('property_type_group_id', '=', Number(group.id))
|
|
552
|
+
.execute()
|
|
514
553
|
if (Number(inUse[0]?.n ?? 0) === 0)
|
|
515
|
-
await tx.
|
|
554
|
+
await tx.q.deleteFrom('property_type_group').where('id', '=', Number(group.id)).execute()
|
|
516
555
|
}
|
|
517
556
|
|
|
518
557
|
// ---- relations: replaced wholesale; nothing references these rows
|
|
519
|
-
await tx.
|
|
520
|
-
|
|
521
|
-
|
|
558
|
+
await tx.q
|
|
559
|
+
.deleteFrom('content_type_composition')
|
|
560
|
+
.where('child_content_type_id', '=', nodeId)
|
|
561
|
+
.execute()
|
|
522
562
|
for (const composition of aggregate.compositions) {
|
|
523
563
|
const parent = await repo.nodes.byKey(composition.contentTypeKey)
|
|
524
564
|
if (parent)
|
|
525
|
-
await tx.
|
|
526
|
-
'
|
|
527
|
-
|
|
528
|
-
|
|
565
|
+
await tx.q
|
|
566
|
+
.insertInto('content_type_composition')
|
|
567
|
+
.values({ parent_content_type_id: parent.id, child_content_type_id: nodeId })
|
|
568
|
+
.execute()
|
|
529
569
|
}
|
|
530
|
-
await tx.
|
|
570
|
+
await tx.q
|
|
571
|
+
.deleteFrom('content_type_allowed_child')
|
|
572
|
+
.where('content_type_id', '=', nodeId)
|
|
573
|
+
.execute()
|
|
531
574
|
for (const allowed of aggregate.allowedContentTypes) {
|
|
532
575
|
const child = await repo.nodes.byKey(allowed.contentTypeKey)
|
|
533
576
|
if (child)
|
|
534
|
-
await tx.
|
|
535
|
-
'
|
|
536
|
-
|
|
537
|
-
|
|
577
|
+
await tx.q
|
|
578
|
+
.insertInto('content_type_allowed_child')
|
|
579
|
+
.values({
|
|
580
|
+
content_type_id: nodeId,
|
|
581
|
+
allowed_content_type_id: child.id,
|
|
582
|
+
sort_order: allowed.sortOrder,
|
|
583
|
+
})
|
|
584
|
+
.execute()
|
|
538
585
|
}
|
|
539
|
-
await tx.
|
|
586
|
+
await tx.q
|
|
587
|
+
.deleteFrom('content_type_template')
|
|
588
|
+
.where('content_type_node_id', '=', nodeId)
|
|
589
|
+
.execute()
|
|
540
590
|
for (const componentKey of aggregate.allowedComponentKeys) {
|
|
541
591
|
const template = await repo.nodes.byKey(componentKey)
|
|
542
592
|
if (template)
|
|
543
|
-
await tx.
|
|
544
|
-
'
|
|
545
|
-
|
|
546
|
-
|
|
593
|
+
await tx.q
|
|
594
|
+
.insertInto('content_type_template')
|
|
595
|
+
.values({
|
|
596
|
+
content_type_node_id: nodeId,
|
|
597
|
+
template_node_id: template.id,
|
|
598
|
+
is_default: bool(componentKey === aggregate.defaultComponentKey),
|
|
599
|
+
})
|
|
600
|
+
.execute()
|
|
547
601
|
}
|
|
548
602
|
|
|
549
603
|
if (existing && propertiesBefore !== (await propertySignature(tx, nodeId))) {
|
|
@@ -560,10 +614,12 @@ export class ContentTypeRepository {
|
|
|
560
614
|
async retiredProperties(typeKey: string): Promise<RetiredProperty[]> {
|
|
561
615
|
const node = await this.#nodes.byKey(typeKey)
|
|
562
616
|
if (!node) return []
|
|
563
|
-
const rows = await this.#db.
|
|
564
|
-
'
|
|
565
|
-
[
|
|
566
|
-
|
|
617
|
+
const rows = await this.#db.q
|
|
618
|
+
.selectFrom('property_type')
|
|
619
|
+
.select(['unique_id', 'alias', 'retired_at'])
|
|
620
|
+
.where('content_type_id', '=', node.id)
|
|
621
|
+
.where('retired_at', 'is not', null)
|
|
622
|
+
.execute()
|
|
567
623
|
return rows.map((row) => ({
|
|
568
624
|
key: normaliseUuid(String(row.unique_id)),
|
|
569
625
|
alias: String(row.alias),
|
|
@@ -577,20 +633,20 @@ export class ContentTypeRepository {
|
|
|
577
633
|
* ever held. The contract step; nothing else in the system deletes values.
|
|
578
634
|
*/
|
|
579
635
|
async purgeRetired(olderThan: Date): Promise<Array<{ type: string; alias: string }>> {
|
|
580
|
-
const rows = await this.#db.
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
636
|
+
const rows = await this.#db.q
|
|
637
|
+
.selectFrom('property_type as p')
|
|
638
|
+
.innerJoin('content_type as ct', 'ct.node_id', 'p.content_type_id')
|
|
639
|
+
.select(['p.id', 'p.alias', 'ct.alias as type_alias'])
|
|
640
|
+
.where('p.retired_at', 'is not', null)
|
|
641
|
+
.where('p.retired_at', '<', DbDate.toDb(olderThan))
|
|
642
|
+
.execute()
|
|
586
643
|
const purged: Array<{ type: string; alias: string }> = []
|
|
587
644
|
await this.#db.transaction(async (tx) => {
|
|
588
645
|
for (const row of rows) {
|
|
589
|
-
|
|
590
|
-
await tx.
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
await tx.exec('DELETE FROM property_type WHERE id = ?', [Number(row.id)])
|
|
646
|
+
const id = Number(row.id)
|
|
647
|
+
await tx.q.deleteFrom('property_value').where('property_type_id', '=', id).execute()
|
|
648
|
+
await tx.q.deleteFrom('member_property_type').where('property_type_id', '=', id).execute()
|
|
649
|
+
await tx.q.deleteFrom('property_type').where('id', '=', id).execute()
|
|
594
650
|
purged.push({ type: String(row.type_alias), alias: String(row.alias) })
|
|
595
651
|
}
|
|
596
652
|
})
|
|
@@ -609,21 +665,26 @@ export class ContentTypeRepository {
|
|
|
609
665
|
|
|
610
666
|
/** Every live type, cheap enough while types number in the dozens. */
|
|
611
667
|
async all(): Promise<ContentTypeAggregate[]> {
|
|
612
|
-
const rows = await this.#db.
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
668
|
+
const rows = await this.#db.q
|
|
669
|
+
.selectFrom('content_type as ct')
|
|
670
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
671
|
+
.select('n.unique_id')
|
|
672
|
+
.where('ct.retired_at', 'is', null)
|
|
673
|
+
.where('n.node_object_type', '=', this.#objectType)
|
|
674
|
+
.orderBy('n.text')
|
|
675
|
+
.execute()
|
|
617
676
|
return this.byKeys(rows.map((r) => String(r.unique_id)))
|
|
618
677
|
}
|
|
619
678
|
|
|
620
679
|
/** Every live type's alias by its key, without loading the types themselves. */
|
|
621
680
|
async aliasesByKey(): Promise<Map<string, string>> {
|
|
622
|
-
const rows = await this.#db.
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
[
|
|
626
|
-
|
|
681
|
+
const rows = await this.#db.q
|
|
682
|
+
.selectFrom('content_type as ct')
|
|
683
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
684
|
+
.select(['n.unique_id', 'ct.alias'])
|
|
685
|
+
.where('ct.retired_at', 'is', null)
|
|
686
|
+
.where('n.node_object_type', '=', this.#objectType)
|
|
687
|
+
.execute()
|
|
627
688
|
return new Map(rows.map((r) => [normaliseUuid(String(r.unique_id)), String(r.alias)]))
|
|
628
689
|
}
|
|
629
690
|
|
|
@@ -684,11 +745,12 @@ export class ContentTypeRepository {
|
|
|
684
745
|
async compositionReferences(key: string): Promise<ContentTypeAggregate[]> {
|
|
685
746
|
const node = await this.#nodes.byKey(key)
|
|
686
747
|
if (!node) return []
|
|
687
|
-
const rows = await this.#db.
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
748
|
+
const rows = await this.#db.q
|
|
749
|
+
.selectFrom('content_type_composition as c')
|
|
750
|
+
.innerJoin('node as child', 'child.id', 'c.child_content_type_id')
|
|
751
|
+
.select('child.unique_id')
|
|
752
|
+
.where('c.parent_content_type_id', '=', node.id)
|
|
753
|
+
.execute()
|
|
692
754
|
return this.byKeys(rows.map((r) => String(r.unique_id)))
|
|
693
755
|
}
|
|
694
756
|
|
|
@@ -696,11 +758,12 @@ export class ContentTypeRepository {
|
|
|
696
758
|
async allowedParents(key: string): Promise<string[]> {
|
|
697
759
|
const node = await this.#nodes.byKey(key)
|
|
698
760
|
if (!node) return []
|
|
699
|
-
const rows = await this.#db.
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
761
|
+
const rows = await this.#db.q
|
|
762
|
+
.selectFrom('content_type_allowed_child as ac')
|
|
763
|
+
.innerJoin('node as parent', 'parent.id', 'ac.content_type_id')
|
|
764
|
+
.select('parent.unique_id')
|
|
765
|
+
.where('ac.allowed_content_type_id', '=', node.id)
|
|
766
|
+
.execute()
|
|
704
767
|
return rows.map((r) => normaliseUuid(String(r.unique_id)))
|
|
705
768
|
}
|
|
706
769
|
|
|
@@ -749,10 +812,11 @@ export class ContentTypeRepository {
|
|
|
749
812
|
async contentCount(typeKey: string): Promise<number> {
|
|
750
813
|
const node = await this.#nodes.byKey(typeKey)
|
|
751
814
|
if (!node) return 0
|
|
752
|
-
const rows = await this.#db.
|
|
753
|
-
'
|
|
754
|
-
|
|
755
|
-
|
|
815
|
+
const rows = await this.#db.q
|
|
816
|
+
.selectFrom('content')
|
|
817
|
+
.select((eb) => eb.fn.countAll().as('n'))
|
|
818
|
+
.where('content_type_id', '=', node.id)
|
|
819
|
+
.execute()
|
|
756
820
|
return Number(rows[0]?.n ?? 0)
|
|
757
821
|
}
|
|
758
822
|
|
|
@@ -760,27 +824,42 @@ export class ContentTypeRepository {
|
|
|
760
824
|
const node = await this.#nodes.byKey(key)
|
|
761
825
|
if (!node || node.objectType !== this.#objectType) return false
|
|
762
826
|
return this.#db.transaction(async (tx) => {
|
|
763
|
-
|
|
764
|
-
'
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
await tx.
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
827
|
+
const ownProperties = () =>
|
|
828
|
+
tx.q.selectFrom('property_type').select('id').where('content_type_id', '=', node.id)
|
|
829
|
+
await tx.q
|
|
830
|
+
.deleteFrom('property_value')
|
|
831
|
+
.where('property_type_id', 'in', ownProperties())
|
|
832
|
+
.execute()
|
|
833
|
+
await tx.q
|
|
834
|
+
.deleteFrom('member_property_type')
|
|
835
|
+
.where('property_type_id', 'in', ownProperties())
|
|
836
|
+
.execute()
|
|
837
|
+
await tx.q.deleteFrom('property_type').where('content_type_id', '=', node.id).execute()
|
|
838
|
+
await tx.q
|
|
839
|
+
.deleteFrom('property_type_group')
|
|
840
|
+
.where('content_type_node_id', '=', node.id)
|
|
841
|
+
.execute()
|
|
842
|
+
await tx.q
|
|
843
|
+
.deleteFrom('content_type_composition')
|
|
844
|
+
.where((eb) =>
|
|
845
|
+
eb.or([
|
|
846
|
+
eb('child_content_type_id', '=', node.id),
|
|
847
|
+
eb('parent_content_type_id', '=', node.id),
|
|
848
|
+
]),
|
|
849
|
+
)
|
|
850
|
+
.execute()
|
|
851
|
+
await tx.q
|
|
852
|
+
.deleteFrom('content_type_allowed_child')
|
|
853
|
+
.where((eb) =>
|
|
854
|
+
eb.or([eb('content_type_id', '=', node.id), eb('allowed_content_type_id', '=', node.id)]),
|
|
855
|
+
)
|
|
856
|
+
.execute()
|
|
857
|
+
await tx.q
|
|
858
|
+
.deleteFrom('content_type_template')
|
|
859
|
+
.where('content_type_node_id', '=', node.id)
|
|
860
|
+
.execute()
|
|
861
|
+
await tx.q.deleteFrom('content_type').where('node_id', '=', node.id).execute()
|
|
862
|
+
await tx.q.deleteFrom('node').where('id', '=', node.id).execute()
|
|
784
863
|
return true
|
|
785
864
|
})
|
|
786
865
|
}
|
|
@@ -808,22 +887,46 @@ export class ContentTypeRepository {
|
|
|
808
887
|
name: string,
|
|
809
888
|
parentId: number,
|
|
810
889
|
): Promise<ContentTypeAggregate | undefined> {
|
|
811
|
-
const typeRows = await this.#db.
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
890
|
+
const typeRows = await this.#db.q
|
|
891
|
+
.selectFrom('content_type as ct')
|
|
892
|
+
.leftJoin('schema_state as ss', 'ss.id', 'ct.since_state_id')
|
|
893
|
+
.select([
|
|
894
|
+
'ct.alias',
|
|
895
|
+
'ct.icon',
|
|
896
|
+
'ct.description',
|
|
897
|
+
'ct.list_view',
|
|
898
|
+
'ct.is_element',
|
|
899
|
+
'ct.allow_in_library',
|
|
900
|
+
'ct.allow_at_root',
|
|
901
|
+
'ct.variations',
|
|
902
|
+
'ct.prevent_cleanup',
|
|
903
|
+
'ct.keep_all_versions_newer_than_days',
|
|
904
|
+
'ct.keep_latest_version_per_day_for_days',
|
|
905
|
+
'ct.since_version',
|
|
906
|
+
'ct.site_search',
|
|
907
|
+
'ss.version as since_v',
|
|
908
|
+
'ss.revision as since_r',
|
|
909
|
+
])
|
|
910
|
+
.where('ct.node_id', '=', nodeId)
|
|
911
|
+
.execute()
|
|
818
912
|
const type = typeRows[0]
|
|
819
913
|
if (!type) return undefined
|
|
820
914
|
|
|
821
|
-
const groupRows = await this.#db.
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
915
|
+
const groupRows = await this.#db.q
|
|
916
|
+
.selectFrom('property_type_group as g')
|
|
917
|
+
.leftJoin('property_type_group as parent', 'parent.id', 'g.parent_id')
|
|
918
|
+
.select([
|
|
919
|
+
'g.unique_id',
|
|
920
|
+
'g.text',
|
|
921
|
+
'g.alias',
|
|
922
|
+
'g.type',
|
|
923
|
+
'g.sort_order',
|
|
924
|
+
'parent.unique_id as parent_key',
|
|
925
|
+
])
|
|
926
|
+
.where('g.content_type_node_id', '=', nodeId)
|
|
927
|
+
.orderBy('g.sort_order')
|
|
928
|
+
.orderBy('g.id')
|
|
929
|
+
.execute()
|
|
827
930
|
const containers: PropertyGroupModel[] = groupRows.map((row) => ({
|
|
828
931
|
key: normaliseUuid(String(row.unique_id)),
|
|
829
932
|
name: (row.text as string | null) ?? null,
|
|
@@ -834,21 +937,40 @@ export class ContentTypeRepository {
|
|
|
834
937
|
}))
|
|
835
938
|
|
|
836
939
|
// Retired properties are hidden here; `retiredProperties()` lists them.
|
|
837
|
-
const propertyRows = await this.#db.
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
940
|
+
const propertyRows = await this.#db.q
|
|
941
|
+
.selectFrom('property_type as p')
|
|
942
|
+
.innerJoin('node as dtn', 'dtn.id', 'p.data_type_id')
|
|
943
|
+
.leftJoin('property_type_group as g', 'g.id', 'p.property_type_group_id')
|
|
944
|
+
.leftJoin('schema_state as ss', 'ss.id', 'p.since_state_id')
|
|
945
|
+
.leftJoin('member_property_type as m', 'm.property_type_id', 'p.id')
|
|
946
|
+
.select([
|
|
947
|
+
'p.unique_id',
|
|
948
|
+
'p.alias',
|
|
949
|
+
'p.name',
|
|
950
|
+
'p.description',
|
|
951
|
+
'p.sort_order',
|
|
952
|
+
'p.mandatory',
|
|
953
|
+
'p.mandatory_message',
|
|
954
|
+
'p.validation_reg_exp',
|
|
955
|
+
'p.validation_reg_exp_message',
|
|
956
|
+
'p.label_on_top',
|
|
957
|
+
'p.variations',
|
|
958
|
+
'dtn.unique_id as data_type_key',
|
|
959
|
+
'g.unique_id as container_key',
|
|
960
|
+
'p.since_version',
|
|
961
|
+
'ss.version as since_v',
|
|
962
|
+
'ss.revision as since_r',
|
|
963
|
+
'm.member_can_edit',
|
|
964
|
+
'm.member_can_view',
|
|
965
|
+
'm.is_sensitive',
|
|
966
|
+
'p.searchable',
|
|
967
|
+
'p.site_search',
|
|
968
|
+
])
|
|
969
|
+
.where('p.content_type_id', '=', nodeId)
|
|
970
|
+
.where('p.retired_at', 'is', null)
|
|
971
|
+
.orderBy('p.sort_order')
|
|
972
|
+
.orderBy('p.id')
|
|
973
|
+
.execute()
|
|
852
974
|
const properties: PropertyTypeModel[] = propertyRows.map((row) => ({
|
|
853
975
|
key: normaliseUuid(String(row.unique_id)),
|
|
854
976
|
alias: String(row.alias),
|
|
@@ -877,18 +999,25 @@ export class ContentTypeRepository {
|
|
|
877
999
|
: {}),
|
|
878
1000
|
}))
|
|
879
1001
|
|
|
880
|
-
const compositionRows = await this.#db.
|
|
881
|
-
'
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
'
|
|
890
|
-
|
|
891
|
-
|
|
1002
|
+
const compositionRows = await this.#db.q
|
|
1003
|
+
.selectFrom('content_type_composition as c')
|
|
1004
|
+
.innerJoin('node as parent', 'parent.id', 'c.parent_content_type_id')
|
|
1005
|
+
.select('parent.unique_id')
|
|
1006
|
+
.where('c.child_content_type_id', '=', nodeId)
|
|
1007
|
+
.execute()
|
|
1008
|
+
const allowedRows = await this.#db.q
|
|
1009
|
+
.selectFrom('content_type_allowed_child as ac')
|
|
1010
|
+
.innerJoin('node as child', 'child.id', 'ac.allowed_content_type_id')
|
|
1011
|
+
.select(['child.unique_id', 'ac.sort_order'])
|
|
1012
|
+
.where('ac.content_type_id', '=', nodeId)
|
|
1013
|
+
.orderBy('ac.sort_order')
|
|
1014
|
+
.execute()
|
|
1015
|
+
const templateRows = await this.#db.q
|
|
1016
|
+
.selectFrom('content_type_template as ctt')
|
|
1017
|
+
.innerJoin('node as tn', 'tn.id', 'ctt.template_node_id')
|
|
1018
|
+
.select(['tn.unique_id', 'ctt.is_default'])
|
|
1019
|
+
.where('ctt.content_type_node_id', '=', nodeId)
|
|
1020
|
+
.execute()
|
|
892
1021
|
const parentNode = parentId > 0 ? await this.#nodes.byId(parentId) : undefined
|
|
893
1022
|
const flags = Number(type.variations ?? ContentVariation.Nothing)
|
|
894
1023
|
const num = (value: unknown) => (value === null || value === undefined ? null : Number(value))
|