@crombolo/data 0.77.0 → 0.79.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.77.0",
3
+ "version": "0.79.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",
@@ -29,7 +29,7 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@crombolo/core": "0.77.0",
32
+ "@crombolo/core": "0.79.0",
33
33
  "kysely": "0.29.6"
34
34
  }
35
35
  }
package/src/index.ts CHANGED
@@ -161,6 +161,7 @@ export * from './schema/workspace-conflicts.ts'
161
161
  export * from './schema/workspace-errors.ts'
162
162
  export * from './schema/workspace-links.ts'
163
163
  export * from './schema/workspace-merge.ts'
164
+ export * from './schema/workspace-places.ts'
164
165
  export * from './schema/workspace-privacy.ts'
165
166
  export * from './schema/workspace-processes.ts'
166
167
  export * from './schema/workspace-schedules.ts'
@@ -357,6 +357,40 @@ export class ChangeRepository {
357
357
  await this.#touch(id, now)
358
358
  }
359
359
 
360
+ /**
361
+ * Story 413: a person's newest change that holds a page, made by their own edits or by
362
+ * the merge of their own workspace, closed if it was still open.
363
+ */
364
+ async closeHolding(
365
+ madeBy: string,
366
+ pageKey: string,
367
+ now = new Date(),
368
+ ): Promise<{ id: string; key: string; name: string | null; merged: boolean } | undefined> {
369
+ const row = await this.#db.q
370
+ .selectFrom('content_transfer_change as c')
371
+ .innerJoin('content_transfer_run as r', 'r.id', 'c.run_id')
372
+ .select(['r.id', 'r.change_kind', 'r.closed_at'])
373
+ .where('c.node_key', '=', normaliseUuid(pageKey))
374
+ .where('r.made_by', '=', normaliseUuid(madeBy))
375
+ .where('r.change_kind', 'in', ['edit', 'merge'])
376
+ .orderBy('r.started_at', 'desc')
377
+ .executeTakeFirst()
378
+ if (!row) return undefined
379
+ const id = String(row.id)
380
+ const merged = row.change_kind === 'merge'
381
+ if (!merged && row.closed_at === null) {
382
+ const closed = await this.#close(id, now)
383
+ return { id, ...closed, merged }
384
+ }
385
+ const run = await this.byId(id)
386
+ return run ? { id, key: run.key, name: run.name, merged } : undefined
387
+ }
388
+
389
+ /** Story 413: a page's schedule set by an approval, kept in the change that holds the page. */
390
+ async scheduleIn(changeId: string, pageKey: string, entries: readonly unknown[]): Promise<void> {
391
+ await this.#keepItem(changeId, `${SCHEDULE_PREFIX}${normaliseUuid(pageKey)}`, null, entries)
392
+ }
393
+
360
394
  /** Closes a person's open change (story 411): finished, to be passed on. */
361
395
  async closeOpen(
362
396
  madeBy: string,
@@ -3129,8 +3129,15 @@ export class DocumentRepository {
3129
3129
  const languages = await this.#languages()
3130
3130
  const workspace = this.#workspace ?? null
3131
3131
  await this.#db.transaction(async (tx) => {
3132
- // Story 414: the first time a workspace sets one, Shared's as it was then.
3133
- if (workspace !== null) {
3132
+ // Story 414: the first time a workspace sets one, Shared's as it was then; a publish
3133
+ // that names no time, and finds none to clear, sets none.
3134
+ const timed = entries.some((e) => e.publishTime !== null || e.unpublishTime !== null)
3135
+ const clears =
3136
+ !timed &&
3137
+ workspace !== null &&
3138
+ ((await scheduleEntriesOf(tx, node.id, workspace)).length > 0 ||
3139
+ (await scheduleEntriesOf(tx, node.id, null)).length > 0)
3140
+ if (workspace !== null && (timed || clears)) {
3134
3141
  const held = await tx.q
3135
3142
  .selectFrom('workspace_schedule')
3136
3143
  .select('node_id')
@@ -105,6 +105,7 @@ import { workspaceConflictsMigration } from './workspace-conflicts.ts'
105
105
  import { workspaceErrorsMigration } from './workspace-errors.ts'
106
106
  import { workspaceLinksMigration } from './workspace-links.ts'
107
107
  import { workspaceMergeMigration } from './workspace-merge.ts'
108
+ import { workspacePlacesMigration } from './workspace-places.ts'
108
109
  import { workspacePrivacyMigration } from './workspace-privacy.ts'
109
110
  import { workspaceProcessesMigration } from './workspace-processes.ts'
110
111
  import { workspaceSchedulesMigration } from './workspace-schedules.ts'
@@ -209,4 +210,5 @@ export const cromboloPlan = new MigrationPlan([
209
210
  groupStartKeysMigration,
210
211
  workspaceErrorsMigration,
211
212
  workspaceSchedulesMigration,
213
+ workspacePlacesMigration,
212
214
  ])
@@ -186,7 +186,8 @@ export const BUILT_IN_GROUPS = [
186
186
  name: 'Translators',
187
187
  icon: 'icon-globe',
188
188
  hasAccessToAllLanguages: true,
189
- sections: ['translation'],
189
+ // Story 419: Translation is a place under Content, which it needs too.
190
+ sections: ['content', 'translation'],
190
191
  },
191
192
  {
192
193
  id: 5,
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Migration 098 — Content is what a workspace holds (story 419). Library and
3
+ * Translation are places under Content, so a group holding either without Content
4
+ * gains Content, which opens nothing by itself; and languages are Translation's, so a
5
+ * group holding Structure without Translation gains Translation, keeping the
6
+ * languages it could change. Nobody loses anything they could open.
7
+ */
8
+ import type { Db } from '../database.ts'
9
+ import type { Migration } from '../migrations.ts'
10
+ import { STATE_WORKSPACE_SCHEDULES } from './workspace-schedules.ts'
11
+
12
+ export const STATE_WORKSPACE_PLACES = '{4e7a1c93-0098-4b6d-a2f5-7c1e9d3b0098}'
13
+
14
+ /** Each grant a group gains (`alias`) from one it holds (`from`). */
15
+ const GAINS: ReadonlyArray<{ alias: string; from: readonly string[] }> = [
16
+ { alias: 'content', from: ['library', 'translation'] },
17
+ { alias: 'translation', from: ['structure'] },
18
+ ]
19
+
20
+ export const workspacePlacesMigration: Migration = {
21
+ from: STATE_WORKSPACE_SCHEDULES,
22
+ to: STATE_WORKSPACE_PLACES,
23
+ name: 'AddWorkspacePlaces',
24
+ kind: 'expand',
25
+ release: '0.79.0',
26
+ async up(db: Db) {
27
+ for (const { alias, from } of GAINS)
28
+ await db.q
29
+ .insertInto('user_group_section')
30
+ .columns(['user_group_id', 'app_alias'])
31
+ .expression((eb) =>
32
+ eb
33
+ .selectFrom('user_group_section as held')
34
+ .select(['held.user_group_id', eb.val(alias).as('app_alias')])
35
+ .where('held.app_alias', 'in', [...from])
36
+ .where((w) =>
37
+ w.not(
38
+ w.exists(
39
+ w
40
+ .selectFrom('user_group_section as has')
41
+ .select('has.app_alias')
42
+ .whereRef('has.user_group_id', '=', 'held.user_group_id')
43
+ .where('has.app_alias', '=', alias),
44
+ ),
45
+ ),
46
+ )
47
+ .distinct(),
48
+ )
49
+ .execute()
50
+ },
51
+ }