@things-factory/integration-base 8.0.41 → 8.0.54

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@things-factory/integration-base",
3
- "version": "8.0.41",
3
+ "version": "8.0.54",
4
4
  "main": "dist-server/index.js",
5
5
  "browser": "client/index.js",
6
6
  "things-factory": true,
@@ -27,13 +27,13 @@
27
27
  "dependencies": {
28
28
  "@apollo/client": "^3.6.9",
29
29
  "@operato/moment-timezone-es": "^8.0.0",
30
- "@things-factory/api": "^8.0.41",
31
- "@things-factory/auth-base": "^8.0.41",
32
- "@things-factory/cache-service": "^8.0.41",
30
+ "@things-factory/api": "^8.0.54",
31
+ "@things-factory/auth-base": "^8.0.54",
32
+ "@things-factory/cache-service": "^8.0.54",
33
33
  "@things-factory/env": "^8.0.37",
34
- "@things-factory/oauth2-client": "^8.0.41",
35
- "@things-factory/scheduler-client": "^8.0.41",
36
- "@things-factory/shell": "^8.0.38",
34
+ "@things-factory/oauth2-client": "^8.0.54",
35
+ "@things-factory/scheduler-client": "^8.0.54",
36
+ "@things-factory/shell": "^8.0.54",
37
37
  "@things-factory/utils": "^8.0.37",
38
38
  "async-mqtt": "^2.5.0",
39
39
  "chance": "^1.1.11",
@@ -44,5 +44,5 @@
44
44
  "readline": "^1.3.0",
45
45
  "ses": "^1.5.0"
46
46
  },
47
- "gitHead": "68ed47dc717d534edbee63adf16d2a84df73f501"
47
+ "gitHead": "b222492ba1cb28c9095a66ce2207c8954bcb4b37"
48
48
  }
@@ -1,9 +1,10 @@
1
- import gql from 'graphql-tag'
2
1
  import { TaskRegistry } from '../task-registry'
3
2
  import { InputStep } from '../../service/step/step-type'
4
3
  import { Context } from '../types'
4
+ import { getRepository } from '@things-factory/shell'
5
+ import { StateRegister } from '../../service/state-register/state-register'
5
6
 
6
- async function StateRead(step: InputStep, { logger, publish, data, domain, user, client }: Context) {
7
+ async function StateRead(step: InputStep, { logger, publish, data, domain, user }: Context) {
7
8
  var {
8
9
  params: { name }
9
10
  } = step
@@ -12,34 +13,11 @@ async function StateRead(step: InputStep, { logger, publish, data, domain, user,
12
13
  throw Error(`name should be defined: name - '${name}'`)
13
14
  }
14
15
 
15
- var { data: queryResult, errors } = await client.query({
16
- query: gql`
17
- query ($name: String!) {
18
- stateRegisterByName(name: $name) {
19
- state
20
- }
21
- }
22
- `,
23
- variables: {
24
- name
25
- },
26
- context: {
27
- state: {
28
- domain,
29
- user
30
- }
31
- }
16
+ const result = await getRepository(StateRegister).findOne({
17
+ where: { domain: { id: domain.id }, name }
32
18
  })
33
19
 
34
- if (errors) {
35
- errors.forEach(error => {
36
- logger.error('GraphQL Error: %s', error)
37
- })
38
- }
39
-
40
- return {
41
- data: queryResult?.stateRegisterByName?.state
42
- }
20
+ return { data: result?.state }
43
21
  }
44
22
 
45
23
  StateRead.parameterSpec = [
@@ -1,10 +1,11 @@
1
- import gql from 'graphql-tag'
2
1
  import { access } from '@things-factory/utils'
3
2
  import { TaskRegistry } from '../task-registry'
4
3
  import { InputStep } from '../../service/step/step-type'
5
4
  import { Context } from '../types'
5
+ import { getRepository } from '@things-factory/shell'
6
+ import { StateRegister } from '../../service/state-register/state-register'
6
7
 
7
- async function StateWrite(step: InputStep, { logger, publish, data, domain, user, client }: Context) {
8
+ async function StateWrite(step: InputStep, { logger, publish, data, domain, user }: Context) {
8
9
  var {
9
10
  params: { name, accessor }
10
11
  } = step
@@ -15,34 +16,20 @@ async function StateWrite(step: InputStep, { logger, publish, data, domain, user
15
16
 
16
17
  var state = access(accessor, data)
17
18
 
18
- var { data: mutateResult, errors } = await client.mutate({
19
- mutation: gql`
20
- mutation ($state: Object!, $name: String!) {
21
- updateStateRegisterByName(state: $state, name: $name) {
22
- state
23
- }
24
- }
25
- `,
26
- variables: {
27
- name,
28
- state
29
- },
30
- context: {
31
- state: {
32
- domain,
33
- user
34
- }
35
- }
19
+ const repository = getRepository(StateRegister)
20
+ const stateRegister = await repository.findOne({
21
+ where: { domain: { id: domain?.id }, name }
36
22
  })
37
23
 
38
- if (errors) {
39
- errors.forEach(error => {
40
- logger.error('GraphQL Error: %s', error)
41
- })
42
- }
24
+ const result = await repository.save({
25
+ ...stateRegister,
26
+ state,
27
+ writer: user,
28
+ wroteAt: new Date()
29
+ })
43
30
 
44
31
  return {
45
- data: mutateResult?.updateStateRegisterByName?.state
32
+ data: result?.state
46
33
  }
47
34
  }
48
35