asma-core-helpers 0.41.0 → 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/lib/collaboration/applyOperation.d.ts.map +1 -1
- package/lib/collaboration/applyOperation.js +108 -0
- package/lib/collaboration/applyOperation.js.map +1 -1
- package/lib/collaboration/index.d.ts +1 -0
- package/lib/collaboration/index.d.ts.map +1 -1
- package/lib/collaboration/index.js +1 -0
- package/lib/collaboration/index.js.map +1 -1
- package/lib/collaboration/narrativePresence.d.ts +12 -0
- package/lib/collaboration/narrativePresence.d.ts.map +1 -0
- package/lib/collaboration/narrativePresence.js +34 -0
- package/lib/collaboration/narrativePresence.js.map +1 -0
- package/lib/collaboration/operations.d.ts +26 -1
- package/lib/collaboration/operations.d.ts.map +1 -1
- package/lib/collaboration/operations.js +1 -0
- package/lib/collaboration/operations.js.map +1 -1
- package/lib/collaboration/schemas.d.ts +44 -1
- package/lib/collaboration/schemas.d.ts.map +1 -1
- package/lib/collaboration/schemas.js +18 -1
- package/lib/collaboration/schemas.js.map +1 -1
- package/lib/collaboration/templateAuthoringMeta.d.ts +4 -4
- package/lib/collaboration/templateAuthoringMeta.d.ts.map +1 -1
- package/lib/collaboration/templateAuthoringMeta.js +103 -5
- package/lib/collaboration/templateAuthoringMeta.js.map +1 -1
- package/lib/collaboration/templateDocument.d.ts +9 -2
- package/lib/collaboration/templateDocument.d.ts.map +1 -1
- package/lib/collaboration/templateDocument.js.map +1 -1
- package/lib/g-definitions.d.ts +5 -0
- package/lib/g-definitions.d.ts.map +1 -1
- package/lib/g-definitions.js +6 -0
- package/lib/g-definitions.js.map +1 -1
- package/lib/overlayBack.d.ts +103 -0
- package/lib/overlayBack.d.ts.map +1 -0
- package/lib/overlayBack.js +540 -0
- package/lib/overlayBack.js.map +1 -0
- package/package.json +2 -1
- package/src/collaboration/applyOperation.ts +114 -0
- package/src/collaboration/index.ts +1 -0
- package/src/collaboration/narrativePresence.test.ts +328 -0
- package/src/collaboration/narrativePresence.ts +42 -0
- package/src/collaboration/operations.ts +11 -0
- package/src/collaboration/schemas.ts +27 -2
- package/src/collaboration/templateAuthoringMeta.ts +107 -6
- package/src/collaboration/templateDocument.ts +14 -4
- package/src/g-definitions.ts +13 -0
- package/src/overlayBack.test.ts +742 -0
- package/src/overlayBack.ts +647 -0
|
@@ -937,12 +937,23 @@ const storedLeafValue = <T extends JsonValue>(path: string, value: T | null): Js
|
|
|
937
937
|
* The four typed arms report determinate intents. The two released open arms report `opaque` intents
|
|
938
938
|
* for every canonical locus their patch keys reach — by exact path, by ancestor, by descendant, and
|
|
939
939
|
* through the recognized alias table, because a patch that writes `settings.ask_for_phone_nr` is
|
|
940
|
-
* writing the phone requirement whatever it spells it.
|
|
941
|
-
*
|
|
942
|
-
* the
|
|
940
|
+
* writing the phone requirement whatever it spells it. The new narrative collection arm reports
|
|
941
|
+
* its marker/order/rule writes. All other non-metadata arms retain their released empty result;
|
|
942
|
+
* ownership dependencies are classified separately only when paired with the new arm.
|
|
943
943
|
*/
|
|
944
944
|
export const templateAuthoringIntentsOf = (op: TemplateOp): readonly TemplateAuthoringIntent[] => {
|
|
945
945
|
switch (op.type) {
|
|
946
|
+
case 'narrativeRuleCollection.edit': {
|
|
947
|
+
const intents: TemplateAuthoringIntent[] = [{
|
|
948
|
+
locus: narrativeLocus('narrativeRuleSettingsByQuestionId', op.questionId, 'conditionalPresence'),
|
|
949
|
+
kind: 'set', value: null,
|
|
950
|
+
}]
|
|
951
|
+
if (op.action.kind !== 'materialize') {
|
|
952
|
+
intents.push({ locus: narrativeLocus('narrativeRuleOrderByQuestionId', op.questionId), kind: 'opaque' },
|
|
953
|
+
{ locus: narrativeLocus('narrativeRulesById', op.action.ruleId), kind: 'opaque' })
|
|
954
|
+
}
|
|
955
|
+
return intents
|
|
956
|
+
}
|
|
946
957
|
case 'template.setMetaFieldTyped': {
|
|
947
958
|
const path = metaFieldPath(op.field)
|
|
948
959
|
return [{ locus: path, kind: 'set', value: storedLeafValue(path, op.value) }]
|
|
@@ -1025,12 +1036,72 @@ export type TemplateAuthoringOverlap =
|
|
|
1025
1036
|
| { status: 'convergent'; loci: readonly string[] }
|
|
1026
1037
|
| { status: 'conflict'; loci: readonly string[] }
|
|
1027
1038
|
|
|
1039
|
+
const narrativeLocus = (root: string, id: string, leaf?: string): string =>
|
|
1040
|
+
`${root}[${JSON.stringify(id)}]${leaf === undefined ? '' : `.${leaf}`}`
|
|
1041
|
+
|
|
1042
|
+
/** Ownership reads are dependencies, never fabricated opaque writes. Flags are preserved, not
|
|
1043
|
+
* collection preconditions. All-owner scans conservatively overlap released moving/deleting arms;
|
|
1044
|
+
* NEW arms cannot move IDs and their exact target/rule writes already cover new-vs-new overlap. */
|
|
1045
|
+
const narrativeReadLoci = (op: Extract<TemplateOp, { type: 'narrativeRuleCollection.edit' }>): string[] => {
|
|
1046
|
+
const reads = [narrativeLocus('questionsById', op.questionId), 'questionOrder',
|
|
1047
|
+
narrativeLocus('narrativeRuleSettingsByQuestionId', op.questionId, 'conditionalPresence'),
|
|
1048
|
+
narrativeLocus('narrativeRuleOrderByQuestionId', op.questionId)]
|
|
1049
|
+
if (op.action.kind !== 'materialize') {
|
|
1050
|
+
reads.push(narrativeLocus('narrativeRulesById', op.action.ruleId), 'narrativeRuleOrderByQuestionId')
|
|
1051
|
+
}
|
|
1052
|
+
if (op.action.kind === 'set') {
|
|
1053
|
+
const condition = op.action.condition
|
|
1054
|
+
reads.push(narrativeLocus('questionsById', condition.sourceQuestionId),
|
|
1055
|
+
narrativeLocus('alternativeOrderByQuestionId', condition.sourceQuestionId))
|
|
1056
|
+
for (const id of [...(condition.alternativeId === undefined ? [] : [condition.alternativeId]),
|
|
1057
|
+
...(condition.alternativeIds ?? [])]) {
|
|
1058
|
+
reads.push(narrativeLocus('alternativesById', id), 'alternativeOrderByQuestionId')
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
return reads
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
/** Used ONLY when paired with the NEW arm. Old-vs-old default[] and replay remain released.
|
|
1065
|
+
* A context-free classifier cannot know a grid deletion's descendants or a moved rule's old owner:
|
|
1066
|
+
* those actual write families conservatively cover their roots until row-lock revalidation. */
|
|
1067
|
+
const narrativeInterveningWrites = (op: TemplateOp): readonly TemplateAuthoringIntent[] => {
|
|
1068
|
+
const opaque = (...loci: string[]): TemplateAuthoringIntent[] => loci.map((locus) => ({ locus, kind: 'opaque' }))
|
|
1069
|
+
switch (op.type) {
|
|
1070
|
+
case 'narrativeRuleCollection.edit': return templateAuthoringIntentsOf(op)
|
|
1071
|
+
case 'narrativeRuleSettings.set':
|
|
1072
|
+
return [{ locus: narrativeLocus('narrativeRuleSettingsByQuestionId', op.questionId, op.field),
|
|
1073
|
+
kind: 'set', value: op.value ? true : null }]
|
|
1074
|
+
case 'narrativeRule.set':
|
|
1075
|
+
return opaque(narrativeLocus('narrativeRulesById', op.ruleId), 'narrativeRuleOrderByQuestionId')
|
|
1076
|
+
case 'narrativeRule.delete':
|
|
1077
|
+
return opaque(narrativeLocus('narrativeRulesById', op.ruleId), 'narrativeRuleOrderByQuestionId')
|
|
1078
|
+
case 'question.delete':
|
|
1079
|
+
return opaque('questionsById', 'questionOrder', 'narrativeRuleSettingsByQuestionId',
|
|
1080
|
+
'narrativeRulesById', 'narrativeRuleOrderByQuestionId', 'alternativesById', 'alternativeOrderByQuestionId')
|
|
1081
|
+
case 'question.create':
|
|
1082
|
+
return opaque(narrativeLocus('questionsById', op.questionId), 'questionOrder')
|
|
1083
|
+
case 'question.move': return opaque('questionOrder')
|
|
1084
|
+
case 'gridColumn.create':
|
|
1085
|
+
case 'gridColumn.move':
|
|
1086
|
+
// Structural ownership is read across all grids, not known from op.questionId alone.
|
|
1087
|
+
return opaque('questionsById', 'questionOrder')
|
|
1088
|
+
case 'question.updateField':
|
|
1089
|
+
return opaque(narrativeLocus('questionsById', op.questionId, op.field))
|
|
1090
|
+
case 'alternative.create':
|
|
1091
|
+
case 'alternative.move':
|
|
1092
|
+
case 'alternative.delete':
|
|
1093
|
+
return opaque(narrativeLocus('alternativesById', op.alternativeId), 'alternativeOrderByQuestionId')
|
|
1094
|
+
default: return templateAuthoringIntentsOf(op)
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1028
1098
|
export const classifyTemplateAuthoringOverlap = (
|
|
1029
1099
|
left: TemplateOp,
|
|
1030
1100
|
right: TemplateOp,
|
|
1031
1101
|
): TemplateAuthoringOverlap => {
|
|
1032
|
-
const
|
|
1033
|
-
const
|
|
1102
|
+
const hasNarrativeEdit = left.type === 'narrativeRuleCollection.edit' || right.type === 'narrativeRuleCollection.edit'
|
|
1103
|
+
const leftIntents = hasNarrativeEdit ? narrativeInterveningWrites(left) : templateAuthoringIntentsOf(left)
|
|
1104
|
+
const rightIntents = hasNarrativeEdit ? narrativeInterveningWrites(right) : templateAuthoringIntentsOf(right)
|
|
1034
1105
|
|
|
1035
1106
|
const overlapping = new Set<string>()
|
|
1036
1107
|
let converges = true
|
|
@@ -1044,6 +1115,23 @@ export const classifyTemplateAuthoringOverlap = (
|
|
|
1044
1115
|
}
|
|
1045
1116
|
}
|
|
1046
1117
|
|
|
1118
|
+
const checkReads = (reader: TemplateOp, writer: TemplateOp, writes: readonly TemplateAuthoringIntent[]): void => {
|
|
1119
|
+
if (reader.type !== 'narrativeRuleCollection.edit') return
|
|
1120
|
+
const reads = writer.type === 'narrativeRuleCollection.edit'
|
|
1121
|
+
? (reader.action.kind === 'materialize' ? [narrativeLocus('narrativeRuleOrderByQuestionId', reader.questionId)] : [])
|
|
1122
|
+
: narrativeReadLoci(reader)
|
|
1123
|
+
for (const read of reads) for (const write of writes) {
|
|
1124
|
+
// Ordinary title/value edits do not change identity or structural ownership.
|
|
1125
|
+
if (writer.type === 'question.updateField' &&
|
|
1126
|
+
!['type', 'grid', 'grid.columnIds'].some((field) => templateLociOverlap(field, writer.field))) continue
|
|
1127
|
+
if (!templateLociOverlap(read, write.locus)) continue
|
|
1128
|
+
overlapping.add(read)
|
|
1129
|
+
overlapping.add(write.locus)
|
|
1130
|
+
converges = false
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
checkReads(left, right, rightIntents)
|
|
1134
|
+
checkReads(right, left, leftIntents)
|
|
1047
1135
|
if (overlapping.size === 0) return { status: 'disjoint' }
|
|
1048
1136
|
const loci = [...overlapping].sort()
|
|
1049
1137
|
return converges ? { status: 'convergent', loci } : { status: 'conflict', loci }
|
|
@@ -1060,9 +1148,22 @@ export const classifyTemplateAuthoringOverlap = (
|
|
|
1060
1148
|
* A bracketed member locus answers membership: the id when the set contains it, `null` when not.
|
|
1061
1149
|
*/
|
|
1062
1150
|
export const readTemplateAuthoringLocus = (
|
|
1063
|
-
document: Pick<QnrTemplateDocument, 'meta'
|
|
1151
|
+
document: Pick<QnrTemplateDocument, 'meta'> & Partial<Pick<QnrTemplateDocument,
|
|
1152
|
+
'questionsById' | 'questionOrder' | 'narrativeRulesById' | 'narrativeRuleOrderByQuestionId' |
|
|
1153
|
+
'narrativeRuleSettingsByQuestionId' | 'alternativesById' | 'alternativeOrderByQuestionId'>>,
|
|
1064
1154
|
locus: string,
|
|
1065
1155
|
): JsonValue | null => {
|
|
1156
|
+
const narrative = /^(?<root>questionsById|narrativeRulesById|narrativeRuleOrderByQuestionId|narrativeRuleSettingsByQuestionId|alternativesById|alternativeOrderByQuestionId)\[(?<id>"(?:[^"\\]|\\.)*")\](?:\.(?<leaf>.*))?$/u.exec(locus)
|
|
1157
|
+
if (narrative?.groups !== undefined) {
|
|
1158
|
+
const id: unknown = JSON.parse(narrative.groups['id'] as string)
|
|
1159
|
+
const root = narrative.groups['root'] as keyof typeof document
|
|
1160
|
+
const collection = document[root]
|
|
1161
|
+
if (typeof id !== 'string' || collection === undefined || !Object.hasOwn(collection, id)) return null
|
|
1162
|
+
const entry = (collection as Record<string, unknown>)[id]
|
|
1163
|
+
if (narrative.groups['leaf'] === undefined) return entry as JsonValue
|
|
1164
|
+
const read = readOwnPath(entry, narrative.groups['leaf'])
|
|
1165
|
+
return read.status === 'present' ? read.value as JsonValue : null
|
|
1166
|
+
}
|
|
1066
1167
|
const member = /^(?<collection>meta\.compatibility\.[^.[]+)\[(?<id>.*)\]$/u.exec(locus)
|
|
1067
1168
|
if (member?.groups !== undefined) {
|
|
1068
1169
|
const parsedId: unknown = JSON.parse(member.groups['id'] as string)
|
|
@@ -551,10 +551,16 @@ export type HighlightRuleSettings = { enabled?: true; requiredAll?: true }
|
|
|
551
551
|
* `enabled` is legacy `have_narrative`; `requiredAll` is legacy `required_all`.
|
|
552
552
|
* False means absence of that member only. Disabling retains the rules and the other flag.
|
|
553
553
|
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
|
|
557
|
-
|
|
554
|
+
* Omitted `conditionalPresence` means ARRAY (including empty); `absent`/`null` are source-only
|
|
555
|
+
* states with no owned rules. NULL is a diagnostic draft state, never active-use admission.
|
|
556
|
+
* This source representation does not establish raw source provenance or consumer support.
|
|
557
|
+
*/
|
|
558
|
+
export type NarrativeConditionalPresence = 'array' | 'absent' | 'null'
|
|
559
|
+
export type NarrativeRuleSettings = {
|
|
560
|
+
enabled?: true
|
|
561
|
+
requiredAll?: true
|
|
562
|
+
conditionalPresence?: 'absent' | 'null'
|
|
563
|
+
}
|
|
558
564
|
export type RuleSettingField = 'enabled' | 'requiredAll'
|
|
559
565
|
export type NarrativeRule = { condition: RuleCondition; [key: string]: unknown }
|
|
560
566
|
export type QnrRule = {
|
|
@@ -914,6 +920,10 @@ export type QnrTemplateDocument = {
|
|
|
914
920
|
export type QnrQuestionBundle = {
|
|
915
921
|
rootQuestionId: QuestionId
|
|
916
922
|
questionsById: Record<QuestionId, QnrQuestion>
|
|
923
|
+
/** Representation only. Consumer-owned picks must qualify real target/source/rule ID remaps. */
|
|
924
|
+
narrativeRulesById?: Record<NarrativeRuleId, NarrativeRule>
|
|
925
|
+
narrativeRuleOrderByQuestionId?: Record<QuestionId, NarrativeRuleId[]>
|
|
926
|
+
narrativeRuleSettingsByQuestionId?: Record<QuestionId, NarrativeRuleSettings>
|
|
917
927
|
gridRowsById?: Record<RowId, QnrGridRow>
|
|
918
928
|
gridRowOrderByQuestionId?: Record<QuestionId, RowId[]>
|
|
919
929
|
alternativesById?: Record<AltId, QnrAlternative>
|
package/src/g-definitions.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { realWindow } from './helpers/getSubdomain.js'
|
|
|
9
9
|
import type { ICheckSigninOptions, ICheckSigninTransformedOptions } from './helpers/generateSrvAuthBindings.types.js'
|
|
10
10
|
import type { IBaseJwtClaims } from 'asma-types'
|
|
11
11
|
import type { ActivityStatus } from './helpers/getActivityStatus.js'
|
|
12
|
+
import { finishOverlayBackInstall, installOverlayBackPopstateListener } from './overlayBack.js'
|
|
13
|
+
import type { OverlayBackAdapter } from './overlayBack.js'
|
|
12
14
|
//import type { IGenerateSRVAuthBindings } from './helpers/generateSrvAuthBindings'
|
|
13
15
|
//import type { IGenerateSRVAuthBindings } from './helpers/generateSrvAuthBindings'
|
|
14
16
|
export {}
|
|
@@ -154,6 +156,10 @@ declare global {
|
|
|
154
156
|
* tab in the URL path (`createSectionPath`/`useSectionTab`). */
|
|
155
157
|
sectionRoutePaths?: boolean
|
|
156
158
|
}
|
|
159
|
+
/** Native Back closes the top ui-core overlay (ASMA-8470/8471/8472). `enabled` is the
|
|
160
|
+
* kill switch — stays `false` until a host opts in; ui-core runs registry-only until
|
|
161
|
+
* then. */
|
|
162
|
+
overlayBack?: OverlayBackAdapter
|
|
157
163
|
}
|
|
158
164
|
|
|
159
165
|
_env_cloud?: Record<'adopus' | 'adcuris', Record<string, string>>
|
|
@@ -206,11 +212,18 @@ function getHistory() {
|
|
|
206
212
|
return realWindow.__ASMA__SHELL__.history
|
|
207
213
|
}
|
|
208
214
|
|
|
215
|
+
// Must run before createBrowserHistory() so our popstate listener wins the registration-order
|
|
216
|
+
// race against history@5's own listener (CON-002).
|
|
217
|
+
const overlayBack = installOverlayBackPopstateListener(realWindow)
|
|
218
|
+
|
|
209
219
|
const history = createBrowserHistory()
|
|
210
220
|
|
|
221
|
+
finishOverlayBackInstall(realWindow, history)
|
|
222
|
+
|
|
211
223
|
realWindow.__ASMA__SHELL__ = {
|
|
212
224
|
...realWindow.__ASMA__SHELL__,
|
|
213
225
|
history,
|
|
226
|
+
overlayBack,
|
|
214
227
|
}
|
|
215
228
|
|
|
216
229
|
return history
|