@3e/sqa-common 6.0.6-1 → 6.0.6-12

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 (3) hide show
  1. package/index.d.ts +414 -109
  2. package/package.json +1 -1
  3. package/sqa_common.js +953 -921
package/index.d.ts CHANGED
@@ -672,21 +672,48 @@ declare module '@3e/sqa-common' {
672
672
  body: Section[]
673
673
  }
674
674
 
675
+ export type Parameters = {
676
+ class: string
677
+ id: string
678
+ }
679
+
680
+ export type ViewData = SQView & {
681
+ artifact: {
682
+ type: string
683
+ version: string
684
+ }
685
+ body: {
686
+ body: Parameters[]
687
+ class: string
688
+ id: string
689
+ }[]
690
+ version: string
691
+ }
692
+
693
+ export type ParameterOption = {
694
+ options: {value: string; label: string}[]
695
+ id: string
696
+ label: string
697
+ ldType: string
698
+ container?: string
699
+ value: string
700
+ }
701
+
675
702
  export interface ApiConfig extends RequestInit {
676
703
  token?: string
677
704
  body?: any
678
705
  }
679
706
 
680
707
  export type ApiFn = (
681
- endpoint: string,
682
- config?: ApiConfig,
708
+ endpoint: string,
709
+ config?: ApiConfig,
683
710
  ) => Promise<
684
- {status: ErrorStatus} | {body: Record<string, any>; status: OKStatus}
685
- >
711
+ {status: ErrorStatus} | {body: Record<string, any>; status: OKStatus}
712
+ >
686
713
 
687
714
  export type TokenThunk = () => Promise<
688
- {status: OKStatus; body: {token: string}} | {status: ErrorStatus}
689
- >
715
+ {status: OKStatus; body: {token: string}} | {status: ErrorStatus}
716
+ >
690
717
 
