@crombolo/data 0.49.0 → 0.51.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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
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.51.0",
|
|
32
32
|
"kysely": "0.29.6"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/index.ts
CHANGED
|
@@ -85,6 +85,7 @@ export * from './schema/form-library-types.ts'
|
|
|
85
85
|
export * from './schema/form-permission-prefix.ts'
|
|
86
86
|
export * from './schema/group-permissions.ts'
|
|
87
87
|
export * from './schema/identity.ts'
|
|
88
|
+
export * from './schema/image-alt-text.ts'
|
|
88
89
|
export * from './schema/jobs.ts'
|
|
89
90
|
export * from './schema/log-viewer.ts'
|
|
90
91
|
export * from './schema/media-access.ts'
|
|
@@ -77,6 +77,57 @@ export class FolderRepository {
|
|
|
77
77
|
return 'deleted'
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
+
/** Whether anything outside the recycle bin is still inside. */
|
|
81
|
+
async holdsAnything(key: string): Promise<boolean> {
|
|
82
|
+
const node = await this.#nodes.byKey(key)
|
|
83
|
+
if (!node) return false
|
|
84
|
+
const inside = await this.#nodes.childrenOf(node.id, [this.#objectType, this.#itemType], 0, 1)
|
|
85
|
+
return inside.total > 0
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Moves a folder to `bin`: its branch is trashed, and what it holds stays unpublished. */
|
|
89
|
+
async toRecycleBin(key: string, bin: number): Promise<boolean> {
|
|
90
|
+
const node = await this.#nodes.byKey(key)
|
|
91
|
+
if (!node || node.objectType !== this.#objectType) return false
|
|
92
|
+
await this.#nodes.move(node.id, bin)
|
|
93
|
+
const moved = await this.#nodes.byKey(key)
|
|
94
|
+
const branch = `${moved?.path ?? node.path},%`
|
|
95
|
+
const db = this.#db
|
|
96
|
+
await db.q
|
|
97
|
+
.updateTable('node')
|
|
98
|
+
.set({ trashed: db.dialect.boolValue(true) as boolean })
|
|
99
|
+
.where((eb) => eb.or([eb('id', '=', node.id), eb('path', 'like', branch)]))
|
|
100
|
+
.execute()
|
|
101
|
+
await db.q
|
|
102
|
+
.updateTable('document')
|
|
103
|
+
.set({
|
|
104
|
+
published: db.dialect.boolValue(false) as boolean,
|
|
105
|
+
edited: db.dialect.boolValue(true) as boolean,
|
|
106
|
+
})
|
|
107
|
+
.where('node_id', 'in', (eb) =>
|
|
108
|
+
eb
|
|
109
|
+
.selectFrom('node')
|
|
110
|
+
.select('id')
|
|
111
|
+
.where((w) => w.or([w('id', '=', node.id), w('path', 'like', branch)])),
|
|
112
|
+
)
|
|
113
|
+
.execute()
|
|
114
|
+
return true
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Takes a folder out of the recycle bin to `parentKey`, or the top level. */
|
|
118
|
+
async restore(key: string, parentKey: string | null): Promise<boolean> {
|
|
119
|
+
const node = await this.#nodes.byKey(key)
|
|
120
|
+
if (!node || node.objectType !== this.#objectType || !node.trashed) return false
|
|
121
|
+
await this.#db.q
|
|
122
|
+
.updateTable('node')
|
|
123
|
+
.set({ trashed: this.#db.dialect.boolValue(false) as boolean })
|
|
124
|
+
.where((eb) => eb.or([eb('id', '=', node.id), eb('path', 'like', `${node.path},%`)]))
|
|
125
|
+
.execute()
|
|
126
|
+
const parent = parentKey ? await this.#nodes.byKey(parentKey) : undefined
|
|
127
|
+
await this.#nodes.move(node.id, parent?.id ?? SystemNodes.Root)
|
|
128
|
+
return true
|
|
129
|
+
}
|
|
130
|
+
|
|
80
131
|
/** Makes `A/B/C` exist, creating what is missing; returns the leaf's key, or null for an empty path. */
|
|
81
132
|
async ensurePath(names: readonly string[]): Promise<string | null> {
|
|
82
133
|
let parentId: number = SystemNodes.Root
|
|
@@ -50,6 +50,10 @@ export interface BuiltInMediaType {
|
|
|
50
50
|
properties: BuiltInMediaProperty[]
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/** What describes an image to someone who cannot see it (story 168). */
|
|
54
|
+
export const IMAGE_ALT_TEXT_ALIAS = 'altText'
|
|
55
|
+
export const IMAGE_ALT_TEXT_KEY = '4d1f8a26-7c39-4e0b-a5d2-6b9c0e3f1a64'
|
|
56
|
+
|
|
53
57
|
const extension = (key: string): BuiltInMediaProperty => ({
|
|
54
58
|
key,
|
|
55
59
|
alias: 'umbracoExtension',
|
|
@@ -111,6 +115,13 @@ export const BUILT_IN_MEDIA_TYPES: readonly BuiltInMediaType[] = [
|
|
|
111
115
|
pixels('854087f6-648b-40ed-bc98-b8a9789e80b9', 'umbracoHeight'),
|
|
112
116
|
bytes('bd4c5ace-26e3-4a8b-af1a-e8206a35fa07'),
|
|
113
117
|
extension('f7786fe8-724a-4ed0-b244-72546db32a92'),
|
|
118
|
+
{
|
|
119
|
+
key: IMAGE_ALT_TEXT_KEY,
|
|
120
|
+
alias: IMAGE_ALT_TEXT_ALIAS,
|
|
121
|
+
name: 'Alternative text',
|
|
122
|
+
dataType: 'textstring',
|
|
123
|
+
mandatory: false,
|
|
124
|
+
},
|
|
114
125
|
],
|
|
115
126
|
},
|
|
116
127
|
{
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 064: alt text on the Image media type (story 168), which a fresh
|
|
3
|
+
* site gets from `BUILT_IN_MEDIA_TYPES`. One statement, so the plan can show it:
|
|
4
|
+
* a site with its own `altText` keeps it, and one with no Image yet is about to
|
|
5
|
+
* be given the field with the type.
|
|
6
|
+
*/
|
|
7
|
+
import { SYSTEM_MEDIA_TYPE_KEYS } from '@crombolo/core'
|
|
8
|
+
import type { Db } from '../database.ts'
|
|
9
|
+
import type { Migration } from '../migrations.ts'
|
|
10
|
+
import { sql } from '../query.ts'
|
|
11
|
+
import { IMAGE_ALT_TEXT_ALIAS, IMAGE_ALT_TEXT_KEY } from './built-in-media-types.ts'
|
|
12
|
+
import { STATE_SEARCH_REMOVALS } from './search-removals.ts'
|
|
13
|
+
|
|
14
|
+
export const STATE_IMAGE_ALT_TEXT = '{c3e7a512-0064-4f0b-9d61-a8b2c4e60064}'
|
|
15
|
+
|
|
16
|
+
const TEXTSTRING_DATA_TYPE = '0cc0eba1-9960-42c9-bf9b-60e150b429ae'
|
|
17
|
+
|
|
18
|
+
export const imageAltTextMigration: Migration = {
|
|
19
|
+
from: STATE_SEARCH_REMOVALS,
|
|
20
|
+
to: STATE_IMAGE_ALT_TEXT,
|
|
21
|
+
name: 'AddImageAltText',
|
|
22
|
+
kind: 'expand',
|
|
23
|
+
release: '0.51.0',
|
|
24
|
+
async up(db: Db) {
|
|
25
|
+
const no = sql.lit(db.dialect.boolValue(false))
|
|
26
|
+
await db.q
|
|
27
|
+
.insertInto('property_type')
|
|
28
|
+
.columns([
|
|
29
|
+
'unique_id',
|
|
30
|
+
'data_type_id',
|
|
31
|
+
'content_type_id',
|
|
32
|
+
'property_type_group_id',
|
|
33
|
+
'alias',
|
|
34
|
+
'name',
|
|
35
|
+
'sort_order',
|
|
36
|
+
'mandatory',
|
|
37
|
+
'label_on_top',
|
|
38
|
+
'variations',
|
|
39
|
+
])
|
|
40
|
+
.expression(
|
|
41
|
+
db.q
|
|
42
|
+
.selectFrom(['node as image', 'node as text_type'])
|
|
43
|
+
.where('image.unique_id', '=', SYSTEM_MEDIA_TYPE_KEYS.Image)
|
|
44
|
+
.where('text_type.unique_id', '=', TEXTSTRING_DATA_TYPE)
|
|
45
|
+
.where(({ exists, not, selectFrom }) =>
|
|
46
|
+
not(
|
|
47
|
+
exists(
|
|
48
|
+
selectFrom('property_type as p')
|
|
49
|
+
.select('p.id')
|
|
50
|
+
.whereRef('p.content_type_id', '=', 'image.id')
|
|
51
|
+
.where('p.alias', '=', IMAGE_ALT_TEXT_ALIAS),
|
|
52
|
+
),
|
|
53
|
+
),
|
|
54
|
+
)
|
|
55
|
+
.select(({ selectFrom }) => [
|
|
56
|
+
sql.lit(IMAGE_ALT_TEXT_KEY).as('unique_id'),
|
|
57
|
+
'text_type.id as data_type_id',
|
|
58
|
+
'image.id as content_type_id',
|
|
59
|
+
selectFrom('property_type_group as g')
|
|
60
|
+
.select((group) => group.fn.min('g.id').as('id'))
|
|
61
|
+
.whereRef('g.content_type_node_id', '=', 'image.id')
|
|
62
|
+
.as('property_type_group_id'),
|
|
63
|
+
sql.lit(IMAGE_ALT_TEXT_ALIAS).as('alias'),
|
|
64
|
+
sql.lit('Alternative text').as('name'),
|
|
65
|
+
selectFrom('property_type as p')
|
|
66
|
+
.select((type) => type.fn.countAll().as('n'))
|
|
67
|
+
.whereRef('p.content_type_id', '=', 'image.id')
|
|
68
|
+
.as('sort_order'),
|
|
69
|
+
no.as('mandatory'),
|
|
70
|
+
no.as('label_on_top'),
|
|
71
|
+
sql.lit(0).as('variations'),
|
|
72
|
+
]),
|
|
73
|
+
)
|
|
74
|
+
.execute()
|
|
75
|
+
},
|
|
76
|
+
}
|
package/src/schema/plan.ts
CHANGED
|
@@ -44,6 +44,7 @@ import { formWorkflowsMigration } from './form-workflows.ts'
|
|
|
44
44
|
import { formsMigration } from './forms.ts'
|
|
45
45
|
import { groupPermissionsMigration } from './group-permissions.ts'
|
|
46
46
|
import { identityMigration } from './identity.ts'
|
|
47
|
+
import { imageAltTextMigration } from './image-alt-text.ts'
|
|
47
48
|
import { jobsMigration } from './jobs.ts'
|
|
48
49
|
import { logViewerMigration } from './log-viewer.ts'
|
|
49
50
|
import { mediaAccessMigration } from './media-access.ts'
|
|
@@ -141,4 +142,5 @@ export const cromboloPlan = new MigrationPlan([
|
|
|
141
142
|
remoteTrustMigration,
|
|
142
143
|
mediaTreeOrderMigration,
|
|
143
144
|
searchRemovalsMigration,
|
|
145
|
+
imageAltTextMigration,
|
|
144
146
|
])
|