@webda/core 2.4.2 → 3.0.1

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 (227) hide show
  1. package/lib/application.d.ts +171 -34
  2. package/lib/application.js +243 -47
  3. package/lib/application.js.map +1 -1
  4. package/lib/application.spec.js +44 -8
  5. package/lib/application.spec.js.map +1 -1
  6. package/lib/core.d.ts +113 -54
  7. package/lib/core.js +222 -135
  8. package/lib/core.js.map +1 -1
  9. package/lib/core.spec.js +87 -43
  10. package/lib/core.spec.js.map +1 -1
  11. package/lib/errors.d.ts +65 -0
  12. package/lib/errors.js +113 -0
  13. package/lib/errors.js.map +1 -0
  14. package/lib/errors.spec.d.ts +1 -0
  15. package/lib/errors.spec.js +33 -0
  16. package/lib/errors.spec.js.map +1 -0
  17. package/lib/index.d.ts +3 -0
  18. package/lib/index.js +3 -0
  19. package/lib/index.js.map +1 -1
  20. package/lib/models/aclmodel.d.ts +4 -4
  21. package/lib/models/aclmodel.js +10 -6
  22. package/lib/models/aclmodel.js.map +1 -1
  23. package/lib/models/aclmodel.spec.js +33 -24
  24. package/lib/models/aclmodel.spec.js.map +1 -1
  25. package/lib/models/coremodel.d.ts +284 -92
  26. package/lib/models/coremodel.js +403 -103
  27. package/lib/models/coremodel.js.map +1 -1
  28. package/lib/models/coremodel.spec.js +162 -24
  29. package/lib/models/coremodel.spec.js.map +1 -1
  30. package/lib/models/ident.d.ts +20 -6
  31. package/lib/models/ident.js.map +1 -1
  32. package/lib/models/ownermodel.d.ts +13 -23
  33. package/lib/models/ownermodel.js +24 -51
  34. package/lib/models/ownermodel.js.map +1 -1
  35. package/lib/models/ownermodel.spec.js +23 -11
  36. package/lib/models/ownermodel.spec.js.map +1 -1
  37. package/lib/models/relations.d.ts +167 -0
  38. package/lib/models/relations.js +113 -0
  39. package/lib/models/relations.js.map +1 -0
  40. package/lib/models/rolemodel.d.ts +3 -3
  41. package/lib/models/rolemodel.js +6 -6
  42. package/lib/models/rolemodel.js.map +1 -1
  43. package/lib/models/rolemodel.spec.js +12 -12
  44. package/lib/models/rolemodel.spec.js.map +1 -1
  45. package/lib/models/user.d.ts +40 -24
  46. package/lib/models/user.js +74 -48
  47. package/lib/models/user.js.map +1 -1
  48. package/lib/models/user.spec.js +24 -4
  49. package/lib/models/user.spec.js.map +1 -1
  50. package/lib/queues/memoryqueue.spec.js +9 -5
  51. package/lib/queues/memoryqueue.spec.js.map +1 -1
  52. package/lib/queues/queueservice.js.map +1 -1
  53. package/lib/router.d.ts +17 -8
  54. package/lib/router.js +81 -9
  55. package/lib/router.js.map +1 -1
  56. package/lib/router.spec.js +89 -5
  57. package/lib/router.spec.js.map +1 -1
  58. package/lib/services/asyncevents.spec.js +4 -4
  59. package/lib/services/authentication.d.ts +21 -22
  60. package/lib/services/authentication.js +90 -109
  61. package/lib/services/authentication.js.map +1 -1
  62. package/lib/services/authentication.spec.js +51 -65
  63. package/lib/services/authentication.spec.js.map +1 -1
  64. package/lib/services/binary.d.ts +132 -31
  65. package/lib/services/binary.js +257 -72
  66. package/lib/services/binary.js.map +1 -1
  67. package/lib/services/binary.spec.d.ts +16 -6
  68. package/lib/services/binary.spec.js +44 -117
  69. package/lib/services/binary.spec.js.map +1 -1
  70. package/lib/services/cloudbinary.d.ts +9 -10
  71. package/lib/services/cloudbinary.js +14 -15
  72. package/lib/services/cloudbinary.js.map +1 -1
  73. package/lib/services/cloudbinary.spec.d.ts +2 -2
  74. package/lib/services/cloudbinary.spec.js +13 -12
  75. package/lib/services/cloudbinary.spec.js.map +1 -1
  76. package/lib/services/configuration.js +9 -9
  77. package/lib/services/configuration.js.map +1 -1
  78. package/lib/services/configuration.spec.js +5 -7
  79. package/lib/services/configuration.spec.js.map +1 -1
  80. package/lib/services/cron.spec.js +3 -4
  81. package/lib/services/cron.spec.js.map +1 -1
  82. package/lib/services/cryptoservice.d.ts +2 -2
  83. package/lib/services/cryptoservice.js +5 -2
  84. package/lib/services/cryptoservice.js.map +1 -1
  85. package/lib/services/domainservice.d.ts +113 -0
  86. package/lib/services/domainservice.js +357 -0
  87. package/lib/services/domainservice.js.map +1 -0
  88. package/lib/services/domainservice.spec.d.ts +1 -0
  89. package/lib/services/domainservice.spec.js +334 -0
  90. package/lib/services/domainservice.spec.js.map +1 -0
  91. package/lib/services/echo.d.ts +2 -2
  92. package/lib/services/echo.js.map +1 -1
  93. package/lib/services/echo.spec.js +9 -2
  94. package/lib/services/echo.spec.js.map +1 -1
  95. package/lib/services/filebinary.d.ts +13 -14
  96. package/lib/services/filebinary.js +79 -73
  97. package/lib/services/filebinary.js.map +1 -1
  98. package/lib/services/filebinary.spec.d.ts +5 -0
  99. package/lib/services/filebinary.spec.js +222 -11
  100. package/lib/services/filebinary.spec.js.map +1 -1
  101. package/lib/services/fileconfiguration.js +4 -4
  102. package/lib/services/fileconfiguration.js.map +1 -1
  103. package/lib/services/fileconfiguration.spec.js +23 -24
  104. package/lib/services/fileconfiguration.spec.js.map +1 -1
  105. package/lib/services/invitationservice.d.ts +11 -9
  106. package/lib/services/invitationservice.js +17 -23
  107. package/lib/services/invitationservice.js.map +1 -1
  108. package/lib/services/invitationservice.spec.js +43 -40
  109. package/lib/services/invitationservice.spec.js.map +1 -1
  110. package/lib/services/kubernetesconfiguration.js +12 -22
  111. package/lib/services/kubernetesconfiguration.js.map +1 -1
  112. package/lib/services/kubernetesconfiguration.spec.js +1 -6
  113. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  114. package/lib/services/mailer.js +1 -1
  115. package/lib/services/mailer.js.map +1 -1
  116. package/lib/services/mailer.spec.js +4 -1
  117. package/lib/services/mailer.spec.js.map +1 -1
  118. package/lib/services/oauth.d.ts +17 -9
  119. package/lib/services/oauth.js +30 -4
  120. package/lib/services/oauth.js.map +1 -1
  121. package/lib/services/oauth.spec.js +32 -15
  122. package/lib/services/oauth.spec.js.map +1 -1
  123. package/lib/services/prometheus.spec.js.map +1 -1
  124. package/lib/services/proxy.d.ts +9 -8
  125. package/lib/services/proxy.js +65 -36
  126. package/lib/services/proxy.js.map +1 -1
  127. package/lib/services/proxy.spec.js +28 -2
  128. package/lib/services/proxy.spec.js.map +1 -1
  129. package/lib/services/resource.d.ts +3 -3
  130. package/lib/services/resource.js +4 -3
  131. package/lib/services/resource.js.map +1 -1
  132. package/lib/services/resource.spec.js +3 -3
  133. package/lib/services/resource.spec.js.map +1 -1
  134. package/lib/services/service.d.ts +10 -13
  135. package/lib/services/service.js +29 -13
  136. package/lib/services/service.js.map +1 -1
  137. package/lib/services/service.spec.js +49 -11
  138. package/lib/services/service.spec.js.map +1 -1
  139. package/lib/services/version.d.ts +2 -2
  140. package/lib/services/version.js.map +1 -1
  141. package/lib/stores/aggregator.js +1 -0
  142. package/lib/stores/aggregator.js.map +1 -1
  143. package/lib/stores/aliasstore.d.ts +2 -2
  144. package/lib/stores/aliasstore.js +15 -4
  145. package/lib/stores/aliasstore.js.map +1 -1
  146. package/lib/stores/aliasstore.spec.js +4 -2
  147. package/lib/stores/aliasstore.spec.js.map +1 -1
  148. package/lib/stores/file.d.ts +5 -2
  149. package/lib/stores/file.js +11 -8
  150. package/lib/stores/file.js.map +1 -1
  151. package/lib/stores/file.spec.js +21 -34
  152. package/lib/stores/file.spec.js.map +1 -1
  153. package/lib/stores/mapper.d.ts +4 -2
  154. package/lib/stores/mapper.js +18 -11
  155. package/lib/stores/mapper.js.map +1 -1
  156. package/lib/stores/mapper.spec.js +6 -3
  157. package/lib/stores/mapper.spec.js.map +1 -1
  158. package/lib/stores/memory.d.ts +5 -2
  159. package/lib/stores/memory.js +11 -9
  160. package/lib/stores/memory.js.map +1 -1
  161. package/lib/stores/memory.spec.d.ts +3 -0
  162. package/lib/stores/memory.spec.js +100 -11
  163. package/lib/stores/memory.spec.js.map +1 -1
  164. package/lib/stores/store.d.ts +177 -87
  165. package/lib/stores/store.js +312 -141
  166. package/lib/stores/store.js.map +1 -1
  167. package/lib/stores/store.spec.d.ts +2 -2
  168. package/lib/stores/store.spec.js +54 -38
  169. package/lib/stores/store.spec.js.map +1 -1
  170. package/lib/stores/webdaql/WebdaQLLexer.d.ts +14 -13
  171. package/lib/stores/webdaql/WebdaQLLexer.js +121 -112
  172. package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
  173. package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +14 -13
  174. package/lib/stores/webdaql/WebdaQLParserLexer.js +121 -112
  175. package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
  176. package/lib/stores/webdaql/WebdaQLParserListener.d.ts +15 -3
  177. package/lib/stores/webdaql/WebdaQLParserParser.d.ts +23 -13
  178. package/lib/stores/webdaql/WebdaQLParserParser.js +149 -94
  179. package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
  180. package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +9 -2
  181. package/lib/stores/webdaql/query.d.ts +6 -2
  182. package/lib/stores/webdaql/query.js +14 -1
  183. package/lib/stores/webdaql/query.js.map +1 -1
  184. package/lib/stores/webdaql/query.spec.js +10 -1
  185. package/lib/stores/webdaql/query.spec.js.map +1 -1
  186. package/lib/test.d.ts +48 -19
  187. package/lib/test.js +171 -63
  188. package/lib/test.js.map +1 -1
  189. package/lib/unpackedapplication.d.ts +5 -0
  190. package/lib/unpackedapplication.js +58 -10
  191. package/lib/unpackedapplication.js.map +1 -1
  192. package/lib/utils/context.d.ts +76 -29
  193. package/lib/utils/context.js +91 -55
  194. package/lib/utils/context.js.map +1 -1
  195. package/lib/utils/context.spec.d.ts +9 -1
  196. package/lib/utils/context.spec.js +73 -8
  197. package/lib/utils/context.spec.js.map +1 -1
  198. package/lib/utils/cookie.d.ts +4 -5
  199. package/lib/utils/cookie.js +1 -2
  200. package/lib/utils/cookie.js.map +1 -1
  201. package/lib/utils/cookie.spec.js +5 -3
  202. package/lib/utils/cookie.spec.js.map +1 -1
  203. package/lib/utils/httpcontext.spec.js +9 -3
  204. package/lib/utils/httpcontext.spec.js.map +1 -1
  205. package/lib/utils/serializers.d.ts +46 -17
  206. package/lib/utils/serializers.js +116 -2
  207. package/lib/utils/serializers.js.map +1 -1
  208. package/lib/utils/serializers.spec.js +84 -20
  209. package/lib/utils/serializers.spec.js.map +1 -1
  210. package/lib/utils/session.d.ts +14 -8
  211. package/lib/utils/session.js +14 -3
  212. package/lib/utils/session.js.map +1 -1
  213. package/lib/utils/session.spec.js +6 -1
  214. package/lib/utils/session.spec.js.map +1 -1
  215. package/package.json +16 -10
  216. package/test/cachedapp/webda.config.json +6 -1
  217. package/test/config-cached.json +5 -0
  218. package/test/config-file-missing-file.json +5 -7
  219. package/test/config-file-no-reload.json +5 -7
  220. package/test/config-file-reload.json +5 -7
  221. package/test/config-kube-reload.json +5 -11
  222. package/test/config-reload.json +2 -4
  223. package/test/config.json +12 -2
  224. package/test/moddas/voidstore.js +1 -1
  225. package/test/models/ident.js +6 -4
  226. package/test/models/task.js +4 -4
  227. package/webda.module.json +1587 -1266
