@things-factory/integration-base 6.1.154 → 6.1.156

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.
@@ -0,0 +1,24 @@
1
+ # JSonata
2
+
3
+ このタスクは JSonata 式を実行し、その結果を返します。
4
+
5
+ [JSonata](https://jsonata.org/)は JSON データを対象とする軽量なクエリおよび変換言語です。
6
+
7
+ [JSonata テスト](https://try.jsonata.org/)で式をテストできます。
8
+
9
+ ## パラメータ
10
+
11
+ ### JSonata 式(expression)
12
+
13
+ JSonata のベース(base)は次の 5 つの組み込み変数(data、variables、domain、user、lng)で構成されています。
14
+
15
+ ```
16
+ # JSonataベース(base)のJSON表現
17
+ {
18
+ data,
19
+ variables,
20
+ domain,
21
+ user,
22
+ lng
23
+ }
24
+ ```
@@ -0,0 +1,25 @@
1
+ # JSonata
2
+
3
+ JSonata 표현식을 실행하여 그 결과를 리턴하는 태스크이다.
4
+
5
+ [JSonata](https://jsonata.org/) 는 JSON 데이터를 대상으로하는 간편한 쿼리 및 변환 언어이다.
6
+
7
+ [JSonata 테스트](https://try.jsonata.org/)에서 표현식을 테스트 해볼 수 있다.
8
+
9
+ ## parameters
10
+
11
+ ### JSonata 표현식(expression)
12
+
13
+ JSonata의 베이스는 일반 [스크립트 내장변수](../concept/script-internal-variables.md)인 data, variables, domain, user, lng 다섯가지이다.
14
+
15
+ ```
16
+ # JSonata base의 json 표현
17
+ {
18
+ data,
19
+ variables,
20
+ domain,
21
+ user,
22
+ lng
23
+ }
24
+
25
+ ```
@@ -0,0 +1,24 @@
1
+ # JSonata
2
+
3
+ This task executes JSonata expressions and returns the results.
4
+
5
+ [JSonata](https://jsonata.org/) is a lightweight query and transformation language for JSON data.
6
+
7
+ You can test expressions on [JSonata Test](https://try.jsonata.org/).
8
+
9
+ ## Parameters
10
+
11
+ ### JSonata Expression (expression)
12
+
13
+ The JSonata base consists of five built-in variables (data, variables, domain, user, lng) as follows:
14
+
15
+ ```
16
+ # JSON representation of the JSonata base
17
+ {
18
+ data,
19
+ variables,
20
+ domain,
21
+ user,
22
+ lng
23
+ }
24
+ ```
@@ -0,0 +1,24 @@
1
+ # JSonata
2
+
3
+ Tugas ini menjalankan ekspresi JSonata dan mengembalikan hasilnya.
4
+
5
+ [JSonata](https://jsonata.org/) adalah bahasa kueri dan transformasi yang ringan untuk data JSON.
6
+
7
+ Anda dapat menguji ekspresi di [JSonata Test](https://try.jsonata.org/).
8
+
9
+ ## Parameter
10
+
11
+ ### Ekspresi JSonata (expression)
12
+
13
+ Basis JSonata terdiri dari lima variabel bawaan(data, variables, domain, user, lng) seperti berikut.
14
+
15
+ ```
16
+ # Representasi JSON basis(base) JSonata
17
+ {
18
+ data,
19
+ variables,
20
+ domain,
21
+ user,
22
+ lng
23
+ }
24
+ ```
@@ -0,0 +1,24 @@
1
+ # JSonata
2
+
3
+ 这个任务执行 JSonata 表达式并返回结果。
4
+
5
+ [JSonata](https://jsonata.org/) 是一种用于 JSON 数据的轻量级查询和转换语言。
6
+
7
+ 您可以在[JSonata 测试](https://try.jsonata.org/)中测试表达式。
8
+
9
+ ## 参数
10
+
11
+ ### JSonata 表达式(expression)
12
+
13
+ JSonata 的基本(base)由以下五个内置变量(data, variables, domain, user, lng)组成。
14
+
15
+ ```
16
+ # JSonata基本(base)的JSON表示
17
+ {
18
+ data,
19
+ variables,
20
+ domain,
21
+ user,
22
+ lng
23
+ }
24
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-base",
3
- "version": "6.1.154",
3
+ "version": "6.1.156",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -26,12 +26,12 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@apollo/client": "^3.6.9",
29
- "@things-factory/api": "^6.1.154",
30
- "@things-factory/auth-base": "^6.1.154",
29
+ "@things-factory/api": "^6.1.156",
30
+ "@things-factory/auth-base": "^6.1.156",
31
31
  "@things-factory/env": "^6.1.154",
32
- "@things-factory/oauth2-client": "^6.1.154",
33
- "@things-factory/scheduler-client": "^6.1.154",
34
- "@things-factory/shell": "^6.1.154",
32
+ "@things-factory/oauth2-client": "^6.1.156",
33
+ "@things-factory/scheduler-client": "^6.1.156",
34
+ "@things-factory/shell": "^6.1.156",
35
35
  "async-mqtt": "^2.5.0",
36
36
  "chance": "^1.1.11",
37
37
  "cross-fetch": "^3.0.4",
@@ -46,5 +46,5 @@
46
46
  "devDependencies": {
47
47
  "@types/cron": "^2.0.1"
48
48
  },
49
- "gitHead": "f724eab413cae097192afa2865d27664bc5b4a6f"
49
+ "gitHead": "5a0f1cd16edee089468c231b3bb97bd0c03c8727"
50
50
  }
@@ -38,3 +38,4 @@ import './headless-post'
38
38
  import './headless-scrap'
39
39
  import './set-domain'
40
40
  import './oracle-procedure'
41
+ import './jsonata'
@@ -0,0 +1,35 @@
1
+ import { TaskRegistry } from '../task-registry'
2
+ import jsonata from 'jsonata'
3
+
4
+ async function JSonata(step, context) {
5
+ var {
6
+ params: { expression }
7
+ } = step
8
+
9
+ const { domain, user, data, variables, lng, logger } = context
10
+
11
+ var result = jsonata(expression).evaluate({
12
+ domain,
13
+ user,
14
+ lng,
15
+ data,
16
+ variables
17
+ })
18
+
19
+ return {
20
+ data: result
21
+ }
22
+ }
23
+
24
+ JSonata.parameterSpec = [
25
+ {
26
+ type: 'textarea',
27
+ name: 'expression',
28
+ label: 'jsonata-expression'
29
+ }
30
+ ]
31
+
32
+ JSonata.connectorFree = true
33
+ JSonata.help = 'integration/task/jsonata'
34
+
35
+ TaskRegistry.registerTaskHandler('jsonata', JSonata)
@@ -166,12 +166,41 @@ export class ConnectionMutation {
166
166
  ): Promise<boolean> {
167
167
  const { tx, domain, user } = context.state
168
168
 
169
+ const repository = tx.getRepository(Connection)
170
+
169
171
  await Promise.all(
170
172
  connections.map(async (connection: Connection) => {
171
- await tx.getRepository(Connection).save({
173
+ const { id, name } = connection
174
+
175
+ if (id) {
176
+ const sameId = await repository.findOneBy({ id })
177
+
178
+ if (sameId) {
179
+ if (sameId.domainId != domain.id) {
180
+ throw `Connection with id '${id}:${name}' is already taken by another domain`
181
+ }
182
+
183
+ const sameName = await repository.findOneBy({ domain: { id: domain.id }, name })
184
+ if (sameName && sameName.id != id) {
185
+ throw `Connection with name '${name}' is already taken by another connection`
186
+ }
187
+
188
+ await repository.save({
189
+ ...sameId,
190
+ ...connection,
191
+ domain,
192
+ updater: user
193
+ })
194
+
195
+ return
196
+ }
197
+ }
198
+
199
+ await repository.save({
172
200
  ...connection,
173
201
  domain,
174
- updater: user
202
+ updater: user,
203
+ creator: user
175
204
  })
176
205
  })
177
206
  )
@@ -147,27 +147,62 @@ export class ScenarioMutation {
147
147
  @Arg('scenarios', type => [ScenarioPatch]) scenarios: Scenario[],
148
148
  @Ctx() context: ResolverContext
149
149
  ): Promise<boolean> {
150
- const { domain, user, tx } = context.state
150
+ const { tx, domain, user } = context.state
151
+
152
+ const repository = tx.getRepository(Scenario)
151
153
 
152
154
  await Promise.all(
153
155
  scenarios.map(async (scenario: Scenario) => {
154
- const savedScenario: Scenario = await tx.getRepository(Scenario).save({
155
- domain,
156
- ...scenario,
157
- updater: user
158
- })
159
- if (scenario.steps?.length) {
160
- await tx.getRepository(Step).save(
161
- scenario.steps.map((step: Step) => {
162
- return {
163
- ...step,
164
- domain,
165
- scenario: savedScenario,
166
- updater: user
167
- }
156
+ const { id, name } = scenario
157
+ var savedScenario
158
+
159
+ if (id) {
160
+ const sameId = await repository.findOneBy({ id })
161
+
162
+ if (sameId) {
163
+ if (sameId.domainId != domain.id) {
164
+ throw `Scenario with id '${id}:${name}' is already taken by another domain`
165
+ }
166
+
167
+ const sameName = await repository.findOneBy({ domain: { id: domain.id }, name })
168
+ if (sameName && sameName.id != id) {
169
+ throw `Scenario Name '${name}' is already taken by another scenario`
170
+ }
171
+
172
+ savedScenario = await repository.save({
173
+ ...sameId,
174
+ ...scenario,
175
+ domain,
176
+ updater: user
177
+ })
178
+ } else {
179
+ savedScenario = await repository.save({
180
+ ...scenario,
181
+ domain,
182
+ updater: user,
183
+ creator: user
168
184
  })
169
- )
185
+ }
186
+ } else {
187
+ savedScenario = await repository.save({
188
+ ...scenario,
189
+ domain,
190
+ updater: user,
191
+ creator: user
192
+ })
170
193
  }
194
+
195
+ await tx.getRepository(Step).delete({ domain: { id: domain.id }, scenario: { id: savedScenario.id } })
196
+ await tx.getRepository(Step).save(
197
+ scenario.steps.map((step: Step) => {
198
+ return {
199
+ ...step,
200
+ domain,
201
+ scenario: savedScenario,
202
+ updater: user
203
+ }
204
+ })
205
+ )
171
206
  })
172
207
  )
173
208