@matter/protocol 0.13.1-alpha.0-20250520-d699cd56d → 0.14.0-alpha.0-20250524-51a7e1721
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/dist/cjs/action/Interactable.d.ts +1 -1
- package/dist/cjs/action/Interactable.d.ts.map +1 -1
- package/dist/cjs/action/client/ClientInteraction.d.ts +1 -1
- package/dist/cjs/action/client/ClientInteraction.d.ts.map +1 -1
- package/dist/cjs/action/client/ClientInteraction.js +50 -8
- package/dist/cjs/action/client/ClientInteraction.js.map +1 -1
- package/dist/cjs/action/protocols.d.ts +49 -15
- package/dist/cjs/action/protocols.d.ts.map +1 -1
- package/dist/cjs/action/request/Invoke.d.ts +10 -1
- package/dist/cjs/action/request/Invoke.d.ts.map +1 -1
- package/dist/cjs/action/request/Invoke.js +17 -5
- package/dist/cjs/action/request/Invoke.js.map +1 -1
- package/dist/cjs/action/request/Read.d.ts.map +1 -1
- package/dist/cjs/action/request/Read.js +1 -1
- package/dist/cjs/action/request/Read.js.map +1 -1
- package/dist/cjs/action/request/Write.d.ts +2 -0
- package/dist/cjs/action/request/Write.d.ts.map +1 -1
- package/dist/cjs/action/request/Write.js.map +1 -1
- package/dist/cjs/action/response/InvokeResult.d.ts +22 -6
- package/dist/cjs/action/response/InvokeResult.d.ts.map +1 -1
- package/dist/cjs/action/server/AttributeReadResponse.d.ts.map +1 -1
- package/dist/cjs/action/server/AttributeReadResponse.js +1 -2
- package/dist/cjs/action/server/AttributeReadResponse.js.map +2 -2
- package/dist/cjs/action/server/AttributeWriteResponse.d.ts.map +1 -1
- package/dist/cjs/action/server/AttributeWriteResponse.js +1 -14
- package/dist/cjs/action/server/AttributeWriteResponse.js.map +1 -1
- package/dist/cjs/action/server/CommandInvokeResponse.d.ts +25 -0
- package/dist/cjs/action/server/CommandInvokeResponse.d.ts.map +1 -0
- package/dist/cjs/action/server/CommandInvokeResponse.js +331 -0
- package/dist/cjs/action/server/CommandInvokeResponse.js.map +6 -0
- package/dist/cjs/action/server/EventReadResponse.js +1 -1
- package/dist/cjs/action/server/ServerInteraction.d.ts +1 -3
- package/dist/cjs/action/server/ServerInteraction.d.ts.map +1 -1
- package/dist/cjs/action/server/ServerInteraction.js +4 -2
- package/dist/cjs/action/server/ServerInteraction.js.map +1 -1
- package/dist/cjs/action/server/index.d.ts +1 -0
- package/dist/cjs/action/server/index.d.ts.map +1 -1
- package/dist/cjs/action/server/index.js +1 -0
- package/dist/cjs/action/server/index.js.map +1 -1
- package/dist/cjs/cluster/client/AttributeClient.d.ts +2 -0
- package/dist/cjs/cluster/client/AttributeClient.d.ts.map +1 -1
- package/dist/cjs/cluster/client/AttributeClient.js +10 -0
- package/dist/cjs/cluster/client/AttributeClient.js.map +1 -1
- package/dist/cjs/cluster/client/ClusterClientTypes.d.ts +0 -4
- package/dist/cjs/cluster/client/ClusterClientTypes.d.ts.map +1 -1
- package/dist/cjs/cluster/index.d.ts +0 -1
- package/dist/cjs/cluster/index.d.ts.map +1 -1
- package/dist/cjs/cluster/index.js +0 -1
- package/dist/cjs/cluster/index.js.map +1 -1
- package/dist/cjs/events/OccurrenceManager.d.ts +10 -2
- package/dist/cjs/events/OccurrenceManager.d.ts.map +1 -1
- package/dist/cjs/events/OccurrenceManager.js +57 -11
- package/dist/cjs/events/OccurrenceManager.js.map +1 -1
- package/dist/cjs/fabric/Fabric.d.ts +2 -11
- package/dist/cjs/fabric/Fabric.d.ts.map +1 -1
- package/dist/cjs/fabric/Fabric.js +1 -38
- package/dist/cjs/fabric/Fabric.js.map +1 -1
- package/dist/cjs/index.d.ts +0 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interaction/AttributeDataEncoder.d.ts +1 -1
- package/dist/cjs/interaction/InteractionClient.d.ts +13 -0
- package/dist/cjs/interaction/InteractionClient.d.ts.map +1 -1
- package/dist/cjs/interaction/InteractionClient.js +14 -0
- package/dist/cjs/interaction/InteractionClient.js.map +1 -1
- package/dist/cjs/interaction/InteractionMessenger.d.ts +8 -8
- package/dist/cjs/interaction/index.d.ts +0 -1
- package/dist/cjs/interaction/index.d.ts.map +1 -1
- package/dist/cjs/interaction/index.js +0 -1
- package/dist/cjs/interaction/index.js.map +1 -1
- package/dist/cjs/mdns/MdnsScanner.d.ts +23 -1
- package/dist/cjs/mdns/MdnsScanner.d.ts.map +1 -1
- package/dist/cjs/mdns/MdnsScanner.js +124 -11
- package/dist/cjs/mdns/MdnsScanner.js.map +2 -2
- package/dist/esm/action/Interactable.d.ts +1 -1
- package/dist/esm/action/Interactable.d.ts.map +1 -1
- package/dist/esm/action/client/ClientInteraction.d.ts +1 -1
- package/dist/esm/action/client/ClientInteraction.d.ts.map +1 -1
- package/dist/esm/action/client/ClientInteraction.js +50 -8
- package/dist/esm/action/client/ClientInteraction.js.map +1 -1
- package/dist/esm/action/protocols.d.ts +49 -15
- package/dist/esm/action/protocols.d.ts.map +1 -1
- package/dist/esm/action/request/Invoke.d.ts +10 -1
- package/dist/esm/action/request/Invoke.d.ts.map +1 -1
- package/dist/esm/action/request/Invoke.js +17 -5
- package/dist/esm/action/request/Invoke.js.map +1 -1
- package/dist/esm/action/request/Read.d.ts.map +1 -1
- package/dist/esm/action/request/Read.js +1 -1
- package/dist/esm/action/request/Read.js.map +1 -1
- package/dist/esm/action/request/Write.d.ts +2 -0
- package/dist/esm/action/request/Write.d.ts.map +1 -1
- package/dist/esm/action/request/Write.js.map +1 -1
- package/dist/esm/action/response/InvokeResult.d.ts +22 -6
- package/dist/esm/action/response/InvokeResult.d.ts.map +1 -1
- package/dist/esm/action/server/AttributeReadResponse.d.ts.map +1 -1
- package/dist/esm/action/server/AttributeReadResponse.js +1 -1
- package/dist/esm/action/server/AttributeReadResponse.js.map +1 -1
- package/dist/esm/action/server/AttributeWriteResponse.d.ts.map +1 -1
- package/dist/esm/action/server/AttributeWriteResponse.js +2 -15
- package/dist/esm/action/server/AttributeWriteResponse.js.map +1 -1
- package/dist/esm/action/server/CommandInvokeResponse.d.ts +25 -0
- package/dist/esm/action/server/CommandInvokeResponse.d.ts.map +1 -0
- package/dist/esm/action/server/CommandInvokeResponse.js +317 -0
- package/dist/esm/action/server/CommandInvokeResponse.js.map +6 -0
- package/dist/esm/action/server/EventReadResponse.js +1 -1
- package/dist/esm/action/server/ServerInteraction.d.ts +1 -3
- package/dist/esm/action/server/ServerInteraction.d.ts.map +1 -1
- package/dist/esm/action/server/ServerInteraction.js +4 -2
- package/dist/esm/action/server/ServerInteraction.js.map +1 -1
- package/dist/esm/action/server/index.d.ts +1 -0
- package/dist/esm/action/server/index.d.ts.map +1 -1
- package/dist/esm/action/server/index.js +1 -0
- package/dist/esm/action/server/index.js.map +1 -1
- package/dist/esm/cluster/client/AttributeClient.d.ts +2 -0
- package/dist/esm/cluster/client/AttributeClient.d.ts.map +1 -1
- package/dist/esm/cluster/client/AttributeClient.js +10 -0
- package/dist/esm/cluster/client/AttributeClient.js.map +1 -1
- package/dist/esm/cluster/client/ClusterClientTypes.d.ts +0 -4
- package/dist/esm/cluster/client/ClusterClientTypes.d.ts.map +1 -1
- package/dist/esm/cluster/index.d.ts +0 -1
- package/dist/esm/cluster/index.d.ts.map +1 -1
- package/dist/esm/cluster/index.js +0 -1
- package/dist/esm/cluster/index.js.map +1 -1
- package/dist/esm/events/OccurrenceManager.d.ts +10 -2
- package/dist/esm/events/OccurrenceManager.d.ts.map +1 -1
- package/dist/esm/events/OccurrenceManager.js +62 -12
- package/dist/esm/events/OccurrenceManager.js.map +1 -1
- package/dist/esm/fabric/Fabric.d.ts +2 -11
- package/dist/esm/fabric/Fabric.d.ts.map +1 -1
- package/dist/esm/fabric/Fabric.js +1 -38
- package/dist/esm/fabric/Fabric.js.map +1 -1
- package/dist/esm/index.d.ts +0 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interaction/AttributeDataEncoder.d.ts +1 -1
- package/dist/esm/interaction/InteractionClient.d.ts +13 -0
- package/dist/esm/interaction/InteractionClient.d.ts.map +1 -1
- package/dist/esm/interaction/InteractionClient.js +14 -0
- package/dist/esm/interaction/InteractionClient.js.map +1 -1
- package/dist/esm/interaction/InteractionMessenger.d.ts +8 -8
- package/dist/esm/interaction/index.d.ts +0 -1
- package/dist/esm/interaction/index.d.ts.map +1 -1
- package/dist/esm/interaction/index.js +0 -1
- package/dist/esm/interaction/index.js.map +1 -1
- package/dist/esm/mdns/MdnsScanner.d.ts +23 -1
- package/dist/esm/mdns/MdnsScanner.d.ts.map +1 -1
- package/dist/esm/mdns/MdnsScanner.js +127 -11
- package/dist/esm/mdns/MdnsScanner.js.map +2 -2
- package/package.json +6 -6
- package/src/action/Interactable.ts +1 -1
- package/src/action/client/ClientInteraction.ts +53 -16
- package/src/action/protocols.ts +70 -16
- package/src/action/request/Invoke.ts +32 -5
- package/src/action/request/Read.ts +1 -1
- package/src/action/request/Write.ts +4 -1
- package/src/action/response/InvokeResult.ts +26 -6
- package/src/action/response/ReadResult.ts +1 -1
- package/src/action/server/AttributeReadResponse.ts +1 -1
- package/src/action/server/AttributeWriteResponse.ts +2 -20
- package/src/action/server/CommandInvokeResponse.ts +427 -0
- package/src/action/server/EventReadResponse.ts +1 -1
- package/src/action/server/ServerInteraction.ts +6 -5
- package/src/action/server/index.ts +1 -0
- package/src/cluster/client/AttributeClient.ts +12 -0
- package/src/cluster/client/ClusterClientTypes.ts +0 -6
- package/src/cluster/index.ts +0 -1
- package/src/events/OccurrenceManager.ts +91 -11
- package/src/fabric/Fabric.ts +1 -49
- package/src/index.ts +0 -1
- package/src/interaction/InteractionClient.ts +24 -0
- package/src/interaction/index.ts +0 -1
- package/src/mdns/MdnsScanner.ts +187 -12
- package/dist/cjs/cluster/server/AttributeServer.d.ts +0 -307
- package/dist/cjs/cluster/server/AttributeServer.d.ts.map +0 -1
- package/dist/cjs/cluster/server/AttributeServer.js +0 -736
- package/dist/cjs/cluster/server/AttributeServer.js.map +0 -6
- package/dist/cjs/cluster/server/ClusterDatasource.d.ts +0 -16
- package/dist/cjs/cluster/server/ClusterDatasource.d.ts.map +0 -1
- package/dist/cjs/cluster/server/ClusterDatasource.js +0 -22
- package/dist/cjs/cluster/server/ClusterDatasource.js.map +0 -6
- package/dist/cjs/cluster/server/ClusterServer.d.ts +0 -40
- package/dist/cjs/cluster/server/ClusterServer.d.ts.map +0 -1
- package/dist/cjs/cluster/server/ClusterServer.js +0 -22
- package/dist/cjs/cluster/server/ClusterServer.js.map +0 -6
- package/dist/cjs/cluster/server/CommandServer.d.ts +0 -34
- package/dist/cjs/cluster/server/CommandServer.d.ts.map +0 -1
- package/dist/cjs/cluster/server/CommandServer.js +0 -76
- package/dist/cjs/cluster/server/CommandServer.js.map +0 -6
- package/dist/cjs/cluster/server/EventServer.d.ts +0 -42
- package/dist/cjs/cluster/server/EventServer.d.ts.map +0 -1
- package/dist/cjs/cluster/server/EventServer.js +0 -152
- package/dist/cjs/cluster/server/EventServer.js.map +0 -6
- package/dist/cjs/cluster/server/index.d.ts +0 -11
- package/dist/cjs/cluster/server/index.d.ts.map +0 -1
- package/dist/cjs/cluster/server/index.js +0 -28
- package/dist/cjs/cluster/server/index.js.map +0 -6
- package/dist/cjs/endpoint/EndpointInterface.d.ts +0 -37
- package/dist/cjs/endpoint/EndpointInterface.d.ts.map +0 -1
- package/dist/cjs/endpoint/EndpointInterface.js +0 -22
- package/dist/cjs/endpoint/EndpointInterface.js.map +0 -6
- package/dist/cjs/endpoint/EndpointStructureLogger.d.ts +0 -31
- package/dist/cjs/endpoint/EndpointStructureLogger.d.ts.map +0 -1
- package/dist/cjs/endpoint/EndpointStructureLogger.js +0 -230
- package/dist/cjs/endpoint/EndpointStructureLogger.js.map +0 -6
- package/dist/cjs/endpoint/index.d.ts +0 -8
- package/dist/cjs/endpoint/index.d.ts.map +0 -1
- package/dist/cjs/endpoint/index.js +0 -25
- package/dist/cjs/endpoint/index.js.map +0 -6
- package/dist/cjs/interaction/InteractionEndpointStructure.d.ts +0 -95
- package/dist/cjs/interaction/InteractionEndpointStructure.d.ts.map +0 -1
- package/dist/cjs/interaction/InteractionEndpointStructure.js +0 -359
- package/dist/cjs/interaction/InteractionEndpointStructure.js.map +0 -6
- package/dist/esm/cluster/server/AttributeServer.d.ts +0 -307
- package/dist/esm/cluster/server/AttributeServer.d.ts.map +0 -1
- package/dist/esm/cluster/server/AttributeServer.js +0 -729
- package/dist/esm/cluster/server/AttributeServer.js.map +0 -6
- package/dist/esm/cluster/server/ClusterDatasource.d.ts +0 -16
- package/dist/esm/cluster/server/ClusterDatasource.d.ts.map +0 -1
- package/dist/esm/cluster/server/ClusterDatasource.js +0 -6
- package/dist/esm/cluster/server/ClusterDatasource.js.map +0 -6
- package/dist/esm/cluster/server/ClusterServer.d.ts +0 -40
- package/dist/esm/cluster/server/ClusterServer.d.ts.map +0 -1
- package/dist/esm/cluster/server/ClusterServer.js +0 -6
- package/dist/esm/cluster/server/ClusterServer.js.map +0 -6
- package/dist/esm/cluster/server/CommandServer.d.ts +0 -34
- package/dist/esm/cluster/server/CommandServer.d.ts.map +0 -1
- package/dist/esm/cluster/server/CommandServer.js +0 -56
- package/dist/esm/cluster/server/CommandServer.js.map +0 -6
- package/dist/esm/cluster/server/EventServer.d.ts +0 -42
- package/dist/esm/cluster/server/EventServer.d.ts.map +0 -1
- package/dist/esm/cluster/server/EventServer.js +0 -141
- package/dist/esm/cluster/server/EventServer.js.map +0 -6
- package/dist/esm/cluster/server/index.d.ts +0 -11
- package/dist/esm/cluster/server/index.d.ts.map +0 -1
- package/dist/esm/cluster/server/index.js +0 -11
- package/dist/esm/cluster/server/index.js.map +0 -6
- package/dist/esm/endpoint/EndpointInterface.d.ts +0 -37
- package/dist/esm/endpoint/EndpointInterface.d.ts.map +0 -1
- package/dist/esm/endpoint/EndpointInterface.js +0 -6
- package/dist/esm/endpoint/EndpointInterface.js.map +0 -6
- package/dist/esm/endpoint/EndpointStructureLogger.d.ts +0 -31
- package/dist/esm/endpoint/EndpointStructureLogger.d.ts.map +0 -1
- package/dist/esm/endpoint/EndpointStructureLogger.js +0 -210
- package/dist/esm/endpoint/EndpointStructureLogger.js.map +0 -6
- package/dist/esm/endpoint/index.d.ts +0 -8
- package/dist/esm/endpoint/index.d.ts.map +0 -1
- package/dist/esm/endpoint/index.js +0 -8
- package/dist/esm/endpoint/index.js.map +0 -6
- package/dist/esm/interaction/InteractionEndpointStructure.d.ts +0 -95
- package/dist/esm/interaction/InteractionEndpointStructure.d.ts.map +0 -1
- package/dist/esm/interaction/InteractionEndpointStructure.js +0 -355
- package/dist/esm/interaction/InteractionEndpointStructure.js.map +0 -6
- package/src/cluster/server/AttributeServer.ts +0 -997
- package/src/cluster/server/ClusterDatasource.ts +0 -17
- package/src/cluster/server/ClusterServer.ts +0 -46
- package/src/cluster/server/CommandServer.ts +0 -89
- package/src/cluster/server/EventServer.ts +0 -202
- package/src/cluster/server/index.ts +0 -11
- package/src/endpoint/EndpointInterface.ts +0 -41
- package/src/endpoint/EndpointStructureLogger.ts +0 -270
- package/src/endpoint/index.ts +0 -8
- package/src/interaction/InteractionEndpointStructure.ts +0 -510
|
@@ -1,736 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var AttributeServer_exports = {};
|
|
20
|
-
__export(AttributeServer_exports, {
|
|
21
|
-
AttributeServer: () => AttributeServer,
|
|
22
|
-
BaseAttributeServer: () => BaseAttributeServer,
|
|
23
|
-
FabricScopeError: () => FabricScopeError,
|
|
24
|
-
FabricScopedAttributeServer: () => FabricScopedAttributeServer,
|
|
25
|
-
FixedAttributeServer: () => FixedAttributeServer,
|
|
26
|
-
createAttributeServer: () => createAttributeServer,
|
|
27
|
-
genericFabricScopedAttributeGetter: () => genericFabricScopedAttributeGetter,
|
|
28
|
-
genericFabricScopedAttributeGetterFromFabric: () => genericFabricScopedAttributeGetterFromFabric,
|
|
29
|
-
genericFabricScopedAttributeSetter: () => genericFabricScopedAttributeSetter,
|
|
30
|
-
genericFabricScopedAttributeSetterForFabric: () => genericFabricScopedAttributeSetterForFabric
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(AttributeServer_exports);
|
|
33
|
-
var import_general = require("#general");
|
|
34
|
-
var import_model = require("#model");
|
|
35
|
-
var import_types = require("#types");
|
|
36
|
-
var import_SecureSession = require("../../session/SecureSession.js");
|
|
37
|
-
/**
|
|
38
|
-
* @license
|
|
39
|
-
* Copyright 2022-2025 Matter.js Authors
|
|
40
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
41
|
-
*/
|
|
42
|
-
const logger = import_general.Logger.get("AttributeServer");
|
|
43
|
-
const FabricIndexName = (0, import_general.camelize)(import_model.FabricIndex.name);
|
|
44
|
-
class FabricScopeError extends import_general.MatterError {
|
|
45
|
-
}
|
|
46
|
-
function createAttributeServer(clusterDef, attributeDef, attributeName, initValue, datasource, getter, setter, validator) {
|
|
47
|
-
const {
|
|
48
|
-
id,
|
|
49
|
-
schema,
|
|
50
|
-
writable,
|
|
51
|
-
fabricScoped,
|
|
52
|
-
fixed,
|
|
53
|
-
omitChanges,
|
|
54
|
-
timed,
|
|
55
|
-
default: defaultValue,
|
|
56
|
-
readAcl,
|
|
57
|
-
writeAcl
|
|
58
|
-
} = attributeDef;
|
|
59
|
-
if (fixed) {
|
|
60
|
-
return new FixedAttributeServer(
|
|
61
|
-
id,
|
|
62
|
-
attributeName,
|
|
63
|
-
readAcl,
|
|
64
|
-
writeAcl,
|
|
65
|
-
schema,
|
|
66
|
-
writable,
|
|
67
|
-
false,
|
|
68
|
-
timed,
|
|
69
|
-
initValue,
|
|
70
|
-
defaultValue,
|
|
71
|
-
datasource,
|
|
72
|
-
getter
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
if (fabricScoped) {
|
|
76
|
-
return new FabricScopedAttributeServer(
|
|
77
|
-
id,
|
|
78
|
-
attributeName,
|
|
79
|
-
readAcl,
|
|
80
|
-
writeAcl,
|
|
81
|
-
schema,
|
|
82
|
-
writable,
|
|
83
|
-
!omitChanges,
|
|
84
|
-
timed,
|
|
85
|
-
initValue,
|
|
86
|
-
defaultValue,
|
|
87
|
-
clusterDef,
|
|
88
|
-
datasource,
|
|
89
|
-
getter,
|
|
90
|
-
setter,
|
|
91
|
-
validator
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
return new AttributeServer(
|
|
95
|
-
id,
|
|
96
|
-
attributeName,
|
|
97
|
-
readAcl,
|
|
98
|
-
writeAcl,
|
|
99
|
-
schema,
|
|
100
|
-
writable,
|
|
101
|
-
!omitChanges,
|
|
102
|
-
timed,
|
|
103
|
-
initValue,
|
|
104
|
-
defaultValue,
|
|
105
|
-
datasource,
|
|
106
|
-
getter,
|
|
107
|
-
setter,
|
|
108
|
-
validator
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
class BaseAttributeServer {
|
|
112
|
-
constructor(id, name, readAcl, writeAcl, schema, isWritable, isSubscribable, requiresTimedInteraction, initValue, defaultValue) {
|
|
113
|
-
this.id = id;
|
|
114
|
-
this.name = name;
|
|
115
|
-
this.schema = schema;
|
|
116
|
-
this.isWritable = isWritable;
|
|
117
|
-
this.isSubscribable = isSubscribable;
|
|
118
|
-
this.requiresTimedInteraction = requiresTimedInteraction;
|
|
119
|
-
this.#readAcl = readAcl;
|
|
120
|
-
this.#writeAcl = writeAcl;
|
|
121
|
-
try {
|
|
122
|
-
this.validateWithSchema(initValue);
|
|
123
|
-
this.value = initValue;
|
|
124
|
-
} catch (error) {
|
|
125
|
-
logger.warn(
|
|
126
|
-
`Attribute value to initialize for ${name} has an invalid value ${import_general.Diagnostic.json(
|
|
127
|
-
initValue
|
|
128
|
-
)}. Restore to default ${import_general.Diagnostic.json(defaultValue)}`
|
|
129
|
-
);
|
|
130
|
-
if (defaultValue === void 0) {
|
|
131
|
-
throw new import_general.ImplementationError(`Attribute value to initialize for ${name} cannot be undefined.`);
|
|
132
|
-
}
|
|
133
|
-
this.validateWithSchema(defaultValue);
|
|
134
|
-
this.value = defaultValue;
|
|
135
|
-
}
|
|
136
|
-
this.defaultValue = this.value;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* The value is undefined when getter/setter are used. But we still handle the version number here.
|
|
140
|
-
*/
|
|
141
|
-
value = void 0;
|
|
142
|
-
endpoint;
|
|
143
|
-
defaultValue;
|
|
144
|
-
#readAcl;
|
|
145
|
-
#writeAcl;
|
|
146
|
-
get hasFabricSensitiveData() {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
validateWithSchema(value) {
|
|
150
|
-
try {
|
|
151
|
-
this.schema.validate(value);
|
|
152
|
-
} catch (e) {
|
|
153
|
-
import_types.ValidationError.accept(e);
|
|
154
|
-
e.message = `Validation error for attribute "${this.name}"${e.fieldName !== void 0 ? ` in field ${e.fieldName}` : ""}: ${e.message}`;
|
|
155
|
-
throw e;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
assignToEndpoint(endpoint) {
|
|
159
|
-
this.endpoint = endpoint;
|
|
160
|
-
}
|
|
161
|
-
get writeAcl() {
|
|
162
|
-
return this.#writeAcl ?? import_model.AccessLevel.Operate;
|
|
163
|
-
}
|
|
164
|
-
get readAcl() {
|
|
165
|
-
return this.#readAcl ?? import_model.AccessLevel.View;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
class FixedAttributeServer extends BaseAttributeServer {
|
|
169
|
-
constructor(id, name, readAcl, writeAcl, schema, isWritable, isSubscribable, requiresTimedInteraction, initValue, defaultValue, datasource, getter) {
|
|
170
|
-
super(
|
|
171
|
-
id,
|
|
172
|
-
name,
|
|
173
|
-
readAcl,
|
|
174
|
-
writeAcl,
|
|
175
|
-
schema,
|
|
176
|
-
isWritable,
|
|
177
|
-
isSubscribable,
|
|
178
|
-
requiresTimedInteraction,
|
|
179
|
-
initValue,
|
|
180
|
-
defaultValue
|
|
181
|
-
);
|
|
182
|
-
this.datasource = datasource;
|
|
183
|
-
if (getter === void 0) {
|
|
184
|
-
this.getter = () => {
|
|
185
|
-
if (this.value === void 0) {
|
|
186
|
-
throw new import_general.InternalError(`Attribute value for attribute "${name}" is not initialized.`);
|
|
187
|
-
}
|
|
188
|
-
return this.value;
|
|
189
|
-
};
|
|
190
|
-
} else {
|
|
191
|
-
this.getter = getter;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
isFixed = true;
|
|
195
|
-
getter;
|
|
196
|
-
/**
|
|
197
|
-
* Get the value of the attribute. This method is used by the Interaction model to read the value of the attribute
|
|
198
|
-
* and includes the ACL check. It should not be used locally in the code!
|
|
199
|
-
*
|
|
200
|
-
* If a getter is defined the value is determined by that getter method.
|
|
201
|
-
*/
|
|
202
|
-
get(session, isFabricFiltered, message) {
|
|
203
|
-
return this.getter(session, this.endpoint, isFabricFiltered, message);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Get the value of the attribute including the version number. This method is used by the Interaction model to read
|
|
207
|
-
* the value of the attribute and includes the ACL check. It should not be used locally in the code!
|
|
208
|
-
*
|
|
209
|
-
* If a getter is defined the value is determined by that getter method. The version number is always 0 for fixed
|
|
210
|
-
* attributes.
|
|
211
|
-
*/
|
|
212
|
-
getWithVersion(session, isFabricFiltered, message) {
|
|
213
|
-
return { version: this.datasource.version, value: this.get(session, isFabricFiltered, message) };
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Get the value of the attribute locally. This method should be used locally in the code and does not include the
|
|
217
|
-
* ACL check.
|
|
218
|
-
* If a getter is defined the value is determined by that getter method.
|
|
219
|
-
*/
|
|
220
|
-
getLocal() {
|
|
221
|
-
return this.getter(void 0, this.endpoint);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Initialize the value of the attribute, used when a persisted value is set initially or when values needs to be
|
|
225
|
-
* adjusted before the Device gets announced. Do not use this method to change values when the device is in use!
|
|
226
|
-
* If a getter or setter is defined the value must be undefined The version number must also be undefined.
|
|
227
|
-
*/
|
|
228
|
-
init(value) {
|
|
229
|
-
if (value === void 0) {
|
|
230
|
-
throw new import_general.InternalError(`Cannot initialize fixed attribute "${this.name}" with undefined value.`);
|
|
231
|
-
}
|
|
232
|
-
this.validateWithSchema(value);
|
|
233
|
-
this.value = value;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* Add an internal listener that is called when the value of the attribute changes. The listener is called with the
|
|
237
|
-
* new value and the version number.
|
|
238
|
-
*/
|
|
239
|
-
addValueChangeListener(_listener) {
|
|
240
|
-
}
|
|
241
|
-
/**
|
|
242
|
-
* Remove an internal listener.
|
|
243
|
-
*/
|
|
244
|
-
removeValueChangeListener(_listener) {
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Add an external listener that is called when the value of the attribute changes. The listener is called with the
|
|
248
|
-
* new value and the old value.
|
|
249
|
-
*/
|
|
250
|
-
addValueSetListener(_listener) {
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Add an external listener that is called when the value of the attribute changes. The listener is called with the
|
|
254
|
-
* new value and the old value. This method is a convenient alias for addValueSetListener.
|
|
255
|
-
*/
|
|
256
|
-
subscribe(_listener) {
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Remove an external listener.
|
|
260
|
-
*/
|
|
261
|
-
removeValueSetListener(_listener) {
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
class AttributeServer extends FixedAttributeServer {
|
|
265
|
-
isFixed = false;
|
|
266
|
-
valueChangeListeners = new Array();
|
|
267
|
-
valueSetListeners = new Array();
|
|
268
|
-
setter;
|
|
269
|
-
validator;
|
|
270
|
-
delayedChangeData = void 0;
|
|
271
|
-
constructor(id, name, readAcl, writeAcl, schema, isWritable, isSubscribable, requiresTimedInteraction, initValue, defaultValue, datasource, getter, setter, validator) {
|
|
272
|
-
if (isWritable && (getter === void 0 || setter === void 0) && !(getter === void 0 && setter === void 0)) {
|
|
273
|
-
throw new import_general.ImplementationError(
|
|
274
|
-
`Getter and setter must be implemented together for writeable attribute "${name}".`
|
|
275
|
-
);
|
|
276
|
-
}
|
|
277
|
-
super(
|
|
278
|
-
id,
|
|
279
|
-
name,
|
|
280
|
-
readAcl,
|
|
281
|
-
writeAcl,
|
|
282
|
-
schema,
|
|
283
|
-
isWritable,
|
|
284
|
-
isSubscribable,
|
|
285
|
-
requiresTimedInteraction,
|
|
286
|
-
initValue,
|
|
287
|
-
defaultValue,
|
|
288
|
-
datasource,
|
|
289
|
-
getter
|
|
290
|
-
);
|
|
291
|
-
if (setter === void 0) {
|
|
292
|
-
this.setter = (value) => {
|
|
293
|
-
const oldValue = this.value;
|
|
294
|
-
this.value = value;
|
|
295
|
-
return !(0, import_general.isDeepEqual)(value, oldValue);
|
|
296
|
-
};
|
|
297
|
-
} else {
|
|
298
|
-
this.setter = setter;
|
|
299
|
-
}
|
|
300
|
-
this.validator = (value, session, endpoint) => {
|
|
301
|
-
this.validateWithSchema(value);
|
|
302
|
-
if (validator !== void 0) {
|
|
303
|
-
validator(value, session, endpoint);
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* Initialize the value of the attribute, used when a persisted value is set initially or when values needs to be
|
|
309
|
-
* adjusted before the Device gets announced. Do not use this method to change values when the device is in use!
|
|
310
|
-
*/
|
|
311
|
-
init(value) {
|
|
312
|
-
if (value === void 0) {
|
|
313
|
-
value = this.getter(void 0, this.endpoint);
|
|
314
|
-
}
|
|
315
|
-
if (value === void 0) {
|
|
316
|
-
throw new import_general.InternalError(`Cannot initialize attribute "${this.name}" with undefined value.`);
|
|
317
|
-
}
|
|
318
|
-
this.validator(value, void 0, this.endpoint);
|
|
319
|
-
this.value = value;
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Set the value of the attribute. This method is used by the Interaction model to write the value of the attribute
|
|
323
|
-
* and includes the ACL check. It should not be used locally in the code!
|
|
324
|
-
*
|
|
325
|
-
* If a setter is defined this setter method is called to store the value.
|
|
326
|
-
*
|
|
327
|
-
* Listeners are called when the value changes (internal listeners) or in any case (external listeners).
|
|
328
|
-
*/
|
|
329
|
-
set(value, session, message, delayChangeEvents = false) {
|
|
330
|
-
if (!this.isWritable) {
|
|
331
|
-
throw new import_types.StatusResponseError(`Attribute "${this.name}" is not writable.`, import_types.StatusCode.UnsupportedWrite);
|
|
332
|
-
}
|
|
333
|
-
this.setRemote(value, session, message, delayChangeEvents);
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Method that contains the logic to set a value "from remote" (e.g. from a client).
|
|
337
|
-
*/
|
|
338
|
-
setRemote(value, session, message, delayChangeEvents = false) {
|
|
339
|
-
this.processSet(value, session, message, delayChangeEvents);
|
|
340
|
-
this.value = value;
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* Set the value of the attribute locally. This method should be used locally in the code and does not include the
|
|
344
|
-
* ACL check.
|
|
345
|
-
*
|
|
346
|
-
* If a setter is defined this setter method is called to validate and store the value.
|
|
347
|
-
*
|
|
348
|
-
* Else if a validator is defined the value is validated before it is stored.
|
|
349
|
-
*
|
|
350
|
-
* Listeners are called when the value changes (internal listeners) or in any case (external listeners).
|
|
351
|
-
*/
|
|
352
|
-
setLocal(value) {
|
|
353
|
-
this.processSet(value, void 0);
|
|
354
|
-
this.value = value;
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Helper Method to process the set of a value in a generic way. This method is used internally.
|
|
358
|
-
*/
|
|
359
|
-
processSet(value, session, message, delayChangeEvents = false) {
|
|
360
|
-
this.validator(value, session, this.endpoint);
|
|
361
|
-
const oldValue = this.getter(session, this.endpoint, void 0, message);
|
|
362
|
-
const valueChanged = this.setter(value, session, this.endpoint, message);
|
|
363
|
-
if (delayChangeEvents) {
|
|
364
|
-
this.delayedChangeData = {
|
|
365
|
-
oldValue: this.delayedChangeData?.oldValue ?? oldValue,
|
|
366
|
-
// We keep the oldest value
|
|
367
|
-
newValue: value,
|
|
368
|
-
changed: !!this.delayedChangeData?.changed || valueChanged
|
|
369
|
-
// We combine the changed flag
|
|
370
|
-
};
|
|
371
|
-
logger.info(`Delay change for attribute "${this.name}" with value ${import_general.Diagnostic.json(value)}`);
|
|
372
|
-
} else {
|
|
373
|
-
this.handleVersionAndTriggerListeners(value, oldValue, valueChanged);
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
triggerDelayedChangeEvents() {
|
|
377
|
-
if (this.delayedChangeData !== void 0) {
|
|
378
|
-
const { oldValue, newValue, changed } = this.delayedChangeData;
|
|
379
|
-
this.delayedChangeData = void 0;
|
|
380
|
-
logger.info(`Trigger delayed change for attribute "${this.name}" with value ${import_general.Diagnostic.json(newValue)}`);
|
|
381
|
-
this.handleVersionAndTriggerListeners(newValue, oldValue, changed);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Helper Method to handle needed version increases and trigger the relevant listeners. This method is used
|
|
386
|
-
* internally.
|
|
387
|
-
*/
|
|
388
|
-
handleVersionAndTriggerListeners(value, oldValue, considerVersionChanged) {
|
|
389
|
-
if (considerVersionChanged) {
|
|
390
|
-
const version = this.datasource.increaseVersion();
|
|
391
|
-
this.valueChangeListeners.forEach((listener) => listener(value, version));
|
|
392
|
-
}
|
|
393
|
-
if (oldValue !== void 0) {
|
|
394
|
-
this.valueSetListeners.forEach((listener) => listener(value, oldValue));
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* When the value is handled by getter or setter methods and is changed by other processes this method can be used
|
|
399
|
-
* to notify the attribute server that the value has changed. This will increase the version number and trigger the
|
|
400
|
-
* listeners.
|
|
401
|
-
*
|
|
402
|
-
* ACL checks needs to be performed before calling this method.
|
|
403
|
-
*/
|
|
404
|
-
updated(session) {
|
|
405
|
-
const oldValue = this.value ?? this.defaultValue;
|
|
406
|
-
try {
|
|
407
|
-
this.value = this.get(session, false);
|
|
408
|
-
} catch (e) {
|
|
409
|
-
import_SecureSession.NoAssociatedFabricError.accept(e);
|
|
410
|
-
if (this.value === void 0) {
|
|
411
|
-
this.value = this.defaultValue;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
this.handleVersionAndTriggerListeners(this.value, oldValue, true);
|
|
415
|
-
}
|
|
416
|
-
/**
|
|
417
|
-
* When the value is handled by getter or setter methods and is changed by other processes and no session from the
|
|
418
|
-
* originating process is known this method can be used to notify the attribute server that the value has changed.
|
|
419
|
-
* This will increase the version number and trigger the listeners.
|
|
420
|
-
*
|
|
421
|
-
* ACL checks needs to be performed before calling this method.
|
|
422
|
-
*/
|
|
423
|
-
updatedLocal() {
|
|
424
|
-
const oldValue = this.value ?? this.defaultValue;
|
|
425
|
-
this.value = this.getLocal();
|
|
426
|
-
this.handleVersionAndTriggerListeners(this.value, oldValue, true);
|
|
427
|
-
}
|
|
428
|
-
/**
|
|
429
|
-
* Add an internal listener that is called when the value of the attribute changes. The listener is called with the
|
|
430
|
-
* new value and the version number.
|
|
431
|
-
*/
|
|
432
|
-
addValueChangeListener(listener) {
|
|
433
|
-
this.valueChangeListeners.push(listener);
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* Remove an internal listener.
|
|
437
|
-
*/
|
|
438
|
-
removeValueChangeListener(listener) {
|
|
439
|
-
const entryIndex = this.valueChangeListeners.indexOf(listener);
|
|
440
|
-
if (entryIndex !== -1) {
|
|
441
|
-
this.valueChangeListeners.splice(entryIndex, 1);
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
/**
|
|
445
|
-
* Add an external listener that is called when the value of the attribute changes. The listener is called with the
|
|
446
|
-
* new value and the old value.
|
|
447
|
-
*/
|
|
448
|
-
addValueSetListener(listener) {
|
|
449
|
-
this.valueSetListeners.push(listener);
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Add an external listener that is called when the value of the attribute changes. The listener is called with the
|
|
453
|
-
* new value and the old value. This method is a convenient alias for addValueSetListener.
|
|
454
|
-
*/
|
|
455
|
-
subscribe(listener) {
|
|
456
|
-
this.addValueSetListener(listener);
|
|
457
|
-
}
|
|
458
|
-
/**
|
|
459
|
-
* Remove an external listener.
|
|
460
|
-
*/
|
|
461
|
-
removeValueSetListener(listener) {
|
|
462
|
-
const entryIndex = this.valueSetListeners.indexOf(listener);
|
|
463
|
-
if (entryIndex !== -1) {
|
|
464
|
-
this.valueSetListeners.splice(entryIndex, 1);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
function genericFabricScopedAttributeGetterFromFabric(fabric, cluster, attributeName, defaultValue) {
|
|
469
|
-
const data = fabric.getScopedClusterDataValue(cluster, attributeName);
|
|
470
|
-
return data?.value ?? defaultValue;
|
|
471
|
-
}
|
|
472
|
-
function genericFabricScopedAttributeGetter(session, isFabricFiltered, cluster, attributeName, defaultValue, fabrics) {
|
|
473
|
-
if (session === void 0) {
|
|
474
|
-
throw new FabricScopeError(`Session is required for fabric scoped attribute ${attributeName}`);
|
|
475
|
-
}
|
|
476
|
-
if (isFabricFiltered) {
|
|
477
|
-
(0, import_SecureSession.assertSecureSession)(session);
|
|
478
|
-
return genericFabricScopedAttributeGetterFromFabric(
|
|
479
|
-
session.associatedFabric,
|
|
480
|
-
cluster,
|
|
481
|
-
attributeName,
|
|
482
|
-
defaultValue
|
|
483
|
-
);
|
|
484
|
-
} else {
|
|
485
|
-
const values = new Array();
|
|
486
|
-
for (const fabric of fabrics) {
|
|
487
|
-
const value = genericFabricScopedAttributeGetterFromFabric(fabric, cluster, attributeName, defaultValue);
|
|
488
|
-
if (!Array.isArray(value)) {
|
|
489
|
-
throw new FabricScopeError(
|
|
490
|
-
`Fabric scoped attribute "${attributeName}" can only be read for all fabrics if they are arrays.`
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
values.push(...value);
|
|
494
|
-
}
|
|
495
|
-
return values;
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
function genericFabricScopedAttributeSetterForFabric(fabric, cluster, attributeName, value, defaultValue) {
|
|
499
|
-
const oldValue = genericFabricScopedAttributeGetterFromFabric(fabric, cluster, attributeName, defaultValue);
|
|
500
|
-
if (!(0, import_general.isDeepEqual)(value, oldValue)) {
|
|
501
|
-
const setResult = fabric.setScopedClusterDataValue(cluster, attributeName, { value });
|
|
502
|
-
if (import_general.MaybePromise.is(setResult)) {
|
|
503
|
-
throw new import_general.ImplementationError(
|
|
504
|
-
"Seems like an Asynchronous Storage is used with Legacy code paths which is forbidden!"
|
|
505
|
-
);
|
|
506
|
-
}
|
|
507
|
-
return true;
|
|
508
|
-
}
|
|
509
|
-
return false;
|
|
510
|
-
}
|
|
511
|
-
function genericFabricScopedAttributeSetter(value, session, cluster, attributeName, defaultValue) {
|
|
512
|
-
if (session === void 0) {
|
|
513
|
-
throw new FabricScopeError(`Session is required for fabric scoped attribute "${attributeName}".`);
|
|
514
|
-
}
|
|
515
|
-
(0, import_SecureSession.assertSecureSession)(session);
|
|
516
|
-
const fabric = session.associatedFabric;
|
|
517
|
-
return genericFabricScopedAttributeSetterForFabric(fabric, cluster, attributeName, value, defaultValue);
|
|
518
|
-
}
|
|
519
|
-
class FabricScopedAttributeServer extends AttributeServer {
|
|
520
|
-
constructor(id, name, readAcl, writeAcl, schema, isWritable, isSubscribable, requiresTimedInteraction, initValue, defaultValue, cluster, datasource, getter, setter, validator) {
|
|
521
|
-
if (isWritable && (getter === void 0 || setter === void 0) && !(getter === void 0 && setter === void 0)) {
|
|
522
|
-
throw new import_general.ImplementationError(
|
|
523
|
-
`Getter and setter must be implemented together for writeable fabric scoped attribute "${name}".`
|
|
524
|
-
);
|
|
525
|
-
}
|
|
526
|
-
let isCustomGetter = false;
|
|
527
|
-
if (getter === void 0) {
|
|
528
|
-
getter = (session, _endpoint, isFabricFiltered) => {
|
|
529
|
-
if (session === void 0)
|
|
530
|
-
throw new FabricScopeError(`Session is required for fabric scoped attribute ${name}`);
|
|
531
|
-
if (isFabricFiltered === true) {
|
|
532
|
-
(0, import_SecureSession.assertSecureSession)(session);
|
|
533
|
-
return this.getLocalForFabric(session.associatedFabric);
|
|
534
|
-
} else {
|
|
535
|
-
const values = new Array();
|
|
536
|
-
for (const fabric of datasource.fabrics) {
|
|
537
|
-
const value = this.getLocalForFabric(fabric);
|
|
538
|
-
if (!Array.isArray(value)) {
|
|
539
|
-
throw new FabricScopeError(
|
|
540
|
-
`Fabric scoped attribute "${name}" can only be read for all fabrics if they are arrays.`
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
values.push(...value);
|
|
544
|
-
}
|
|
545
|
-
return values;
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
} else {
|
|
549
|
-
isCustomGetter = true;
|
|
550
|
-
}
|
|
551
|
-
let isCustomSetter = false;
|
|
552
|
-
if (setter === void 0) {
|
|
553
|
-
setter = (value, session) => genericFabricScopedAttributeSetter(value, session, this.cluster, this.name, this.defaultValue);
|
|
554
|
-
} else {
|
|
555
|
-
isCustomSetter = true;
|
|
556
|
-
}
|
|
557
|
-
super(
|
|
558
|
-
id,
|
|
559
|
-
name,
|
|
560
|
-
readAcl,
|
|
561
|
-
writeAcl,
|
|
562
|
-
schema,
|
|
563
|
-
isWritable,
|
|
564
|
-
isSubscribable,
|
|
565
|
-
requiresTimedInteraction,
|
|
566
|
-
initValue,
|
|
567
|
-
defaultValue,
|
|
568
|
-
datasource,
|
|
569
|
-
getter,
|
|
570
|
-
setter,
|
|
571
|
-
validator
|
|
572
|
-
);
|
|
573
|
-
this.cluster = cluster;
|
|
574
|
-
this.isCustomGetter = isCustomGetter;
|
|
575
|
-
this.isCustomSetter = isCustomSetter;
|
|
576
|
-
this.#determineSensitiveFieldsToRemove();
|
|
577
|
-
}
|
|
578
|
-
isCustomGetter;
|
|
579
|
-
isCustomSetter;
|
|
580
|
-
fabricSensitiveElementsToRemove = new Array();
|
|
581
|
-
#determineSensitiveFieldsToRemove() {
|
|
582
|
-
const clusterFromModel = import_model.MatterModel.standard.get(import_model.ClusterModel, this.cluster.id);
|
|
583
|
-
if (clusterFromModel === void 0) {
|
|
584
|
-
logger.debug(`${this.cluster.name}: Cluster for Fabric scoped element not found in Model, ignore`);
|
|
585
|
-
return;
|
|
586
|
-
}
|
|
587
|
-
const attributeFromModel = clusterFromModel.get(import_model.AttributeModel, this.id);
|
|
588
|
-
if (attributeFromModel === void 0) {
|
|
589
|
-
logger.debug(
|
|
590
|
-
`${this.cluster.name}.${this.id}: Attribute for Fabric scoped element not found in Model, ignore`
|
|
591
|
-
);
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
if (!attributeFromModel.fabricScoped) {
|
|
595
|
-
logger.debug(`${this.cluster.name}.${this.id}: Attribute is not Fabric scoped in model, ignore`);
|
|
596
|
-
return;
|
|
597
|
-
}
|
|
598
|
-
if (attributeFromModel.children.length !== 1) {
|
|
599
|
-
logger.debug(`${this.cluster.name}.${this.id}: Attribute has not exactly one child, ignore`);
|
|
600
|
-
return;
|
|
601
|
-
}
|
|
602
|
-
const type = attributeFromModel.children[0].type;
|
|
603
|
-
if (type === void 0) {
|
|
604
|
-
logger.debug(`${this.cluster.name}.${this.id}: Attribute field has no type, ignore`);
|
|
605
|
-
return;
|
|
606
|
-
}
|
|
607
|
-
const dataType = clusterFromModel.get(import_model.DatatypeModel, type);
|
|
608
|
-
if (dataType === void 0) {
|
|
609
|
-
logger.debug(`${this.cluster.name}.${this.id}: DataType ${type} not found in model, ignore`);
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
dataType.children.filter((field) => field.fabricSensitive).forEach((field) => this.fabricSensitiveElementsToRemove.push((0, import_general.camelize)(field.name)));
|
|
613
|
-
}
|
|
614
|
-
get hasFabricSensitiveData() {
|
|
615
|
-
return this.fabricSensitiveElementsToRemove.length > 0;
|
|
616
|
-
}
|
|
617
|
-
/**
|
|
618
|
-
* Sanitize the value of the attribute by removing fabric sensitive fields that do not belong to the
|
|
619
|
-
* associated fabric
|
|
620
|
-
*/
|
|
621
|
-
sanitizeFabricSensitiveFields(value, associatedFabric) {
|
|
622
|
-
if (this.fabricSensitiveElementsToRemove.length && Array.isArray(value)) {
|
|
623
|
-
const associatedFabricIndex = associatedFabric?.fabricIndex ?? -1;
|
|
624
|
-
return value.map((data) => {
|
|
625
|
-
if (data[FabricIndexName] !== associatedFabricIndex) {
|
|
626
|
-
const result = { ...data };
|
|
627
|
-
this.fabricSensitiveElementsToRemove.forEach((fieldName) => delete result[fieldName]);
|
|
628
|
-
return result;
|
|
629
|
-
}
|
|
630
|
-
return data;
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
return value;
|
|
634
|
-
}
|
|
635
|
-
/**
|
|
636
|
-
* Initialize the attribute with a value. Because the value is stored on fabric level this method only initializes
|
|
637
|
-
* the version number.
|
|
638
|
-
*/
|
|
639
|
-
init(value) {
|
|
640
|
-
if (value !== void 0) {
|
|
641
|
-
throw new import_general.InternalError(`Cannot initialize fabric scoped attribute "${this.name}" with a value.`);
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
/**
|
|
645
|
-
* Fabric scoped enhancement of set to allow setting special fabricindex locally.
|
|
646
|
-
*/
|
|
647
|
-
set(value, session, message, delayChangeEvents = false, preserveFabricIndex = false) {
|
|
648
|
-
if (!this.isWritable) {
|
|
649
|
-
throw new import_types.StatusResponseError(`Attribute "${this.name}" is not writable.`, import_types.StatusCode.UnsupportedWrite);
|
|
650
|
-
}
|
|
651
|
-
this.setRemote(value, session, message, delayChangeEvents, preserveFabricIndex);
|
|
652
|
-
}
|
|
653
|
-
/**
|
|
654
|
-
* Method that contains the logic to set a value "from remote" (e.g. from a client). For Fabric scoped attributes
|
|
655
|
-
* we need to inject the fabric index into the value.
|
|
656
|
-
*/
|
|
657
|
-
setRemote(value, session, message, delayChangeEvents = false, preserveFabricIndex = false) {
|
|
658
|
-
value = this.schema.injectField(
|
|
659
|
-
value,
|
|
660
|
-
import_model.FabricIndex.id,
|
|
661
|
-
session.associatedFabric.fabricIndex,
|
|
662
|
-
() => !preserveFabricIndex
|
|
663
|
-
// No one should send any index and if we simply SHALL ignore it, but internally we might need it
|
|
664
|
-
);
|
|
665
|
-
logger.info(
|
|
666
|
-
`Set remote value for fabric scoped attribute "${this.name}" to ${import_general.Diagnostic.json(value)} (delayed=${delayChangeEvents})`
|
|
667
|
-
);
|
|
668
|
-
super.setRemote(value, session, message, delayChangeEvents);
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
* Set Local is not allowed for fabric scoped attributes. Use setLocalForFabric instead.
|
|
672
|
-
*/
|
|
673
|
-
setLocal(_value) {
|
|
674
|
-
throw new FabricScopeError(
|
|
675
|
-
`Fabric scoped attribute "${this.name}" can only be set locally by providing a Fabric. Use setLocalForFabric instead.`
|
|
676
|
-
);
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* Set the value of the attribute locally for a fabric. This method should be used locally in the code and does not
|
|
680
|
-
* include the ACL check.
|
|
681
|
-
* If a setter is defined this method cannot be used!
|
|
682
|
-
* If a validator is defined the value is validated before it is stored.
|
|
683
|
-
* Listeners are called when the value changes (internal listeners) or in any case (external listeners).
|
|
684
|
-
*/
|
|
685
|
-
setLocalForFabric(value, fabric) {
|
|
686
|
-
if (this.isCustomSetter) {
|
|
687
|
-
throw new FabricScopeError(
|
|
688
|
-
`Fabric scoped attribute "${this.name}" cannot be set locally when a custom setter is defined.`
|
|
689
|
-
);
|
|
690
|
-
}
|
|
691
|
-
this.validator(value, void 0, this.endpoint);
|
|
692
|
-
const oldValue = this.getLocalForFabric(fabric);
|
|
693
|
-
const valueChanged = !(0, import_general.isDeepEqual)(value, oldValue);
|
|
694
|
-
if (valueChanged) {
|
|
695
|
-
const setResult = fabric.setScopedClusterDataValue(this.cluster, this.name, { value });
|
|
696
|
-
if (import_general.MaybePromise.is(setResult)) {
|
|
697
|
-
throw new import_general.ImplementationError(
|
|
698
|
-
"Seems like an Asynchronous Storage is used with Legacy code paths which is forbidden!"
|
|
699
|
-
);
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
this.handleVersionAndTriggerListeners(value, oldValue, valueChanged);
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* When the value is handled by getter or setter methods and is changed by other processes and no session from the
|
|
706
|
-
* originating process is known this method can be used to notify the attribute server that the value has changed.
|
|
707
|
-
* This will increase the version number and trigger the listeners.
|
|
708
|
-
* ACL checks needs to be performed before calling this method.
|
|
709
|
-
*/
|
|
710
|
-
updatedLocalForFabric(fabric) {
|
|
711
|
-
const oldValue = this.value ?? this.defaultValue;
|
|
712
|
-
try {
|
|
713
|
-
this.value = this.getLocalForFabric(fabric);
|
|
714
|
-
} catch (e) {
|
|
715
|
-
FabricScopeError.accept(e);
|
|
716
|
-
if (this.value === void 0) {
|
|
717
|
-
this.value = this.defaultValue;
|
|
718
|
-
}
|
|
719
|
-
}
|
|
720
|
-
this.handleVersionAndTriggerListeners(this.value, oldValue, true);
|
|
721
|
-
}
|
|
722
|
-
/**
|
|
723
|
-
* Get the value of the attribute locally for a special Fabric. This method should be used locally in the code and
|
|
724
|
-
* does not include the ACL check.
|
|
725
|
-
* If a getter is defined this method returns an error and the value should be retrieved directly internally.
|
|
726
|
-
*/
|
|
727
|
-
getLocalForFabric(fabric) {
|
|
728
|
-
if (this.isCustomGetter) {
|
|
729
|
-
throw new FabricScopeError(
|
|
730
|
-
`Fabric scoped attribute "${this.name}" cannot be read locally when a custom getter is defined.`
|
|
731
|
-
);
|
|
732
|
-
}
|
|
733
|
-
return genericFabricScopedAttributeGetterFromFabric(fabric, this.cluster, this.name, this.defaultValue);
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
//# sourceMappingURL=AttributeServer.js.map
|