@@ -1,14 +1,14 @@
1
- import { Counter, EventWithContext, Histogram, WebdaError } from "../core.js";
2
- import { ConfigurationProvider } from "../index.js";
3
- import { Constructor, CoreModel, CoreModelDefinition } from "../models/coremodel.js";
1
+ import { Counter, EventWithContext, Histogram } from "../core.js";
2
+ import { ConfigurationProvider, WebdaError } from "../index.js";
3
+ import { Constructor, CoreModel, CoreModelDefinition, FilterKeys } from "../models/coremodel.js";
4
4
  import { Service, ServiceParameters } from "../services/service.js";
5
- import { Context, OperationContext } from "../utils/context.js";
5
+ import { OperationContext, WebContext } from "../utils/context.js";
6
6
  import { HttpMethodType } from "../utils/httpcontext.js";
7
7
  import { WebdaQL } from "./webdaql/query.js";
8
- export declare class StoreNotFoundError extends WebdaError {
8
+ export declare class StoreNotFoundError extends WebdaError.CodeError {
9
9
  constructor(uuid: string, storeName: string);
10
10
  }
11
- export declare class UpdateConditionFailError extends WebdaError {
11
+ export declare class UpdateConditionFailError extends WebdaError.CodeError {
12
12
  constructor(uuid: string, conditionField: string, condition: string | Date);
13
13
  }
14
14
  interface EventStore {
@@ -20,6 +20,10 @@ interface EventStore {
20
20
  * Store emitting
21
21
  */
22
22
  store: Store;
23
+ /**
24
+ * Context of the operation
25
+ */
26
+ context?: OperationContext;
23
27
  }
24
28
  /**
25
29
  * Event called before save of an object
@@ -58,6 +62,10 @@ export interface EventStoreAction extends EventWithContext {
58
62
  * Target object unless it is a global action
59
63
  */
60
64
  object?: CoreModel;
65
+ /**
66
+ * Model of the object if global action
67
+ */
68
+ model?: CoreModelDefinition;
61
69
  /**
62
70
  * Emitting store
63
71
  */
@@ -99,7 +107,7 @@ export interface EventStorePatchUpdated extends EventStoreUpdated {
99
107
  /**
100
108
  * Event called after partial update of an object
101
109
  */
102
- export interface EventStorePartialUpdated {
110
+ export interface EventStorePartialUpdated<T extends CoreModel = CoreModel> {
103
111
  /**
104
112
  * Object uuid
105
113
  */
@@ -107,7 +115,7 @@ export interface EventStorePartialUpdated {
107
115
  /**
108
116
  * Emitting store
109
117
  */
110
- store: Store;
118
+ store: Store<T>;
111
119
  /**
112
120
  * Update date
113
121
  */
@@ -119,7 +127,7 @@ export interface EventStorePartialUpdated {
119
127
  /**
120
128
  * If incremental update
121
129
  */
122
- increment?: {
130
+ increments?: {
123
131
  /**
124
132
  * Increment value
125
133
  */
@@ -128,7 +136,7 @@ export interface EventStorePartialUpdated {
128
136
  * Property to increment
129
137
  */
130
138
  property: string;
131
- };
139
+ }[];
132
140
  /**
133
141
  * Add item to a collection
134
142
  */
@@ -178,6 +186,10 @@ export interface EventStoreQuery {
178
186
  * The parsed query by our grammar
179
187
  */
180
188
  parsedQuery: WebdaQL.Query;
189
+ /**
190
+ * Context in which the query was run
191
+ */
192
+ context: OperationContext;
181
193
  }
182
194
  /**
183
195
  * Event sent when query is resolved
@@ -269,7 +281,11 @@ export interface EventStoreWebDelete extends EventWithContext {
269
281
  */
270
282
  store: Store;
271
283
  }
272
- export type ExposeParameters = {
284
+ /**
285
+ * @deprecated Store should not be exposed directly anymore
286
+ * You should use the DomainService instead
287
+ */
288
+ export type StoreExposeParameters = {
273
289
  /**
274
290
  * URL endpoint to use to expose REST Resources API
275
291
  *
@@ -342,18 +358,16 @@ export declare class StoreParameters extends ServiceParameters {
342
358
  * @default "Webda/CoreModel"
343
359
  */
344
360
  model?: string;
345
- /**
346
- * Different models managed by this store
347
- */
348
- models?: string[];
349
361
  /**
350
362
  * async delete
351
363
  */
352
364
  asyncDelete: boolean;
353
365
  /**
354
366
  * Expose the service to an urls
367
+ *
368
+ * @deprecated will probably be removed in 4.0 in favor of Expose annotation
355
369
  */
356
- expose?: ExposeParameters;
370
+ expose?: StoreExposeParameters;
357
371
  /**
358
372
  * Allow to load object that does not have the type data
359
373
  *
@@ -383,20 +397,11 @@ export declare class StoreParameters extends ServiceParameters {
383
397
  */
384
398
  slowQueryThreshold: number;
385
399
  /**
386
- * Parent of the store
387
- *
388
- * If parent is specified the url route is relative to it
400
+ * Model Aliases to allow easier rename of Model
389
401
  */
390
- parent?: {
391
- name: string;
392
- condition: string;
402
+ modelAliases?: {
403
+ [key: string]: string;
393
404
  };
394
- /**
395
- * For future use in our GraphQL api
396
- *
397
- * Expose this store in the graphql
398
- */
399
- graphql?: boolean;
400
405
  constructor(params: any, service: Service<any>);
401
406
  }
402
407
  export type StoreEvents = {
@@ -477,39 +482,31 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
477
482
  /**
478
483
  * Contains the current model
479
484
  */
480
- _model: CoreModelDefinition;
485
+ _model: CoreModelDefinition<T>;
481
486
  /**
482
- * Models of this store
487
+ * Store teh manager hierarchy with their depth
483
488
  */
484
- _models: CoreModelDefinition[];
489
+ _modelsHierarchy: {
490
+ [key: string]: number;
491
+ };
485
492
  /**
486
493
  * Contains the current model type
487
494
  */
488
495
  _modelType: string;
489
- /**
490
- * Contain the model update date
491
- */
492
- _lastUpdateField: string;
493
- /**
494
- * Contain the model creation date
495
- */
496
- _creationDateField: string;
497
496
  /**
498
497
  * Contain the model uuid field
499
498
  */
500
499
  protected _uuidField: string;
501
500
  /**
502
501
  * Add metrics counter
502
+ * ' UNION SELECT name, tbl_name as email, "" as col1, "" as col2, "" as col3, "" as col4, "" as col5, "" as col6, "" as col7, "" as col8 FROM sqlite_master --
503
+ * {"email":"' UNION SELECT name as profileImage, tbl_name as email, '' AS column3 FROM sqlite_master --","password":"we"}
503
504
  */
504
505
  metrics: {
505
506
  operations_total: Counter;
506
507
  slow_queries_total: Counter;
507
508
  queries: Histogram;
508
509
  };
509
- /**
510
- * The parent store if it is nested
511
- */
512
- parent?: Store;
513
510
  /**
514
511
  * Load the parameters for a service
515
512
  */
@@ -530,7 +527,6 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
530
527
  * @returns
531
528
  */
532
529
  getModel(): CoreModelDefinition;
533
- getLastUpdateField(): string;
534
530
  /**
535
531
  * Return if a model is handled by the store
536
532
  * @param model
@@ -551,13 +547,6 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
551
547
  * @returns
552
548
  */
553
549
  getObject(uid: string): Promise<T>;
554
- /**
555
- * Get the full url with the nested parent
556
- * @param url
557
- * @param methods
558
- * @param depth
559
- */
560
- getParentUrl(depth?: number): string;
561
550
  /**
562
551
  * @override
563
552
  */
@@ -570,7 +559,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
570
559
  * OVerwrite the model
571
560
  * Used mainly in test
572
561
  */
573
- setModel(model: CoreModelDefinition): void;
562
+ setModel(model: CoreModelDefinition<T>): void;
574
563
  /**
575
564
  * We should ignore exception from the store
576
565
  */
@@ -598,9 +587,46 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
598
587
  * @param store
599
588
  */
600
589
  addReverseMap(prop: string, store: MappingService): void;
601
- incrementAttribute(uid: string, prop: string, value: number): Promise<void | any[]>;
602
- upsertItemToCollection(uid: string, prop: string, item: any, index?: number, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<void>;
603
- deleteItemFromCollection(uid: string, prop: string, index: number, itemWriteCondition: any, itemWriteConditionField?: string): Promise<void>;
590
+ /**
591
+ * Increment attributes of an object
592
+ *
593
+ * @param uid
594
+ * @param info
595
+ * @returns
596
+ */
597
+ incrementAttributes<FK extends FilterKeys<T, number>>(uid: string, info: {
598
+ property: FK;
599
+ value: number;
600
+ }[]): Promise<any[]>;
601
+ /**
602
+ * Helper function that call incrementAttributes
603
+ * @param uid
604
+ * @param prop
605
+ * @param value
606
+ * @returns
607
+ */
608
+ incrementAttribute<FK extends FilterKeys<T, number>>(uid: string, prop: FK, value: number): Promise<any[]>;
609
+ /**
610
+ * Add or update an item to an array in the model
611
+ *
612
+ * @param uid of the model
613
+ * @param prop of the model to add in
614
+ * @param item to add in the array
615
+ * @param index if specified update item in this index
616
+ * @param itemWriteCondition value of the condition to test (in case of update)
617
+ * @param itemWriteConditionField field to read the condition from (in case of update)
618
+ */
619
+ upsertItemToCollection<FK extends FilterKeys<T, Array<any>>>(uid: string, prop: FK, item: any, index?: number, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<void>;
620
+ /**
621
+ * Remove an item from an array in the model
622
+ *
623
+ * @param uid of the model
624
+ * @param prop of the model to remove from
625
+ * @param index of the item to remove in the array
626
+ * @param itemWriteCondition value of the condition
627
+ * @param itemWriteConditionField field to read the condition from
628
+ */
629
+ deleteItemFromCollection<FK extends FilterKeys<T, Array<any>>>(uid: string, prop: FK, index: number, itemWriteCondition: any, itemWriteConditionField?: string): Promise<void>;
604
630
  /**
605
631
  * Get all results without pagination
606
632
  *
@@ -609,20 +635,26 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
609
635
  * @param query
610
636
  * @param context
611
637
  */
612
- queryAll(query: string, context?: Context): Promise<T[]>;
638
+ queryAll(query: string, context?: OperationContext): Promise<T[]>;
639
+ /**
640
+ * Check that __type Comparison is only used with = and CONTAINS
641
+ * If CONTAINS is used, move __type to __types
642
+ * If __type = store._model, remove it
643
+ */
644
+ queryTypeUpdater(query: WebdaQL.Query): WebdaQL.Query;
613
645
  /**
614
646
  * Query store with WebdaQL
615
647
  * @param query
616
648
  * @param context to apply permission
617
649
  */
618
- query(query: string, context?: Context): Promise<{
650
+ query(query: string, context?: OperationContext): Promise<{
619
651
  results: T[];
620
652
  continuationToken?: string;
621
653
  }>;
622
654
  /**
623
655
  * Expose query to http
624
656
  */
625
- protected httpQuery(ctx: Context): Promise<void>;
657
+ httpQuery(ctx: WebContext): Promise<void>;
626
658
  /**
627
659
  * Save an object
628
660
  *
@@ -632,8 +664,14 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
632
664
  *
633
665
  * Might want to rename to create
634
666
  */
635
- save(object: any, ctx?: Context): Promise<T>;
636
- create(object: any, ctx?: Context): Promise<any>;
667
+ save(object: any, ctx?: OperationContext): Promise<T>;
668
+ /**
669
+ *
670
+ * @param object
671
+ * @param ctx
672
+ * @returns
673
+ */
674
+ create(object: any, ctx?: OperationContext): Promise<any>;
637
675
  /**
638
676
  * Patch an object
639
677
  *
@@ -641,7 +679,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
641
679
  * @param reverseMap
642
680
  * @returns
643
681
  */
644
- patch(object: Partial<T>, reverseMap?: boolean, conditionField?: string | null, conditionValue?: any): Promise<T | undefined>;
682
+ patch<FK extends keyof T>(object: Partial<T>, reverseMap?: boolean, conditionField?: FK | null, conditionValue?: any): Promise<T | undefined>;
645
683
  /**
646
684
  * Check if an UpdateCondition is met
647
685
  * @param model
@@ -649,7 +687,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
649
687
  * @param condition
650
688
  * @param uid
651
689
  */
652
- checkUpdateCondition(model: T, conditionField?: string, condition?: any, uid?: string): void;
690
+ checkUpdateCondition<CK extends keyof T>(model: T, conditionField?: CK, condition?: any, uid?: string): void;
653
691
  /**
654
692
  * Check if an UpdateCondition is met
655
693
  * @param model
@@ -657,7 +695,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
657
695
  * @param condition
658
696
  * @param uid
659
697
  */
660
- checkCollectionUpdateCondition(model: T, collection: string, conditionField?: string, condition?: any, index?: number): void;
698
+ checkCollectionUpdateCondition<FK extends FilterKeys<T, Array<any>>, CK extends keyof T>(model: T, collection: FK, conditionField?: CK, condition?: any, index?: number): void;
661
699
  /**
662
700
  * Update conditionally
663
701
  * @param uuid
@@ -665,7 +703,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
665
703
  * @param conditionField
666
704
  * @param condition
667
705
  */
668
- conditionalPatch(uuid: string, updates: any, conditionField: any, condition: any): Promise<boolean>;
706
+ conditionalPatch<CK extends keyof T>(uuid: string, updates: Partial<T>, conditionField: CK, condition: any): Promise<boolean>;
669
707
  /**
670
708
  *
671
709
  * @param model
@@ -676,7 +714,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
676
714
  * @param itemWriteConditionField
677
715
  * @param updateDate
678
716
  */
679
- simulateUpsertItemToCollection(model: T, prop: string, item: any, updateDate: Date, index?: number, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<void>;
717
+ simulateUpsertItemToCollection<FK extends FilterKeys<T, Array<any>>>(model: T, prop: FK, item: any, updateDate: Date, index?: number, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<void>;
680
718
  /**
681
719
  * Update an object
682
720
  *
@@ -686,7 +724,45 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
686
724
  * @param {Boolean} reverseMap internal use only, for disable map resolution
687
725
  * @return {Promise} with saved object
688
726
  */
689
- update(object: any, reverseMap?: boolean, partial?: boolean, conditionField?: string | null, conditionValue?: any): Promise<T | undefined>;
727
+ update<CK extends keyof T>(object: any, reverseMap?: boolean, partial?: boolean, conditionField?: CK | null, conditionValue?: any): Promise<T | undefined>;
728
+ /**
729
+ * Manage the store migration for __type case sensitivity
730
+ */
731
+ v3Migration(): Promise<void>;
732
+ /**
733
+ *
734
+ */
735
+ recomputeTypeShortId(): Promise<void>;
736
+ /**
737
+ * Ensure model aliases are not used in this store
738
+ *
739
+ * So alias can be cleaned
740
+ */
741
+ cleanModelAliases(): Promise<void>;
742
+ /**
743
+ * Recompute type case
744
+ */
745
+ recomputeTypeCase(): Promise<void>;
746
+ /**
747
+ * Recompute the __types for all objects (storeMigration.Registry.typesCompute)
748
+ */
749
+ recomputeTypes(): Promise<void>;
750
+ /**
751
+ * Delete a migration
752
+ * @param name
753
+ */
754
+ cancelMigration(name: string): Promise<void>;
755
+ /**
756
+ * Get a migration
757
+ * @param name
758
+ */
759
+ getMigration(name: string): Promise<any>;
760
+ /**
761
+ * Add a migration mechanism to store
762
+ * @param name
763
+ * @param patcher
764
+ */
765
+ migration(name: string, patcher: (object: T) => Promise<Partial<T> | undefined>, batchSize?: number): Promise<void>;
690
766
  /**
691
767
  * Remove an attribute from an object
692
768
  *
@@ -694,7 +770,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
694
770
  * @param attribute
695
771
  * @returns
696
772
  */
697
- removeAttribute(uuid: string, attribute: string, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<void>;
773
+ removeAttribute<CK extends keyof T>(uuid: string, attribute: CK, itemWriteCondition?: any, itemWriteConditionField?: CK): Promise<void>;
698
774
  /**
699
775
  * Cascade delete a related object
700
776
  *
@@ -716,7 +792,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
716
792
  * @param {Boolean} delete sync even if asyncDelete is active
717
793
  * @return {Promise} the deletion promise
718
794
  */
719
- delete(uid: string | T, writeCondition?: any, writeConditionField?: string, sync?: boolean): Promise<void>;
795
+ delete<CK extends keyof T>(uid: string | T, writeCondition?: any, writeConditionField?: CK, sync?: boolean): Promise<void>;
720
796
  /**
721
797
  * By default we cannot know if the store will trigger or not
722
798
  *
@@ -737,7 +813,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
737
813
  * @param uuid
738
814
  * @param data
739
815
  */
740
- put(uuid: string, data: any): Promise<T>;
816
+ put(uuid: string, data: Partial<T>): Promise<T>;
741
817
  /**
742
818
  * Get an object
743
819
  *
@@ -755,7 +831,7 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
755
831
  * @param value new value
756
832
  * @returns
757
833
  */
758
- setAttribute(uid: string, property: string, value: any): Promise<void>;
834
+ setAttribute<CK extends keyof T>(uid: string, property: CK, value: any): Promise<void>;
759
835
  /**
760
836
  * @override
761
837
  */
@@ -767,40 +843,52 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
767
843
  * Handle POST
768
844
  * @param ctx
769
845
  */
770
- httpCreate(ctx: Context): Promise<void>;
846
+ httpCreate(ctx: WebContext): Promise<void>;
847
+ /**
848
+ * Create a new object based on the context
849
+ * @param ctx
850
+ * @param model
851
+ */
852
+ operationCreate(ctx: OperationContext, model: string): Promise<void>;
771
853
  /**
772
854
  * Handle obect action
773
855
  * @param ctx
774
856
  */
775
- httpAction(ctx: Context): Promise<void>;
857
+ httpAction(ctx: WebContext): Promise<void>;
776
858
  /**
777
859
  * Handle collection action
778
860
  * @param ctx
779
861
  */
780
- httpGlobalAction(ctx: Context): Promise<void>;
862
+ httpGlobalAction(ctx: WebContext, model?: CoreModelDefinition): Promise<void>;
781
863
  /**
782
864
  * Handle HTTP Update for an object
783
865
  *
784
866
  * @param ctx context of the request
785
867
  */
786
- httpUpdate(ctx: Context): Promise<void>;
868
+ httpUpdate(ctx: WebContext): Promise<void>;
787
869
  /**
788
870
  * Handle GET on object
789
871
  *
790
872
  * @param ctx context of the request
791
873
  */
792
- httpGet(ctx: Context): Promise<void>;
874
+ httpGet(ctx: WebContext): Promise<void>;
793
875
  /**
794
876
  * Handle HTTP request
795
877
  *
796
878
  * @param ctx context of the request
797
879
  * @returns
798
880
  */
799
- httpRoute(ctx: Context): Promise<void>;
881
+ httpDelete(ctx: WebContext): Promise<void>;
800
882
  /**
801
883
  * Return the model uuid field
802
884
  */
803
885
  getUuidField(): string;
886
+ /**
887
+ * Check if an object exists
888
+ * @abstract
889
+ * @params {String} uuid of the object or the object
890
+ */
891
+ exists(uid: string | CoreModel): Promise<boolean>;
804
892
  /**
805
893
  * Search within the store
806
894
  */
@@ -808,9 +896,8 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
808
896
  /**
809
897
  * Check if an object exists
810
898
  * @abstract
811
- * @params {String} uuid of the object
812
899
  */
813
- abstract exists(uid: string): Promise<boolean>;
900
+ abstract _exists(uid: string): Promise<boolean>;
814
901
  /**
815
902
  * The underlying store should recheck writeCondition only if it does not require
816
903
  * another get()
@@ -819,14 +906,14 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
819
906
  * @param writeCondition
820
907
  * @param itemWriteConditionField
821
908
  */
822
- abstract _delete(uid: string, writeCondition?: any, itemWriteConditionField?: string): Promise<void>;
909
+ protected abstract _delete(uid: string, writeCondition?: any, itemWriteConditionField?: string): Promise<void>;
823
910
  /**
824
911
  * Retrieve an element from the store
825
912
  *
826
913
  * @param uid to retrieve
827
914
  * @param raiseIfNotFound raise an StoreNotFound exception if not found
828
915
  */
829
- abstract _get(uid: string, raiseIfNotFound?: boolean): Promise<T>;
916
+ protected abstract _get(uid: string, raiseIfNotFound?: boolean): Promise<T>;
830
917
  /**
831
918
  * Get an object
832
919
  *
@@ -834,14 +921,14 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
834
921
  * @return {Promise} the objects retrieved ( can be [] if not found )
835
922
  */
836
923
  abstract getAll(list?: string[]): Promise<T[]>;
837
- abstract _update(object: any, uid: string, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<any>;
838
- abstract _patch(object: any, uid: string, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<any>;
839
- abstract _removeAttribute(uuid: string, attribute: string, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<void>;
924
+ protected abstract _update(object: any, uid: string, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<any>;
925
+ protected abstract _patch(object: any, uid: string, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<any>;
926
+ protected abstract _removeAttribute(uuid: string, attribute: string, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<void>;
840
927
  /**
841
928
  * Save within the store
842
929
  * @param object
843
930
  */
844
- abstract _save(object: T): Promise<any>;
931
+ protected abstract _save(object: T): Promise<any>;
845
932
  /**
846
933
  * Increment the attribute
847
934
  * @param uid
@@ -849,8 +936,11 @@ declare abstract class Store<T extends CoreModel = CoreModel, K extends StorePar
849
936
  * @param value
850
937
  * @param updateDate
851
938
  */
852
- abstract _incrementAttribute(uid: string, prop: string, value: number, updateDate: Date): Promise<any>;
853
- abstract _upsertItemToCollection(uid: string, prop: string, item: any, index: number, itemWriteCondition: any, itemWriteConditionField: string, updateDate: Date): Promise<any>;
854
- abstract _deleteItemFromCollection(uid: string, prop: string, index: number, itemWriteCondition: any, itemWriteConditionField: string, updateDate: Date): Promise<any>;
939
+ protected abstract _incrementAttributes(uid: string, params: {
940
+ property: string;
941
+ value: number;
942
+ }[], updateDate: Date): Promise<any>;
943
+ protected abstract _upsertItemToCollection(uid: string, prop: string, item: any, index: number, itemWriteCondition: any, itemWriteConditionField: string, updateDate: Date): Promise<any>;
944
+ protected abstract _deleteItemFromCollection(uid: string, prop: string, index: number, itemWriteCondition: any, itemWriteConditionField: string, updateDate: Date): Promise<any>;
855
945
  }
856
946
  export { Store };