@operato/scene-integration 0.0.5

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 (82) hide show
  1. package/@types/global/index.d.ts +1 -0
  2. package/CHANGELOG.md +17 -0
  3. package/LICENSE +21 -0
  4. package/README.md +105 -0
  5. package/assets/icon-camera-stream.png +0 -0
  6. package/assets/icon-connection-control.png +0 -0
  7. package/assets/icon-connection-state-subscription.png +0 -0
  8. package/assets/icon-data-subscription.png +0 -0
  9. package/assets/icon-integration.png +0 -0
  10. package/assets/icon-scenario-control.png +0 -0
  11. package/assets/icon-scenario-instance-subscription.png +0 -0
  12. package/assets/icon-scenario-queue-subscription.png +0 -0
  13. package/assets/icon-scenario-run.png +0 -0
  14. package/assets/icon-scenario-start.png +0 -0
  15. package/assets/icon-scenario-stop.png +0 -0
  16. package/assets/no-image.png +0 -0
  17. package/assets/symbol-connection-control.png +0 -0
  18. package/assets/symbol-connection-state-subscription.png +0 -0
  19. package/assets/symbol-data-subscription.png +0 -0
  20. package/assets/symbol-integration.png +0 -0
  21. package/assets/symbol-scenario-control.png +0 -0
  22. package/assets/symbol-scenario-instance-subscription.png +0 -0
  23. package/assets/symbol-scenario-queue-subscription.png +0 -0
  24. package/assets/symbol-scenario-run.png +0 -0
  25. package/assets/symbol-scenario-start.png +0 -0
  26. package/assets/symbol-scenario-stop.png +0 -0
  27. package/helps/scene/component/connection-control.ko.md +15 -0
  28. package/helps/scene/component/connection-control.md +15 -0
  29. package/helps/scene/component/connection-control.zh.md +16 -0
  30. package/helps/scene/component/connection-state-subscription.ko.md +17 -0
  31. package/helps/scene/component/connection-state-subscription.md +17 -0
  32. package/helps/scene/component/connection-state-subscription.zh.md +18 -0
  33. package/helps/scene/component/data-subscription.ko.md +10 -0
  34. package/helps/scene/component/data-subscription.md +10 -0
  35. package/helps/scene/component/data-subscription.zh.md +10 -0
  36. package/helps/scene/component/scenario-control.ko.md +4 -0
  37. package/helps/scene/component/scenario-control.md +4 -0
  38. package/helps/scene/component/scenario-control.zh.md +4 -0
  39. package/helps/scene/component/scenario-instance-subscription.ko.md +23 -0
  40. package/helps/scene/component/scenario-instance-subscription.md +24 -0
  41. package/helps/scene/component/scenario-instance-subscription.zh.md +23 -0
  42. package/helps/scene/component/scenario-queue-subscription.ko.md +27 -0
  43. package/helps/scene/component/scenario-queue-subscription.md +27 -0
  44. package/helps/scene/component/scenario-run.ko.md +27 -0
  45. package/helps/scene/component/scenario-run.md +27 -0
  46. package/helps/scene/component/scenario-run.zh.md +27 -0
  47. package/helps/scene/component/scenario-start.ko.md +16 -0
  48. package/helps/scene/component/scenario-start.md +16 -0
  49. package/helps/scene/component/scenario-start.zh.md +16 -0
  50. package/helps/scene/component/scenario-stop.ko.md +12 -0
  51. package/helps/scene/component/scenario-stop.md +12 -0
  52. package/helps/scene/component/scenario-stop.zh.md +12 -0
  53. package/package.json +64 -0
  54. package/src/connection-control.ts +163 -0
  55. package/src/connection-state-subscription.ts +113 -0
  56. package/src/data-subscription.ts +103 -0
  57. package/src/editors/index.js +1 -0
  58. package/src/index.ts +21 -0
  59. package/src/origin-client.ts +136 -0
  60. package/src/scenario-control.ts +163 -0
  61. package/src/scenario-instance-subscription.ts +133 -0
  62. package/src/scenario-queue-subscription.ts +91 -0
  63. package/src/scenario-run.ts +157 -0
  64. package/src/scenario-start.ts +155 -0
  65. package/src/scenario-stop.ts +143 -0
  66. package/templates/connection-control.js +17 -0
  67. package/templates/connection-state-subscription.js +17 -0
  68. package/templates/data-subscription.js +17 -0
  69. package/templates/index.js +21 -0
  70. package/templates/scenario-control.js +18 -0
  71. package/templates/scenario-instance-subscription.js +17 -0
  72. package/templates/scenario-queue-subscription.js +17 -0
  73. package/templates/scenario-run.js +17 -0
  74. package/templates/scenario-start.js +17 -0
  75. package/templates/scenario-stop.js +17 -0
  76. package/things-scene.config.js +7 -0
  77. package/translations/en.json +9 -0
  78. package/translations/ko.json +9 -0
  79. package/translations/ms.json +9 -0
  80. package/translations/zh.json +9 -0
  81. package/tsconfig.json +23 -0
  82. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,163 @@
