@airalogy/aimd-recorder 1.24.5 → 1.25.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 +13 -1
- package/README.zh-CN.md +13 -1
- package/dist/{AimdDnaSequenceField-CxFtD5Au.js → AimdDnaSequenceField-BHV1_c2o.js} +1 -1
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-B0n0inzY.js → AimdEditor.vue_vue_type_style_index_0_lang-phvUVTHV.js} +643 -605
- package/dist/AimdEntityRefField-COzwbHwr.js +4 -0
- package/dist/{AimdEntityRefField-DCE79vca.js → AimdEntityRefField.vue_vue_type_script_setup_true_lang-BIvUuZFV.js} +2 -2
- package/dist/{AimdMarkdownField-Du0Fh5sG.js → AimdMarkdownField-t8hqazDv.js} +3 -3
- package/dist/{AimdMarkdownNoteField-YnyNmBvM.js → AimdMarkdownNoteField-BGjkSXEY.js} +2 -2
- package/dist/AimdResourceRefField-BBaRSLcL.js +264 -0
- package/dist/aimd-recorder.css +1 -1
- package/dist/{arc-B0vwJ3nm.js → arc-CsBMJYPv.js} +1 -1
- package/dist/{architectureDiagram-3BPJPVTR-B5niz6cr.js → architectureDiagram-3BPJPVTR-BeKUSqHO.js} +2 -2
- package/dist/{blockDiagram-GPEHLZMM-Qtk9HFm8.js → blockDiagram-GPEHLZMM-CJeAC_1p.js} +4 -4
- package/dist/{c4Diagram-AAUBKEIU-DfTlAW2e.js → c4Diagram-AAUBKEIU-LoQMp4kW.js} +2 -2
- package/dist/{channel-CTIJccfL.js → channel-BoLQO6Dk.js} +1 -1
- package/dist/{chunk-2J33WTMH-9xMy_Pgx.js → chunk-2J33WTMH-D1vw38h5.js} +1 -1
- package/dist/{chunk-4BX2VUAB-BYosfXC9.js → chunk-4BX2VUAB-BFSVnsyi.js} +1 -1
- package/dist/{chunk-55IACEB6-B8fHTImy.js → chunk-55IACEB6-D13UaCP1.js} +1 -1
- package/dist/{chunk-727SXJPM-C83DIicG.js → chunk-727SXJPM-BCcz4POX.js} +5 -5
- package/dist/{chunk-AQP2D5EJ-C-IOiRzH.js → chunk-AQP2D5EJ-DTOfpg2m.js} +3 -3
- package/dist/{chunk-FMBD7UC4-BtkEX_DM.js → chunk-FMBD7UC4-XGRN-sFg.js} +1 -1
- package/dist/{chunk-ND2GUHAM-DIB3ib7j.js → chunk-ND2GUHAM-DSgp1I9F.js} +1 -1
- package/dist/{chunk-QZHKN3VN-BRsoqg2B.js → chunk-QZHKN3VN-DQl3-kKo.js} +1 -1
- package/dist/{classDiagram-v2-Q7XG4LA2-D39GKFwR.js → classDiagram-4FO5ZUOK-CI-4bhme.js} +2 -2
- package/dist/{classDiagram-4FO5ZUOK-D39GKFwR.js → classDiagram-v2-Q7XG4LA2-CI-4bhme.js} +2 -2
- package/dist/components.js +2222 -2110
- package/dist/composables.js +2 -2
- package/dist/{cose-bilkent-S5V4N54A-CyRaJD1S.js → cose-bilkent-S5V4N54A-CU1K-fx3.js} +1 -1
- package/dist/{dagre-BM42HDAG-K85xJEFU.js → dagre-BM42HDAG-HIHsvvPF.js} +3 -3
- package/dist/{diagram-2AECGRRQ-DET7fuM5.js → diagram-2AECGRRQ-XlYRVMia.js} +2 -2
- package/dist/{diagram-5GNKFQAL-Dlba-FRw.js → diagram-5GNKFQAL-BeA9dVE2.js} +3 -3
- package/dist/{diagram-KO2AKTUF-J4PMcx3F.js → diagram-KO2AKTUF-D501LuyG.js} +2 -2
- package/dist/{diagram-LMA3HP47-ldR5Az83.js → diagram-LMA3HP47-ClkmdOf_.js} +2 -2
- package/dist/{diagram-OG6HWLK6-UM1_l5na.js → diagram-OG6HWLK6-30O5epks.js} +3 -3
- package/dist/{erDiagram-TEJ5UH35-eGmNSbi1.js → erDiagram-TEJ5UH35-Dk5azNFu.js} +4 -4
- package/dist/{flowDiagram-I6XJVG4X-rHTJn3LZ.js → flowDiagram-I6XJVG4X-C4K9bB2d.js} +6 -6
- package/dist/{ganttDiagram-6RSMTGT7-DKmi_hWM.js → ganttDiagram-6RSMTGT7-sFuSkRH3.js} +2 -2
- package/dist/{gitGraphDiagram-PVQCEYII-DpQ1cu5h.js → gitGraphDiagram-PVQCEYII-CC4Kf_0S.js} +3 -3
- package/dist/{graph-CSRKgcbg.js → graph-BBr12s4M.js} +1 -1
- package/dist/index.js +124 -122
- package/dist/{infoDiagram-5YYISTIA-v8jIxUL5.js → infoDiagram-5YYISTIA-PObcwLKW.js} +1 -1
- package/dist/{ishikawaDiagram-YF4QCWOH-BaV5bCe8.js → ishikawaDiagram-YF4QCWOH-B93dpm60.js} +1 -1
- package/dist/{journeyDiagram-JHISSGLW-DeU65SpU.js → journeyDiagram-JHISSGLW-Z0_jIQ5z.js} +4 -4
- package/dist/{kanban-definition-UN3LZRKU-TGHAcp6_.js → kanban-definition-UN3LZRKU-BicW7pfZ.js} +2 -2
- package/dist/{layout-D_sj0Eed.js → layout-jm5q2dTB.js} +2 -2
- package/dist/{linear-TldV7C5w.js → linear-Bv4EbUf4.js} +1 -1
- package/dist/{mermaid.core-CRSTqrrD.js → mermaid.core-BN0BM26i.js} +34 -34
- package/dist/{mindmap-definition-RKZ34NQL-CejyEBat.js → mindmap-definition-RKZ34NQL-Ba85mo62.js} +3 -3
- package/dist/{pieDiagram-4H26LBE5-CWLZWcAW.js → pieDiagram-4H26LBE5-CfU3ahlI.js} +3 -3
- package/dist/{quadrantDiagram-W4KKPZXB-CYidUieH.js → quadrantDiagram-W4KKPZXB-BPTjR1PA.js} +2 -2
- package/dist/record.js +2 -2
- package/dist/{requirementDiagram-4Y6WPE33-Cw4ko-tB.js → requirementDiagram-4Y6WPE33-DVfyUAUL.js} +3 -3
- package/dist/{sankeyDiagram-5OEKKPKP-BnX4Evuh.js → sankeyDiagram-5OEKKPKP-B_9c0VJt.js} +1 -1
- package/dist/{sequenceDiagram-3UESZ5HK-BiGVMmS5.js → sequenceDiagram-3UESZ5HK-BFSDCMig.js} +3 -3
- package/dist/{stateDiagram-AJRCARHV-DIaBI1Uq.js → stateDiagram-AJRCARHV-DNCya3UT.js} +4 -4
- package/dist/{stateDiagram-v2-BHNVJYJU-BgfV-ldT.js → stateDiagram-v2-BHNVJYJU-BlmsFnk2.js} +2 -2
- package/dist/{timeline-definition-PNZ67QCA-C0_5OwxD.js → timeline-definition-PNZ67QCA-B297WQKg.js} +2 -2
- package/dist/{useFieldRendering-B2iMfsEA.js → useFieldRendering-DQN_MbSg.js} +1 -1
- package/dist/{useVarHelpers-CSogsd1T.js → useVarHelpers-D00Za8e6.js} +975 -934
- package/dist/validation-Dn_j1py1.js +5712 -0
- package/dist/{vennDiagram-CIIHVFJN-_ktbUOEm.js → vennDiagram-CIIHVFJN-gDmDgx6K.js} +1 -1
- package/dist/{wardleyDiagram-YWT4CUSO-iwftOr4-.js → wardleyDiagram-YWT4CUSO-ek5B-FUl.js} +2 -2
- package/dist/{xychartDiagram-2RQKCTM6-C_h9QW07.js → xychartDiagram-2RQKCTM6-DRtlxacH.js} +2 -2
- package/package.json +3 -3
- package/src/__tests__/record-validation.test.ts +121 -0
- package/src/__tests__/required-marker.test.ts +4 -0
- package/src/__tests__/resource-form.test.ts +20 -0
- package/src/__tests__/resource-ref-field.test.ts +125 -0
- package/src/__tests__/var-field-render.test.ts +39 -1
- package/src/components/AimdRecorder.vue +11 -1
- package/src/components/AimdRecorderEditor.vue +5 -0
- package/src/components/AimdRecorderWysiwygFieldHost.vue +1 -0
- package/src/components/AimdRecorderWysiwygSurface.vue +5 -0
- package/src/components/AimdResourceForm.vue +129 -0
- package/src/components/AimdResourceRefField.vue +393 -0
- package/src/components/AimdVarField.vue +39 -2
- package/src/components/index.ts +4 -0
- package/src/components/recorderMilkdownPlugin.ts +2 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +53 -4
- package/src/composables/useVarHelpers.ts +82 -3
- package/src/index.ts +12 -1
- package/src/locales.ts +57 -0
- package/src/record/validation.ts +145 -11
- package/src/styles/recorder.css +7 -0
- package/src/types.ts +30 -1
- package/dist/validation-BYjlufCM.js +0 -5629
|
@@ -76,6 +76,13 @@ export interface EntityRefTypeConfig {
|
|
|
76
76
|
source?: string
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
+
export interface ResourceRefTypeConfig extends EntityRefTypeConfig {
|
|
80
|
+
role: "input" | "output" | "reference" | "equipment"
|
|
81
|
+
quantityField?: string
|
|
82
|
+
containerRequired: boolean
|
|
83
|
+
bookingRequired: boolean
|
|
84
|
+
}
|
|
85
|
+
|
|
79
86
|
export function getFileInputConfig(
|
|
80
87
|
type: string | undefined,
|
|
81
88
|
kwargs?: Record<string, unknown>,
|
|
@@ -199,6 +206,10 @@ function resolveOverrideInputKind(inputType: string | undefined, codeLanguage: s
|
|
|
199
206
|
return 'entity-ref'
|
|
200
207
|
}
|
|
201
208
|
|
|
209
|
+
if (normalized === 'resourceref' || normalized === 'resource-ref') {
|
|
210
|
+
return 'resource-ref'
|
|
211
|
+
}
|
|
212
|
+
|
|
202
213
|
if (normalized === 'dna') {
|
|
203
214
|
return 'dna'
|
|
204
215
|
}
|
|
@@ -374,11 +385,73 @@ function getEntityFromEntityRefExpression(type: string | undefined): string | un
|
|
|
374
385
|
return match ? stripTypeArgumentQuotes(match[1]) : undefined
|
|
375
386
|
}
|
|
376
387
|
|
|
388
|
+
function getEntityFromResourceRefExpression(type: string | undefined): string | undefined {
|
|
389
|
+
const normalized = canonicalizeTypeExpression(type).replace(/^typing\./, "")
|
|
390
|
+
const match = normalized.match(/^(?:airalogy\.types\.)?resourceref(?:\[(.*)\])?$/)
|
|
391
|
+
return match ? stripTypeArgumentQuotes(match[1]) : undefined
|
|
392
|
+
}
|
|
393
|
+
|
|
377
394
|
function isEntityRefExpression(type: string | undefined): boolean {
|
|
378
395
|
const normalized = canonicalizeTypeExpression(type).replace(/^typing\./, "")
|
|
379
396
|
return /^(?:airalogy\.types\.)?entityref(?:\[.*\])?$/.test(normalized)
|
|
380
397
|
}
|
|
381
398
|
|
|
399
|
+
function isResourceRefExpression(type: string | undefined): boolean {
|
|
400
|
+
const normalized = canonicalizeTypeExpression(type).replace(/^typing\./, "")
|
|
401
|
+
return /^(?:airalogy\.types\.)?resourceref(?:\[.*\])?$/.test(normalized)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
export function getResourceRefTypeConfig(
|
|
405
|
+
type: string | undefined,
|
|
406
|
+
kwargs?: Record<string, unknown>,
|
|
407
|
+
fieldMeta?: AimdFieldMeta,
|
|
408
|
+
): ResourceRefTypeConfig | undefined {
|
|
409
|
+
const unwrapped = unwrapOptionalTypeAnnotation(type)
|
|
410
|
+
const compact = canonicalizeTypeExpression(unwrapped).replace(/^typing\./, "")
|
|
411
|
+
let multiple = false
|
|
412
|
+
let expressionEntity = getEntityFromResourceRefExpression(unwrapped)
|
|
413
|
+
let resourceRef = isResourceRefExpression(unwrapped)
|
|
414
|
+
const listMatch = compact.match(/^(?:list|array)\[(.*)\]$/)
|
|
415
|
+
if (listMatch) {
|
|
416
|
+
multiple = true
|
|
417
|
+
expressionEntity = getEntityFromResourceRefExpression(listMatch[1])
|
|
418
|
+
resourceRef = isResourceRefExpression(listMatch[1])
|
|
419
|
+
}
|
|
420
|
+
else if (compact.endsWith("[]")) {
|
|
421
|
+
multiple = true
|
|
422
|
+
const itemType = compact.slice(0, -2)
|
|
423
|
+
expressionEntity = getEntityFromResourceRefExpression(itemType)
|
|
424
|
+
resourceRef = isResourceRefExpression(itemType)
|
|
425
|
+
}
|
|
426
|
+
if (!resourceRef) return undefined
|
|
427
|
+
|
|
428
|
+
const roleValue = fieldMeta?.resource_role ?? kwargs?.resource_role
|
|
429
|
+
const role = ["input", "output", "reference", "equipment"].includes(String(roleValue))
|
|
430
|
+
? roleValue as ResourceRefTypeConfig["role"]
|
|
431
|
+
: "reference"
|
|
432
|
+
return {
|
|
433
|
+
multiple,
|
|
434
|
+
entity: normalizeEntityRefMetadataString(fieldMeta?.entity)
|
|
435
|
+
?? normalizeEntityRefMetadataString(kwargs?.entity)
|
|
436
|
+
?? expressionEntity,
|
|
437
|
+
source: normalizeEntityRefMetadataString(fieldMeta?.source)
|
|
438
|
+
?? normalizeEntityRefMetadataString(kwargs?.source),
|
|
439
|
+
role,
|
|
440
|
+
quantityField: normalizeEntityRefMetadataString(fieldMeta?.quantity_field)
|
|
441
|
+
?? normalizeEntityRefMetadataString(kwargs?.quantity_field),
|
|
442
|
+
containerRequired: fieldMeta?.container_required === true || kwargs?.container_required === true,
|
|
443
|
+
bookingRequired: fieldMeta?.booking_required === true || kwargs?.booking_required === true,
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export function isResourceRefVarType(
|
|
448
|
+
type: string | undefined,
|
|
449
|
+
kwargs?: Record<string, unknown>,
|
|
450
|
+
fieldMeta?: AimdFieldMeta,
|
|
451
|
+
): boolean {
|
|
452
|
+
return getResourceRefTypeConfig(type, kwargs, fieldMeta) !== undefined
|
|
453
|
+
}
|
|
454
|
+
|
|
382
455
|
export function getEntityRefTypeConfig(
|
|
383
456
|
type: string | undefined,
|
|
384
457
|
kwargs?: Record<string, unknown>,
|
|
@@ -469,6 +542,10 @@ export function getVarInputKind(type: string | undefined, options: VarInputKindO
|
|
|
469
542
|
return typePlugin.inputKind
|
|
470
543
|
}
|
|
471
544
|
|
|
545
|
+
if (isResourceRefVarType(type, options.kwargs, options.fieldMeta)) {
|
|
546
|
+
return "resource-ref"
|
|
547
|
+
}
|
|
548
|
+
|
|
472
549
|
if (isEntityRefVarType(type, options.kwargs, options.fieldMeta)) {
|
|
473
550
|
return "entity-ref"
|
|
474
551
|
}
|
|
@@ -909,7 +986,7 @@ export function getVarInputDisplayValue(
|
|
|
909
986
|
))
|
|
910
987
|
}
|
|
911
988
|
|
|
912
|
-
if (kind === "entity-ref") {
|
|
989
|
+
if (kind === "entity-ref" || kind === "resource-ref") {
|
|
913
990
|
return getEntityRefDisplayValue(normalized)
|
|
914
991
|
}
|
|
915
992
|
|
|
@@ -1022,7 +1099,8 @@ function getVarControlMinWidth(inputKind: VarInputKind): number {
|
|
|
1022
1099
|
case "file":
|
|
1023
1100
|
case "scalar-list":
|
|
1024
1101
|
case "entity-ref":
|
|
1025
|
-
|
|
1102
|
+
case "resource-ref":
|
|
1103
|
+
return inputKind === "scalar-list" || inputKind === "entity-ref" || inputKind === "resource-ref" ? 220 : 160
|
|
1026
1104
|
default:
|
|
1027
1105
|
return 0
|
|
1028
1106
|
}
|
|
@@ -1040,6 +1118,7 @@ function getVarControlExtraWidth(inputKind: VarInputKind): number {
|
|
|
1040
1118
|
return 24
|
|
1041
1119
|
case "scalar-list":
|
|
1042
1120
|
case "entity-ref":
|
|
1121
|
+
case "resource-ref":
|
|
1043
1122
|
return 16
|
|
1044
1123
|
default:
|
|
1045
1124
|
return 4
|
|
@@ -1238,7 +1317,7 @@ export function applyVarStackWidth(target: HTMLElement, inputKind: VarInputKind)
|
|
|
1238
1317
|
return
|
|
1239
1318
|
}
|
|
1240
1319
|
|
|
1241
|
-
if (inputKind === "scalar-list" || inputKind === "entity-ref") {
|
|
1320
|
+
if (inputKind === "scalar-list" || inputKind === "entity-ref" || inputKind === "resource-ref") {
|
|
1242
1321
|
wrapper.style.width = "100%"
|
|
1243
1322
|
wrapper.style.maxWidth = "100%"
|
|
1244
1323
|
return
|
package/src/index.ts
CHANGED
|
@@ -17,8 +17,9 @@ export {
|
|
|
17
17
|
AimdRecorderEditor,
|
|
18
18
|
AimdQuizRecorder,
|
|
19
19
|
AimdRequiredMarker,
|
|
20
|
+
AimdResourceForm,
|
|
20
21
|
} from './components'
|
|
21
|
-
export { AimdDnaSequenceField, AimdEntityRefField, AimdMarkdownField } from './components'
|
|
22
|
+
export { AimdDnaSequenceField, AimdEntityRefField, AimdMarkdownField, AimdResourceRefField } from './components'
|
|
22
23
|
/**
|
|
23
24
|
* @deprecated Use `AimdRecorder` instead.
|
|
24
25
|
*/
|
|
@@ -65,6 +66,16 @@ export type {
|
|
|
65
66
|
AimdEntityRefOption,
|
|
66
67
|
AimdEntityRefValue,
|
|
67
68
|
AimdEntitySearchHandler,
|
|
69
|
+
AimdEquipmentSlotOption,
|
|
70
|
+
AimdPreparedResourceOutput,
|
|
71
|
+
AimdResourceAvailability,
|
|
72
|
+
AimdResourceContainerOption,
|
|
73
|
+
AimdResourceLotOption,
|
|
74
|
+
AimdResourceRefOption,
|
|
75
|
+
AimdResourceRefValue,
|
|
76
|
+
AimdResourceResolveContext,
|
|
77
|
+
AimdResourceResolver,
|
|
78
|
+
AimdResourceResolverMap,
|
|
68
79
|
AimdResolvedFileInfo,
|
|
69
80
|
AimdSelectedFileValue,
|
|
70
81
|
AimdTypePlugin,
|
package/src/locales.ts
CHANGED
|
@@ -118,6 +118,21 @@ export interface AimdRecorderMessages {
|
|
|
118
118
|
noMatches: string
|
|
119
119
|
searchFailed: string
|
|
120
120
|
}
|
|
121
|
+
resourceRef: {
|
|
122
|
+
availability: string
|
|
123
|
+
available: string
|
|
124
|
+
lot: string
|
|
125
|
+
container: string
|
|
126
|
+
quantity: string
|
|
127
|
+
unit: string
|
|
128
|
+
booking: string
|
|
129
|
+
selectLot: string
|
|
130
|
+
selectContainer: string
|
|
131
|
+
selectBooking: string
|
|
132
|
+
availabilityFailed: string
|
|
133
|
+
prepareOutputFailed: string
|
|
134
|
+
quantityFrom: (field: string) => string
|
|
135
|
+
}
|
|
121
136
|
collector: {
|
|
122
137
|
snapshot: string
|
|
123
138
|
start: string
|
|
@@ -161,6 +176,10 @@ export interface AimdRecorderMessages {
|
|
|
161
176
|
numeric: (label: string, detail: string) => string
|
|
162
177
|
type: (label: string, expected: string) => string
|
|
163
178
|
format: (label: string, format: string) => string
|
|
179
|
+
resource: (label: string, detail: string) => string
|
|
180
|
+
resourceInvalid: string
|
|
181
|
+
resourceContainerRequired: string
|
|
182
|
+
resourceBookingRequired: string
|
|
164
183
|
schema: (label: string, detail: string) => string
|
|
165
184
|
tableCell: (row: number, column: string) => string
|
|
166
185
|
}
|
|
@@ -373,6 +392,21 @@ const EN_US_MESSAGES: AimdRecorderMessages = {
|
|
|
373
392
|
noMatches: "No matching entities",
|
|
374
393
|
searchFailed: "Entity search failed.",
|
|
375
394
|
},
|
|
395
|
+
resourceRef: {
|
|
396
|
+
availability: "Availability",
|
|
397
|
+
available: "Available",
|
|
398
|
+
lot: "Lot",
|
|
399
|
+
container: "Container",
|
|
400
|
+
quantity: "Quantity",
|
|
401
|
+
unit: "Unit",
|
|
402
|
+
booking: "Booking",
|
|
403
|
+
selectLot: "Select a lot",
|
|
404
|
+
selectContainer: "Select a container",
|
|
405
|
+
selectBooking: "Select a time slot",
|
|
406
|
+
availabilityFailed: "Resource availability could not be loaded.",
|
|
407
|
+
prepareOutputFailed: "The output resource could not be prepared.",
|
|
408
|
+
quantityFrom: field => `Quantity is read from ${field}.`,
|
|
409
|
+
},
|
|
376
410
|
collector: {
|
|
377
411
|
snapshot: "Read now",
|
|
378
412
|
start: "Start collecting",
|
|
@@ -425,6 +459,10 @@ const EN_US_MESSAGES: AimdRecorderMessages = {
|
|
|
425
459
|
numeric: (label, detail) => `${label}: ${detail}`,
|
|
426
460
|
type: (label, expected) => `${label} must be ${expected}.`,
|
|
427
461
|
format: (label, format) => `${label} must use ${format} format.`,
|
|
462
|
+
resource: (label, detail) => `${label}: ${detail}`,
|
|
463
|
+
resourceInvalid: "Select a valid resource.",
|
|
464
|
+
resourceContainerRequired: "A container must be selected.",
|
|
465
|
+
resourceBookingRequired: "An equipment booking must be selected.",
|
|
428
466
|
schema: (label, detail) => `${label}: ${detail}`,
|
|
429
467
|
tableCell: (row, column) => `Row ${row}, ${column}`,
|
|
430
468
|
},
|
|
@@ -610,6 +648,21 @@ const ZH_CN_MESSAGES: AimdRecorderMessages = {
|
|
|
610
648
|
noMatches: "没有匹配的实体",
|
|
611
649
|
searchFailed: "实体搜索失败。",
|
|
612
650
|
},
|
|
651
|
+
resourceRef: {
|
|
652
|
+
availability: "可用情况",
|
|
653
|
+
available: "可用量",
|
|
654
|
+
lot: "批次",
|
|
655
|
+
container: "容器",
|
|
656
|
+
quantity: "数量",
|
|
657
|
+
unit: "单位",
|
|
658
|
+
booking: "设备预约",
|
|
659
|
+
selectLot: "选择批次",
|
|
660
|
+
selectContainer: "选择容器",
|
|
661
|
+
selectBooking: "选择可用时段",
|
|
662
|
+
availabilityFailed: "无法读取资源可用情况。",
|
|
663
|
+
prepareOutputFailed: "无法准备产出资源。",
|
|
664
|
+
quantityFrom: field => `数量读取自 ${field}。`,
|
|
665
|
+
},
|
|
613
666
|
collector: {
|
|
614
667
|
snapshot: "立即采集",
|
|
615
668
|
start: "开始采集",
|
|
@@ -662,6 +715,10 @@ const ZH_CN_MESSAGES: AimdRecorderMessages = {
|
|
|
662
715
|
numeric: (label, detail) => `${label}:${detail}`,
|
|
663
716
|
type: (label, expected) => `${label}必须是${expected}类型。`,
|
|
664
717
|
format: (label, format) => `${label}必须使用 ${format} 格式。`,
|
|
718
|
+
resource: (label, detail) => `${label}:${detail}`,
|
|
719
|
+
resourceInvalid: "请选择有效资源。",
|
|
720
|
+
resourceContainerRequired: "必须选择容器。",
|
|
721
|
+
resourceBookingRequired: "必须选择设备预约时段。",
|
|
665
722
|
schema: (label, detail) => `${label}:${detail}`,
|
|
666
723
|
tableCell: (row, column) => `第 ${row} 行,${column}`,
|
|
667
724
|
},
|
package/src/record/validation.ts
CHANGED
|
@@ -14,7 +14,11 @@ import type {
|
|
|
14
14
|
AimdRecorderValidationIssue,
|
|
15
15
|
AimdRecorderValidationResult,
|
|
16
16
|
} from "../types"
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
getNumericConstraintViolation,
|
|
19
|
+
getResourceRefTypeConfig,
|
|
20
|
+
isNullableVarType,
|
|
21
|
+
} from "../composables/useVarHelpers"
|
|
18
22
|
|
|
19
23
|
export interface ValidateAimdRecordOptions {
|
|
20
24
|
fieldMeta?: Record<string, AimdFieldMeta>
|
|
@@ -225,6 +229,53 @@ function findArraySchema(
|
|
|
225
229
|
return undefined
|
|
226
230
|
}
|
|
227
231
|
|
|
232
|
+
function schemaAllowsNull(
|
|
233
|
+
root: Record<string, unknown>,
|
|
234
|
+
candidate: unknown,
|
|
235
|
+
visited = new Set<object>(),
|
|
236
|
+
): boolean {
|
|
237
|
+
if (!isRecord(candidate) || visited.has(candidate)) return false
|
|
238
|
+
visited.add(candidate)
|
|
239
|
+
|
|
240
|
+
const schema = resolveLocalSchemaReference(root, candidate)
|
|
241
|
+
if (schema !== candidate && schemaAllowsNull(root, schema, visited)) return true
|
|
242
|
+
if (schema.nullable === true) return true
|
|
243
|
+
if (schema.type === "null") return true
|
|
244
|
+
if (Array.isArray(schema.type) && schema.type.includes("null")) return true
|
|
245
|
+
|
|
246
|
+
for (const branchKey of ["anyOf", "oneOf"] as const) {
|
|
247
|
+
const branches = schema[branchKey]
|
|
248
|
+
if (Array.isArray(branches) && branches.some(branch => schemaAllowsNull(root, branch, visited))) {
|
|
249
|
+
return true
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return false
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function getSchemaNullableFieldKeys(schemaSections: ResolvedSchemaSection[]): Set<string> {
|
|
256
|
+
const keys = new Set<string>()
|
|
257
|
+
for (const { section, schema } of schemaSections) {
|
|
258
|
+
const properties = isRecord(schema.properties) ? schema.properties : {}
|
|
259
|
+
for (const [id, propertySchema] of Object.entries(properties)) {
|
|
260
|
+
if (schemaAllowsNull(schema, propertySchema)) {
|
|
261
|
+
keys.add(`${section}:${id}`)
|
|
262
|
+
if (section === "var") keys.add(`var_table:${id}`)
|
|
263
|
+
}
|
|
264
|
+
if (section !== "var") continue
|
|
265
|
+
|
|
266
|
+
const arraySchema = findArraySchema(schema, propertySchema)
|
|
267
|
+
const itemSchema = isRecord(arraySchema?.items)
|
|
268
|
+
? resolveLocalSchemaReference(schema, arraySchema.items)
|
|
269
|
+
: undefined
|
|
270
|
+
const itemProperties = itemSchema && isRecord(itemSchema.properties) ? itemSchema.properties : {}
|
|
271
|
+
for (const [column, columnSchema] of Object.entries(itemProperties)) {
|
|
272
|
+
if (schemaAllowsNull(schema, columnSchema)) keys.add(`var_table:${id}:${column}`)
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return keys
|
|
277
|
+
}
|
|
278
|
+
|
|
228
279
|
function getSchemaRequiredFieldKeys(schemaSections: ResolvedSchemaSection[]): Set<string> {
|
|
229
280
|
const keys = new Set<string>()
|
|
230
281
|
for (const { section, schema } of schemaSections) {
|
|
@@ -264,31 +315,39 @@ export function getAimdRequiredFieldKeys(
|
|
|
264
315
|
const schemaSections = resolveSchemaSections(options.schema)
|
|
265
316
|
const schemaCoveredKeys = getSchemaCoveredFieldKeys(schemaSections)
|
|
266
317
|
const schemaRequiredKeys = getSchemaRequiredFieldKeys(schemaSections)
|
|
318
|
+
const schemaNullableKeys = getSchemaNullableFieldKeys(schemaSections)
|
|
267
319
|
|
|
268
320
|
const addWhenRequired = (
|
|
269
321
|
fieldKey: string,
|
|
270
322
|
kwargs: Record<string, unknown> | undefined,
|
|
271
323
|
inferredRequired: boolean,
|
|
324
|
+
type?: string,
|
|
272
325
|
) => {
|
|
273
326
|
const required = schemaCoveredKeys.has(fieldKey)
|
|
274
|
-
?
|
|
275
|
-
|
|
327
|
+
? fieldMeta[fieldKey]?.required === true
|
|
328
|
+
|| (schemaRequiredKeys.has(fieldKey) && !schemaNullableKeys.has(fieldKey))
|
|
329
|
+
: resolveRequired(fieldMeta[fieldKey], kwargs, inferredRequired && !isNullableVarType(type))
|
|
276
330
|
if (required) keys.add(fieldKey)
|
|
277
331
|
}
|
|
278
332
|
|
|
279
333
|
for (const field of fields.var_definitions ?? []) {
|
|
280
|
-
addWhenRequired(`var:${field.id}`, field.kwargs, !hasOwn(field, "default"))
|
|
334
|
+
addWhenRequired(`var:${field.id}`, field.kwargs, !hasOwn(field, "default"), field.type)
|
|
281
335
|
}
|
|
282
336
|
|
|
283
337
|
for (const table of fields.var_table ?? []) {
|
|
284
338
|
const tableKey = `var_table:${table.id}`
|
|
285
|
-
addWhenRequired(tableKey, table.kwargs, !hasOwn(table, "default"))
|
|
339
|
+
addWhenRequired(tableKey, table.kwargs, !hasOwn(table, "default"), table.type_annotation)
|
|
286
340
|
const schemaCovered = schemaCoveredKeys.has(tableKey)
|
|
287
341
|
for (const column of table.subvars ?? []) {
|
|
288
342
|
const columnKey = `${tableKey}:${column.id}`
|
|
289
343
|
const required = schemaCovered
|
|
290
|
-
?
|
|
291
|
-
|
|
344
|
+
? fieldMeta[columnKey]?.required === true
|
|
345
|
+
|| (schemaRequiredKeys.has(columnKey) && !schemaNullableKeys.has(columnKey))
|
|
346
|
+
: resolveRequired(
|
|
347
|
+
fieldMeta[columnKey],
|
|
348
|
+
column.kwargs,
|
|
349
|
+
!hasOwn(column, "default") && !isNullableVarType(column.type),
|
|
350
|
+
)
|
|
292
351
|
if (required) keys.add(columnKey)
|
|
293
352
|
}
|
|
294
353
|
}
|
|
@@ -587,6 +646,7 @@ function validateValue(
|
|
|
587
646
|
inferredRequired?: boolean
|
|
588
647
|
schemaCovered?: boolean
|
|
589
648
|
schemaRequired?: boolean
|
|
649
|
+
schemaNullable?: boolean
|
|
590
650
|
},
|
|
591
651
|
) {
|
|
592
652
|
const {
|
|
@@ -603,15 +663,19 @@ function validateValue(
|
|
|
603
663
|
inferredRequired = false,
|
|
604
664
|
schemaCovered = false,
|
|
605
665
|
schemaRequired = false,
|
|
666
|
+
schemaNullable = false,
|
|
606
667
|
} = input
|
|
607
668
|
const details = { rowIndex, column }
|
|
608
669
|
const fallbackKwargs = schemaCovered ? undefined : kwargs
|
|
609
670
|
const fallbackEnumValues = schemaCovered ? undefined : enumValues
|
|
671
|
+
const explicitlyRequired = meta?.required === true || (!schemaCovered && kwargs?.required === true)
|
|
672
|
+
const nullable = schemaCovered ? schemaNullable : isNullableVarType(type)
|
|
610
673
|
const required = schemaCovered
|
|
611
674
|
? schemaRequired || meta?.required === true
|
|
612
|
-
: resolveRequired(meta, kwargs, inferredRequired)
|
|
675
|
+
: resolveRequired(meta, kwargs, inferredRequired && !nullable)
|
|
676
|
+
const allowedNullableEmpty = value === null && nullable && !explicitlyRequired
|
|
613
677
|
|
|
614
|
-
if (required && isEmptyValue(value)) {
|
|
678
|
+
if (required && isEmptyValue(value) && !allowedNullableEmpty) {
|
|
615
679
|
addIssue(issues, fieldKey, section, "required", options.messages.required(label), value, details)
|
|
616
680
|
return
|
|
617
681
|
}
|
|
@@ -652,6 +716,60 @@ function validateValue(
|
|
|
652
716
|
}
|
|
653
717
|
}
|
|
654
718
|
|
|
719
|
+
function validateResourceRefValue(
|
|
720
|
+
issues: AimdRecorderValidationIssue[],
|
|
721
|
+
options: ValidateAimdRecordOptions,
|
|
722
|
+
input: {
|
|
723
|
+
fieldKey: string
|
|
724
|
+
label: string
|
|
725
|
+
value: unknown
|
|
726
|
+
type?: string
|
|
727
|
+
kwargs?: Record<string, unknown>
|
|
728
|
+
meta?: AimdFieldMeta
|
|
729
|
+
},
|
|
730
|
+
): void {
|
|
731
|
+
const config = getResourceRefTypeConfig(input.type, input.kwargs, input.meta)
|
|
732
|
+
if (!config || isEmptyValue(input.value)) return
|
|
733
|
+
const values = config.multiple
|
|
734
|
+
? Array.isArray(input.value) ? input.value : [input.value]
|
|
735
|
+
: [input.value]
|
|
736
|
+
for (const value of values) {
|
|
737
|
+
if (!isRecord(value) || typeof value.id !== "string" || !value.id.trim()) {
|
|
738
|
+
addIssue(
|
|
739
|
+
issues,
|
|
740
|
+
input.fieldKey,
|
|
741
|
+
"var",
|
|
742
|
+
"resource",
|
|
743
|
+
options.messages.resource(input.label, options.messages.resourceInvalid),
|
|
744
|
+
input.value,
|
|
745
|
+
)
|
|
746
|
+
return
|
|
747
|
+
}
|
|
748
|
+
if (config.containerRequired && (typeof value.container_id !== "string" || !value.container_id.trim())) {
|
|
749
|
+
addIssue(
|
|
750
|
+
issues,
|
|
751
|
+
input.fieldKey,
|
|
752
|
+
"var",
|
|
753
|
+
"resource",
|
|
754
|
+
options.messages.resource(input.label, options.messages.resourceContainerRequired),
|
|
755
|
+
input.value,
|
|
756
|
+
)
|
|
757
|
+
return
|
|
758
|
+
}
|
|
759
|
+
if (config.bookingRequired && (typeof value.booking_id !== "string" || !value.booking_id.trim())) {
|
|
760
|
+
addIssue(
|
|
761
|
+
issues,
|
|
762
|
+
input.fieldKey,
|
|
763
|
+
"var",
|
|
764
|
+
"resource",
|
|
765
|
+
options.messages.resource(input.label, options.messages.resourceBookingRequired),
|
|
766
|
+
input.value,
|
|
767
|
+
)
|
|
768
|
+
return
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
655
773
|
function matchesFieldSelector(fieldKey: string, selector: string): boolean {
|
|
656
774
|
if (fieldKey === selector) return true
|
|
657
775
|
const selectorParts = selector.split(":")
|
|
@@ -715,6 +833,7 @@ export function validateAimdRecord(
|
|
|
715
833
|
const schemaSections = resolveSchemaSections(options.schema)
|
|
716
834
|
const schemaCoveredKeys = getSchemaCoveredFieldKeys(schemaSections)
|
|
717
835
|
const schemaRequiredKeys = getSchemaRequiredFieldKeys(schemaSections)
|
|
836
|
+
const schemaNullableKeys = getSchemaNullableFieldKeys(schemaSections)
|
|
718
837
|
|
|
719
838
|
validateSchema(issues, fields, record, schemaSections, options.messages)
|
|
720
839
|
|
|
@@ -732,6 +851,15 @@ export function validateAimdRecord(
|
|
|
732
851
|
inferredRequired: !hasOwn(field, "default"),
|
|
733
852
|
schemaCovered: schemaCoveredKeys.has(fieldKey),
|
|
734
853
|
schemaRequired: schemaRequiredKeys.has(fieldKey),
|
|
854
|
+
schemaNullable: schemaNullableKeys.has(fieldKey),
|
|
855
|
+
})
|
|
856
|
+
validateResourceRefValue(issues, options, {
|
|
857
|
+
fieldKey,
|
|
858
|
+
label: field.title || field.id,
|
|
859
|
+
value: record.var[field.id],
|
|
860
|
+
type: field.type,
|
|
861
|
+
kwargs: field.kwargs,
|
|
862
|
+
meta: fieldMeta[fieldKey],
|
|
735
863
|
})
|
|
736
864
|
}
|
|
737
865
|
|
|
@@ -740,8 +868,13 @@ export function validateAimdRecord(
|
|
|
740
868
|
const rows = Array.isArray(record.var[table.id]) ? record.var[table.id] as Record<string, unknown>[] : []
|
|
741
869
|
const schemaCovered = schemaCoveredKeys.has(tableKey)
|
|
742
870
|
const required = schemaCovered
|
|
743
|
-
?
|
|
744
|
-
|
|
871
|
+
? fieldMeta[tableKey]?.required === true
|
|
872
|
+
|| (schemaRequiredKeys.has(tableKey) && !schemaNullableKeys.has(tableKey))
|
|
873
|
+
: resolveRequired(
|
|
874
|
+
fieldMeta[tableKey],
|
|
875
|
+
table.kwargs,
|
|
876
|
+
!hasOwn(table, "default") && !isNullableVarType(table.type_annotation),
|
|
877
|
+
)
|
|
745
878
|
if (required && rows.length === 0) {
|
|
746
879
|
addIssue(issues, tableKey, "var_table", "required", options.messages.required(table.title || table.id), rows)
|
|
747
880
|
continue
|
|
@@ -764,6 +897,7 @@ export function validateAimdRecord(
|
|
|
764
897
|
inferredRequired: !hasOwn(column, "default"),
|
|
765
898
|
schemaCovered,
|
|
766
899
|
schemaRequired: schemaRequiredKeys.has(columnMetaKey),
|
|
900
|
+
schemaNullable: schemaNullableKeys.has(columnMetaKey),
|
|
767
901
|
})
|
|
768
902
|
}
|
|
769
903
|
})
|
package/src/styles/recorder.css
CHANGED
|
@@ -139,6 +139,13 @@
|
|
|
139
139
|
transform: translateY(-0.08em);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
+
.aimd-field__title-row {
|
|
143
|
+
display: inline-flex;
|
|
144
|
+
align-items: baseline;
|
|
145
|
+
min-width: 0;
|
|
146
|
+
max-width: 100%;
|
|
147
|
+
}
|
|
148
|
+
|
|
142
149
|
.aimd-field--no-style.aimd-field__label .aimd-field__name--with-metadata {
|
|
143
150
|
align-items: flex-start;
|
|
144
151
|
justify-content: center;
|
package/src/types.ts
CHANGED
|
@@ -9,6 +9,18 @@ import type {
|
|
|
9
9
|
AimdVarTableNode,
|
|
10
10
|
} from "@airalogy/aimd-core/types"
|
|
11
11
|
import type { AimdRecorderMessages } from "./locales"
|
|
12
|
+
import type {
|
|
13
|
+
AimdEquipmentSlotOption as CoreAimdEquipmentSlotOption,
|
|
14
|
+
AimdPreparedResourceOutput as CoreAimdPreparedResourceOutput,
|
|
15
|
+
AimdResourceAvailability as CoreAimdResourceAvailability,
|
|
16
|
+
AimdResourceContainerOption as CoreAimdResourceContainerOption,
|
|
17
|
+
AimdResourceLotOption as CoreAimdResourceLotOption,
|
|
18
|
+
AimdResourceRefOption as CoreAimdResourceRefOption,
|
|
19
|
+
AimdResourceRefValue as CoreAimdResourceRefValue,
|
|
20
|
+
AimdResourceResolveContext as CoreAimdResourceResolveContext,
|
|
21
|
+
AimdResourceResolver as CoreAimdResourceResolver,
|
|
22
|
+
AimdResourceResolverMap as CoreAimdResourceResolverMap,
|
|
23
|
+
} from "@airalogy/aimd-core"
|
|
12
24
|
|
|
13
25
|
export interface AimdStepOrCheckRecordItem {
|
|
14
26
|
checked: boolean
|
|
@@ -158,6 +170,17 @@ export interface AimdEntityResolver {
|
|
|
158
170
|
export type AimdEntityResolverEntry = AimdEntityResolver | AimdEntitySearchHandler
|
|
159
171
|
export type AimdEntityResolverMap = Record<string, AimdEntityResolverEntry>
|
|
160
172
|
|
|
173
|
+
export type AimdResourceRefValue = CoreAimdResourceRefValue
|
|
174
|
+
export type AimdResourceRefOption = CoreAimdResourceRefOption
|
|
175
|
+
export type AimdResourceLotOption = CoreAimdResourceLotOption
|
|
176
|
+
export type AimdResourceContainerOption = CoreAimdResourceContainerOption
|
|
177
|
+
export type AimdEquipmentSlotOption = CoreAimdEquipmentSlotOption
|
|
178
|
+
export type AimdResourceAvailability = CoreAimdResourceAvailability
|
|
179
|
+
export type AimdPreparedResourceOutput = CoreAimdPreparedResourceOutput
|
|
180
|
+
export type AimdResourceResolveContext = CoreAimdResourceResolveContext
|
|
181
|
+
export type AimdResourceResolver = CoreAimdResourceResolver
|
|
182
|
+
export type AimdResourceResolverMap = CoreAimdResourceResolverMap
|
|
183
|
+
|
|
161
184
|
export type AimdCollectorRuntimeStatus =
|
|
162
185
|
| "idle"
|
|
163
186
|
| "waiting_for_permission"
|
|
@@ -235,7 +258,7 @@ export type AimdCollectorPermissionHandler = (
|
|
|
235
258
|
request: AimdCollectorPermissionRequest,
|
|
236
259
|
) => AimdCollectorPermissionDecision | Promise<AimdCollectorPermissionDecision>
|
|
237
260
|
|
|
238
|
-
export type AimdVarInputKind = "text" | "number" | "checkbox" | "boolean-select" | "textarea" | "scalar-list" | "entity-ref" | "date" | "datetime" | "time" | "dna" | "code" | "file"
|
|
261
|
+
export type AimdVarInputKind = "text" | "number" | "checkbox" | "boolean-select" | "textarea" | "scalar-list" | "entity-ref" | "resource-ref" | "date" | "datetime" | "time" | "dna" | "code" | "file"
|
|
239
262
|
export type AimdStepDetailDisplay = "auto" | "always"
|
|
240
263
|
export type AimdChoiceOptionExplanationMode = "hidden" | "selected" | "submitted" | "graded"
|
|
241
264
|
export type AimdScaleGradeDisplayMode = "hidden" | "completed" | "submitted" | "graded"
|
|
@@ -271,6 +294,10 @@ export interface AimdFieldMeta {
|
|
|
271
294
|
accept?: string // native file input accept string for file-like vars
|
|
272
295
|
entity?: string // entity namespace for EntityRef fields
|
|
273
296
|
source?: string // connector id/source for EntityRef fields
|
|
297
|
+
resource_role?: "input" | "output" | "reference" | "equipment"
|
|
298
|
+
quantity_field?: string
|
|
299
|
+
container_required?: boolean
|
|
300
|
+
booking_required?: boolean
|
|
274
301
|
assigner?: { mode: AimdAssignerMode }
|
|
275
302
|
}
|
|
276
303
|
|
|
@@ -289,6 +316,7 @@ export type AimdRecorderValidationCode =
|
|
|
289
316
|
| "numeric"
|
|
290
317
|
| "type"
|
|
291
318
|
| "format"
|
|
319
|
+
| "resource"
|
|
292
320
|
| "schema"
|
|
293
321
|
|
|
294
322
|
export type AimdRecorderValidationTrigger = "change" | "blur" | "submit"
|
|
@@ -448,6 +476,7 @@ export interface AimdTypePluginRenderContext extends AimdTypePluginValueContext
|
|
|
448
476
|
resolveFile?: (src: string) => string | null
|
|
449
477
|
resolveFileInfo?: AimdFileInfoResolver
|
|
450
478
|
entityResolvers?: AimdEntityResolverMap
|
|
479
|
+
resourceResolvers?: AimdResourceResolverMap
|
|
451
480
|
emitChange: (value: unknown) => void
|
|
452
481
|
emitBlur: () => void
|
|
453
482
|
}
|