@crombolo/data 0.79.1 → 0.80.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/documents.ts +20 -1
- package/src/repositories/workspaces.ts +41 -8
- package/src/schema/plan.ts +4 -0
- package/src/schema/users-in-settings.ts +41 -0
- package/src/schema/workspace-description.ts +24 -0
- package/src/tables.gen.ts +1 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.80.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",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@crombolo/core": "0.
|
|
32
|
+
"@crombolo/core": "0.80.1",
|
|
33
33
|
"kysely": "0.29.6"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/index.ts
CHANGED
|
@@ -154,10 +154,12 @@ export * from './schema/two-factor.ts'
|
|
|
154
154
|
export * from './schema/upgrade-report.ts'
|
|
155
155
|
export * from './schema/user-group-owners.ts'
|
|
156
156
|
export * from './schema/user-start-nodes-dropped.ts'
|
|
157
|
+
export * from './schema/users-in-settings.ts'
|
|
157
158
|
export * from './schema/users-localisation.ts'
|
|
158
159
|
export * from './schema/values.ts'
|
|
159
160
|
export * from './schema/webhooks.ts'
|
|
160
161
|
export * from './schema/workspace-conflicts.ts'
|
|
162
|
+
export * from './schema/workspace-description.ts'
|
|
161
163
|
export * from './schema/workspace-errors.ts'
|
|
162
164
|
export * from './schema/workspace-links.ts'
|
|
163
165
|
export * from './schema/workspace-merge.ts'
|
|
@@ -967,6 +967,24 @@ export class DocumentRepository {
|
|
|
967
967
|
return true
|
|
968
968
|
}
|
|
969
969
|
|
|
970
|
+
/** Whether the workspace moves the page, or one above it, out of the bin at its merge. */
|
|
971
|
+
async #leavesBin(node: NodeRow): Promise<boolean> {
|
|
972
|
+
const rows = await this.#db.q
|
|
973
|
+
.selectFrom('workspace_pending')
|
|
974
|
+
.select('id')
|
|
975
|
+
.where('workspace_id', '=', this.#workspace as number)
|
|
976
|
+
.where('kind', '=', 'move')
|
|
977
|
+
.where('node_id', 'in', [
|
|
978
|
+
node.id,
|
|
979
|
+
...node.path
|
|
980
|
+
.split(',')
|
|
981
|
+
.map(Number)
|
|
982
|
+
.filter((id) => id > 0),
|
|
983
|
+
])
|
|
984
|
+
.execute()
|
|
985
|
+
return rows.length > 0
|
|
986
|
+
}
|
|
987
|
+
|
|
970
988
|
/**
|
|
971
989
|
* Publishes a page in the workspace only (story 375): Shared's published
|
|
972
990
|
* page, its flags and the published cache are untouched, and the usual rules
|
|
@@ -976,7 +994,8 @@ export class DocumentRepository {
|
|
|
976
994
|
node: NodeRow,
|
|
977
995
|
cultures: readonly string[] | null,
|
|
978
996
|
): Promise<DocumentAggregate | undefined> {
|
|
979
|
-
if (node.trashed
|
|
997
|
+
if (node.trashed && !(await this.#leavesBin(node)))
|
|
998
|
+
throw new PublishBlockedError('The document is in the recycle bin.')
|
|
980
999
|
if (!(await this.#ancestorsPublishedInWorkspace(node)))
|
|
981
1000
|
throw new PublishBlockedError('An ancestor is not published.')
|
|
982
1001
|
await this.#touch(node)
|
|
@@ -21,6 +21,9 @@ import {
|
|
|
21
21
|
import { WorkspaceFileRepository } from './workspace-files.ts'
|
|
22
22
|
|
|
23
23
|
/** A change staged in a workspace (story 383), with the schedules its merge sets (story 395). */
|
|
24
|
+
/** How lately a workspace changed a page for someone else opening it to be told. */
|
|
25
|
+
export const TOUCHED_WITHIN_MS = 7 * 24 * 60 * 60 * 1000
|
|
26
|
+
|
|
24
27
|
export interface StagedChange {
|
|
25
28
|
key: string
|
|
26
29
|
name: string | null
|
|
@@ -55,8 +58,10 @@ export interface Workspace {
|
|
|
55
58
|
stagedReadOnly: boolean
|
|
56
59
|
/** Who can see it (story 384): its members, or everyone who may edit, reading only. */
|
|
57
60
|
visibility: 'members' | 'editors'
|
|
58
|
-
/**
|
|
61
|
+
/** No longer chosen: anyone opening an item it changed lately is told so. Kept as stored. */
|
|
59
62
|
tellOthers: boolean
|
|
63
|
+
/** What it is for, in its owner's words. */
|
|
64
|
+
description: string | null
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
/** A move, reorder or delete waiting for the merge, with where its page stood (story 380). */
|
|
@@ -109,6 +114,7 @@ export class WorkspaceRepository {
|
|
|
109
114
|
personal?: boolean
|
|
110
115
|
visibility?: 'members' | 'editors'
|
|
111
116
|
tellOthers?: boolean
|
|
117
|
+
description?: string | null
|
|
112
118
|
/** Opened only to see what something would do, then discarded: raises nothing. */
|
|
113
119
|
quiet?: boolean
|
|
114
120
|
}): Promise<Workspace> {
|
|
@@ -123,6 +129,7 @@ export class WorkspaceRepository {
|
|
|
123
129
|
personal: this.#db.dialect.boolValue(input.personal === true) as boolean,
|
|
124
130
|
visibility: input.visibility ?? 'members',
|
|
125
131
|
tell_others: this.#db.dialect.boolValue(input.tellOthers !== false) as boolean,
|
|
132
|
+
description: input.description?.trim() || null,
|
|
126
133
|
created_at: now,
|
|
127
134
|
updated_at: now,
|
|
128
135
|
})
|
|
@@ -327,17 +334,37 @@ export class WorkspaceRepository {
|
|
|
327
334
|
await this.#db.q.updateTable('workspace').set(set).where('id', '=', id).execute()
|
|
328
335
|
}
|
|
329
336
|
|
|
330
|
-
/**
|
|
331
|
-
async
|
|
337
|
+
/** What it is for, changed by its owner; empty clears it. */
|
|
338
|
+
async setDescription(id: number, description: string | null): Promise<void> {
|
|
339
|
+
await this.#db.q
|
|
340
|
+
.updateTable('workspace')
|
|
341
|
+
.set({ description: description?.trim() || null })
|
|
342
|
+
.where('id', '=', id)
|
|
343
|
+
.execute()
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Open workspaces, other than `except`'s own, that changed a page lately (story 384):
|
|
348
|
+
* since `since`, seven days ago unless said. An older change is not worth a warning.
|
|
349
|
+
*/
|
|
350
|
+
async touching(
|
|
351
|
+
nodeId: number,
|
|
352
|
+
exceptUser: string,
|
|
353
|
+
since = new Date(Date.now() - TOUCHED_WITHIN_MS),
|
|
354
|
+
): Promise<Workspace[]> {
|
|
355
|
+
const from = DbDate.toDb(since)
|
|
332
356
|
const documents = await this.#db.q
|
|
333
|
-
.selectFrom('
|
|
357
|
+
.selectFrom('content_version')
|
|
334
358
|
.select('workspace_id')
|
|
335
359
|
.where('node_id', '=', nodeId)
|
|
360
|
+
.where('workspace_id', 'is not', null)
|
|
361
|
+
.where('version_date', '>=', from)
|
|
336
362
|
.execute()
|
|
337
363
|
const pending = await this.#db.q
|
|
338
364
|
.selectFrom('workspace_pending')
|
|
339
365
|
.select('workspace_id')
|
|
340
366
|
.where('node_id', '=', nodeId)
|
|
367
|
+
.where('recorded_at', '>=', from)
|
|
341
368
|
.execute()
|
|
342
369
|
const ids = [...new Set([...documents, ...pending].map((r) => Number(r.workspace_id)))]
|
|
343
370
|
if (ids.length === 0) return []
|
|
@@ -349,7 +376,6 @@ export class WorkspaceRepository {
|
|
|
349
376
|
.execute()
|
|
350
377
|
return (await this.#withMembers(rows)).filter(
|
|
351
378
|
(w) =>
|
|
352
|
-
w.tellOthers &&
|
|
353
379
|
w.ownerKey !== normaliseUuid(exceptUser) &&
|
|
354
380
|
!w.memberKeys.includes(normaliseUuid(exceptUser)),
|
|
355
381
|
)
|
|
@@ -456,12 +482,17 @@ export class WorkspaceRepository {
|
|
|
456
482
|
.execute()
|
|
457
483
|
}
|
|
458
484
|
|
|
459
|
-
async dropPending(
|
|
460
|
-
|
|
485
|
+
async dropPending(
|
|
486
|
+
id: number,
|
|
487
|
+
nodeId: number,
|
|
488
|
+
kinds?: ReadonlyArray<WorkspacePending['kind']>,
|
|
489
|
+
): Promise<void> {
|
|
490
|
+
let rows = this.#db.q
|
|
461
491
|
.deleteFrom('workspace_pending')
|
|
462
492
|
.where('workspace_id', '=', id)
|
|
463
493
|
.where('node_id', '=', nodeId)
|
|
464
|
-
|
|
494
|
+
if (kinds) rows = rows.where('kind', 'in', [...kinds])
|
|
495
|
+
await rows.execute()
|
|
465
496
|
}
|
|
466
497
|
|
|
467
498
|
/** A page merged alone from a person's own workspace (story 380): its rows there go. */
|
|
@@ -638,6 +669,7 @@ export class WorkspaceRepository {
|
|
|
638
669
|
staged_changes?: string | null
|
|
639
670
|
visibility?: string | null
|
|
640
671
|
tell_others?: unknown
|
|
672
|
+
description?: string | null
|
|
641
673
|
}>,
|
|
642
674
|
): Promise<Workspace[]> {
|
|
643
675
|
if (rows.length === 0) return []
|
|
@@ -668,6 +700,7 @@ export class WorkspaceRepository {
|
|
|
668
700
|
...stagedOf(row.staged_changes),
|
|
669
701
|
visibility: row.visibility === 'editors' ? 'editors' : 'members',
|
|
670
702
|
tellOthers: row.tell_others === undefined ? true : fromDbBool(row.tell_others),
|
|
703
|
+
description: row.description ?? null,
|
|
671
704
|
}))
|
|
672
705
|
}
|
|
673
706
|
}
|
package/src/schema/plan.ts
CHANGED
|
@@ -98,10 +98,12 @@ import { twoFactorMigration } from './two-factor.ts'
|
|
|
98
98
|
import { upgradeReportMigration } from './upgrade-report.ts'
|
|
99
99
|
import { userGroupOwnersMigration } from './user-group-owners.ts'
|
|
100
100
|
import { userStartNodesDroppedMigration } from './user-start-nodes-dropped.ts'
|
|
101
|
+
import { usersInSettingsMigration } from './users-in-settings.ts'
|
|
101
102
|
import { usersLocalisationMigration } from './users-localisation.ts'
|
|
102
103
|
import { valuesMigration } from './values.ts'
|
|
103
104
|
import { webhooksMigration } from './webhooks.ts'
|
|
104
105
|
import { workspaceConflictsMigration } from './workspace-conflicts.ts'
|
|
106
|
+
import { workspaceDescriptionMigration } from './workspace-description.ts'
|
|
105
107
|
import { workspaceErrorsMigration } from './workspace-errors.ts'
|
|
106
108
|
import { workspaceLinksMigration } from './workspace-links.ts'
|
|
107
109
|
import { workspaceMergeMigration } from './workspace-merge.ts'
|
|
@@ -211,4 +213,6 @@ export const cromboloPlan = new MigrationPlan([
|
|
|
211
213
|
workspaceErrorsMigration,
|
|
212
214
|
workspaceSchedulesMigration,
|
|
213
215
|
workspacePlacesMigration,
|
|
216
|
+
workspaceDescriptionMigration,
|
|
217
|
+
usersInSettingsMigration,
|
|
214
218
|
])
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 100 — Users are in Settings (story 429), and need it: each group holding Users
|
|
3
|
+
* without Settings gains Settings, so nobody loses the users they could open.
|
|
4
|
+
*/
|
|
5
|
+
import type { Db } from '../database.ts'
|
|
6
|
+
import type { Migration } from '../migrations.ts'
|
|
7
|
+
import { STATE_WORKSPACE_DESCRIPTION } from './workspace-description.ts'
|
|
8
|
+
|
|
9
|
+
export const STATE_USERS_IN_SETTINGS = '{2f6b9d40-0100-4c8e-b173-5e0d8a6c0100}'
|
|
10
|
+
|
|
11
|
+
export const usersInSettingsMigration: Migration = {
|
|
12
|
+
from: STATE_WORKSPACE_DESCRIPTION,
|
|
13
|
+
to: STATE_USERS_IN_SETTINGS,
|
|
14
|
+
name: 'PutUsersInSettings',
|
|
15
|
+
kind: 'expand',
|
|
16
|
+
release: '0.80.0',
|
|
17
|
+
async up(db: Db) {
|
|
18
|
+
await db.q
|
|
19
|
+
.insertInto('user_group_section')
|
|
20
|
+
.columns(['user_group_id', 'app_alias'])
|
|
21
|
+
.expression((eb) =>
|
|
22
|
+
eb
|
|
23
|
+
.selectFrom('user_group_section as held')
|
|
24
|
+
.select(['held.user_group_id', eb.val('settings').as('app_alias')])
|
|
25
|
+
.where('held.app_alias', '=', 'users')
|
|
26
|
+
.where((w) =>
|
|
27
|
+
w.not(
|
|
28
|
+
w.exists(
|
|
29
|
+
w
|
|
30
|
+
.selectFrom('user_group_section as has')
|
|
31
|
+
.select('has.app_alias')
|
|
32
|
+
.whereRef('has.user_group_id', '=', 'held.user_group_id')
|
|
33
|
+
.where('has.app_alias', '=', 'settings'),
|
|
34
|
+
),
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
.distinct(),
|
|
38
|
+
)
|
|
39
|
+
.execute()
|
|
40
|
+
},
|
|
41
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 099 — what a workspace is for: a description, said when it is
|
|
3
|
+
* opened and changed by its owner, beside its name.
|
|
4
|
+
*/
|
|
5
|
+
import type { Db } from '../database.ts'
|
|
6
|
+
import type { Migration } from '../migrations.ts'
|
|
7
|
+
import { sql } from '../query.ts'
|
|
8
|
+
import { STATE_WORKSPACE_PLACES } from './workspace-places.ts'
|
|
9
|
+
|
|
10
|
+
export const STATE_WORKSPACE_DESCRIPTION = '{7d2c5a18-0099-4f3b-8e61-9a4b0c7d0099}'
|
|
11
|
+
|
|
12
|
+
export const workspaceDescriptionMigration: Migration = {
|
|
13
|
+
from: STATE_WORKSPACE_PLACES,
|
|
14
|
+
to: STATE_WORKSPACE_DESCRIPTION,
|
|
15
|
+
name: 'AddWorkspaceDescription',
|
|
16
|
+
kind: 'expand',
|
|
17
|
+
release: '0.80.0',
|
|
18
|
+
async up(db: Db) {
|
|
19
|
+
await db.q.schema
|
|
20
|
+
.alterTable('workspace')
|
|
21
|
+
.addColumn('description', sql.raw(db.dialect.types.varchar(1000)))
|
|
22
|
+
.execute()
|
|
23
|
+
},
|
|
24
|
+
}
|