@matter/model 0.16.1-alpha.0-20260113-4616af40a → 0.16.2-alpha.0-20260114-d3127faee

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.
Files changed (64) hide show
  1. package/dist/cjs/decoration/decorators/element.d.ts +10 -1
  2. package/dist/cjs/decoration/decorators/element.d.ts.map +1 -1
  3. package/dist/cjs/decoration/decorators/element.js +32 -5
  4. package/dist/cjs/decoration/decorators/element.js.map +1 -1
  5. package/dist/cjs/decoration/decorators/index.d.ts +2 -0
  6. package/dist/cjs/decoration/decorators/index.d.ts.map +1 -1
  7. package/dist/cjs/decoration/decorators/index.js +2 -0
  8. package/dist/cjs/decoration/decorators/index.js.map +1 -1
  9. package/dist/cjs/decoration/decorators/response.d.ts +2 -2
  10. package/dist/cjs/decoration/decorators/response.d.ts.map +1 -1
  11. package/dist/cjs/decoration/decorators/response.js +3 -19
  12. package/dist/cjs/decoration/decorators/response.js.map +1 -1
  13. package/dist/cjs/decoration/semantics/ClassSemantics.d.ts +1 -0
  14. package/dist/cjs/decoration/semantics/ClassSemantics.d.ts.map +1 -1
  15. package/dist/cjs/decoration/semantics/ClassSemantics.js +4 -1
  16. package/dist/cjs/decoration/semantics/ClassSemantics.js.map +1 -1
  17. package/dist/cjs/decoration/semantics/FieldSemantics.d.ts +3 -0
  18. package/dist/cjs/decoration/semantics/FieldSemantics.d.ts.map +1 -1
  19. package/dist/cjs/decoration/semantics/FieldSemantics.js +8 -0
  20. package/dist/cjs/decoration/semantics/FieldSemantics.js.map +1 -1
  21. package/dist/cjs/decoration/semantics/Semantics.d.ts +5 -1
  22. package/dist/cjs/decoration/semantics/Semantics.d.ts.map +1 -1
  23. package/dist/cjs/decoration/semantics/Semantics.js +12 -0
  24. package/dist/cjs/decoration/semantics/Semantics.js.map +1 -1
  25. package/dist/cjs/models/CommandModel.d.ts +9 -1
  26. package/dist/cjs/models/CommandModel.d.ts.map +1 -1
  27. package/dist/cjs/models/CommandModel.js +21 -1
  28. package/dist/cjs/models/CommandModel.js.map +1 -1
  29. package/dist/esm/decoration/decorators/element.d.ts +10 -1
  30. package/dist/esm/decoration/decorators/element.d.ts.map +1 -1
  31. package/dist/esm/decoration/decorators/element.js +32 -5
  32. package/dist/esm/decoration/decorators/element.js.map +1 -1
  33. package/dist/esm/decoration/decorators/index.d.ts +2 -0
  34. package/dist/esm/decoration/decorators/index.d.ts.map +1 -1
  35. package/dist/esm/decoration/decorators/index.js +2 -0
  36. package/dist/esm/decoration/decorators/index.js.map +1 -1
  37. package/dist/esm/decoration/decorators/response.d.ts +2 -2
  38. package/dist/esm/decoration/decorators/response.d.ts.map +1 -1
  39. package/dist/esm/decoration/decorators/response.js +3 -19
  40. package/dist/esm/decoration/decorators/response.js.map +1 -1
  41. package/dist/esm/decoration/semantics/ClassSemantics.d.ts +1 -0
  42. package/dist/esm/decoration/semantics/ClassSemantics.d.ts.map +1 -1
  43. package/dist/esm/decoration/semantics/ClassSemantics.js +4 -1
  44. package/dist/esm/decoration/semantics/ClassSemantics.js.map +1 -1
  45. package/dist/esm/decoration/semantics/FieldSemantics.d.ts +3 -0
  46. package/dist/esm/decoration/semantics/FieldSemantics.d.ts.map +1 -1
  47. package/dist/esm/decoration/semantics/FieldSemantics.js +8 -0
  48. package/dist/esm/decoration/semantics/FieldSemantics.js.map +1 -1
  49. package/dist/esm/decoration/semantics/Semantics.d.ts +5 -1
  50. package/dist/esm/decoration/semantics/Semantics.d.ts.map +1 -1
  51. package/dist/esm/decoration/semantics/Semantics.js +12 -0
  52. package/dist/esm/decoration/semantics/Semantics.js.map +1 -1
  53. package/dist/esm/models/CommandModel.d.ts +9 -1
  54. package/dist/esm/models/CommandModel.d.ts.map +1 -1
  55. package/dist/esm/models/CommandModel.js +21 -1
  56. package/dist/esm/models/CommandModel.js.map +1 -1
  57. package/package.json +4 -4
  58. package/src/decoration/decorators/element.ts +46 -6
  59. package/src/decoration/decorators/index.ts +2 -0
  60. package/src/decoration/decorators/response.ts +3 -22
  61. package/src/decoration/semantics/ClassSemantics.ts +7 -3
  62. package/src/decoration/semantics/FieldSemantics.ts +11 -0
  63. package/src/decoration/semantics/Semantics.ts +19 -0
  64. package/src/models/CommandModel.ts +33 -2
