@crombolo/data 0.39.1 → 0.41.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 +2 -2
- package/src/index.ts +2 -0
- package/src/repositories/bundles.ts +51 -0
- package/src/repositories/content-types.ts +24 -2
- package/src/repositories/tags.ts +3 -0
- package/src/repositories/users.ts +68 -0
- package/src/schema/bundle-schema-picks.ts +22 -0
- package/src/schema/plan.ts +4 -0
- package/src/schema/site-settings-types.ts +27 -0
- package/src/site-search.ts +2 -0
- package/src/tables.gen.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.1",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. SQLite and Postgres storage for crombolo: schema, migrations and repositories.",
|
|
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.
|
|
31
|
+
"@crombolo/core": "0.41.1",
|
|
32
32
|
"kysely": "0.29.6"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/index.ts
CHANGED
|
@@ -60,6 +60,7 @@ export * from './schema/built-in-media-types.ts'
|
|
|
60
60
|
export * from './schema/built-in-member-types.ts'
|
|
61
61
|
export * from './schema/bundle-grants.ts'
|
|
62
62
|
export * from './schema/bundle-package.ts'
|
|
63
|
+
export * from './schema/bundle-schema-picks.ts'
|
|
63
64
|
export * from './schema/bundles-disabled.ts'
|
|
64
65
|
export * from './schema/bundles-rename.ts'
|
|
65
66
|
export * from './schema/change-report.ts'
|
|
@@ -97,6 +98,7 @@ export * from './schema/search-index.ts'
|
|
|
97
98
|
export * from './schema/seed.ts'
|
|
98
99
|
export * from './schema/since-version.ts'
|
|
99
100
|
export * from './schema/site-search.ts'
|
|
101
|
+
export * from './schema/site-settings-types.ts'
|
|
100
102
|
export * from './schema/transfer-answers.ts'
|
|
101
103
|
export * from './schema/transfer-run-package.ts'
|
|
102
104
|
export * from './schema/transfer-runs.ts'
|
|
@@ -139,6 +139,25 @@ const hydrate = (row: Row): Bundle => ({
|
|
|
139
139
|
updateDate: DbDate.fromDb(row.update_date) ?? new Date(0),
|
|
140
140
|
})
|
|
141
141
|
|
|
142
|
+
/** What a bundle picks beyond Umbraco's definition (story 226), by alias. */
|
|
143
|
+
export interface BundleSchemaPicks {
|
|
144
|
+
forms: string[]
|
|
145
|
+
workflows: string[]
|
|
146
|
+
userGroups: string[]
|
|
147
|
+
/** What a pick brought and its author unticked: `<kind>:<alias>`. */
|
|
148
|
+
excluded: string[]
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export const NO_SCHEMA_PICKS: BundleSchemaPicks = {
|
|
152
|
+
forms: [],
|
|
153
|
+
workflows: [],
|
|
154
|
+
userGroups: [],
|
|
155
|
+
excluded: [],
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const strings = (value: unknown): string[] =>
|
|
159
|
+
Array.isArray(value) ? value.filter((item): item is string => typeof item === 'string') : []
|
|
160
|
+
|
|
142
161
|
export class BundleRepository {
|
|
143
162
|
#db: Db
|
|
144
163
|
constructor(db: Db) {
|
|
@@ -172,6 +191,38 @@ export class BundleRepository {
|
|
|
172
191
|
return row ? hydrate(row) : undefined
|
|
173
192
|
}
|
|
174
193
|
|
|
194
|
+
/** The forms, workflows and user groups it picks; none when it picks none. */
|
|
195
|
+
async schemaPicks(id: string): Promise<BundleSchemaPicks> {
|
|
196
|
+
const row = await this.#db.q
|
|
197
|
+
.selectFrom('bundle')
|
|
198
|
+
.select('schema_picks')
|
|
199
|
+
.where('id', '=', id)
|
|
200
|
+
.executeTakeFirst()
|
|
201
|
+
if (!row?.schema_picks) return { ...NO_SCHEMA_PICKS }
|
|
202
|
+
try {
|
|
203
|
+
const parsed = JSON.parse(row.schema_picks) as Record<string, unknown>
|
|
204
|
+
return {
|
|
205
|
+
forms: strings(parsed.forms),
|
|
206
|
+
workflows: strings(parsed.workflows),
|
|
207
|
+
userGroups: strings(parsed.userGroups),
|
|
208
|
+
excluded: strings(parsed.excluded),
|
|
209
|
+
}
|
|
210
|
+
} catch {
|
|
211
|
+
return { ...NO_SCHEMA_PICKS }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/** Replaces them; false when there is no such bundle. */
|
|
216
|
+
async setSchemaPicks(id: string, picks: BundleSchemaPicks): Promise<boolean> {
|
|
217
|
+
if (!(await this.byId(id))) return false
|
|
218
|
+
await this.#db.q
|
|
219
|
+
.updateTable('bundle')
|
|
220
|
+
.set({ schema_picks: JSON.stringify(picks), update_date: DbDate.toDb(new Date()) })
|
|
221
|
+
.where('id', '=', id)
|
|
222
|
+
.execute()
|
|
223
|
+
return true
|
|
224
|
+
}
|
|
225
|
+
|
|
175
226
|
async byName(name: string): Promise<Bundle | undefined> {
|
|
176
227
|
const row = await this.#db.q
|
|
177
228
|
.selectFrom('bundle')
|
|
@@ -47,11 +47,12 @@ async function propertySignature(db: Db, contentTypeNodeId: number): Promise<str
|
|
|
47
47
|
.execute()
|
|
48
48
|
const [type] = await db.q
|
|
49
49
|
.selectFrom('content_type')
|
|
50
|
-
.select('site_search')
|
|
50
|
+
.select(['site_search', 'site_settings'])
|
|
51
51
|
.where('node_id', '=', contentTypeNodeId)
|
|
52
52
|
.execute()
|
|
53
53
|
return [
|
|
54
|
-
|
|
54
|
+
// A site's settings page is never searched (story 058).
|
|
55
|
+
`site:${type ? fromDbBool(type.site_search) && !fromDbBool(type.site_settings) : true}`,
|
|
55
56
|
...rows.map(
|
|
56
57
|
(row) =>
|
|
57
58
|
`${row.id}:${row.alias}:${row.variations}:${row.data_type_id}:${fromDbBool(row.searchable)}:${row.site_search}`,
|
|
@@ -367,6 +368,12 @@ export class ContentTypeRepository {
|
|
|
367
368
|
.set({ site_search: bool(aggregate.siteSearch) })
|
|
368
369
|
.where('node_id', '=', nodeId)
|
|
369
370
|
.execute()
|
|
371
|
+
if (aggregate.siteSettings !== undefined)
|
|
372
|
+
await tx.q
|
|
373
|
+
.updateTable('content_type')
|
|
374
|
+
.set({ site_settings: bool(aggregate.siteSettings) })
|
|
375
|
+
.where('node_id', '=', nodeId)
|
|
376
|
+
.execute()
|
|
370
377
|
|
|
371
378
|
// ---- groups: upsert by key
|
|
372
379
|
const groupIdByKey = new Map<string, number>()
|
|
@@ -688,6 +695,19 @@ export class ContentTypeRepository {
|
|
|
688
695
|
return new Map(rows.map((r) => [normaliseUuid(String(r.unique_id)), String(r.alias)]))
|
|
689
696
|
}
|
|
690
697
|
|
|
698
|
+
/** The aliases of the types that are a site's settings (story 058). */
|
|
699
|
+
async siteSettingsAliases(): Promise<string[]> {
|
|
700
|
+
const rows = await this.#db.q
|
|
701
|
+
.selectFrom('content_type as ct')
|
|
702
|
+
.innerJoin('node as n', 'n.id', 'ct.node_id')
|
|
703
|
+
.select('ct.alias')
|
|
704
|
+
.where('ct.retired_at', 'is', null)
|
|
705
|
+
.where('ct.site_settings', '=', this.#db.dialect.boolValue(true) as boolean)
|
|
706
|
+
.where('n.node_object_type', '=', this.#objectType)
|
|
707
|
+
.execute()
|
|
708
|
+
return rows.map((row) => String(row.alias))
|
|
709
|
+
}
|
|
710
|
+
|
|
691
711
|
async move(key: string, parentKey: string | null): Promise<boolean> {
|
|
692
712
|
const node = await this.#nodes.byKey(key)
|
|
693
713
|
if (!node || node.objectType !== this.#objectType) return false
|
|
@@ -904,6 +924,7 @@ export class ContentTypeRepository {
|
|
|
904
924
|
'ct.keep_latest_version_per_day_for_days',
|
|
905
925
|
'ct.since_version',
|
|
906
926
|
'ct.site_search',
|
|
927
|
+
'ct.site_settings',
|
|
907
928
|
'ss.version as since_v',
|
|
908
929
|
'ss.revision as since_r',
|
|
909
930
|
])
|
|
@@ -1034,6 +1055,7 @@ export class ContentTypeRepository {
|
|
|
1034
1055
|
isElement: fromDbBool(type.is_element),
|
|
1035
1056
|
allowedInLibrary: fromDbBool(type.allow_in_library),
|
|
1036
1057
|
siteSearch: fromDbBool(type.site_search),
|
|
1058
|
+
siteSettings: fromDbBool(type.site_settings),
|
|
1037
1059
|
collectionKey: type.list_view ? normaliseUuid(String(type.list_view)) : null,
|
|
1038
1060
|
cleanup: {
|
|
1039
1061
|
preventCleanup: fromDbBool(type.prevent_cleanup),
|
package/src/repositories/tags.ts
CHANGED
|
@@ -53,6 +53,9 @@ export class TagRepository {
|
|
|
53
53
|
.where('pv.is_current', '=', this.#db.dialect.boolValue(true))
|
|
54
54
|
.where('d.editor_alias', '=', 'Umbraco.Tags')
|
|
55
55
|
.where('n.trashed', '=', this.#db.dialect.boolValue(false))
|
|
56
|
+
// The earliest page's spelling names a tag, whatever order the engine reads in.
|
|
57
|
+
.orderBy('pv.node_id')
|
|
58
|
+
.orderBy('pv.id')
|
|
56
59
|
.execute()
|
|
57
60
|
const tags = new Map<string, TagRow & { nodes: Set<number> }>()
|
|
58
61
|
for (const row of rows) {
|
|
@@ -97,6 +97,33 @@ export interface UserGroupInput {
|
|
|
97
97
|
granular: GranularPermission[]
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
/** A group as a site's files declare it (story 228). */
|
|
101
|
+
export interface DeclaredUserGroup {
|
|
102
|
+
alias: string
|
|
103
|
+
name: string
|
|
104
|
+
description?: string
|
|
105
|
+
icon?: string
|
|
106
|
+
sections: readonly string[]
|
|
107
|
+
permissions: readonly string[]
|
|
108
|
+
languages: readonly string[] | 'all'
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const sameSet = (a: readonly string[], b: readonly string[]) =>
|
|
112
|
+
a.length === new Set(b).size && a.every((item) => b.includes(item))
|
|
113
|
+
|
|
114
|
+
/** Whether a group already holds what its file says. */
|
|
115
|
+
function sameDeclared(existing: UserGroupRecord, input: UserGroupInput): boolean {
|
|
116
|
+
return (
|
|
117
|
+
existing.name === input.name &&
|
|
118
|
+
(existing.description ?? null) === input.description &&
|
|
119
|
+
(existing.icon ?? null) === input.icon &&
|
|
120
|
+
existing.hasAccessToAllLanguages === input.hasAccessToAllLanguages &&
|
|
121
|
+
sameSet(existing.sections, input.sections) &&
|
|
122
|
+
sameSet(existing.permissions, input.permissions) &&
|
|
123
|
+
sameSet(existing.languages, input.languages)
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
100
127
|
export interface UserInput {
|
|
101
128
|
key: string
|
|
102
129
|
name: string
|
|
@@ -945,6 +972,47 @@ export class UserGroupRepository {
|
|
|
945
972
|
})
|
|
946
973
|
}
|
|
947
974
|
|
|
975
|
+
/**
|
|
976
|
+
* Creates or updates the groups a site declares in files (story 228), by
|
|
977
|
+
* alias: their name, description, icon, sections, verbs and languages. Start
|
|
978
|
+
* nodes, per-page permissions and members are the environment's, and kept.
|
|
979
|
+
*/
|
|
980
|
+
async syncDeclared(groups: readonly DeclaredUserGroup[]): Promise<{
|
|
981
|
+
created: string[]
|
|
982
|
+
updated: string[]
|
|
983
|
+
}> {
|
|
984
|
+
const created: string[] = []
|
|
985
|
+
const updated: string[] = []
|
|
986
|
+
const none: GroupStartNode = { root: false, key: null }
|
|
987
|
+
for (const group of groups) {
|
|
988
|
+
const existing = await this.byAlias(group.alias)
|
|
989
|
+
const languages = group.languages === 'all' ? [] : [...group.languages]
|
|
990
|
+
const input: UserGroupInput = {
|
|
991
|
+
key: existing?.key ?? crypto.randomUUID(),
|
|
992
|
+
alias: group.alias,
|
|
993
|
+
name: group.name,
|
|
994
|
+
description: group.description ?? null,
|
|
995
|
+
icon: group.icon ?? null,
|
|
996
|
+
sections: [...group.sections],
|
|
997
|
+
languages,
|
|
998
|
+
hasAccessToAllLanguages: group.languages === 'all',
|
|
999
|
+
startNodes: existing?.startNodes ?? { document: none, media: none, element: none },
|
|
1000
|
+
permissions: [...group.permissions],
|
|
1001
|
+
granular: existing?.granular ?? [],
|
|
1002
|
+
}
|
|
1003
|
+
if (existing && sameDeclared(existing, input)) continue
|
|
1004
|
+
const saved = await this.save(input)
|
|
1005
|
+
if (saved === 'missing-language')
|
|
1006
|
+
throw new Error(
|
|
1007
|
+
`The user group "${group.alias}" names a language the site does not have: ${languages.join(', ')}.`,
|
|
1008
|
+
)
|
|
1009
|
+
if (saved !== 'saved')
|
|
1010
|
+
throw new Error(`The user group "${group.alias}" keeps a start node that no longer exists.`)
|
|
1011
|
+
;(existing ? updated : created).push(group.alias)
|
|
1012
|
+
}
|
|
1013
|
+
return { created, updated }
|
|
1014
|
+
}
|
|
1015
|
+
|
|
948
1016
|
async delete(key: string): Promise<void> {
|
|
949
1017
|
const group = await this.byKey(key)
|
|
950
1018
|
if (!group) return
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 058: what a created bundle picks beyond Umbraco's definition (story
|
|
3
|
+
* 226): its forms, approval workflows and user groups, and what its author
|
|
4
|
+
* unticked of what they bring. JSON text, as the definition's other lists are.
|
|
5
|
+
*/
|
|
6
|
+
import type { Db } from '../database.ts'
|
|
7
|
+
import type { Migration } from '../migrations.ts'
|
|
8
|
+
import { schemaOps } from '../schema-ops.ts'
|
|
9
|
+
import { STATE_SITE_SETTINGS_TYPES } from './site-settings-types.ts'
|
|
10
|
+
|
|
11
|
+
export const STATE_BUNDLE_SCHEMA_PICKS = '{4b198f00-0058-4ca8-bc39-97d92fca0058}'
|
|
12
|
+
|
|
13
|
+
export const bundleSchemaPicksMigration: Migration = {
|
|
14
|
+
from: STATE_SITE_SETTINGS_TYPES,
|
|
15
|
+
to: STATE_BUNDLE_SCHEMA_PICKS,
|
|
16
|
+
name: 'AddBundleSchemaPicks',
|
|
17
|
+
kind: 'expand',
|
|
18
|
+
release: '0.41.1',
|
|
19
|
+
async up(db: Db) {
|
|
20
|
+
await schemaOps(db).addColumn('bundle', 'schema_picks', db.dialect.types.text)
|
|
21
|
+
},
|
|
22
|
+
}
|
package/src/schema/plan.ts
CHANGED
|
@@ -20,6 +20,7 @@ import { auditLogMigration } from './audit-log.ts'
|
|
|
20
20
|
import { bundleComponentsMigration } from './bundle-components.ts'
|
|
21
21
|
import { bundleGrantsMigration } from './bundle-grants.ts'
|
|
22
22
|
import { bundlePackageMigration } from './bundle-package.ts'
|
|
23
|
+
import { bundleSchemaPicksMigration } from './bundle-schema-picks.ts'
|
|
23
24
|
import { bundlesDisabledMigration } from './bundles-disabled.ts'
|
|
24
25
|
import { bundlesRenameMigration } from './bundles-rename.ts'
|
|
25
26
|
import { changeReportMigration } from './change-report.ts'
|
|
@@ -60,6 +61,7 @@ import { searchIndexMigration } from './search-index.ts'
|
|
|
60
61
|
import { serverRoleMigration } from './server-role.ts'
|
|
61
62
|
import { sinceVersionMigration } from './since-version.ts'
|
|
62
63
|
import { siteSearchMigration } from './site-search.ts'
|
|
64
|
+
import { siteSettingsTypesMigration } from './site-settings-types.ts'
|
|
63
65
|
import { transferAnswersMigration } from './transfer-answers.ts'
|
|
64
66
|
import { transferRunPackageMigration } from './transfer-run-package.ts'
|
|
65
67
|
import { transferRunsMigration } from './transfer-runs.ts'
|
|
@@ -127,4 +129,6 @@ export const cromboloPlan = new MigrationPlan([
|
|
|
127
129
|
bundleGrantsMigration,
|
|
128
130
|
jobsMigration,
|
|
129
131
|
bundlesDisabledMigration,
|
|
132
|
+
siteSettingsTypesMigration,
|
|
133
|
+
bundleSchemaPicksMigration,
|
|
130
134
|
])
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 057: a content type can be a site's settings (story 058). Its page,
|
|
3
|
+
* a direct child of a root, holds that site's settings and has no address.
|
|
4
|
+
*/
|
|
5
|
+
import type { Db } from '../database.ts'
|
|
6
|
+
import type { Migration } from '../migrations.ts'
|
|
7
|
+
import { schemaOps } from '../schema-ops.ts'
|
|
8
|
+
import { STATE_BUNDLES_DISABLED } from './bundles-disabled.ts'
|
|
9
|
+
|
|
10
|
+
export const STATE_SITE_SETTINGS_TYPES = '{4b198f00-0057-4ca8-bc39-97d92fca0057}'
|
|
11
|
+
|
|
12
|
+
export const siteSettingsTypesMigration: Migration = {
|
|
13
|
+
from: STATE_BUNDLES_DISABLED,
|
|
14
|
+
to: STATE_SITE_SETTINGS_TYPES,
|
|
15
|
+
name: 'AddSiteSettingsTypes',
|
|
16
|
+
kind: 'expand',
|
|
17
|
+
release: '0.40.0',
|
|
18
|
+
async up(db: Db) {
|
|
19
|
+
const t = db.dialect.types
|
|
20
|
+
const postgres = db.dialect.name === 'postgres'
|
|
21
|
+
await schemaOps(db).addColumn(
|
|
22
|
+
'content_type',
|
|
23
|
+
'site_settings',
|
|
24
|
+
`${t.boolean} NOT NULL DEFAULT ${postgres ? 'FALSE' : '0'}`,
|
|
25
|
+
)
|
|
26
|
+
},
|
|
27
|
+
}
|
package/src/site-search.ts
CHANGED
|
@@ -71,6 +71,7 @@ export async function siteEntriesFor(db: Db, nodeId: number): Promise<SiteSearch
|
|
|
71
71
|
'n.trashed',
|
|
72
72
|
'c.content_type_id',
|
|
73
73
|
'ct.site_search',
|
|
74
|
+
'ct.site_settings',
|
|
74
75
|
'ct.is_element',
|
|
75
76
|
'd.published',
|
|
76
77
|
eb
|
|
@@ -87,6 +88,7 @@ export async function siteEntriesFor(db: Db, nodeId: number): Promise<SiteSearch
|
|
|
87
88
|
fromDbBool(node.trashed) ||
|
|
88
89
|
!fromDbBool(node.published) ||
|
|
89
90
|
!fromDbBool(node.site_search) ||
|
|
91
|
+
fromDbBool(node.site_settings) ||
|
|
90
92
|
fromDbBool(node.is_element) ||
|
|
91
93
|
Number(node.components) === 0
|
|
92
94
|
)
|
package/src/tables.gen.ts
CHANGED
|
@@ -107,6 +107,7 @@ export interface CoreTables {
|
|
|
107
107
|
name: string
|
|
108
108
|
package_name: string | null
|
|
109
109
|
package_version: string | null
|
|
110
|
+
schema_picks: string | null
|
|
110
111
|
scripts: string
|
|
111
112
|
stylesheets: string
|
|
112
113
|
update_date: Timestamp
|
|
@@ -249,6 +250,7 @@ export interface CoreTables {
|
|
|
249
250
|
since_state_id: number | null
|
|
250
251
|
since_version: string | null
|
|
251
252
|
site_search: Default<Bool>
|
|
253
|
+
site_settings: Default<Bool>
|
|
252
254
|
thumbnail: string | null
|
|
253
255
|
variations: number
|
|
254
256
|
}
|