nayota-show-sdk 1.3.89 → 1.3.90

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nayota-show-sdk",
3
- "version": "1.3.89",
3
+ "version": "1.3.90",
4
4
  "description": "nayota-show-server rest-api",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -511,6 +511,90 @@ function normalizeLegacyValueStr(value, fallback = '') {
511
511
  return ''
512
512
  }
513
513
 
514
+ function normalizeLegacyEasyListPropTypeValue(value) {
515
+ if (value == null || value === '') {
516
+ return undefined
517
+ }
518
+
519
+ const normalized = String(value).trim().replace(/[\s_-]/g, '').toLowerCase()
520
+
521
+ if (['operate', 'operation', 'control', 'controller', 'write', 'writable', 'readwrite', 'writeonly', 'rw', 'wr', 'w'].includes(normalized)) {
522
+ return 'Operate'
523
+ }
524
+
525
+ if (['check', 'monitor', 'sensor', 'read', 'readonly', 'ro', 'r'].includes(normalized)) {
526
+ return 'Check'
527
+ }
528
+
529
+ if (['控制', '控制器', '读写', '只写', '可写'].includes(normalized)) {
530
+ return 'Operate'
531
+ }
532
+
533
+ if (['监测', '监测器', '只读'].includes(normalized)) {
534
+ return 'Check'
535
+ }
536
+
537
+ if ((normalized.includes('write') || normalized.includes('写')) && normalized !== 'readonly' && normalized !== '只读') {
538
+ return 'Operate'
539
+ }
540
+
541
+ if (normalized.includes('read') || normalized.includes('读') || normalized.includes('check')) {
542
+ return 'Check'
543
+ }
544
+
545
+ return undefined
546
+ }
547
+
548
+ function resolveLegacyEasyListPropType(source = {}, prop = {}) {
549
+ const explicitCandidates = [
550
+ source.propType,
551
+ source.type,
552
+ source.propertyType,
553
+ prop.propType,
554
+ prop.type,
555
+ prop.propertyType,
556
+ getNestedValue(source, 'metadata.propType'),
557
+ getNestedValue(prop, 'metadata.propType')
558
+ ]
559
+
560
+ const explicitPropType = explicitCandidates
561
+ .map(normalizeLegacyEasyListPropTypeValue)
562
+ .find(Boolean)
563
+
564
+ if (explicitPropType) {
565
+ return explicitPropType
566
+ }
567
+
568
+ const accessCandidates = [
569
+ source.access,
570
+ source.propertyAccess,
571
+ source.accessMode,
572
+ source.permission,
573
+ source.permissions,
574
+ source.accessPermission,
575
+ prop.access,
576
+ prop.propertyAccess,
577
+ prop.accessMode,
578
+ prop.permission,
579
+ prop.permissions,
580
+ prop.accessPermission,
581
+ getNestedValue(source, 'metadata.access'),
582
+ getNestedValue(source, 'metadata.propertyAccess'),
583
+ getNestedValue(source, 'typeProperty.access'),
584
+ getNestedValue(source, 'deviceProperty.access'),
585
+ getNestedValue(source, 'deviceTypeProperty.access'),
586
+ getNestedValue(prop, 'metadata.access'),
587
+ getNestedValue(prop, 'metadata.propertyAccess'),
588
+ getNestedValue(prop, 'typeProperty.access'),
589
+ getNestedValue(prop, 'deviceProperty.access'),
590
+ getNestedValue(prop, 'deviceTypeProperty.access')
591
+ ]
592
+
593
+ return accessCandidates
594
+ .map(normalizeLegacyEasyListPropTypeValue)
595
+ .find(Boolean)
596
+ }
597
+
514
598
  function normalizeLegacyPropLine(source = {}, prop = {}, row = {}) {
515
599
  if (typeof source.line === 'boolean') {
516
600
  return source.line
@@ -664,10 +748,12 @@ function normalizeLegacyEasyListProp(source = {}, row = {}) {
664
748
  const isStatus = Boolean(source.isStatus)
665
749
  const isNumber = Boolean(source.isNumber)
666
750
  const isImport = Boolean(source.isImport || isMain || isStatus || isNumber)
751
+ const propType = resolveLegacyEasyListPropType(source, prop)
667
752
 
668
753
  const legacyProp = removeUndefinedFields({
669
754
  ...prop,
670
755
  _id: propId,
756
+ propType,
671
757
  deviceId: prop.deviceId || source.deviceId || '',
672
758
  key: prop.key || source.propertyKey,
673
759
  name: prop.name || source.propName || source.name || source.code || source.propertyKey,
@@ -698,6 +784,7 @@ function normalizeLegacyEasyListProp(source = {}, row = {}) {
698
784
  isMain,
699
785
  isStatus,
700
786
  isNumber,
787
+ propType,
701
788
  line,
702
789
  value,
703
790
  valueStr,
@@ -636,6 +636,60 @@ describe('iotModuleSpecs devices easyList legacy compatibility', () => {
636
636
  })
637
637
  )
638
638
  })
639
+
640
+ test('maps writable access permissions to legacy BMS Operate props', () => {
641
+ const response = easyList.fromResponse({
642
+ code: 0,
643
+ data: {
644
+ total: 1,
645
+ rows: [
646
+ {
647
+ id: 'twin-1',
648
+ props: [
649
+ {
650
+ id: 'write-only-prop',
651
+ propertyKey: 'reset',
652
+ name: '复位',
653
+ access: 'write_only',
654
+ interval: '[["复位"],[1]]',
655
+ prop: {
656
+ id: 'device-prop-reset'
657
+ }
658
+ },
659
+ {
660
+ id: 'read-write-prop',
661
+ propertyKey: 'reply',
662
+ name: '回复',
663
+ propertyAccess: '读写',
664
+ interval: '[["确认"],[1]]',
665
+ prop: {
666
+ id: 'device-prop-reply'
667
+ }
668
+ },
669
+ {
670
+ id: 'read-only-prop',
671
+ propertyKey: 'version',
672
+ name: '版本',
673
+ access: 'read_only',
674
+ prop: {
675
+ id: 'device-prop-version'
676
+ }
677
+ }
678
+ ]
679
+ }
680
+ ]
681
+ }
682
+ })
683
+
684
+ const [writeOnlyProp, readWriteProp, readOnlyProp] = response.data.rows[0].props
685
+
686
+ expect(writeOnlyProp).toEqual(expect.objectContaining({ propType: 'Operate' }))
687
+ expect(writeOnlyProp.prop).toEqual(expect.objectContaining({ propType: 'Operate' }))
688
+ expect(readWriteProp).toEqual(expect.objectContaining({ propType: 'Operate' }))
689
+ expect(readWriteProp.prop).toEqual(expect.objectContaining({ propType: 'Operate' }))
690
+ expect(readOnlyProp).toEqual(expect.objectContaining({ propType: 'Check' }))
691
+ expect(readOnlyProp.prop).toEqual(expect.objectContaining({ propType: 'Check' }))
692
+ })
639
693
  })
640
694
 
641
695
  describe('iotModuleSpecs devices getPropHistoryData legacy compatibility', () => {