@singularsystems/neo-core 1.0.0-beta.5 → 1.0.0-beta.7

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.
@@ -18,7 +18,7 @@ import { IRouteSecurityService } from '../Routing/IRouteSecurityService';
18
18
  import { IContextMenuState } from '../Components/ContextMenu/ContextMenu';
19
19
  import { INavigationHelper } from '../Routing/INavigationHelper';
20
20
  import { ILoginErrorHandler } from '../Security/ILoginErrorHandler';
21
- import Decimal from 'decimal.js-light';
21
+ import { IDecimalService } from "../Numeric";
22
22
  declare const NeoTypes: {
23
23
  Axios: ServiceIdentifier<import("axios").AxiosStatic>;
24
24
  Config: {
@@ -28,14 +28,12 @@ declare const NeoTypes: {
28
28
  Core: {
29
29
  AutoRunnerFactory: ServiceIdentifier<IAutoRunnerFactory>;
30
30
  ConnectionManager: ServiceIdentifier<IConnectionManager>;
31
+ DecimalService: ServiceIdentifier<IDecimalService<import("../Numeric").IDecimal>>;
31
32
  ModelCreator: ServiceIdentifier<IModelCreatorBase>;
32
33
  };
33
34
  Localisation: {
34
35
  LocalisationService: ServiceIdentifier<ILocalisationService>;
35
36
  };
36
- Misc: {
37
- DecimalType: ServiceIdentifier<typeof Decimal>;
38
- };
39
37
  Routing: {
40
38
  MenuItemProvider: ServiceIdentifier<IMenuItemProvider<import("../Routing").IMenuRoute>>;
41
39
  NavigationHelper: ServiceIdentifier<INavigationHelper>;
@@ -9,14 +9,12 @@ var NeoTypes = {
9
9
  Core: {
10
10
  AutoRunnerFactory: new ServiceIdentifier("Neo.AutoRunnerFactory"),
11
11
  ConnectionManager: new ServiceIdentifier("Neo.ConnectionManager"),
12
+ DecimalService: new ServiceIdentifier("Neo.DecimalService"),
12
13
  ModelCreator: new ServiceIdentifier("Neo.ModelCreator")
13
14
  },
14
15
  Localisation: {
15
16
  LocalisationService: new ServiceIdentifier("Neo.Localisation")
16
17
  },
17
- Misc: {
18
- DecimalType: new ServiceIdentifier("Neo.Decimal")
19
- },
20
18
  Routing: {
21
19
  MenuItemProvider: new ServiceIdentifier("Neo.MenuItemProvider"),
22
20
  NavigationHelper: new ServiceIdentifier("Neo.NavigationHelper"),
@@ -115,7 +115,7 @@ export var DataViewBase = /** @class */ (function () {
115
115
  }
116
116
  DataViewBase.unTrackedSort(function () {
117
117
  for (var i = sortFns_1.length - 1; i >= 0; i--) {
118
- itemsToSort_1.sortBy(sortFns_1[i].valueFn, sortFns_1[i].direction, sortFns_1[i].property.propertyType);
118
+ itemsToSort_1 = itemsToSort_1.sortBy(sortFns_1[i].valueFn, sortFns_1[i].direction, sortFns_1[i].property.propertyType);
119
119
  }
120
120
  });
121
121
  return __spreadArray(__spreadArray([], itemsToSort_1, true), endItems, true);
@@ -1,6 +1,6 @@
1
1
  import { TrackingState, SerialiseType, DataType, RelationType } from '../Model/Misc';
2
2
  import { Utils } from '../Utils';
3
- import Decimal from 'decimal.js-light';
3
+ import NumberUtils from "../NumberUtils";
4
4
  var Deserialiser = /** @class */ (function () {
5
5
  function Deserialiser() {
6
6
  this.objectRefs = {};
@@ -169,7 +169,7 @@ var Deserialiser = /** @class */ (function () {
169
169
  to[key] = new Date(fromValue);
170
170
  }
171
171
  else if (fromValue !== null && propertyInfo.propertyType === DataType.Decimal) {
172
- to[key] = new Decimal(fromValue);
172
+ to[key] = NumberUtils.decimalService.createDecimal(fromValue);
173
173
  }
174
174
  else {
175
175
  if (fromValue instanceof Array && !propertyInfo.assignOnDeserialise) {
@@ -2,7 +2,7 @@ import { TrackingState, SerialiseType, RelationType, TimeZoneFormat, DataType }
2
2
  import { Deserialiser } from './Deserialiser';
3
3
  import ValueObject from '../Model/ValueObject';
4
4
  import DateUtils from '../Dates/DateUtils';
5
- import Globals from '../Globals';
5
+ import NumberUtils from "../NumberUtils";
6
6
  var referenceIdKey = Symbol("referenceId");
7
7
  var JSFormatter = /** @class */ (function () {
8
8
  function JSFormatter() {
@@ -116,7 +116,7 @@ var Serialiser = /** @class */ (function () {
116
116
  propertyInfo.serialise !== SerialiseType.MappingOnly &&
117
117
  (propertyInfo.serialise !== SerialiseType.FullOnly || this.options.includeClean)) {
118
118
  var fromValue = from[key];
119
- var isChildObject = (fromValue && fromValue instanceof Object && !(fromValue instanceof Date) && !(fromValue instanceof Globals.decimalType)) || propertyInfo.relationType === RelationType.ChildObject;
119
+ var isChildObject = (fromValue && fromValue instanceof Object && !(fromValue instanceof Date) && !(NumberUtils.decimalService.isDecimal(fromValue))) || propertyInfo.relationType === RelationType.ChildObject;
120
120
  if (fromValue instanceof Array) {
121
121
  // Arrays of simple types are always included.
122
122
  if (!this.options.suppressChildren || (fromValue.length > 0 && !(fromValue[0] instanceof Object))) {
@@ -144,7 +144,7 @@ var Serialiser = /** @class */ (function () {
144
144
  // Simple values and dates
145
145
  if (fromValue !== null || propertyInfo.serialise !== SerialiseType.NotNull) {
146
146
  if (fromValue !== null && propertyInfo.propertyType === DataType.Decimal) {
147
- to[key] = fromValue.toNumber();
147
+ to[key] = NumberUtils.decimalService.toNumber(fromValue);
148
148
  }
149
149
  else if (propertyInfo.timeZoneSerialisation === TimeZoneFormat.None && fromValue instanceof Date) {
150
150
  to[key] = DateUtils.format(fromValue, "yyyy-MM-dd") + "T00:00:00";
@@ -0,0 +1,23 @@
1
+ import { IDecimal, IDecimalService } from "./IDecimal";
2
+ interface IMikeMCLDecimal extends IDecimal {
3
+ toNumber(): number;
4
+ round(precision: number, roundingType: number): IMikeMCLDecimal;
5
+ cmp(to: IMikeMCLDecimal): 0 | 1 | -1;
6
+ plus(number: IMikeMCLDecimal): IMikeMCLDecimal;
7
+ div(number: IMikeMCLDecimal | number): IMikeMCLDecimal;
8
+ }
9
+ export declare class DecimalService<T extends IMikeMCLDecimal> implements IDecimalService<T> {
10
+ private decimalType;
11
+ private roundHalfUpValue;
12
+ private roundDownValue;
13
+ constructor(decimalType: T, roundHalfUpValue: number, roundDownValue: number);
14
+ isDecimal(value: any): value is IMikeMCLDecimal;
15
+ createDecimal(value: number | string): T;
16
+ toNumber(value: number | T): number;
17
+ round(value: T, precision: number): T;
18
+ truncate(value: T): T;
19
+ compare(value1: T, value2: T): 0 | 1 | -1;
20
+ sum(values: T[]): T;
21
+ divideBy(value: T, divisor: number | T): T;
22
+ }
23
+ export {};
@@ -0,0 +1,38 @@
1
+ var DecimalService = /** @class */ (function () {
2
+ function DecimalService(decimalType, roundHalfUpValue, roundDownValue) {
3
+ this.decimalType = decimalType;
4
+ this.roundHalfUpValue = roundHalfUpValue;
5
+ this.roundDownValue = roundDownValue;
6
+ }
7
+ DecimalService.prototype.isDecimal = function (value) {
8
+ return value instanceof this.decimalType;
9
+ };
10
+ DecimalService.prototype.createDecimal = function (value) {
11
+ return new this.decimalType(value);
12
+ };
13
+ DecimalService.prototype.toNumber = function (value) {
14
+ if (this.isDecimal(value)) {
15
+ return value.toNumber();
16
+ }
17
+ else {
18
+ return value;
19
+ }
20
+ };
21
+ DecimalService.prototype.round = function (value, precision) {
22
+ return value.round(precision, this.roundHalfUpValue);
23
+ };
24
+ DecimalService.prototype.truncate = function (value) {
25
+ return value.round(0, this.roundDownValue);
26
+ };
27
+ DecimalService.prototype.compare = function (value1, value2) {
28
+ return value1.cmp(value2);
29
+ };
30
+ DecimalService.prototype.sum = function (values) {
31
+ return values.reduce(function (total, item) { return total.plus(item); }, this.createDecimal(0));
32
+ };
33
+ DecimalService.prototype.divideBy = function (value, divisor) {
34
+ return value.div(divisor);
35
+ };
36
+ return DecimalService;
37
+ }());
38
+ export { DecimalService };
@@ -0,0 +1,25 @@
1
+ export interface IDecimal {
2
+ new (value: number | string): IDecimal;
3
+ }
4
+ export interface IDecimalService<T extends IDecimal = IDecimal> {
5
+ /** Returns true if the provided value is a decimal instance. */
6
+ isDecimal(value: any): value is IDecimal;
7
+ /** Creates a decimal instance from a javascript number. */
8
+ createDecimal(value: number | string): T;
9
+ /** If the provided value is a decimal, converts it to a number, otherwise returns the number passed in. */
10
+ toNumber(value: number | T): number;
11
+ /** Rounds a number. */
12
+ round(value: T, precision: number): T;
13
+ /** Removes decimal places from the value. Equivalent to round down with zero decimal places. */
14
+ truncate(value: T): T;
15
+ /** Compares 2 decimals.
16
+ * Returns 1 if value1 > value2
17
+ * Returns -1 if value1 < value2
18
+ * Returns 0 if equal
19
+ */
20
+ compare(value1: T, value2: T): 0 | 1 | -1;
21
+ /** Sums a list of decimals and returns the total as a decimal. */
22
+ sum(values: T[]): T;
23
+ /** Divides value by divisor and returns the result. */
24
+ divideBy(value: T, divisor: number | T): T;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { IPropertyInstance } from './Model/PropertyInstance';
2
2
  import PropertyInfo from './Model/PropertyInfo';
3
3
  import { DataType } from './Misc';
4
- import Decimal from 'decimal.js-light';
4
+ import { IDecimal } from "./Numeric/IDecimalService";
5
5
  type Group<T> = {
6
6
  item: T;
7
7
  details: T[];
@@ -34,11 +34,11 @@ declare global {
34
34
  /**
35
35
  * Returns the sum for a given property.
36
36
  */
37
- sum<V extends number | Decimal = number>(propertyName: keyof T | IPropertyInstance<V> | PropertyInfo | ((item: T) => number)): V;
37
+ sum<V extends number | IDecimal = number>(propertyName: keyof T | IPropertyInstance<V> | PropertyInfo | ((item: T) => V)): V;
38
38
  /**
39
39
  * Returns the sum for a given property.
40
40
  */
41
- sumDecimal(propertyName: keyof T | IPropertyInstance<Decimal> | PropertyInfo | ((item: T) => Decimal)): Decimal;
41
+ sumDecimal(propertyName: keyof T | IPropertyInstance<IDecimal> | PropertyInfo | ((item: T) => IDecimal)): IDecimal;
42
42
  /**
43
43
  * Returns the average for a given property.
44
44
  */
@@ -1,6 +1,6 @@
1
1
  import { __spreadArray } from "tslib";
2
2
  import { DataType } from './Misc';
3
- import Decimal from 'decimal.js-light';
3
+ import { NumberUtils, Utils } from ".";
4
4
  //#region Strings
5
5
  String.prototype.format = function () {
6
6
  var args = [];
@@ -84,16 +84,12 @@ Array.prototype.sortBy = function (valueFnOrKey, direction, dataType) {
84
84
  return delta;
85
85
  }
86
86
  else {
87
- return bValue.comparedTo(aValue) * delta;
87
+ return NumberUtils.decimalService.compare(aValue, bValue) * delta; // TODO: check this! bValue!.comparedTo(aValue!) * delta;
88
88
  }
89
89
  };
90
90
  }
91
91
  var array = this;
92
- if (this.addNew) {
93
- // Mobx6 doesn't allow the array to be sorted in place, must create a new one.
94
- array = this.slice();
95
- }
96
- return array.sort(comparer);
92
+ return Utils.sortableArray(array).sort(comparer);
97
93
  };
98
94
  Array.prototype.remove = function (item) {
99
95
  var index = this.indexOf(item);
@@ -102,43 +98,38 @@ Array.prototype.remove = function (item) {
102
98
  }
103
99
  };
104
100
  function getPropertyName(property) {
105
- if (property instanceof String) {
106
- return { key: property };
101
+ if (typeof property === "string") {
102
+ return property;
107
103
  }
108
104
  else {
109
105
  var propertyInfo = property;
110
106
  if (property.propertyInfo) {
111
107
  propertyInfo = property.propertyInfo;
112
108
  }
113
- return { key: propertyInfo.propertyName, isDecimal: propertyInfo.propertyType === DataType.Decimal };
109
+ return propertyInfo.propertyName;
114
110
  }
115
111
  }
116
- Array.prototype.sum = function (property) {
117
- if (property instanceof Function) {
118
- return this.reduce(function (total, item) { return total + property(item); }, 0);
112
+ function map(list, property) {
113
+ if (typeof property === "function") {
114
+ return list.map(property);
119
115
  }
120
116
  else {
121
- var propertyInfo_1 = getPropertyName(property);
122
- if (propertyInfo_1.isDecimal) {
123
- return sumDecimal(this, propertyInfo_1.key);
124
- }
125
- else {
126
- return this.reduce(function (total, item) { return total + item[propertyInfo_1.key]; }, 0);
127
- }
117
+ var propertyName_1 = getPropertyName(property);
118
+ return list.map(function (item) { return item[propertyName_1]; });
128
119
  }
129
- };
130
- Array.prototype.sumDecimal = function (property) {
131
- if (property instanceof Function) {
132
- return this.reduce(function (total, item) { return total.add(property(item)); }, new Decimal(0));
120
+ }
121
+ Array.prototype.sum = function (property) {
122
+ if (this.length === 0) {
123
+ return 0;
124
+ }
125
+ var values = map(this, property);
126
+ if (NumberUtils.decimalService.isDecimal(values[0])) {
127
+ return NumberUtils.decimalService.sum(values);
133
128
  }
134
129
  else {
135
- var propertyInfo = getPropertyName(property);
136
- return sumDecimal(this, propertyInfo.key);
130
+ return values.reduce(function (total, number) { return total + number; }, 0);
137
131
  }
138
132
  };
139
- function sumDecimal(items, propertyName) {
140
- return items.reduce(function (total, item) { return total.add(item[propertyName]); }, new Decimal(0));
141
- }
142
133
  Array.prototype.average = function (property) {
143
134
  return this.length === 0 ? 0 : this.sum(property) / this.length;
144
135
  };
package/dist/Globals.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { IAppService } from './AppServices/AppService';
2
- import Decimal from 'decimal.js-light';
3
2
  export default class Globals {
4
3
  /** Global app service which hosts the DI container. */
5
4
  static appService: IAppService;
@@ -14,6 +13,4 @@ export default class Globals {
14
13
  * Use this for adding elements to the root level.
15
14
  */
16
15
  static get rootElement(): HTMLElement | ShadowRoot;
17
- private static _decimalType;
18
- static get decimalType(): typeof Decimal;
19
16
  }
package/dist/Globals.js CHANGED
@@ -1,4 +1,3 @@
1
- import { NeoTypes } from './AppServices';
2
1
  var Globals = /** @class */ (function () {
3
2
  function Globals() {
4
3
  }
@@ -26,16 +25,6 @@ var Globals = /** @class */ (function () {
26
25
  enumerable: false,
27
26
  configurable: true
28
27
  });
29
- Object.defineProperty(Globals, "decimalType", {
30
- get: function () {
31
- if (this._decimalType === undefined) {
32
- this._decimalType = this.appService.get(NeoTypes.Misc.DecimalType);
33
- }
34
- return this._decimalType;
35
- },
36
- enumerable: false,
37
- configurable: true
38
- });
39
28
  return Globals;
40
29
  }());
41
30
  export default Globals;
@@ -1,13 +1,6 @@
1
- import { IDeserialiseOptions } from '../Data/Deserialiser';
2
1
  import { BindableBase } from './BindableBase';
3
- import { IBindableBase, PartialPlainObject } from './IModelBase';
2
+ import { IBindableBase } from './IModelBase';
4
3
  export interface ILookupBase extends IBindableBase {
5
4
  }
6
5
  export declare abstract class LookupBase extends BindableBase implements ILookupBase {
7
- /**
8
- * @deprecated Models that extend LookupBase are designed to be immutable.
9
- * Calling set() on an instance that is already being observed will not cause the ui to update.
10
- * Rather deserialise on create using `MyLookup.fromJSObject<MyLookup>(data)`.
11
- * */
12
- set(jsObject: PartialPlainObject<this>, options?: IDeserialiseOptions): void;
13
6
  }
@@ -5,15 +5,6 @@ var LookupBase = /** @class */ (function (_super) {
5
5
  function LookupBase() {
6
6
  return _super !== null && _super.apply(this, arguments) || this;
7
7
  }
8
- /**
9
- * @deprecated Models that extend LookupBase are designed to be immutable.
10
- * Calling set() on an instance that is already being observed will not cause the ui to update.
11
- * Rather deserialise on create using `MyLookup.fromJSObject<MyLookup>(data)`.
12
- * */
13
- LookupBase.prototype.set = function (jsObject, options) {
14
- console.warn("Do not use the set() method on lookup models. Rather use the static fromJSObject().");
15
- _super.prototype.set.call(this, jsObject, options);
16
- };
17
8
  return LookupBase;
18
9
  }(BindableBase));
19
10
  export { LookupBase };
@@ -1,6 +1,6 @@
1
1
  import { __spreadArray } from "tslib";
2
2
  import { SerialiseType, RelationType, DataType } from './Misc';
3
- import Globals from '../Globals';
3
+ import NumberUtils from "../NumberUtils";
4
4
  var PropertyInfo = /** @class */ (function () {
5
5
  function PropertyInfo(propertyName) {
6
6
  this.propertyName = propertyName;
@@ -127,7 +127,7 @@ var PropertyInfo = /** @class */ (function () {
127
127
  PropertyInfo.prototype.setupFromInstance = function (instance) {
128
128
  var value = instance[this.propertyName];
129
129
  if (value) {
130
- if (value instanceof Globals.decimalType) {
130
+ if (NumberUtils.decimalService.isDecimal(value)) {
131
131
  this.propertyType = DataType.Decimal;
132
132
  }
133
133
  }
@@ -1,5 +1,5 @@
1
- import Decimal from "decimal.js-light";
2
1
  import { IPropertyInstance } from "./Model";
2
+ import { IDecimal, IDecimalService } from "./Numeric/IDecimalService";
3
3
  export declare enum NumberFormat {
4
4
  None = 0,
5
5
  NoDecimals = 4096,
@@ -10,6 +10,9 @@ export declare enum NumberFormat {
10
10
  CurrencyDecimals = 4353
11
11
  }
12
12
  export default class NumberUtils {
13
+ private static _decimalService?;
14
+ /** Decimal service used internally by neo. Project code should use the chosen decimal package directly. */
15
+ static get decimalService(): IDecimalService;
13
16
  static thousandsSeparator: string;
14
17
  static decimalSeparator?: string;
15
18
  /** Set this to `","` if you want to allow a comma as a decimal separator when parsing string input. */
@@ -41,7 +44,7 @@ export default class NumberUtils {
41
44
  /**
42
45
  * Rounds a number to the nearest no of decimals.
43
46
  */
44
- static round<T extends number | Decimal>(number: T, decimals: number): T;
47
+ static round<T extends number | IDecimal>(number: T, decimals: number): T;
45
48
  /**
46
49
  * Returns the number of decimal places in a format string.
47
50
  * @param formatString Format string.
@@ -53,15 +56,15 @@ export default class NumberUtils {
53
56
  * Converts a number to a string using the specified format.
54
57
  * E.g. #,##0.00;(#,##0.00)
55
58
  */
56
- static format(number: number | Decimal, formatString: string): string;
59
+ static format(number: number | IDecimal, formatString: string): string;
57
60
  /**
58
61
  * Converts a number to a string using the specified format.
59
62
  */
60
- static format(number: number | Decimal, format: NumberFormat, currencySymbol?: string): string;
63
+ static format(number: number | IDecimal, format: NumberFormat, currencySymbol?: string): string;
61
64
  /**
62
65
  * Converts the properties value to a string based on the float / integer decorator.
63
66
  */
64
- static format(property: IPropertyInstance<number | Decimal>): string;
67
+ static format(property: IPropertyInstance<number | IDecimal>): string;
65
68
  private static formatUsingEnum;
66
69
  private static formatInternal;
67
70
  }
@@ -1,6 +1,6 @@
1
- import Decimal from "decimal.js-light";
1
+ import { Misc } from ".";
2
+ import { NeoTypes } from "./AppServices";
2
3
  import { DataType } from "./Model/Misc";
3
- import Globals from './Globals';
4
4
  export var NumberFormat;
5
5
  (function (NumberFormat) {
6
6
  // Mask is [Thousands Separator, Decimals (2 places), Percent, Currency Symbol]
@@ -15,6 +15,17 @@ export var NumberFormat;
15
15
  var NumberUtils = /** @class */ (function () {
16
16
  function NumberUtils() {
17
17
  }
18
+ Object.defineProperty(NumberUtils, "decimalService", {
19
+ /** Decimal service used internally by neo. Project code should use the chosen decimal package directly. */
20
+ get: function () {
21
+ if (!this._decimalService) {
22
+ this._decimalService = Misc.Globals.appService.get(NeoTypes.Core.DecimalService);
23
+ }
24
+ return this._decimalService;
25
+ },
26
+ enumerable: false,
27
+ configurable: true
28
+ });
18
29
  NumberUtils.initialise = function () {
19
30
  NumberUtils.numberFormats[NumberFormat.None] = "#";
20
31
  NumberUtils.numberFormats[NumberFormat.NoDecimals] = "#,##0;(#,##0)";
@@ -85,13 +96,13 @@ var NumberUtils = /** @class */ (function () {
85
96
  * Rounds a number to the nearest no of decimals.
86
97
  */
87
98
  NumberUtils.round = function (number, decimals) {
88
- if (number instanceof Globals.decimalType) {
99
+ if (this.decimalService.isDecimal(number)) {
89
100
  // Round away from zero.
90
- return number.toDecimalPlaces(decimals, Decimal.ROUND_HALF_UP);
101
+ return this.decimalService.round(number, decimals);
91
102
  }
92
103
  else {
93
104
  if (decimals > 0) {
94
- return parseFloat((number).toFixed(decimals));
105
+ return parseFloat(number.toFixed(decimals));
95
106
  }
96
107
  else {
97
108
  return parseInt(number.toFixed(0));
@@ -135,19 +146,19 @@ var NumberUtils = /** @class */ (function () {
135
146
  }
136
147
  return decimalsPart;
137
148
  };
138
- NumberUtils.format = function (number, format, currencySymbol) {
139
- if (number instanceof Globals.decimalType) {
140
- number = number.toNumber();
149
+ NumberUtils.format = function (value, format, currencySymbol) {
150
+ if (this.decimalService.isDecimal(value)) {
151
+ value = this.decimalService.toNumber(value);
141
152
  }
142
- if (number !== null && typeof number === "object") {
143
- var numberValue = number.propertyInfo.propertyType === DataType.Decimal ? number.value.toNumber() : number.value;
144
- return NumberUtils.formatUsingEnum(numberValue, number.propertyInfo.propertyType === DataType.Float || number.propertyInfo.propertyType === DataType.Decimal ? NumberFormat.Decimals : NumberFormat.NoDecimals);
153
+ if (value !== null && typeof value === "object") {
154
+ var numberValue = this.decimalService.toNumber(value.value);
155
+ return NumberUtils.formatUsingEnum(numberValue, value.propertyInfo.propertyType === DataType.Float || value.propertyInfo.propertyType === DataType.Decimal ? NumberFormat.Decimals : NumberFormat.NoDecimals);
145
156
  }
146
157
  else if (typeof format === "string") {
147
- return NumberUtils.formatInternal(number, format);
158
+ return NumberUtils.formatInternal(value, format);
148
159
  }
149
160
  else {
150
- return NumberUtils.formatUsingEnum(number, format, currencySymbol);
161
+ return NumberUtils.formatUsingEnum(value, format, currencySymbol);
151
162
  }
152
163
  };
153
164
  NumberUtils.formatUsingEnum = function (number, format, currencySymbol) {
@@ -0,0 +1,35 @@
1
+ import { IDecimal, IDecimalService } from "./IDecimalService";
2
+ /** Constructor representing Big, or Decimal from the big.js or decimal.js packages. */
3
+ interface IBigDecimalConstructor {
4
+ new (value: number | string): IBigDecimal;
5
+ }
6
+ /** Instance representing Big, or Decimal from the big.js or decimal.js packages. */
7
+ interface IBigDecimal extends IDecimal {
8
+ toNumber(): number;
9
+ toDecimalPlaces?(precision: number, roundingType: number): IBigDecimal;
10
+ round?(precision?: number, roundingType?: number): IBigDecimal;
11
+ cmp(to: IBigDecimal | number | string): 0 | 1 | -1;
12
+ plus(number: IBigDecimal | number | string): IBigDecimal;
13
+ div(number: IBigDecimal | number | string): IBigDecimal;
14
+ }
15
+ /**
16
+ * Service used by neo to perform decimal operations.
17
+ * This class can be used by any of the decimal packages in the repos under https://github.com/MikeMcl.
18
+ * `big.js` is the smallest package, `decimal.js-light` is slightly larger, but newer with a slightly easier api.
19
+ */
20
+ export declare class DecimalService<T extends IBigDecimal> implements IDecimalService<T> {
21
+ private decimalType;
22
+ private roundHalfUpValue;
23
+ private roundDownValue;
24
+ private roundFn;
25
+ constructor(decimalType: IBigDecimalConstructor, roundHalfUpValue: number, roundDownValue: number);
26
+ isDecimal(value: any): value is IBigDecimal;
27
+ createDecimal(value: number | string): T;
28
+ toNumber(value: number | T): number;
29
+ round(value: T, precision: number): T;
30
+ truncate(value: T): T;
31
+ compare(value1: T, value2: T): 0 | 1 | -1;
32
+ sum(values: T[]): T;
33
+ divideBy(value: T, divisor: number | T): T;
34
+ }
35
+ export {};
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Service used by neo to perform decimal operations.
3
+ * This class can be used by any of the decimal packages in the repos under https://github.com/MikeMcl.
4
+ * `big.js` is the smallest package, `decimal.js-light` is slightly larger, but newer with a slightly easier api.
5
+ */
6
+ var DecimalService = /** @class */ (function () {
7
+ function DecimalService(decimalType, roundHalfUpValue, roundDownValue) {
8
+ this.decimalType = decimalType;
9
+ this.roundHalfUpValue = roundHalfUpValue;
10
+ this.roundDownValue = roundDownValue;
11
+ var prototype = decimalType.prototype;
12
+ if (prototype.round) {
13
+ this.roundFn = prototype.round;
14
+ }
15
+ else if (prototype.toDecimalPlaces) {
16
+ this.roundFn = prototype.toDecimalPlaces;
17
+ }
18
+ else {
19
+ throw "Decimal type doesn't provide rounding function";
20
+ }
21
+ }
22
+ DecimalService.prototype.isDecimal = function (value) {
23
+ return value instanceof this.decimalType;
24
+ };
25
+ DecimalService.prototype.createDecimal = function (value) {
26
+ return new this.decimalType(value);
27
+ };
28
+ DecimalService.prototype.toNumber = function (value) {
29
+ if (this.isDecimal(value)) {
30
+ return value.toNumber();
31
+ }
32
+ else {
33
+ return value;
34
+ }
35
+ };
36
+ DecimalService.prototype.round = function (value, precision) {
37
+ return this.roundFn.call(value, precision, this.roundHalfUpValue);
38
+ };
39
+ DecimalService.prototype.truncate = function (value) {
40
+ return this.roundFn.call(value, 0, this.roundDownValue);
41
+ };
42
+ DecimalService.prototype.compare = function (value1, value2) {
43
+ return value1.cmp(value2);
44
+ };
45
+ DecimalService.prototype.sum = function (values) {
46
+ return values.reduce(function (total, item) { return total.plus(item); }, this.createDecimal(0));
47
+ };
48
+ DecimalService.prototype.divideBy = function (value, divisor) {
49
+ return value.div(divisor);
50
+ };
51
+ return DecimalService;
52
+ }());
53
+ export { DecimalService };
@@ -0,0 +1,25 @@
1
+ export interface IDecimal {
2
+ toNumber(): number;
3
+ }
4
+ export interface IDecimalService<T = IDecimal> {
5
+ /** Returns true if the provided value is a decimal instance. */
6
+ isDecimal(value: any): value is IDecimal;
7
+ /** Creates a decimal instance from a javascript number. */
8
+ createDecimal(value: number | string): T;
9
+ /** If the provided value is a decimal, converts it to a number, otherwise returns the number passed in. */
10
+ toNumber(value: number | T): number;
11
+ /** Rounds a number using .net like midpoint away from zero rounding. */
12
+ round(value: T, precision: number): T;
13
+ /** Removes decimal places from the value. Equivalent to round down with zero decimal places. */
14
+ truncate(value: T): T;
15
+ /** Compares 2 decimals.
16
+ * Returns 1 if value1 > value2
17
+ * Returns -1 if value1 < value2
18
+ * Returns 0 if equal
19
+ */
20
+ compare(value1: T, value2: T): 0 | 1 | -1;
21
+ /** Sums a list of decimals and returns the total as a decimal. */
22
+ sum(values: T[]): T;
23
+ /** Divides value by divisor and returns the result. */
24
+ divideBy(value: T, divisor: number | T): T;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,25 @@
1
+ export interface IDecimal {
2
+ toNumber(): number;
3
+ }
4
+ export interface IDecimalService<T = IDecimal> {
5
+ /** Returns true if the provided value is a decimal instance. */
6
+ isDecimal(value: any): value is IDecimal;
7
+ /** Creates a decimal instance from a javascript number. */
8
+ createDecimal(value: number | string): T;
9
+ /** If the provided value is a decimal, converts it to a number, otherwise returns the number passed in. */
10
+ toNumber(value: number | T): number;
11
+ /** Rounds a number using .net like midpoint away from zero rounding. */
12
+ round(value: T, precision: number): T;
13
+ /** Removes decimal places from the value. Equivalent to round down with zero decimal places. */
14
+ truncate(value: T): T;
15
+ /** Compares 2 decimals.
16
+ * Returns 1 if value1 > value2
17
+ * Returns -1 if value1 < value2
18
+ * Returns 0 if equal
19
+ */
20
+ compare(value1: T, value2: T): 0 | 1 | -1;
21
+ /** Sums a list of decimals and returns the total as a decimal. */
22
+ sum(values: T[]): T;
23
+ /** Divides value by divisor and returns the result. */
24
+ divideBy(value: T, divisor: number | T): T;
25
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export type { IDecimal, IDecimalService } from './IDecimalService';
2
+ export { DecimalService } from './DecimalService';
@@ -0,0 +1 @@
1
+ export { DecimalService } from './DecimalService';
@@ -1,10 +1,6 @@
1
1
  import { IUser } from './IUser';
2
2
  import { ISignInResult } from './SignInResult';
3
3
  export default interface IAuthenticationService {
4
- /**
5
- * @deprecated Use loadUserFromSession() instead.
6
- */
7
- loadUserFromToken(): Promise<IUser | null>;
8
4
  /**
9
5
  * Load a user from session storage if there is a stored token.
10
6
  */
@@ -3,8 +3,6 @@ export interface IUser {
3
3
  readonly userName: string;
4
4
  /** Name to display in UI components. */
5
5
  readonly displayName: string;
6
- /** True if the access token has expired. */
7
- readonly hasExpired: boolean;
8
6
  /** Access token for requesting protected resources. */
9
7
  readonly accessToken: string;
10
8
  }
package/dist/Utils.d.ts CHANGED
@@ -31,6 +31,11 @@ export declare class Utils {
31
31
  * Runs the callback in the context of a batch transaction. E.g. a mobx action in react.
32
32
  */
33
33
  static batchUpdate<T>(unitOfWork: () => T): T;
34
+ /**
35
+ * Returns an array that can be sorted using the built in Array.sort method.
36
+ * Mobx dissallows in place sorting on observable arrays.
37
+ */
38
+ static sortableArray<T>(array: T[]): T[];
34
39
  /**
35
40
  * Instructs the ui not to encode the provided html text.
36
41
  * Returns a new element containing the html.
package/dist/Utils.js CHANGED
@@ -46,6 +46,13 @@ var Utils = /** @class */ (function () {
46
46
  Utils.batchUpdate = function (unitOfWork) {
47
47
  return unitOfWork();
48
48
  };
49
+ /**
50
+ * Returns an array that can be sorted using the built in Array.sort method.
51
+ * Mobx dissallows in place sorting on observable arrays.
52
+ */
53
+ Utils.sortableArray = function (array) {
54
+ return array;
55
+ };
49
56
  /**
50
57
  * Instructs the ui not to encode the provided html text.
51
58
  * Returns a new element containing the html.
package/dist/index.d.ts CHANGED
@@ -23,16 +23,18 @@ import * as Localisation from './Localisation';
23
23
  import * as Misc from './Misc';
24
24
  import * as Model from './Model';
25
25
  import * as Network from './ConnectionManager';
26
+ import * as Numeric from './Numeric';
26
27
  import * as Routing from './Routing';
27
28
  import * as Security from './Security';
28
29
  import * as SignalR from './SignalR';
29
30
  import * as Validation from './Validation';
30
31
  import * as Views from './Views/IViewBase';
31
32
  declare const NotifyUtils: Components.INotificationHelper;
32
- export { AppServices, Attributes, Components, Data, DateUtils, DebounceHelper, EnumHelper, FileUtils, JsonSchema, Localisation, List, MenuUtils, Misc, ModalUtils, Model, NeoModel, NeoStrings, Network, NotifyUtils, NumberUtils, Routing, Rules, Security, SignalR, StringUtils, Validation, Views, };
33
+ export { AppServices, Attributes, Components, Data, DateUtils, DebounceHelper, EnumHelper, FileUtils, JsonSchema, Localisation, List, MenuUtils, Misc, ModalUtils, Model, NeoModel, NeoStrings, Network, NotifyUtils, Numeric, NumberUtils, Routing, Rules, Security, SignalR, StringUtils, Validation, Views, };
33
34
  export { runInTask, createProperty };
34
35
  export { default as ModelBase } from './Model/ModelBase';
35
36
  export { default as ValueObject } from './Model/ValueObject';
36
37
  export { LookupBase } from './Model/LookupBase';
37
- export { default as TaskRunner, ITaskRunner } from './Components/TaskRunner/TaskRunner';
38
+ export { default as TaskRunner } from './Components/TaskRunner/TaskRunner';
39
+ export type { ITaskRunner } from './Components/TaskRunner/TaskRunner';
38
40
  export { Utils } from './Utils';
package/dist/index.js CHANGED
@@ -26,6 +26,7 @@ import * as Localisation from './Localisation';
26
26
  import * as Misc from './Misc';
27
27
  import * as Model from './Model';
28
28
  import * as Network from './ConnectionManager';
29
+ import * as Numeric from './Numeric';
29
30
  import * as Routing from './Routing';
30
31
  import * as Security from './Security';
31
32
  import * as SignalR from './SignalR';
@@ -34,7 +35,7 @@ import * as Views from './Views/IViewBase';
34
35
  import { NotificationHelper } from './Components/Notifications/NotificationHelper';
35
36
  var NotifyUtils = new NotificationHelper();
36
37
  // Types
37
- export { AppServices, Attributes, Components, Data, DateUtils, DebounceHelper, EnumHelper, FileUtils, JsonSchema, Localisation, List, MenuUtils, Misc, ModalUtils, Model, NeoModel, NeoStrings, Network, NotifyUtils, NumberUtils, Routing, Rules, Security, SignalR, StringUtils, Validation, Views, };
38
+ export { AppServices, Attributes, Components, Data, DateUtils, DebounceHelper, EnumHelper, FileUtils, JsonSchema, Localisation, List, MenuUtils, Misc, ModalUtils, Model, NeoModel, NeoStrings, Network, NotifyUtils, Numeric, NumberUtils, Routing, Rules, Security, SignalR, StringUtils, Validation, Views, };
38
39
  // Functions
39
40
  export { runInTask, createProperty };
40
41
  export { default as ModelBase } from './Model/ModelBase';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@singularsystems/neo-core",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.7",
4
4
  "description": "Core functionality for the Neo client library",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -24,7 +24,6 @@
24
24
  "dependencies": {
25
25
  "@microsoft/signalr": "^6.0.1",
26
26
  "axios": "1.4.0",
27
- "decimal.js-light": "^2.5.1",
28
27
  "inversify": "^6.0.1",
29
28
  "reflect-metadata": "0.1.13",
30
29
  "tslib": "2.5.0"