@webda/core 2.4.1 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +7 -7
  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,45 +1,32 @@
1
+ import { JSONSchema7 } from "json-schema";
2
+ import { ModelGraph, ModelsTree } from "../application.js";
1
3
  import { Core } from "../core.js";
2
4
  import { Service } from "../services/service.js";
3
5
  import { Store } from "../stores/store.js";
4
- import { Context, OperationContext } from "../utils/context.js";
6
+ import { OperationContext } from "../utils/context.js";
5
7
  import { HttpMethodType } from "../utils/httpcontext.js";
6
- type ModelLoader<T> = {
7
- refresh: () => Promise<T>;
8
- getUuid(): string;
9
- };
10
- type ModelLinker<T> = string & ModelLoader<T>;
11
- /**
12
- * Load related objects
13
- */
14
- export type ModelLinked<T> = (query?: string) => Promise<T[]>;
15
- /**
16
- * Mapper attribute (target of a Mapper service)
17
- */
18
- export type ModelMapper<T, K extends keyof T> = Pick<T, K> & ModelLoader<T>;
8
+ import { ModelActions, RawModel } from "./relations.js";
19
9
  /**
20
- * Define a ModelMap attribute
21
- */
22
- export type ModelMappers<T, _FK extends keyof T, K extends keyof T> = ModelMapper<T, K>[];
23
- /**
24
- * Define a link to 1:n relation
25
- */
26
- export type ModelLink<T, _FK extends keyof T = any> = ModelLinker<T>;
27
- /**
28
- * Define several links for n:m relation
10
+ * Expose the model through API or GraphQL if it exists
11
+ * The model will be exposed using its class name + 's'
12
+ * If you need to have a specific plural, use the annotation WebdaPlural
13
+ * to define the plural name
14
+ *
15
+ * @returns
29
16
  */
30
- export type ModelLinks<T, _FK extends keyof T> = ModelLinker<T>[] | {
31
- [key: string]: ModelLinker<T>;
32
- };
17
+ export declare function Expose(params?: Partial<ExposeParameters>): (target: CoreModelDefinition) => void;
33
18
  /**
34
- * Define the parent of the model
19
+ * Filter type keys by type
35
20
  */
36
- export type ModelParent<T> = ModelLink<T, any>;
21
+ export type FilterKeys<T extends CoreModel, K> = {
22
+ [L in keyof T]: T[L] extends K ? L : never;
23
+ }[keyof T];
37
24
  /**
38
- * Define an export of actions from Model
25
+ * Define an Action on a model
26
+ *
27
+ * It is basically a method designed to be called by the API or external
28
+ * systems
39
29
  */
40
- export type ModelActions = {
41
- [key: string]: ModelAction;
42
- };
43
30
  export interface ModelAction {
44
31
  /**
45
32
  * Method for the route
@@ -59,8 +46,58 @@ export interface ModelAction {
59
46
  */
60
47
  openapi?: any;
61
48
  }