691
718
  export interface InitialisationConfig {
692
719
  apiFn: ApiFn
@@ -695,75 +722,75 @@ declare module '@3e/sqa-common' {
695
722
  export type PeriodTimeMode = 'absolute' | 'local'
696
723
 
697
724
  export type ViewType =
698
- | 'time-chart'
699
- | 'object-chart'
700
- | 'object-heatmap'
701
- | 'scatter-chart'
702
- | 'object-table'
703
- | 'time-table'
704
- | 'kpis'
725
+ | 'time-chart'
726
+ | 'object-chart'
727
+ | 'object-heatmap'
728
+ | 'scatter-chart'
729
+ | 'object-table'
730
+ | 'time-table'
731
+ | 'kpis'
705
732
 
706
733
  export type Granularity =
707
- | '1 minute'
708
- | '5 minutes'
709
- | '10 minutes'
710
- | '15 minutes'
711
- | '30 minutes'
712
- | '1 hour'
713
- | '1 day'
714
- | '1 week'
715
- | '1 month'
716
- | '3 months'
717
- | '1 year'
734
+ | '1 minute'
735
+ | '5 minutes'
736
+ | '10 minutes'
737
+ | '15 minutes'
738
+ | '30 minutes'
739
+ | '1 hour'
740
+ | '1 day'
741
+ | '1 week'
742
+ | '1 month'
743
+ | '3 months'
744
+ | '1 year'
718
745
 
719
746
  export type Period =
720
- | 'last-7-days'
721
- | 'last-week'
722
- | 'since-beginning'
723
- | 'last-12-months'
724
- | 'year-to-date'
725
- | 'today'
726
- | 'current-month'
727
- | 'last-month'
728
- | 'forecast-4-days'
729
- | 'tomorrow'
730
- | 'last-24-hours'
731
- | 'last-30-days'
732
- | 'last-7x24-hours'
733
- | 'last-3x24-hours'
734
- | 'last-15-minutes'
735
- | 'last-3-days'
736
- | 'last-year'
737
- | 'yesterday'
738
- | 'forecast-10-days'
739
- | 'custom'
747
+ | 'last-7-days'
748
+ | 'last-week'
749
+ | 'since-beginning'
750
+ | 'last-12-months'
751
+ | 'year-to-date'
752
+ | 'today'
753
+ | 'current-month'
754
+ | 'last-month'
755
+ | 'forecast-4-days'
756
+ | 'tomorrow'
757
+ | 'last-24-hours'
758
+ | 'last-30-days'
759
+ | 'last-7x24-hours'
760
+ | 'last-3x24-hours'
761
+ | 'last-15-minutes'
762
+ | 'last-3-days'
763
+ | 'last-year'
764
+ | 'yesterday'
765
+ | 'forecast-10-days'
766
+ | 'custom'
740
767
 
741
768
  export type LevelValue =
742
- | 'site-group'
743
- | 'site'
744
- | 'ac-node'
745
- | 'ac-input'
746
- | 'ac-phase'
747
- | 'connection'
748
- | 'dc-input'
749
- | 'dc-node'
750
- | 'inverter'
751
- | 'inverter-device'
752
- | 'logger'
753
- | 'mppt'
754
- | 'module-group'
755
- | 'power-unit'
756
- | 'sensor'
757
- | 'strings'
758
- | 'tracker'
769
+ | 'site-group'
770
+ | 'site'
771
+ | 'ac-node'
772
+ | 'ac-input'
773
+ | 'ac-phase'
774
+ | 'connection'
775
+ | 'dc-input'
776
+ | 'dc-node'
777
+ | 'inverter'
778
+ | 'inverter-device'
779
+ | 'logger'
780
+ | 'mppt'
781
+ | 'module-group'
782
+ | 'power-unit'
783
+ | 'sensor'
784
+ | 'strings'
785
+ | 'tracker'
759
786
 
760
787
  export type RepresentationValue =
761
- | 'line'
762
- | 'line-and-marker'
763
- | 'marker'
764
- | 'spline'
765
- | 'column'
766
- | 'area'
788
+ | 'line'
789
+ | 'line-and-marker'
790
+ | 'marker'
791
+ | 'spline'
792
+ | 'column'
793
+ | 'area'
767
794
 
768
795
  export type StackingOptionValue = 'no' | 'normal' | 'percent'
769
796
 
@@ -777,6 +804,7 @@ declare module '@3e/sqa-common' {
777
804
  export type Level = {
778
805
  value: LevelValue
779
806
  label: string
807
+ models?: {label: string; value: string}[]
780
808
  }
781
809
 
782
810
  /**
@@ -787,6 +815,8 @@ declare module '@3e/sqa-common' {
787
815
  label: string
788
816
  }
789
817
 
818
+ export type ContainerValue = string
819
+
790
820
  /**
791
821
  * Containers (Actually physical plants)
792
822
  */
@@ -825,6 +855,15 @@ declare module '@3e/sqa-common' {
825
855
 
826
856
  export type ColorSchemeValue = 'scheme_blrd' | 'scheme_ylrdbl'
827
857
 
858
+ export type ColorSettings =
859
+ | {
860
+ label: string
861
+ value: string
862
+ type: 'palette'
863
+ colors: string[]
864
+ }
865
+ | {label: string; value: string; type: 'fixed'; color: string}
866
+
828
867
  export type ColorScheme = {
829
868
  value: ColorSchemeValue
830
869
  label: string
@@ -882,13 +921,63 @@ declare module '@3e/sqa-common' {
882
921
  }
883
922
  }
884
923
 
924
+ export interface LdType {
925
+ sqid: string
926
+ ref: string
927
+ label: string
928
+ }
929
+
930
+ export interface LDRoot {
931
+ sqid: string
932
+ ref: string
933
+ label: string
934
+ }
935
+
936
+ export interface Model {
937
+ sqid: string
938
+ ref: string
939
+ label: string
940
+ }
941
+
942
+ export interface LogicalDevice {
943
+ sqid: string
944
+ ld_type: string
945
+ ref: string
946
+ root: LDRoot
947
+ label: string
948
+ full_name: string
949
+ act_to: Date
950
+ act_from: Date
951
+ model: Model
952
+ }
953
+
954
+ export interface Indicator {
955
+ default_graphical_representation: string
956
+ description: string
957
+ key: string
958
+ label: string
959
+ level: LevelValue
960
+ unit: string
961
+ unit_key: string
962
+ }
963
+
964
+ export interface LDIndicator {
965
+ indicator_key: string
966
+ object_ref: string
967
+ unit: string
968
+ unit_key: string
969
+ }
970
+
885
971
  /**
886
972
  * Options for representing the dataset
887
973
  */
888
974
  export interface DatasetOptions {
889
- graphicalRepresentation: string
890
- id: string
891
- colorSetting: string
975
+ graphicalRepresentation?: string
976
+ id?: string
977
+ colorSetting?: string
978
+ stacking?: StackingOptionValue
979
+ showNullsAs?: string
980
+ label?: string
892
981
  }
893
982
 
894
983
  export interface DatasetTemplateSpec {
@@ -897,7 +986,99 @@ declare module '@3e/sqa-common' {
897
986
  selectedTemplate: string
898
987
  }
899
988
 
900
- export type Dataset = any //TODO: Better types here
989
+ export interface Object {
990
+ name: string
991
+ level: LevelValue
992
+ ref: string
993
+ type: string
994
+ statistics?: {
995
+ median: number
996
+ mean: number
997
+ sum: number
998
+ min: number
999
+ max: number
1000
+ }
1001
+ }
1002
+
1003
+ export interface ObjectSet {
1004
+ template: string
1005
+ level: string
1006
+ objects: Object[]
1007
+ }
1008
+
1009
+ export interface UnitScale {
1010
+ min?: any
1011
+ max?: any
1012
+ }
1013
+
1014
+ export type Scaling = Record<string, UnitScale>
1015
+
1016
+ export interface Dataset {
1017
+ objects?: any
1018
+ colorSetting?: ColorSettings
1019
+ indicators: Indicator[]
1020
+ objectSet: ObjectSet
1021
+ stacking: StackingOptionValue
1022
+ showNullsAs?: any
1023
+ representation: string
1024
+ label?: any
1025
+ id: string
1026
+ scaling: Scaling
1027
+ stack?: any
1028
+ error?: any
1029
+ idx: number
1030
+ objectSetLabel: string
1031
+ }
1032
+
1033
+ // TODO: Better types for PacoViewParameters
1034
+ type PacoViewParameters = any
1035
+
1036
+ type SaveDataJobStatus =
1037
+ | {
1038
+ status: 'terminated'
1039
+ respResult: {downloadUrl: string}
1040
+ completedTime: ISODateString
1041
+ respStatus: number
1042
+ }
1043
+ | {status: 'running'}
1044
+
1045
+ type SaveDataJobResponse = SaveDataJobStatus & {
1046
+ actorSqid: string
1047
+ numRetries: number
1048
+ sqid: string
1049
+ maxRetries: number
1050
+
1051
+ /**
1052
+ * The arguments derived from the visualization given as argument
1053
+ * for the `createSaveDataJob` function
1054
+ */
1055
+ arguments: {
1056
+ object: string[]
1057
+ toDate: ISODateString
1058
+ filename: string
1059
+ replyTz: string
1060
+ fromDate: string
1061
+ indicator: string[]
1062
+ granularity: Granularity[] // must be a single value
1063
+ }
1064
+ /**
1065
+ * The place in the queue
1066
+ */
1067
+ priority: number
1068
+
1069
+ timeout: number
1070
+
1071
+ /**
1072
+ * currently can be just save_data
1073
+ */
1074
+ typeSqid: number
1075
+ }
1076
+
1077
+ type Parameter = {
1078
+ id: string
1079
+ class: 'Parameter'
1080
+ parameter: {class: string; label: string; initial: unknown; value: unknown}
1081
+ }
901
1082
 
902
1083
  /**
903
1084
  * Type definitions for all the API
@@ -917,8 +1098,8 @@ declare module '@3e/sqa-common' {
917
1098
  * @param getToken - function with no arguments that returns the JWT token
918
1099
  */
919
1100
  wrapRefresh(
920
- apiFn: ApiFn,
921
- getToken: TokenThunk,
1101
+ apiFn: ApiFn,
1102
+ getToken: TokenThunk,
922
1103
  ): {apiFn: ApiFn; resetFn: () => void}
923
1104
 
924
1105
  /**
@@ -932,6 +1113,12 @@ declare module '@3e/sqa-common' {
932
1113
  */
933
1114
  newEmptyView(viewOptions: EmptyViewOptions): SQView
934
1115
 
1116
+ /**
1117
+ * Returns the type for the given view
1118
+ * @param view SQView
1119
+ */
1120
+ getViewType(view: SQView): ViewType
1121
+
935
1122
  /**
936
1123
  * Get title of the view
937
1124
  * @param view - the SQView
@@ -977,19 +1164,28 @@ declare module '@3e/sqa-common' {
977
1164
  * @param options - creation options
978
1165
  */
979
1166
  getVisualization(
980
- view: SQView,
981
- options: VisualisationOptions,
1167
+ view: SQView,
1168
+ options: VisualisationOptions,
982
1169
  ): Promise<Visualization>
983
1170
 
984
1171
  /**
985
1172
  * Populates a visualization with data, using the default `append-data` to append each page.
986
1173
  * @param visualisation - the visualization to be populated
987
- * @param callback - A callback that will be called when the operation is complete
1174
+ * @param callback - Callback function called with the populated viz when the operation is done
1175
+ *
1176
+ * @returns a function to cancel the operation
988
1177
  */
989
1178
  populateVisualisation(
990
- visualisation: Visualization,
991
- callback: (data: any) => void,
992
- ): Promise<void>
1179
+ visualisation: Visualization,
1180
+ callback: (visualization: Visualization) => void,
1181
+ ): () => void
1182
+
1183
+ /**
1184
+ * @param visualisation - the visualization to be populated
1185
+ *
1186
+ * @returns A promise with the populated visualization
1187
+ */
1188
+ populateVisualisation(visualisation: Visualization): Promise<Visualization>
993
1189
 
994
1190
  /**
995
1191
  * Returns the granularity for the view
@@ -999,9 +1195,10 @@ declare module '@3e/sqa-common' {
999
1195
 
1000
1196
  /**
1001
1197
  * Returns the granularity for the view
1002
- * @param view
1198
+ * @param view - the view to modify
1199
+ * @param granularity - the new granularity
1003
1200
  */
1004
- setGranularityParameter(view: SQView): Granularity
1201
+ setGranularityParameter(view: SQView, granularity: Granularity): SQView
1005
1202
 
1006
1203
  /**
1007
1204
  * Returns the object parameters for a view
@@ -1010,10 +1207,10 @@ declare module '@3e/sqa-common' {
1010
1207
  getObjectParameters(view: SQView): {
1011
1208
  id: string
1012
1209
  label: string
1013
- ldType: LDType
1014
- container: Container
1210
+ ldType: string
1211
+ container: string
1015
1212
  value: string
1016
- }
1213
+ }[]
1017
1214
 
1018
1215
  /**
1019
1216
  * Sets the object parameter with the given id
@@ -1021,19 +1218,21 @@ declare module '@3e/sqa-common' {
1021
1218
  * @param id - The ID of the parameter //TODO: Get list of possible parameters
1022
1219
  * @param value - Value of the parameter
1023
1220
  */
1024
- setObjectParameters(view: SQView, id: string, value: string): SQView
1221
+ setObjectParameter(view: SQView, id: string, value: string): SQView
1025
1222
 
1026
1223
  DataTimezoneModes: [
1027
1224
  {value: 'user'; label: 'Display data in my own timezone'},
1028
1225
  {value: 'plant'; label: 'Display data in the timezone of the plant'},
1029
1226
  ]
1030
1227
 
1031
- ShowNullAsOptions: [
1228
+ ShowNullsAsOptions: [
1032
1229
  {value: 'no'; label: 'No'},
1033
1230
  {value: 'normal'; label: 'Normal'},
1034
1231
  {value: 'percent'; label: 'Percent'},
1035
1232
  ]
1036
1233
 
1234
+ ViewTypes: {label: string; value: ViewType}[]
1235
+
1037
1236
  /**
1038
1237
  * A collection of all timezones in the format {label, value}
1039
1238
  */
@@ -1056,12 +1255,33 @@ declare module '@3e/sqa-common' {
1056
1255
  */
1057
1256
  getColorSchemes(): ColorScheme[]
1058
1257
 
1258
+ /**
1259
+ * Returns the possible color settings for a certain view type
1260
+ * @param viewType
1261
+ */
1262
+ getColorSettings(viewType: ViewType): ColorSettings[]
1263
+
1264
+ getColorSettingsCssStyle(colorSetting: ColorSettings):
1265
+ | {
1266
+ backgroundColor: string
1267
+ }
1268
+ | {
1269
+ backgroundImage: string
1270
+ }
1271
+
1272
+ /**
1273
+ * Sets the colorscheme of a view
1274
+ * @param view the view to be modified
1275
+ * @param colorScheme - the new colorscheme
1276
+ */
1277
+ setViewColorScheme(view: SQView, colorScheme: string): SQView
1278
+
1059
1279
  /**
1060
1280
  * Array with available levels
1061
1281
  *
1062
1282
  * !! Only usable after `init` has been called
1063
1283
  */
1064
- getLevels: Level[]
1284
+ getLevels(): Level[]
1065
1285
 
1066
1286
  StackingOptions: StackingOption[]
1067
1287
 
@@ -1072,7 +1292,7 @@ declare module '@3e/sqa-common' {
1072
1292
  * Gets the container logical devices types to populate
1073
1293
  * @param level - level means container
1074
1294
  */
1075
- getContainerLdTypes(level: LevelValue): LDType[]
1295
+ getContainersLdTypes(level: LevelValue): Promise<LDType[]>
1076
1296
 
1077
1297
  /**
1078
1298
  * Based on the selected level and the Selected Logical Device type, returns
@@ -1081,16 +1301,22 @@ declare module '@3e/sqa-common' {
1081
1301
  * @param selectedContainerLdType
1082
1302
  */
1083
1303
  getContainers(
1084
- selectedLevel: LevelValue,
1085
- selectedContainerLdType: LDType,
1086
- ): Container[]
1304
+ selectedLevel: LevelValue,
1305
+ selectedContainerLdType?: string,
1306
+ ): Promise<Container[]>
1087
1307
 
1088
1308
  /**
1089
1309
  * Get all available templates for the current selection
1090
- * @param selectedLevel
1091
- * @param selectedContainer
1310
+ * @param view
1311
+ * @param specification
1092
1312
  */
1093
- getTemplates(selectedLevel: Level, selectedContainer: Container): Template[]
1313
+ getTemplates(
1314
+ view: SQView,
1315
+ specification: {
1316
+ selectedLevel: LevelValue
1317
+ selectedContainer: ContainerValue
1318
+ },
1319
+ ): Promise<Template[]>
1094
1320
 
1095
1321
  /**
1096
1322
  * Sets the unit scaling for a view.
@@ -1100,9 +1326,9 @@ declare module '@3e/sqa-common' {
1100
1326
  * @param unitScaling
1101
1327
  */
1102
1328
  setUnitScaling(
1103
- view: SQView,
1104
- unitKey: string,
1105
- unitScaling: {min?: number; max?: number},
1329
+ view: SQView,
1330
+ unitKey: string,
1331
+ unitScaling: {min?: number; max?: number},
1106
1332
  ): SQView
1107
1333
 
1108
1334
  /**
@@ -1111,8 +1337,8 @@ declare module '@3e/sqa-common' {
1111
1337
  * @param unitKey - the
1112
1338
  */
1113
1339
  getUnitScaling(
1114
- view: SQView,
1115
- unitKey: string,
1340
+ view: SQView,
1341
+ unitKey: string,
1116
1342
  ): {
1117
1343
  min: number
1118
1344
  max: number
@@ -1175,7 +1401,7 @@ declare module '@3e/sqa-common' {
1175
1401
  periodTimeMode: PeriodTimeMode
1176
1402
  }
1177
1403
 
1178
- getDatasets(view: SQView): Dataset[]
1404
+ getDatasets(view: SQView): Promise<Dataset[]>
1179
1405
 
1180
1406
  /**
1181
1407
  * Adds a dataset to the view using a fixed set of objects.
@@ -1186,18 +1412,98 @@ declare module '@3e/sqa-common' {
1186
1412
  * @param options
1187
1413
  */
1188
1414
  addEnumDataset(
1189
- view: SQView,
1190
- objects: LDType,
1191
- indicators: [string],
1192
- options: DatasetOptions,
1415
+ view: SQView,
1416
+ objects: string[],
1417
+ indicators: [string],
1418
+ options: DatasetOptions,
1193
1419
  ): SQView
1194
1420
 
1195
1421
  addTemplateDataset(
1196
- view: SQView,
1197
- spec: DatasetTemplateSpec,
1198
- indicators: [string],
1199
- opts: DatasetOptions,
1422
+ view: SQView,
1423
+ spec: DatasetTemplateSpec,
1424
+ indicators: [string],
1425
+ opts: DatasetOptions,
1200
1426
  ): SQView
1427
+
1428
+ /**
1429
+ * Remove a dataset from the view
1430
+ * @param view the view to be modified
1431
+ * @param id the id of the dataset
1432
+ */
1433
+ removeDataset(view: SQView, id: string): SQView
1434
+
1435
+ /**
1436
+ * Set particular options on a dataset for a view
1437
+ * @param view - the view to be updated
1438
+ * @param id - the id of the dataset in the view body
1439
+ * @param options - the new options
1440
+ *
1441
+ * @returns The updated view
1442
+ */
1443
+ setDatasetOptions(view: SQView, id: string, options: DatasetOptions): SQView
1444
+
1445
+ /**
1446
+ * Returns the type of picker needed for the granularity
1447
+ * @param granularity
1448
+ */
1449
+ getClockOrCalendarMode(granularity: Granularity): 'clock' | 'calendar'
1450
+
1451
+ /**
1452
+ * Returns the type of picker needed for the granularity
1453
+ * @param granularity
1454
+ */
1455
+ getTimeMode(granularity: Granularity): 'clock' | 'calendar'
1456
+
1457
+ /**
1458
+ * Adds the statistics alongside the objects in the dataset
1459
+ * @param datasets - datasets to be updated
1460
+ * @param visualization - Visualization to be added to datasets
1461
+ */
1462
+ withStatistics(datasets: Dataset[], visualization: Visualization): Dataset[]
1463
+
1464
+ levelToLdTypeAndModel(level: LevelValue): {ldType: string; model: string}
1465
+
1466
+ viewVariablesRefCategories(viewParameters: PacoViewParameters): any
1467
+
1468
+ /**
1469
+ * Update a visualization
1470
+ * @param visualization
1471
+ */
1472
+ updateVisualization(visualization: Visualization): Visualization
1473
+
1474
+ /**
1475
+ * Create a SAVE_DATA job request for a visualization. After a job is
1476
+ * successfully created, a *JobUrl* is returned to be polled for a status
1477
+ * on the job
1478
+ *
1479
+ * @param visualization - The visualization to be saved in a .csv format
1480
+ * @param filename - the name of the csv.zip file to be downloaded
1481
+ *
1482
+ * @throws An error in case the provided parameters were incorrect. Wrap the
1483
+ * request inside a `try-catch` block
1484
+ */
1485
+ createSaveDataJob(
1486
+ visualization: Visualization,
1487
+ filename: string,
1488
+ ): Promise<string>
1489
+
1490
+ /**
1491
+ * Used for polling the SQA API for the job status.
1492
+ *
1493
+ * Use the jobUrl returned from `createSaveDataJob` and poll until `status` is `terminated`
1494
+ * @param jobUrl
1495
+ *
1496
+ * @throws An error in case something goes wrong with the request or the job does not
1497
+ * exist. Wrap the call inside a `try-catch` block
1498
+ */
1499
+ checkJobStatus(jobUrl: string): Promise<SaveDataJobResponse>
1500
+
1501
+ /**
1502
+ * Returns the parameters of a view
1503
+ * @param view
1504
+ */
1505
+ getViewParameters(view: SQView): Parameter[]
1506
+
1201
1507
  }
1202
1508
 
1203
1509
  export const sqa: {
@@ -1206,4 +1512,3 @@ declare module '@3e/sqa-common' {
1206
1512
 
1207
1513
  export default sqa
1208
1514
  }
1209
-