1
+ import { Component, DataSource, Properties, RectPath, Shape } from '@hatiolab/things-scene'
2
+
3
+ /*
4
+ * Copyright © HatioLab Inc. All rights reserved.
5
+ */
6
+ import COMPONENT_IMAGE from '../assets/symbol-scenario-control.png'
7
+ import { getClient } from './origin-client'
8
+ import gql from 'graphql-tag'
9
+
10
+ const NATURE = {
11
+ mutable: false,
12
+ resizable: true,
13
+ rotatable: true,
14
+ properties: [
15
+ {
16
+ type: 'select',
17
+ label: 'scenario-name',
18
+ name: 'scenarioName',
19
+ property: {
20
+ options: async () => {
21
+ var response = await getClient().query({
22
+ query: gql`
23
+ query {
24
+ scenarios {
25
+ items {
26
+ name
27
+ }
28
+ }
29
+ }
30
+ `
31
+ })
32
+ if (response.errors) {
33
+ return ['']
34
+ }
35
+
36
+ return [''].concat(response.data.scenarios.items.map((item: any) => item.name))
37
+ }
38
+ }
39
+ },
40
+ {
41
+ type: 'select',
42
+ label: 'control-type',
43
+ name: 'controlType',
44
+ property: {
45
+ options: [
46
+ {
47
+ display: '',
48
+ value: ''
49
+ },
50
+ {
51
+ display: 'start',
52
+ value: 'start'
53
+ },
54
+ {
55
+ display: 'stop',
56
+ value: 'stop'
57
+ }
58
+ ]
59
+ }
60
+ }
61
+ ],
62
+ 'value-property': 'controlType',
63
+ help: 'scene/component/scenario-control'
64
+ }
65
+
66
+ export default class ScenarioControl extends DataSource(RectPath(Shape)) {
67
+ static _image: HTMLImageElement
68
+
69
+ static get image() {
70
+ if (!ScenarioControl._image) {
71
+ ScenarioControl._image = new Image()
72
+ ScenarioControl._image.src = COMPONENT_IMAGE
73
+ }
74
+ return ScenarioControl._image
75
+ }
76
+
77
+ private _client: any
78
+
79
+ render(context: CanvasRenderingContext2D) {
80
+ var { left, top, width, height } = this.bounds
81
+ context.beginPath()
82
+ this.drawImage(context, ScenarioControl.image, left, top, width, height)
83
+ }
84
+
85
+ ready() {
86
+ super.ready()
87
+ this._initScenario()
88
+ }
89
+
90
+ _initScenario() {
91
+ if (!this.app.isViewMode) return
92
+
93
+ this._client = getClient()
94
+ this.requestData()
95
+ }
96
+
97
+ dispose() {
98
+ super.dispose()
99
+
100
+ try {
101
+ if (this._client) {
102
+ this._client.stop()
103
+ }
104
+ } catch (e) {
105
+ console.error(e)
106
+ }
107
+ delete this._client
108
+ }
109
+
110
+ get nature() {
111
+ return NATURE
112
+ }
113
+
114
+ onchange(after: Properties) {
115
+ if ('controlType' in after) {
116
+ this.requestData()
117
+ }
118
+ }
119
+
120
+ get client() {
121
+ return this._client
122
+ }
123
+
124
+ get controlType() {
125
+ return this.getState('controlType')
126
+ }
127
+
128
+ set controlType(controlType) {
129
+ this.setState('controlType', controlType)
130
+ }
131
+
132
+ async requestData() {
133
+ let { controlType, scenarioName } = this.state
134
+ if (!controlType || !scenarioName || !this.app.isViewMode) return
135
+ var client = this._client
136
+ var query = ''
137
+ if (controlType == 'start') {
138
+ query = `mutation{
139
+ ${controlType}Scenario(instanceName: "${scenarioName}", scenarioName: "${scenarioName}", variables: {}) {
140
+ state
141
+ }
142
+ }`
143
+ } else {
144
+ query = `mutation{
145
+ ${controlType}Scenario(instanceName: "${scenarioName}") {
146
+ state
147
+ }
148
+ }`
149
+ }
150
+
151
+ if (client) {
152
+ var response = await client.query({
153
+ query: gql`
154
+ ${query}
155
+ `
156
+ })
157
+
158
+ this.data = response
159
+ }
160
+ }
161
+ }
162
+
163
+ Component.register('scenario-control', ScenarioControl)
@@ -0,0 +1,133 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import gql from 'graphql-tag'
6
+
7
+ import { Component, DataSource, RectPath, Shape } from '@hatiolab/things-scene'
8
+
9
+ import COMPONENT_IMAGE from '../assets/symbol-scenario-instance-subscription.png'
10
+ import { getClient, subscribe } from './origin-client'
11
+
12
+ const NATURE = {
13
+ mutable: false,
14
+ resizable: true,
15
+ rotatable: true,
16
+ properties: [
17
+ {
18
+ type: 'select',
19
+ label: 'scenario-name',
20
+ name: 'scenarioName',
21
+ property: {
22
+ options: async () => {
23
+ var response = await getClient().query({
24
+ query: gql`
25
+ query {
26
+ scenarios {
27
+ items {
28
+ name
29
+ }
30
+ }
31
+ }
32
+ `
33
+ })
34
+ if (response.errors) {
35
+ return ['']
36
+ }
37
+
38
+ return [''].concat(response.data.scenarios.items.map((item: any) => item.name))
39
+ }
40
+ }
41
+ },
42
+ {
43
+ type: 'string',
44
+ label: 'instance-name',
45
+ name: 'instanceName'
46
+ }
47
+ ],
48
+ help: 'scene/component/scenario-instance-subscription'
49
+ }
50
+
51
+ export default class ScenarioInstanceSubscription extends DataSource(RectPath(Shape)) {
52
+ static _image: HTMLImageElement
53
+
54
+ static get image() {
55
+ if (!ScenarioInstanceSubscription._image) {
56
+ ScenarioInstanceSubscription._image = new Image()
57
+ ScenarioInstanceSubscription._image.src = COMPONENT_IMAGE
58
+ }
59
+
60
+ return ScenarioInstanceSubscription._image
61
+ }
62
+
63
+ private subscription?: {
64
+ unsubscribe(): void
65
+ }
66
+
67
+ dispose() {
68
+ super.dispose()
69
+
70
+ this.subscription?.unsubscribe()
71
+ delete this.subscription
72
+ }
73
+
74
+ render(context: CanvasRenderingContext2D) {
75
+ var { left, top, width, height } = this.bounds
76
+
77
+ context.beginPath()
78
+ this.drawImage(context, ScenarioInstanceSubscription.image, left, top, width, height)
79
+ }
80
+
81
+ ready() {
82
+ if (!this.app.isViewMode) return
83
+ this._initScenarioInstanceSubscription()
84
+ }
85
+
86
+ get nature() {
87
+ return NATURE
88
+ }
89
+
90
+ _initScenarioInstanceSubscription() {
91
+ if (!this.app.isViewMode) return
92
+ this.startSubscribe()
93
+ }
94
+
95
+ async startSubscribe() {
96
+ var { instanceName, scenarioName = '' } = this.state
97
+
98
+ instanceName = instanceName || scenarioName
99
+
100
+ this.subscription = await subscribe(
101
+ {
102
+ query: gql`
103
+ subscription {
104
+ scenarioInstanceState(instanceName: "${instanceName}", scenarioName: "${scenarioName}") {
105
+ instanceName
106
+ scenarioName
107
+ state
108
+ variables
109
+ progress{
110
+ rounds
111
+ rate
112
+ steps
113
+ step
114
+ }
115
+ data
116
+ message
117
+ timestamp
118
+ }
119
+ }
120
+ `
121
+ },
122
+ {
123
+ next: async ({ data }: { data: any }) => {
124
+ if (data) {
125
+ this.data = data.scenarioInstanceState
126
+ }
127
+ }
128
+ }
129
+ )
130
+ }
131
+ }
132
+
133
+ Component.register('scenario-instance-subscription', ScenarioInstanceSubscription)
@@ -0,0 +1,91 @@
1
+ /*
2
+ * Copyright © HatioLab Inc. All rights reserved.
3
+ */
4
+
5
+ import gql from 'graphql-tag'
6
+
7
+ import { Component, DataSource, RectPath, Shape } from '@hatiolab/things-scene'
8
+
9
+ import COMPONENT_IMAGE from '../assets/symbol-scenario-queue-subscription.png'
10
+ import { subscribe } from './origin-client'
11
+
12
+ const NATURE = {
13
+ mutable: false,
14
+ resizable: true,
15
+ rotatable: true,
16
+ properties: [],
17
+ help: 'scene/component/scenario-queue-subscription'
18
+ }
19
+
20
+ export default class ScenarioQueueSubscription extends DataSource(RectPath(Shape)) {
21
+ static _image: HTMLImageElement
22
+
23
+ static get image() {
24
+ if (!ScenarioQueueSubscription._image) {
25
+ ScenarioQueueSubscription._image = new Image()
26
+ ScenarioQueueSubscription._image.src = COMPONENT_IMAGE
27
+ }
28
+
29
+ return ScenarioQueueSubscription._image
30
+ }
31
+
32
+ private subscription?: {
33
+ unsubscribe(): void
34
+ }
35
+
36
+ dispose() {
37
+ super.dispose()
38
+
39
+ this.subscription?.unsubscribe()
40
+ delete this.subscription
41
+ }
42
+
43
+ render(context: CanvasRenderingContext2D) {
44
+ var { left, top, width, height } = this.bounds
45
+
46
+ context.beginPath()
47
+ this.drawImage(context, ScenarioQueueSubscription.image, left, top, width, height)
48
+ }
49
+
50
+ ready() {
51
+ if (!this.app.isViewMode) return
52
+ this._initScenarioQueueSubscription()
53
+ }
54
+
55
+ get nature() {
56
+ return NATURE
57
+ }
58
+
59
+ _initScenarioQueueSubscription() {
60
+ if (!this.app.isViewMode) return
61
+ this.startSubscribe()
62
+ }
63
+
64
+ async startSubscribe() {
65
+ this.subscription = await subscribe(
66
+ {
67
+ query: gql`
68
+ subscription {
69
+ scenarioQueueState {
70
+ queue {
71
+ stuff
72
+ due
73
+ priority
74
+ tag
75
+ }
76
+ }
77
+ }
78
+ `
79
+ },
80
+ {
81
+ next: async ({ data }: { data: any }) => {
82
+ if (data) {
83
+ this.data = data.scenarioQueueState
84
+ }
85
+ }
86
+ }
87
+ )
88
+ }
89
+ }
90
+
91
+ Component.register('scenario-queue-subscription', ScenarioQueueSubscription)
@@ -0,0 +1,157 @@
1
+ import { Component, DataSource, Properties, RectPath, Shape } from '@hatiolab/things-scene'
2
+
3
+ /*
4
+ * Copyright © HatioLab Inc. All rights reserved.
5
+ */
6
+ import COMPONENT_IMAGE from '../assets/symbol-scenario-run.png'
7
+ import { getClient } from './origin-client'
8
+ import gql from 'graphql-tag'
9
+
10
+ const NATURE = {
11
+ mutable: false,
12
+ resizable: true,
13
+ rotatable: true,
14
+ properties: [
15
+ {
16
+ type: 'select',
17
+ label: 'scenario-name',
18
+ name: 'scenarioName',
19
+ property: {
20
+ options: async () => {
21
+ var response = await getClient().query({
22
+ query: gql`
23
+ query {
24
+ scenarios {
25
+ items {
26
+ name
27
+ }
28
+ }
29
+ }
30
+ `
31
+ })
32
+ if (response.errors) {
33
+ return ['']
34
+ }
35
+
36
+ return [''].concat(response.data.scenarios.items.map((item: any) => item.name))
37
+ }
38
+ }
39
+ },
40
+ {
41
+ type: 'data',
42
+ label: 'variables',
43
+ name: 'variables'
44
+ },
45
+ {
46
+ type: 'checkbox',
47
+ label: 'run-on-start',
48
+ name: 'runOnStart'
49
+ }
50
+ ],
51
+ 'value-property': 'variables',
52
+ help: 'scene/component/scenario-run'
53
+ }
54
+
55
+ export default class ScenarioRun extends DataSource(RectPath(Shape)) {
56
+ static _image: HTMLImageElement
57
+
58
+ static get image() {
59
+ if (!ScenarioRun._image) {
60
+ ScenarioRun._image = new Image()
61
+ ScenarioRun._image.src = COMPONENT_IMAGE
62
+ }
63
+ return ScenarioRun._image
64
+ }
65
+
66
+ private _client: any
67
+
68
+ render(context: CanvasRenderingContext2D) {
69
+ var { left, top, width, height } = this.bounds
70
+ context.beginPath()
71
+ this.drawImage(context, ScenarioRun.image, left, top, width, height)
72
+ }
73
+
74
+ ready() {
75
+ super.ready()
76
+ this._initScenario()
77
+ }
78
+
79
+ _initScenario() {
80
+ if (!this.app.isViewMode) {
81
+ return
82
+ }
83
+ this._client = getClient()
84
+ if (this.state.runOnStart) {
85
+ this.requestData()
86
+ }
87
+ }
88
+
89
+ dispose() {
90
+ super.dispose()
91
+
92
+ try {
93
+ if (this._client) {
94
+ this._client.stop()
95
+ }
96
+ } catch (e) {
97
+ console.error(e)
98
+ }
99
+ delete this._client
100
+ }
101
+
102
+ get nature() {
103
+ return NATURE
104
+ }
105
+
106
+ onchange(after: Properties) {
107
+ if ('variables' in after) {
108
+ this.requestData()
109
+ }
110
+ }
111
+
112
+ get variables() {
113
+ return this.state.variables
114
+ }
115
+
116
+ set variables(variables) {
117
+ this.setState('variables', variables)
118
+ }
119
+
120
+ get client() {
121
+ return this._client
122
+ }
123
+
124
+ async requestData() {
125
+ let { scenarioName, variables } = this.state
126
+ if (!scenarioName || !this.app.isViewMode) return
127
+
128
+ var client = this._client
129
+ try {
130
+ variables = typeof variables == 'string' ? JSON.parse(variables) : variables
131
+ } catch (e) {
132
+ console.warn('runScenario mutation variable is not an object')
133
+ }
134
+
135
+ if (client) {
136
+ var response = await client.query({
137
+ query: gql`
138
+ mutation ($scenarioName: String!, $variables: Object) {
139
+ runScenario(scenarioName: $scenarioName, variables: $variables) {
140
+ state
141
+ message
142
+ data
143
+ }
144
+ }
145
+ `,
146
+ variables: {
147
+ scenarioName: scenarioName,
148
+ variables
149
+ }
150
+ })
151
+
152
+ this.data = response?.data?.runScenario?.data
153
+ }
154
+ }
155
+ }
156
+
157
+ Component.register('scenario-run', ScenarioRun)
@@ -0,0 +1,155 @@
1
+ import { Component, DataSource, Properties, RectPath, Shape } from '@hatiolab/things-scene'
2
+
3
+ /*
4
+ * Copyright © HatioLab Inc. All rights reserved.
5
+ */
6
+ import COMPONENT_IMAGE from '../assets/symbol-scenario-start.png'
7
+ import { getClient } from './origin-client'
8
+ import gql from 'graphql-tag'
9
+
10
+ const NATURE = {
11
+ mutable: false,
12
+ resizable: true,
13
+ rotatable: true,
14
+ properties: [
15
+ {
16
+ type: 'string',
17
+ label: 'instance-name',
18
+ name: 'instanceName'
19
+ },
20
+ {
21
+ type: 'select',
22
+ label: 'scenario-name',
23
+ name: 'scenarioName',
24
+ property: {
25
+ options: async () => {
26
+ var response = await getClient().query({
27
+ query: gql`
28
+ query {
29
+ scenarios {
30
+ items {
31
+ name
32
+ }
33
+ }
34
+ }
35
+ `
36
+ })
37
+ if (response.errors) {
38
+ return ['']
39
+ }
40
+
41
+ return [''].concat(response.data.scenarios.items.map((item: any) => item.name))
42
+ }
43
+ }
44
+ },
45
+ {
46
+ type: 'data',
47
+ label: 'variables',
48
+ name: 'variables'
49
+ }
50
+ ],
51
+ 'value-property': 'variables',
52
+ help: 'scene/component/scenario-start'
53
+ }
54
+
55
+ export default class ScenarioStart extends DataSource(RectPath(Shape)) {
56
+ static _image: HTMLImageElement
57
+
58
+ static get image() {
59
+ if (!ScenarioStart._image) {
60
+ ScenarioStart._image = new Image()
61
+ ScenarioStart._image.src = COMPONENT_IMAGE
62
+ }
63
+ return ScenarioStart._image
64
+ }
65
+
66
+ private _client: any
67
+
68
+ render(context: CanvasRenderingContext2D) {
69
+ var { left, top, width, height } = this.bounds
70
+ context.beginPath()
71
+ this.drawImage(context, ScenarioStart.image, left, top, width, height)
72
+ }
73
+
74
+ ready() {
75
+ super.ready()
76
+ this._initScenario()
77
+ }
78
+
79
+ _initScenario() {
80
+ if (!this.app.isViewMode) {
81
+ return
82
+ }
83
+ this._client = getClient()
84
+ }
85
+
86
+ dispose() {
87
+ super.dispose()
88
+
89
+ try {
90
+ if (this._client) {
91
+ this._client.stop()
92
+ }
93
+ } catch (e) {
94
+ console.error(e)
95
+ }
96
+ delete this._client
97
+ }
98
+
99
+ get nature() {
100
+ return NATURE
101
+ }
102
+
103
+ async onchange(after: Properties) {
104
+ if ('variables' in after) {
105
+ this.requestData()
106
+ }
107
+ }
108
+
109
+ get variables() {
110
+ return this.state.variables
111
+ }
112
+
113
+ set variables(variables) {
114
+ this.setState('variables', variables)
115
+ }
116
+
117
+ get client() {
118
+ return this._client
119
+ }
120
+
121
+ async requestData() {
122
+ let { instanceName, scenarioName, variables } = this.state
123
+ if (!scenarioName || !this.app.isViewMode) return
124
+
125
+ var client = this._client
126
+ try {
127
+ variables = typeof variables == 'string' ? JSON.parse(variables) : variables
128
+ } catch (e) {
129
+ console.error(e)
130
+ }
131
+
132
+ if (client) {
133
+ var response = await client.query({
134
+ query: gql`
135
+ mutation ($instanceName: String, $scenarioName: String!, $variables: Object) {
136
+ startScenario(instanceName: $instanceName, scenarioName: $scenarioName, variables: $variables) {
137
+ state
138
+ message
139
+ data
140
+ }
141
+ }
142
+ `,
143
+ variables: {
144
+ instanceName: instanceName,
145
+ scenarioName: scenarioName,
146
+ variables
147
+ }
148
+ })
149
+
150
+ this.data = response?.data?.startScenario?.data
151
+ }
152
+ }
153
+ }
154
+
155
+ Component.register('scenario-start', ScenarioStart)