49
+ /**
50
+ * Expose parameters for the model
51
+ */
52
+ export interface ExposeParameters {
53
+ /**
54
+ * If model have parent but you still want it to be exposed as root
55
+ * in domain-like service: DomainService, GraphQL
56
+ *
57
+ * It would create alias for the model in the root too
58
+ */
59
+ root?: boolean;
60
+ /**
61
+ * You can select to not expose some methods like create, update, delete, get, query
62
+ */
63
+ restrict: {
64
+ /**
65
+ * Create a new object
66
+ */
67
+ create?: boolean;
68
+ /**
69
+ * Update an existing object
70
+ *
71
+ * Includes PUT and PATCH
72
+ */
73
+ update?: boolean;
74
+ /**
75
+ * Query the object
76
+ */
77
+ query?: boolean;
78
+ /**
79
+ * Get a single object
80
+ */
81
+ get?: boolean;
82
+ /**
83
+ * Delete an object
84
+ */
85
+ delete?: boolean;
86
+ /**
87
+ * Do not create operations for the model
88
+ */
89
+ operation?: boolean;
90
+ };
91
+ }
92
+ /**
93
+ *
94
+ */
62
95
  export interface CoreModelDefinition<T extends CoreModel = CoreModel> {
63
96
  new (): T;
97
+ /**
98
+ * If the model have some Expose annotation
99
+ */
100
+ Expose?: ExposeParameters;
64
101
  /**
65
102
  * Create a CoreModel object loaded with the content of object
66
103
  *
@@ -70,28 +107,73 @@ export interface CoreModelDefinition<T extends CoreModel = CoreModel> {
70
107
  * @param object to load data from
71
108
  * @param context if the data is unsafe from http
72
109
  */
73
- factory(model: new () => T, object: any, context?: Context): T;
110
+ factory(model: new () => T, object: any, context?: OperationContext): T;
111
+ /**
112
+ * Get the model actions
113
+ */
74
114
  getActions(): {
75
115
  [key: string]: ModelAction;
76
116
  };
117
+ /**
118
+ * Get the model store
119
+ */
120
+ store(): Store<T>;
121
+ /**
122
+ * Get the model schema
123
+ */
124
+ getSchema(): JSONSchema7;
125
+ /**
126
+ * Get the model hierarchy
127
+ */
128
+ getHierarchy(): {
129
+ ancestors: string[];
130
+ children: ModelsTree;
131
+ };
132
+ /**
133
+ * Get the model relations
134
+ */
135
+ getRelations(): ModelGraph;
136
+ /**
137
+ * Get Model identifier
138
+ */
139
+ getIdentifier(short?: boolean): string;
140
+ /**
141
+ * Complete uuid useful to implement uuid prefix or suffix
142
+ * @param uid
143
+ */
144
+ completeUid(uid: string): string;
145
+ /**
146
+ * Get the model uuid field if you do not want to use the uuid field
147
+ */
77
148
  getUuidField(): string;
78
- getLastUpdateField(): string;
79
- getCreationField(): string;
80
- getPermissionQuery(context?: Context): null | {
149
+ /**
150
+ * Permission query for the model
151
+ * @param context
152
+ */
153
+ getPermissionQuery(context?: OperationContext): null | {
81
154
  partial: boolean;
82
155
  query: string;
83
156
  };
157
+ /**
158
+ * Reference to an object without doing a DB request yet
159
+ */
160
+ ref: typeof CoreModel.ref;
161
+ /**
162
+ * Create a new model
163
+ * @param this
164
+ * @param data
165
+ */
166
+ create<T extends CoreModel>(this: Constructor<T>, data: RawModel<T>): Promise<T>;
167
+ /**
168
+ * Query the model
169
+ * @param query
170
+ */
171
+ query(query?: string, includeSubclass?: boolean, context?: OperationContext): Promise<{
172
+ results: T[];
173
+ continuationToken?: string;
174
+ }>;
84
175
  }
85
- export type Constructor<T> = new (...args: any[]) => T;
86
- /**
87
- * Sent if action required attached CoreModel is trigger
88
- * A Model cannot be detached anymore
89
- *
90
- * @deprecated
91
- */
92
- export declare class CoreModelUnattachedError extends Error {
93
- constructor();
94
- }
176
+ export type Constructor<T, K extends Array<any> = []> = new (...args: K) => T;
95
177
  /**
96
178
  * Make a property hidden from json
97
179
  * @param target
@@ -107,6 +189,56 @@ export declare function Action(options?: {
107
189
  methods?: HttpMethodType[];
108
190
  openapi?: any;
109
191
  }): (target: any, propertyKey: string) => void;
192
+ export declare class ModelRef<T extends CoreModel> {
193
+ protected uuid: string;
194
+ protected store: Store<T>;
195
+ protected model: CoreModelDefinition<T>;
196
+ constructor(uuid: string, model: CoreModelDefinition<T>);
197
+ get(): Promise<T>;
198
+ set(id: string | T): void;
199
+ toString(): string;
200
+ toJSON(): string;
201
+ getUuid(): string;
202
+ deleteItemFromCollection(prop: FilterKeys<T, any[]>, index: number, itemWriteCondition: any, itemWriteConditionField?: string): Promise<void>;
203
+ upsertItemToCollection(prop: FilterKeys<T, any[]>, item: any, index?: number, itemWriteCondition?: any, itemWriteConditionField?: string): Promise<void>;
204
+ exists(): Promise<boolean>;
205
+ delete(): Promise<void>;
206
+ conditionalPatch(updates: Partial<T>, conditionField: any, condition: any): Promise<boolean>;
207
+ patch(updates: Partial<T>): Promise<boolean>;
208
+ setAttribute(attribute: keyof T, value: any): Promise<void>;
209
+ removeAttribute(attribute: keyof T, itemWriteCondition?: any, itemWriteConditionField?: keyof T): Promise<void>;
210
+ incrementAttributes(info: {
211
+ property: FilterKeys<T, number>;
212
+ value: number;
213
+ }[]): Promise<any[]>;
214
+ }
215
+ export declare class ModelRefWithCreate<T extends CoreModel> extends ModelRef<T> {
216
+ /**
217
+ * Allow to create a model
218
+ * @param defaultValue
219
+ * @param context
220
+ * @param withSave
221
+ * @returns
222
+ */
223
+ create(defaultValue: RawModel<T>, context?: OperationContext, withSave?: boolean): Promise<T>;
224
+ /**
225
+ * Load a model from the known store
226
+ *
227
+ * @param this the class from which the static is called
228
+ * @param id of the object to load
229
+ * @param defaultValue if object not found return a default object
230
+ * @param context to set on the object
231
+ * @returns
232
+ */
233
+ getOrCreate(defaultValue: RawModel<T>, context?: OperationContext, withSave?: boolean): Promise<T>;
234
+ }
235
+ export declare class ModelRefCustom<T extends CoreModel> extends ModelRef<T> {
236
+ uuid: string;
237
+ constructor(uuid: string, model: CoreModelDefinition<T>, data: any);
238
+ toJSON(): any;
239
+ getUuid(): string;
240
+ }
241
+ export type ModelRefCustomProperties<T extends CoreModel, K> = ModelRefCustom<T> & K;
110
242
  /**
111
243
  * Basic Object in Webda
112
244
  *
@@ -121,11 +253,15 @@ declare class CoreModel {
121
253
  /**
122
254
  * Class reference to the object
123
255
  */
