Skip to content

Commit fad2a60

Browse files
authored
further cleanup and documentation (#1290)
* further cleanup and documentation
1 parent fba7659 commit fad2a60

File tree

1 file changed

+47
-34
lines changed

1 file changed

+47
-34
lines changed

src-electron/sdk/matter.js

Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,20 @@ const queryPackage = require('../db/query-package.js')
2020
const queryCluster = require('../db/query-cluster.js')
2121
const queryAttribute = require('../db/query-attribute.js')
2222
const dbEnum = require('../../src-shared/db-enum.js')
23-
const fs = require('fs')
24-
const fsp = fs.promises
2523

2624
/**
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
29-
*/
30-
31-
/**
32-
* Returns an array of objects containing global attributes that should be forced external.
25+
* This asynchronous function retrieves and returns the forced external storage options.
3326
*
34-
* @export
35-
* @param {*} db
36-
* @param {*} attributeId
37-
* @returns An array of objects
27+
* @param {Object} db - The database instance.
28+
*
29+
* The function calls the 'getAttributeAccessInterface' method from 'queryPackage' with
30+
* the database instance and 'attributeAccessInterface' from 'storagePolicy' as parameters.
31+
* The result is assigned to 'forcedExternal'.
32+
* Finally, it returns the 'forcedExternal' options.
3833
*/
3934

4035
async function getForcedExternalStorage(db) {
41-
let forcedExternal = await queryPackage.getAttributeAccessInterface(
36+
let forcedExternal = queryPackage.getAttributeAccessInterface(
4237
db,
4338
dbEnum.storagePolicy.attributeAccessInterface
4439
)
@@ -72,13 +67,14 @@ async function computeStoragePolicyForGlobalAttributes(
7267
attributes.map(async (attribute) => {
7368
if (attribute.clusterId == null) {
7469
forcedExternal = await getForcedExternalStorage(db, attribute.id)
75-
forcedExternal.map((option) => {
70+
forcedExternal.some((option) => {
7671
if (
7772
option.optionCategory == clusterName &&
7873
option.optionLabel == attribute.name
7974
) {
8075
attribute.storagePolicy =
8176
dbEnum.storagePolicy.attributeAccessInterface
77+
return true
8278
}
8379
})
8480
}
@@ -87,16 +83,15 @@ async function computeStoragePolicyForGlobalAttributes(
8783
)
8884
}
8985
/**
90-
* Returns a flag stating which type of storage option the attribute is categorized to be.
86+
* This asynchronous function computes and returns the new configuration for a storage option.
9187
*
92-
* @export
93-
* @param {*} db
94-
* @param {*} clusterName
95-
* @param {*} clusterRef
96-
* @param {*} storagePolicy
97-
* @param {*} forcedExternal
98-
* @param {*} attributeId
99-
* @returns Storage Option
88+
* @param {String} storagePolicy - The current storage policy.
89+
*
90+
* The function first initializes the storageOption. Then it checks the storagePolicy:
91+
* - If it's 'attributeAccessInterface', it sets the storageOption to 'external'.
92+
* - If it's 'any', it sets the storageOption to 'ram'.
93+
* If the storagePolicy is neither of these, it throws an error 'check storage policy'.
94+
* Finally, it returns the updated storage option.
10095
*/
10196

10297
async function computeStorageOptionNewConfig(storagePolicy) {
@@ -110,36 +105,54 @@ async function computeStorageOptionNewConfig(storagePolicy) {
110105
}
111106
return storageOption
112107
}
113-
108+
/**
109+
* This asynchronous function computes and returns the new configuration for a storage policy.
110+
*
111+
* @param {Object} db - The database instance.
112+
* @param {Number} clusterRef - The reference to the cluster.
113+
* @param {String} storagePolicy - The current storage policy.
114+
* @param {Array} forcedExternal - An array of external options.
115+
* @param {String} attributeName - The name of the attribute.
116+
*
117+
* The function first queries to get the cluster name using the cluster reference.
118+
* Then it iterates over each option in the forcedExternal array. If the option's category
119+
* matches the cluster name and the option's label matches the attribute name, it updates
120+
* the storage policy to attributeAccessInterface. Finally, it returns the updated storage policy.
121+
*/
114122
async function computeStoragePolicyNewConfig(
115123
db,
116124
clusterRef,
117125
storagePolicy,
118126
forcedExternal,
119127
attributeName
120128
) {
121-
let clusterName
122-
clusterName = await queryCluster.selectClusterName(db, clusterRef)
123-
forcedExternal.map((option) => {
129+
let clusterName = await queryCluster.selectClusterName(db, clusterRef)
130+
forcedExternal.some((option) => {
124131
if (
125132
option.optionCategory == clusterName &&
126133
option.optionLabel == attributeName
127134
) {
128135
storagePolicy = dbEnum.storagePolicy.attributeAccessInterface
136+
return true
129137
}
130138
})
131139
return storagePolicy
132140
}
133141

134142
/**
135-
* Returns a flag stating which type of storage option the attribute is categorized to be.
143+
* This asynchronous function computes and returns the updated storage import policy.
136144
*
137-
* @export
138-
* @param {*} db
139-
* @param {*} clusterName
140-
* @param {*} forcedExternal
141-
* @param {*} attributeId
142-
* @returns Storage Policy
145+
* @param {Object} db - The database instance.
146+
* @param {String} clusterName - The name of the cluster.
147+
* @param {String} storagePolicy - The current storage policy.
148+
* @param {Array} forcedExternal - An array of external options.
149+
* @param {String} attributeName - The name of the attribute.
150+
*
151+
* The function first initializes the updatedStoragePolicy with the current storage policy.
152+
* Then it iterates over each option in the forcedExternal array. If the option's category
153+
* matches the cluster name and the option's label matches the attribute name, it updates
154+
* the updatedStoragePolicy to attributeAccessInterface and stops the iteration.
155+
* Finally, it returns the updated storage policy.
143156
*/
144157

145158
async function computeStorageImport(

0 commit comments

Comments
 (0)