@@ -23,26 +23,11 @@ const dbEnum = require('../../src-shared/db-enum.js')
2323const fs = require ( 'fs' )
2424const fsp = fs . promises
2525
26- function parseJson ( json ) {
27- try {
28- return JSON . parse ( json )
29- } catch ( err ) {
30- return undefined
31- }
32- }
33-
3426/**
35- * This file implements upgrade rules which are used to upgrade .zap files and xml files
36- * to be in sync with the spec
27+ * This file implements SDK rules which are used to upgrade .zap files and xml files
28+ * to be in sync with the Matter SDK and spec
3729 */
38- async function getForcedExternalStorageList ( db , zcl ) {
39- let obj = await fsp . readFile ( zcl , 'utf-8' )
40- let data = parseJson ( obj )
41- let byName = data ?. attributeAccessInterfaceAttributes
42- let lists = data ?. listsUseAttributeAccessInterface
43- let forcedExternal = { byName, lists }
44- return forcedExternal
45- }
30+
4631/**
4732 * Returns an array of objects containing global attributes that should be forced external.
4833 *
@@ -52,15 +37,11 @@ async function getForcedExternalStorageList(db, zcl) {
5237 * @returns An array of objects
5338 */
5439
55- async function getForcedExternalStorage ( db , attributeId ) {
56- let pkgs = await queryPackage . getPackageRefByAttributeId ( db , attributeId )
57- let zcl = await queryPackage . getPackageByPackageId ( db , pkgs )
58- zcl = zcl ?. path
59- let obj = await fsp . readFile ( zcl , 'utf-8' )
60- let data = parseJson ( obj )
61- let byName = data ?. attributeAccessInterfaceAttributes
62- let lists = data ?. listsUseAttributeAccessInterface
63- let forcedExternal = { byName, lists }
40+ async function getForcedExternalStorage ( db ) {
41+ let forcedExternal = await queryPackage . getAttributeAccessInterface (
42+ db ,
43+ dbEnum . storagePolicy . attributeAccessInterface
44+ )
6445 return forcedExternal
6546}
6647
@@ -85,26 +66,26 @@ async function computeStoragePolicyForGlobalAttributes(
8566 clusterId ,
8667 attributes
8768) {
88- let clusterName
8969 let forcedExternal
90- clusterName = await queryCluster . selectClusterName ( db , clusterId )
70+ let clusterName = await queryCluster . selectClusterName ( db , clusterId )
9171 return Promise . all (
9272 attributes . map ( async ( attribute ) => {
9373 if ( attribute . clusterId == null ) {
9474 forcedExternal = await getForcedExternalStorage ( db , attribute . id )
95- if ( forcedExternal . byName ?. [ clusterName ] ?. includes ( attribute . name ) ) {
96- attribute . storagePolicy =
97- dbEnum . storagePolicy . attributeAccessInterface
98- }
75+ forcedExternal . map ( ( option ) => {
76+ if (
77+ option . optionCategory == clusterName &&
78+ option . optionLabel == attribute . name
79+ ) {
80+ attribute . storagePolicy =
81+ dbEnum . storagePolicy . attributeAccessInterface
82+ }
83+ } )
9984 }
10085 return attribute
10186 } )
10287 )
10388}
104- async function getDisabledStorage ( db , zcl ) {
105- return await getForcedExternalStorageList ( db , zcl )
106- }
107-
10889/**
10990 * Returns a flag stating which type of storage option the attribute is categorized to be.
11091 *
@@ -118,33 +99,38 @@ async function getDisabledStorage(db, zcl) {
11899 * @returns Storage Option
119100 */
120101
121- async function computeStorageNewConfig (
122- db ,
123- clusterRef ,
124- storagePolicy ,
125- forcedExternal ,
126- attributeName
127- ) {
102+ async function computeStorageOptionNewConfig ( storagePolicy ) {
128103 let storageOption
129- let clusterName
130- clusterName = await queryCluster . selectClusterName ( db , clusterRef )
131104 if ( storagePolicy == dbEnum . storagePolicy . attributeAccessInterface ) {
132105 storageOption = dbEnum . storageOption . external
133106 } else if ( storagePolicy == dbEnum . storagePolicy . any ) {
134107 storageOption = dbEnum . storageOption . ram
135108 } else {
136109 throw 'check storage policy'
137110 }
138- if (
139- forcedExternal . byName &&
140- forcedExternal . byName [ clusterName ] &&
141- forcedExternal . byName [ clusterName ] . includes ( attributeName )
142- ) {
143- storageOption = dbEnum . storageOption . external
144- }
145111 return storageOption
146112}
147113
114+ async function computeStoragePolicyNewConfig (
115+ db ,
116+ clusterRef ,
117+ storagePolicy ,
118+ forcedExternal ,
119+ attributeName
120+ ) {
121+ let clusterName
122+ clusterName = await queryCluster . selectClusterName ( db , clusterRef )
123+ forcedExternal . map ( ( option ) => {
124+ if (
125+ option . optionCategory == clusterName &&
126+ option . optionLabel == attributeName
127+ ) {
128+ storagePolicy = dbEnum . storagePolicy . attributeAccessInterface
129+ }
130+ } )
131+ return storagePolicy
132+ }
133+
148134/**
149135 * Returns a flag stating which type of storage option the attribute is categorized to be.
150136 *
@@ -163,19 +149,23 @@ async function computeStorageImport(
163149 forcedExternal ,
164150 attributeName
165151) {
166- if (
167- forcedExternal . byName &&
168- forcedExternal . byName [ clusterName ] &&
169- forcedExternal . byName [ clusterName ] . includes ( attributeName )
170- ) {
171- storagePolicy = dbEnum . storagePolicy . attributeAccessInterface
172- }
173- return storagePolicy
152+ let updatedStoragePolicy = storagePolicy
153+ forcedExternal . some ( ( option ) => {
154+ if (
155+ option . optionCategory == clusterName &&
156+ option . optionLabel == attributeName
157+ ) {
158+ updatedStoragePolicy = dbEnum . storagePolicy . attributeAccessInterface
159+ return true
160+ }
161+ return false
162+ } )
163+ return updatedStoragePolicy
174164}
175165
176166exports . getForcedExternalStorage = getForcedExternalStorage
177- exports . getDisabledStorage = getDisabledStorage
178167exports . computeStorageImport = computeStorageImport
179- exports . computeStorageNewConfig = computeStorageNewConfig
168+ exports . computeStoragePolicyNewConfig = computeStoragePolicyNewConfig
169+ exports . computeStorageOptionNewConfig = computeStorageOptionNewConfig
180170exports . computeStoragePolicyForGlobalAttributes =
181171 computeStoragePolicyForGlobalAttributes
0 commit comments