remult 0.22.7-exp.0 → 0.22.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.
Files changed (249) hide show
  1. package/SseSubscriptionServer.d.ts +25 -25
  2. package/SseSubscriptionServer.js +145 -145
  3. package/ably.d.ts +13 -13
  4. package/ably.js +59 -59
  5. package/assign.d.ts +1 -1
  6. package/assign.js +9 -9
  7. package/classType.d.ts +3 -3
  8. package/classType.js +2 -2
  9. package/esm/SseSubscriptionServer.d.ts +25 -25
  10. package/esm/SseSubscriptionServer.js +107 -104
  11. package/esm/ably.d.ts +13 -13
  12. package/esm/ably.js +30 -28
  13. package/esm/assign.d.ts +1 -1
  14. package/esm/assign.js +5 -5
  15. package/esm/classType.d.ts +3 -3
  16. package/esm/classType.js +1 -1
  17. package/esm/graphql.d.ts +14 -14
  18. package/esm/graphql.js +785 -785
  19. package/esm/index.d.ts +31 -31
  20. package/esm/index.js +25 -25
  21. package/esm/inputTypes.d.ts +9 -9
  22. package/esm/inputTypes.js +9 -9
  23. package/esm/live-query/data-provider-live-query-storage.d.ts +23 -23
  24. package/esm/live-query/data-provider-live-query-storage.js +91 -93
  25. package/esm/myLog.d.ts +1 -1
  26. package/esm/myLog.js +5 -5
  27. package/esm/postgres/index.d.ts +2 -2
  28. package/esm/postgres/index.js +2 -2
  29. package/esm/postgres/postgres-data-provider.d.ts +36 -36
  30. package/esm/postgres/postgres-data-provider.js +126 -122
  31. package/esm/postgres/schema-builder.d.ts +19 -19
  32. package/esm/postgres/schema-builder.js +197 -196
  33. package/esm/remult-express.d.ts +9 -9
  34. package/esm/remult-express.js +26 -25
  35. package/esm/remult-fastify.d.ts +6 -6
  36. package/esm/remult-fastify.js +68 -68
  37. package/esm/remult-fresh.d.ts +17 -17
  38. package/esm/remult-fresh.js +26 -26
  39. package/esm/remult-knex/index.d.ts +30 -30
  40. package/esm/remult-knex/index.js +466 -460
  41. package/esm/remult-mongo.d.ts +24 -24
  42. package/esm/remult-mongo.js +269 -262
  43. package/esm/remult-next.d.ts +25 -25
  44. package/esm/remult-next.js +114 -114
  45. package/esm/remult-sveltekit.d.ts +4 -4
  46. package/esm/remult-sveltekit.js +71 -71
  47. package/esm/server/JsonEntityFileStorage.d.ts +11 -11
  48. package/esm/server/JsonEntityFileStorage.js +27 -26
  49. package/esm/server/core.d.ts +4 -4
  50. package/esm/server/core.js +4 -4
  51. package/esm/server/expressBridge.d.ts +128 -128
  52. package/esm/server/expressBridge.js +988 -971
  53. package/esm/server/index.d.ts +6 -6
  54. package/esm/server/index.js +12 -12
  55. package/esm/server/initAsyncHooks.d.ts +1 -1
  56. package/esm/server/initAsyncHooks.js +9 -9
  57. package/esm/server/initDataProvider.d.ts +2 -2
  58. package/esm/server/initDataProvider.js +14 -14
  59. package/esm/src/CompoundIdField.d.ts +27 -27
  60. package/esm/src/CompoundIdField.js +54 -41
  61. package/esm/src/__EntityValueProvider.d.ts +11 -11
  62. package/esm/src/__EntityValueProvider.js +1 -1
  63. package/esm/src/__RowsOfDataForTesting.d.ts +3 -3
  64. package/esm/src/__RowsOfDataForTesting.js +1 -1
  65. package/esm/src/buildRestDataProvider.d.ts +31 -31
  66. package/esm/src/buildRestDataProvider.js +121 -120
  67. package/esm/src/column-interfaces.d.ts +160 -160
  68. package/esm/src/column-interfaces.js +7 -7
  69. package/esm/src/column.d.ts +31 -31
  70. package/esm/src/column.js +108 -101
  71. package/esm/src/context.d.ts +134 -134
  72. package/esm/src/context.js +287 -282
  73. package/esm/src/data-api.d.ts +38 -38
  74. package/esm/src/data-api.js +281 -279
  75. package/esm/src/data-interfaces.d.ts +41 -41
  76. package/esm/src/data-interfaces.js +12 -12
  77. package/esm/src/data-providers/array-entity-data-provider.d.ts +22 -22
  78. package/esm/src/data-providers/array-entity-data-provider.js +252 -249
  79. package/esm/src/data-providers/in-memory-database.d.ts +9 -9
  80. package/esm/src/data-providers/in-memory-database.js +16 -18
  81. package/esm/src/data-providers/json-data-provider.d.ts +12 -12
  82. package/esm/src/data-providers/json-data-provider.js +55 -52
  83. package/esm/src/data-providers/rest-data-provider.d.ts +39 -39
  84. package/esm/src/data-providers/rest-data-provider.js +272 -267
  85. package/esm/src/data-providers/sql-database.d.ts +33 -33
  86. package/esm/src/data-providers/sql-database.js +401 -394
  87. package/esm/src/data-providers/web-sql-data-provider.d.ts +21 -21
  88. package/esm/src/data-providers/web-sql-data-provider.js +145 -137
  89. package/esm/src/entity.d.ts +95 -95
  90. package/esm/src/entity.js +1 -1
  91. package/esm/src/filter/filter-consumer-bridge-to-sql-request.d.ts +50 -50
  92. package/esm/src/filter/filter-consumer-bridge-to-sql-request.js +165 -162
  93. package/esm/src/filter/filter-interfaces.d.ts +86 -86
  94. package/esm/src/filter/filter-interfaces.js +524 -515
  95. package/esm/src/live-query/LiveQueryClient.d.ts +1 -1
  96. package/esm/src/live-query/LiveQueryClient.js +196 -192
  97. package/esm/src/live-query/SseSubscriptionClient.d.ts +5 -5
  98. package/esm/src/live-query/SseSubscriptionClient.js +86 -86
  99. package/esm/src/live-query/SubscriptionChannel.d.ts +41 -41
  100. package/esm/src/live-query/SubscriptionChannel.js +126 -121
  101. package/esm/src/live-query/SubscriptionServer.d.ts +38 -38
  102. package/esm/src/live-query/SubscriptionServer.js +114 -112
  103. package/esm/src/remult-proxy.d.ts +2 -2
  104. package/esm/src/remult-proxy.js +177 -178
  105. package/esm/src/remult3/DecoratorReplacer.d.ts +10 -10
  106. package/esm/src/remult3/DecoratorReplacer.js +20 -20
  107. package/esm/src/remult3/RepositoryImplementation.d.ts +332 -332
  108. package/esm/src/remult3/RepositoryImplementation.js +2122 -2051
  109. package/esm/src/remult3/__updateEntityBasedOnWhere.d.ts +2 -2
  110. package/esm/src/remult3/__updateEntityBasedOnWhere.js +24 -24
  111. package/esm/src/remult3/entity.d.ts +28 -28
  112. package/esm/src/remult3/entity.js +70 -70
  113. package/esm/src/remult3/getEntityRef.d.ts +9 -9
  114. package/esm/src/remult3/getEntityRef.js +27 -27
  115. package/esm/src/remult3/remult3.d.ts +397 -397
  116. package/esm/src/remult3/remult3.js +1 -1
  117. package/esm/src/resultCompoundIdFilter.d.ts +3 -3
  118. package/esm/src/resultCompoundIdFilter.js +16 -16
  119. package/esm/src/server-action-info.d.ts +10 -10
  120. package/esm/src/server-action-info.js +12 -12
  121. package/esm/src/server-action.d.ts +79 -79
  122. package/esm/src/server-action.js +397 -387
  123. package/esm/src/sort.d.ts +16 -16
  124. package/esm/src/sort.js +105 -104
  125. package/esm/src/sql-command.d.ts +19 -19
  126. package/esm/src/sql-command.js +1 -1
  127. package/esm/src/validators.d.ts +14 -14
  128. package/esm/src/validators.js +36 -36
  129. package/esm/src/valueConverters.d.ts +13 -13
  130. package/esm/src/valueConverters.js +210 -210
  131. package/esm/urlBuilder.d.ts +6 -6
  132. package/esm/urlBuilder.js +20 -19
  133. package/graphql.d.ts +14 -14
  134. package/graphql.js +953 -953
  135. package/index.d.ts +31 -31
  136. package/index.js +67 -67
  137. package/inputTypes.d.ts +9 -9
  138. package/inputTypes.js +16 -16
  139. package/live-query/data-provider-live-query-storage.d.ts +23 -23
  140. package/live-query/data-provider-live-query-storage.js +263 -263
  141. package/myLog.d.ts +1 -1
  142. package/myLog.js +20 -20
  143. package/package.json +1 -1
  144. package/postgres/index.d.ts +2 -2
  145. package/postgres/index.js +5 -5
  146. package/postgres/postgres-data-provider.d.ts +36 -36
  147. package/postgres/postgres-data-provider.js +191 -191
  148. package/postgres/schema-builder.d.ts +19 -19
  149. package/postgres/schema-builder.js +369 -369
  150. package/remult-express.d.ts +9 -9
  151. package/remult-express.js +34 -33
  152. package/remult-fastify.d.ts +6 -6
  153. package/remult-fastify.js +79 -79
  154. package/remult-fresh.d.ts +17 -17
  155. package/remult-fresh.js +41 -41
  156. package/remult-knex/index.d.ts +30 -30
  157. package/remult-knex/index.js +917 -915
  158. package/remult-mongo.d.ts +24 -24
  159. package/remult-mongo.js +515 -515
  160. package/remult-next.d.ts +25 -25
  161. package/remult-next.js +171 -171
  162. package/remult-sveltekit.d.ts +4 -4
  163. package/remult-sveltekit.js +110 -110
  164. package/server/JsonEntityFileStorage.d.ts +11 -11
  165. package/server/JsonEntityFileStorage.js +35 -35
  166. package/server/core.d.ts +4 -4
  167. package/server/core.js +12 -12
  168. package/server/expressBridge.d.ts +128 -128
  169. package/server/expressBridge.js +1401 -1402
  170. package/server/index.d.ts +6 -6
  171. package/server/index.js +24 -24
  172. package/server/initAsyncHooks.d.ts +1 -1
  173. package/server/initAsyncHooks.js +13 -13
  174. package/server/initDataProvider.d.ts +2 -2
  175. package/server/initDataProvider.js +26 -26
  176. package/src/CompoundIdField.d.ts +27 -27
  177. package/src/CompoundIdField.js +54 -54
  178. package/src/__EntityValueProvider.d.ts +11 -11
  179. package/src/__EntityValueProvider.js +2 -2
  180. package/src/__RowsOfDataForTesting.d.ts +3 -3
  181. package/src/__RowsOfDataForTesting.js +2 -2
  182. package/src/buildRestDataProvider.d.ts +31 -31
  183. package/src/buildRestDataProvider.js +177 -174
  184. package/src/column-interfaces.d.ts +160 -160
  185. package/src/column-interfaces.js +11 -11
  186. package/src/column.d.ts +31 -31
  187. package/src/column.js +132 -132
  188. package/src/context.d.ts +134 -134
  189. package/src/context.js +451 -451
  190. package/src/data-api.d.ts +38 -38
  191. package/src/data-api.js +524 -524
  192. package/src/data-interfaces.d.ts +41 -41
  193. package/src/data-interfaces.js +16 -16
  194. package/src/data-providers/array-entity-data-provider.d.ts +22 -22
  195. package/src/data-providers/array-entity-data-provider.js +364 -364
  196. package/src/data-providers/in-memory-database.d.ts +9 -9
  197. package/src/data-providers/in-memory-database.js +33 -33
  198. package/src/data-providers/json-data-provider.d.ts +12 -12
  199. package/src/data-providers/json-data-provider.js +106 -106
  200. package/src/data-providers/rest-data-provider.d.ts +39 -39
  201. package/src/data-providers/rest-data-provider.js +388 -388
  202. package/src/data-providers/sql-database.d.ts +33 -33
  203. package/src/data-providers/sql-database.js +653 -653
  204. package/src/data-providers/web-sql-data-provider.d.ts +21 -21
  205. package/src/data-providers/web-sql-data-provider.js +229 -229
  206. package/src/entity.d.ts +95 -95
  207. package/src/entity.js +2 -2
  208. package/src/filter/filter-consumer-bridge-to-sql-request.d.ts +50 -50
  209. package/src/filter/filter-consumer-bridge-to-sql-request.js +307 -307
  210. package/src/filter/filter-interfaces.d.ts +86 -86
  211. package/src/filter/filter-interfaces.js +693 -685
  212. package/src/live-query/LiveQueryClient.d.ts +1 -1
  213. package/src/live-query/LiveQueryClient.js +293 -293
  214. package/src/live-query/SseSubscriptionClient.d.ts +5 -5
  215. package/src/live-query/SseSubscriptionClient.js +154 -154
  216. package/src/live-query/SubscriptionChannel.d.ts +41 -41
  217. package/src/live-query/SubscriptionChannel.js +189 -189
  218. package/src/live-query/SubscriptionServer.d.ts +38 -38
  219. package/src/live-query/SubscriptionServer.js +264 -264
  220. package/src/remult-proxy.d.ts +2 -2
  221. package/src/remult-proxy.js +307 -307
  222. package/src/remult3/DecoratorReplacer.d.ts +10 -10
  223. package/src/remult3/DecoratorReplacer.js +24 -24
  224. package/src/remult3/RepositoryImplementation.d.ts +332 -332
  225. package/src/remult3/RepositoryImplementation.js +3391 -3373
  226. package/src/remult3/__updateEntityBasedOnWhere.d.ts +2 -2
  227. package/src/remult3/__updateEntityBasedOnWhere.js +28 -28
  228. package/src/remult3/entity.d.ts +28 -28
  229. package/src/remult3/entity.js +88 -88
  230. package/src/remult3/getEntityRef.d.ts +9 -9
  231. package/src/remult3/getEntityRef.js +35 -35
  232. package/src/remult3/remult3.d.ts +397 -397
  233. package/src/remult3/remult3.js +2 -2
  234. package/src/resultCompoundIdFilter.d.ts +3 -3
  235. package/src/resultCompoundIdFilter.js +20 -20
  236. package/src/server-action-info.d.ts +10 -10
  237. package/src/server-action-info.js +15 -15
  238. package/src/server-action.d.ts +79 -79
  239. package/src/server-action.js +632 -632
  240. package/src/sort.d.ts +16 -16
  241. package/src/sort.js +161 -161
  242. package/src/sql-command.d.ts +19 -19
  243. package/src/sql-command.js +2 -2
  244. package/src/validators.d.ts +14 -14
  245. package/src/validators.js +71 -69
  246. package/src/valueConverters.d.ts +13 -13
  247. package/src/valueConverters.js +213 -213
  248. package/urlBuilder.d.ts +6 -6
  249. package/urlBuilder.js +25 -25
