@trackunit/iris-app-runtime-core 0.3.146 → 0.3.147

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/index.cjs.js CHANGED
@@ -253,44 +253,37 @@ const getDateValue = (value) => {
253
253
  const year = date.toLocaleString("en-US", { year: "numeric" });
254
254
  return `${year}-${month}-${day}`;
255
255
  };
256
- const CustomFieldRuntime = {
257
- getCustomFieldsFor: (entity) => __awaiter(void 0, void 0, void 0, function* () {
258
- const api = yield getHostConnector();
259
- return api.getCustomFieldsFor(entity);
260
- }),
261
- setCustomFieldsFor: (entity, values) => __awaiter(void 0, void 0, void 0, function* () {
262
- const api = yield getHostConnector();
263
- return api.setCustomFieldsFor(entity, values);
264
- }),
265
- setCustomFieldsFromFormData: (entity, formData, originalDefinitions) => __awaiter(void 0, void 0, void 0, function* () {
266
- const api = yield getHostConnector();
267
- const values = [];
268
- Object.keys(formData).forEach(key => {
269
- var _a;
270
- const found = (_a = originalDefinitions.find(originalDefinition => originalDefinition.definition.key === key)) === null || _a === void 0 ? void 0 : _a.definition;
271
- const formDataValue = formData[key];
272
- if (found && formDataValue) {
273
- values.push({
274
- definitionKey: key,
275
- value: getCustomFieldValueToSaveFromRawValue(found, formDataValue),
276
- });
277
- }
278
- else {
279
- throw new Error("Unsupported custom field type: " + key);
280
- }
281
- });
282
- return api.setCustomFieldsFor(entity, values);
283
- }),
284
- getCustomFieldValueForDisplayInUI: (value, _unit, _systemOfMeasurement, language) => {
285
- if (value === undefined || value === null || value === "") {
286
- return "";
287
- }
288
- const numberValue = Number(value);
289
- const numberAsString = numberValue > 9999
290
- ? Math.round(numberValue)
291
- : new Intl.NumberFormat(language, { maximumSignificantDigits: 4, minimumSignificantDigits: 4 }).format(numberValue);
292
- return numberAsString;
293
- },
256
+ /**
257
+ * Format a custom field value to ensure a consistent representation in the ui.
258
+ */
259
+ const getCustomFieldValueForDisplayInUI = (value, _unit, _systemOfMeasurement, language) => {
260
+ if (value === undefined || value === null || value === "") {
261
+ return "";
262
+ }
263
+ const numberValue = Number(value);
264
+ const numberAsString = numberValue > 9999
265
+ ? Math.round(numberValue)
266
+ : new Intl.NumberFormat(language, { maximumSignificantDigits: 4, minimumSignificantDigits: 4 }).format(numberValue);
267
+ return numberAsString;
268
+ };
269
+ /**
270
+ * type guard to ensure that a value is of a type compatible with custom fields
271
+ */
272
+ const isValidCustomFieldValue = (value) => {
273
+ const isBoolean = typeof value === "boolean";
274
+ const isString = typeof value === "string";
275
+ const isStringArray = Array.isArray(value) && value.every(item => typeof item === "string");
276
+ const isDropdownSelectionArray = Array.isArray(value) && value.every(item => isDropdownSelection(item));
277
+ const isDropdownSelection = (dropdownValue) => typeof dropdownValue === "object" && dropdownValue !== null && "value" in dropdownValue;
278
+ const isNumber = typeof value === "number";
279
+ const isNull = value === null;
280
+ return (isBoolean ||
281
+ isString ||
282
+ isStringArray ||
283
+ isDropdownSelectionArray ||
284
+ isDropdownSelection(value) ||
285
+ isNumber ||
286
+ isNull);
294
287
  };
295
288
 
296
289
  const EnvironmentRuntime = {
@@ -429,7 +422,6 @@ exports.AssetSortingRuntime = AssetSortingRuntime;
429
422
  exports.ConfirmationDialogRuntime = ConfirmationDialogRuntime;
430
423
  exports.CurrentUserPreferenceRuntime = CurrentUserPreferenceRuntime;
431
424
  exports.CurrentUserRuntime = CurrentUserRuntime;
432
- exports.CustomFieldRuntime = CustomFieldRuntime;
433
425
  exports.EnvironmentRuntime = EnvironmentRuntime;
434
426
  exports.EventRuntime = EventRuntime;
435
427
  exports.FilterBarRuntime = FilterBarRuntime;
@@ -442,10 +434,12 @@ exports.SiteRuntime = SiteRuntime;
442
434
  exports.ToastRuntime = ToastRuntime;
443
435
  exports.TokenRuntime = TokenRuntime;
444
436
  exports.UserSubscriptionRuntime = UserSubscriptionRuntime;
437
+ exports.getCustomFieldValueForDisplayInUI = getCustomFieldValueForDisplayInUI;
445
438
  exports.getCustomFieldValueToSaveFromRawValue = getCustomFieldValueToSaveFromRawValue;
446
439
  exports.getDateValue = getDateValue;
447
440
  exports.getHostConnector = getHostConnector;
448
441
  exports.getStringValue = getStringValue;
442
+ exports.isValidCustomFieldValue = isValidCustomFieldValue;
449
443
  exports.setupHostConnector = setupHostConnector;
450
444
  Object.keys(irisAppRuntimeCoreApi).forEach(function (k) {
451
445
  if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
package/index.esm.js CHANGED
@@ -249,44 +249,37 @@ const getDateValue = (value) => {
249
249
  const year = date.toLocaleString("en-US", { year: "numeric" });
250
250
  return `${year}-${month}-${day}`;
251
251
  };
252
- const CustomFieldRuntime = {
253
- getCustomFieldsFor: (entity) => __awaiter(void 0, void 0, void 0, function* () {
254
- const api = yield getHostConnector();
255
- return api.getCustomFieldsFor(entity);
256
- }),
257
- setCustomFieldsFor: (entity, values) => __awaiter(void 0, void 0, void 0, function* () {
258
- const api = yield getHostConnector();
259
- return api.setCustomFieldsFor(entity, values);
260
- }),
261
- setCustomFieldsFromFormData: (entity, formData, originalDefinitions) => __awaiter(void 0, void 0, void 0, function* () {
262
- const api = yield getHostConnector();
263
- const values = [];
264
- Object.keys(formData).forEach(key => {
265
- var _a;
266
- const found = (_a = originalDefinitions.find(originalDefinition => originalDefinition.definition.key === key)) === null || _a === void 0 ? void 0 : _a.definition;
267
- const formDataValue = formData[key];
268
- if (found && formDataValue) {
269
- values.push({
270
- definitionKey: key,
271
- value: getCustomFieldValueToSaveFromRawValue(found, formDataValue),
272
- });
273
- }
274
- else {
275
- throw new Error("Unsupported custom field type: " + key);
276
- }
277
- });
278
- return api.setCustomFieldsFor(entity, values);
279
- }),
280
- getCustomFieldValueForDisplayInUI: (value, _unit, _systemOfMeasurement, language) => {
281
- if (value === undefined || value === null || value === "") {
282
- return "";
283
- }
284
- const numberValue = Number(value);
285
- const numberAsString = numberValue > 9999
286
- ? Math.round(numberValue)
287
- : new Intl.NumberFormat(language, { maximumSignificantDigits: 4, minimumSignificantDigits: 4 }).format(numberValue);
288
- return numberAsString;
289
- },
252
+ /**
253
+ * Format a custom field value to ensure a consistent representation in the ui.
254
+ */
255
+ const getCustomFieldValueForDisplayInUI = (value, _unit, _systemOfMeasurement, language) => {
256
+ if (value === undefined || value === null || value === "") {
257
+ return "";
258
+ }
259
+ const numberValue = Number(value);
260
+ const numberAsString = numberValue > 9999
261
+ ? Math.round(numberValue)
262
+ : new Intl.NumberFormat(language, { maximumSignificantDigits: 4, minimumSignificantDigits: 4 }).format(numberValue);
263
+ return numberAsString;
264
+ };
265
+ /**
266
+ * type guard to ensure that a value is of a type compatible with custom fields
267
+ */
268
+ const isValidCustomFieldValue = (value) => {
269
+ const isBoolean = typeof value === "boolean";
270
+ const isString = typeof value === "string";
271
+ const isStringArray = Array.isArray(value) && value.every(item => typeof item === "string");
272
+ const isDropdownSelectionArray = Array.isArray(value) && value.every(item => isDropdownSelection(item));
273
+ const isDropdownSelection = (dropdownValue) => typeof dropdownValue === "object" && dropdownValue !== null && "value" in dropdownValue;
274
+ const isNumber = typeof value === "number";
275
+ const isNull = value === null;
276
+ return (isBoolean ||
277
+ isString ||
278
+ isStringArray ||
279
+ isDropdownSelectionArray ||
280
+ isDropdownSelection(value) ||
281
+ isNumber ||
282
+ isNull);
290
283
  };
291
284
 
292
285
  const EnvironmentRuntime = {
@@ -419,4 +412,4 @@ const UserSubscriptionRuntime = {
419
412
  }),
420
413
  };
421
414
 
422
- export { AnalyticsContextRuntime, AssetRuntime, AssetSortingRuntime, ConfirmationDialogRuntime, CurrentUserPreferenceRuntime, CurrentUserRuntime, CustomFieldRuntime, EnvironmentRuntime, EventRuntime, FilterBarRuntime, NavigationRuntime, OemBrandingContextRuntime, ParamsRuntime, RestRuntime, RouterRuntime, SiteRuntime, ToastRuntime, TokenRuntime, UserSubscriptionRuntime, getCustomFieldValueToSaveFromRawValue, getDateValue, getHostConnector, getStringValue, setupHostConnector };
415
+ export { AnalyticsContextRuntime, AssetRuntime, AssetSortingRuntime, ConfirmationDialogRuntime, CurrentUserPreferenceRuntime, CurrentUserRuntime, EnvironmentRuntime, EventRuntime, FilterBarRuntime, NavigationRuntime, OemBrandingContextRuntime, ParamsRuntime, RestRuntime, RouterRuntime, SiteRuntime, ToastRuntime, TokenRuntime, UserSubscriptionRuntime, getCustomFieldValueForDisplayInUI, getCustomFieldValueToSaveFromRawValue, getDateValue, getHostConnector, getStringValue, isValidCustomFieldValue, setupHostConnector };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/iris-app-runtime-core",
3
- "version": "0.3.146",
3
+ "version": "0.3.147",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -1,4 +1,4 @@
1
- import { CustomFieldError, CustomFieldType, CustomFieldValue, EntityIdentity, UnitSiType, UnitUsType, ValueAndDefinition, ValueAndDefinitionKey } from "@trackunit/iris-app-runtime-core-api";
1
+ import { CustomFieldType, CustomFieldValue, UnitSiType, UnitUsType } from "@trackunit/iris-app-runtime-core-api";
2
2
  import { SystemOfMeasurementType } from "@trackunit/react-core-contexts-api";
3
3
  export interface DropdownSelection {
4
4
  value: string;
@@ -23,10 +23,11 @@ export declare const getStringValue: (value: boolean | string | string[] | Dropd
23
23
  * yyyy-mm-dd
24
24
  */
25
25
  export declare const getDateValue: (value: string) => string;
26
- export interface ICustomFieldRuntime {
27
- getCustomFieldsFor: (entity: EntityIdentity) => Promise<ValueAndDefinition[]>;
28
- setCustomFieldsFor: (entity: EntityIdentity, values: ValueAndDefinitionKey[]) => Promise<void | CustomFieldError>;
29
- setCustomFieldsFromFormData: (entity: EntityIdentity, formData: Record<string, boolean | string | string[] | number>, originalDefinitions: ValueAndDefinition[]) => Promise<void | CustomFieldError>;
30
- getCustomFieldValueForDisplayInUI: (value: number | string | null | undefined, unit: UnitUsType | UnitSiType | null | undefined, systemOfMeasurement?: SystemOfMeasurementType | null, language?: string) => number | string | null | undefined;
31
- }
32
- export declare const CustomFieldRuntime: ICustomFieldRuntime;
26
+ /**
27
+ * Format a custom field value to ensure a consistent representation in the ui.
28
+ */
29
+ export declare const getCustomFieldValueForDisplayInUI: (value: number | string | null | undefined, _unit: UnitUsType | UnitSiType | null | undefined, _systemOfMeasurement?: SystemOfMeasurementType | null, language?: string) => number | string | null | undefined;
30
+ /**
31
+ * type guard to ensure that a value is of a type compatible with custom fields
32
+ */
33
+ export declare const isValidCustomFieldValue: (value: unknown) => value is string | number | boolean | DropdownSelection | string[] | DropdownSelection[] | null;