@@ -4,31 +4,12 @@
4
4
  * SPDX-License-Identifier: Apache-2.0
5
5
  */
6
6
 
7
- import { FieldSemantics } from "#decoration/semantics/FieldSemantics.js";
8
- import { CommandElement } from "#elements/CommandElement.js";
9
7
  import { Decorator } from "#general";
10
- import { CommandModel } from "#models/CommandModel.js";
11
- import { DatatypeModel } from "#models/DatatypeModel.js";
8
+ import { element } from "./element.js";
12
9
 
13
10
  /**
14
11
  * Specify the response type for a command.
15
12
  */
16
- export function response(type: DatatypeModel): Decorator.ClassMethod {
17
- return Decorator((_target, context) => {
18
- const requestSemantics = FieldSemantics.of(context);
19
-
20
- requestSemantics.modelType = CommandModel;
21
- const request = requestSemantics.mutableModel as CommandModel;
22
-
23
- const name = `${request.name}Response`;
24
- new CommandModel({
25
- name,
26
- id: request.id,
27
- parent: request.parent,
28
- direction: CommandElement.Direction.Response,
29
- operationalBase: type,
30
- });
31
-
32
- request.response = name;
33
- });
13
+ export function response(...modifiers: element.Modifier<Decorator.MethodCollector>[]) {
14
+ return element({ Tag: "response" }, ...modifiers);
34
15
  }
@@ -291,15 +291,15 @@ export class ClassSemantics extends Semantics {
291
291
  // Invoke any custom extension logic
292
292
  this.#new?.[ClassSemantics.extend]?.(this);
293
293
 
294
- // Apply base finalization
295
- super.finalize();
296
-
297
294
  // Finalize fields
298
295
  if (this.#definedFields) {
299
296
  for (const field of this.#definedFields.values()) {
300
297
  field.finalize();
301
298
  }
302
299
  }
300
+
301
+ // Apply base finalization
302
+ super.finalize();
303
303
  }
304
304
 
305
305
  #applyBaseSemantics() {
@@ -355,6 +355,10 @@ export class ClassSemantics extends Semantics {
355
355
  }
356
356
  return new type({ name, operationalBase: struct });
357
357
  }
358
+
359
+ get owner() {
360
+ return this;
361
+ }
358
362
  }
359
363
 