@@ -1,397 +1,397 @@
1
- import type { ErrorInfo } from '../..';
2
- import type { ClassType } from '../../classType';
3
- import type { entityEventListener } from '../__EntityValueProvider';
4
- import type { FieldMetadata } from '../column-interfaces';
5
- import type { EntityOptions } from '../entity';
6
- import type { LiveQueryChange, SubscriptionListener, Unsubscribe } from '../live-query/SubscriptionChannel';
7
- import type { SortSegment } from '../sort';
8
- export interface EntityRef<entityType> extends Subscribable {
9
- hasErrors(): boolean;
10
- undoChanges(): any;
11
- save(): Promise<entityType>;
12
- reload(): Promise<entityType>;
13
- delete(): Promise<void>;
14
- isNew(): boolean;
15
- wasChanged(): boolean;
16
- wasDeleted(): boolean;
17
- fields: FieldsRef<entityType>;
18
- error: string;
19
- getId(): idType<entityType>;
20
- getOriginalId(): idType<entityType>;
21
- repository: Repository<entityType>;
22
- metadata: EntityMetadata<entityType>;
23
- toApiJson(): any;
24
- validate(): Promise<ErrorInfo<entityType> | undefined>;
25
- readonly apiUpdateAllowed: boolean;
26
- readonly apiDeleteAllowed: boolean;
27
- readonly apiInsertAllowed: boolean;
28
- readonly isLoading: boolean;
29
- }
30
- export interface ControllerRef<entityType> extends Subscribable {
31
- hasErrors(): boolean;
32
- fields: FieldsRef<entityType>;
33
- error: string;
34
- validate(): Promise<ErrorInfo<entityType> | undefined>;
35
- readonly isLoading: boolean;
36
- }
37
- export interface RefSubscriberBase {
38
- reportChanged: () => void;
39
- reportObserved: () => void;
40
- }
41
- export declare type RefSubscriber = (() => void) | RefSubscriberBase;
42
- export interface Subscribable {
43
- subscribe(listener: RefSubscriber): Unsubscribe;
44
- }
45
- export declare type FieldsRef<entityType> = {
46
- [Properties in keyof OmitEB<entityType>]: entityType[Properties] extends {
47
- id?: number | string;
48
- } ? IdFieldRef<entityType, entityType[Properties]> : FieldRef<entityType, entityType[Properties]>;
49
- } & {
50
- find(fieldMetadataOrKey: FieldMetadata | string): FieldRef<entityType, any>;
51
- [Symbol.iterator]: () => IterableIterator<FieldRef<entityType, any>>;
52
- toArray(): FieldRef<entityType, any>[];
53
- };
54
- export declare type FieldsMetadata<entityType> = {
55
- [Properties in keyof OmitEB<entityType>]: FieldMetadata<entityType[Properties], entityType>;
56
- } & {
57
- find(fieldMetadataOrKey: FieldMetadata | string): FieldMetadata<any, entityType>;
58
- [Symbol.iterator]: () => IterableIterator<FieldMetadata<any, entityType>>;
59
- toArray(): FieldMetadata<any, entityType>[];
60
- };
61
- export declare type SortSegments<entityType> = {
62
- [Properties in keyof entityType]: SortSegment & {
63
- descending(): SortSegment;
64
- };
65
- };
66
- export interface IdFieldRef<entityType, valueType> extends FieldRef<entityType, valueType> {
67
- setId(id: valueType extends {
68
- id?: number;
69
- } ? number : valueType extends {
70
- id?: string;
71
- } ? string : string | number): any;
72
- getId(): valueType extends {
73
- id?: number;
74
- } ? number : valueType extends {
75
- id?: string;
76
- } ? string : string | number;
77
- }
78
- export interface FieldRef<entityType = any, valueType = any> extends Subscribable {
79
- error: string;
80
- displayValue: string;
81
- value: valueType;
82
- originalValue: valueType;
83
- inputValue: string;
84
- valueChanged(): boolean;
85
- entityRef: EntityRef<entityType>;
86
- container: entityType;
87
- metadata: FieldMetadata<valueType>;
88
- load(): Promise<valueType>;
89
- valueIsNull(): boolean;
90
- originalValueIsNull(): boolean;
91
- validate(): Promise<boolean>;
92
- }
93
- export interface IdMetadata<entityType = any> {
94
- /** Extracts the id value of an entity item. Useful in cases where the id column is not called id
95
- * @example
96
- * repo.metadata.idMetadata.getId(task)
97
- */
98
- getId(item: Partial<OmitEB<entityType>>): any;
99
- field: FieldMetadata<any>;
100
- getIdFilter(...ids: any[]): EntityFilter<entityType>;
101
- isIdField(col: FieldMetadata): boolean;
102
- createIdInFilter(items: Partial<OmitEB<entityType>>[]): EntityFilter<entityType>;
103
- }
104
- /** Metadata for an `Entity`, this metadata can be used in the user interface to provide a richer UI experience */
105
- export interface EntityMetadata<entityType = any> {
106
- /** The Entity's key also used as it's url */
107
- readonly key: string;
108
- /** Metadata for the Entity's fields */
109
- readonly fields: FieldsMetadata<entityType>;
110
- /** A human readable caption for the entity. Can be used to achieve a consistent caption for a field throughout the app
111
- * @example
112
- * <h1>Create a new item in {taskRepo.metadata.caption}</h1>
113
- */
114
- readonly caption: string;
115
- /** The options send to the `Entity`'s decorator */
116
- readonly options: EntityOptions;
117
- /** The class type of the entity */
118
- readonly entityType: ClassType<entityType>;
119
- /** true if the current user is allowed to update an entity instance
120
- * @example
121
- * const taskRepo = remult.repo(Task);
122
- * if (taskRepo.metadata.apiUpdateAllowed(task)){
123
- * // Allow user to edit the entity
124
- * }
125
- */
126
- apiUpdateAllowed(item?: entityType): boolean;
127
- /** true if the current user is allowed to read from entity
128
- * @example
129
- * const taskRepo = remult.repo(Task);
130
- * if (taskRepo.metadata.apiReadAllowed){
131
- * await taskRepo.find()
132
- * }
133
- */
134
- readonly apiReadAllowed: boolean;
135
- /** true if the current user is allowed to delete an entity instance
136
- * @example
137
- * const taskRepo = remult.repo(Task);
138
- * if (taskRepo.metadata.apiDeleteAllowed(task)){
139
- * // display delete button
140
- * }
141
- */
142
- apiDeleteAllowed(item?: entityType): boolean;
143
- /** true if the current user is allowed to create an entity instance
144
- * @example
145
- * const taskRepo = remult.repo(Task);
146
- * if (taskRepo.metadata.apiInsertAllowed(task)){
147
- * // display insert button
148
- * }
149
- */
150
- apiInsertAllowed(item?: entityType): boolean;
151
- /** Returns the dbName - based on it's `dbName` option and it's `sqlExpression` option */
152
- getDbName(): Promise<string>;
153
- /** Metadata for the Entity's id */
154
- readonly idMetadata: IdMetadata<entityType>;
155
- }
156
- export declare type OmitEB<T> = Omit<T, keyof import('./RepositoryImplementation').EntityBase>;
157
- export declare type idType<entityType> = entityType extends {
158
- id?: number;
159
- } ? number : entityType extends {
160
- id?: string;
161
- } ? string : string | number;
162
- /**used to perform CRUD operations on an `entityType` */
163
- export interface Repository<entityType> {
164
- /** returns a result array based on the provided options */
165
- find(options?: FindOptions<entityType>): Promise<entityType[]>;
166
- /** returns a result array based on the provided options */
167
- liveQuery(options?: FindOptions<entityType>): LiveQuery<entityType>;
168
- /** returns the first item that matchers the `where` condition
169
- * @example
170
- * await taskRepo.findFirst({ completed:false })
171
- * @example
172
- * await taskRepo.findFirst({ completed:false },{ createIfNotFound: true })
173
- * */
174
- findFirst(where?: EntityFilter<entityType>, options?: FindFirstOptions<entityType>): Promise<entityType>;
175
- /** returns the items that matches the idm the result is cached unless specified differently in the `options` parameter */
176
- findId(id: idType<entityType>, options?: FindFirstOptionsBase<entityType>): Promise<entityType>;
177
- /** An alternative form of fetching data from the API server, which is intended for operating on large numbers of entity objects.
178
- *
179
- * It also has it's own paging mechanism that can be used n paging scenarios.
180
- *
181
- * The `query` method doesn't return an array (as the `find` method) and instead returns an `iterable` `QueryResult` object
182
- * which supports iterations using the JavaScript `for await` statement.
183
- * @example
184
- * for await (const task of taskRepo.query()) {
185
- * // do something.
186
- * }
187
- * */
188
- query(options?: QueryOptions<entityType>): QueryResult<entityType>;
189
- /** Returns a count of the items matching the criteria.
190
- * @see [EntityFilter](http://remult.dev/docs/entityFilter.html)
191
- * @example
192
- * await taskRepo.count({ completed:false })
193
- */
194
- count(where?: EntityFilter<entityType>): Promise<number>;
195
- /**Validates an item
196
- * @example
197
- * const error = repo.validate(task);
198
- * if (error){
199
- * alert(error.message);
200
- * alert(error.modelState.title);//shows the specific error for the title field
201
- * }
202
- * // Can also be used to validate specific fields
203
- * const error = repo.validate(task,"title")
204
- */
205
- validate(item: Partial<entityType>, ...fields: Extract<keyof OmitEB<entityType>, string>[]): Promise<ErrorInfo<entityType> | undefined>;
206
- /** saves an item or item[] to the data source. It assumes that if an `id` value exists, it's an existing row - otherwise it's a new row
207
- * @example
208
- * await taskRepo.save({...task, completed:true })
209
- */
210
- save(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
211
- save(item: Partial<OmitEB<entityType>>): Promise<entityType>;
212
- /**Insert an item or item[] to the data source
213
- * @example
214
- * await taskRepo.insert({title:"task a"})
215
- * @example
216
- * await taskRepo.insert([{title:"task a"}, {title:"task b", completed:true }])
217
- */
218
- insert(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
219
- insert(item: Partial<OmitEB<entityType>>): Promise<entityType>;
220
- /** Updates an item, based on its `id`
221
- * @example
222
- * taskRepo.update(task.id,{...task,completed:true})
223
- */
224
- update(id: entityType extends {
225
- id?: number;
226
- } ? number : entityType extends {
227
- id?: string;
228
- } ? string : string | number, item: Partial<OmitEB<entityType>>): Promise<entityType>;
229
- update(id: Partial<OmitEB<entityType>>, item: Partial<OmitEB<entityType>>): Promise<entityType>;
230
- /** Deletes an Item*/
231
- delete(id: entityType extends {
232
- id?: number;
233
- } ? number : entityType extends {
234
- id?: string;
235
- } ? string : string | number): Promise<void>;
236
- delete(item: Partial<OmitEB<entityType>>): Promise<void>;
237
- /** Creates an instance of an item. It'll not be saved to the data source unless `save` or `insert` will be called for that item */
238
- create(item?: Partial<OmitEB<entityType>>): entityType;
239
- toJson(item: Promise<entityType[]>): Promise<any[]>;
240
- toJson(item: entityType[]): any[];
241
- toJson(item: Promise<entityType>): Promise<any>;
242
- toJson(item: entityType): any;
243
- /** Translates a json object to an item instance */
244
- fromJson(x: any[], isNew?: boolean): entityType[];
245
- fromJson(x: any, isNew?: boolean): entityType;
246
- /** returns an `entityRef` for an item returned by `create`, `find` etc... */
247
- getEntityRef(item: entityType): EntityRef<entityType>;
248
- /** Provides information about the fields of the Repository's entity
249
- * @example
250
- * console.log(repo.fields.title.caption) // displays the caption of a specific field
251
- * console.log(repo.fields.title.options)// writes the options that were defined for this field
252
- */
253
- fields: FieldsMetadata<entityType>;
254
- /**The metadata for the `entity`
255
- * @See [EntityMetadata](https://remult.dev/docs/ref_entitymetadata.html)
256
- */
257
- metadata: EntityMetadata<entityType>;
258
- addEventListener(listener: entityEventListener<entityType>): Unsubscribe;
259
- }
260
- export interface LiveQuery<entityType> {
261
- subscribe(next: (info: LiveQueryChangeInfo<entityType>) => void): Unsubscribe;
262
- subscribe(listener: Partial<SubscriptionListener<LiveQueryChangeInfo<entityType>>>): Unsubscribe;
263
- }
264
- export interface LiveQueryChangeInfo<entityType> {
265
- items: entityType[];
266
- changes: LiveQueryChange[];
267
- applyChanges(prevState: entityType[] | undefined): entityType[];
268
- }
269
- export interface FindOptions<entityType> extends FindOptionsBase<entityType> {
270
- /** Determines the number of rows returned by the request, on the browser the default is 100 rows
271
- * @example
272
- * await this.remult.repo(Products).find({
273
- * limit:10,
274
- * page:2
275
- * })
276
- */
277
- limit?: number;
278
- /** Determines the page number that will be used to extract the data
279
- * @example
280
- * await this.remult.repo(Products).find({
281
- * limit:10,
282
- * page:2
283
- * })
284
- */
285
- page?: number;
286
- }
287
- /** Determines the order of items returned .
288
- * @example
289
- * await this.remult.repo(Products).find({ orderBy: { name: "asc" }})
290
- * @example
291
- * await this.remult.repo(Products).find({ orderBy: { price: "desc", name: "asc" }})
292
- */
293
- export declare type EntityOrderBy<entityType> = {
294
- [Properties in keyof Partial<OmitEB<entityType>>]?: 'asc' | 'desc';
295
- };
296
- /**Used to filter the desired result set
297
- * @see [EntityFilter](http://remult.dev/docs/entityFilter.html)
298
- */
299
- export declare type EntityFilter<entityType> = {
300
- [Properties in keyof Partial<OmitEB<entityType>>]?: (Partial<OmitEB<entityType>>[Properties] extends number | Date | undefined ? ComparisonValueFilter<Partial<OmitEB<entityType>>[Properties]> : Partial<OmitEB<entityType>>[Properties] extends string | undefined ? ContainsStringValueFilter & ComparisonValueFilter<string> : Partial<OmitEB<entityType>>[Properties] extends boolean | undefined ? ValueFilter<boolean> : Partial<OmitEB<entityType>>[Properties] extends {
301
- id?: string | number;
302
- } | undefined ? IdFilter<Partial<OmitEB<entityType>>[Properties]> : ValueFilter<Partial<OmitEB<entityType>>[Properties]>) & ContainsStringValueFilter;
303
- } & {
304
- $or?: EntityFilter<entityType>[];
305
- $and?: EntityFilter<entityType>[];
306
- };
307
- export declare type ValueFilter<valueType> = valueType | valueType[] | {
308
- $ne?: valueType | valueType[];
309
- '!='?: valueType | valueType[];
310
- $in?: valueType[];
311
- $nin?: valueType[];
312
- };
313
- export declare type ComparisonValueFilter<valueType> = ValueFilter<valueType> & {
314
- $gt?: valueType;
315
- '>'?: valueType;
316
- $gte?: valueType;
317
- '>='?: valueType;
318
- $lt?: valueType;
319
- '<'?: valueType;
320
- $lte?: valueType;
321
- '<='?: valueType;
322
- };
323
- export interface ContainsStringValueFilter {
324
- $contains?: string;
325
- }
326
- export declare type IdFilter<valueType> = ValueFilter<valueType> | {
327
- $id: ValueFilter<valueType extends {
328
- id?: number;
329
- } ? number : string>;
330
- };
331
- export interface LoadOptions<entityType> {
332
- load?: (entity: FieldsMetadata<entityType>) => FieldMetadata[];
333
- }
334
- export interface FindOptionsBase<entityType> extends LoadOptions<entityType> {
335
- /** filters the data
336
- * @example
337
- * await taskRepo.find({where: { completed:false }})
338
- * @see For more usage examples see [EntityFilter](https://remult.dev/docs/entityFilter.html)
339
- */
340
- where?: EntityFilter<entityType>;
341
- /** Determines the order of items returned .
342
- * @example
343
- * await this.remult.repo(Products).find({ orderBy: { name: "asc" }})
344
- * @example
345
- * await this.remult.repo(Products).find({ orderBy: { price: "desc", name: "asc" }})
346
- */
347
- orderBy?: EntityOrderBy<entityType>;
348
- }
349
- export interface FindFirstOptions<entityType> extends FindOptionsBase<entityType>, FindFirstOptionsBase<entityType> {
350
- }
351
- export interface FindFirstOptionsBase<entityType> extends LoadOptions<entityType> {
352
- /** determines if to cache the result, and return the results from cache.
353
- */
354
- useCache?: boolean;
355
- /** If set to true and an item is not found, it's created and returned*/
356
- createIfNotFound?: boolean;
357
- }
358
- export interface QueryOptions<entityType> extends FindOptionsBase<entityType> {
359
- /** The number of items to return in each step */
360
- pageSize?: number;
361
- /** A callback method to indicate the progress of the iteration */
362
- progress?: {
363
- progress: (progress: number) => void;
364
- };
365
- }
366
- /** The result of a call to the `query` method in the `Repository` object.
367
- */
368
- export interface QueryResult<entityType> {
369
- /** returns an iterator that iterates the rows in the result using a paging mechanism
370
- * @example
371
- * for await (const task of taskRepo.query()) {
372
- * await taskRepo.save({ ...task, completed });
373
- * }
374
- */
375
- [Symbol.asyncIterator](): {
376
- next: () => Promise<IteratorResult<entityType, entityType>>;
377
- };
378
- /** returns the number of rows that match the query criteria */
379
- count(): Promise<number>;
380
- /** Returns a `Paginator` object that is used for efficient paging */
381
- paginator(): Promise<Paginator<entityType>>;
382
- /** gets the items in a specific page */
383
- getPage(pageNumber?: number): Promise<entityType[]>;
384
- /** Performs an operation on all the items matching the query criteria */
385
- forEach(what: (item: entityType) => Promise<any>): Promise<number>;
386
- }
387
- /** An interface used to paginating using the `query` method in the `Repository` object */
388
- export interface Paginator<entityType> {
389
- /** the items in the current page */
390
- items: entityType[];
391
- /** True if next page exists */
392
- hasNextPage: boolean;
393
- /** Gets the next page in the `query`'s result set */
394
- nextPage(): Promise<Paginator<entityType>>;
395
- /** the count of the total items in the `query`'s result */
396
- count(): Promise<number>;
397
- }
1
+ import type { ErrorInfo } from '../..';
2
+ import type { ClassType } from '../../classType';
3
+ import type { entityEventListener } from '../__EntityValueProvider';
4
+ import type { FieldMetadata } from '../column-interfaces';
5
+ import type { EntityOptions } from '../entity';
6
+ import type { LiveQueryChange, SubscriptionListener, Unsubscribe } from '../live-query/SubscriptionChannel';
7
+ import type { SortSegment } from '../sort';
8
+ export interface EntityRef<entityType> extends Subscribable {
9
+ hasErrors(): boolean;
10
+ undoChanges(): any;
11
+ save(): Promise<entityType>;
12
+ reload(): Promise<entityType>;
13
+ delete(): Promise<void>;
14
+ isNew(): boolean;
15
+ wasChanged(): boolean;
16
+ wasDeleted(): boolean;
17
+ fields: FieldsRef<entityType>;
18
+ error: string;
19
+ getId(): idType<entityType>;
20
+ getOriginalId(): idType<entityType>;
21
+ repository: Repository<entityType>;
22
+ metadata: EntityMetadata<entityType>;
23
+ toApiJson(): any;
24
+ validate(): Promise<ErrorInfo<entityType> | undefined>;
25
+ readonly apiUpdateAllowed: boolean;
26
+ readonly apiDeleteAllowed: boolean;
27
+ readonly apiInsertAllowed: boolean;
28
+ readonly isLoading: boolean;
29
+ }
30
+ export interface ControllerRef<entityType> extends Subscribable {
31
+ hasErrors(): boolean;
32
+ fields: FieldsRef<entityType>;
33
+ error: string;
34
+ validate(): Promise<ErrorInfo<entityType> | undefined>;
35
+ readonly isLoading: boolean;
36
+ }
37
+ export interface RefSubscriberBase {
38
+ reportChanged: () => void;
39
+ reportObserved: () => void;
40
+ }
41
+ export declare type RefSubscriber = (() => void) | RefSubscriberBase;
42
+ export interface Subscribable {
43
+ subscribe(listener: RefSubscriber): Unsubscribe;
44
+ }
45
+ export type FieldsRef<entityType> = {
46
+ [Properties in keyof OmitEB<entityType>]: entityType[Properties] extends {
47
+ id?: number | string;
48
+ } ? IdFieldRef<entityType, entityType[Properties]> : FieldRef<entityType, entityType[Properties]>;
49
+ } & {
50
+ find(fieldMetadataOrKey: FieldMetadata | string): FieldRef<entityType, any>;
51
+ [Symbol.iterator]: () => IterableIterator<FieldRef<entityType, any>>;
52
+ toArray(): FieldRef<entityType, any>[];
53
+ };
54
+ export type FieldsMetadata<entityType> = {
55
+ [Properties in keyof OmitEB<entityType>]: FieldMetadata<entityType[Properties], entityType>;
56
+ } & {
57
+ find(fieldMetadataOrKey: FieldMetadata | string): FieldMetadata<any, entityType>;
58
+ [Symbol.iterator]: () => IterableIterator<FieldMetadata<any, entityType>>;
59
+ toArray(): FieldMetadata<any, entityType>[];
60
+ };
61
+ export type SortSegments<entityType> = {
62
+ [Properties in keyof entityType]: SortSegment & {
63
+ descending(): SortSegment;
64
+ };
65
+ };
66
+ export interface IdFieldRef<entityType, valueType> extends FieldRef<entityType, valueType> {
67
+ setId(id: valueType extends {
68
+ id?: number;
69
+ } ? number : valueType extends {
70
+ id?: string;
71
+ } ? string : string | number): any;
72
+ getId(): valueType extends {
73
+ id?: number;
74
+ } ? number : valueType extends {
75
+ id?: string;
76
+ } ? string : string | number;
77
+ }
78
+ export interface FieldRef<entityType = any, valueType = any> extends Subscribable {
79
+ error: string;
80
+ displayValue: string;
81
+ value: valueType;
82
+ originalValue: valueType;
83
+ inputValue: string;
84
+ valueChanged(): boolean;
85
+ entityRef: EntityRef<entityType>;
86
+ container: entityType;
87
+ metadata: FieldMetadata<valueType>;
88
+ load(): Promise<valueType>;
89
+ valueIsNull(): boolean;
90
+ originalValueIsNull(): boolean;
91
+ validate(): Promise<boolean>;
92
+ }
93
+ export interface IdMetadata<entityType = any> {
94
+ /** Extracts the id value of an entity item. Useful in cases where the id column is not called id
95
+ * @example
96
+ * repo.metadata.idMetadata.getId(task)
97
+ */
98
+ getId(item: Partial<OmitEB<entityType>>): any;
99
+ field: FieldMetadata<any>;
100
+ getIdFilter(...ids: any[]): EntityFilter<entityType>;
101
+ isIdField(col: FieldMetadata): boolean;
102
+ createIdInFilter(items: Partial<OmitEB<entityType>>[]): EntityFilter<entityType>;
103
+ }
104
+ /** Metadata for an `Entity`, this metadata can be used in the user interface to provide a richer UI experience */
105
+ export interface EntityMetadata<entityType = any> {
106
+ /** The Entity's key also used as it's url */
107
+ readonly key: string;
108
+ /** Metadata for the Entity's fields */
109
+ readonly fields: FieldsMetadata<entityType>;
110
+ /** A human readable caption for the entity. Can be used to achieve a consistent caption for a field throughout the app
111
+ * @example
112
+ * <h1>Create a new item in {taskRepo.metadata.caption}</h1>
113
+ */
114
+ readonly caption: string;
115
+ /** The options send to the `Entity`'s decorator */
116
+ readonly options: EntityOptions;
117
+ /** The class type of the entity */
118
+ readonly entityType: ClassType<entityType>;
119
+ /** true if the current user is allowed to update an entity instance
120
+ * @example
121
+ * const taskRepo = remult.repo(Task);
122
+ * if (taskRepo.metadata.apiUpdateAllowed(task)){
123
+ * // Allow user to edit the entity
124
+ * }
125
+ */
126
+ apiUpdateAllowed(item?: entityType): boolean;
127
+ /** true if the current user is allowed to read from entity
128
+ * @example
129
+ * const taskRepo = remult.repo(Task);
130
+ * if (taskRepo.metadata.apiReadAllowed){
131
+ * await taskRepo.find()
132
+ * }
133
+ */
134
+ readonly apiReadAllowed: boolean;
135
+ /** true if the current user is allowed to delete an entity instance
136
+ * @example
137
+ * const taskRepo = remult.repo(Task);
138
+ * if (taskRepo.metadata.apiDeleteAllowed(task)){
139
+ * // display delete button
140
+ * }
141
+ */
142
+ apiDeleteAllowed(item?: entityType): boolean;
143
+ /** true if the current user is allowed to create an entity instance
144
+ * @example
145
+ * const taskRepo = remult.repo(Task);
146
+ * if (taskRepo.metadata.apiInsertAllowed(task)){
147
+ * // display insert button
148
+ * }
149
+ */
150
+ apiInsertAllowed(item?: entityType): boolean;
151
+ /** Returns the dbName - based on it's `dbName` option and it's `sqlExpression` option */
152
+ getDbName(): Promise<string>;
153
+ /** Metadata for the Entity's id */
154
+ readonly idMetadata: IdMetadata<entityType>;
155
+ }
156
+ export declare type OmitEB<T> = Omit<T, keyof import('./RepositoryImplementation').EntityBase>;
157
+ export declare type idType<entityType> = entityType extends {
158
+ id?: number;
159
+ } ? number : entityType extends {
160
+ id?: string;
161
+ } ? string : string | number;
162
+ /**used to perform CRUD operations on an `entityType` */
163
+ export interface Repository<entityType> {
164
+ /** returns a result array based on the provided options */
165
+ find(options?: FindOptions<entityType>): Promise<entityType[]>;
166
+ /** returns a result array based on the provided options */
167
+ liveQuery(options?: FindOptions<entityType>): LiveQuery<entityType>;
168
+ /** returns the first item that matchers the `where` condition
169
+ * @example
170
+ * await taskRepo.findFirst({ completed:false })
171
+ * @example
172
+ * await taskRepo.findFirst({ completed:false },{ createIfNotFound: true })
173
+ * */
174
+ findFirst(where?: EntityFilter<entityType>, options?: FindFirstOptions<entityType>): Promise<entityType>;
175
+ /** returns the items that matches the idm the result is cached unless specified differently in the `options` parameter */
176
+ findId(id: idType<entityType>, options?: FindFirstOptionsBase<entityType>): Promise<entityType>;
177
+ /** An alternative form of fetching data from the API server, which is intended for operating on large numbers of entity objects.
178
+ *
179
+ * It also has it's own paging mechanism that can be used n paging scenarios.
180
+ *
181
+ * The `query` method doesn't return an array (as the `find` method) and instead returns an `iterable` `QueryResult` object
182
+ * which supports iterations using the JavaScript `for await` statement.
183
+ * @example
184
+ * for await (const task of taskRepo.query()) {
185
+ * // do something.
186
+ * }
187
+ * */
188
+ query(options?: QueryOptions<entityType>): QueryResult<entityType>;
189
+ /** Returns a count of the items matching the criteria.
190
+ * @see [EntityFilter](http://remult.dev/docs/entityFilter.html)
191
+ * @example
192
+ * await taskRepo.count({ completed:false })
193
+ */
194
+ count(where?: EntityFilter<entityType>): Promise<number>;
195
+ /**Validates an item
196
+ * @example
197
+ * const error = repo.validate(task);
198
+ * if (error){
199
+ * alert(error.message);
200
+ * alert(error.modelState.title);//shows the specific error for the title field
201
+ * }
202
+ * // Can also be used to validate specific fields
203
+ * const error = repo.validate(task,"title")
204
+ */
205
+ validate(item: Partial<entityType>, ...fields: Extract<keyof OmitEB<entityType>, string>[]): Promise<ErrorInfo<entityType> | undefined>;
206
+ /** saves an item or item[] to the data source. It assumes that if an `id` value exists, it's an existing row - otherwise it's a new row
207
+ * @example
208
+ * await taskRepo.save({...task, completed:true })
209
+ */
210
+ save(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
211
+ save(item: Partial<OmitEB<entityType>>): Promise<entityType>;
212
+ /**Insert an item or item[] to the data source
213
+ * @example
214
+ * await taskRepo.insert({title:"task a"})
215
+ * @example
216
+ * await taskRepo.insert([{title:"task a"}, {title:"task b", completed:true }])
217
+ */
218
+ insert(item: Partial<OmitEB<entityType>>[]): Promise<entityType[]>;
219
+ insert(item: Partial<OmitEB<entityType>>): Promise<entityType>;
220
+ /** Updates an item, based on its `id`
221
+ * @example
222
+ * taskRepo.update(task.id,{...task,completed:true})
223
+ */
224
+ update(id: entityType extends {
225
+ id?: number;
226
+ } ? number : entityType extends {
227
+ id?: string;
228
+ } ? string : string | number, item: Partial<OmitEB<entityType>>): Promise<entityType>;
229
+ update(id: Partial<OmitEB<entityType>>, item: Partial<OmitEB<entityType>>): Promise<entityType>;
230
+ /** Deletes an Item*/
231
+ delete(id: entityType extends {
232
+ id?: number;
233
+ } ? number : entityType extends {
234
+ id?: string;
235
+ } ? string : string | number): Promise<void>;
236
+ delete(item: Partial<OmitEB<entityType>>): Promise<void>;
237
+ /** Creates an instance of an item. It'll not be saved to the data source unless `save` or `insert` will be called for that item */
238
+ create(item?: Partial<OmitEB<entityType>>): entityType;
239
+ toJson(item: Promise<entityType[]>): Promise<any[]>;
240
+ toJson(item: entityType[]): any[];
241
+ toJson(item: Promise<entityType>): Promise<any>;
242
+ toJson(item: entityType): any;
243
+ /** Translates a json object to an item instance */
244
+ fromJson(x: any[], isNew?: boolean): entityType[];
245
+ fromJson(x: any, isNew?: boolean): entityType;
246
+ /** returns an `entityRef` for an item returned by `create`, `find` etc... */
247
+ getEntityRef(item: entityType): EntityRef<entityType>;
248
+ /** Provides information about the fields of the Repository's entity
249
+ * @example
250
+ * console.log(repo.fields.title.caption) // displays the caption of a specific field
251
+ * console.log(repo.fields.title.options)// writes the options that were defined for this field
252
+ */
253
+ fields: FieldsMetadata<entityType>;
254
+ /**The metadata for the `entity`
255
+ * @See [EntityMetadata](https://remult.dev/docs/ref_entitymetadata.html)
256
+ */
257
+ metadata: EntityMetadata<entityType>;
258
+ addEventListener(listener: entityEventListener<entityType>): Unsubscribe;
259
+ }
260
+ export interface LiveQuery<entityType> {
261
+ subscribe(next: (info: LiveQueryChangeInfo<entityType>) => void): Unsubscribe;
262
+ subscribe(listener: Partial<SubscriptionListener<LiveQueryChangeInfo<entityType>>>): Unsubscribe;
263
+ }
264
+ export interface LiveQueryChangeInfo<entityType> {
265
+ items: entityType[];
266
+ changes: LiveQueryChange[];
267
+ applyChanges(prevState: entityType[] | undefined): entityType[];
268
+ }
269
+ export interface FindOptions<entityType> extends FindOptionsBase<entityType> {
270
+ /** Determines the number of rows returned by the request, on the browser the default is 100 rows
271
+ * @example
272
+ * await this.remult.repo(Products).find({
273
+ * limit:10,
274
+ * page:2
275
+ * })
276
+ */
277
+ limit?: number;
278
+ /** Determines the page number that will be used to extract the data
279
+ * @example
280
+ * await this.remult.repo(Products).find({
281
+ * limit:10,
282
+ * page:2
283
+ * })
284
+ */
285
+ page?: number;
286
+ }
287
+ /** Determines the order of items returned .
288
+ * @example
289
+ * await this.remult.repo(Products).find({ orderBy: { name: "asc" }})
290
+ * @example
291
+ * await this.remult.repo(Products).find({ orderBy: { price: "desc", name: "asc" }})
292
+ */
293
+ export declare type EntityOrderBy<entityType> = {
294
+ [Properties in keyof Partial<OmitEB<entityType>>]?: 'asc' | 'desc';
295
+ };
296
+ /**Used to filter the desired result set
297
+ * @see [EntityFilter](http://remult.dev/docs/entityFilter.html)
298
+ */
299
+ export declare type EntityFilter<entityType> = {
300
+ [Properties in keyof Partial<OmitEB<entityType>>]?: (Partial<OmitEB<entityType>>[Properties] extends number | Date | undefined ? ComparisonValueFilter<Partial<OmitEB<entityType>>[Properties]> : Partial<OmitEB<entityType>>[Properties] extends string | undefined ? ContainsStringValueFilter & ComparisonValueFilter<string> : Partial<OmitEB<entityType>>[Properties] extends boolean | undefined ? ValueFilter<boolean> : Partial<OmitEB<entityType>>[Properties] extends {
301
+ id?: string | number;
302
+ } | undefined ? IdFilter<Partial<OmitEB<entityType>>[Properties]> : ValueFilter<Partial<OmitEB<entityType>>[Properties]>) & ContainsStringValueFilter;
303
+ } & {
304
+ $or?: EntityFilter<entityType>[];
305
+ $and?: EntityFilter<entityType>[];
306
+ };
307
+ export type ValueFilter<valueType> = valueType | valueType[] | {
308
+ $ne?: valueType | valueType[];
309
+ '!='?: valueType | valueType[];
310
+ $in?: valueType[];
311
+ $nin?: valueType[];
312
+ };
313
+ export type ComparisonValueFilter<valueType> = ValueFilter<valueType> & {
314
+ $gt?: valueType;
315
+ '>'?: valueType;
316
+ $gte?: valueType;
317
+ '>='?: valueType;
318
+ $lt?: valueType;
319
+ '<'?: valueType;
320
+ $lte?: valueType;
321
+ '<='?: valueType;
322
+ };
323
+ export interface ContainsStringValueFilter {
324
+ $contains?: string;
325
+ }
326
+ export type IdFilter<valueType> = ValueFilter<valueType> | {
327
+ $id: ValueFilter<valueType extends {
328
+ id?: number;
329
+ } ? number : string>;
330
+ };
331
+ export interface LoadOptions<entityType> {
332
+ load?: (entity: FieldsMetadata<entityType>) => FieldMetadata[];
333
+ }
334
+ export interface FindOptionsBase<entityType> extends LoadOptions<entityType> {
335
+ /** filters the data
336
+ * @example
337
+ * await taskRepo.find({where: { completed:false }})
338
+ * @see For more usage examples see [EntityFilter](https://remult.dev/docs/entityFilter.html)
339
+ */
340
+ where?: EntityFilter<entityType>;
341
+ /** Determines the order of items returned .
342
+ * @example
343
+ * await this.remult.repo(Products).find({ orderBy: { name: "asc" }})
344
+ * @example
345
+ * await this.remult.repo(Products).find({ orderBy: { price: "desc", name: "asc" }})
346
+ */
347
+ orderBy?: EntityOrderBy<entityType>;
348
+ }
349
+ export interface FindFirstOptions<entityType> extends FindOptionsBase<entityType>, FindFirstOptionsBase<entityType> {
350
+ }
351
+ export interface FindFirstOptionsBase<entityType> extends LoadOptions<entityType> {
352
+ /** determines if to cache the result, and return the results from cache.
353
+ */
354
+ useCache?: boolean;
355
+ /** If set to true and an item is not found, it's created and returned*/
356
+ createIfNotFound?: boolean;
357
+ }
358
+ export interface QueryOptions<entityType> extends FindOptionsBase<entityType> {
359
+ /** The number of items to return in each step */
360
+ pageSize?: number;
361
+ /** A callback method to indicate the progress of the iteration */
362
+ progress?: {
363
+ progress: (progress: number) => void;
364
+ };
365
+ }
366
+ /** The result of a call to the `query` method in the `Repository` object.
367
+ */
368
+ export interface QueryResult<entityType> {
369
+ /** returns an iterator that iterates the rows in the result using a paging mechanism
370
+ * @example
371
+ * for await (const task of taskRepo.query()) {
372
+ * await taskRepo.save({ ...task, completed });
373
+ * }
374
+ */
375
+ [Symbol.asyncIterator](): {
376
+ next: () => Promise<IteratorResult<entityType, entityType>>;
377
+ };
378
+ /** returns the number of rows that match the query criteria */
379
+ count(): Promise<number>;
380
+ /** Returns a `Paginator` object that is used for efficient paging */
381
+ paginator(): Promise<Paginator<entityType>>;
382
+ /** gets the items in a specific page */
383
+ getPage(pageNumber?: number): Promise<entityType[]>;
384
+ /** Performs an operation on all the items matching the query criteria */
385
+ forEach(what: (item: entityType) => Promise<any>): Promise<number>;
386
+ }
387
+ /** An interface used to paginating using the `query` method in the `Repository` object */
388
+ export interface Paginator<entityType> {
389
+ /** the items in the current page */
390
+ items: entityType[];
391
+ /** True if next page exists */
392
+ hasNextPage: boolean;
393
+ /** Gets the next page in the `query`'s result set */
394
+ nextPage(): Promise<Paginator<entityType>>;
395
+ /** the count of the total items in the `query`'s result */
396
+ count(): Promise<number>;
397
+ }