@nexgen-os/core 0.5.1 → 0.6.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/README.md +1 -1
- package/dist/address.d.ts +3 -62
- package/dist/connectors/activations.d.ts +63 -0
- package/dist/connectors/activations.js +73 -0
- package/dist/connectors/devices.d.ts +7 -0
- package/dist/connectors/devices.js +2 -1
- package/dist/connectors/interfaces.d.ts +2 -104
- package/dist/connectors/interfaces.js +4 -11
- package/dist/connectors/measured.d.ts +12 -0
- package/dist/connectors/measured.js +44 -0
- package/dist/connectors/meter-data.d.ts +2 -39
- package/dist/connectors/meter-data.js +3 -13
- package/dist/files/dsmr.d.ts +1 -39
- package/dist/files/dsmr.js +5 -62
- package/dist/files/enedis-r6x.d.ts +1 -32
- package/dist/files/enedis-r6x.js +5 -86
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.js +1 -0
- package/dist/files/wesmart-db.d.ts +229 -0
- package/dist/files/wesmart-db.js +412 -0
- package/dist/gestures.d.ts +19 -0
- package/dist/gestures.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/refusal.d.ts +2 -11
- package/dist/refusal.js +5 -29
- package/package.json +12 -11
package/dist/files/dsmr.js
CHANGED
|
@@ -1,62 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/** The meter's units by the `units` vocabulary's codes, where its spelling is not one. */
|
|
7
|
-
const UNITS = { m3: 'M3' };
|
|
8
|
-
/**
|
|
9
|
-
* The series of one meter in readings of a P1 port: the electricity meter
|
|
10
|
-
* (`channel` 0, the default) or the meter of the bus on that channel.
|
|
11
|
-
*/
|
|
12
|
-
export function meterSeriesOfDsmr(readings, options = {}) {
|
|
13
|
-
const channel = options.channel ?? 0;
|
|
14
|
-
const skipped = [];
|
|
15
|
-
const out = new Map();
|
|
16
|
-
readings.forEach((reading, index) => {
|
|
17
|
-
const blocking = reading.problems.filter((p) => BLOCKING.has(p.code));
|
|
18
|
-
if (blocking.length > 0 || reading.at === null) {
|
|
19
|
-
skipped.push({ index, problems: blocking });
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
for (const v of reading.values) {
|
|
23
|
-
if (v.channel !== channel)
|
|
24
|
-
continue;
|
|
25
|
-
const shape = shapeOf(v);
|
|
26
|
-
if (!shape)
|
|
27
|
-
continue;
|
|
28
|
-
const at = v.measure === 'volume' ? v.at : reading.at;
|
|
29
|
-
if (at === null)
|
|
30
|
-
continue;
|
|
31
|
-
const unit = v.unit ? UNITS[v.unit] ?? v.unit : undefined;
|
|
32
|
-
const key = `${shape.quantity_code} ${shape.name ?? ''} ${unit ?? ''}`;
|
|
33
|
-
let s = out.get(key);
|
|
34
|
-
if (!s) {
|
|
35
|
-
s = { ...shape, step: null, ...(unit ? { unit } : {}), values: [] };
|
|
36
|
-
out.set(key, s);
|
|
37
|
-
}
|
|
38
|
-
s.values.push({ at, value: v.value, quality: 0 });
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
const series = [...out.values()];
|
|
42
|
-
for (const s of series) {
|
|
43
|
-
// One value per instant, in time order: a meter of the bus repeats its
|
|
44
|
-
// last volume in every telegram until it sends a new one.
|
|
45
|
-
const seen = new Set();
|
|
46
|
-
s.values = s.values.sort((a, b) => a.at.localeCompare(b.at)).filter((p) => !seen.has(p.at) && seen.add(p.at));
|
|
47
|
-
}
|
|
48
|
-
return { series, skipped };
|
|
49
|
-
}
|
|
50
|
-
function shapeOf(v) {
|
|
51
|
-
if (v.measure === 'energy' && v.kind === 'cumulative' && v.direction) {
|
|
52
|
-
return { quantity_code: `${v.direction}_energy`, value_kind: 'cumulative', name: v.tariff ? `tariff ${v.tariff}` : null };
|
|
53
|
-
}
|
|
54
|
-
if (v.measure === 'power' && v.kind === 'instant' && v.direction) {
|
|
55
|
-
return { quantity_code: `${v.direction}_power`, value_kind: 'instant', name: v.phase };
|
|
56
|
-
}
|
|
57
|
-
if (v.measure === 'voltage' && v.kind === 'instant')
|
|
58
|
-
return { quantity_code: 'voltage', value_kind: 'instant', name: v.phase };
|
|
59
|
-
if (v.measure === 'volume' && v.kind === 'cumulative')
|
|
60
|
-
return { quantity_code: 'volume', value_kind: 'cumulative', name: null };
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
1
|
+
// The readings of a P1 port as the series of a meter: `meterSeriesOfDsmr()`
|
|
2
|
+
// lives in `@nexgen-os/connector`, MIT, so that a connector that receives
|
|
3
|
+
// them (`mqtt`) maps them without the core (decision 0064); the core
|
|
4
|
+
// re-exports it, one definition for both.
|
|
5
|
+
export { meterSeriesOfDsmr } from '@nexgen-os/connector';
|
|
@@ -1,32 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* An R63 or R64 file of Enedis, once read, as the series of a meter.
|
|
3
|
-
*
|
|
4
|
-
* `@nexgen-os/enedis-r6x` reads the file with the zone and the quality table
|
|
5
|
-
* of the operator's hub (`grid.operators.meter_data`); `meterSeriesOfR6x()`
|
|
6
|
-
* names what it read in the core's terms, ready for `storeSeries()` or
|
|
7
|
-
* `collectMeterReadings()`. One reading, one mapping, whichever way the file
|
|
8
|
-
* came: through an intermediary (Switchgrid), from the operator's own
|
|
9
|
-
* channel, or uploaded by a person.
|
|
10
|
-
*
|
|
11
|
-
* | File | Quantity | Value kind |
|
|
12
|
-
* |---|---|---|
|
|
13
|
-
* | `PA` `CONS` / `PROD` | `offtake_power` / `injection_power` | interval, the file's step |
|
|
14
|
-
* | `PRI` / `PRC` `CONS` | `reactive_power_inductive` / `_capacitive` | interval |
|
|
15
|
-
* | `E` | `voltage` | interval |
|
|
16
|
-
* | `EA` index `CONS` / `PROD` | `offtake_energy` / `injection_energy` | cumulative, one series per dial named `calendar/time class` |
|
|
17
|
-
*
|
|
18
|
-
* Values stay in the file's unit, which `store()` converts. A problem that
|
|
19
|
-
* would make a value wrong (no zone, a letter without a code, a date not
|
|
20
|
-
* read) refuses the file by name; nothing is stored half.
|
|
21
|
-
*/
|
|
22
|
-
import { type R6xFile } from '@nexgen-os/enedis-r6x';
|
|
23
|
-
import type { CollectedSeries } from '../connectors/interfaces.js';
|
|
24
|
-
import type { MeterDataHub } from '../connectors/meter-data.js';
|
|
25
|
-
/** Reads a file with the conventions of the hub it came from. */
|
|
26
|
-
export declare function readMeterFile(text: string | Record<string, unknown>, hub: Pick<MeterDataHub, 'time_zone' | 'quality_codes'>): R6xFile;
|
|
27
|
-
/**
|
|
28
|
-
* The series of one metering point in a file read by `@nexgen-os/enedis-r6x`,
|
|
29
|
-
* as `CollectedSeries`. Refuses `meter_file_unreadable` with the problems
|
|
30
|
-
* that make it so, `meter_file_empty` when the point is not in the file.
|
|
31
|
-
*/
|
|
32
|
-
export declare function meterSeriesOfR6x(file: R6xFile, prm: string): CollectedSeries[];
|
|
1
|
+
export { meterSeriesOfR6x, readMeterFile } from '@nexgen-os/connector';
|
package/dist/files/enedis-r6x.js
CHANGED
|
@@ -1,86 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* names what it read in the core's terms, ready for `storeSeries()` or
|
|
7
|
-
* `collectMeterReadings()`. One reading, one mapping, whichever way the file
|
|
8
|
-
* came: through an intermediary (Switchgrid), from the operator's own
|
|
9
|
-
* channel, or uploaded by a person.
|
|
10
|
-
*
|
|
11
|
-
* | File | Quantity | Value kind |
|
|
12
|
-
* |---|---|---|
|
|
13
|
-
* | `PA` `CONS` / `PROD` | `offtake_power` / `injection_power` | interval, the file's step |
|
|
14
|
-
* | `PRI` / `PRC` `CONS` | `reactive_power_inductive` / `_capacitive` | interval |
|
|
15
|
-
* | `E` | `voltage` | interval |
|
|
16
|
-
* | `EA` index `CONS` / `PROD` | `offtake_energy` / `injection_energy` | cumulative, one series per dial named `calendar/time class` |
|
|
17
|
-
*
|
|
18
|
-
* Values stay in the file's unit, which `store()` converts. A problem that
|
|
19
|
-
* would make a value wrong (no zone, a letter without a code, a date not
|
|
20
|
-
* read) refuses the file by name; nothing is stored half.
|
|
21
|
-
*/
|
|
22
|
-
import { readR6x, durationMs } from '@nexgen-os/enedis-r6x';
|
|
23
|
-
import { GestureError } from '../refusal.js';
|
|
24
|
-
/** Problems of a reading that refuse the file: what is left would be wrong. */
|
|
25
|
-
const BLOCKING = new Set(['file_unreadable', 'time_zone_required', 'local_time_nonexistent', 'date_unreadable', 'quality_unknown']);
|
|
26
|
-
/** The file's units by the `units` vocabulary's codes, where its spelling is not one. */
|
|
27
|
-
const UNITS = { VAr: 'V-A_Reactive', var: 'V-A_Reactive', kVAr: 'KiloV-A_Reactive' };
|
|
28
|
-
/** Reads a file with the conventions of the hub it came from. */
|
|
29
|
-
export function readMeterFile(text, hub) {
|
|
30
|
-
const options = { qualityCodes: hub.quality_codes, ...(hub.time_zone ? { timeZone: hub.time_zone } : {}) };
|
|
31
|
-
return readR6x(text, options);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* The series of one metering point in a file read by `@nexgen-os/enedis-r6x`,
|
|
35
|
-
* as `CollectedSeries`. Refuses `meter_file_unreadable` with the problems
|
|
36
|
-
* that make it so, `meter_file_empty` when the point is not in the file.
|
|
37
|
-
*/
|
|
38
|
-
export function meterSeriesOfR6x(file, prm) {
|
|
39
|
-
const blocking = file.problems.filter((p) => BLOCKING.has(p.code));
|
|
40
|
-
if (blocking.length) {
|
|
41
|
-
throw new GestureError(`meter_file_unreadable: ${blocking.slice(0, 3).map((p) => `${p.code} (${p.detail})`).join('; ')}`);
|
|
42
|
-
}
|
|
43
|
-
const ours = file.series.filter((s) => s.prm === prm);
|
|
44
|
-
if (ours.length === 0)
|
|
45
|
-
throw new GestureError(`meter_file_empty: the file holds no measures of ${prm}`);
|
|
46
|
-
const out = [];
|
|
47
|
-
for (const s of ours) {
|
|
48
|
-
const quantity = quantityOf(s);
|
|
49
|
-
if (!quantity)
|
|
50
|
-
continue;
|
|
51
|
-
out.push({
|
|
52
|
-
quantity_code: quantity,
|
|
53
|
-
value_kind: s.kind === 'index' ? 'cumulative' : 'interval',
|
|
54
|
-
step: s.kind === 'index' ? null : postgresStep(s.step),
|
|
55
|
-
...(s.unit ? { unit: UNITS[s.unit] ?? s.unit } : {}),
|
|
56
|
-
...(s.kind === 'index' ? { name: [s.calendar, s.time_class].filter(Boolean).join('/') || null } : {}),
|
|
57
|
-
values: s.points.map((p) => ({ at: p.start, value: p.value, quality: p.quality })),
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
return out;
|
|
61
|
-
}
|
|
62
|
-
function quantityOf(s) {
|
|
63
|
-
const offtake = s.business === 'CONS';
|
|
64
|
-
const injection = s.business === 'PROD';
|
|
65
|
-
if (!offtake && !injection)
|
|
66
|
-
return null;
|
|
67
|
-
if (s.kind === 'index')
|
|
68
|
-
return s.physical === 'EA' ? (offtake ? 'offtake_energy' : 'injection_energy') : null;
|
|
69
|
-
switch (s.physical) {
|
|
70
|
-
case 'PA': return offtake ? 'offtake_power' : 'injection_power';
|
|
71
|
-
// Reactive power and voltage are read on the offtake side; the core has
|
|
72
|
-
// one series of each per meter.
|
|
73
|
-
case 'PRI': return offtake ? 'reactive_power_inductive' : null;
|
|
74
|
-
case 'PRC': return offtake ? 'reactive_power_capacitive' : null;
|
|
75
|
-
case 'E': return offtake ? 'voltage' : null;
|
|
76
|
-
default: return null;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
/** `PT5M` as Postgres writes an interval, `5 minutes`; null for an irregular curve. */
|
|
80
|
-
function postgresStep(step) {
|
|
81
|
-
const ms = step ? durationMs(step) : null;
|
|
82
|
-
if (!ms)
|
|
83
|
-
return null;
|
|
84
|
-
const minutes = ms / 60_000;
|
|
85
|
-
return minutes % 60 === 0 ? `${minutes / 60} hour${minutes === 60 ? '' : 's'}` : `${minutes} minutes`;
|
|
86
|
-
}
|
|
1
|
+
// An R63 or R64 file of Enedis as the series of a meter: `readMeterFile()`
|
|
2
|
+
// and `meterSeriesOfR6x()` live in `@nexgen-os/connector`, MIT, so that a
|
|
3
|
+
// connector relaying the files reads them without the core (decision 0064);
|
|
4
|
+
// the core re-exports them, one definition for both.
|
|
5
|
+
export { meterSeriesOfR6x, readMeterFile } from '@nexgen-os/connector';
|
package/dist/files/index.d.ts
CHANGED
package/dist/files/index.js
CHANGED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The history of a WeSmart Database, imported table to table into the core.
|
|
3
|
+
*
|
|
4
|
+
* The WeSmart Database keeps, for each project, the participants with the
|
|
5
|
+
* meter they carry in a column (`participants.smart_meter_id`) and their
|
|
6
|
+
* address beside it (`participants.address`, `latitude`, `longitude`), and
|
|
7
|
+
* the devices behind each participant (`devices.participant_id`). The core
|
|
8
|
+
* has the same hierarchy with the meter as an object of its own
|
|
9
|
+
* (decision 0043):
|
|
10
|
+
*
|
|
11
|
+
* | WeSmart Database | Core |
|
|
12
|
+
* |---|---|
|
|
13
|
+
* | `organisations` | `organisations` (`create_organisation()`) |
|
|
14
|
+
* | `projects` | `projects` (`create_project()`), its country and status |
|
|
15
|
+
* | `participants` | `participants` (`join_project()`), with its place |
|
|
16
|
+
* | `participants.address`, `postal_code`, `city`, `latitude`, `longitude`, `country` | the participant's place, in the one standard shape |
|
|
17
|
+
* | `participants.smart_meter_id` | `meters` (`declare_meter()`), carried by the participant |
|
|
18
|
+
* | `devices.participant_id` | `devices.participant_id` (`install_device()`), unchanged |
|
|
19
|
+
*
|
|
20
|
+
* Two steps. `planWesmartImport()` is pure: it reads the rows and names, for
|
|
21
|
+
* each, the gesture that writes it, or why it cannot be written (a refusal
|
|
22
|
+
* by name, with its table and its id); a value it does not carry is counted
|
|
23
|
+
* by its column, never dropped without a word. `importWesmartHistory()`
|
|
24
|
+
* writes a plan through the schema's own gestures, acting as the person, and
|
|
25
|
+
* records on every object the row it came from (`identifiers`, scheme
|
|
26
|
+
* `imported_row`, `wesmart_db:<table>:<id>`): a second import finds the
|
|
27
|
+
* object and writes nothing again.
|
|
28
|
+
*
|
|
29
|
+
* Nothing is guessed. A meter's scheme is the one the grid operators of the
|
|
30
|
+
* participant's country issue and whose pattern its number matches
|
|
31
|
+
* (`meterSchemesOf()`); a placeholder number (`VIRTUAL-…`) names no
|
|
32
|
+
* connection point and declares no meter. The series of the WeSmart Database
|
|
33
|
+
* (its `flows`, profiles and imported readings) are the next step, not this
|
|
34
|
+
* one: they are counted as not carried.
|
|
35
|
+
*/
|
|
36
|
+
import type { Db } from '../db.js';
|
|
37
|
+
/** The database the rows come from, as the prefix of the identifier of every object imported. */
|
|
38
|
+
export declare const WESMART_DB = "wesmart_db";
|
|
39
|
+
/** The identifier scheme that records the row an object was imported from. */
|
|
40
|
+
export declare const IMPORTED_ROW_SCHEME = "imported_row";
|
|
41
|
+
/** A row as read from the database: its columns, any of them null. Numbers may come as text (`numeric`). */
|
|
42
|
+
type Row = Record<string, unknown> & {
|
|
43
|
+
id: string;
|
|
44
|
+
};
|
|
45
|
+
export interface WesmartOrganisation extends Row {
|
|
46
|
+
name?: string | null;
|
|
47
|
+
}
|
|
48
|
+
export interface WesmartProject extends Row {
|
|
49
|
+
name?: string | null;
|
|
50
|
+
organisation_id?: string | null;
|
|
51
|
+
owner_id?: string | null;
|
|
52
|
+
country?: string | null;
|
|
53
|
+
status?: string | null;
|
|
54
|
+
start_date?: string | null;
|
|
55
|
+
created_at?: string | null;
|
|
56
|
+
}
|
|
57
|
+
export interface WesmartParticipant extends Row {
|
|
58
|
+
project_id?: string | null;
|
|
59
|
+
name?: string | null;
|
|
60
|
+
status?: string | null;
|
|
61
|
+
address?: string | null;
|
|
62
|
+
postal_code?: string | null;
|
|
63
|
+
city?: string | null;
|
|
64
|
+
country?: string | null;
|
|
65
|
+
latitude?: number | string | null;
|
|
66
|
+
longitude?: number | string | null;
|
|
67
|
+
smart_meter_id?: string | null;
|
|
68
|
+
power?: number | string | null;
|
|
69
|
+
consumption?: number | string | null;
|
|
70
|
+
join_date?: string | null;
|
|
71
|
+
leave_date?: string | null;
|
|
72
|
+
archived_at?: string | null;
|
|
73
|
+
created_at?: string | null;
|
|
74
|
+
}
|
|
75
|
+
export interface WesmartDevice extends Row {
|
|
76
|
+
participant_id?: string | null;
|
|
77
|
+
name?: string | null;
|
|
78
|
+
device_type?: string | null;
|
|
79
|
+
manufacturer?: string | null;
|
|
80
|
+
model?: string | null;
|
|
81
|
+
power?: number | string | null;
|
|
82
|
+
installation_date?: string | null;
|
|
83
|
+
status?: string | null;
|
|
84
|
+
created_at?: string | null;
|
|
85
|
+
}
|
|
86
|
+
/** The tables read, as rows (`select * from <table>`). */
|
|
87
|
+
export interface WesmartSnapshot {
|
|
88
|
+
organisations?: WesmartOrganisation[];
|
|
89
|
+
projects: WesmartProject[];
|
|
90
|
+
participants: WesmartParticipant[];
|
|
91
|
+
devices?: WesmartDevice[];
|
|
92
|
+
}
|
|
93
|
+
export type WesmartTable = 'organisations' | 'projects' | 'participants' | 'devices';
|
|
94
|
+
/** A row that is not written, by the name of the reason. */
|
|
95
|
+
export interface ImportRefusal {
|
|
96
|
+
code: string;
|
|
97
|
+
table: WesmartTable;
|
|
98
|
+
id: string;
|
|
99
|
+
detail: string;
|
|
100
|
+
}
|
|
101
|
+
/** A column of a table whose values this import does not carry, with the rows that hold one. */
|
|
102
|
+
export interface NotCarried {
|
|
103
|
+
table: WesmartTable;
|
|
104
|
+
column: string;
|
|
105
|
+
rows: number;
|
|
106
|
+
}
|
|
107
|
+
export interface PlannedOrganisation {
|
|
108
|
+
key: string;
|
|
109
|
+
name: string;
|
|
110
|
+
}
|
|
111
|
+
export interface PlannedProject {
|
|
112
|
+
key: string;
|
|
113
|
+
/** The planned organisation it is in, or the id of an organisation of the core. */
|
|
114
|
+
organisation: {
|
|
115
|
+
key: string;
|
|
116
|
+
} | {
|
|
117
|
+
id: string;
|
|
118
|
+
};
|
|
119
|
+
name: string;
|
|
120
|
+
country: string;
|
|
121
|
+
status: string | null;
|
|
122
|
+
start_date: string | null;
|
|
123
|
+
}
|
|
124
|
+
export interface PlannedPlace {
|
|
125
|
+
country: string;
|
|
126
|
+
address_line1?: string;
|
|
127
|
+
postal_code?: string;
|
|
128
|
+
city?: string;
|
|
129
|
+
geometry?: {
|
|
130
|
+
type: 'Point';
|
|
131
|
+
coordinates: [number, number, number];
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
export interface PlannedParticipant {
|
|
135
|
+
key: string;
|
|
136
|
+
project_key: string;
|
|
137
|
+
name: string;
|
|
138
|
+
category: 'consumer' | 'producer' | 'prosumer';
|
|
139
|
+
status: string;
|
|
140
|
+
join_date: string | null;
|
|
141
|
+
leave_date: string | null;
|
|
142
|
+
place: PlannedPlace;
|
|
143
|
+
}
|
|
144
|
+
export interface PlannedMeter {
|
|
145
|
+
key: string;
|
|
146
|
+
participant_key: string;
|
|
147
|
+
identifier: string;
|
|
148
|
+
scheme: string;
|
|
149
|
+
}
|
|
150
|
+
export interface PlannedDevice {
|
|
151
|
+
key: string;
|
|
152
|
+
participant_key: string;
|
|
153
|
+
device_type: string;
|
|
154
|
+
name: string;
|
|
155
|
+
rated_power_kw: number | null;
|
|
156
|
+
installed_on: string | null;
|
|
157
|
+
status: string | null;
|
|
158
|
+
nameplate: {
|
|
159
|
+
manufacturer?: string;
|
|
160
|
+
model?: string;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
export interface WesmartImportPlan {
|
|
164
|
+
organisations: PlannedOrganisation[];
|
|
165
|
+
projects: PlannedProject[];
|
|
166
|
+
participants: PlannedParticipant[];
|
|
167
|
+
meters: PlannedMeter[];
|
|
168
|
+
devices: PlannedDevice[];
|
|
169
|
+
refusals: ImportRefusal[];
|
|
170
|
+
notCarried: NotCarried[];
|
|
171
|
+
}
|
|
172
|
+
/** A scheme a meter number may be in: the grid operators of a country issue it, its pattern says which numbers. */
|
|
173
|
+
export interface MeterScheme {
|
|
174
|
+
country: string;
|
|
175
|
+
scheme: string;
|
|
176
|
+
pattern: string | null;
|
|
177
|
+
}
|
|
178
|
+
export interface WesmartPlanOptions {
|
|
179
|
+
/** The schemes of the connection points, by country (`meterSchemesOf()`). */
|
|
180
|
+
meterSchemes: MeterScheme[];
|
|
181
|
+
/**
|
|
182
|
+
* The organisation of the core a project without an organisation goes
|
|
183
|
+
* into (a project its owner kept alone). Without it such a project is
|
|
184
|
+
* refused, `project_organisation_required`.
|
|
185
|
+
*/
|
|
186
|
+
organisationForOwnProjects?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* The device types of the WeSmart Database, by the core's `device_types`
|
|
190
|
+
* code. A type absent here is refused, `device_type_unmapped`.
|
|
191
|
+
*/
|
|
192
|
+
export declare const WESMART_DEVICE_TYPES: Readonly<Record<string, string>>;
|
|
193
|
+
/** The identifier an object imported from a row is recorded under. */
|
|
194
|
+
export declare function importedRowKey(table: WesmartTable, id: string): string;
|
|
195
|
+
/** The meter number as the WeSmart Database compares it: spaces removed (`normalizeMeterId`). */
|
|
196
|
+
export declare function normaliseMeterNumber(value: string): string;
|
|
197
|
+
/**
|
|
198
|
+
* What every row of a WeSmart Database becomes in the core, or why it does
|
|
199
|
+
* not. Pure: reads the rows and the options, touches nothing.
|
|
200
|
+
*
|
|
201
|
+
* A refused row refuses what hangs from it (`parent_refused`): the
|
|
202
|
+
* participants of a refused project, the meter and the devices of a refused
|
|
203
|
+
* participant. Two participants of one project carrying one meter
|
|
204
|
+
* number are one connection point: the first entered carries the meter, the
|
|
205
|
+
* others are refused theirs (`meter_shared`) and keep their own row.
|
|
206
|
+
*/
|
|
207
|
+
export declare function planWesmartImport(snapshot: WesmartSnapshot, options: WesmartPlanOptions): WesmartImportPlan;
|
|
208
|
+
export interface WesmartImportResult {
|
|
209
|
+
/** The id in the core of every object of the plan, by its key. */
|
|
210
|
+
ids: Record<string, string>;
|
|
211
|
+
/** What was written now, and what a previous import had written already, by kind. */
|
|
212
|
+
created: Record<'organisations' | 'projects' | 'participants' | 'meters' | 'devices', number>;
|
|
213
|
+
alreadyImported: Record<'organisations' | 'projects' | 'participants' | 'meters' | 'devices', number>;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The schemes of the connection points by country: those the grid operators
|
|
217
|
+
* of the `grid` module issue, with their pattern. Refuses
|
|
218
|
+
* `module_not_installed` when the module is not.
|
|
219
|
+
*/
|
|
220
|
+
export declare function meterSchemesOf(db: Db): Promise<MeterScheme[]>;
|
|
221
|
+
/**
|
|
222
|
+
* Writes a plan, as the person the connection acts as, each object through
|
|
223
|
+
* the gesture of its kind; finds first, by the row it came from, what a
|
|
224
|
+
* previous import wrote, and writes it no second time. Run it in one
|
|
225
|
+
* transaction (`Session.run()`): a refusal of the database stops it whole,
|
|
226
|
+
* with the name of the refusal and the row it was writing.
|
|
227
|
+
*/
|
|
228
|
+
export declare function importWesmartHistory(db: Db, plan: WesmartImportPlan): Promise<WesmartImportResult>;
|
|
229
|
+
export {};
|