@webda/core 1.2.1 → 1.6.0-beta.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 (199) hide show
  1. package/lib/application.d.ts +3 -0
  2. package/lib/application.js +26 -22
  3. package/lib/application.js.map +1 -1
  4. package/lib/application.spec.js +185 -2
  5. package/lib/application.spec.js.map +1 -1
  6. package/lib/core.d.ts +62 -6
  7. package/lib/core.js +127 -86
  8. package/lib/core.js.map +1 -1
  9. package/lib/core.spec.js +151 -6
  10. package/lib/core.spec.js.map +1 -1
  11. package/lib/index.d.ts +4 -0
  12. package/lib/index.js +4 -0
  13. package/lib/index.js.map +1 -1
  14. package/lib/models/aclmodel.d.ts +42 -3
  15. package/lib/models/aclmodel.js +58 -3
  16. package/lib/models/aclmodel.js.map +1 -1
  17. package/lib/models/aclmodel.spec.js +46 -0
  18. package/lib/models/aclmodel.spec.js.map +1 -1
  19. package/lib/models/coremodel.d.ts +58 -10
  20. package/lib/models/coremodel.js +39 -32
  21. package/lib/models/coremodel.js.map +1 -1
  22. package/lib/models/coremodel.spec.js +68 -6
  23. package/lib/models/coremodel.spec.js.map +1 -1
  24. package/lib/models/ident.d.ts +8 -2
  25. package/lib/models/ident.js.map +1 -1
  26. package/lib/models/ident.spec.js +16 -0
  27. package/lib/models/ident.spec.js.map +1 -1
  28. package/lib/models/ownermodel.d.ts +1 -1
  29. package/lib/models/ownermodel.js.map +1 -1
  30. package/lib/models/ownermodel.spec.js +22 -19
  31. package/lib/models/ownermodel.spec.js.map +1 -1
  32. package/lib/models/user.d.ts +2 -0
  33. package/lib/models/user.js +4 -2
  34. package/lib/models/user.js.map +1 -1
  35. package/lib/models/user.spec.js +9 -2
  36. package/lib/models/user.spec.js.map +1 -1
  37. package/lib/queues/filequeue.d.ts +63 -0
  38. package/lib/queues/filequeue.js +161 -0
  39. package/lib/queues/filequeue.js.map +1 -0
  40. package/lib/queues/filequeue.spec.d.ts +1 -0
  41. package/lib/queues/filequeue.spec.js +90 -0
  42. package/lib/queues/filequeue.spec.js.map +1 -0
  43. package/lib/queues/memoryqueue.d.ts +18 -4
  44. package/lib/queues/memoryqueue.js +20 -13
  45. package/lib/queues/memoryqueue.js.map +1 -1
  46. package/lib/queues/memoryqueue.spec.js +142 -39
  47. package/lib/queues/memoryqueue.spec.js.map +1 -1
  48. package/lib/queues/pubsubservice.d.ts +27 -0
  49. package/lib/queues/pubsubservice.js +21 -0
  50. package/lib/queues/pubsubservice.js.map +1 -0
  51. package/lib/queues/queue.spec.js +16 -7
  52. package/lib/queues/queue.spec.js.map +1 -1
  53. package/lib/queues/queueservice.d.ts +108 -13
  54. package/lib/queues/queueservice.js +100 -36
  55. package/lib/queues/queueservice.js.map +1 -1
  56. package/lib/router.js +4 -6
  57. package/lib/router.js.map +1 -1
  58. package/lib/router.spec.js +27 -2
  59. package/lib/router.spec.js.map +1 -1
  60. package/lib/services/asyncevents.d.ts +110 -5
  61. package/lib/services/asyncevents.js +134 -39
  62. package/lib/services/asyncevents.js.map +1 -1
  63. package/lib/services/asyncevents.spec.js +58 -4
  64. package/lib/services/asyncevents.spec.js.map +1 -1
  65. package/lib/services/authentication.d.ts +57 -5
  66. package/lib/services/authentication.js +93 -84
  67. package/lib/services/authentication.js.map +1 -1
  68. package/lib/services/authentication.spec.js +118 -82
  69. package/lib/services/authentication.spec.js.map +1 -1
  70. package/lib/services/binary.d.ts +175 -48
  71. package/lib/services/binary.js +205 -170
  72. package/lib/services/binary.js.map +1 -1
  73. package/lib/services/binary.spec.d.ts +22 -3
  74. package/lib/services/binary.spec.js +327 -22
  75. package/lib/services/binary.spec.js.map +1 -1
  76. package/lib/services/configuration.d.ts +94 -13
  77. package/lib/services/configuration.js +98 -28
  78. package/lib/services/configuration.js.map +1 -1
  79. package/lib/services/configuration.spec.js +40 -1
  80. package/lib/services/configuration.spec.js.map +1 -1
  81. package/lib/services/cron.d.ts +4 -4
  82. package/lib/services/cron.js +37 -53
  83. package/lib/services/cron.js.map +1 -1
  84. package/lib/services/cron.spec.d.ts +1 -0
  85. package/lib/services/cron.spec.js +76 -0
  86. package/lib/services/cron.spec.js.map +1 -0
  87. package/lib/services/debugmailer.spec.js +18 -4
  88. package/lib/services/debugmailer.spec.js.map +1 -1
  89. package/lib/services/echo.js +22 -13
  90. package/lib/services/echo.js.map +1 -1
  91. package/lib/services/echo.spec.d.ts +1 -0
  92. package/lib/services/echo.spec.js +52 -0
  93. package/lib/services/echo.spec.js.map +1 -0
  94. package/lib/services/filebinary.d.ts +16 -9
  95. package/lib/services/filebinary.js +58 -73
  96. package/lib/services/filebinary.js.map +1 -1
  97. package/lib/services/filebinary.spec.d.ts +8 -1
  98. package/lib/services/filebinary.spec.js +133 -7
  99. package/lib/services/filebinary.spec.js.map +1 -1
  100. package/lib/services/fileconfiguration.d.ts +9 -3
  101. package/lib/services/fileconfiguration.js +13 -6
  102. package/lib/services/fileconfiguration.js.map +1 -1
  103. package/lib/services/fileconfiguration.spec.js +100 -5
  104. package/lib/services/fileconfiguration.spec.js.map +1 -1
  105. package/lib/services/kubernetesconfiguration.d.ts +8 -2
  106. package/lib/services/kubernetesconfiguration.js +16 -5
  107. package/lib/services/kubernetesconfiguration.js.map +1 -1
  108. package/lib/services/kubernetesconfiguration.spec.js +53 -16
  109. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  110. package/lib/services/mailer.d.ts +11 -2
  111. package/lib/services/mailer.js +28 -34
  112. package/lib/services/mailer.js.map +1 -1
  113. package/lib/services/mailer.spec.js +69 -23
  114. package/lib/services/mailer.spec.js.map +1 -1
  115. package/lib/services/oauth.d.ts +5 -2
  116. package/lib/services/oauth.js +22 -8
  117. package/lib/services/oauth.js.map +1 -1
  118. package/lib/services/oauth.spec.js +33 -3
  119. package/lib/services/oauth.spec.js.map +1 -1
  120. package/lib/services/resource.spec.js +39 -2
  121. package/lib/services/resource.spec.js.map +1 -1
  122. package/lib/services/service.d.ts +16 -0
  123. package/lib/services/service.js +47 -6
  124. package/lib/services/service.js.map +1 -1
  125. package/lib/services/service.spec.d.ts +1 -0
  126. package/lib/services/service.spec.js +119 -0
  127. package/lib/services/service.spec.js.map +1 -0
  128. package/lib/stores/aggregator.d.ts +43 -0
  129. package/lib/stores/aggregator.js +106 -0
  130. package/lib/stores/aggregator.js.map +1 -0
  131. package/lib/stores/file.d.ts +49 -11
  132. package/lib/stores/file.js +84 -81
  133. package/lib/stores/file.js.map +1 -1
  134. package/lib/stores/file.spec.d.ts +6 -1
  135. package/lib/stores/file.spec.js +134 -9
  136. package/lib/stores/file.spec.js.map +1 -1
  137. package/lib/stores/mapper.d.ts +151 -0
  138. package/lib/stores/mapper.js +294 -0
  139. package/lib/stores/mapper.js.map +1 -0
  140. package/lib/stores/mapper.spec.d.ts +1 -0
  141. package/lib/stores/mapper.spec.js +55 -0
  142. package/lib/stores/mapper.spec.js.map +1 -0
  143. package/lib/stores/memory.d.ts +52 -7
  144. package/lib/stores/memory.js +71 -33
  145. package/lib/stores/memory.js.map +1 -1
  146. package/lib/stores/memory.spec.d.ts +6 -1
  147. package/lib/stores/memory.spec.js +65 -4
  148. package/lib/stores/memory.spec.js.map +1 -1
  149. package/lib/stores/store.d.ts +263 -126
  150. package/lib/stores/store.js +285 -493
  151. package/lib/stores/store.js.map +1 -1
  152. package/lib/stores/store.spec.d.ts +20 -0
  153. package/lib/stores/store.spec.js +242 -18
  154. package/lib/stores/store.spec.js.map +1 -1
  155. package/lib/test.d.ts +1 -7
  156. package/lib/test.js +3 -12
  157. package/lib/test.js.map +1 -1
  158. package/lib/utils/abstractdeployer.spec.d.ts +1 -0
  159. package/lib/utils/abstractdeployer.spec.js +23 -0
  160. package/lib/utils/abstractdeployer.spec.js.map +1 -0
  161. package/lib/utils/context.d.ts +25 -2
  162. package/lib/utils/context.js +33 -12
  163. package/lib/utils/context.js.map +1 -1
  164. package/lib/utils/context.spec.js +81 -11
  165. package/lib/utils/context.spec.js.map +1 -1
  166. package/lib/utils/cookie.d.ts +12 -0
  167. package/lib/utils/cookie.js +13 -1
  168. package/lib/utils/cookie.js.map +1 -1
  169. package/lib/utils/cookie.spec.js +42 -11
  170. package/lib/utils/cookie.spec.js.map +1 -1
  171. package/lib/utils/logger.d.ts +23 -4
  172. package/lib/utils/logger.js +29 -6
  173. package/lib/utils/logger.js.map +1 -1
  174. package/lib/utils/logger.spec.js +8 -0
  175. package/lib/utils/logger.spec.js.map +1 -1
  176. package/lib/utils/serializers.d.ts +5 -5
  177. package/lib/utils/serializers.js +10 -10
  178. package/lib/utils/serializers.js.map +1 -1
  179. package/lib/utils/serializers.spec.js +41 -16
  180. package/lib/utils/serializers.spec.js.map +1 -1
  181. package/lib/utils/waiter.d.ts +59 -1
  182. package/lib/utils/waiter.js +86 -3
  183. package/lib/utils/waiter.js.map +1 -1
  184. package/lib/utils/waiter.spec.js +48 -4
  185. package/lib/utils/waiter.spec.js.map +1 -1
  186. package/package.json +16 -11
  187. package/test/badapp/package.json +4 -0
  188. package/test/badapp/webda.config.json +1 -0
  189. package/test/cachedapp/webda.config.json +7 -0
  190. package/test/config-file-no-reload.json +70 -0
  191. package/test/config-file-reload.json +7 -1
  192. package/test/config-kube-reload.json +7 -1
  193. package/test/config.json +45 -21
  194. package/test/config.old-default.json +0 -16
  195. package/test/config.old.json +0 -16
  196. package/test/deployments/invalid.json +1 -0
  197. package/test/moddas/fakeservice.js +5 -0
  198. package/test/models/ident.js +10 -14
  199. package/test/models/task.js +2 -4
