@airalogy/aimd-recorder 1.17.0 → 1.18.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/README.md +11 -10
- package/README.zh-CN.md +11 -10
- package/dist/AimdCodeField-BQUuM-EF.js +182 -0
- package/dist/{AimdDnaSequenceField-D6ZgCDpp.js → AimdDnaSequenceField-KZU2Zj3E.js} +2 -2
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-B5Tq4zPV.js → AimdEditor.vue_vue_type_style_index_0_lang-CzfYPp5r.js} +3922 -3829
- package/dist/AimdMarkdownField-t2d8uOeU.js +254 -0
- package/dist/AimdMarkdownNoteField-_h1oZSwH.js +259 -0
- package/dist/{_commonjsHelpers-CZXJ37nu.js → _commonjsHelpers-B5RozER-.js} +2 -2
- package/dist/aimd-recorder.css +1 -1
- package/dist/arc-DS_ocYoe.js +83 -0
- package/dist/architectureDiagram-3BPJPVTR-Dq2W8_tb.js +4692 -0
- package/dist/blockDiagram-GPEHLZMM-B4hnSAF_.js +2425 -0
- package/dist/c4Diagram-AAUBKEIU-CbffqNLY.js +1577 -0
- package/dist/channel-CtXnYrAk.js +5 -0
- package/dist/chunk-2J33WTMH-CROScrt5.js +19 -0
- package/dist/chunk-4BX2VUAB-DTmsQu5_.js +8 -0
- package/dist/chunk-55IACEB6-B5wDJzeX.js +8 -0
- package/dist/chunk-727SXJPM-CfyltY6o.js +1528 -0
- package/dist/chunk-AQP2D5EJ-B8274EYy.js +1387 -0
- package/dist/chunk-FMBD7UC4-CT_FK-SH.js +19 -0
- package/dist/chunk-ND2GUHAM-g9GulPi-.js +68 -0
- package/dist/chunk-QZHKN3VN-Di5HEktz.js +15 -0
- package/dist/classDiagram-4FO5ZUOK-BVUr246k.js +16 -0
- package/dist/classDiagram-v2-Q7XG4LA2-BVUr246k.js +16 -0
- package/dist/components.js +3279 -2216
- package/dist/composables.js +92 -68
- package/dist/cose-bilkent-S5V4N54A-GJ4IOO6v.js +2609 -0
- package/dist/cytoscape.esm-r59gEWFs.js +18710 -0
- package/dist/dagre-BM42HDAG-oL7Br44o.js +445 -0
- package/dist/defaultLocale-BgPVtth8.js +171 -0
- package/dist/diagram-2AECGRRQ-DtoCG_N4.js +217 -0
- package/dist/diagram-5GNKFQAL-f8QNdS7L.js +123 -0
- package/dist/diagram-KO2AKTUF-CsJOW_AX.js +461 -0
- package/dist/diagram-LMA3HP47-xmEKNZ7y.js +142 -0
- package/dist/diagram-OG6HWLK6-unpC7vo8.js +528 -0
- package/dist/erDiagram-TEJ5UH35-BGzFnCJD.js +899 -0
- package/dist/flowDiagram-I6XJVG4X-LBFhDnOs.js +1628 -0
- package/dist/ganttDiagram-6RSMTGT7-CFBc-jPD.js +2707 -0
- package/dist/gitGraphDiagram-PVQCEYII-BLduh-Rb.js +815 -0
- package/dist/graph-DdlKE625.js +1510 -0
- package/dist/index.js +104 -80
- package/dist/infoDiagram-5YYISTIA-CLQQI6zM.js +24 -0
- package/dist/init-DjUOC4st.js +16 -0
- package/dist/ishikawaDiagram-YF4QCWOH-CStdYBmW.js +621 -0
- package/dist/journeyDiagram-JHISSGLW-B6mRTzoE.js +834 -0
- package/dist/kanban-definition-UN3LZRKU-C-vnN5v4.js +724 -0
- package/dist/katex-DNob3HGn.js +11690 -0
- package/dist/layout-DDt0fz-M.js +1703 -0
- package/dist/linear-C-IAFdOt.js +259 -0
- package/dist/mermaid.core-CuZ3nINf.js +15940 -0
- package/dist/mindmap-definition-RKZ34NQL-TSZ1Vb3z.js +827 -0
- package/dist/ordinal-B6-f3MAq.js +61 -0
- package/dist/pieDiagram-4H26LBE5-DYok-1-k.js +163 -0
- package/dist/quadrantDiagram-W4KKPZXB-Cg856sbH.js +1024 -0
- package/dist/requirementDiagram-4Y6WPE33-BN9fGdlJ.js +882 -0
- package/dist/sankeyDiagram-5OEKKPKP-CDqTgonY.js +847 -0
- package/dist/sequenceDiagram-3UESZ5HK-Chjrc0-W.js +2891 -0
- package/dist/stateDiagram-AJRCARHV-DRyLHrdr.js +263 -0
- package/dist/stateDiagram-v2-BHNVJYJU-CZTIDHid.js +16 -0
- package/dist/timeline-definition-PNZ67QCA-Bc3D9AAG.js +1055 -0
- package/dist/{useFieldRendering-xLajJhyA.js → useCodeBlockRendering-qA6gj4vz.js} +3035 -2254
- package/dist/useMonacoAutoHeight-D4T-El3J.js +66 -0
- package/dist/vennDiagram-CIIHVFJN-CYAul48m.js +1557 -0
- package/dist/wardley-L42UT6IY-D7b2ujEZ.js +22512 -0
- package/dist/wardleyDiagram-YWT4CUSO-B7Tg0MG9.js +675 -0
- package/dist/xychartDiagram-2RQKCTM6-xWYVEqth.js +1342 -0
- package/package.json +9 -8
- package/src/__tests__/assigner-runner-dependent-data.test.ts +32 -0
- package/src/__tests__/markdown-field.test.ts +150 -1
- package/src/__tests__/markdown-note-field.test.ts +86 -3
- package/src/__tests__/recorder-assigner-control.test.ts +844 -0
- package/src/__tests__/recorder-editor.test.ts +17 -0
- package/src/__tests__/recorder-markdown-assigner-integration.test.ts +49 -0
- package/src/__tests__/step-field.test.ts +47 -1
- package/src/__tests__/type-plugins.test.ts +1 -0
- package/src/__tests__/var-field-render.test.ts +741 -1
- package/src/components/AimdCodeField.vue +24 -5
- package/src/components/AimdMarkdownField.vue +548 -11
- package/src/components/AimdMarkdownNoteField.vue +241 -30
- package/src/components/AimdRecorder.vue +1521 -95
- package/src/components/AimdRecorderEditor.vue +276 -8
- package/src/components/AimdRecorderWysiwygFieldHost.vue +6 -0
- package/src/components/AimdRecorderWysiwygSurface.vue +32 -0
- package/src/components/AimdStepCheckField.vue +82 -18
- package/src/components/AimdVarField.vue +694 -25
- package/src/components/AimdVarTableField.vue +283 -110
- package/src/components/icons/AimdAssignerCalculatorIcon.vue +18 -0
- package/src/components/icons/AimdAssignerCloudStatusIcon.vue +22 -0
- package/src/components/recorderMilkdownPlugin.ts +14 -0
- package/src/composables/__tests__/useRecordState.test.ts +86 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +133 -0
- package/src/composables/index.ts +27 -1
- package/src/composables/useAssignerRunner.ts +376 -0
- package/src/composables/useCodeBlockRendering.ts +51 -0
- package/src/composables/useFieldRendering.ts +32 -4
- package/src/composables/useMonacoAutoHeight.ts +127 -0
- package/src/composables/useRecordState.ts +22 -3
- package/src/composables/useVarHelpers.ts +377 -9
- package/src/index.ts +13 -0
- package/src/locales.ts +45 -0
- package/src/styles/aimd.css +151 -1
- package/src/type-plugins.ts +7 -0
- package/src/types.ts +93 -2
- package/dist/AimdCodeField-DC3DPvgc.js +0 -172
- package/dist/AimdMarkdownField-BJ20QtO8.js +0 -67
- package/dist/AimdMarkdownNoteField-DwAQhoyk.js +0 -186
|
@@ -647,6 +647,92 @@ describe('ensureDefaultsFromFields', () => {
|
|
|
647
647
|
expect(record.quiz.q1).toBe('')
|
|
648
648
|
})
|
|
649
649
|
|
|
650
|
+
it('adds missing var table defaults from extracted AIMD fields', () => {
|
|
651
|
+
const record = createEmptyProtocolRecordData()
|
|
652
|
+
const fields = {
|
|
653
|
+
step: [],
|
|
654
|
+
check: [],
|
|
655
|
+
quiz: [],
|
|
656
|
+
var: [],
|
|
657
|
+
subvar: [],
|
|
658
|
+
assigner: [],
|
|
659
|
+
ref: [],
|
|
660
|
+
fig: [],
|
|
661
|
+
cite: [],
|
|
662
|
+
var_table: [{
|
|
663
|
+
id: 'monitoring_sites',
|
|
664
|
+
scope: 'var_table',
|
|
665
|
+
subvars: [{ id: 'site_id' }, { id: 'elevation_m' }],
|
|
666
|
+
default: [
|
|
667
|
+
{ site_id: 'S01', elevation_m: 128 },
|
|
668
|
+
{ site_id: 'S02', elevation_m: 82 },
|
|
669
|
+
],
|
|
670
|
+
}],
|
|
671
|
+
}
|
|
672
|
+
const changed = ensureDefaultsFromFields(record, fields as any)
|
|
673
|
+
expect(changed).toBe(true)
|
|
674
|
+
expect(record.var.monitoring_sites).toEqual([
|
|
675
|
+
{ site_id: 'S01', elevation_m: '128' },
|
|
676
|
+
{ site_id: 'S02', elevation_m: '82' },
|
|
677
|
+
])
|
|
678
|
+
})
|
|
679
|
+
|
|
680
|
+
it('replaces a generated empty var table placeholder with extracted defaults', () => {
|
|
681
|
+
const record = createEmptyProtocolRecordData()
|
|
682
|
+
record.var.monitoring_sites = [{ site_id: '', elevation_m: '' }]
|
|
683
|
+
const fields = {
|
|
684
|
+
step: [],
|
|
685
|
+
check: [],
|
|
686
|
+
quiz: [],
|
|
687
|
+
var: [],
|
|
688
|
+
subvar: [],
|
|
689
|
+
assigner: [],
|
|
690
|
+
ref: [],
|
|
691
|
+
fig: [],
|
|
692
|
+
cite: [],
|
|
693
|
+
var_table: [{
|
|
694
|
+
id: 'monitoring_sites',
|
|
695
|
+
scope: 'var_table',
|
|
696
|
+
subvars: [{ id: 'site_id' }, { id: 'elevation_m' }],
|
|
697
|
+
default: [
|
|
698
|
+
{ site_id: 'S01', elevation_m: 128 },
|
|
699
|
+
{ site_id: 'S02', elevation_m: 82 },
|
|
700
|
+
],
|
|
701
|
+
}],
|
|
702
|
+
}
|
|
703
|
+
const changed = ensureDefaultsFromFields(record, fields as any)
|
|
704
|
+
expect(changed).toBe(true)
|
|
705
|
+
expect(record.var.monitoring_sites).toEqual([
|
|
706
|
+
{ site_id: 'S01', elevation_m: '128' },
|
|
707
|
+
{ site_id: 'S02', elevation_m: '82' },
|
|
708
|
+
])
|
|
709
|
+
})
|
|
710
|
+
|
|
711
|
+
it('does not overwrite existing var table rows with extracted defaults', () => {
|
|
712
|
+
const record = createEmptyProtocolRecordData()
|
|
713
|
+
record.var.monitoring_sites = [{ site_id: 'USER', elevation_m: '10' }]
|
|
714
|
+
const fields = {
|
|
715
|
+
step: [],
|
|
716
|
+
check: [],
|
|
717
|
+
quiz: [],
|
|
718
|
+
var: [],
|
|
719
|
+
subvar: [],
|
|
720
|
+
assigner: [],
|
|
721
|
+
ref: [],
|
|
722
|
+
fig: [],
|
|
723
|
+
cite: [],
|
|
724
|
+
var_table: [{
|
|
725
|
+
id: 'monitoring_sites',
|
|
726
|
+
scope: 'var_table',
|
|
727
|
+
subvars: [{ id: 'site_id' }, { id: 'elevation_m' }],
|
|
728
|
+
default: [{ site_id: 'S01', elevation_m: 128 }],
|
|
729
|
+
}],
|
|
730
|
+
}
|
|
731
|
+
const changed = ensureDefaultsFromFields(record, fields as any)
|
|
732
|
+
expect(changed).toBe(false)
|
|
733
|
+
expect(record.var.monitoring_sites).toEqual([{ site_id: 'USER', elevation_m: '10' }])
|
|
734
|
+
})
|
|
735
|
+
|
|
650
736
|
it('returns false when nothing changes', () => {
|
|
651
737
|
const record = createEmptyProtocolRecordData()
|
|
652
738
|
const fields = { step: [], check: [], quiz: [], var: [], var_table: [], subvar: [], assigner: [], ref: [], fig: [], cite: [] }
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
formatDateTimeWithTimezone,
|
|
10
10
|
normalizeDateTimeValueWithTimezone,
|
|
11
11
|
formatDateForInput,
|
|
12
|
+
getFileDisplayName,
|
|
13
|
+
getFileInputConfig,
|
|
12
14
|
getVarInputDisplayValue,
|
|
13
15
|
parseVarInputValue,
|
|
14
16
|
getNumericConstraintViolation,
|
|
@@ -16,6 +18,8 @@ import {
|
|
|
16
18
|
getNumericInputAttributes,
|
|
17
19
|
calculateVarStackWidth,
|
|
18
20
|
syncAutoWrapTextareaHeight,
|
|
21
|
+
measureVarLabelWidth,
|
|
22
|
+
createSelectedFileValue,
|
|
19
23
|
} from '../useVarHelpers'
|
|
20
24
|
|
|
21
25
|
// ---------------------------------------------------------------------------
|
|
@@ -111,6 +115,74 @@ describe('getVarInputKind', () => {
|
|
|
111
115
|
expect(getVarInputKind('str', { inputType: 'yaml' })).toBe('code')
|
|
112
116
|
expect(getVarInputKind('str', { codeLanguage: 'sql' })).toBe('code')
|
|
113
117
|
})
|
|
118
|
+
|
|
119
|
+
it('returns "file" for file-like AIMD types and metadata overrides', () => {
|
|
120
|
+
expect(getVarInputKind('FileIdCSV')).toBe('file')
|
|
121
|
+
expect(getVarInputKind('csv')).toBe('file')
|
|
122
|
+
expect(getVarInputKind('FileIdPNG')).toBe('file')
|
|
123
|
+
expect(getVarInputKind('image')).toBe('file')
|
|
124
|
+
expect(getVarInputKind('str', { inputType: 'audio' })).toBe('file')
|
|
125
|
+
expect(getVarInputKind('str', { kwargs: { file_extension: 'xlsx' } })).toBe('file')
|
|
126
|
+
expect(getVarInputKind('str', { fieldMeta: { accept: '.pdf' } })).toBe('file')
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
// File-like vars
|
|
132
|
+
// ---------------------------------------------------------------------------
|
|
133
|
+
|
|
134
|
+
describe('file-like var helpers', () => {
|
|
135
|
+
it('resolves accept strings and display badges for built-in file aliases', () => {
|
|
136
|
+
expect(getFileInputConfig('FileIdCSV')).toMatchObject({
|
|
137
|
+
kind: 'csv',
|
|
138
|
+
accept: '.csv,text/csv',
|
|
139
|
+
badge: 'CSV',
|
|
140
|
+
})
|
|
141
|
+
expect(getFileInputConfig('FileIdPNG')).toMatchObject({
|
|
142
|
+
kind: 'image',
|
|
143
|
+
accept: '.png,image/png',
|
|
144
|
+
badge: 'IMG',
|
|
145
|
+
})
|
|
146
|
+
expect(getFileInputConfig('str', undefined, { inputType: 'image' })).toMatchObject({
|
|
147
|
+
kind: 'image',
|
|
148
|
+
accept: 'image/*',
|
|
149
|
+
badge: 'IMG',
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('honors explicit accept and file extension metadata', () => {
|
|
154
|
+
expect(getFileInputConfig('str', { file_extension: 'xlsx' })).toMatchObject({
|
|
155
|
+
kind: 'document',
|
|
156
|
+
accept: '.xlsx,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
157
|
+
badge: 'DOC',
|
|
158
|
+
})
|
|
159
|
+
expect(getFileInputConfig('FileIdCSV', undefined, { accept: '.tsv,text/tab-separated-values' })).toMatchObject({
|
|
160
|
+
kind: 'csv',
|
|
161
|
+
accept: '.tsv,text/tab-separated-values',
|
|
162
|
+
badge: 'CSV',
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
it('extracts display names from file ids and structured file values', () => {
|
|
167
|
+
expect(getFileDisplayName('file-123')).toBe('file-123')
|
|
168
|
+
expect(getFileDisplayName({ name: 'dose.csv' })).toBe('dose.csv')
|
|
169
|
+
expect(getFileDisplayName({ value: { file_name: 'chart.svg' } })).toBe('chart.svg')
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
it('creates serializable selected-file metadata when no host upload handler is provided', () => {
|
|
173
|
+
const file = new File(['a,b\n1,2'], 'dose.csv', {
|
|
174
|
+
type: 'text/csv',
|
|
175
|
+
lastModified: 123,
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
expect(createSelectedFileValue(file)).toEqual({
|
|
179
|
+
format: 'airalogy_selected_file_v1',
|
|
180
|
+
name: 'dose.csv',
|
|
181
|
+
type: 'text/csv',
|
|
182
|
+
size: 7,
|
|
183
|
+
lastModified: 123,
|
|
184
|
+
})
|
|
185
|
+
})
|
|
114
186
|
})
|
|
115
187
|
|
|
116
188
|
// ---------------------------------------------------------------------------
|
|
@@ -414,6 +486,67 @@ describe('calculateVarStackWidth', () => {
|
|
|
414
486
|
})
|
|
415
487
|
})
|
|
416
488
|
|
|
489
|
+
// ---------------------------------------------------------------------------
|
|
490
|
+
// measureVarLabelWidth
|
|
491
|
+
// ---------------------------------------------------------------------------
|
|
492
|
+
|
|
493
|
+
describe('measureVarLabelWidth', () => {
|
|
494
|
+
afterEach(() => {
|
|
495
|
+
vi.restoreAllMocks()
|
|
496
|
+
document.body.innerHTML = ''
|
|
497
|
+
})
|
|
498
|
+
|
|
499
|
+
it('measures visible label tokens without letting metadata popovers expand the field', () => {
|
|
500
|
+
vi.spyOn(HTMLCanvasElement.prototype, 'getContext').mockImplementation(() => ({
|
|
501
|
+
measureText: (text: string) => ({ width: text.length * 8 }),
|
|
502
|
+
} as unknown as CanvasRenderingContext2D))
|
|
503
|
+
vi.spyOn(window, 'getComputedStyle').mockImplementation((element: Element) => {
|
|
504
|
+
const classList = (element as HTMLElement).classList
|
|
505
|
+
const horizontalPadding = classList.contains('aimd-field__name')
|
|
506
|
+
? '16px'
|
|
507
|
+
: classList.contains('aimd-field__scope--var')
|
|
508
|
+
? '14px'
|
|
509
|
+
: '0px'
|
|
510
|
+
return {
|
|
511
|
+
fontSize: '14px',
|
|
512
|
+
fontFamily: 'sans-serif',
|
|
513
|
+
fontWeight: '500',
|
|
514
|
+
fontStyle: 'normal',
|
|
515
|
+
paddingLeft: horizontalPadding,
|
|
516
|
+
paddingRight: '0px',
|
|
517
|
+
borderLeftWidth: '0px',
|
|
518
|
+
borderRightWidth: '0px',
|
|
519
|
+
marginLeft: '0px',
|
|
520
|
+
marginRight: '0px',
|
|
521
|
+
} as CSSStyleDeclaration
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
const wrapper = document.createElement('span')
|
|
525
|
+
wrapper.className = 'aimd-rec-inline--var-stacked'
|
|
526
|
+
wrapper.innerHTML = `
|
|
527
|
+
<span class="aimd-field__label">
|
|
528
|
+
<span class="aimd-field__scope aimd-field__scope--var">var</span>
|
|
529
|
+
<span class="aimd-field__name aimd-field__metadata-host">
|
|
530
|
+
<span class="aimd-field__title">Sample Name</span>
|
|
531
|
+
<span class="aimd-field__key">sample_name</span>
|
|
532
|
+
<span class="aimd-field__metadata-popover">Human-readable label used throughout this protocol</span>
|
|
533
|
+
</span>
|
|
534
|
+
</span>
|
|
535
|
+
`
|
|
536
|
+
Object.defineProperty(wrapper.querySelector('.aimd-field__label'), 'scrollWidth', {
|
|
537
|
+
configurable: true,
|
|
538
|
+
get: () => 720,
|
|
539
|
+
})
|
|
540
|
+
Object.defineProperty(wrapper.querySelector('.aimd-field__metadata-popover'), 'scrollWidth', {
|
|
541
|
+
configurable: true,
|
|
542
|
+
get: () => 680,
|
|
543
|
+
})
|
|
544
|
+
document.body.appendChild(wrapper)
|
|
545
|
+
|
|
546
|
+
expect(measureVarLabelWidth(wrapper)).toBeLessThan(240)
|
|
547
|
+
})
|
|
548
|
+
})
|
|
549
|
+
|
|
417
550
|
// ---------------------------------------------------------------------------
|
|
418
551
|
// syncAutoWrapTextareaHeight
|
|
419
552
|
// ---------------------------------------------------------------------------
|
package/src/composables/index.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { captureFocusSnapshot, restoreFocusSnapshot } from './useFocusManagement'
|
|
2
2
|
export type { FocusSnapshot } from './useFocusManagement'
|
|
3
|
+
export { createChainedElementRenderer, useCodeBlockRendering } from './useCodeBlockRendering'
|
|
4
|
+
export { createMonacoAutoHeight, estimateMonacoVisualLineCount } from './useMonacoAutoHeight'
|
|
5
|
+
export type { MonacoAutoHeightController, MonacoAutoHeightEditor, MonacoAutoHeightOptions } from './useMonacoAutoHeight'
|
|
3
6
|
|
|
4
7
|
export {
|
|
5
8
|
cloneRecordData,
|
|
@@ -47,6 +50,12 @@ export {
|
|
|
47
50
|
formatDateTimeWithTimezone,
|
|
48
51
|
normalizeDateTimeValueWithTimezone,
|
|
49
52
|
formatDateForInput,
|
|
53
|
+
getFileDisplayName,
|
|
54
|
+
getFileInputConfig,
|
|
55
|
+
isFileLikeVarType,
|
|
56
|
+
createSelectedFileValue,
|
|
57
|
+
getVarEnumSelectValue,
|
|
58
|
+
getVarEnumValueFromSelectValue,
|
|
50
59
|
getVarInputDisplayValue,
|
|
51
60
|
parseVarInputValue,
|
|
52
61
|
calculateVarStackWidth,
|
|
@@ -55,7 +64,7 @@ export {
|
|
|
55
64
|
syncAutoWrapTextareaHeight,
|
|
56
65
|
applyVarStackWidth,
|
|
57
66
|
} from './useVarHelpers'
|
|
58
|
-
export type { VarInputKind } from './useVarHelpers'
|
|
67
|
+
export type { AimdVarEnumOption, FileInputConfig, FileInputDisplayKind, VarInputKind } from './useVarHelpers'
|
|
59
68
|
|
|
60
69
|
export {
|
|
61
70
|
AIMD_DNA_SEQUENCE_FORMAT,
|
|
@@ -77,6 +86,23 @@ export {
|
|
|
77
86
|
export { useClientAssignerRunner } from './useClientAssignerRunner'
|
|
78
87
|
export type { ClientAssignerRunnerOptions } from './useClientAssignerRunner'
|
|
79
88
|
|
|
89
|
+
export {
|
|
90
|
+
applyAimdAssignedFieldsToRecord,
|
|
91
|
+
buildAimdAssignerDependentData,
|
|
92
|
+
extractAimdAssignedFields,
|
|
93
|
+
getAimdAssignerDependentFields,
|
|
94
|
+
getAimdAssignerFieldKey,
|
|
95
|
+
getAimdAssignerFieldNameSets,
|
|
96
|
+
getAimdAssignerMode,
|
|
97
|
+
getAimdAssignerPayloadFieldKey,
|
|
98
|
+
isReadonlyAimdAssignerMode,
|
|
99
|
+
normalizeAimdAssignerDependentData,
|
|
100
|
+
normalizeAimdAssignerDependentValue,
|
|
101
|
+
normalizeAimdAssignerMode,
|
|
102
|
+
resolveAimdAssigners,
|
|
103
|
+
} from './useAssignerRunner'
|
|
104
|
+
export type { AimdResolvedAssigner } from './useAssignerRunner'
|
|
105
|
+
|
|
80
106
|
export {
|
|
81
107
|
useVarTableDragDrop,
|
|
82
108
|
getVarTableRowKey,
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import type { ExtractedAimdFields } from "@airalogy/aimd-core/types"
|
|
2
|
+
import type {
|
|
3
|
+
AimdAssignerDefinition,
|
|
4
|
+
AimdAssignerMap,
|
|
5
|
+
AimdAssignerMode,
|
|
6
|
+
AimdProtocolRecordData,
|
|
7
|
+
AimdRecorderFieldType,
|
|
8
|
+
} from "../types"
|
|
9
|
+
import {
|
|
10
|
+
normalizeCheckLike,
|
|
11
|
+
normalizeStepLike,
|
|
12
|
+
} from "./useRecordState"
|
|
13
|
+
import { getFileValueId, isAiralogyFileId } from "./useVarHelpers"
|
|
14
|
+
|
|
15
|
+
export interface AimdResolvedAssigner {
|
|
16
|
+
assignedField: string
|
|
17
|
+
fieldKey: string
|
|
18
|
+
mode: string
|
|
19
|
+
dependentFields: string[]
|
|
20
|
+
assigner: AimdAssignerDefinition
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type AssignableRecorderFieldType = Exclude<AimdRecorderFieldType, "quiz">
|
|
24
|
+
|
|
25
|
+
interface AssignerFieldNameSets {
|
|
26
|
+
var?: ReadonlySet<string>
|
|
27
|
+
varTable?: ReadonlySet<string>
|
|
28
|
+
step?: ReadonlySet<string>
|
|
29
|
+
check?: ReadonlySet<string>
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function isObjectRecord(value: unknown): value is Record<string, unknown> {
|
|
33
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isEmptyObjectRecord(value: unknown): boolean {
|
|
37
|
+
return isObjectRecord(value) && Object.keys(value).length === 0
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getStringProperty(record: Record<string, unknown>, keys: string[]): string | undefined {
|
|
41
|
+
for (const key of keys) {
|
|
42
|
+
const value = record[key]
|
|
43
|
+
if (typeof value === "string" && value.trim()) {
|
|
44
|
+
return value.trim()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return undefined
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getNestedErrorMessage(value: unknown): string | undefined {
|
|
51
|
+
if (typeof value === "string" && value.trim()) {
|
|
52
|
+
return value.trim()
|
|
53
|
+
}
|
|
54
|
+
if (!isObjectRecord(value)) {
|
|
55
|
+
return undefined
|
|
56
|
+
}
|
|
57
|
+
return getStringProperty(value, [
|
|
58
|
+
"error_message",
|
|
59
|
+
"errorMessage",
|
|
60
|
+
"message",
|
|
61
|
+
"detail",
|
|
62
|
+
"reason",
|
|
63
|
+
])
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function collectAssignerResultCandidates(result: unknown): unknown[] {
|
|
67
|
+
const candidates: unknown[] = [result]
|
|
68
|
+
const appendNested = (value: unknown) => {
|
|
69
|
+
if (!isObjectRecord(value)) return
|
|
70
|
+
candidates.push(value.data)
|
|
71
|
+
candidates.push(value.result)
|
|
72
|
+
if (isObjectRecord(value.data)) {
|
|
73
|
+
candidates.push(value.data.result)
|
|
74
|
+
}
|
|
75
|
+
if (isObjectRecord(value.result)) {
|
|
76
|
+
candidates.push(value.result.data)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
appendNested(result)
|
|
81
|
+
if (isObjectRecord(result)) {
|
|
82
|
+
appendNested(result.data)
|
|
83
|
+
appendNested(result.result)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return candidates
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function parsedFieldName(value: unknown): string {
|
|
90
|
+
if (typeof value === "string" && value.trim()) return value.trim()
|
|
91
|
+
if (!isObjectRecord(value)) return ""
|
|
92
|
+
|
|
93
|
+
const name = value.name ?? value.id
|
|
94
|
+
return typeof name === "string" && name.trim() ? name.trim() : ""
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function extractedFieldNameSet(value: unknown): Set<string> {
|
|
98
|
+
if (!Array.isArray(value)) return new Set<string>()
|
|
99
|
+
return new Set(value.map(parsedFieldName).filter(Boolean))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function getAimdAssignerDependentFields(assigner: unknown): string[] {
|
|
103
|
+
if (!isObjectRecord(assigner)) return []
|
|
104
|
+
const fields = assigner.dependent_fields
|
|
105
|
+
if (!Array.isArray(fields)) return []
|
|
106
|
+
return fields
|
|
107
|
+
.map(field => (typeof field === "string" ? field.trim() : ""))
|
|
108
|
+
.filter(Boolean)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function getAimdAssignerAssignedFields(assigner: unknown): string[] {
|
|
112
|
+
if (!isObjectRecord(assigner)) return []
|
|
113
|
+
const fields = Array.isArray(assigner.assigned_fields)
|
|
114
|
+
? assigner.assigned_fields
|
|
115
|
+
: Array.isArray(assigner.assignedFields)
|
|
116
|
+
? assigner.assignedFields
|
|
117
|
+
: []
|
|
118
|
+
return fields
|
|
119
|
+
.map(field => (typeof field === "string" ? field.trim() : ""))
|
|
120
|
+
.filter(Boolean)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function getAimdAssignerMode(assigner: unknown): string {
|
|
124
|
+
if (!isObjectRecord(assigner)) return "manual"
|
|
125
|
+
const mode = assigner.mode
|
|
126
|
+
return typeof mode === "string" && mode.trim() ? mode.trim() : "manual"
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function normalizeAimdAssignerMode(mode: string): AimdAssignerMode {
|
|
130
|
+
if (
|
|
131
|
+
mode === "auto"
|
|
132
|
+
|| mode === "auto_first"
|
|
133
|
+
|| mode === "auto_force"
|
|
134
|
+
|| mode === "manual"
|
|
135
|
+
|| mode === "manual_readonly"
|
|
136
|
+
|| mode === "auto_readonly"
|
|
137
|
+
) {
|
|
138
|
+
return mode
|
|
139
|
+
}
|
|
140
|
+
return "manual"
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function isReadonlyAimdAssignerMode(mode: string): boolean {
|
|
144
|
+
return mode === "auto_readonly" || mode === "manual_readonly"
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function getAimdAssignerFieldNameSets(fields?: Partial<ExtractedAimdFields> | null): AssignerFieldNameSets {
|
|
148
|
+
return {
|
|
149
|
+
var: extractedFieldNameSet(fields?.var),
|
|
150
|
+
varTable: extractedFieldNameSet(fields?.var_table),
|
|
151
|
+
step: extractedFieldNameSet(fields?.step),
|
|
152
|
+
check: extractedFieldNameSet(fields?.check),
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export function getAimdAssignerFieldKey(
|
|
157
|
+
assignedField: string,
|
|
158
|
+
fieldNameSets: AssignerFieldNameSets = {},
|
|
159
|
+
): string {
|
|
160
|
+
const normalized = assignedField.trim()
|
|
161
|
+
if (normalized.includes(".")) {
|
|
162
|
+
const [tableName, ...columnParts] = normalized.split(".")
|
|
163
|
+
return `var_table:${tableName}:${columnParts.join(".")}`
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (fieldNameSets.varTable?.has(normalized)) return `var_table:${normalized}`
|
|
167
|
+
if (fieldNameSets.step?.has(normalized)) return `step:${normalized}`
|
|
168
|
+
if (fieldNameSets.check?.has(normalized)) return `check:${normalized}`
|
|
169
|
+
return `var:${normalized}`
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function resolveAimdAssigners(
|
|
173
|
+
assigners: AimdAssignerMap | undefined,
|
|
174
|
+
fields?: Partial<ExtractedAimdFields> | null,
|
|
175
|
+
): AimdResolvedAssigner[] {
|
|
176
|
+
if (!assigners || typeof assigners !== "object" || Array.isArray(assigners)) {
|
|
177
|
+
return []
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const fieldNameSets = getAimdAssignerFieldNameSets(fields)
|
|
181
|
+
return Object.entries(assigners)
|
|
182
|
+
.flatMap(([assignedField, assigner]) => {
|
|
183
|
+
const normalizedEntryField = assignedField.trim()
|
|
184
|
+
if (!normalizedEntryField) return []
|
|
185
|
+
const definition = isObjectRecord(assigner) ? assigner : {}
|
|
186
|
+
const mode = getAimdAssignerMode(definition)
|
|
187
|
+
const dependentFields = getAimdAssignerDependentFields(definition)
|
|
188
|
+
const assignedFields = new Set([
|
|
189
|
+
normalizedEntryField,
|
|
190
|
+
...getAimdAssignerAssignedFields(definition),
|
|
191
|
+
])
|
|
192
|
+
return [...assignedFields].map((normalizedAssignedField) => ({
|
|
193
|
+
assignedField: normalizedAssignedField,
|
|
194
|
+
fieldKey: getAimdAssignerFieldKey(normalizedAssignedField, fieldNameSets),
|
|
195
|
+
mode,
|
|
196
|
+
dependentFields,
|
|
197
|
+
assigner: definition,
|
|
198
|
+
} satisfies AimdResolvedAssigner))
|
|
199
|
+
})
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export function normalizeAimdAssignerDependentValue(value: unknown): unknown {
|
|
203
|
+
if (value === "") return undefined
|
|
204
|
+
|
|
205
|
+
if (Array.isArray(value)) {
|
|
206
|
+
const normalizedItems = value
|
|
207
|
+
.map(item => normalizeAimdAssignerDependentValue(item))
|
|
208
|
+
.filter(item => item !== undefined && !isEmptyObjectRecord(item))
|
|
209
|
+
return normalizedItems
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (isObjectRecord(value)) {
|
|
213
|
+
const fileId = getFileValueId(value)
|
|
214
|
+
if (isAiralogyFileId(fileId)) {
|
|
215
|
+
return fileId
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const normalizedObject = Object.fromEntries(
|
|
219
|
+
Object.entries(value)
|
|
220
|
+
.map(([key, item]) => [key, normalizeAimdAssignerDependentValue(item)] as const)
|
|
221
|
+
.filter(([, item]) => item !== undefined),
|
|
222
|
+
)
|
|
223
|
+
return normalizedObject
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
return value
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export function normalizeAimdAssignerDependentData(value: unknown): Record<string, unknown> {
|
|
230
|
+
const normalized = normalizeAimdAssignerDependentValue(value)
|
|
231
|
+
return isObjectRecord(normalized) ? normalized : {}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function readRecordFieldValue(record: AimdProtocolRecordData, field: string): unknown {
|
|
235
|
+
if (Object.prototype.hasOwnProperty.call(record.var, field)) return record.var[field]
|
|
236
|
+
if (Object.prototype.hasOwnProperty.call(record.step, field)) return record.step[field]
|
|
237
|
+
if (Object.prototype.hasOwnProperty.call(record.check, field)) return record.check[field]
|
|
238
|
+
if (Object.prototype.hasOwnProperty.call(record.quiz, field)) return record.quiz[field]
|
|
239
|
+
|
|
240
|
+
if (field.includes(".")) {
|
|
241
|
+
const [tableName, ...columnParts] = field.split(".")
|
|
242
|
+
const columnName = columnParts.join(".")
|
|
243
|
+
const tableValue = record.var[tableName]
|
|
244
|
+
if (Array.isArray(tableValue) && columnName) {
|
|
245
|
+
return tableValue.map((row) => (isObjectRecord(row) ? row[columnName] : undefined))
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return undefined
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export function buildAimdAssignerDependentData(
|
|
253
|
+
record: AimdProtocolRecordData,
|
|
254
|
+
assigner: Pick<AimdResolvedAssigner, "dependentFields"> | AimdAssignerDefinition | unknown,
|
|
255
|
+
): Record<string, unknown> {
|
|
256
|
+
const dependentFields = Array.isArray((assigner as { dependentFields?: unknown } | null)?.dependentFields)
|
|
257
|
+
? (assigner as { dependentFields: string[] }).dependentFields
|
|
258
|
+
: getAimdAssignerDependentFields(assigner)
|
|
259
|
+
|
|
260
|
+
if (dependentFields.length === 0) {
|
|
261
|
+
return normalizeAimdAssignerDependentData(record.var)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return Object.fromEntries(
|
|
265
|
+
dependentFields
|
|
266
|
+
.map((field) => [field, normalizeAimdAssignerDependentValue(readRecordFieldValue(record, field))] as const)
|
|
267
|
+
.filter(([, value]) => value !== undefined),
|
|
268
|
+
)
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
export function extractAimdAssignedFields(result: unknown): Record<string, unknown> {
|
|
272
|
+
const candidates = collectAssignerResultCandidates(result)
|
|
273
|
+
|
|
274
|
+
for (const candidate of candidates) {
|
|
275
|
+
if (!isObjectRecord(candidate)) continue
|
|
276
|
+
const snakeCase = candidate.assigned_fields
|
|
277
|
+
if (isObjectRecord(snakeCase)) return snakeCase
|
|
278
|
+
const camelCase = candidate.assignedFields
|
|
279
|
+
if (isObjectRecord(camelCase)) return camelCase
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return {}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export function extractAimdAssignerErrorMessage(result: unknown): string | undefined {
|
|
286
|
+
const candidates = collectAssignerResultCandidates(result)
|
|
287
|
+
|
|
288
|
+
for (const candidate of candidates) {
|
|
289
|
+
if (!isObjectRecord(candidate)) continue
|
|
290
|
+
|
|
291
|
+
const success = candidate.success
|
|
292
|
+
const status = candidate.status
|
|
293
|
+
const failed = success === false
|
|
294
|
+
|| success === "false"
|
|
295
|
+
|| status === "error"
|
|
296
|
+
|| status === "failed"
|
|
297
|
+
|
|
298
|
+
if (!failed) {
|
|
299
|
+
continue
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
return getStringProperty(candidate, [
|
|
303
|
+
"error_message",
|
|
304
|
+
"errorMessage",
|
|
305
|
+
"message",
|
|
306
|
+
"detail",
|
|
307
|
+
"reason",
|
|
308
|
+
"output",
|
|
309
|
+
])
|
|
310
|
+
?? getNestedErrorMessage(candidate.error)
|
|
311
|
+
?? getNestedErrorMessage(candidate.exception)
|
|
312
|
+
?? "Assigner failed"
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return undefined
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export function applyAimdAssignedFieldsToRecord(
|
|
319
|
+
record: AimdProtocolRecordData,
|
|
320
|
+
assignedFields: Record<string, unknown>,
|
|
321
|
+
): boolean {
|
|
322
|
+
let changed = false
|
|
323
|
+
|
|
324
|
+
for (const [field, value] of Object.entries(assignedFields)) {
|
|
325
|
+
const normalizedField = field.trim()
|
|
326
|
+
if (!normalizedField) continue
|
|
327
|
+
|
|
328
|
+
if (normalizedField.includes(".")) {
|
|
329
|
+
const [tableName, ...columnParts] = normalizedField.split(".")
|
|
330
|
+
const columnName = columnParts.join(".")
|
|
331
|
+
const tableValue = record.var[tableName]
|
|
332
|
+
if (Array.isArray(tableValue) && columnName) {
|
|
333
|
+
if (Array.isArray(value)) {
|
|
334
|
+
tableValue.forEach((row, index) => {
|
|
335
|
+
if (isObjectRecord(row) && index < value.length) {
|
|
336
|
+
row[columnName] = value[index]
|
|
337
|
+
}
|
|
338
|
+
})
|
|
339
|
+
} else {
|
|
340
|
+
tableValue.forEach((row) => {
|
|
341
|
+
if (isObjectRecord(row)) {
|
|
342
|
+
row[columnName] = value
|
|
343
|
+
}
|
|
344
|
+
})
|
|
345
|
+
}
|
|
346
|
+
changed = true
|
|
347
|
+
continue
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (Object.prototype.hasOwnProperty.call(record.step, normalizedField)) {
|
|
352
|
+
record.step[normalizedField] = normalizeStepLike(value)
|
|
353
|
+
changed = true
|
|
354
|
+
continue
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (Object.prototype.hasOwnProperty.call(record.check, normalizedField)) {
|
|
358
|
+
record.check[normalizedField] = normalizeCheckLike(value)
|
|
359
|
+
changed = true
|
|
360
|
+
continue
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
record.var[normalizedField] = value
|
|
364
|
+
changed = true
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return changed
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
export function getAimdAssignerPayloadFieldKey(
|
|
371
|
+
fieldType: AssignableRecorderFieldType,
|
|
372
|
+
fieldKey: string,
|
|
373
|
+
): string {
|
|
374
|
+
const prefix = `${fieldType}:`
|
|
375
|
+
return fieldKey.startsWith(prefix) ? fieldKey.slice(prefix.length) : fieldKey
|
|
376
|
+
}
|