@lionweb/delta-protocol-test-cli 0.0.1-alpha.0

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/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ export * from "./gen/Shapes.g.js"
19
+
package/src/tasks.ts ADDED
@@ -0,0 +1,218 @@
1
+ // Copyright 2025 TRUMPF Laser SE and other contributors
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License")
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+ //
15
+ // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
+ // SPDX-License-Identifier: Apache-2.0
17
+
18
+ import { INodeBase } from "@lionweb/class-core"
19
+ import { LionWebClient } from "@lionweb/delta-protocol-impl"
20
+ import { LionWebId } from "@lionweb/json"
21
+ import { ClientAppliedEvent, ISemanticLogItem } from "@lionweb/delta-protocol-impl/dist/semantic-logging.js"
22
+ import { withStylesApplied } from "@lionweb/delta-protocol-impl/dist/utils/ansi.js"
23
+ import { waitUntil } from "@lionweb/delta-protocol-impl/dist/utils/async.js"
24
+ import { Documentation, Geometry, ShapesBase } from "./gen/Shapes.g.js"
25
+ import {
26
+ DataTypeTestConcept,
27
+ LinkTestConcept,
28
+ TestAnnotation,
29
+ TestLanguageBase
30
+ } from "@lionweb/class-core-test/dist/gen/TestLanguage.g.js"
31
+
32
+
33
+ const lastOf = <T>(ts: T[]): T => {
34
+ if (ts.length === 0) {
35
+ throw new Error(`empty array doesn't have a last element`)
36
+ }
37
+ return ts[ts.length - 1]
38
+ }
39
+
40
+
41
+ export const recognizedTasks: Record<string, boolean> = {
42
+ "SignOn": true,
43
+ "SignOff": true,
44
+ "Wait": true,
45
+ "AddDocs": true,
46
+ "SetDocsText": true,
47
+ "AddStringValue_0_1": true,
48
+ "SetStringValue_0_1": true,
49
+ "DeleteStringValue_0_1": true,
50
+ "AddAnnotation": true,
51
+ "AddAnnotations": true,
52
+ "AddAnnotation_to_Containment_0_1": true,
53
+ "DeleteAnnotation": true,
54
+ "MoveAnnotationInSameParent": true,
55
+ "MoveAnnotationFromOtherParent": true,
56
+ "AddReference_0_1_to_Containment_0_1": true,
57
+ "AddReference_0_1_to_Containment_1": true,
58
+ "DeleteReference_0_1": true,
59
+ "AddContainment_0_1": true,
60
+ "AddContainment_1": true,
61
+ "ReplaceContainment_0_1": true,
62
+ "DeleteContainment_0_1": true,
63
+ "AddContainment_0_1_Containment_0_1": true,
64
+ "AddContainment_1_Containment_0_1": true,
65
+ "AddContainment_0_n": true,
66
+ "AddContainment_1_n": true,
67
+ "MoveAndReplaceChildFromOtherContainment_Single": true,
68
+ "MoveAndReplaceChildFromOtherContainmentInSameParent_Single": true,
69
+ "MoveAndReplaceChildFromOtherContainment_Multiple": true,
70
+ "MoveChildInSameContainment": true,
71
+ "MoveChildFromOtherContainment_Single": true,
72
+ "MoveChildFromOtherContainment_Multiple": true,
73
+ "MoveChildFromOtherContainmentInSameParent_Single": true,
74
+ "MoveChildFromOtherContainmentInSameParent_Multiple": true,
75
+ "AddPartition": true
76
+ }
77
+
78
+
79
+ const shapesLanguageBase = ShapesBase.INSTANCE
80
+ const testLanguageBase = TestLanguageBase.INSTANCE
81
+
82
+
83
+ export const taskExecutor = (lionWebClient: LionWebClient, partition: INodeBase, semanticLogItems: ISemanticLogItem[]) => {
84
+ const numberOfAppliedEvents = () =>
85
+ semanticLogItems.filter((item) => item instanceof ClientAppliedEvent).length
86
+
87
+ const waitForReceived = async (delta: number) => {
88
+ const expectedNumber = numberOfAppliedEvents() + delta // (precompute here)
89
+ return waitUntil(10, () => numberOfAppliedEvents() >= expectedNumber)
90
+ .then(() => {
91
+ console.log(withStylesApplied("italic")(`(client applied (the deltas from) a total of ${numberOfAppliedEvents()} events so far)`))
92
+ })
93
+ }
94
+
95
+ const annotation = (id: LionWebId) =>
96
+ lionWebClient.factory(testLanguageBase.TestAnnotation, id) as TestAnnotation
97
+
98
+ const linkTestConcept = (id?: LionWebId) =>
99
+ id === undefined
100
+ ? partition as LinkTestConcept
101
+ : lionWebClient.factory(testLanguageBase.LinkTestConcept, id) as LinkTestConcept
102
+
103
+ return async (task: string, queryId: string) => {
104
+ switch (task) {
105
+ case "SignOn":
106
+ return await lionWebClient.signOn(queryId)
107
+ case "SignOff":
108
+ return await lionWebClient.signOff(queryId)
109
+ case "Wait": {
110
+ return waitForReceived(1)
111
+ }
112
+ case "AddDocs": {
113
+ (partition as Geometry).documentation = lionWebClient.factory(shapesLanguageBase.Documentation, "documentation") as Documentation
114
+ return waitForReceived(1)
115
+ }
116
+ case "SetDocsText": {
117
+ (partition as Geometry).documentation!.text = "hello there"
118
+ return waitForReceived(1)
119
+ }
120
+ case "AddStringValue_0_1":
121
+ (partition as DataTypeTestConcept).stringValue_0_1 = "new property"
122
+ return waitForReceived(1)
123
+ case "SetStringValue_0_1":
124
+ (partition as DataTypeTestConcept).stringValue_0_1 = "changed property"
125
+ return waitForReceived(1)
126
+ case "DeleteStringValue_0_1":
127
+ (partition as DataTypeTestConcept).stringValue_0_1 = undefined
128
+ return waitForReceived(1)
129
+ case "AddAnnotation":
130
+ linkTestConcept().addAnnotation(annotation("annotation"))
131
+ return waitForReceived(1)
132
+ case "AddAnnotations":
133
+ linkTestConcept().addAnnotation(annotation("annotation0")); // (keep ;!)
134
+ linkTestConcept().addAnnotation(annotation("annotation1"))
135
+ return waitForReceived(2)
136
+ case "AddAnnotation_to_Containment_0_1":
137
+ linkTestConcept().containment_0_1!.addAnnotation(annotation("annotation"))
138
+ return waitForReceived(1)
139
+ case "DeleteAnnotation":
140
+ linkTestConcept().removeAnnotation(linkTestConcept().annotations[0])
141
+ return waitForReceived(1)
142
+ case "MoveAnnotationInSameParent":
143
+ linkTestConcept().insertAnnotationAtIndex(lastOf(linkTestConcept().annotations), 0)
144
+ return waitForReceived(1)
145
+ case "MoveAnnotationFromOtherParent":
146
+ linkTestConcept().addAnnotation(linkTestConcept().containment_0_1!.annotations[0])
147
+ return waitForReceived(1)
148
+ case "AddReference_0_1_to_Containment_0_1":
149
+ linkTestConcept().reference_0_1 = linkTestConcept().containment_0_1
150
+ return waitForReceived(1)
151
+ case "AddReference_0_1_to_Containment_1":
152
+ linkTestConcept().reference_0_1 = linkTestConcept().containment_1
153
+ return waitForReceived(1)
154
+ case "DeleteReference_0_1":
155
+ linkTestConcept().reference_0_1 = undefined
156
+ return waitForReceived(1)
157
+ case "AddContainment_0_1":
158
+ linkTestConcept().containment_0_1 = linkTestConcept("containment_0_1")
159
+ return waitForReceived(1)
160
+ case "AddContainment_1":
161
+ linkTestConcept().containment_1 = linkTestConcept("containment_1")
162
+ return waitForReceived(1)
163
+ case "ReplaceContainment_0_1":
164
+ linkTestConcept().containment_0_1 = linkTestConcept("substitute")
165
+ return waitForReceived(1)
166
+ case "DeleteContainment_0_1":
167
+ linkTestConcept().containment_0_1 = undefined
168
+ return waitForReceived(1)
169
+ case "AddContainment_0_1_Containment_0_1":
170
+ linkTestConcept().containment_0_1!.containment_0_1 = linkTestConcept("containment_0_1_containment_0_1")
171
+ return waitForReceived(1)
172
+ case "AddContainment_1_Containment_0_1":
173
+ linkTestConcept().containment_1.containment_0_1 = linkTestConcept("containment_1_containment_0_1")
174
+ return waitForReceived(1)
175
+ case "AddContainment_0_n":
176
+ linkTestConcept().addContainment_0_n(linkTestConcept("containment_0_n_child0")); // (keep ;!)
177
+ linkTestConcept().addContainment_0_n(linkTestConcept("containment_0_n_child1"))
178
+ return waitForReceived(2)
179
+ case "AddContainment_1_n":
180
+ linkTestConcept().addContainment_1_n(linkTestConcept("containment_1_n_child0")); // (keep ;!)
181
+ linkTestConcept().addContainment_1_n(linkTestConcept("containment_1_n_child1"))
182
+ return waitForReceived(2)
183
+ case "MoveAndReplaceChildFromOtherContainment_Single":
184
+ linkTestConcept().containment_1.replaceContainment_0_1With(linkTestConcept().containment_0_1!.containment_0_1!)
185
+ return waitForReceived(1)
186
+ case "MoveAndReplaceChildFromOtherContainmentInSameParent_Single":
187
+ linkTestConcept().replaceContainment_1With(linkTestConcept().containment_0_1!)
188
+ return waitForReceived(1)
189
+ case "MoveAndReplaceChildFromOtherContainment_Multiple":
190
+ linkTestConcept().replaceContainment_1_nAtIndex(lastOf(linkTestConcept().containment_0_n), linkTestConcept().containment_1_n.length - 1)
191
+ return waitForReceived(1)
192
+ case "MoveChildInSameContainment":
193
+ linkTestConcept().addContainment_0_nAtIndex(lastOf(linkTestConcept().containment_0_n), 0)
194
+ return waitForReceived(1)
195
+ case "MoveChildFromOtherContainment_Single":
196
+ linkTestConcept().containment_1 = linkTestConcept().containment_0_1!.containment_0_1!
197
+ return waitForReceived(1)
198
+ case "MoveChildFromOtherContainment_Multiple":
199
+ linkTestConcept().addContainment_1_nAtIndex(lastOf(linkTestConcept().containment_0_n).containment_0_n[0], 1)
200
+ return waitForReceived(1)
201
+ case "MoveChildFromOtherContainmentInSameParent_Single":
202
+ linkTestConcept().containment_1 = linkTestConcept().containment_0_1!
203
+ return waitForReceived(1)
204
+ case "MoveChildFromOtherContainmentInSameParent_Multiple":
205
+ linkTestConcept().addContainment_1_nAtIndex(lastOf(linkTestConcept().containment_0_n), 1)
206
+ return waitForReceived(1)
207
+ case "AddPartition":
208
+ lionWebClient.addPartition(linkTestConcept("partition"))
209
+ return waitForReceived(1)
210
+
211
+ default: {
212
+ console.log(withStylesApplied("italic", "red")(`task "${task}" is unknown => ignored`))
213
+ return Promise.resolve()
214
+ }
215
+ }
216
+ }
217
+ }
218
+
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "src",
5
+ "outDir": "dist/"
6
+ }
7
+ }