remult 0.13.17 → 0.13.20

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/graphql.js CHANGED
@@ -98,15 +98,15 @@ function remultGraphql(api) {
98
98
  root[key] = function (_a, req) {
99
99
  var options = _a.options, filter = _a.filter;
100
100
  return tslib_1.__awaiter(_this, void 0, void 0, function () {
101
- var remult, repo, dapi, result, err;
101
+ var remult, repo, dApi, result, err;
102
102
  return tslib_1.__generator(this, function (_b) {
103
103
  switch (_b.label) {
104
104
  case 0: return [4 /*yield*/, api.getRemult(req)];
105
105
  case 1:
106
106
  remult = _b.sent();
107
107
  repo = remult.repo(e);
108
- dapi = new data_api_1.DataApi(repo, remult);
109
- return [4 /*yield*/, dapi.getArray({
108
+ dApi = new data_api_1.DataApi(repo, remult);
109
+ return [4 /*yield*/, dApi.getArray({
110
110
  success: function (x) { return result = x; },
111
111
  created: undefined,
112
112
  deleted: undefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "remult",
3
- "version": "0.13.17",
3
+ "version": "0.13.20",
4
4
  "description": "remult core lib",
5
5
  "homepage": "https://remult.dev/",
6
6
  "repository": {
@@ -19,7 +19,7 @@ export declare function remultExpress(options?: {
19
19
  logApiEndPoints?: boolean;
20
20
  defaultGetLimit?: number;
21
21
  entities?: ClassType<any>[];
22
- controllers?: [];
22
+ controllers?: ClassType<any>[];
23
23
  }): RemultExpressBridge;
24
24
  export interface RemultExpressBridge extends express.RequestHandler {
25
25
  getRemult(req: express.Request): Promise<Remult>;
@@ -453,6 +453,8 @@ var SiteArea = /** @class */ (function () {
453
453
  _b.apply(_a, [_c.sent()]);
454
454
  if (req) {
455
455
  user = req['user'];
456
+ if (!user)
457
+ user = req['auth'];
456
458
  if (user)
457
459
  remult.setUser(user);
458
460
  }
@@ -176,7 +176,18 @@ db_tests_setup_1.testAll("transactions", function (_a) {
176
176
  });
177
177
  });
178
178
  var client = new mongodb_1.MongoClient("mongodb://localhost:27017/local");
179
- var mongoDbPromise = client.connect().then(function (c) { return c.db("test"); });
179
+ var done;
180
+ var mongoDbPromise = client.connect().then(function (c) {
181
+ done = c;
182
+ return c.db("test");
183
+ });
184
+ afterAll(function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
185
+ return tslib_1.__generator(this, function (_a) {
186
+ if (done)
187
+ done.close();
188
+ return [2 /*return*/];
189
+ });
190
+ }); });
180
191
  function testMongo(key, what, focus) {
181
192
  var _this = this;
182
193
  if (focus === void 0) { focus = false; }
@@ -2,24 +2,65 @@ import { ClassType } from '../classType';
2
2
  import { Allowed, AllowedForInstance } from './context';
3
3
  import { EntityMetadata, FieldRef } from './remult3';
4
4
  export interface FieldOptions<entityType = any, valueType = any> {
5
- key?: string;
6
- target?: ClassType<entityType>;
7
- valueType?: any;
5
+ /**A human readable name for the field */
8
6
  caption?: string;
9
- displayValue?: (entity: entityType, value: valueType) => string;
10
- defaultValue?: (entity: entityType) => valueType | Promise<valueType>;
7
+ /** If it can store null in the database */
8
+ allowNull?: boolean;
9
+ /** If this field data is included in the api.
10
+ * @see [allowed](http://remult.dev/docs/allowed.html)*/
11
+ includeInApi?: Allowed;
12
+ /** If this field data can be updated in the api.
13
+ * @see [allowed](http://remult.dev/docs/allowed.html)*/
14
+ allowApiUpdate?: AllowedForInstance<entityType>;
15
+ /** An arrow function that'll be used to perform validations on it
16
+ * @example
17
+ * .@Fields.string({
18
+ * validate: Validators.required
19
+ * })
20
+ * @example
21
+ * .@Fields.string<Task>({
22
+ * validate: task=>{
23
+ * if (task.title.length<3)
24
+ * throw "Too Short";
25
+ * }
26
+ * })
27
+ * @example
28
+ * .@Fields.string({
29
+ * validate: (_, fieldRef)=>{
30
+ * if (fieldRef.value.length<3)
31
+ * fieldRef.error = "Too Short";
32
+ * }
33
+ * })
34
+ */
11
35
  validate?: ((entity: entityType, col: FieldRef<entityType, valueType>) => (any | Promise<any>)) | ((entity: entityType, col: FieldRef<entityType, valueType>) => (any | Promise<any>))[];
36
+ /** Will be fired before this field is saved to the server/database */
12
37
  saving?: ((entity: entityType, col: FieldRef<entityType, valueType>) => (any | Promise<any>));
13
- inputType?: string;
14
- allowNull?: boolean;
38
+ /** An expression that will determine this fields value on the backend and be provided to the front end*/
39
+ serverExpression?: (entity: entityType) => valueType | Promise<valueType>;
40
+ /** The name of the column in the database that holds the data for this field. If no name is set, the key will be used instead. */
15
41
  dbName?: string;
42
+ /** Used or fields that are based on an sql expressions, instead of a physical table column */
16
43
  sqlExpression?: string | ((entity: EntityMetadata<entityType>) => string | Promise<string>);
17
- serverExpression?: (entity: entityType) => valueType | Promise<valueType>;
44
+ /** For fields that shouldn't be part of an update or insert statement */
18
45
  dbReadOnly?: boolean;
46
+ /** The value converter to be used when loading and saving this field */
19
47
  valueConverter?: ValueConverter<valueType>;
20
- includeInApi?: Allowed;
21
- allowApiUpdate?: AllowedForInstance<entityType>;
48
+ /** an arrow function that translates the value to a display value */
49
+ displayValue?: (entity: entityType, value: valueType) => string;
50
+ /** an arrow function that determines the default value of the field, when the entity is created using the `repo.create` method */
51
+ defaultValue?: (entity: entityType) => valueType | Promise<valueType>;
52
+ /** The html input type for this field */
53
+ inputType?: string;
54
+ /** Determines if the referenced entity will be loaded immediately or on demand.
55
+ * @see[Lazy loading of related entities](http://remult.dev/docs/lazy-loading-of-related-entities.html)
56
+ */
22
57
  lazy?: boolean;
58
+ /** The value type for this field */
59
+ valueType?: any;
60
+ /** The entity type to which this field belongs */
61
+ target?: ClassType<entityType>;
62
+ /** The key to be used for this field */
63
+ key?: string;
23
64
  }
24
65
  export interface FieldMetadata<valueType = any> {
25
66
  readonly key: string;
package/src/column.d.ts CHANGED
@@ -44,7 +44,6 @@ export declare class OneToMany<T> {
44
44
  private _currentPromise;
45
45
  get lazyItems(): T[];
46
46
  load(): Promise<T[]>;
47
- reload(): Promise<T[]>;
48
47
  private find;
49
48
  create(item?: Partial<T>): T;
50
49
  }
package/src/column.js CHANGED
@@ -131,8 +131,6 @@ var OneToMany = /** @class */ (function () {
131
131
  function OneToMany(provider, settings) {
132
132
  this.provider = provider;
133
133
  this.settings = settings;
134
- if (!this.settings)
135
- this.settings = {};
136
134
  }
137
135
  Object.defineProperty(OneToMany.prototype, "lazyItems", {
138
136
  get: function () {
@@ -159,14 +157,6 @@ var OneToMany = /** @class */ (function () {
159
157
  });
160
158
  });
161
159
  };
162
- OneToMany.prototype.reload = function () {
163
- return tslib_1.__awaiter(this, void 0, void 0, function () {
164
- return tslib_1.__generator(this, function (_a) {
165
- this._currentPromise = undefined;
166
- return [2 /*return*/, this.load()];
167
- });
168
- });
169
- };
170
160
  OneToMany.prototype.find = function () {
171
161
  return tslib_1.__awaiter(this, void 0, void 0, function () {
172
162
  return tslib_1.__generator(this, function (_a) {
@@ -178,8 +168,6 @@ var OneToMany = /** @class */ (function () {
178
168
  var r = this.provider.create();
179
169
  remult3_1.__updateEntityBasedOnWhere(this.provider.metadata, this.settings.where, r);
180
170
  assign_1.assign(r, item);
181
- if (this.settings.create)
182
- this.settings.create(r);
183
171
  return r;
184
172
  };
185
173
  return OneToMany;
package/src/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { DataProvider } from "./data-interfaces";
1
+ import { DataProvider, RestDataProviderHttpProvider } from "./data-interfaces";
2
2
  import { EntityMetadata, EntityRef, FindOptions, Repository } from "./remult3";
3
3
  import { ClassType } from "../classType";
4
4
  export interface HttpProvider {
@@ -15,33 +15,76 @@ export interface HttpProvider {
15
15
  toPromise(): Promise<any>;
16
16
  };
17
17
  }
18
+ export declare class HttpProviderBridgeToRestDataProviderHttpProvider implements RestDataProviderHttpProvider {
19
+ private http;
20
+ constructor(http: HttpProvider);
21
+ post(url: string, data: any): Promise<any>;
22
+ delete(url: string): Promise<void>;
23
+ put(url: string, data: any): Promise<any>;
24
+ get(url: string): Promise<any>;
25
+ }
26
+ export declare function retry<T>(what: () => Promise<T>): Promise<T>;
18
27
  export declare function toPromise<T>(p: Promise<T> | {
19
28
  toPromise(): Promise<T>;
20
29
  }): Promise<any>;
21
30
  export declare function processHttpException(ex: any): Promise<any>;
22
31
  export declare function isBackend(): boolean;
23
32
  export declare class Remult {
24
- static onFind: (metadata: EntityMetadata, options: FindOptions<any>) => void;
25
- clearAllCache(): any;
26
- static entityRefInit?: (ref: EntityRef<any>, row: any) => void;
27
- authenticated(): boolean;
28
- constructor(provider?: HttpProvider | DataProvider);
29
- _dataSource: DataProvider;
30
- setDataProvider(dataProvider: DataProvider): void;
31
- protected _user: UserInfo;
33
+ /**Return's a `Repository` of the specific entity type
34
+ * @example
35
+ * const taskRepo = remult.repo(Task);
36
+ * @see [Repository](https://remult.dev/docs/ref_repository.html)
37
+ *
38
+ */
39
+ repo<T>(entity: ClassType<T>, dataProvider?: DataProvider): Repository<T>;
40
+ /** Returns the current user's info */
32
41
  get user(): UserInfo;
33
- private _userChangeEvent;
34
- get userChange(): EventDispatcher;
42
+ /** Set's the current user info */
35
43
  setUser(info: UserInfo | {
36
44
  sub?: string;
37
45
  name?: string;
38
46
  permissions?: string[];
39
47
  }): Promise<void>;
40
- static apiBaseUrl: string;
41
- isAllowedForInstance(instance: any, x: AllowedForInstance<any>): boolean;
48
+ private _user;
49
+ private _userChangeEvent;
50
+ /** Checks if a user was authenticated */
51
+ authenticated(): boolean;
52
+ /** checks if the user has any of the roles specified in the parameters
53
+ * @example
54
+ * remult.isAllowed("admin")
55
+ * @see
56
+ * [Allowed](https://remult.dev/docs/allowed.html)
57
+ */
42
58
  isAllowed(roles: Allowed): boolean;
59
+ /** checks if the user matches the allowedForInstance callback
60
+ * @see
61
+ * [Allowed](https://remult.dev/docs/allowed.html)
62
+ */
63
+ isAllowedForInstance(instance: any, x: AllowedForInstance<any>): boolean;
64
+ /** returns a dispatcher object that fires once a user has changed*/
65
+ get userChange(): EventDispatcher;
43
66
  private repCache;
44
- repo<T>(entity: ClassType<T>, dataProvider?: DataProvider): Repository<T>;
67
+ /** Creates a new instance of the `remult` object.
68
+ *
69
+ * Can receive either an HttpProvider or a DataProvider as a parameter - which will be used to fetch data from.
70
+ *
71
+ * If no provider is specified, `fetch` will be used as an http provider
72
+ */
73
+ constructor(provider?: HttpProvider | DataProvider);
74
+ /** The api Base Url to be used in all remult calls. by default it's set to `/api`.
75
+ *
76
+ * Set this property in case you want to determine a non relative api url
77
+ */
78
+ static apiBaseUrl: string;
79
+ /** The current data provider */
80
+ _dataSource: DataProvider;
81
+ /** sets the current data provider */
82
+ setDataProvider(dataProvider: DataProvider): void;
83
+ /** A helper callback that can be used to debug and trace all find operations. Useful in debugging scenarios */
84
+ static onFind: (metadata: EntityMetadata, options: FindOptions<any>) => void;
85
+ clearAllCache(): any;
86
+ /** A helper callback that is called whenever an entity is created. */
87
+ static entityRefInit?: (ref: EntityRef<any>, row: any) => void;
45
88
  }
46
89
  export declare const allEntities: ClassType<any>[];
47
90
  export interface ControllerOptions {
package/src/context.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EventSource = exports.queryConfig = exports.Allow = exports.setControllerSettings = exports.MethodHelper = exports.ClassHelper = exports.classHelpers = exports.allEntities = exports.Remult = exports.isBackend = exports.processHttpException = exports.toPromise = void 0;
3
+ exports.EventSource = exports.queryConfig = exports.Allow = exports.setControllerSettings = exports.MethodHelper = exports.ClassHelper = exports.classHelpers = exports.allEntities = exports.Remult = exports.isBackend = exports.processHttpException = exports.toPromise = exports.retry = exports.HttpProviderBridgeToRestDataProviderHttpProvider = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var server_action_1 = require("./server-action");
6
6
  var rest_data_provider_1 = require("./data-providers/rest-data-provider");
@@ -39,29 +39,30 @@ var HttpProviderBridgeToRestDataProviderHttpProvider = /** @class */ (function (
39
39
  };
40
40
  return HttpProviderBridgeToRestDataProviderHttpProvider;
41
41
  }());
42
+ exports.HttpProviderBridgeToRestDataProviderHttpProvider = HttpProviderBridgeToRestDataProviderHttpProvider;
42
43
  function retry(what) {
43
- var _a, _b;
44
+ var _a, _b, _c;
44
45
  return tslib_1.__awaiter(this, void 0, void 0, function () {
45
46
  var err_1;
46
- return tslib_1.__generator(this, function (_c) {
47
- switch (_c.label) {
47
+ return tslib_1.__generator(this, function (_d) {
48
+ switch (_d.label) {
48
49
  case 0:
49
50
  if (!true) return [3 /*break*/, 7];
50
- _c.label = 1;
51
+ _d.label = 1;
51
52
  case 1:
52
- _c.trys.push([1, 3, , 6]);
53
+ _d.trys.push([1, 3, , 6]);
53
54
  return [4 /*yield*/, what()];
54
- case 2: return [2 /*return*/, _c.sent()];
55
+ case 2: return [2 /*return*/, _d.sent()];
55
56
  case 3:
56
- err_1 = _c.sent();
57
- if (!(((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.startsWith("Error occurred while trying to proxy")) || ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.startsWith("Error occured while trying to proxy")))) return [3 /*break*/, 5];
57
+ err_1 = _d.sent();
58
+ if (!(((_a = err_1.message) === null || _a === void 0 ? void 0 : _a.startsWith("Error occurred while trying to proxy")) || ((_b = err_1.message) === null || _b === void 0 ? void 0 : _b.startsWith("Error occured while trying to proxy")) || ((_c = err_1.message) === null || _c === void 0 ? void 0 : _c.startsWith("Gateway Timeout")))) return [3 /*break*/, 5];
58
59
  return [4 /*yield*/, new Promise(function (res, req) {
59
60
  setTimeout(function () {
60
61
  res({});
61
62
  }, 250);
62
63
  })];
63
64
  case 4:
64
- _c.sent();
65
+ _d.sent();
65
66
  return [3 /*break*/, 0];
66
67
  case 5: throw err_1;
67
68
  case 6: return [3 /*break*/, 0];
@@ -70,6 +71,7 @@ function retry(what) {
70
71
  });
71
72
  });
72
73
  }
74
+ exports.retry = retry;
73
75
  function toPromise(p) {
74
76
  var _this = this;
75
77
  var r;
@@ -139,6 +141,12 @@ function isBackend() {
139
141
  }
140
142
  exports.isBackend = isBackend;
141
143
  var Remult = /** @class */ (function () {
144
+ /** Creates a new instance of the `remult` object.
145
+ *
146
+ * Can receive either an HttpProvider or a DataProvider as a parameter - which will be used to fetch data from.
147
+ *
148
+ * If no provider is specified, `fetch` will be used as an http provider
149
+ */
142
150
  function Remult(provider) {
143
151
  this._userChangeEvent = new EventSource();
144
152
  this.repCache = new Map();
@@ -158,16 +166,26 @@ var Remult = /** @class */ (function () {
158
166
  if (!server_action_1.Action.provider)
159
167
  server_action_1.Action.provider = dataProvider;
160
168
  }
161
- Remult.prototype.clearAllCache = function () {
162
- this.repCache.clear();
163
- };
164
- Remult.prototype.authenticated = function () {
165
- return this.user.id !== undefined;
166
- };
167
- Remult.prototype.setDataProvider = function (dataProvider) {
168
- this._dataSource = dataProvider;
169
+ /**Return's a `Repository` of the specific entity type
170
+ * @example
171
+ * const taskRepo = remult.repo(Task);
172
+ * @see [Repository](https://remult.dev/docs/ref_repository.html)
173
+ *
174
+ */
175
+ Remult.prototype.repo = function (entity, dataProvider) {
176
+ if (dataProvider === undefined)
177
+ dataProvider = this._dataSource;
178
+ var dpCache = this.repCache.get(dataProvider);
179
+ if (!dpCache)
180
+ this.repCache.set(dataProvider, dpCache = new Map());
181
+ var r = dpCache.get(entity);
182
+ if (!r) {
183
+ dpCache.set(entity, r = new RepositoryImplementation_1.RepositoryImplementation(entity, this, dataProvider));
184
+ }
185
+ return r;
169
186
  };
170
187
  Object.defineProperty(Remult.prototype, "user", {
188
+ /** Returns the current user's info */
171
189
  get: function () {
172
190
  if (this._user === undefined) {
173
191
  return {
@@ -181,70 +199,44 @@ var Remult = /** @class */ (function () {
181
199
  enumerable: false,
182
200
  configurable: true
183
201
  });
184
- Object.defineProperty(Remult.prototype, "userChange", {
185
- get: function () {
186
- return this._userChangeEvent.dispatcher;
187
- },
188
- enumerable: false,
189
- configurable: true
190
- });
202
+ /** Set's the current user info */
191
203
  Remult.prototype.setUser = function (info) {
192
- var _a;
193
204
  return tslib_1.__awaiter(this, void 0, void 0, function () {
194
205
  var auth;
195
- return tslib_1.__generator(this, function (_b) {
196
- switch (_b.label) {
206
+ return tslib_1.__generator(this, function (_a) {
207
+ switch (_a.label) {
197
208
  case 0:
198
209
  this._user = info;
199
210
  auth = info;
200
211
  if (auth) {
201
212
  if (!this._user.id && auth.sub)
202
213
  this._user.id = auth.sub;
203
- if (!this._user.name && auth.name)
204
- this._user.name = auth.name;
205
214
  if (!this._user.roles && auth.permissions) {
206
215
  this._user.roles = auth.permissions;
207
216
  }
208
217
  }
209
- if (this._user && !((_a = this._user) === null || _a === void 0 ? void 0 : _a.roles))
218
+ if (this._user && !this._user.roles)
210
219
  this._user.roles = [];
211
220
  return [4 /*yield*/, this._userChangeEvent.fire()];
212
221
  case 1:
213
- _b.sent();
222
+ _a.sent();
214
223
  return [2 /*return*/];
215
224
  }
216
225
  });
217
226
  });
218
227
  };
219
- Remult.prototype.isAllowedForInstance = function (instance, x) {
220
- var e_1, _a;
221
- if (Array.isArray(x)) {
222
- {
223
- try {
224
- for (var x_1 = tslib_1.__values(x), x_1_1 = x_1.next(); !x_1_1.done; x_1_1 = x_1.next()) {
225
- var item = x_1_1.value;
226
- if (this.isAllowedForInstance(instance, item))
227
- return true;
228
- }
229
- }
230
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
231
- finally {
232
- try {
233
- if (x_1_1 && !x_1_1.done && (_a = x_1.return)) _a.call(x_1);
234
- }
235
- finally { if (e_1) throw e_1.error; }
236
- }
237
- }
238
- }
239
- else if (typeof (x) === "function") {
240
- return x(this, instance);
241
- }
242
- else
243
- return this.isAllowed(x);
228
+ /** Checks if a user was authenticated */
229
+ Remult.prototype.authenticated = function () {
230
+ return this.user.id !== undefined;
244
231
  };
232
+ /** checks if the user has any of the roles specified in the parameters
233
+ * @example
234
+ * remult.isAllowed("admin")
235
+ * @see
236
+ * [Allowed](https://remult.dev/docs/allowed.html)
237
+ */
245
238
  Remult.prototype.isAllowed = function (roles) {
246
- var e_2, _a;
247
- var _b, _c;
239
+ var e_1, _a;
248
240
  if (roles == undefined)
249
241
  return undefined;
250
242
  if (roles instanceof Array) {
@@ -256,12 +248,12 @@ var Remult = /** @class */ (function () {
256
248
  }
257
249
  }
258
250
  }
259
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
251
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
260
252
  finally {
261
253
  try {
262
254
  if (roles_1_1 && !roles_1_1.done && (_a = roles_1.return)) _a.call(roles_1);
263
255
  }
264
- finally { if (e_2) throw e_2.error; }
256
+ finally { if (e_1) throw e_1.error; }
265
257
  }
266
258
  return false;
267
259
  }
@@ -270,27 +262,63 @@ var Remult = /** @class */ (function () {
270
262
  }
271
263
  if (typeof roles === 'boolean')
272
264
  return roles;
273
- if (!this.user)
274
- return false;
275
265
  if (typeof roles === 'string')
276
- if (((_c = (_b = this.user) === null || _b === void 0 ? void 0 : _b.roles) === null || _c === void 0 ? void 0 : _c.indexOf(roles.toString())) >= 0)
266
+ if (this.user.roles.indexOf(roles.toString()) >= 0)
277
267
  return true;
278
268
  return false;
279
269
  };
280
- Remult.prototype.repo = function (entity, dataProvider) {
281
- if (dataProvider === undefined)
282
- dataProvider = this._dataSource;
283
- var dpCache = this.repCache.get(dataProvider);
284
- if (!dpCache)
285
- this.repCache.set(dataProvider, dpCache = new Map());
286
- var r = dpCache.get(entity);
287
- if (!r) {
288
- dpCache.set(entity, r = new RepositoryImplementation_1.RepositoryImplementation(entity, this, dataProvider));
270
+ /** checks if the user matches the allowedForInstance callback
271
+ * @see
272
+ * [Allowed](https://remult.dev/docs/allowed.html)
273
+ */
274
+ Remult.prototype.isAllowedForInstance = function (instance, x) {
275
+ var e_2, _a;
276
+ if (Array.isArray(x)) {
277
+ {
278
+ try {
279
+ for (var x_1 = tslib_1.__values(x), x_1_1 = x_1.next(); !x_1_1.done; x_1_1 = x_1.next()) {
280
+ var item = x_1_1.value;
281
+ if (this.isAllowedForInstance(instance, item))
282
+ return true;
283
+ }
284
+ }
285
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
286
+ finally {
287
+ try {
288
+ if (x_1_1 && !x_1_1.done && (_a = x_1.return)) _a.call(x_1);
289
+ }
290
+ finally { if (e_2) throw e_2.error; }
291
+ }
292
+ }
289
293
  }
290
- return r;
294
+ else if (typeof (x) === "function") {
295
+ return x(this, instance);
296
+ }
297
+ else
298
+ return this.isAllowed(x);
291
299
  };
292
- Remult.onFind = function (metadata, options) { };
300
+ Object.defineProperty(Remult.prototype, "userChange", {
301
+ /** returns a dispatcher object that fires once a user has changed*/
302
+ get: function () {
303
+ return this._userChangeEvent.dispatcher;
304
+ },
305
+ enumerable: false,
306
+ configurable: true
307
+ });
308
+ /** sets the current data provider */
309
+ Remult.prototype.setDataProvider = function (dataProvider) {
310
+ this._dataSource = dataProvider;
311
+ };
312
+ Remult.prototype.clearAllCache = function () {
313
+ this.repCache.clear();
314
+ };
315
+ /** The api Base Url to be used in all remult calls. by default it's set to `/api`.
316
+ *
317
+ * Set this property in case you want to determine a non relative api url
318
+ */
293
319
  Remult.apiBaseUrl = '/api';
320
+ /** A helper callback that can be used to debug and trace all find operations. Useful in debugging scenarios */
321
+ Remult.onFind = function (metadata, options) { };
294
322
  return Remult;
295
323
  }());
296
324
  exports.Remult = Remult;
@@ -24,11 +24,12 @@ export declare class RestEntityDataProvider implements EntityDataProvider {
24
24
  insert(data: any): Promise<any>;
25
25
  }
26
26
  export declare class RestDataProviderHttpProviderUsingFetch implements RestDataProviderHttpProvider {
27
- private addRequestHeader?;
28
- constructor(addRequestHeader?: (add: ((name: string, value: string) => void)) => void);
27
+ private fetch?;
28
+ constructor(fetch?: (input: RequestInfo, init?: RequestInit) => Promise<Response>);
29
29
  get(url: string): Promise<any>;
30
30
  put(url: string, data: any): Promise<any>;
31
31
  delete(url: string): Promise<any>;
32
32
  post(url: string, data: any): Promise<any>;
33
+ myFetch(url: string, init?: RequestInit): Promise<any>;
33
34
  }
34
35
  export declare function addFilterToUrlAndReturnTrueIfSuccessful(filter: any, url: UrlBuilder): boolean;