remult 0.17.3 → 0.18.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 (163) hide show
  1. package/SseSubscriptionServer.d.ts +23 -0
  2. package/SseSubscriptionServer.js +143 -0
  3. package/ably.d.ts +13 -0
  4. package/ably.js +59 -0
  5. package/esm/SseSubscriptionServer.d.ts +23 -0
  6. package/esm/SseSubscriptionServer.js +102 -0
  7. package/esm/ably.d.ts +13 -0
  8. package/esm/ably.js +28 -0
  9. package/esm/index.d.ts +7 -4
  10. package/esm/index.js +4 -2
  11. package/esm/live-query/data-provider-live-query-storage.d.ts +23 -0
  12. package/esm/live-query/data-provider-live-query-storage.js +78 -0
  13. package/esm/myLog.d.ts +1 -0
  14. package/esm/myLog.js +5 -0
  15. package/esm/postgres/postgres-data-provider.d.ts +4 -2
  16. package/esm/postgres/postgres-data-provider.js +18 -6
  17. package/esm/postgres/schema-builder.d.ts +2 -1
  18. package/esm/postgres/schema-builder.js +49 -29
  19. package/esm/remult-knex/index.d.ts +10 -32
  20. package/esm/remult-knex/index.js +75 -51
  21. package/esm/remult-mongo.d.ts +9 -2
  22. package/esm/remult-mongo.js +24 -8
  23. package/esm/remult-next.d.ts +11 -0
  24. package/esm/remult-next.js +27 -0
  25. package/esm/server/core.d.ts +2 -0
  26. package/esm/server/core.js +2 -0
  27. package/esm/server/expressBridge.d.ts +19 -7
  28. package/esm/server/expressBridge.js +135 -31
  29. package/esm/server/index.d.ts +2 -1
  30. package/esm/server/index.js +2 -1
  31. package/esm/server/initDataProvider.d.ts +2 -0
  32. package/esm/server/initDataProvider.js +14 -0
  33. package/esm/src/buildRestDataProvider.d.ts +31 -0
  34. package/esm/src/buildRestDataProvider.js +110 -0
  35. package/esm/src/column-interfaces.d.ts +44 -8
  36. package/esm/src/column.d.ts +3 -3
  37. package/esm/src/context.d.ts +39 -36
  38. package/esm/src/context.js +87 -117
  39. package/esm/src/data-api.d.ts +9 -3
  40. package/esm/src/data-api.js +130 -63
  41. package/esm/src/data-interfaces.d.ts +5 -1
  42. package/esm/src/data-providers/array-entity-data-provider.d.ts +1 -1
  43. package/esm/src/data-providers/array-entity-data-provider.js +2 -17
  44. package/esm/src/data-providers/rest-data-provider.d.ts +4 -3
  45. package/esm/src/data-providers/rest-data-provider.js +64 -23
  46. package/esm/src/data-providers/sql-database.d.ts +7 -3
  47. package/esm/src/data-providers/sql-database.js +60 -17
  48. package/esm/src/data-providers/web-sql-data-provider.d.ts +3 -0
  49. package/esm/src/data-providers/web-sql-data-provider.js +23 -9
  50. package/esm/src/entity.d.ts +2 -2
  51. package/esm/src/filter/filter-consumer-bridge-to-sql-request.d.ts +16 -16
  52. package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +29 -21
  53. package/esm/src/filter/filter-interfaces.d.ts +5 -5
  54. package/esm/src/filter/filter-interfaces.js +31 -26
  55. package/esm/src/live-query/LiveQueryClient.d.ts +1 -0
  56. package/esm/src/live-query/LiveQueryClient.js +184 -0
  57. package/esm/src/live-query/SseSubscriptionClient.d.ts +5 -0
  58. package/esm/src/live-query/SseSubscriptionClient.js +86 -0
  59. package/esm/src/live-query/SubscriptionChannel.d.ts +41 -0
  60. package/esm/src/live-query/SubscriptionChannel.js +121 -0
  61. package/esm/src/live-query/SubscriptionServer.d.ts +38 -0
  62. package/esm/src/live-query/SubscriptionServer.js +108 -0
  63. package/esm/src/remult-proxy.d.ts +1 -1
  64. package/esm/src/remult-proxy.js +52 -7
  65. package/esm/src/remult3/RepositoryImplementation.d.ts +14 -5
  66. package/esm/src/remult3/RepositoryImplementation.js +124 -44
  67. package/esm/src/remult3/getId.d.ts +2 -0
  68. package/esm/src/remult3/getId.js +7 -0
  69. package/esm/src/remult3/remult3.d.ts +67 -10
  70. package/esm/src/remult3/remult3.js +1 -0
  71. package/esm/src/server-action.d.ts +5 -1
  72. package/esm/src/server-action.js +11 -12
  73. package/esm/src/shared-tests/db-tests-setup.d.ts +12 -5
  74. package/esm/src/shared-tests/db-tests-setup.js +14 -6
  75. package/esm/src/shared-tests/db-tests.db-tests.js +71 -10
  76. package/esm/src/sort.d.ts +1 -0
  77. package/esm/src/sort.js +18 -0
  78. package/esm/src/sql-command.d.ts +5 -2
  79. package/esm/src/tests/entityForCustomFilter.d.ts +6 -6
  80. package/esm/src/tests/entityForCustomFilter.js +20 -21
  81. package/esm/src/tests/frontend-database-tests-setup.spec.js +3 -4
  82. package/esm/src/tests/testHelper.spec.d.ts +3 -1
  83. package/esm/src/tests/testHelper.spec.js +63 -60
  84. package/esm/src/valueConverters.js +15 -7
  85. package/index.d.ts +7 -4
  86. package/index.js +7 -3
  87. package/live-query/data-provider-live-query-storage.d.ts +23 -0
  88. package/live-query/data-provider-live-query-storage.js +236 -0
  89. package/myLog.d.ts +1 -0
  90. package/myLog.js +20 -0
  91. package/package.json +18 -1
  92. package/postgres/postgres-data-provider.d.ts +4 -2
  93. package/postgres/postgres-data-provider.js +54 -39
  94. package/postgres/schema-builder.d.ts +2 -1
  95. package/postgres/schema-builder.js +118 -70
  96. package/remult-express.js +1 -1
  97. package/remult-knex/index.d.ts +10 -32
  98. package/remult-knex/index.js +134 -87
  99. package/remult-mongo.d.ts +9 -2
  100. package/remult-mongo.js +39 -7
  101. package/remult-next.d.ts +11 -0
  102. package/remult-next.js +73 -0
  103. package/server/JsonEntityFileStorage.js +2 -2
  104. package/server/core.d.ts +2 -0
  105. package/server/core.js +5 -1
  106. package/server/expressBridge.d.ts +19 -7
  107. package/server/expressBridge.js +283 -69
  108. package/server/index.d.ts +2 -1
  109. package/server/index.js +3 -1
  110. package/server/initDataProvider.d.ts +2 -0
  111. package/server/initDataProvider.js +26 -0
  112. package/src/buildRestDataProvider.d.ts +31 -0
  113. package/src/buildRestDataProvider.js +162 -0
  114. package/src/column-interfaces.d.ts +44 -8
  115. package/src/column.d.ts +3 -3
  116. package/src/context.d.ts +39 -36
  117. package/src/context.js +171 -166
  118. package/src/data-api.d.ts +9 -3
  119. package/src/data-api.js +233 -88
  120. package/src/data-interfaces.d.ts +5 -1
  121. package/src/data-providers/array-entity-data-provider.d.ts +1 -1
  122. package/src/data-providers/array-entity-data-provider.js +2 -17
  123. package/src/data-providers/rest-data-provider.d.ts +4 -3
  124. package/src/data-providers/rest-data-provider.js +105 -39
  125. package/src/data-providers/sql-database.d.ts +7 -3
  126. package/src/data-providers/sql-database.js +89 -16
  127. package/src/data-providers/web-sql-data-provider.d.ts +3 -0
  128. package/src/data-providers/web-sql-data-provider.js +56 -11
  129. package/src/entity.d.ts +2 -2
  130. package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +16 -16
  131. package/src/filter/filter-consumer-bridge-to-sql-request.js +59 -50
  132. package/src/filter/filter-interfaces.d.ts +5 -5
  133. package/src/filter/filter-interfaces.js +31 -26
  134. package/src/live-query/LiveQueryClient.d.ts +1 -0
  135. package/src/live-query/LiveQueryClient.js +283 -0
  136. package/src/live-query/SseSubscriptionClient.d.ts +5 -0
  137. package/src/live-query/SseSubscriptionClient.js +150 -0
  138. package/src/live-query/SubscriptionChannel.d.ts +41 -0
  139. package/src/live-query/SubscriptionChannel.js +209 -0
  140. package/src/live-query/SubscriptionServer.d.ts +38 -0
  141. package/src/live-query/SubscriptionServer.js +258 -0
  142. package/src/remult-proxy.d.ts +1 -1
  143. package/src/remult-proxy.js +153 -8
  144. package/src/remult3/RepositoryImplementation.d.ts +14 -5
  145. package/src/remult3/RepositoryImplementation.js +200 -85
  146. package/src/remult3/getId.d.ts +2 -0
  147. package/src/remult3/getId.js +11 -0
  148. package/src/remult3/remult3.d.ts +67 -10
  149. package/src/remult3/remult3.js +1 -0
  150. package/src/server-action.d.ts +5 -1
  151. package/src/server-action.js +11 -11
  152. package/src/shared-tests/db-tests-setup.d.ts +12 -5
  153. package/src/shared-tests/db-tests-setup.js +17 -8
  154. package/src/shared-tests/db-tests.db-tests.js +140 -8
  155. package/src/sort.d.ts +1 -0
  156. package/src/sort.js +18 -0
  157. package/src/sql-command.d.ts +5 -2
  158. package/src/tests/entityForCustomFilter.d.ts +6 -6
  159. package/src/tests/entityForCustomFilter.js +30 -31
  160. package/src/tests/frontend-database-tests-setup.spec.js +5 -6
  161. package/src/tests/testHelper.spec.d.ts +3 -1
  162. package/src/tests/testHelper.spec.js +104 -100
  163. package/src/valueConverters.js +15 -7