@@ -1,11 +1,20 @@
1
+ /// <reference types="node" />
2
+ import { Readable } from "stream";
3
+ import { WebdaError } from "..";
1
4
  import { CoreModel } from "../models/coremodel";
2
- import { Store } from "../stores/store";
5
+ import { MappingService, Store } from "../stores/store";
3
6
  import { Context } from "../utils/context";
4
7
  import { Service, ServiceParameters } from "./service";
8
+ /**
9
+ * Represent basic EventBinary
10
+ */
5
11
  export interface EventBinary {
6
12
  object: BinaryMap;
7
13
  service: Binary;
8
14
  }
15
+ /**
16
+ * Emitted when someone download a binary
17
+ */
9
18
  export interface EventBinaryGet extends EventBinary {
10
19
  }
11
20
  export interface EventBinaryUploadSuccess extends EventBinary {
@@ -15,8 +24,52 @@ export interface EventBinaryDelete extends EventBinary {
15
24
  }
16
25
  export interface EventBinaryCreate extends EventBinaryUploadSuccess {
17
26
  }
18
- export interface EventBinaryUpdate extends EventBinaryUploadSuccess {
19
- old: BinaryMap;
27
+ /**
28
+ * Emitted if binary does not exist
29
+ */
30
+ export declare class BinaryNotFoundError extends WebdaError {
31
+ constructor(hash: string, storeName: string);
32
+ }
33
+ /**
34
+ * Represent a file to store
35
+ */
36
+ export interface BinaryFile {
37
+ /**
38
+ * Path on the hard drive
39
+ */
40
+ path?: string;
41
+ /**
42
+ * Content
43
+ */
44
+ buffer?: Buffer;
45
+ /**
46
+ * Current name
47
+ */
48
+ name?: string;
49
+ /**
50
+ * Original name
51
+ */
52
+ originalname?: string;
53
+ /**
54
+ * Size of the binary
55
+ */
56
+ size?: number;
57
+ /**
58
+ * Mimetype of the binary
59
+ */
60
+ mimetype?: string;
61
+ /**
62
+ * Will be computed by the service
63
+ *
64
+ * hash of the content prefixed by 'WEBDA'
65
+ */
66
+ challenge?: string;
67
+ /**
68
+ * Will be computed by the service
69
+ *
70
+ * hash of the content
71
+ */
72
+ hash?: string;
20
73
  }
21
74
  /**
22
75
  * This is a map used to retrieve binary
@@ -24,26 +77,44 @@ export interface EventBinaryUpdate extends EventBinaryUploadSuccess {
24
77
  * @class BinaryMap
25
78
  */
26
79
  export declare class BinaryMap {
80
+ /**
81
+ * Current context
82
+ */
27
83
  __ctx: Context;
84
+ /**
85
+ * Link to the binary store
86
+ */
28
87
  __store: Binary;
29
88
  /**
30
89
  * Hash of the binary
31
90
  */
32
91
  hash: string;
92
+ /**
93
+ * Size of the file
94
+ */
95
+ size: number;
96
+ /**
97
+ * Mimetype
98
+ */
99
+ mime: string;
33
100
  constructor(service: any, obj: any);
34
101
  /**
35
- * Get the CoreModel
102
+ * Prevent all the attributes starting with '__' to be serialized
103
+ * @returns
104
+ */
105
+ toJSON(): {};
106
+ /**
107
+ * Get the binary data
36
108
  *
37
109
  * @returns
38
110
  */
39
- get(): Promise<ReadableStream<any>>;
111
+ get(): Promise<Readable>;
40
112
  /**
41
113
  * Download the binary to a path
42
114
  *
43
115
  * Shortcut to call {@link Binary.downloadTo} with current object
44
116
  *
45
117
  * @param filename
46
- * @returns
47
118
  */
48
119
  downloadTo(filename: string): Promise<void>;
49
120
  /**
@@ -55,6 +126,9 @@ export declare class BinaryMap {
55
126
  export declare class BinaryParameters extends ServiceParameters {
56
127
  /**
57
128
  * Define the map to Object collection
129
+ *
130
+ * key is a Store name
131
+ * the string[] represent all valids attributes to store files in
58
132
  */
59
133
  map: {
60
134
  [key: string]: string[];
@@ -89,8 +163,16 @@ export declare class BinaryParameters extends ServiceParameters {
89
163
  }
90
164
  /**
91
165
  * This is an abstract service to represent a storage of files
92
- * The binary allow you to expose this service as HTTP ( therefore is an executor )
93
- * It needs an object to attach the binary too
166
+ * The binary allow you to expose this service as HTTP
167
+ *
168
+ * It supports two modes:
169
+ * - attached to a CoreModel (attach, detach, reattach)
170
+ * - pure storage with no managed id (read, write, delete)
171
+ *
172
+ * As we have deduplication builtin you can get some stats
173
+ * - getUsageCount(hash)
174
+ * - getUsageCountForRaw()
175
+ * - getUsageCountForMap()
94
176
  *
95
177
  * The Binary storage should store only once a binary and reference every object that are used by this binary, so it can be cleaned.
96
178
  *
@@ -102,12 +184,8 @@ export declare class BinaryParameters extends ServiceParameters {
102
184
  * @abstract
103
185
  * @class Binary
104
186
  */
105
- declare abstract class Binary<T extends BinaryParameters = BinaryParameters> extends Service<T> {
187
+ declare abstract class Binary<T extends BinaryParameters = BinaryParameters> extends Service<T> implements MappingService<BinaryMap> {
106
188
  _lowercaseMaps: any;
107
- /**
108
- * @inheritdoc
109
- */
110
- loadParameters(params: any): ServiceParameters;
111
189
  /**
112
190
  * When you store a binary to be able to retrieve it you need to store the information into another object
113
191
  *
@@ -125,68 +203,88 @@ declare abstract class Binary<T extends BinaryParameters = BinaryParameters> ext
125
203
  * ```
126
204
  *
127
205
  *
128
- * @param {Store} targetStore The store that handles the object to attach binary to
129
206
  * @param {CoreModel} object The object uuid to get from the store
130
207
  * @param {String} property The object property to add the file to
131
208
  * @param {Object} file The file by itself
132
209
  * @param {Object} metadatas to add to the binary object
133
210
  * @emits 'binaryCreate'
134
211
  */
135
- abstract store(targetStore: Store<CoreModel>, object: CoreModel, property: string, file: any, metadatas: any, index?: number): Promise<any>;
212
+ abstract store(object: CoreModel, property: string, file: BinaryFile, metadatas?: {
213
+ [key: string]: any;
214
+ }): Promise<void>;
136
215
  /**
137
216
  * The store can retrieve how many time a binary has been used
138
217
  */
139
218
  abstract getUsageCount(hash: any): Promise<number>;
140
219
  /**
141
- * Update a binary
142
- *
220
+ * Delete a binary
143
221
  *
144
- * @param {Store} targetStore The store that handles the object to attach binary to
145
- * @param {String} object The object uuid to get from the store
146
- * @param {String} property The object property to add the file to
147
- * @param {Number} index The index of the file to change in the property
148
- * @param {Object} file The file by itself
149
- * @param {Object} metadatas to add to the binary object
150
- * @emits 'binaryUpdate'
151
- */
152
- abstract update(targetStore: any, object: any, property: any, index: any, file: any, metadatas: any): Promise<CoreModel>;
153
- /**
154
- * Update a binary
155
- *
156
- *
157
- * @param {Store} targetStore The store that handles the object to attach binary to
158
222
  * @param {CoreModel} object The object uuid to get from the store
159
223
  * @param {String} property The object property to add the file to
160
224
  * @param {Number} index The index of the file to change in the property
161
225
  * @emits 'binaryDelete'
162
226
  */
163
- abstract delete(targetStore: Store<CoreModel>, object: CoreModel, property: string, index: number): Promise<CoreModel>;
227
+ abstract delete(object: CoreModel, property: string, index: number): Promise<void>;
164
228
  /**
165
229
  * Get a binary
166
230
  *
167
231
  * @param {Object} info The reference stored in your target object
168
232
  * @emits 'binaryGet'
169
233
  */
170
- get(info: BinaryMap): Promise<ReadableStream<any>>;
234
+ get(info: BinaryMap): Promise<Readable>;
171
235
  /**
172
236
  * Download a binary to a file
173
237
  *
174
238
  * @param {Object} info The reference stored in your target object
175
239
  * @param {String} filepath to save the binary to
176
240
  */
177
- downloadTo(info: any, filename: any): Promise<void>;
178
- /** @ignore */
179
- init(): Promise<void>;
180
- _getUrl(info: any, ctx: Context): void;
181
- _get(info: any): ReadableStream;
241
+ downloadTo(info: BinaryMap, filename: any): Promise<void>;
242
+ /**
243
+ * @override
244
+ */
245
+ resolve(): void;
246
+ abstract _get(info: BinaryMap): Promise<Readable>;
247
+ /**
248
+ * Init the declared maps, adding reverse maps
249
+ *
250
+ * @param map
251
+ */
182
252
  initMap(map: any): void;
253
+ /**
254
+ * Based on the raw Map init a BinaryMap
255
+ * @param obj
256
+ * @returns
257
+ */
183
258
  initModel(obj: any): BinaryMap;
184
- _getHashes(buffer: any): any;
185
- _prepareInput(file: any): void;
186
- _checkMap(name: any, property: any): void;
187
- _validChallenge(challenge: any): boolean;
188
- challenge(hash: any, challenge: any): boolean;
189
- updateSuccess(targetStore: Store, object: CoreModel, property: string, index: number, file: any, metadatas: any): Promise<any>;
259
+ /**
260
+ * Create hashes
261
+ * @param buffer
262
+ * @returns
263
+ */
264
+ _getHashes(buffer: Buffer): {
265
+ hash: string;
266
+ challenge: string;
267
+ };
268
+ /**
269
+ * Read a stream to a buffer
270
+ *
271
+ * @param stream
272
+ * @returns
273
+ */
274
+ static streamToBuffer(stream: Readable): Promise<Buffer>;
275
+ /**
276
+ * Update the BinaryFile
277
+ * @param file
278
+ */
279
+ _prepareInput(file: BinaryFile): void;
280
+ /**
281
+ * Check if a map is defined
282
+ *
283
+ * @param name
284
+ * @param property
285
+ */
286
+ _checkMap(name: string, property: string): void;
287
+ uploadSuccess(object: CoreModel, property: string, file: any, metadatas?: any): Promise<void>;
190
288
  /**
191
289
  * Cascade delete the object
192
290
  *
@@ -202,20 +300,49 @@ declare abstract class Binary<T extends BinaryParameters = BinaryParameters> ext
202
300
  * @param index
203
301
  * @returns
204
302
  */
205
- deleteSuccess(targetStore: Store, object: CoreModel, property: string, index: number): Promise<any>;
206
- _getFile(req: any): any;
303
+ deleteSuccess(object: CoreModel, property: string, index: number): Promise<void>;
304
+ /**
305
+ * Get file either from multipart post or raw
306
+ * @param req
307
+ * @returns
308
+ */
309
+ _getFile(req: Context): any;
207
310
  /**
208
311
  * Init the Binary system routes
209
312
  */
210
313
  initRoutes(): void;
314
+ /**
315
+ * Return the name of the service for OpenAPI
316
+ * @returns
317
+ */
318
+ protected getOperationName(): string;
211
319
  /**
212
320
  * This is used to allow subclasses to add more route
213
321
  */
214
322
  _initRoutes(): boolean;
215
- httpPost(ctx: Context): Promise<void>;
323
+ /**
324
+ * Based on the request parameter verify it match a known mapping
325
+ * @param ctx
326
+ * @returns
327
+ */
216
328
  _verifyMapAndStore(ctx: Context): Store<CoreModel>;
217
- putRedirectUrl(ctx: Context): Promise<string>;
329
+ /**
330
+ * By default no challenge is managed so throws 404
331
+ *
332
+ * @param ctx
333
+ */
334
+ putRedirectUrl(ctx: Context): Promise<{
335
+ url: string;
336
+ method?: string;
337
+ }>;
338
+ /**
339
+ * Mechanism to add a data based on challenge
340
+ */
218
341
  httpChallenge(ctx: Context): Promise<void>;
342
+ /**
343
+ * Manage the different routes
344
+ * @param ctx
345
+ */
219
346
  httpRoute(ctx: Context): Promise<void>;
220
347
  }
221
348
  export { Binary };