@crombolo/data 0.74.1 → 0.75.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 +2 -2
- package/src/index.ts +1 -0
- package/src/repositories/users.ts +51 -2
- package/src/schema/group-start-keys.ts +25 -0
- package/src/schema/plan.ts +2 -0
- package/src/tables.gen.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/data",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.75.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.
|
|
32
|
+
"@crombolo/core": "0.75.0",
|
|
33
33
|
"kysely": "0.29.6"
|
|
34
34
|
}
|
|
35
35
|
}
|
package/src/index.ts
CHANGED
|
@@ -112,6 +112,7 @@ export * from './schema/form-library-types.ts'
|
|
|
112
112
|
export * from './schema/form-permission-prefix.ts'
|
|
113
113
|
export * from './schema/form-workflow-secrets.ts'
|
|
114
114
|
export * from './schema/group-permissions.ts'
|
|
115
|
+
export * from './schema/group-start-keys.ts'
|
|
115
116
|
export * from './schema/identity.ts'
|
|
116
117
|
export * from './schema/image-alt-text.ts'
|
|
117
118
|
export * from './schema/jobs.ts'
|
|
@@ -24,6 +24,8 @@ export interface StartNodeSelection {
|
|
|
24
24
|
export interface GroupStartNode {
|
|
25
25
|
root: boolean
|
|
26
26
|
key: string | null
|
|
27
|
+
/** Story 405: held by key, its item not on this site yet, so it gives no start here. */
|
|
28
|
+
waiting?: boolean
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
export interface UserRecord {
|
|
@@ -96,6 +98,8 @@ export interface UserGroupInput {
|
|
|
96
98
|
startNodes: Record<StartNodeTree, GroupStartNode>
|
|
97
99
|
permissions: string[]
|
|
98
100
|
granular: GranularPermission[]
|
|
101
|
+
/** Story 405: a start node whose item is not here is kept by key, to apply when it arrives. */
|
|
102
|
+
holdStartNodes?: boolean
|
|
99
103
|
}
|
|
100
104
|
|
|
101
105
|
/** A group as a site's files declare it (story 228). */
|
|
@@ -710,6 +714,9 @@ const GROUP_COLUMNS = [
|
|
|
710
714
|
'start_content_id',
|
|
711
715
|
'start_media_id',
|
|
712
716
|
'start_element_id',
|
|
717
|
+
'start_content_key',
|
|
718
|
+
'start_media_key',
|
|
719
|
+
'start_element_key',
|
|
713
720
|
] as const
|
|
714
721
|
|
|
715
722
|
const GROUP_START_COLUMN: Record<StartNodeTree, string> = {
|
|
@@ -718,6 +725,13 @@ const GROUP_START_COLUMN: Record<StartNodeTree, string> = {
|
|
|
718
725
|
element: 'start_element_id',
|
|
719
726
|
}
|
|
720
727
|
|
|
728
|
+
/** Story 405: where a start node is held by key while its item is not here. */
|
|
729
|
+
const GROUP_START_KEY_COLUMN: Record<StartNodeTree, string> = {
|
|
730
|
+
document: 'start_content_key',
|
|
731
|
+
media: 'start_media_key',
|
|
732
|
+
element: 'start_element_key',
|
|
733
|
+
}
|
|
734
|
+
|
|
721
735
|
const groups = (db: Db) => db.q.selectFrom('user_group').select(GROUP_COLUMNS)
|
|
722
736
|
|
|
723
737
|
export class UserGroupRepository {
|
|
@@ -772,12 +786,37 @@ export class UserGroupRepository {
|
|
|
772
786
|
.where('id', 'in', positive)
|
|
773
787
|
.execute())
|
|
774
788
|
nodes.set(Number(row.id), normaliseUuid(String(row.unique_id)))
|
|
789
|
+
// Story 405: held start nodes, and which of them have arrived since.
|
|
790
|
+
const heldKeys = [
|
|
791
|
+
...new Set(
|
|
792
|
+
rows.flatMap((r) =>
|
|
793
|
+
TREES.flatMap((tree) => {
|
|
794
|
+
const held = r[GROUP_START_KEY_COLUMN[tree] as keyof typeof r]
|
|
795
|
+
return typeof held === 'string' && held ? [normaliseUuid(held)] : []
|
|
796
|
+
}),
|
|
797
|
+
),
|
|
798
|
+
),
|
|
799
|
+
]
|
|
800
|
+
const arrived = new Set<string>()
|
|
801
|
+
if (heldKeys.length > 0)
|
|
802
|
+
for (const row of await this.#db.q
|
|
803
|
+
.selectFrom('node')
|
|
804
|
+
.select('unique_id')
|
|
805
|
+
.where('unique_id', 'in', heldKeys)
|
|
806
|
+
.where('workspace_id', 'is', null)
|
|
807
|
+
.execute())
|
|
808
|
+
arrived.add(normaliseUuid(String(row.unique_id)))
|
|
775
809
|
|
|
776
810
|
return rows.map((row) => {
|
|
777
811
|
const id = Number(row.id)
|
|
778
812
|
const key = normaliseUuid(String(row.key))
|
|
779
813
|
const start = (tree: StartNodeTree): GroupStartNode => {
|
|
780
814
|
const value = row[GROUP_START_COLUMN[tree]]
|
|
815
|
+
const held = row[GROUP_START_KEY_COLUMN[tree] as keyof typeof row]
|
|
816
|
+
if ((value === null || value === undefined) && typeof held === 'string' && held) {
|
|
817
|
+
const key = normaliseUuid(held)
|
|
818
|
+
return { root: false, key, ...(arrived.has(key) ? {} : { waiting: true }) }
|
|
819
|
+
}
|
|
781
820
|
if (value === null || value === undefined) return { root: false, key: null }
|
|
782
821
|
const nodeId = Number(value)
|
|
783
822
|
if (nodeId === ROOT_ID) return { root: true, key: null }
|
|
@@ -893,13 +932,20 @@ export class UserGroupRepository {
|
|
|
893
932
|
media: null,
|
|
894
933
|
element: null,
|
|
895
934
|
}
|
|
935
|
+
const held: Record<StartNodeTree, string | null> = {
|
|
936
|
+
document: null,
|
|
937
|
+
media: null,
|
|
938
|
+
element: null,
|
|
939
|
+
}
|
|
896
940
|
for (const tree of TREES) {
|
|
897
941
|
const start = input.startNodes[tree]
|
|
898
942
|
if (start.root) starts[tree] = ROOT_ID
|
|
899
943
|
else if (start.key) {
|
|
900
944
|
const ids = await users.nodeIds([start.key])
|
|
901
|
-
|
|
902
|
-
|
|
945
|
+
// Story 405: one not here yet is held by key, giving no start until it arrives.
|
|
946
|
+
if (!ids && input.holdStartNodes) held[tree] = normaliseUuid(start.key)
|
|
947
|
+
else if (!ids) return { missingNode: tree }
|
|
948
|
+
else starts[tree] = ids.get(normaliseUuid(start.key)) ?? null
|
|
903
949
|
}
|
|
904
950
|
}
|
|
905
951
|
const languageIds: number[] = []
|
|
@@ -925,6 +971,9 @@ export class UserGroupRepository {
|
|
|
925
971
|
start_content_id: starts.document,
|
|
926
972
|
start_media_id: starts.media,
|
|
927
973
|
start_element_id: starts.element,
|
|
974
|
+
start_content_key: held.document,
|
|
975
|
+
start_media_key: held.media,
|
|
976
|
+
start_element_key: held.element,
|
|
928
977
|
}
|
|
929
978
|
const existing = await new UserGroupRepository(tx).byKey(key)
|
|
930
979
|
if (existing)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration 095 — a group's start node kept by key while its item is not on this site
|
|
3
|
+
* (story 405): a group defined outside the site names its start nodes by key, and one
|
|
4
|
+
* whose item has not arrived yet waits here, giving no start in that tree until it does.
|
|
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_CHANGE_SOURCES } from './change-sources.ts'
|
|
10
|
+
|
|
11
|
+
export const STATE_GROUP_START_KEYS = '{7e4c1a83-0095-4d9f-a031-5c8f1e6d0095}'
|
|
12
|
+
|
|
13
|
+
export const groupStartKeysMigration: Migration = {
|
|
14
|
+
from: STATE_CHANGE_SOURCES,
|
|
15
|
+
to: STATE_GROUP_START_KEYS,
|
|
16
|
+
name: 'AddGroupStartKeys',
|
|
17
|
+
kind: 'expand',
|
|
18
|
+
release: '0.75.0',
|
|
19
|
+
async up(db: Db) {
|
|
20
|
+
const ops = schemaOps(db)
|
|
21
|
+
const text = db.dialect.types.varchar(36)
|
|
22
|
+
for (const column of ['start_content_key', 'start_media_key', 'start_element_key'])
|
|
23
|
+
await ops.addColumn('user_group', column, text)
|
|
24
|
+
},
|
|
25
|
+
}
|
package/src/schema/plan.ts
CHANGED
|
@@ -57,6 +57,7 @@ import { formWorkflowSecretsMigration } from './form-workflow-secrets.ts'
|
|
|
57
57
|
import { formWorkflowsMigration } from './form-workflows.ts'
|
|
58
58
|
import { formsMigration } from './forms.ts'
|
|
59
59
|
import { groupPermissionsMigration } from './group-permissions.ts'
|
|
60
|
+
import { groupStartKeysMigration } from './group-start-keys.ts'
|
|
60
61
|
import { identityMigration } from './identity.ts'
|
|
61
62
|
import { imageAltTextMigration } from './image-alt-text.ts'
|
|
62
63
|
import { jobsMigration } from './jobs.ts'
|
|
@@ -203,4 +204,5 @@ export const cromboloPlan = new MigrationPlan([
|
|
|
203
204
|
workspaceProcessesMigration,
|
|
204
205
|
workspaceConflictsMigration,
|
|
205
206
|
changeSourcesMigration,
|
|
207
|
+
groupStartKeysMigration,
|
|
206
208
|
])
|
package/src/tables.gen.ts
CHANGED
|
@@ -932,8 +932,11 @@ export interface CoreTables {
|
|
|
932
932
|
key: string
|
|
933
933
|
name: string
|
|
934
934
|
start_content_id: number | null
|
|
935
|
+
start_content_key: string | null
|
|
935
936
|
start_element_id: number | null
|
|
937
|
+
start_element_key: string | null
|
|
936
938
|
start_media_id: number | null
|
|
939
|
+
start_media_key: string | null
|
|
937
940
|
update_date: Timestamp
|
|
938
941
|
}
|
|
939
942
|
user_group_granular_permission: {
|