@things-factory/kpi 10.1.39 → 10.1.40
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/dist-server/service/index.d.ts +2 -2
- package/dist-server/service/kpi/index.d.ts +1 -1
- package/dist-server/service/kpi-metric/kpi-metric.js +7 -1
- package/dist-server/service/kpi-metric/kpi-metric.js.map +1 -1
- package/dist-server/service/kpi-value/index.d.ts +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/tests/entities-sqlite.test.ts +92 -0
- package/tests/list-search-db.test.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@things-factory/kpi",
|
|
3
|
-
"version": "10.1.
|
|
3
|
+
"version": "10.1.40",
|
|
4
4
|
"main": "dist-server/index.js",
|
|
5
5
|
"browser": "dist-client/index.js",
|
|
6
6
|
"things-factory": true,
|
|
@@ -41,9 +41,9 @@
|
|
|
41
41
|
"@operato/shell": "^10.0.0",
|
|
42
42
|
"@operato/styles": "^10.0.0",
|
|
43
43
|
"@operato/utils": "^10.0.0",
|
|
44
|
-
"@things-factory/auth-base": "^10.1.
|
|
45
|
-
"@things-factory/dataset": "^10.1.
|
|
46
|
-
"@things-factory/shell": "^10.1.
|
|
44
|
+
"@things-factory/auth-base": "^10.1.40",
|
|
45
|
+
"@things-factory/dataset": "^10.1.40",
|
|
46
|
+
"@things-factory/shell": "^10.1.40"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "51c5d804c14ad8fcc6d4707e6ef80c9deede2766"
|
|
49
49
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* kpi's tables build on sqlite - the development default.
|
|
3
|
+
*
|
|
4
|
+
* KpiMetric.collectType was declared type 'enum', a name only postgres and mysql know. The sqlite driver
|
|
5
|
+
* refused it when the DataSource opened (DataTypeNotSupportedError), so no app with kpi could start on
|
|
6
|
+
* sqlite, and list-search-db could only run on postgres. It is 'simple-enum' now: postgres and mysql turn
|
|
7
|
+
* it into the same native enum as before (an existing postgres table sees no schema change), sqlite a
|
|
8
|
+
* varchar with a CHECK.
|
|
9
|
+
*
|
|
10
|
+
* Needs kpi's dist-server, for the same reason list-search-db does:
|
|
11
|
+
*
|
|
12
|
+
* yarn workspace @things-factory/kpi build:server
|
|
13
|
+
* yarn _test packages/kpi/tests
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import type { DataSource } from 'typeorm'
|
|
17
|
+
import { existsSync } from 'fs'
|
|
18
|
+
import { join } from 'path'
|
|
19
|
+
|
|
20
|
+
/* Entities pick their column types from ormconfig.type when they load, so the driver is named first. */
|
|
21
|
+
require('@things-factory/env').config.set('ormconfig', { type: 'sqlite' })
|
|
22
|
+
|
|
23
|
+
const { DataSource: TypeOrmDataSource } = require('typeorm')
|
|
24
|
+
const shell = require('@things-factory/shell')
|
|
25
|
+
const authBase = require('@things-factory/auth-base')
|
|
26
|
+
/* The same closed entity graph list-search-db builds: KpiMetric -> DataSet -> Scenario, worklist. */
|
|
27
|
+
const integration = require('@things-factory/integration-base')
|
|
28
|
+
const worklist = require('@things-factory/worklist')
|
|
29
|
+
const dataset = require('@things-factory/dataset')
|
|
30
|
+
const attachment = require('@things-factory/attachment-base')
|
|
31
|
+
|
|
32
|
+
const DIST = join(__dirname, '..', 'dist-server')
|
|
33
|
+
if (!existsSync(join(DIST, 'service', 'index.js'))) {
|
|
34
|
+
throw new Error(`kpi's dist-server is missing - run "yarn workspace @things-factory/kpi build:server" first`)
|
|
35
|
+
}
|
|
36
|
+
const kpi = require(join(DIST, 'service', 'index.js'))
|
|
37
|
+
|
|
38
|
+
let dataSource: DataSource
|
|
39
|
+
let domain: any
|
|
40
|
+
|
|
41
|
+
describe('kpi entities on sqlite', () => {
|
|
42
|
+
beforeAll(async () => {
|
|
43
|
+
dataSource = new TypeOrmDataSource({
|
|
44
|
+
type: 'sqlite',
|
|
45
|
+
database: ':memory:',
|
|
46
|
+
synchronize: true,
|
|
47
|
+
dropSchema: true,
|
|
48
|
+
namingStrategy: new shell.NamingStrategy(),
|
|
49
|
+
entities: [
|
|
50
|
+
...shell.entities,
|
|
51
|
+
...authBase.entities,
|
|
52
|
+
...attachment.entities,
|
|
53
|
+
...integration.entities,
|
|
54
|
+
...worklist.entities,
|
|
55
|
+
...dataset.entities,
|
|
56
|
+
...kpi.entities
|
|
57
|
+
],
|
|
58
|
+
logging: false
|
|
59
|
+
})
|
|
60
|
+
await dataSource.initialize()
|
|
61
|
+
domain = await dataSource.getRepository(shell.Domain).save({ name: 'Plant A', subdomain: 'plant-a' })
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
afterAll(async () => {
|
|
65
|
+
if (dataSource?.isInitialized) await dataSource.destroy()
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('builds every kpi table', async () => {
|
|
69
|
+
const tables = (await dataSource.query(`SELECT name FROM sqlite_master WHERE type = 'table'`)).map(
|
|
70
|
+
(row: any) => row.name
|
|
71
|
+
)
|
|
72
|
+
for (const entity of kpi.entities) {
|
|
73
|
+
expect(tables).toContain(dataSource.getMetadata(entity).tableName)
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('a metric takes AUTO when no collect type is given, and keeps the one it is given', async () => {
|
|
78
|
+
const repo = dataSource.getRepository(kpi.KpiMetric)
|
|
79
|
+
const auto = await repo.save({ domain, name: 'Downtime minutes' })
|
|
80
|
+
const manual = await repo.save({ domain, name: 'Good units', collectType: kpi.KpiMetricCollectType.MANUAL })
|
|
81
|
+
expect((await repo.findOneBy({ id: auto.id })).collectType).toBe('AUTO')
|
|
82
|
+
expect((await repo.findOneBy({ id: manual.id })).collectType).toBe('MANUAL')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('refuses a collect type outside the enum - the column still holds only its values', async () => {
|
|
86
|
+
const table = dataSource.getMetadata(kpi.KpiMetric).tableName
|
|
87
|
+
await dataSource.getRepository(kpi.KpiMetric).save({ domain, name: 'Scrap count' })
|
|
88
|
+
await expect(
|
|
89
|
+
dataSource.query(`UPDATE "${table}" SET "collect_type" = 'SOMETHING_ELSE'`)
|
|
90
|
+
).rejects.toThrow(/CHECK constraint failed/)
|
|
91
|
+
})
|
|
92
|
+
})
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* docker run -d --rm --name kpi-pg -e POSTGRES_PASSWORD=x -p 55433:5432 postgres:14-alpine
|
|
14
14
|
* TEST_POSTGRES_URL=postgres://postgres:x@localhost:55433/postgres yarn _test packages/kpi/tests
|
|
15
15
|
*
|
|
16
|
-
* Not sqlite
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* Not sqlite: sqlite lowers a uuid without complaint, so it cannot show the defect. (It builds these
|
|
17
|
+
* tables since KpiMetric.collectType became 'simple-enum' - entities-sqlite.test.ts keeps that so.)
|
|
18
|
+
* Without the variable the suite is skipped, and says so.
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
import type { DataSource } from 'typeorm'
|