124
- __class: any;
256
+ __class: CoreModelDefinition;
125
257
  /**
126
258
  * Type name
127
259
  */
128
260
  __type: string;
261
+ /**
262
+ * Types name
263
+ */
264
+ __types: string[];
129
265
  /**
130
266
  * Object context
131
267
  *
@@ -154,12 +290,66 @@ declare class CoreModel {
154
290
  */
155
291
  __deleted: boolean;
156
292
  constructor();
293
+ /**
294
+ *
295
+ * @returns
296
+ */
297
+ static getRelations(): ModelGraph;
157
298
  /**
158
299
  * Get Store for this model
159
300
  * @param this
160
301
  * @returns
161
302
  */
162
303
  static store<T extends CoreModel>(this: Constructor<T>): Store<T>;
304
+ /**
305
+ * Complete the uid with prefix if any
306
+ *
307
+ * Useful when object are stored with a prefix for full uuid
308
+ * @param uid
309
+ * @returns
310
+ */
311
+ static completeUid(uid: string): string;
312
+ /**
313
+ * Return the known schema
314
+ * @returns
315
+ */
316
+ static getSchema(): JSONSchema7;
317
+ /**
318
+ * Get a reference to a model
319
+ * @param this
320
+ * @param uid
321
+ * @returns
322
+ */
323
+ static ref<T extends CoreModel>(this: Constructor<T>, uid: string): ModelRefWithCreate<T>;
324
+ /**
325
+ * Get a reference to a model
326
+ * @param this
327
+ * @param uid
328
+ * @returns
329
+ */
330
+ static create<T extends CoreModel>(this: Constructor<T>, data: RawModel<T>): Promise<T>;
331
+ /**
332
+ * Get identifier for this model
333
+ * @returns
334
+ */
335
+ static getIdentifier(short?: boolean): string;
336
+ /**
337
+ * Get the model hierarchy
338
+ *
339
+ * Ancestors will contain every model it inherits from
340
+ * Children will contain every model that inherits from this model in a tree structure
341
+ */
342
+ static getHierarchy(): {
343
+ ancestors: string[];
344
+ children: ModelsTree;
345
+ };
346
+ /**
347
+ * Unflat an object
348
+ * @param data
349
+ * @param split
350
+ * @returns
351
+ */
352
+ static unflat<T = any>(data: any, split?: string): T;
163
353
  /**
164
354
  * Create subobject for a model
165
355
  *
@@ -169,13 +359,36 @@ declare class CoreModel {
169
359
  * @returns
170
360
  */