@@ -1,43 +1,20 @@
1
- import { DataProvider, RestDataProviderHttpProvider } from "./data-interfaces";
2
- import { RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider';
1
+ import { DataProvider } from "./data-interfaces";
3
2
  import { EntityMetadata, EntityRef, FindOptions, Repository } from "./remult3";
4
3
  import { ClassType } from "../classType";
5
- export interface ExternalHttpProvider {
6
- post(url: string, data: any): Promise<any> | {
7
- toPromise(): Promise<any>;
8
- };
9
- delete(url: string): Promise<void> | {
10
- toPromise(): Promise<void>;
11
- };
12
- put(url: string, data: any): Promise<any> | {
13
- toPromise(): Promise<any>;
14
- };
15
- get(url: string): Promise<any> | {
16
- toPromise(): Promise<any>;
17
- };
18
- }
19
- export declare class HttpProviderBridgeToRestDataProviderHttpProvider implements RestDataProviderHttpProvider {
20
- private http;
21
- constructor(http: ExternalHttpProvider);
22
- post(url: string, data: any): Promise<any>;
23
- delete(url: string): Promise<void>;
24
- put(url: string, data: any): Promise<any>;
25
- get(url: string): Promise<any>;
26
- }
27
- export declare function retry<T>(what: () => Promise<T>): Promise<T>;
28
- export declare function toPromise<T>(p: Promise<T> | {
29
- toPromise(): Promise<T>;
30
- }): Promise<any>;
31
- export declare function processHttpException(ex: any): Promise<any>;
4
+ import type { SubscriptionServer } from "./live-query/SubscriptionServer";
5
+ import { ExternalHttpProvider } from "./buildRestDataProvider";
6
+ import { SubscriptionClient } from "./live-query/SubscriptionChannel";
32
7
  export declare function isBackend(): boolean;
33
8
  export declare class Remult {
34
9
  /**Return's a `Repository` of the specific entity type
35
10
  * @example
36
11
  * const taskRepo = remult.repo(Task);
37
12
  * @see [Repository](https://remult.dev/docs/ref_repository.html)
38
- *
13
+ * @param entity - the entity to use
14
+ * @param dataProvider - an optional alternative data provider to use. Useful for writing to offline storage or an alternative data provider
39
15
  */
40
16
  repo<T>(entity: ClassType<T>, dataProvider?: DataProvider): Repository<T>;
17
+ /** Returns the current user's info */
41
18
  user?: UserInfo;
42
19
  /** Checks if a user was authenticated */
43
20
  authenticated(): boolean;
@@ -53,6 +30,8 @@ export declare class Remult {
53
30
  * [Allowed](https://remult.dev/docs/allowed.html)
54
31
  */
55
32
  isAllowedForInstance(instance: any, allowed?: AllowedForInstance<any>): boolean;
33
+ /** The current data provider */
34
+ dataProvider: DataProvider;
56
35
  /** Creates a new instance of the `remult` object.
57
36
  *
58
37
  * Can receive either an HttpProvider or a DataProvider as a parameter - which will be used to fetch data from.
@@ -62,23 +41,42 @@ export declare class Remult {
62
41
  constructor(http: ExternalHttpProvider | typeof fetch | ApiClient);
63
42
  constructor(p: DataProvider);
64
43
  constructor();
44
+ subscriptionServer?: SubscriptionServer;
45
+ /** Used to call a `backendMethod` using a specific `remult` object
46
+ * @example
47
+ * await remult.call(TasksController.setAll, undefined, true);
48
+ * @param backendMethod - the backend method to call
49
+ * @param classInstance - the class instance of the backend method, for static backend methods use undefined
50
+ * @param args - the arguments to send to the backend method
51
+ */
65
52
  call<T extends ((...args: any[]) => Promise<any>)>(backendMethod: T, classInstance?: any, ...args: GetArguments<T>): ReturnType<T>;
66
- /** The current data provider */
67
- dataProvider: DataProvider;
68
53
  /** A helper callback that can be used to debug and trace all find operations. Useful in debugging scenarios */
69
54
  static onFind: (metadata: EntityMetadata, options: FindOptions<any>) => void;
70
55
  clearAllCache(): any;
71
56
  /** A helper callback that is called whenever an entity is created. */
72
57
  static entityRefInit?: (ref: EntityRef<any>, row: any) => void;
58
+ /** context information that can be used to store custom information that will be disposed as part of the `remult` object */
73
59
  readonly context: RemultContext;
60
+ /** The api client that will be used by `remult` to perform calls to the `api` */
74
61
  apiClient: ApiClient;
75
62
  }
76
63
  export declare type GetArguments<T> = T extends (...args: infer FirstArgument) => any ? FirstArgument : never;
77
64
  export interface RemultContext {
78
65
  }
79
66
  export interface ApiClient {
67
+ /** The http client to use when making api calls.
68
+ * @example
69
+ * remult.apiClient.httpClient = axios;
70
+ * @example
71
+ * remult.apiClient.httpClient = httpClient;//angular http client
72
+ * @example
73
+ * remult.apiClient.httpClient = fetch; //this is the default
74
+ */
80
75
  httpClient?: ExternalHttpProvider | typeof fetch;
76
+ /** The base url to for making api calls */
81
77
  url?: string;
78
+ subscriptionClient?: SubscriptionClient;
79
+ wrapMessageHandling?: (x: VoidFunction) => void;
82
80
  }
83
81
  export declare const allEntities: ClassType<any>[];
84
82
  export interface ControllerOptions {
@@ -88,18 +86,17 @@ export declare const classHelpers: Map<any, ClassHelper>;
88
86
  export declare class ClassHelper {
89
87
  classes: Map<any, ControllerOptions>;
90
88
  }
91
- export declare function buildRestDataProvider(provider: ExternalHttpProvider | typeof fetch): RestDataProviderHttpProvider | RestDataProviderHttpProviderUsingFetch;
92
89
  export declare function setControllerSettings(target: any, options: ControllerOptions): void;
93
90
  export interface UserInfo {
94
91
  id: string;
95
92
  name?: string;
96
93
  roles?: string[];
97
94
  }
98
- export declare type Allowed = boolean | string | string[] | ((c: Remult) => boolean);
99
- export declare type AllowedForInstance<T> = boolean | string | string[] | ((c: Remult, entity?: T) => boolean);
95
+ export declare type Allowed = boolean | string | string[] | ((c?: Remult) => boolean);
96
+ export declare type AllowedForInstance<T> = boolean | string | string[] | ((entity?: T, c?: Remult) => boolean);
100
97
  export declare class Allow {
101
98
  static everyone: () => boolean;
102
- static authenticated: (remult: Remult) => boolean;
99
+ static authenticated: (...args: any[]) => any;
103
100
  }
104
101
  export declare const queryConfig: {
105
102
  defaultPageSize: number;
@@ -113,3 +110,9 @@ export declare class EventSource {
113
110
  fire(): Promise<void>;
114
111
  dispatcher: EventDispatcher;
115
112
  }
113
+ export interface itemChange {
114
+ id: any;
115
+ oldId: any;
116
+ deleted: boolean;
117
+ }
118
+ export declare function doTransaction(remult: Remult, what: () => Promise<void>): Promise<void>;
@@ -1,105 +1,31 @@
1
1
  import { actionInfo, serverActionField } from './server-action';
2
- import { RestDataProvider, RestDataProviderHttpProviderUsingFetch } from './data-providers/rest-data-provider';
2
+ import { RestDataProvider } from './data-providers/rest-data-provider';
3
3
  import { RepositoryImplementation } from "./remult3/RepositoryImplementation";
4
- export class HttpProviderBridgeToRestDataProviderHttpProvider {
5
- constructor(http) {
6
- this.http = http;
7
- }
8
- async post(url, data) {
9
- return await retry(() => toPromise(this.http.post(url, data)));
10
- }
11
- delete(url) {
12
- return toPromise(this.http.delete(url));
13
- }
14
- put(url, data) {
15
- return toPromise(this.http.put(url, data));
16
- }
17
- async get(url) {
18
- return await retry(() => toPromise(this.http.get(url)));
19
- }
20
- }
21
- export async function retry(what) {
22
- while (true) {
23
- try {
24
- return await what();
25
- }
26
- catch (err) {
27
- if (err.message?.startsWith("Error occurred while trying to proxy") ||
28
- err.message?.startsWith("Error occured while trying to proxy") ||
29
- err.message?.includes("http proxy error") ||
30
- err.message?.startsWith("Gateway Timeout")) {
31
- await new Promise((res, req) => {
32
- setTimeout(() => {
33
- res({});
34
- }, 250);
35
- });
36
- continue;
37
- }
38
- throw err;
39
- }
40
- }
41
- }
42
- export function toPromise(p) {
43
- let r;
44
- if (p["toPromise"] !== undefined) {
45
- r = p["toPromise"]();
46
- }
47
- //@ts-ignore
48
- else
49
- r = p;
50
- return r.then((x) => {
51
- if (x && (x.status == 200 || x.status == 201) && x.headers && x.request && x.data) //for axios
52
- return x.data;
53
- return x;
54
- }).catch(async (ex) => {
55
- throw await processHttpException(ex);
56
- });
57
- }
58
- export async function processHttpException(ex) {
59
- let z = await ex;
60
- var error;
61
- if (z.error)
62
- error = z.error;
63
- else if (z.isAxiosError) {
64
- if (typeof z.response?.data === "string")
65
- error = z.response.data;
66
- else
67
- error = z?.response?.data;
68
- }
69
- if (!error)
70
- error = z.message;
71
- if (z.status == 0 && z.error.isTrusted)
72
- error = "Network Error";
73
- if (typeof error === 'string') {
74
- error = {
75
- message: error,
76
- };
77
- }
78
- if (z.modelState)
79
- error.modelState = z.modelState;
80
- let httpStatusCode = z.status;
81
- if (httpStatusCode === undefined)
82
- httpStatusCode = z.response?.status;
83
- if (httpStatusCode !== undefined && httpStatusCode !== null) {
84
- error.httpStatusCode = httpStatusCode;
85
- }
86
- var result = Object.assign(error, {
87
- // exception: ex disabled for now because JSON.stringify crashed with this
88
- });
89
- return result;
90
- }
4
+ import { LiveQueryClient } from "./live-query/LiveQueryClient";
5
+ import { SseSubscriptionClient } from "./live-query/SseSubscriptionClient";
6
+ import { RemultProxy } from "./remult-proxy";
7
+ import { buildRestDataProvider, isExternalHttpProvider } from "./buildRestDataProvider";
91
8
  export function isBackend() {
92
9
  return actionInfo.runningOnServer;
93
10
  }
94
11
  export class Remult {
95
12
  constructor(provider) {
96
- /* @internal */
97
- this.repCache = new Map();
98
13
  /** The current data provider */
99
14
  this.dataProvider = new RestDataProvider(() => this.apiClient);
15
+ /* @internal */
16
+ this.repCache = new Map();
17
+ /* @internal*/
18
+ this.liveQueryPublisher = {
19
+ itemChanged: async () => { }
20
+ };
21
+ /* @internal*/
22
+ this.liveQuerySubscriber = new LiveQueryClient(() => this.apiClient, () => this.user?.id);
23
+ /** context information that can be used to store custom information that will be disposed as part of the `remult` object */
100
24
  this.context = {};
25
+ /** The api client that will be used by `remult` to perform calls to the `api` */
101
26
  this.apiClient = {
102
- url: '/api'
27
+ url: '/api',
28
+ subscriptionClient: new SseSubscriptionClient()
103
29
  };
104
30
  if (provider && provider.getEntityDataProvider) {
105
31
  this.dataProvider = provider;
@@ -116,13 +42,18 @@ export class Remult {
116
42
  this.apiClient.httpClient = apiClient.httpClient;
117
43
  if (apiClient.url)
118
44
  this.apiClient.url = apiClient.url;
45
+ if (apiClient.subscriptionClient)
46
+ this.apiClient.subscriptionClient = apiClient.subscriptionClient;
47
+ if (apiClient.wrapMessageHandling)
48
+ this.apiClient.wrapMessageHandling = apiClient.wrapMessageHandling;
119
49
  }
120
50
  }
121
51
  /**Return's a `Repository` of the specific entity type
122
52
  * @example
123
53
  * const taskRepo = remult.repo(Task);
124
54
  * @see [Repository](https://remult.dev/docs/ref_repository.html)
125
- *
55
+ * @param entity - the entity to use
56
+ * @param dataProvider - an optional alternative data provider to use. Useful for writing to offline storage or an alternative data provider
126
57
  */
127
58
  repo(entity, dataProvider) {
128
59
  if (dataProvider === undefined)
@@ -136,7 +67,6 @@ export class Remult {
136
67
  }
137
68
  return r;
138
69
  }
139
- /* delete me */
140
70
  /** Checks if a user was authenticated */
141
71
  authenticated() {
142
72
  return this.user?.id !== undefined;
@@ -182,11 +112,19 @@ export class Remult {
182
112
  }
183
113
  }
184
114
  else if (typeof (allowed) === "function") {
185
- return allowed(this, instance);
115
+ return allowed(instance, this);
186
116
  }
187
117
  else
188
118
  return this.isAllowed(allowed);
189
119
  }
120
+ //@ts-ignore // type error of typescript regarding args that doesn't appear in my normal development
121
+ /** Used to call a `backendMethod` using a specific `remult` object
122
+ * @example
123
+ * await remult.call(TasksController.setAll, undefined, true);
124
+ * @param backendMethod - the backend method to call
125
+ * @param classInstance - the class instance of the backend method, for static backend methods use undefined
126
+ * @param args - the arguments to send to the backend method
127
+ */
190
128
  call(backendMethod, classInstance, ...args) {
191
129
  const z = (backendMethod[serverActionField]);
192
130
  if (!z.doWork)
@@ -200,6 +138,7 @@ export class Remult {
200
138
  }
201
139
  /** A helper callback that can be used to debug and trace all find operations. Useful in debugging scenarios */
202
140
  Remult.onFind = (metadata, options) => { };
141
+ RemultProxy.defaultRemult = new Remult();
203
142
  ;
204
143
  export const allEntities = [];
205
144
  export const classHelpers = new Map();
@@ -208,28 +147,6 @@ export class ClassHelper {
208
147
  this.classes = new Map();
209
148
  }
210
149
  }
211
- function isExternalHttpProvider(item) {
212
- let http = item;
213
- if (http && http.get && http.put && http.post && http.delete)
214
- return true;
215
- return false;
216
- }
217
- export function buildRestDataProvider(provider) {
218
- if (!provider)
219
- return new RestDataProviderHttpProviderUsingFetch();
220
- let httpDataProvider;
221
- if (!httpDataProvider) {
222
- if (isExternalHttpProvider(provider)) {
223
- httpDataProvider = new HttpProviderBridgeToRestDataProviderHttpProvider(provider);
224
- }
225
- }
226
- if (!httpDataProvider) {
227
- if (typeof provider === "function") {
228
- httpDataProvider = new RestDataProviderHttpProviderUsingFetch(provider);
229
- }
230
- }
231
- return httpDataProvider;
232
- }
233
150
  export function setControllerSettings(target, options) {
234
151
  let r = target;
235
152
  while (true) {
@@ -246,7 +163,16 @@ export function setControllerSettings(target, options) {
246
163
  export class Allow {
247
164
  }
248
165
  Allow.everyone = () => true;
249
- Allow.authenticated = (remult) => remult.authenticated();
166
+ Allow.authenticated = (...args) => {
167
+ if (args.length > 1) {
168
+ return args[1].authenticated();
169
+ }
170
+ else if (args.length == 1) {
171
+ if (args[0].authenticated)
172
+ return args[0].authenticated();
173
+ }
174
+ return RemultProxy.defaultRemult.authenticated();
175
+ };
250
176
  export const queryConfig = {
251
177
  defaultPageSize: 200
252
178
  };
@@ -269,3 +195,47 @@ export class EventSource {
269
195
  }
270
196
  }
271
197
  }
198
+ export async function doTransaction(remult, what) {
199
+ const trans = new transactionLiveQueryPublisher(remult.liveQueryPublisher);
200
+ let ok = true;
201
+ const result = await remult.dataProvider.transaction(async (ds) => {
202
+ remult.dataProvider = (ds);
203
+ remult.liveQueryPublisher = trans;
204
+ await what();
205
+ ok = true;
206
+ });
207
+ if (ok)
208
+ await trans.flush();
209
+ }
210
+ class transactionLiveQueryPublisher {
211
+ constructor(orig) {
212
+ this.orig = orig;
213
+ this.transactionItems = new Map();
214
+ }
215
+ async itemChanged(entityKey, changes) {
216
+ let items = this.transactionItems.get(entityKey);
217
+ if (!items) {
218
+ this.transactionItems.set(entityKey, items = []);
219
+ }
220
+ for (const c of changes) {
221
+ if (c.oldId !== undefined) {
222
+ const item = items.find(y => y.id === c.oldId);
223
+ if (item !== undefined) {
224
+ if (c.deleted)
225
+ item.deleted = true;
226
+ if (c.id != item.id)
227
+ item.id = c.id;
228
+ }
229
+ else
230
+ items.push(c);
231
+ }
232
+ else
233
+ items.push(c);
234
+ }
235
+ }
236
+ async flush() {
237
+ for (const key of this.transactionItems.keys()) {
238
+ await this.orig.itemChanged(key, this.transactionItems.get(key));
239
+ }
240
+ }
241
+ }
@@ -1,16 +1,21 @@
1
1
  import { Remult } from './context';
2
- import { Repository } from './remult3';
2
+ import { FindOptions, Repository } from './remult3';
3
3
  import { ErrorInfo } from './data-interfaces';
4
4
  export declare class DataApi<T = any> {
5
5
  private repository;
6
6
  private remult;
7
7
  constructor(repository: Repository<T>, remult: Remult);
8
- httpGet(res: DataApiResponse, req: DataApiRequest): Promise<void>;
9
- httpPost(res: DataApiResponse, req: DataApiRequest, body: any): Promise<void>;
8
+ httpGet(res: DataApiResponse, req: DataApiRequest, serializeRequest: () => any): Promise<void>;
9
+ httpPost(res: DataApiResponse, req: DataApiRequest, body: any, serializeRequest: () => any): Promise<void>;
10
10
  static defaultGetLimit: number;
11
11
  get(response: DataApiResponse, id: any): Promise<void>;
12
12
  count(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
13
+ getArrayImpl(response: DataApiResponse, request: DataApiRequest, filterBody: any): Promise<{
14
+ r: any[];
15
+ findOptions: FindOptions<T>;
16
+ }>;
13
17
  getArray(response: DataApiResponse, request: DataApiRequest, filterBody?: any): Promise<void>;
18
+ liveQuery(response: DataApiResponse, request: DataApiRequest, filterBody: any, serializeRequest: () => any, queryChannel: string): Promise<void>;
14
19
  private buildWhere;
15
20
  private doOnId;
16
21
  put(response: DataApiResponse, id: any, body: any): Promise<void>;
@@ -31,3 +36,4 @@ export interface DataApiRequest {
31
36
  }
32
37
  export declare function determineSort(sortUrlParm: string, dirUrlParam: string): any;
33
38
  export declare function serializeError(data: ErrorInfo): ErrorInfo<any>;
39
+ export declare function getLiveQueryChannel(queryId: string, userId: string): string;