@singularsystems/neo-core 1.0.0-beta.9 → 1.0.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.
Files changed (66) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/README.md +4 -0
  3. package/dist/AppServices/Config/ConfigService.js +2 -1
  4. package/dist/AppServices/NeoTypes.d.ts +6 -0
  5. package/dist/AppServices/NeoTypes.js +7 -1
  6. package/dist/AppServices/ServiceIdentifier.js +2 -1
  7. package/dist/AxiosUtils.js +8 -9
  8. package/dist/Components/ErrorHandler.d.ts +1 -5
  9. package/dist/Components/ErrorHandler.js +5 -6
  10. package/dist/Components/FileManager/FileManager.js +5 -4
  11. package/dist/Components/FileManager/FileUploadBatch.js +2 -1
  12. package/dist/Components/Notifications/Notification.js +2 -1
  13. package/dist/Components/Notifications/NotificationHelper.js +2 -1
  14. package/dist/Components/Notifications/NotificationStore.js +2 -1
  15. package/dist/Components/TaskRunner/ProgressState.js +2 -1
  16. package/dist/Components/TaskRunner/TaskRunner.js +2 -1
  17. package/dist/ConnectionManager.js +2 -1
  18. package/dist/Data/ApiDataSource.d.ts +25 -26
  19. package/dist/Data/ApiDataSource.js +87 -97
  20. package/dist/Data/AsyncDataSource.d.ts +6 -2
  21. package/dist/Data/AsyncDataSource.js +22 -2
  22. package/dist/Data/CacheService.d.ts +4 -7
  23. package/dist/Data/CacheService.js +7 -5
  24. package/dist/Data/DataCacheEntry.d.ts +0 -4
  25. package/dist/Data/DataCacheEntry.js +0 -6
  26. package/dist/Data/DataView.js +4 -2
  27. package/dist/Data/Paging/PageManager.js +9 -8
  28. package/dist/Data/Paging/PageRequest.js +2 -1
  29. package/dist/Data/Serialiser.js +1 -0
  30. package/dist/Data/StaticDataSource.d.ts +1 -2
  31. package/dist/Data/StaticDataSource.js +0 -3
  32. package/dist/Data/WindowedDataView.js +2 -1
  33. package/dist/Data/index.d.ts +1 -1
  34. package/dist/Data/index.js +1 -1
  35. package/dist/Dates/DateUtils.js +2 -1
  36. package/dist/Extensions.d.ts +0 -4
  37. package/dist/Extensions.js +1 -1
  38. package/dist/IndexDb/IDbSet.d.ts +2 -0
  39. package/dist/JsonSchema/JsonSchemaTypes.d.ts +1 -0
  40. package/dist/Model/BaseModels/AuditValues.js +4 -2
  41. package/dist/Model/BaseModels/CriteriaBase.js +2 -1
  42. package/dist/Model/BaseModels/ReasonedUserEvent.js +2 -1
  43. package/dist/Model/BaseModels/UserEvent.js +4 -2
  44. package/dist/Model/BindableBase.js +2 -1
  45. package/dist/Model/IModelBase.d.ts +3 -3
  46. package/dist/Model/ModelCreatorBase.js +2 -1
  47. package/dist/Model/ModelFieldInfo.js +2 -1
  48. package/dist/Model/ObservableValue.js +2 -1
  49. package/dist/NumberUtils.d.ts +3 -1
  50. package/dist/NumberUtils.js +2 -2
  51. package/dist/Routing/MenuItemProvider.js +2 -1
  52. package/dist/Routing/RouteSecurityService.js +2 -1
  53. package/dist/Security/LoginErrorHandler.js +2 -1
  54. package/dist/Security/SecurityService.js +2 -1
  55. package/dist/SignalR/IServerMessageSubscriber.d.ts +4 -0
  56. package/dist/SignalR/index.d.ts +1 -0
  57. package/dist/Validation/DisplayHelper.d.ts +3 -1
  58. package/dist/Validation/RuleContext.d.ts +4 -0
  59. package/dist/Validation/RuleContext.js +4 -0
  60. package/package.json +9 -7
  61. package/dist/Decimal/DecimalService.d.ts +0 -23
  62. package/dist/Decimal/DecimalService.js +0 -38
  63. package/dist/Decimal/IDecimal.d.ts +0 -25
  64. package/dist/Numeric/IDecimal.d.ts +0 -25
  65. package/dist/Numeric/IDecimal.js +0 -1
  66. /package/dist/{Decimal/IDecimal.js → SignalR/IServerMessageSubscriber.js} +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+