171
361
  unflat<T>(split?: string): T;
362
+ /**
363
+ * Flat an object into another
364
+ *
365
+ * {
366
+ * a: {
367
+ * b: 1
368
+ * },
369
+ * c: 1
370
+ * }
371
+ *
372
+ * become
373
+ *
374
+ * {
375
+ * "a#b": 1
376
+ * "c": 1
377
+ * }
378
+ *
379
+ * @param target
380
+ * @param data
381
+ * @param split
382
+ * @param prefix
383
+ */
384
+ static flat(target: any, data: any, split?: string, prefix?: string): any;
172
385
  /**
173
386
  * Query for models
174
387
  * @param this
175
388
  * @param id
176
389
  * @returns
177
390
  */
178
- static query<T extends CoreModel>(this: Constructor<T>, query: string): Promise<{
391
+ static query<T extends CoreModel>(this: Constructor<T>, query?: string, includeSubclass?: boolean, context?: OperationContext): Promise<{
179
392
  results: T[];
180
393
  continuationToken?: string;
181
394
  }>;
@@ -212,27 +425,20 @@ declare class CoreModel {
212
425
  * @param context of the query
213
426
  * @returns
214
427
  */
215
- static getPermissionQuery(_ctx: Context): null | {
428
+ static getPermissionQuery(_ctx: OperationContext): null | {
216
429
  partial: boolean;
217
430
  query: string;
218
431
  };
432
+ checkAct(context: OperationContext, action: "create" | "update" | "get" | "delete" | "get_binary" | "detach_binary" | "attach_binary" | "update_binary_metadata" | "subscribe" | string): Promise<void>;
219
433
  /**
220
434
  * By default nothing is permitted on a CoreModel
221
435
  * @returns
222
436
  */
223
- canAct(_ctx: Context, _action: "create" | "update" | "get" | "delete" | "get_binary" | "detach_binary" | "attach_binary" | "update_binary_metadata" | "subscribe" | string): Promise<this>;
437
+ canAct(_context: OperationContext, _action: "create" | "update" | "get" | "delete" | "get_binary" | "detach_binary" | "attach_binary" | "update_binary_metadata" | "subscribe" | string): Promise<string | boolean>;
224
438
  /**
225
439
  * Get the UUID property
226
440
  */
227
441
  static getUuidField(): string;
228
- /**
229
- * Get the UUID property
230
- */
231
- static getLastUpdateField(): string;
232
- /**
233
- * Get the UUID property
234
- */
235
- static getCreationField(): string;
236
442
  /**
237
443
  * Create an object
238
444
  * @returns
@@ -244,16 +450,6 @@ declare class CoreModel {
244
450
  * @returns
245
451
  */
246
452
  static instanceOf(object: any): boolean;
247
- /**
248
- * Return if an object is attached to its store
249
- * @deprecated Will be removed in 3.0
250
- */
251
- isAttached(): boolean;
252
- /**
253
- * Attach an object to a store instance
254
- * @deprecated Will be removed in 3.0
255
- */
256
- attach(store: Store<this>): this;
257
453
  /**
258
454
  * Return a unique reference within the application to the object
259
455
  *
@@ -268,16 +464,7 @@ declare class CoreModel {
268
464
  * @param partials
269
465
  * @returns
270
466
  */
271
- static fromFullUuid<T extends CoreModel = CoreModel>(core: Core, fullUuid: string, partials?: any): Promise<T>;
272
- /**
273
- * Remove all the attribute starting with __
274
- * @param key
275
- * @param value
276
- * @returns
277
- *
278
- * @deprecated
279
- */
280
- _jsonFilter(key: any, value: any): any;
467
+ static fromFullUuid<T extends CoreModel = CoreModel>(fullUuid: string, core?: Core, partials?: any): Promise<T>;
281
468
  /**
282
469
  * Allow to define custom permission per attribute
283
470
  *
@@ -297,7 +484,12 @@ declare class CoreModel {
297
484
  * @param raw data
298
485
  * @param secure if false will ignore any _ variable
299
486
  */
300
- load(raw: Partial<this>, secure?: boolean): this;
487
+ load(raw: RawModel<this>, secure?: boolean): this;
488
+ /**
489
+ * Patch every attribute that is based on a relation
490
+ * to add all the helpers
491
+ */
492
+ protected handleRelations(): void;
301
493
  /**
302
494
  * Context of the request
303
495
  */
@@ -329,23 +521,13 @@ declare class CoreModel {
329
521
  * @throws Error if the object is not coming from a store
330
522
  */
331
523
  delete(): Promise<void>;
332
- /**
333
- * Load a model from the known store
334
- *
335
- * @param this the class from which the static is called
336
- * @param id of the object to load
337
- * @param defaultValue if object not found return a default object
338
- * @param context to set on the object
339
- * @returns
340
- */
341
- static get<T>(this: Constructor<T>, id: string, defaultValue?: Partial<T>, context?: OperationContext): Promise<T>;
342
524
  /**
343
525
  * Patch current object with this update
344
526
  * @param obj
345
527
  * @param conditionField if null no condition used otherwise fallback to lastUpdate
346
528
  * @param conditionValue
347
529
  */
348
- patch(obj: Partial<this>, conditionField?: string | null, conditionValue?: any): Promise<void>;
530
+ patch(obj: Partial<this>, conditionField?: keyof this | null, conditionValue?: any): Promise<void>;
349
531
  /**
350
532
  * Save this object
351
533
  *
@@ -358,7 +540,7 @@ declare class CoreModel {
358
540
  * @param ctx
359
541
  * @param updates
360
542
  */
361
- validate(ctx: Context, updates: any, ignoreRequired?: boolean): Promise<boolean>;
543
+ validate(ctx: OperationContext, updates: any, ignoreRequired?: boolean): Promise<boolean>;
362
544
  /**
363
545
  * Generate uuid for the object
364
546
  *
@@ -426,4 +608,14 @@ declare class CoreModel {
426
608
  */
427
609
  _onUpdated(): Promise<void>;
428
610
  }
429
- export { CoreModel };
611
+ /**
612
+ * CoreModel with a uuid
613
+ */
614
+ declare class UuidModel extends CoreModel {
615
+ uuid: string;
616
+ /**
617
+ * @override
618
+ */
619
+ validate(ctx: OperationContext<any, any>, updates: any, ignoreRequired?: boolean): Promise<boolean>;
620
+ }
621
+ export { CoreModel, UuidModel };