@crombolo/schema 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 -3
- package/src/check.ts +23 -13
- package/src/export.ts +14 -8
- package/src/generate-delivery.ts +2 -2
- package/src/sync.ts +14 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.38.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Schema-as-code for crombolo: TOML document, media and member type definitions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
32
|
-
"@crombolo/data": "0.
|
|
31
|
+
"@crombolo/core": "0.38.1",
|
|
32
|
+
"@crombolo/data": "0.38.1"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/check.ts
CHANGED
|
@@ -125,15 +125,22 @@ export async function affectedProperties(
|
|
|
125
125
|
|
|
126
126
|
/** A type's node id plus every type that composes it, transitively: their documents carry its properties. */
|
|
127
127
|
export async function typeNodeIdsCarrying(db: Db, typeKey: string): Promise<number[]> {
|
|
128
|
-
const rows = await db.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
128
|
+
const rows = await db.q
|
|
129
|
+
.withRecursive('carriers(id)', (qb) =>
|
|
130
|
+
qb
|
|
131
|
+
.selectFrom('node')
|
|
132
|
+
.select('id')
|
|
133
|
+
.where('unique_id', '=', typeKey)
|
|
134
|
+
.union(
|
|
135
|
+
qb
|
|
136
|
+
.selectFrom('content_type_composition as c')
|
|
137
|
+
.innerJoin('carriers as p', 'p.id', 'c.parent_content_type_id')
|
|
138
|
+
.select('c.child_content_type_id as id'),
|
|
139
|
+
),
|
|
140
|
+
)
|
|
141
|
+
.selectFrom('carriers')
|
|
142
|
+
.select('id')
|
|
143
|
+
.execute()
|
|
137
144
|
return rows.map((r) => Number(r.id))
|
|
138
145
|
}
|
|
139
146
|
|
|
@@ -245,10 +252,13 @@ export async function runCheck(
|
|
|
245
252
|
for (const { kind, files, noun, items } of kinds) {
|
|
246
253
|
const repo = kind === 'document' ? types : new ContentTypeRepository(db, { kind })
|
|
247
254
|
const inFiles = new Set(files.map((t) => t.alias.toLowerCase()))
|
|
248
|
-
const dbTypes = await db.
|
|
249
|
-
'
|
|
250
|
-
|
|
251
|
-
|
|
255
|
+
const dbTypes = await db.q
|
|
256
|
+
.selectFrom('content_type as ct')
|
|
257
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
258
|
+
.select(['n.unique_id', 'ct.alias'])
|
|
259
|
+
.where('ct.retired_at', 'is', null)
|
|
260
|
+
.where('n.node_object_type', '=', repo.objectType)
|
|
261
|
+
.execute()
|
|
252
262
|
for (const row of dbTypes) {
|
|
253
263
|
const key = String(row.unique_id).toLowerCase()
|
|
254
264
|
if (inFiles.has(String(row.alias).toLowerCase()) || shipped.has(key)) continue
|
package/src/export.ts
CHANGED
|
@@ -220,11 +220,14 @@ export async function exportSchemaSet(db: Db, version: string): Promise<SchemaSe
|
|
|
220
220
|
|
|
221
221
|
const mediaTypeRepo = new ContentTypeRepository(db, { kind: 'media' })
|
|
222
222
|
const liveTypes = async (repo: ContentTypeRepository) => {
|
|
223
|
-
const rows = await db.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
223
|
+
const rows = await db.q
|
|
224
|
+
.selectFrom('content_type as ct')
|
|
225
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
226
|
+
.select('n.unique_id')
|
|
227
|
+
.where('ct.retired_at', 'is', null)
|
|
228
|
+
.where('n.node_object_type', '=', repo.objectType)
|
|
229
|
+
.orderBy('ct.alias')
|
|
230
|
+
.execute()
|
|
228
231
|
const out: ContentTypeAggregate[] = []
|
|
229
232
|
for (const row of rows) {
|
|
230
233
|
const aggregate = await repo.byKey(String(row.unique_id))
|
|
@@ -244,9 +247,12 @@ export async function exportSchemaSet(db: Db, version: string): Promise<SchemaSe
|
|
|
244
247
|
)
|
|
245
248
|
const typeAliasOf = (key: string) => typeAliasByKey.get(key.toLowerCase())
|
|
246
249
|
|
|
247
|
-
const dataTypeRows = await db.
|
|
248
|
-
'
|
|
249
|
-
|
|
250
|
+
const dataTypeRows = await db.q
|
|
251
|
+
.selectFrom('data_type as d')
|
|
252
|
+
.innerJoin('node as n', 'n.id', 'd.node_id')
|
|
253
|
+
.select('n.unique_id')
|
|
254
|
+
.orderBy('n.text')
|
|
255
|
+
.execute()
|
|
250
256
|
const dataTypeAliasByKey = new Map<string, string>()
|
|
251
257
|
const exportedDataTypes: SchemaDataType[] = []
|
|
252
258
|
const taken = new Set<string>()
|
package/src/generate-delivery.ts
CHANGED
|
@@ -71,7 +71,7 @@ export function generateDeliveryTypes(set: SchemaSet, options: DeliveryTypesOpti
|
|
|
71
71
|
case 'Umbraco.TrueFalse':
|
|
72
72
|
return 'boolean'
|
|
73
73
|
case 'Umbraco.RichText':
|
|
74
|
-
return '
|
|
74
|
+
return 'RichTextValue'
|
|
75
75
|
case 'Umbraco.ContentPicker':
|
|
76
76
|
return 'ContentReference'
|
|
77
77
|
case 'Umbraco.MultiNodeTreePicker': {
|
|
@@ -220,9 +220,9 @@ export function generateDeliveryTypes(set: SchemaSet, options: DeliveryTypesOpti
|
|
|
220
220
|
'ApiLink',
|
|
221
221
|
'ApiMediaReference',
|
|
222
222
|
'ApiMediaWithCrops',
|
|
223
|
-
'ApiRichText',
|
|
224
223
|
'ContentItem',
|
|
225
224
|
'MediaItem',
|
|
225
|
+
'RichTextValue',
|
|
226
226
|
].filter((shape) => new RegExp(`\\b${shape}\\b`).test(text))
|
|
227
227
|
out[2] = `import type { ${shapes.join(', ')} } from '${DELIVERY_CLIENT_MODULE}'\n`
|
|
228
228
|
return `${out.join('\n').trimEnd()}\n`
|
package/src/sync.ts
CHANGED
|
@@ -632,10 +632,13 @@ export async function syncSchema(
|
|
|
632
632
|
|
|
633
633
|
// ---- types in the database but not in files: retire, unless they have content
|
|
634
634
|
const inFiles = new Set(typeKeyByAlias.values())
|
|
635
|
-
const dbTypes = await tx.
|
|
636
|
-
'
|
|
637
|
-
|
|
638
|
-
|
|
635
|
+
const dbTypes = await tx.q
|
|
636
|
+
.selectFrom('content_type as ct')
|
|
637
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
638
|
+
.select(['n.unique_id', 'ct.alias'])
|
|
639
|
+
.where('ct.retired_at', 'is', null)
|
|
640
|
+
.where('n.node_object_type', '=', kind.repo.objectType)
|
|
641
|
+
.execute()
|
|
639
642
|
for (const row of dbTypes) {
|
|
640
643
|
const key = String(row.unique_id).toLowerCase()
|
|
641
644
|
if (inFiles.has(key)) continue
|
|
@@ -653,10 +656,13 @@ export async function syncSchema(
|
|
|
653
656
|
`${kind.noun} "${row.alias}" was removed from schema/ but ${count} ${kind.items} of it exist; restore the file, or retire it deliberately with --force-retire-types`,
|
|
654
657
|
)
|
|
655
658
|
}
|
|
656
|
-
await tx.
|
|
657
|
-
'
|
|
658
|
-
|
|
659
|
-
|
|
659
|
+
await tx.q
|
|
660
|
+
.updateTable('content_type')
|
|
661
|
+
.set({ retired_at: DbDate.toDb(new Date()) })
|
|
662
|
+
.where('node_id', '=', (eb) =>
|
|
663
|
+
eb.selectFrom('node').select('id').where('unique_id', '=', key),
|
|
664
|
+
)
|
|
665
|
+
.execute()
|
|
660
666
|
report.retiredTypes.push(String(row.alias))
|
|
661
667
|
}
|
|
662
668
|
}
|