2
+
3
+ # Breaking changes
4
+
5
+ ## 0.10.65 (6 March 2023)
6
+
7
+ * `IErrorHandler` now requires the return type to be `Promise<IErrorDisplay>` instead of `IErrorDisplay`.
8
+ * Most of the protected methods in `ErrorHandler` have been changed to `async`.
9
+ * These changes were required in order to be able to read errors from axios blob responses.
10
+
11
+ # Change Log
12
+
13
+ ## 0.10.65 (6 March 2023)
14
+
15
+ * Fixed error handler not parsing axios responses when response type is `blob`.
package/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  This project contains the core functionality of the neo client library.
4
4
 
5
+ ## Building
6
+
7
+ Run `yarn dlx @yarnpkg/sdks vscode` to enable typescript for yarn in vscode.
8
+
5
9
  ## Testing
6
10
 
7
11
  To debug the tests, you need to add the following to .vscode\launch.json
@@ -3,7 +3,7 @@ import { injectable, inject } from 'inversify';
3
3
  import Axios from "axios";
4
4
  import NeoTypes from '../NeoTypes';
5
5
  import AxiosUtils from "../../AxiosUtils";
6
- export var ConfigService = /** @class */ (function () {
6
+ var ConfigService = /** @class */ (function () {
7
7
  function ConfigService(config) {
8
8
  this.config = config;
9
9
  }
@@ -68,3 +68,4 @@ export var ConfigService = /** @class */ (function () {
68
68
  ], ConfigService);
69
69
  return ConfigService;
70
70
  }());
71
+ export { ConfigService };
@@ -19,6 +19,7 @@ import { IContextMenuState } from '../Components/ContextMenu/ContextMenu';
19
19
  import { INavigationHelper } from '../Routing/INavigationHelper';
20
20
  import { ILoginErrorHandler } from '../Security/ILoginErrorHandler';
21
21
  import { IDecimalService } from "../Numeric";
22
+ import { IServerMessageSubscriber } from "../SignalR/IServerMessageSubscriber";
22
23
  declare const NeoTypes: {
23
24
  Axios: ServiceIdentifier<import("axios").AxiosStatic>;
24
25
  Config: {
@@ -27,6 +28,7 @@ declare const NeoTypes: {
27
28
  };
28
29
  Core: {
29
30
  AutoRunnerFactory: ServiceIdentifier<IAutoRunnerFactory>;
31
+ /** @deprecated Use Messaging.ConnectionManager */
30
32
  ConnectionManager: ServiceIdentifier<IConnectionManager>;
31
33
  DecimalService: ServiceIdentifier<IDecimalService<import("../Numeric").IDecimal>>;
32
34
  ModelCreator: ServiceIdentifier<IModelCreatorBase>;
@@ -34,6 +36,10 @@ declare const NeoTypes: {
34
36
  Localisation: {
35
37
  LocalisationService: ServiceIdentifier<ILocalisationService>;
36
38
  };
39
+ Messaging: {
40
+ ConnectionManager: ServiceIdentifier<IConnectionManager>;
41
+ ServerMessageSubscriber: ServiceIdentifier<IServerMessageSubscriber>;
42
+ };
37
43
  Routing: {
38
44
  MenuItemProvider: ServiceIdentifier<IMenuItemProvider<import("../Routing").IMenuRoute>>;
39
45
  NavigationHelper: ServiceIdentifier<INavigationHelper>;
@@ -1,4 +1,5 @@
1
1
  import { ServiceIdentifier } from './ServiceIdentifier';
2
+ var connectionManagerType = new ServiceIdentifier("Neo.ConnectionManager");
2
3
  // Neo Module Type Symbols
3
4
  var NeoTypes = {
4
5
  Axios: new ServiceIdentifier("Neo.Axios"),
@@ -8,13 +9,18 @@ var NeoTypes = {
8
9
  },
9
10
  Core: {
10
11
  AutoRunnerFactory: new ServiceIdentifier("Neo.AutoRunnerFactory"),
11
- ConnectionManager: new ServiceIdentifier("Neo.ConnectionManager"),
12
+ /** @deprecated Use Messaging.ConnectionManager */
13
+ ConnectionManager: connectionManagerType,
12
14
  DecimalService: new ServiceIdentifier("Neo.DecimalService"),
13
15
  ModelCreator: new ServiceIdentifier("Neo.ModelCreator")
14
16
  },
15
17
  Localisation: {
16
18
  LocalisationService: new ServiceIdentifier("Neo.Localisation")
17
19
  },
20
+ Messaging: {
21
+ ConnectionManager: connectionManagerType,
22
+ ServerMessageSubscriber: new ServiceIdentifier("Neo.ServerMessageSubscriber"),
23
+ },
18
24
  Routing: {
19
25
  MenuItemProvider: new ServiceIdentifier("Neo.MenuItemProvider"),
20
26
  NavigationHelper: new ServiceIdentifier("Neo.NavigationHelper"),
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Strongly typed identifier for a service.
3
3
  */
4
- export var ServiceIdentifier = /** @class */ (function () {
4
+ var ServiceIdentifier = /** @class */ (function () {
5
5
  /**
6
6
  * Creates a service identifier.
7
7
  * @param name Name used for debugging, not required to be unique.
@@ -36,3 +36,4 @@ export var ServiceIdentifier = /** @class */ (function () {
36
36
  ServiceIdentifier.typeNames = new Set();
37
37
  return ServiceIdentifier;
38
38
  }());
39
+ export { ServiceIdentifier };
@@ -13,7 +13,7 @@ var AxiosUtils = /** @class */ (function () {
13
13
  return __generator(this, function (_a) {
14
14
  switch (_a.label) {
15
15
  case 0:
16
- _a.trys.push([0, 2, , 3]);
16
+ _a.trys.push([0, 2, , 5]);
17
17
  return [4 /*yield*/, request];
18
18
  case 1:
19
19
  waited = _a.sent();
@@ -23,22 +23,21 @@ var AxiosUtils = /** @class */ (function () {
23
23
  }];
24
24
  case 2:
25
25
  e_1 = _a.sent();
26
- if (isAxiosError(e_1)) {
27
- if (filter === undefined || filter(e_1.response)) {
28
- return [2 /*return*/, this.readError(e_1)];
29
- }
30
- }
31
- throw e_1;
32
- case 3: return [2 /*return*/];
26
+ if (!isAxiosError(e_1)) return [3 /*break*/, 4];
27
+ if (!(filter === undefined || filter(e_1.response))) return [3 /*break*/, 4];
28
+ return [4 /*yield*/, this.readError(e_1)];
29
+ case 3: return [2 /*return*/, _a.sent()];
30
+ case 4: throw e_1;
31
+ case 5: return [2 /*return*/];
33
32
  }
34
33
  });
35
34
  });
36
35
  };
37
36
  /** Reads the properties of an axios error. */
38
37
  AxiosUtils.readError = function (e) {
39
- var _a, _b;
40
38
  return __awaiter(this, void 0, void 0, function () {
41
39
  var data, isServerError;
40
+ var _a, _b;
42
41
  return __generator(this, function (_c) {
43
42
  switch (_c.label) {
44
43
  case 0:
@@ -39,11 +39,7 @@ export declare enum ErrorDisplayType {
39
39
  }
40
40
  export declare class ErrorHandler implements IErrorHandler {
41
41
  private notifications;
42
- private blobType;
43
- constructor(notifications: INotificationHelper, blobType?: {
44
- new (blobParts?: BlobPart[] | undefined, options?: BlobPropertyBag | undefined): Blob;
45
- prototype: Blob;
46
- });
42
+ constructor(notifications: INotificationHelper);
47
43
  showError(error: any, displayType: ErrorDisplayType): Promise<void>;
48
44
  parseError(error: any): Promise<IErrorDisplay>;
49
45
  protected getAxiosError(error: AxiosError, response?: AxiosResponse): Promise<IErrorDisplay>;
@@ -14,11 +14,9 @@ export var ErrorDisplayType;
14
14
  /** Do nothing, error will be re-thrown. */
15
15
  ErrorDisplayType[ErrorDisplayType["ThrowError"] = 2] = "ThrowError";
16
16
  })(ErrorDisplayType || (ErrorDisplayType = {}));
17
- export var ErrorHandler = /** @class */ (function () {
18
- function ErrorHandler(notifications, blobType) {
19
- if (blobType === void 0) { blobType = Blob; }
17
+ var ErrorHandler = /** @class */ (function () {
18
+ function ErrorHandler(notifications) {
20
19
  this.notifications = notifications;
21
- this.blobType = blobType;
22
20
  }
23
21
  ErrorHandler.prototype.showError = function (error, displayType) {
24
22
  return __awaiter(this, void 0, void 0, function () {
@@ -120,9 +118,9 @@ export var ErrorHandler = /** @class */ (function () {
120
118
  * @param error Axios error.
121
119
  */
122
120
  ErrorHandler.prototype.parseAxiosError = function (header, body, error) {
123
- var _a;
124
121
  return __awaiter(this, void 0, void 0, function () {
125
122
  var errorDisplay, rawErrorData_1, errorData_1;
123
+ var _a;
126
124
  return __generator(this, function (_b) {
127
125
  switch (_b.label) {
128
126
  case 0:
@@ -186,7 +184,8 @@ export var ErrorHandler = /** @class */ (function () {
186
184
  ErrorHandler = __decorate([
187
185
  injectable(),
188
186
  __param(0, inject(NeoTypes.UI.GlobalNotifications.symbol)),
189
- __metadata("design:paramtypes", [Object, Object])
187
+ __metadata("design:paramtypes", [Object])
190
188
  ], ErrorHandler);
191
189
  return ErrorHandler;
192
190
  }());
191
+ export { ErrorHandler };
@@ -9,7 +9,7 @@ import { Settings } from '../../Settings';
9
9
  import { FileUploadBatch } from './FileUploadBatch';
10
10
  import NeoStrings from '../../Localisation/NeoStrings';
11
11
  var fileInputSymbol = Symbol("FileInput");
12
- export var FileManagerBase = /** @class */ (function () {
12
+ var FileManagerBase = /** @class */ (function () {
13
13
  function FileManagerBase(uploadEndpointOrOptions, options) {
14
14
  this.currentUploads = [];
15
15
  if (uploadEndpointOrOptions === undefined || typeof uploadEndpointOrOptions === "string") {
@@ -97,9 +97,9 @@ export var FileManagerBase = /** @class */ (function () {
97
97
  /**
98
98
  * Checks if file extensions are allowed, then calls onFilesSelected, or uploadFiles
99
99
  */
100
- FileManagerBase.prototype.processFiles = function (files, options) {
101
- if (options === void 0) { options = {}; }
102
- return __awaiter(this, void 0, void 0, function () {
100
+ FileManagerBase.prototype.processFiles = function (files_1) {
101
+ return __awaiter(this, arguments, void 0, function (files, options) {
102
+ if (options === void 0) { options = {}; }
103
103
  return __generator(this, function (_a) {
104
104
  if (files.length > 1 && !this.allowMultiple) {
105
105
  files = [Array.from(files)[0]];
@@ -252,6 +252,7 @@ export var FileManagerBase = /** @class */ (function () {
252
252
  ], FileManagerBase.prototype, "currentUploads", void 0);
253
253
  return FileManagerBase;
254
254
  }());
255
+ export { FileManagerBase };
255
256
  var FileManager = /** @class */ (function (_super) {
256
257
  __extends(FileManager, _super);
257
258
  function FileManager() {
@@ -2,7 +2,7 @@ import { __decorate, __metadata } from "tslib";
2
2
  import { Utils } from "../../Utils";
3
3
  import NeoModel from "../../Model/NeoModel";
4
4
  import { Observable } from "../../Model/Decorators";
5
- export var FileUploadBatch = /** @class */ (function () {
5
+ var FileUploadBatch = /** @class */ (function () {
6
6
  function FileUploadBatch(files) {
7
7
  this.recordIndex = {};
8
8
  this.key = Utils.uuidv4();
@@ -81,3 +81,4 @@ export var FileUploadBatch = /** @class */ (function () {
81
81
  ], FileUploadBatch);
82
82
  return FileUploadBatch;
83
83
  }());
84
+ export { FileUploadBatch };
@@ -2,7 +2,7 @@ import { __decorate, __metadata } from "tslib";
2
2
  import { Utils } from "../../Utils";
3
3
  import { Observable } from '../../Model/Decorators';
4
4
  import NeoModel from '../../Model/NeoModel';
5
- export var Notification = /** @class */ (function () {
5
+ var Notification = /** @class */ (function () {
6
6
  function Notification(options, body) {
7
7
  this.options = options;
8
8
  this.body = body;
@@ -24,3 +24,4 @@ export var Notification = /** @class */ (function () {
24
24
  ], Notification);
25
25
  return Notification;
26
26
  }());
27
+ export { Notification };
@@ -3,7 +3,7 @@ import { Globals } from '../../Misc';
3
3
  import NeoTypes from '../../AppServices/NeoTypes';
4
4
  import { ModalUtils } from '../Modal/ModalUtils';
5
5
  import { injectable, inject } from 'inversify';
6
- export var NotificationHelper = /** @class */ (function () {
6
+ var NotificationHelper = /** @class */ (function () {
7
7
  /**
8
8
  * Creates a new notification helper which can be bound to a ToastContainer / other alert ui component.
9
9
  * @param store Optional store which contains the notification message objects.
@@ -109,3 +109,4 @@ export var NotificationHelper = /** @class */ (function () {
109
109
  ], NotificationHelper);
110
110
  return NotificationHelper;
111
111
  }());
112
+ export { NotificationHelper };
@@ -4,7 +4,7 @@ import { Notification } from './Notification';
4
4
  import { Observable } from '../../Model/Decorators';
5
5
  import NeoModel from '../../Model/NeoModel';
6
6
  import { injectable } from 'inversify';
7
- export var NotificationStore = /** @class */ (function () {
7
+ var NotificationStore = /** @class */ (function () {
8
8
  function NotificationStore() {
9
9
  this.notifications = [];
10
10
  }
@@ -76,3 +76,4 @@ export var NotificationStore = /** @class */ (function () {
76
76
  ], NotificationStore);
77
77
  return NotificationStore;
78
78
  }());
79
+ export { NotificationStore };
@@ -1,7 +1,7 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import NeoModel from '../../Model/NeoModel';
3
3
  import { Observable } from '../../Model/Decorators';
4
- export var ProgressState = /** @class */ (function () {
4
+ var ProgressState = /** @class */ (function () {
5
5
  function ProgressState() {
6
6
  this._progress = 0;
7
7
  /** Animation state used by UI components. */
@@ -69,3 +69,4 @@ export var ProgressState = /** @class */ (function () {
69
69
  ], ProgressState);
70
70
  return ProgressState;
71
71
  }());
72
+ export { ProgressState };
@@ -6,7 +6,7 @@ import { injectable, inject } from 'inversify';
6
6
  import { ErrorDisplayType } from '../ErrorHandler';
7
7
  import { NeoTypes } from '../../AppServices';
8
8
  import { ProgressState } from './ProgressState';
9
- export var TaskRunnerOptions = /** @class */ (function () {
9
+ var TaskRunnerOptions = /** @class */ (function () {
10
10
  function TaskRunnerOptions(taskRunner) {
11
11
  this.taskRunner = taskRunner;
12
12
  /** Specifies how the task runner must handle errors that are raised by your code. */
@@ -42,6 +42,7 @@ export var TaskRunnerOptions = /** @class */ (function () {
42
42
  ], TaskRunnerOptions);
43
43
  return TaskRunnerOptions;
44
44
  }());
45
+ export { TaskRunnerOptions };
45
46
  var WaitForTaskRunnerOptions = /** @class */ (function (_super) {
46
47
  __extends(WaitForTaskRunnerOptions, _super);
47
48
  function WaitForTaskRunnerOptions() {
@@ -25,7 +25,7 @@ var ConnectionInfo = /** @class */ (function () {
25
25
  return ConnectionInfo;
26
26
  }());
27
27
  export { ConnectionInfo };
28
- export var ConnectionManager = /** @class */ (function () {
28
+ var ConnectionManager = /** @class */ (function () {
29
29
  function ConnectionManager() {
30
30
  this._connections = new Map();
31
31
  }
@@ -58,3 +58,4 @@ export var ConnectionManager = /** @class */ (function () {
58
58
  ], ConnectionManager);
59
59
  return ConnectionManager;
60
60
  }());
61
+ export { ConnectionManager };
@@ -1,15 +1,9 @@
1
1
  import { AsyncDataSource, IAsyncDataSource } from './AsyncDataSource';
2
2
  import { AxiosPromise } from 'axios';
3
- import List from '../Model/List';
3
+ import { PlainObject, IBindableBase } from "../Model/IModelBase";
4
+ import { IDbSet } from "../IndexDb/IDbSet";
4
5
  export interface IApiDataSource<T> extends IAsyncDataSource<T> {
5
6
  }
6
- export declare class CallbackDataSource<T> extends AsyncDataSource<T> {
7
- private callBack;
8
- private defaultData;
9
- constructor(callBack: () => Promise<any>, defaultData: T);
10
- protected getDataAsync(): Promise<any>;
11
- copy(): IAsyncDataSource<T>;
12
- }
13
7
  /**
14
8
  * Allows an api endpoint to be used directly by a consumer such as a drop down element.
15
9
  * If you need the data to be deserialised into a specific lookup model, use ApiClientLookupDataSource.
@@ -19,28 +13,33 @@ export declare class ApiClientDataSource<T> extends AsyncDataSource<T> implement
19
13
  private defaultData?;
20
14
  constructor(getMethod: () => AxiosPromise<T>, defaultData?: T | undefined);
21
15
  protected getDataAsync(): Promise<T>;
22
- /** Provides a copy of this datasource, without any data. */
23
- copy(): ApiClientDataSource<T>;
16
+ }
17
+ export declare abstract class ConvertingApiClientDataSource<T> extends AsyncDataSource<T> implements IApiDataSource<T> {
18
+ protected getMethod: () => AxiosPromise<any>;
19
+ private supportOffline;
20
+ constructor(getMethod: () => AxiosPromise<any>, defaultData: T, supportOffline: boolean);
21
+ protected abstract convertData(rawData: any): T;
22
+ protected abstract offlineGet(): Promise<any>;
23
+ protected abstract offlineStore(data: any): Promise<void>;
24
+ protected getDataAsync(): Promise<T>;
24
25
  }
25
26
  /**
26
27
  * Allows an api endpoint to be used directly by a consumer such as a drop down element.
27
28
  * Deserialises the json data returned by the api into a list of the specified lookup object.
28
29
  */
29
- export declare class ApiClientLookupDataSource<T> extends AsyncDataSource<T[]> implements IApiDataSource<T[]> {
30
- private getMethod;
31
- private deserialiseType?;
32
- private defaultData?;
33
- constructor(getMethod: () => AxiosPromise<any>, deserialiseType?: (new () => T) | undefined, defaultData?: T[] | undefined);
34
- protected getDataAsync(): Promise<List<T>>;
35
- /** Provides a copy of this datasource, without any data. */
36
- copy(): ApiClientLookupDataSource<T>;
30
+ export declare class ApiClientLookupDataSource<T extends IBindableBase> extends ConvertingApiClientDataSource<T[]> {
31
+ private deserialiseType;
32
+ private dbSet?;
33
+ constructor(getMethod: () => AxiosPromise<PlainObject<T>[]>, deserialiseType: (new () => T), defaultData?: T[], dbSet?: IDbSet<import("../Model/IModelBase").PlainObject<Exclude<keyof T, keyof import("../Model/IModelBase").IModelBase> & { [P_1 in keyof T]: T[P_1] extends Function ? never : P_1; }[keyof T] extends infer T_1 extends keyof T ? { [P in T_1]: T[P]; } : never>> | undefined);
34
+ protected offlineGet(): Promise<any>;
35
+ protected offlineStore(rawData: any): Promise<void>;
36
+ protected convertData(rawData: any): T[];
37
37
  }
38
- export declare class ApiDataSource<T> extends AsyncDataSource<T> implements IApiDataSource<T> {
39
- private apiEndpoint;
40
- private defaultData;
41
- private axiosInstance;
42
- constructor(apiEndpoint: string, defaultData: T, axiosInstance?: import("axios").AxiosStatic);
43
- protected getDataAsync(): Promise<any>;
44
- /** Provides a copy of this datasource, without any data. */
45
- copy(): ApiDataSource<T>;
38
+ export declare class ApiClientSingleLookupDataSource<T extends IBindableBase> extends ConvertingApiClientDataSource<T> {
39
+ private deserialiseType;
40
+ private dbSet?;
41
+ constructor(getMethod: () => AxiosPromise<PlainObject<T>>, deserialiseType: (new () => T), defaultData?: T, dbSet?: IDbSet<import("../Model/IModelBase").PlainObject<Exclude<keyof T, keyof import("../Model/IModelBase").IModelBase> & { [P_1 in keyof T]: T[P_1] extends Function ? never : P_1; }[keyof T] extends infer T_1 extends keyof T ? { [P in T_1]: T[P]; } : never>> | undefined);
42
+ protected offlineGet(): Promise<any>;
43
+ protected offlineStore(rawData: any): Promise<void>;
44
+ protected convertData(rawData: any): T;
46
45
  }
@@ -1,58 +1,13 @@
1
1
  import { __awaiter, __decorate, __extends, __generator, __metadata } from "tslib";
2
2
  import { AsyncDataSource } from './AsyncDataSource';
3
- import { Globals } from '../Misc';
4
3
  import NeoModel from '../Model/NeoModel';
5
- import { NeoTypes } from '../AppServices';
6
4
  import List from '../Model/List';
7
- export var CallbackDataSource = /** @class */ (function (_super) {
8
- __extends(CallbackDataSource, _super);
9
- function CallbackDataSource(callBack, defaultData) {
10
- var _this = _super.call(this, defaultData) || this;
11
- _this.callBack = callBack;
12
- _this.defaultData = defaultData;
13
- return _this;
14
- }
15
- CallbackDataSource_1 = CallbackDataSource;
16
- CallbackDataSource.prototype.getDataAsync = function () {
17
- return this.callBack();
18
- };
19
- CallbackDataSource.prototype.copy = function () {
20
- return new CallbackDataSource_1(this.callBack, this.defaultData);
21
- };
22
- var CallbackDataSource_1;
23
- CallbackDataSource = CallbackDataSource_1 = __decorate([
24
- NeoModel,
25
- __metadata("design:paramtypes", [Function, Object])
26
- ], CallbackDataSource);
27
- return CallbackDataSource;
28
- }(AsyncDataSource));
29
- function unwrapAxiosPromise(axiosPromise) {
30
- var _this = this;
31
- return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
32
- var _a, e_1;
33
- return __generator(this, function (_b) {
34
- switch (_b.label) {
35
- case 0:
36
- _b.trys.push([0, 2, , 3]);
37
- _a = resolve;
38
- return [4 /*yield*/, axiosPromise];
39
- case 1:
40
- _a.apply(void 0, [(_b.sent()).data]);
41
- return [3 /*break*/, 3];
42
- case 2:
43
- e_1 = _b.sent();
44
- reject(e_1);
45
- return [3 /*break*/, 3];
46
- case 3: return [2 /*return*/];
47
- }
48
- });
49
- }); });
50
- }
5
+ import AxiosUtils from "../AxiosUtils";
51
6
  /**
52
7
  * Allows an api endpoint to be used directly by a consumer such as a drop down element.
53
8
  * If you need the data to be deserialised into a specific lookup model, use ApiClientLookupDataSource.
54
9
  */
55
- export var ApiClientDataSource = /** @class */ (function (_super) {
10
+ var ApiClientDataSource = /** @class */ (function (_super) {
56
11
  __extends(ApiClientDataSource, _super);
57
12
  function ApiClientDataSource(getMethod, defaultData) {
58
13
  var _this = _super.call(this, defaultData !== null && defaultData !== void 0 ? defaultData : []) || this;
@@ -60,81 +15,116 @@ export var ApiClientDataSource = /** @class */ (function (_super) {
60
15
  _this.defaultData = defaultData;
61
16
  return _this;
62
17
  }
63
- ApiClientDataSource_1 = ApiClientDataSource;
64
18
  ApiClientDataSource.prototype.getDataAsync = function () {
65
- return unwrapAxiosPromise(this.getMethod());
66
- };
67
- /** Provides a copy of this datasource, without any data. */
68
- ApiClientDataSource.prototype.copy = function () {
69
- return new ApiClientDataSource_1(this.getMethod, this.defaultData);
19
+ return __awaiter(this, void 0, void 0, function () {
20
+ return __generator(this, function (_a) {
21
+ switch (_a.label) {
22
+ case 0: return [4 /*yield*/, this.getMethod()];
23
+ case 1: return [2 /*return*/, (_a.sent()).data];
24
+ }
25
+ });
26
+ });
70
27
  };
71
- var ApiClientDataSource_1;
72
- ApiClientDataSource = ApiClientDataSource_1 = __decorate([
28
+ ApiClientDataSource = __decorate([
73
29
  NeoModel,
74
30
  __metadata("design:paramtypes", [Function, Object])
75
31
  ], ApiClientDataSource);
76
32
  return ApiClientDataSource;
77
33
  }(AsyncDataSource));
78
- /**
79
- * Allows an api endpoint to be used directly by a consumer such as a drop down element.
80
- * Deserialises the json data returned by the api into a list of the specified lookup object.
81
- */
82
- export var ApiClientLookupDataSource = /** @class */ (function (_super) {
83
- __extends(ApiClientLookupDataSource, _super);
84
- function ApiClientLookupDataSource(getMethod, deserialiseType, defaultData) {
85
- var _this = _super.call(this, defaultData !== null && defaultData !== void 0 ? defaultData : []) || this;
34
+ export { ApiClientDataSource };
35
+ var ConvertingApiClientDataSource = /** @class */ (function (_super) {
36
+ __extends(ConvertingApiClientDataSource, _super);
37
+ function ConvertingApiClientDataSource(getMethod, defaultData, supportOffline) {
38
+ var _this = _super.call(this, defaultData) || this;
86
39
  _this.getMethod = getMethod;
87
- _this.deserialiseType = deserialiseType;
88
- _this.defaultData = defaultData;
40
+ _this.supportOffline = supportOffline;
89
41
  return _this;
90
42
  }
91
- ApiClientLookupDataSource_1 = ApiClientLookupDataSource;
92
- ApiClientLookupDataSource.prototype.getDataAsync = function () {
43
+ ConvertingApiClientDataSource.prototype.getDataAsync = function () {
93
44
  return __awaiter(this, void 0, void 0, function () {
94
- var rawData;
45
+ var rawData, result;
95
46
  return __generator(this, function (_a) {
96
47
  switch (_a.label) {
97
- case 0: return [4 /*yield*/, unwrapAxiosPromise(this.getMethod())];
48
+ case 0:
49
+ if (!navigator.onLine) return [3 /*break*/, 2];
50
+ return [4 /*yield*/, AxiosUtils.catchErrors(this.getMethod())];
98
51
  case 1:
52
+ result = _a.sent();
53
+ if (result.success) {
54
+ rawData = result.data;
55
+ if (this.supportOffline) {
56
+ this.offlineStore(rawData);
57
+ }
58
+ }
59
+ else if (!result.isNetworkError || !this.supportOffline) {
60
+ throw result.error;
61
+ }
62
+ _a.label = 2;
63
+ case 2:
64
+ if (!this.supportOffline) return [3 /*break*/, 4];
65
+ return [4 /*yield*/, this.offlineGet()];
66
+ case 3:
99
67
  rawData = _a.sent();
100
- return [2 /*return*/, List.fromJSArray(this.deserialiseType, rawData)];
68
+ _a.label = 4;
69
+ case 4: return [2 /*return*/, this.convertData(rawData)];
101
70
  }
102
71
  });
103
72
  });
104
73
  };
105
- /** Provides a copy of this datasource, without any data. */
106
- ApiClientLookupDataSource.prototype.copy = function () {
107
- return new ApiClientLookupDataSource_1(this.getMethod, this.deserialiseType, this.defaultData);
74
+ return ConvertingApiClientDataSource;
75
+ }(AsyncDataSource));
76
+ export { ConvertingApiClientDataSource };
77
+ /**
78
+ * Allows an api endpoint to be used directly by a consumer such as a drop down element.
79
+ * Deserialises the json data returned by the api into a list of the specified lookup object.
80
+ */
81
+ var ApiClientLookupDataSource = /** @class */ (function (_super) {
82
+ __extends(ApiClientLookupDataSource, _super);
83
+ function ApiClientLookupDataSource(getMethod, deserialiseType, defaultData, dbSet) {
84
+ var _this = _super.call(this, getMethod, defaultData !== null && defaultData !== void 0 ? defaultData : [], dbSet !== undefined) || this;
85
+ _this.deserialiseType = deserialiseType;
86
+ _this.dbSet = dbSet;
87
+ return _this;
88
+ }
89
+ ApiClientLookupDataSource.prototype.offlineGet = function () {
90
+ return this.dbSet.getAllAsync();
91
+ };
92
+ ApiClientLookupDataSource.prototype.offlineStore = function (rawData) {
93
+ return this.dbSet.putAsync(rawData);
108
94
  };
109
- var ApiClientLookupDataSource_1;
110
- ApiClientLookupDataSource = ApiClientLookupDataSource_1 = __decorate([
95
+ ApiClientLookupDataSource.prototype.convertData = function (rawData) {
96
+ return List.fromJSArray(this.deserialiseType, rawData);
97
+ };
98
+ ApiClientLookupDataSource = __decorate([
111
99
  NeoModel,
112
- __metadata("design:paramtypes", [Function, Function, Array])
100
+ __metadata("design:paramtypes", [Function, Function, Array, Object])
113
101
  ], ApiClientLookupDataSource);
114
102
  return ApiClientLookupDataSource;
115
- }(AsyncDataSource));
116
- export var ApiDataSource = /** @class */ (function (_super) {
117
- __extends(ApiDataSource, _super);
118
- function ApiDataSource(apiEndpoint, defaultData, axiosInstance) {
119
- if (axiosInstance === void 0) { axiosInstance = Globals.appService.get(NeoTypes.Axios); }
120
- var _this = _super.call(this, defaultData) || this;
121
- _this.apiEndpoint = apiEndpoint;
122
- _this.defaultData = defaultData;
123
- _this.axiosInstance = axiosInstance;
103
+ }(ConvertingApiClientDataSource));
104
+ export { ApiClientLookupDataSource };
105
+ var ApiClientSingleLookupDataSource = /** @class */ (function (_super) {
106
+ __extends(ApiClientSingleLookupDataSource, _super);
107
+ function ApiClientSingleLookupDataSource(getMethod, deserialiseType, defaultData, dbSet) {
108
+ var _this = _super.call(this, getMethod, defaultData !== null && defaultData !== void 0 ? defaultData : new deserialiseType(), dbSet !== undefined) || this;
109
+ _this.deserialiseType = deserialiseType;
110
+ _this.dbSet = dbSet;
124
111
  return _this;
125
112
  }
126
- ApiDataSource_1 = ApiDataSource;
127
- ApiDataSource.prototype.getDataAsync = function () {
128
- return unwrapAxiosPromise(this.axiosInstance.get(this.apiEndpoint));
113
+ ApiClientSingleLookupDataSource.prototype.offlineGet = function () {
114
+ return this.dbSet.getAsync(1);
129
115
  };
130
- /** Provides a copy of this datasource, without any data. */
131
- ApiDataSource.prototype.copy = function () {
132
- return new ApiDataSource_1(this.apiEndpoint, this.defaultData);
116
+ ApiClientSingleLookupDataSource.prototype.offlineStore = function (rawData) {
117
+ return this.dbSet.putAsync(rawData, 1);
133
118
  };
134
- var ApiDataSource_1;
135
- ApiDataSource = ApiDataSource_1 = __decorate([
119
+ ApiClientSingleLookupDataSource.prototype.convertData = function (rawData) {
120
+ var model = new this.deserialiseType();
121
+ model.set(rawData);
122
+ return model;
123
+ };
124
+ ApiClientSingleLookupDataSource = __decorate([
136
125
  NeoModel,
137
- __metadata("design:paramtypes", [String, Object, Object])
138
- ], ApiDataSource);
139
- return ApiDataSource;
140
- }(AsyncDataSource));
126
+ __metadata("design:paramtypes", [Function, Function, Object, Object])
127
+ ], ApiClientSingleLookupDataSource);
128
+ return ApiClientSingleLookupDataSource;
129
+ }(ConvertingApiClientDataSource));
130
+ export { ApiClientSingleLookupDataSource };