Skip to content

Commit 979eda0

Browse files
authored
Refactor Legacy stuff (#2045)
* Refactor Legacy stuff * typo * remove unneeded class
1 parent 9035754 commit 979eda0

File tree

20 files changed

+44
-617
lines changed

20 files changed

+44
-617
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ The main work (all changes without a GitHub username in brackets in the below li
3434

3535
- @matter/protocol
3636
- Breaking: `logEndpoint()` was removed. The Endpoints support logging directly via Diagnostics
37+
- Breaking: All legacy used *Server classes (AttributeServer, EventServer, CommandServer) are moved to the matter.js legacy package
3738
- Feature: Added `getLocal()` to AttributeClient to retrieve the currently stored/cached value
3839
- Adjustment: ACL writes are not sent chunked by default from now on like also in chip SDK
3940
- Fix: Handles messages only that are secured as required for the relevant protocol

packages/matter.js/src/cluster/export.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
export * from "./server/ClusterServer.js";
8-
export * from "./server/ClusterServerTypes.js";
7+
export * from "./server/index.js";

packages/protocol/src/cluster/server/AttributeServer.ts renamed to packages/matter.js/src/cluster/server/AttributeServer.ts

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
import { Endpoint } from "#device/Endpoint.js";
78
import {
89
Diagnostic,
910
ImplementationError,
@@ -15,6 +16,7 @@ import {
1516
isDeepEqual,
1617
} from "#general";
1718
import { AccessLevel, AttributeModel, ClusterModel, DatatypeModel, FabricIndex, MatterModel } from "#model";
19+
import { Fabric, Message, NoAssociatedFabricError, SecureSession, Session, assertSecureSession } from "#protocol";
1820
import {
1921
Attribute,
2022
AttributeId,
@@ -29,11 +31,6 @@ import {
2931
TypeFromPartialBitSchema,
3032
ValidationError,
3133
} from "#types";
32-
import { Message } from "../../codec/MessageCodec.js";
33-
import { EndpointInterface } from "../../endpoint/EndpointInterface.js";
34-
import { Fabric } from "../../fabric/Fabric.js";
35-
import { NoAssociatedFabricError, SecureSession, assertSecureSession } from "../../session/SecureSession.js";
36-
import { Session } from "../../session/Session.js";
3734
import { ClusterDatasource } from "./ClusterDatasource.js";
3835

3936
const logger = Logger.get("AttributeServer");
@@ -70,9 +67,9 @@ export function createAttributeServer<
7067
attributeName: string,
7168
initValue: T,
7269
datasource: ClusterDatasource,
73-
getter?: (session?: Session, endpoint?: EndpointInterface, isFabricFiltered?: boolean, message?: Message) => T,
74-
setter?: (value: T, session?: Session, endpoint?: EndpointInterface, message?: Message) => boolean,
75-
validator?: (value: T, session?: Session, endpoint?: EndpointInterface) => void,
70+
getter?: (session?: Session, endpoint?: Endpoint, isFabricFiltered?: boolean, message?: Message) => T,
71+
setter?: (value: T, session?: Session, endpoint?: Endpoint, message?: Message) => boolean,
72+
validator?: (value: T, session?: Session, endpoint?: Endpoint) => void,
7673
) {
7774
const {
7875
id,
@@ -150,7 +147,7 @@ export abstract class BaseAttributeServer<T> {
150147
* The value is undefined when getter/setter are used. But we still handle the version number here.
151148
*/
152149
protected value: T | undefined = undefined;
153-
protected endpoint?: EndpointInterface;
150+
protected endpoint?: Endpoint;
154151
readonly defaultValue: T;
155152
#readAcl: AccessLevel | undefined;
156153
#writeAcl: AccessLevel | undefined;
@@ -203,7 +200,7 @@ export abstract class BaseAttributeServer<T> {
203200
}
204201
}
205202

206-
assignToEndpoint(endpoint: EndpointInterface) {
203+
assignToEndpoint(endpoint: Endpoint) {
207204
this.endpoint = endpoint;
208205
}
209206

@@ -230,7 +227,7 @@ export class FixedAttributeServer<T> extends BaseAttributeServer<T> {
230227
readonly isFixed: boolean = true;
231228
protected readonly getter: (
232229
session?: Session,
233-
endpoint?: EndpointInterface,
230+
endpoint?: Endpoint,
234231
isFabricFiltered?: boolean,
235232
message?: Message,
236233
) => T;
@@ -256,7 +253,7 @@ export class FixedAttributeServer<T> extends BaseAttributeServer<T> {
256253
* @param isFabricFiltered whether the read request is fabric scoped or not
257254
* @param message the wire message that initiated the request (if any)
258255
*/
259-
getter?: (session?: Session, endpoint?: EndpointInterface, isFabricFiltered?: boolean, message?: Message) => T,
256+
getter?: (session?: Session, endpoint?: Endpoint, isFabricFiltered?: boolean, message?: Message) => T,
260257
) {
261258
super(
262259
id,
@@ -375,13 +372,8 @@ export class AttributeServer<T> extends FixedAttributeServer<T> {
375372
override readonly isFixed = false;
376373
protected readonly valueChangeListeners = new Array<(value: T, version: number) => void>();
377374
protected readonly valueSetListeners = new Array<(newValue: T, oldValue: T) => void>();
378-
protected readonly setter: (
379-
value: T,
380-
session?: Session,
381-
endpoint?: EndpointInterface,
382-
message?: Message,
383-
) => boolean;
384-
protected readonly validator: (value: T, session?: Session, endpoint?: EndpointInterface) => void;
375+
protected readonly setter: (value: T, session?: Session, endpoint?: Endpoint, message?: Message) => boolean;
376+
protected readonly validator: (value: T, session?: Session, endpoint?: Endpoint) => void;
385377
protected delayedChangeData?: DelayedChangeData = undefined;
386378

387379
constructor(
@@ -396,7 +388,7 @@ export class AttributeServer<T> extends FixedAttributeServer<T> {
396388
initValue: T,
397389
defaultValue: T | undefined,
398390
datasource: ClusterDatasource,
399-
getter?: (session?: Session, endpoint?: EndpointInterface, isFabricFiltered?: boolean, message?: Message) => T,
391+
getter?: (session?: Session, endpoint?: Endpoint, isFabricFiltered?: boolean, message?: Message) => T,
400392

401393
/**
402394
* Optional setter function to handle special requirements or the data are stored in different places. If a
@@ -408,7 +400,7 @@ export class AttributeServer<T> extends FixedAttributeServer<T> {
408400
* @param endpoint the endpoint the cluster server of this attribute is assigned to.
409401
* @returns true if the value has changed, false otherwise.
410402
*/
411-
setter?: (value: T, session?: Session, endpoint?: EndpointInterface, message?: Message) => boolean,
403+
setter?: (value: T, session?: Session, endpoint?: Endpoint, message?: Message) => boolean,
412404

413405
/**
414406
* Optional Validator function to handle special requirements for verification of stored data. The method should
@@ -421,7 +413,7 @@ export class AttributeServer<T> extends FixedAttributeServer<T> {
421413
* @param session the session that is requesting the value (if any).
422414
* @param endpoint the endpoint the cluster server of this attribute is assigned to.
423415
*/
424-
validator?: (value: T, session?: Session, endpoint?: EndpointInterface) => void,
416+
validator?: (value: T, session?: Session, endpoint?: Endpoint) => void,
425417
) {
426418
if (
427419
isWritable &&
@@ -746,9 +738,9 @@ export class FabricScopedAttributeServer<T> extends AttributeServer<T> {
746738
defaultValue: T | undefined,
747739
readonly cluster: Cluster<any, any, any, any, any>,
748740
datasource: ClusterDatasource,
749-
getter?: (session?: Session, endpoint?: EndpointInterface, isFabricFiltered?: boolean) => T,
750-
setter?: (value: T, session?: Session, endpoint?: EndpointInterface, message?: Message) => boolean,
751-
validator?: (value: T, session?: Session, endpoint?: EndpointInterface) => void,
741+
getter?: (session?: Session, endpoint?: Endpoint, isFabricFiltered?: boolean) => T,
742+
setter?: (value: T, session?: Session, endpoint?: Endpoint, message?: Message) => boolean,
743+
validator?: (value: T, session?: Session, endpoint?: Endpoint) => void,
752744
) {
753745
if (
754746
isWritable &&

packages/protocol/src/cluster/server/ClusterDatasource.ts renamed to packages/matter.js/src/cluster/server/ClusterDatasource.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { OccurrenceManager } from "#events/OccurrenceManager.js";
8-
import { Fabric } from "#fabric/Fabric.js";
97
import { SupportedStorageTypes } from "#general";
8+
import { Fabric, OccurrenceManager } from "#protocol";
109

1110
export interface ClusterDatasource {
1211
readonly version: number;

packages/matter.js/src/cluster/server/ClusterServer.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,7 @@
66

77
import { capitalize, Diagnostic, ImplementationError, InternalError, Logger, MaybePromise } from "#general";
88
import { AccessLevel } from "#model";
9-
import {
10-
ClusterServer as BaseClusterServer,
11-
ClusterDatasource,
12-
CommandServer,
13-
createAttributeServer,
14-
createEventServer,
15-
Fabric,
16-
} from "#protocol";
9+
import { Fabric } from "#protocol";
1710
import {
1811
AttributeId,
1912
BitSchema,
@@ -26,6 +19,8 @@ import {
2619
TypeFromPartialBitSchema,
2720
} from "#types";
2821
import { Endpoint } from "../../device/Endpoint.js";
22+
import { createAttributeServer } from "./AttributeServer.js";
23+
import { ClusterDatasource } from "./ClusterDatasource.js";
2924
import {
3025
AttributeInitialValues,
3126
AttributeServers,
@@ -35,6 +30,8 @@ import {
3530
EventServers,
3631
SupportedEventsList,
3732
} from "./ClusterServerTypes.js";
33+
import { CommandServer } from "./CommandServer.js";
34+
import { createEventServer } from "./EventServer.js";
3835

3936
const logger = Logger.get("ClusterServer");
4037

@@ -53,7 +50,7 @@ function isConditionMatching<F extends BitSchema, SF extends TypeFromPartialBitS
5350
/**
5451
* A collection of servers for a cluster's attributes, commands and events.
5552
*/
56-
export interface ClusterServer<T extends ClusterType = ClusterType> extends BaseClusterServer {
53+
export interface ClusterServer<T extends ClusterType = ClusterType> {
5754
/**
5855
* Cluster ID
5956
*/

packages/matter.js/src/cluster/server/ClusterServerTypes.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,7 @@
55
*/
66

77
import { Merge } from "#general";
8-
import {
9-
AnyEventServer,
10-
AttributeServer,
11-
ClusterClientObj,
12-
CommandServer,
13-
Fabric,
14-
FabricScopedAttributeServer,
15-
FixedAttributeServer,
16-
Message,
17-
Session,
18-
} from "#protocol";
8+
import { ClusterClientObj, Fabric, Message, Session } from "#protocol";
199
import {
2010
Attribute,
2111
AttributeId,
@@ -48,7 +38,10 @@ import {
4838
WritableFabricScopedAttribute,
4939
} from "#types";
5040
import { Endpoint } from "../../device/Endpoint.js";
41+
import { AttributeServer, FabricScopedAttributeServer, FixedAttributeServer } from "./AttributeServer.js";
5142
import { type ClusterServer } from "./ClusterServer.js";
43+
import { CommandServer } from "./CommandServer.js";
44+
import { AnyEventServer } from "./EventServer.js";
5245

5346
/** Cluster attributes accessible on the cluster server */
5447
type MandatoryAttributeServers<A extends Attributes> = Omit<

packages/protocol/src/cluster/server/CommandServer.ts renamed to packages/matter.js/src/cluster/server/CommandServer.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
import { Endpoint } from "#device/Endpoint.js";
78
import { Diagnostic, Logger } from "#general";
89
import { AccessLevel, FabricIndex } from "#model";
10+
import { Message, SecureSession, Session } from "#protocol";
911
import { CommandId, StatusCode, TlvSchema, TlvStream } from "#types";
10-
import { Message } from "../../codec/MessageCodec.js";
11-
import { EndpointInterface } from "../../endpoint/EndpointInterface.js";
12-
import { SecureSession } from "../../session/SecureSession.js";
13-
import { Session } from "../../session/Session.js";
1412

1513
const logger = Logger.get("CommandServer");
1614

@@ -29,7 +27,7 @@ export class CommandServer<RequestT = any, ResponseT = any> {
2927
request: RequestT,
3028
session: Session,
3129
message: Message,
32-
endpoint: EndpointInterface,
30+
endpoint: Endpoint,
3331
) => Promise<ResponseT> | ResponseT,
3432
) {
3533
this.#invokeAcl = invokeAcl;
@@ -39,7 +37,7 @@ export class CommandServer<RequestT = any, ResponseT = any> {
3937
session: Session,
4038
args: TlvStream,
4139
message: Message,
42-
endpoint: EndpointInterface,
40+
endpoint: Endpoint,
4341
): Promise<{
4442
/** Primary StatusCode of the invoke request as defined by Interaction proptocol. */
4543
code: StatusCode;

packages/protocol/src/cluster/server/EventServer.ts renamed to packages/matter.js/src/cluster/server/EventServer.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import { NumberedOccurrence, Occurrence } from "#events/Occurrence.js";
8-
import { OccurrenceManager } from "#events/OccurrenceManager.js";
7+
import { Endpoint } from "#device/Endpoint.js";
98
import {
109
ImplementationError,
1110
InternalError,
@@ -17,6 +16,7 @@ import {
1716
Time,
1817
} from "#general";
1918
import { AccessLevel, ClusterModel, EventModel, MatterModel } from "#model";
19+
import { Message, NumberedOccurrence, Occurrence, OccurrenceManager, SecureSession, Session } from "#protocol";
2020
import {
2121
Attributes,
2222
BitSchema,
@@ -33,10 +33,6 @@ import {
3333
TypeFromPartialBitSchema,
3434
TypeFromSchema,
3535
} from "#types";
36-
import { Message } from "../../codec/MessageCodec.js";
37-
import { EndpointInterface } from "../../endpoint/EndpointInterface.js";
38-
import { SecureSession } from "../../session/SecureSession.js";
39-
import { Session } from "../../session/Session.js";
4036

4137
export type AnyEventServer<T = any, S extends Storage = any> = EventServer<T, S> | FabricSensitiveEventServer<T, S>;
4238

@@ -73,7 +69,7 @@ export function createEventServer<
7369
export class EventServer<T = any, S extends Storage = any> {
7470
private eventList = new Array<Occurrence>();
7571
private readonly listeners = new Array<(event: NumberedOccurrence) => void>();
76-
protected endpoint?: EndpointInterface;
72+
protected endpoint?: Endpoint;
7773
protected eventHandler?: OccurrenceManager;
7874
#readAcl: AccessLevel | undefined;
7975
hasFabricSensitiveData = false;
@@ -93,7 +89,7 @@ export class EventServer<T = any, S extends Storage = any> {
9389
return this.#readAcl ?? AccessLevel.View; // ???
9490
}
9591

96-
assignToEndpoint(endpoint: EndpointInterface) {
92+
assignToEndpoint(endpoint: Endpoint) {
9793
this.endpoint = endpoint;
9894
}
9995

packages/matter.js/src/device/Endpoint.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ import {
1111
UserLabelCluster,
1212
} from "#clusters";
1313
import { AtLeastOne, Diagnostic, ImplementationError, InternalError, NotImplementedError } from "#general";
14-
import {
15-
ClusterClientObj,
16-
EndpointInterface,
17-
SupportedAttributeClient,
18-
UnknownSupportedAttributeClient,
19-
} from "#protocol";
14+
import { ClusterClientObj, SupportedAttributeClient, UnknownSupportedAttributeClient } from "#protocol";
2015
import {
2116
Attributes,
2217
BitSchema,
@@ -39,7 +34,7 @@ export interface EndpointOptions {
3934
uniqueStorageKey?: string;
4035
}
4136

42-
export class Endpoint implements EndpointInterface {
37+
export class Endpoint {
4338
private readonly clusterServers = new Map<ClusterId, ClusterServerObj>();
4439
private readonly clusterClients = new Map<ClusterId, ClusterClientObj>();
4540
private readonly childEndpoints: Endpoint[] = [];
@@ -220,7 +215,7 @@ export class Endpoint implements EndpointInterface {
220215
this.name = deviceTypes[0].name;
221216
}
222217

223-
addChildEndpoint(endpoint: EndpointInterface): void {
218+
addChildEndpoint(endpoint: Endpoint): void {
224219
if (!(endpoint instanceof Endpoint)) {
225220
throw new Error("Only supported EndpointInterface implementation is Endpoint");
226221
}

packages/matter.js/src/device/PairedNode.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import {
2727
ClusterClientObj,
2828
DecodedAttributeReportValue,
2929
DecodedEventReportValue,
30-
EndpointInterface,
3130
InteractionClient,
3231
NodeDiscoveryType,
3332
PaseClient,
@@ -1179,7 +1178,7 @@ export class PairedNode {
11791178
}
11801179

11811180
/** Returns the functional devices/endpoints (the "childs" of the Root Endpoint) known for this node. */
1182-
getDevices(): EndpointInterface[] {
1181+
getDevices(): Endpoint[] {
11831182
return this.#endpoints.get(EndpointNumber(0))?.getChildEndpoints() ?? [];
11841183
}
11851184

0 commit comments

Comments
 (0)