360
364
  export namespace ClassSemantics {
@@ -15,12 +15,23 @@ import { Semantics } from "./Semantics.js";
15
15
  * Decorator metadata associated with a specific class field.
16
16
  */
17
17
  export class FieldSemantics extends Semantics {
18
+ #owner: ClassSemantics;
19
+
18
20
  constructor(owner: ClassSemantics, name: string) {
19
21
  super();
22
+ this.#owner = owner;
20
23
 
21
24
  this.mutableModel = new FieldModel({ name, parent: owner.mutableModel });
22
25
  }
23
26
 
27
+ get owner() {
28
+ return this.#owner;
29
+ }
30
+
31
+ get semanticModel() {
32
+ return this.localModel;
33
+ }
34
+
24
35
  protected override createModel(): Model {
25
36
  // We create our model unconditionally so this shouldn't happen
26
37
  throw new InternalError("Unexpected FieldSemantics.createModel");
@@ -6,9 +6,11 @@
6
6
 
7
7
  import { MetadataConflictError } from "#decoration/errors.js";
8
8
  import { InternalError } from "#general";
9
+ import { CommandModel } from "#models/CommandModel.js";
9
10
  import type { Model } from "#models/Model.js";
10
11
  import * as models from "#standard/elements/models.js";
11
12
  import type { ClassSemantics } from "./ClassSemantics.js";
13
+ import type { FieldSemantics } from "./FieldSemantics.js";
12
14
 
13
15
  const standardModels = new Set(Object.values(models) as Model[]);
14
16
 
@@ -22,6 +24,8 @@ export abstract class Semantics {
22
24
  #localModel?: Model;
23
25
  #isFinal = false;
24
26
 
27
+ response?: FieldSemantics;
28
+
25
29
  /**
26
30
  * Determine whether these semantics are final.
27
31
  *
@@ -39,6 +43,19 @@ export abstract class Semantics {
39
43
  return;
40
44
  }
41
45
 
46
+ if (this.response && this.semanticModel instanceof CommandModel) {
47
+ this.response.finalize();
48
+
49
+ const response = this.response.localModel;
50
+ if (response) {
51
+ if (response.id === undefined) {
52
+ // Default response ID is request ID
53
+ response.id = this.semanticModel.id;
54
+ }
55
+ (this.mutableModel as CommandModel).operationalResponse = this.response.localModel as CommandModel;
56
+ }
57
+ }
58
+
42
59
  this.#isFinal = true;
43
60
  Object.freeze(this);
44
61
  this.#localModel?.finalize();
@@ -144,6 +161,8 @@ export abstract class Semantics {
144
161
  this.#localModel = replacement;
145
162
  }
146
163
 
164
+ abstract owner: ClassSemantics;
165
+ abstract semanticModel?: Model;
147
166
  protected abstract createModel(type?: Model.ConcreteType): Model;
148
167
  }
149
168
 
@@ -14,6 +14,8 @@ export class CommandModel extends ValueModel<CommandElement> implements CommandE
14
14
  direction?: CommandElement.Direction;
15
15
  response?: string;
16
16
 
17
+ operationalResponse?: CommandModel | null;
18
+
17
19
  get fabricScoped() {
18
20
  return !!this.effectiveAccess.fabric;
19
21
  }
@@ -26,8 +28,21 @@ export class CommandModel extends ValueModel<CommandElement> implements CommandE
26
28
  return this.effectiveDirection === CommandElement.Direction.Response;
27
29
  }
28
30
 
31
+ set isResponse(isResponse: boolean) {
32
+ this.direction = isResponse ? CommandElement.Direction.Response : CommandElement.Direction.Request;
33
+ }
34
+
29
35
  get responseModel() {
30
- return new ModelTraversal().findResponse(this);
36
+ switch (this.operationalResponse) {
37
+ case undefined:
38
+ return new ModelTraversal().findResponse(this);
39
+
40
+ case null:
41
+ return undefined;
42
+
43
+ default:
44
+ return this.operationalResponse;
45
+ }
31
46
  }
32
47
 
33
48
  get effectiveDirection() {
@@ -55,11 +70,12 @@ export class CommandModel extends ValueModel<CommandElement> implements CommandE
55
70
  return this.direction;
56
71
  }
57
72
 
58
- constructor(definition: Model.Definition<CommandModel>, ...children: Model.ChildDefinition<CommandModel>[]) {
73
+ constructor(definition: CommandModel.Definition, ...children: Model.ChildDefinition<CommandModel>[]) {
59
74
  super(definition, ...children);
60
75
 
61
76
  this.direction = definition.direction as CommandElement.Direction;
62
77
  this.response = definition.response;
78
+ this.operationalResponse = definition.operationalResponse;
63
79
  }
64
80
 
65
81
  override toElement(omitResources = false, extra?: Record<string, unknown>) {
@@ -70,8 +86,23 @@ export class CommandModel extends ValueModel<CommandElement> implements CommandE
70
86
  });
71
87
  }
72
88
 
89
+ override finalize() {
90
+ if (this.isFinal) {
91
+ return;
92
+ }
93
+
94
+ const operationalResponse = this.operationalResponse ?? (this.operationalResponse = this.responseModel ?? null);
95
+ operationalResponse?.finalize();
96
+
97
+ super.finalize();
98
+ }
99
+
73
100
  static Tag = CommandElement.Tag;
74
101
  static requiresId = true;
75
102
  }
76
103
 
104
+ export namespace CommandModel {
105
+ export type Definition = Model.Definition<CommandModel> & { operationalResponse?: CommandModel };
106
+ }
107
+
77
108
  CommandModel.register();