@webda/core 2.0.0-beta.2 → 2.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 (279) hide show
  1. package/lib/application.d.ts +5 -21
  2. package/lib/application.js +71 -84
  3. package/lib/application.js.map +1 -1
  4. package/lib/application.spec.js +121 -140
  5. package/lib/application.spec.js.map +1 -1
  6. package/lib/core.d.ts +44 -45
  7. package/lib/core.js +239 -320
  8. package/lib/core.js.map +1 -1
  9. package/lib/core.spec.js +326 -391
  10. package/lib/core.spec.js.map +1 -1
  11. package/lib/index.d.ts +49 -45
  12. package/lib/index.js +54 -67
  13. package/lib/index.js.map +1 -1
  14. package/lib/models/aclmodel.d.ts +2 -2
  15. package/lib/models/aclmodel.js +63 -90
  16. package/lib/models/aclmodel.js.map +1 -1
  17. package/lib/models/aclmodel.spec.js +128 -151
  18. package/lib/models/aclmodel.spec.js.map +1 -1
  19. package/lib/models/coremodel.d.ts +39 -17
  20. package/lib/models/coremodel.js +160 -117
  21. package/lib/models/coremodel.js.map +1 -1
  22. package/lib/models/coremodel.spec.js +143 -107
  23. package/lib/models/coremodel.spec.js.map +1 -1
  24. package/lib/models/deployment.js +1 -2
  25. package/lib/models/ident.d.ts +3 -3
  26. package/lib/models/ident.js +4 -9
  27. package/lib/models/ident.js.map +1 -1
  28. package/lib/models/ident.spec.js +9 -11
  29. package/lib/models/ident.spec.js.map +1 -1
  30. package/lib/models/ownermodel.d.ts +2 -2
  31. package/lib/models/ownermodel.js +39 -62
  32. package/lib/models/ownermodel.js.map +1 -1
  33. package/lib/models/ownermodel.spec.js +126 -166
  34. package/lib/models/ownermodel.spec.js.map +1 -1
  35. package/lib/models/rolemodel.d.ts +2 -2
  36. package/lib/models/rolemodel.js +24 -40
  37. package/lib/models/rolemodel.js.map +1 -1
  38. package/lib/models/rolemodel.spec.js +44 -61
  39. package/lib/models/rolemodel.spec.js.map +1 -1
  40. package/lib/models/user.d.ts +9 -9
  41. package/lib/models/user.js +3 -8
  42. package/lib/models/user.js.map +1 -1
  43. package/lib/models/user.spec.js +14 -16
  44. package/lib/models/user.spec.js.map +1 -1
  45. package/lib/queues/filequeue.d.ts +2 -2
  46. package/lib/queues/filequeue.js +72 -93
  47. package/lib/queues/filequeue.js.map +1 -1
  48. package/lib/queues/filequeue.spec.js +53 -70
  49. package/lib/queues/filequeue.spec.js.map +1 -1
  50. package/lib/queues/memoryqueue.d.ts +2 -2
  51. package/lib/queues/memoryqueue.js +37 -61
  52. package/lib/queues/memoryqueue.js.map +1 -1
  53. package/lib/queues/memoryqueue.spec.js +142 -165
  54. package/lib/queues/memoryqueue.spec.js.map +1 -1
  55. package/lib/queues/pubsubservice.d.ts +2 -2
  56. package/lib/queues/pubsubservice.js +3 -7
  57. package/lib/queues/pubsubservice.js.map +1 -1
  58. package/lib/queues/queue.spec.d.ts +1 -1
  59. package/lib/queues/queue.spec.js +42 -56
  60. package/lib/queues/queue.spec.js.map +1 -1
  61. package/lib/queues/queueservice.d.ts +4 -4
  62. package/lib/queues/queueservice.js +52 -67
  63. package/lib/queues/queueservice.js.map +1 -1
  64. package/lib/router.d.ts +3 -3
  65. package/lib/router.js +46 -47
  66. package/lib/router.js.map +1 -1
  67. package/lib/router.spec.js +64 -61
  68. package/lib/router.spec.js.map +1 -1
  69. package/lib/services/asyncevents.d.ts +2 -2
  70. package/lib/services/asyncevents.js +44 -64
  71. package/lib/services/asyncevents.js.map +1 -1
  72. package/lib/services/asyncevents.spec.js +81 -98
  73. package/lib/services/asyncevents.spec.js.map +1 -1
  74. package/lib/services/authentication.d.ts +28 -19
  75. package/lib/services/authentication.js +542 -574
  76. package/lib/services/authentication.js.map +1 -1
  77. package/lib/services/authentication.spec.js +411 -447
  78. package/lib/services/authentication.spec.js.map +1 -1
  79. package/lib/services/binary.d.ts +9 -7
  80. package/lib/services/binary.js +213 -245
  81. package/lib/services/binary.js.map +1 -1
  82. package/lib/services/binary.spec.d.ts +3 -3
  83. package/lib/services/binary.spec.js +390 -443
  84. package/lib/services/binary.spec.js.map +1 -1
  85. package/lib/services/cloudbinary.d.ts +3 -3
  86. package/lib/services/cloudbinary.js +45 -70
  87. package/lib/services/cloudbinary.js.map +1 -1
  88. package/lib/services/cloudbinary.spec.d.ts +3 -3
  89. package/lib/services/cloudbinary.spec.js +133 -162
  90. package/lib/services/cloudbinary.spec.js.map +1 -1
  91. package/lib/services/configuration.d.ts +6 -3
  92. package/lib/services/configuration.js +78 -103
  93. package/lib/services/configuration.js.map +1 -1
  94. package/lib/services/configuration.spec.js +63 -83
  95. package/lib/services/configuration.spec.js.map +1 -1
  96. package/lib/services/cron.d.ts +3 -2
  97. package/lib/services/cron.js +9 -13
  98. package/lib/services/cron.js.map +1 -1
  99. package/lib/services/cron.spec.js +18 -21
  100. package/lib/services/cron.spec.js.map +1 -1
  101. package/lib/services/cryptoservice.d.ts +258 -0
  102. package/lib/services/cryptoservice.js +312 -0
  103. package/lib/services/cryptoservice.js.map +1 -0
  104. package/lib/services/cryptoservice.spec.d.ts +1 -0
  105. package/lib/services/cryptoservice.spec.js +137 -0
  106. package/lib/services/cryptoservice.spec.js.map +1 -0
  107. package/lib/services/debugmailer.d.ts +1 -1
  108. package/lib/services/debugmailer.js +13 -34
  109. package/lib/services/debugmailer.js.map +1 -1
  110. package/lib/services/debugmailer.spec.js +16 -29
  111. package/lib/services/debugmailer.spec.js.map +1 -1
  112. package/lib/services/echo.d.ts +2 -2
  113. package/lib/services/echo.js +15 -31
  114. package/lib/services/echo.js.map +1 -1
  115. package/lib/services/echo.spec.js +27 -40
  116. package/lib/services/echo.spec.js.map +1 -1
  117. package/lib/services/filebinary.d.ts +10 -5
  118. package/lib/services/filebinary.js +171 -205
  119. package/lib/services/filebinary.js.map +1 -1
  120. package/lib/services/filebinary.spec.d.ts +2 -1
  121. package/lib/services/filebinary.spec.js +106 -117
  122. package/lib/services/filebinary.spec.js.map +1 -1
  123. package/lib/services/fileconfiguration.d.ts +2 -2
  124. package/lib/services/fileconfiguration.js +25 -43
  125. package/lib/services/fileconfiguration.js.map +1 -1
  126. package/lib/services/fileconfiguration.spec.js +79 -109
  127. package/lib/services/fileconfiguration.spec.js.map +1 -1
  128. package/lib/services/invitationservice.d.ts +10 -10
  129. package/lib/services/invitationservice.js +275 -313
  130. package/lib/services/invitationservice.js.map +1 -1
  131. package/lib/services/invitationservice.spec.js +443 -449
  132. package/lib/services/invitationservice.spec.js.map +1 -1
  133. package/lib/services/kubernetesconfiguration.d.ts +2 -2
  134. package/lib/services/kubernetesconfiguration.js +41 -59
  135. package/lib/services/kubernetesconfiguration.js.map +1 -1
  136. package/lib/services/kubernetesconfiguration.spec.js +80 -98
  137. package/lib/services/kubernetesconfiguration.spec.js.map +1 -1
  138. package/lib/services/mailer.d.ts +4 -4
  139. package/lib/services/mailer.js +62 -86
  140. package/lib/services/mailer.js.map +1 -1
  141. package/lib/services/mailer.spec.js +86 -127
  142. package/lib/services/mailer.spec.js.map +1 -1
  143. package/lib/services/notificationservice.d.ts +4 -4
  144. package/lib/services/notificationservice.js +23 -42
  145. package/lib/services/notificationservice.js.map +1 -1
  146. package/lib/services/notificationservice.spec.js +47 -73
  147. package/lib/services/notificationservice.spec.js.map +1 -1
  148. package/lib/services/oauth.d.ts +32 -6
  149. package/lib/services/oauth.js +73 -78
  150. package/lib/services/oauth.js.map +1 -1
  151. package/lib/services/oauth.spec.js +128 -148
  152. package/lib/services/oauth.spec.js.map +1 -1
  153. package/lib/services/proxy.d.ts +74 -0
  154. package/lib/services/proxy.js +126 -0
  155. package/lib/services/proxy.js.map +1 -0
  156. package/lib/services/proxy.spec.d.ts +1 -0
  157. package/lib/services/proxy.spec.js +59 -0
  158. package/lib/services/proxy.spec.js.map +1 -0
  159. package/lib/services/resource.d.ts +2 -2
  160. package/lib/services/resource.js +12 -18
  161. package/lib/services/resource.js.map +1 -1
  162. package/lib/services/resource.spec.js +67 -99
  163. package/lib/services/resource.spec.js.map +1 -1
  164. package/lib/services/service.d.ts +29 -6
  165. package/lib/services/service.js +69 -39
  166. package/lib/services/service.js.map +1 -1
  167. package/lib/services/service.spec.js +62 -67
  168. package/lib/services/service.spec.js.map +1 -1
  169. package/lib/services/version.d.ts +1 -1
  170. package/lib/services/version.js +3 -8
  171. package/lib/services/version.js.map +1 -1
  172. package/lib/services/version.spec.js +11 -24
  173. package/lib/services/version.spec.js.map +1 -1
  174. package/lib/stores/aggregator.d.ts +3 -3
  175. package/lib/stores/aggregator.js +37 -57
  176. package/lib/stores/aggregator.js.map +1 -1
  177. package/lib/stores/file.d.ts +3 -3
  178. package/lib/stores/file.js +93 -131
  179. package/lib/stores/file.js.map +1 -1
  180. package/lib/stores/file.spec.d.ts +2 -2
  181. package/lib/stores/file.spec.js +262 -289
  182. package/lib/stores/file.spec.js.map +1 -1
  183. package/lib/stores/mapper.d.ts +4 -4
  184. package/lib/stores/mapper.js +111 -137
  185. package/lib/stores/mapper.js.map +1 -1
  186. package/lib/stores/mapper.spec.js +133 -150
  187. package/lib/stores/mapper.spec.js.map +1 -1
  188. package/lib/stores/memory.d.ts +67 -6
  189. package/lib/stores/memory.js +155 -117
  190. package/lib/stores/memory.js.map +1 -1
  191. package/lib/stores/memory.spec.d.ts +3 -2
  192. package/lib/stores/memory.spec.js +127 -105
  193. package/lib/stores/memory.spec.js.map +1 -1
  194. package/lib/stores/store.d.ts +40 -16
  195. package/lib/stores/store.js +847 -830
  196. package/lib/stores/store.js.map +1 -1
  197. package/lib/stores/store.spec.d.ts +6 -4
  198. package/lib/stores/store.spec.js +628 -647
  199. package/lib/stores/store.spec.js.map +1 -1
  200. package/lib/stores/webdaql/WebdaQLLexer.d.ts +4 -4
  201. package/lib/stores/webdaql/WebdaQLLexer.js +9 -13
  202. package/lib/stores/webdaql/WebdaQLLexer.js.map +1 -1
  203. package/lib/stores/webdaql/WebdaQLParserLexer.d.ts +4 -4
  204. package/lib/stores/webdaql/WebdaQLParserLexer.js +9 -13
  205. package/lib/stores/webdaql/WebdaQLParserLexer.js.map +1 -1
  206. package/lib/stores/webdaql/WebdaQLParserListener.d.ts +2 -2
  207. package/lib/stores/webdaql/WebdaQLParserListener.js +1 -2
  208. package/lib/stores/webdaql/WebdaQLParserListener.js.map +1 -1
  209. package/lib/stores/webdaql/WebdaQLParserParser.d.ts +10 -10
  210. package/lib/stores/webdaql/WebdaQLParserParser.js +62 -91
  211. package/lib/stores/webdaql/WebdaQLParserParser.js.map +1 -1
  212. package/lib/stores/webdaql/WebdaQLParserVisitor.d.ts +2 -2
  213. package/lib/stores/webdaql/WebdaQLParserVisitor.js +1 -2
  214. package/lib/stores/webdaql/WebdaQLParserVisitor.js.map +1 -1
  215. package/lib/stores/webdaql/query.d.ts +4 -5
  216. package/lib/stores/webdaql/query.js +16 -19
  217. package/lib/stores/webdaql/query.js.map +1 -1
  218. package/lib/stores/webdaql/query.spec.js +30 -32
  219. package/lib/stores/webdaql/query.spec.js.map +1 -1
  220. package/lib/test.d.ts +3 -3
  221. package/lib/test.js +74 -94
  222. package/lib/test.js.map +1 -1
  223. package/lib/unpackedapplication.d.ts +1 -1
  224. package/lib/unpackedapplication.js +44 -38
  225. package/lib/unpackedapplication.js.map +1 -1
  226. package/lib/utils/abstractdeployer.js +1 -5
  227. package/lib/utils/abstractdeployer.js.map +1 -1
  228. package/lib/utils/abstractdeployer.spec.js +6 -8
  229. package/lib/utils/abstractdeployer.spec.js.map +1 -1
  230. package/lib/utils/context.d.ts +61 -29
  231. package/lib/utils/context.js +133 -127
  232. package/lib/utils/context.js.map +1 -1
  233. package/lib/utils/context.spec.js +144 -153
  234. package/lib/utils/context.spec.js.map +1 -1
  235. package/lib/utils/cookie.d.ts +66 -45
  236. package/lib/utils/cookie.js +69 -158
  237. package/lib/utils/cookie.js.map +1 -1
  238. package/lib/utils/cookie.spec.js +220 -238
  239. package/lib/utils/cookie.spec.js.map +1 -1
  240. package/lib/utils/esm.d.ts +4 -0
  241. package/lib/utils/esm.js +10 -0
  242. package/lib/utils/esm.js.map +1 -0
  243. package/lib/utils/httpcontext.d.ts +3 -0
  244. package/lib/utils/httpcontext.js +48 -65
  245. package/lib/utils/httpcontext.js.map +1 -1
  246. package/lib/utils/httpcontext.spec.js +37 -56
  247. package/lib/utils/httpcontext.spec.js.map +1 -1
  248. package/lib/utils/logger.d.ts +2 -2
  249. package/lib/utils/logger.js +15 -28
  250. package/lib/utils/logger.js.map +1 -1
  251. package/lib/utils/logger.spec.js +9 -11
  252. package/lib/utils/logger.spec.js.map +1 -1
  253. package/lib/utils/serializers.js +17 -20
  254. package/lib/utils/serializers.js.map +1 -1
  255. package/lib/utils/serializers.spec.js +43 -44
  256. package/lib/utils/serializers.spec.js.map +1 -1
  257. package/lib/utils/session.d.ts +120 -0
  258. package/lib/utils/session.js +155 -0
  259. package/lib/utils/session.js.map +1 -0
  260. package/lib/utils/session.spec.d.ts +1 -0
  261. package/lib/utils/session.spec.js +66 -0
  262. package/lib/utils/session.spec.js.map +1 -0
  263. package/lib/utils/waiter.d.ts +1 -1
  264. package/lib/utils/waiter.js +32 -52
  265. package/lib/utils/waiter.js.map +1 -1
  266. package/lib/utils/waiter.spec.js +75 -92
  267. package/lib/utils/waiter.spec.js.map +1 -1
  268. package/package.json +22 -14
  269. package/test/config-invitation.json +1 -3
  270. package/test/config.json +3 -3
  271. package/test/config.old.json +1 -2
  272. package/test/moddas/annotatedservice.js +5 -5
  273. package/test/moddas/debugmailer.js +2 -3
  274. package/test/moddas/fakeservice.js +2 -3
  275. package/test/moddas/voidstore.js +6 -4
  276. package/test/models/ident.js +2 -6
  277. package/test/models/task.js +3 -7
  278. package/test/package.json +2 -1
  279. package/webda.module.json +895 -189
@@ -5,39 +5,27 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
6
  return c > 3 && r && Object.defineProperty(target, key, r), r;
7
7
  };
8
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
9
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
10
- return new (P || (P = Promise))(function (resolve, reject) {
11
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
12
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
13
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
14
- step((generator = generator.apply(thisArg, _arguments || [])).next());
15
- });
16
- };
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.Binary = exports.BinaryParameters = exports.BinaryMap = exports.MemoryBinaryFile = exports.LocalBinaryFile = exports.BinaryFile = exports.BinaryNotFoundError = void 0;
19
- const crypto = require("crypto");
20
- const fs = require("fs");
21
- const mime = require("mime-types");
22
- const path = require("path");
23
- const stream_1 = require("stream");
24
- const __1 = require("..");
25
- const coremodel_1 = require("../models/coremodel");
26
- const store_1 = require("../stores/store");
27
- const service_1 = require("./service");
8
+ import * as crypto from "crypto";
9
+ import * as fs from "fs";
10
+ import * as mime from "mime-types";
11
+ import * as path from "path";
12
+ import { Readable } from "stream";
13
+ import { WebdaError } from "../index.js";
14
+ import { NotEnumerable } from "../models/coremodel.js";
15
+ import { Store } from "../stores/store.js";
16
+ import { Service, ServiceParameters } from "./service.js";
28
17
  /**
29
18
  * Emitted if binary does not exist
30
19
  */
31
- class BinaryNotFoundError extends __1.WebdaError {
20
+ export class BinaryNotFoundError extends WebdaError {
32
21
  constructor(hash, storeName) {
33
22
  super("BINARY_NOTFOUND", `Binary not found ${hash} BinaryService(${storeName})`);
34
23
  }
35
24
  }
36
- exports.BinaryNotFoundError = BinaryNotFoundError;
37
25
  /**
38
26
  * Represent a file to store
39
27
  */
40
- class BinaryFile {
28
+ export class BinaryFile {
41
29
  constructor(info) {
42
30
  this.name = info.name;
43
31
  this.challenge = info.challenge;
@@ -64,37 +52,34 @@ class BinaryFile {
64
52
  * @param buffer
65
53
  * @returns
66
54
  */
67
- getHashes() {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- if (!this.hash) {
70
- // Using MD5 as S3 content verification use md5
71
- const hash = crypto.createHash("md5");
72
- const challenge = crypto.createHash("md5");
73
- const stream = yield this.get();
74
- challenge.update("WEBDA");
75
- yield new Promise((resolve, reject) => {
76
- stream.on("error", err => reject(err));
77
- stream.on("end", () => {
78
- this.hash = hash.digest("hex");
79
- this.challenge = challenge.digest("hex");
80
- resolve();
81
- });
82
- stream.on("data", chunk => {
83
- let buffer = Buffer.from(chunk);
84
- hash.update(buffer);
85
- challenge.update(buffer);
86
- });
55
+ async getHashes() {
56
+ if (!this.hash) {
57
+ // Using MD5 as S3 content verification use md5
58
+ const hash = crypto.createHash("md5");
59
+ const challenge = crypto.createHash("md5");
60
+ const stream = await this.get();
61
+ challenge.update("WEBDA");
62
+ await new Promise((resolve, reject) => {
63
+ stream.on("error", err => reject(err));
64
+ stream.on("end", () => {
65
+ this.hash = hash.digest("hex");
66
+ this.challenge = challenge.digest("hex");
67
+ resolve();
87
68
  });
88
- }
89
- return {
90
- hash: this.hash,
91
- challenge: this.challenge
92
- };
93
- });
69
+ stream.on("data", chunk => {
70
+ let buffer = Buffer.from(chunk);
71
+ hash.update(buffer);
72
+ challenge.update(buffer);
73
+ });
74
+ });
75
+ }
76
+ return {
77
+ hash: this.hash,
78
+ challenge: this.challenge
79
+ };
94
80
  }
95
81
  }
96
- exports.BinaryFile = BinaryFile;
97
- class LocalBinaryFile extends BinaryFile {
82
+ export class LocalBinaryFile extends BinaryFile {
98
83
  constructor(filePath) {
99
84
  super({
100
85
  name: path.basename(filePath),
@@ -106,14 +91,11 @@ class LocalBinaryFile extends BinaryFile {
106
91
  /**
107
92
  * @override
108
93
  */
109
- get() {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- return fs.createReadStream(this.path);
112
- });
94
+ async get() {
95
+ return fs.createReadStream(this.path);
113
96
  }
114
97
  }
115
- exports.LocalBinaryFile = LocalBinaryFile;
116
- class MemoryBinaryFile extends BinaryFile {
98
+ export class MemoryBinaryFile extends BinaryFile {
117
99
  constructor(buffer, info) {
118
100
  super(info);
119
101
  this.buffer = buffer;
@@ -121,22 +103,19 @@ class MemoryBinaryFile extends BinaryFile {
121
103
  /**
122
104
  * @override
123
105
  */
124
- get() {
125
- return __awaiter(this, void 0, void 0, function* () {
126
- return stream_1.Readable.from(this.buffer);
127
- });
106
+ async get() {
107
+ return Readable.from(this.buffer);
128
108
  }
129
109
  }
130
- exports.MemoryBinaryFile = MemoryBinaryFile;
131
110
  /**
132
111
  * This is a map used to retrieve binary
133
112
  *
134
113
  * @class BinaryMap
135
114
  */
136
- class BinaryMap extends BinaryFile {
115
+ export class BinaryMap extends BinaryFile {
137
116
  constructor(service, obj) {
138
117
  super(obj);
139
- for (var i in obj) {
118
+ for (let i in obj) {
140
119
  this[i] = obj[i];
141
120
  }
142
121
  this.__store = service;
@@ -169,10 +148,8 @@ class BinaryMap extends BinaryFile {
169
148
  *
170
149
  * @param filename
171
150
  */
172
- downloadTo(filename) {
173
- return __awaiter(this, void 0, void 0, function* () {
174
- return this.__store.downloadTo(this, filename);
175
- });
151
+ async downloadTo(filename) {
152
+ return this.__store.downloadTo(this, filename);
176
153
  }
177
154
  /**
178
155
  * Set the http context
@@ -183,23 +160,20 @@ class BinaryMap extends BinaryFile {
183
160
  }
184
161
  }
185
162
  __decorate([
186
- coremodel_1.NotEnumerable
163
+ NotEnumerable
187
164
  ], BinaryMap.prototype, "__ctx", void 0);
188
165
  __decorate([
189
- coremodel_1.NotEnumerable
166
+ NotEnumerable
190
167
  ], BinaryMap.prototype, "__store", void 0);
191
- exports.BinaryMap = BinaryMap;
192
- class BinaryParameters extends service_1.ServiceParameters {
168
+ export class BinaryParameters extends ServiceParameters {
193
169
  constructor(params, _service) {
194
- var _a;
195
170
  super(params);
196
171
  if (this.expose) {
197
172
  this.expose.restrict = this.expose.restrict || {};
198
173
  }
199
- (_a = this.map) !== null && _a !== void 0 ? _a : (this.map = {});
174
+ this.map ?? (this.map = {});
200
175
  }
201
176
  }
202
- exports.BinaryParameters = BinaryParameters;
203
177
  /**
204
178
  * This is an abstract service to represent a storage of files
205
179
  * The binary allow you to expose this service as HTTP
@@ -223,21 +197,19 @@ exports.BinaryParameters = BinaryParameters;
223
197
  * @abstract
224
198
  * @class Binary
225
199
  */
226
- class Binary extends service_1.Service {
200
+ class Binary extends Service {
227
201
  /**
228
202
  * Get a binary
229
203
  *
230
204
  * @param {Object} info The reference stored in your target object
231
205
  * @emits 'binaryGet'
232
206
  */
233
- get(info) {
234
- return __awaiter(this, void 0, void 0, function* () {
235
- yield this.emitSync("Binary.Get", {
236
- object: info,
237
- service: this
238
- });
239
- return this._get(info);
207
+ async get(info) {
208
+ await this.emitSync("Binary.Get", {
209
+ object: info,
210
+ service: this
240
211
  });
212
+ return this._get(info);
241
213
  }
242
214
  /**
243
215
  * Download a binary to a file
@@ -245,29 +217,29 @@ class Binary extends service_1.Service {
245
217
  * @param {Object} info The reference stored in your target object
246
218
  * @param {String} filepath to save the binary to
247
219
  */
248
- downloadTo(info, filename) {
249
- return __awaiter(this, void 0, void 0, function* () {
250
- yield this.emitSync("Binary.Get", {
251
- object: info,
252
- service: this
220
+ async downloadTo(info, filename) {
221
+ await this.emitSync("Binary.Get", {
222
+ object: info,
223
+ service: this
224
+ });
225
+ let readStream = await this._get(info);
226
+ let writeStream = fs.createWriteStream(filename);
227
+ return new Promise((resolve, reject) => {
228
+ writeStream.on("finish", _src => {
229
+ return resolve();
253
230
  });
254
- var readStream = yield this._get(info);
255
- var writeStream = fs.createWriteStream(filename);
256
- return new Promise((resolve, reject) => {
257
- writeStream.on("finish", _src => {
258
- return resolve();
259
- });
260
- writeStream.on("error", src => {
261
- try {
262
- fs.unlinkSync(filename);
263
- }
264
- catch (err) {
265
- this._webda.log("ERROR", err);
266
- }
267
- return reject(src);
268
- });
269
- readStream.pipe(writeStream);
231
+ writeStream.on("error", src => {
232
+ try {
233
+ fs.unlinkSync(filename);
234
+ // Stubing the fs module in ESM seems complicated for now
235
+ /* c8 ignore next 3 */
236
+ }
237
+ catch (err) {
238
+ this._webda.log("ERROR", err);
239
+ }
240
+ return reject(src);
270
241
  });
242
+ readStream.pipe(writeStream);
271
243
  });
272
244
  }
273
245
  /**
@@ -276,6 +248,7 @@ class Binary extends service_1.Service {
276
248
  resolve() {
277
249
  super.resolve();
278
250
  this.initMap(this.parameters.map);
251
+ return this;
279
252
  }
280
253
  /**
281
254
  * Init the declared maps, adding reverse maps
@@ -290,7 +263,7 @@ class Binary extends service_1.Service {
290
263
  Object.keys(map).forEach(prop => {
291
264
  this._lowercaseMaps[prop.toLowerCase()] = prop;
292
265
  let reverseStore = this._webda.getService(prop);
293
- if (reverseStore === undefined || !(reverseStore instanceof store_1.Store)) {
266
+ if (reverseStore === undefined || !(reverseStore instanceof Store)) {
294
267
  this._webda.log("WARN", "Can't setup mapping as store ", prop, " doesn't exist");
295
268
  map[prop]["-onerror"] = "NoStore";
296
269
  return;
@@ -299,13 +272,13 @@ class Binary extends service_1.Service {
299
272
  reverseStore.addReverseMap(map[prop][i], this);
300
273
  }
301
274
  // Cascade delete
302
- reverseStore.on("Store.Deleted", (evt) => __awaiter(this, void 0, void 0, function* () {
275
+ reverseStore.on("Store.Deleted", async (evt) => {
303
276
  let infos = [];
304
277
  if (evt.object[map[prop]]) {
305
278
  infos.push(...evt.object[map[prop]]);
306
279
  }
307
- yield Promise.all(infos.map(info => this.cascadeDelete(info, evt.object.getUuid())));
308
- }));
280
+ await Promise.all(infos.map(info => this.cascadeDelete(info, evt.object.getUuid())));
281
+ });
309
282
  });
310
283
  }
311
284
  /**
@@ -313,7 +286,7 @@ class Binary extends service_1.Service {
313
286
  * @param obj
314
287
  * @returns
315
288
  */
316
- initModel(obj) {
289
+ newModel(obj) {
317
290
  return new BinaryMap(this, obj);
318
291
  }
319
292
  /**
@@ -338,7 +311,7 @@ class Binary extends service_1.Service {
338
311
  * @param property
339
312
  */
340
313
  checkMap(name, property) {
341
- var map = this.parameters.map[this._lowercaseMaps[name.toLowerCase()]];
314
+ let map = this.parameters.map[this._lowercaseMaps[name.toLowerCase()]];
342
315
  if (map === undefined) {
343
316
  throw Error("Unknown mapping");
344
317
  }
@@ -349,20 +322,18 @@ class Binary extends service_1.Service {
349
322
  /**
350
323
  * Ensure events are sent correctly after an upload and update the BinaryFileInfo in targetted object
351
324
  */
352
- uploadSuccess(object, property, file) {
353
- return __awaiter(this, void 0, void 0, function* () {
354
- var object_uid = object.getUuid();
355
- yield this.emitSync("Binary.UploadSuccess", {
356
- object: file,
357
- service: this,
358
- target: object
359
- });
360
- yield object.getStore().upsertItemToCollection(object_uid, property, file);
361
- yield this.emitSync("Binary.Create", {
362
- object: file,
363
- service: this,
364
- target: object
365
- });
325
+ async uploadSuccess(object, property, file) {
326
+ let object_uid = object.getUuid();
327
+ await this.emitSync("Binary.UploadSuccess", {
328
+ object: file,
329
+ service: this,
330
+ target: object
331
+ });
332
+ await object.getStore().upsertItemToCollection(object_uid, property, file);
333
+ await this.emitSync("Binary.Create", {
334
+ object: file,
335
+ service: this,
336
+ target: object
366
337
  });
367
338
  }
368
339
  /**
@@ -373,31 +344,27 @@ class Binary extends service_1.Service {
373
344
  * @param index
374
345
  * @returns
375
346
  */
376
- deleteSuccess(object, property, index) {
377
- return __awaiter(this, void 0, void 0, function* () {
378
- var info = object[property][index];
379
- let update = object.getStore().deleteItemFromCollection(object.getUuid(), property, index, info.hash, "hash");
380
- yield this.emitSync("Binary.Delete", {
381
- object: info,
382
- service: this
383
- });
384
- return update;
347
+ async deleteSuccess(object, property, index) {
348
+ let info = object[property][index];
349
+ let update = object.getStore().deleteItemFromCollection(object.getUuid(), property, index, info.hash, "hash");
350
+ await this.emitSync("Binary.Delete", {
351
+ object: info,
352
+ service: this
385
353
  });
354
+ return update;
386
355
  }
387
356
  /**
388
357
  * Get file either from multipart post or raw
389
358
  * @param req
390
359
  * @returns
391
360
  */
392
- _getFile(req) {
393
- return __awaiter(this, void 0, void 0, function* () {
394
- let file = yield req.getHttpContext().getRawBody(10 * 1024 * 1024);
395
- // TODO Check if we have other type
396
- return new MemoryBinaryFile(Buffer.from(file), {
397
- mimetype: req.getHttpContext().getUniqueHeader("Content-Type", "application/octet-stream"),
398
- size: parseInt(req.getHttpContext().getUniqueHeader("Content-Length")) || file.length,
399
- name: ""
400
- });
361
+ async _getFile(req) {
362
+ let file = await req.getHttpContext().getRawBody(10 * 1024 * 1024);
363
+ // TODO Check if we have other type
364
+ return new MemoryBinaryFile(Buffer.from(file), {
365
+ mimetype: req.getHttpContext().getUniqueHeader("Content-Type", "application/octet-stream"),
366
+ size: parseInt(req.getHttpContext().getUniqueHeader("Content-Length")) || file.length,
367
+ name: ""
401
368
  });
402
369
  }
403
370
  /**
@@ -557,14 +524,14 @@ class Binary extends service_1.Service {
557
524
  _verifyMapAndStore(ctx) {
558
525
  let store = ctx.parameter("store").toLowerCase();
559
526
  // To avoid any probleme lowercase everything
560
- var map = this.parameters.map[this._lowercaseMaps[store]];
527
+ let map = this.parameters.map[this._lowercaseMaps[store]];
561
528
  if (map === undefined) {
562
529
  throw 404;
563
530
  }
564
531
  if (map.indexOf(ctx.parameter("property")) == -1) {
565
532
  throw 404;
566
533
  }
567
- var targetStore = this.getService(store);
534
+ let targetStore = this.getService(store);
568
535
  if (targetStore === undefined) {
569
536
  throw 404;
570
537
  }
@@ -575,125 +542,126 @@ class Binary extends service_1.Service {
575
542
  *
576
543
  * @param ctx
577
544
  */
578
- putRedirectUrl(_ctx) {
579
- return __awaiter(this, void 0, void 0, function* () {
580
- // Dont handle the redirect url
581
- throw 404;
582
- });
545
+ async putRedirectUrl(_ctx) {
546
+ // Dont handle the redirect url
547
+ throw 404;
583
548
  }
584
549
  /**
585
550
  * Mechanism to add a data based on challenge
586
551
  */
587
- httpChallenge(ctx) {
588
- return __awaiter(this, void 0, void 0, function* () {
589
- let body = yield ctx.getRequestBody();
590
- if (!body.hash || !body.challenge) {
591
- throw 400;
592
- }
593
- // First verify if map exist
594
- let targetStore = this._verifyMapAndStore(ctx);
595
- // Get the object
596
- let object = yield targetStore.get(ctx.parameter("uid"), ctx);
597
- if (object === undefined) {
598
- throw 404;
599
- }
600
- yield object.canAct(ctx, "attach_binary");
601
- let url = yield this.putRedirectUrl(ctx);
602
- let base64String = Buffer.from(body.hash, "hex").toString("base64");
603
- ctx.write(Object.assign(Object.assign({}, url), { done: url === undefined, md5: base64String }));
552
+ async httpChallenge(ctx) {
553
+ let body = await ctx.getRequestBody();
554
+ if (!body.hash || !body.challenge) {
555
+ throw 400;
556
+ }
557
+ // First verify if map exist
558
+ let targetStore = this._verifyMapAndStore(ctx);
559
+ // Get the object
560
+ let object = await targetStore.get(ctx.parameter("uid"), ctx);
561
+ if (object === undefined) {
562
+ throw 404;
563
+ }
564
+ await object.canAct(ctx, "attach_binary");
565
+ let url = await this.putRedirectUrl(ctx);
566
+ let base64String = Buffer.from(body.hash, "hex").toString("base64");
567
+ ctx.write({
568
+ ...url,
569
+ done: url === undefined,
570
+ md5: base64String
604
571
  });
605
572
  }
606
573
  /**
607
574
  * Manage the different routes
608
575
  * @param ctx
609
576
  */
610
- httpRoute(ctx) {
611
- return __awaiter(this, void 0, void 0, function* () {
612
- // First verify if map exist
613
- let targetStore = this._verifyMapAndStore(ctx);
614
- // Get the object
615
- let object = yield targetStore.get(ctx.parameter("uid"), ctx);
616
- if (object === undefined) {
617
- throw 404;
618
- }
619
- let property = ctx.parameter("property");
620
- let index = ctx.parameter("index");
621
- // Should be an array
622
- if (!Array.isArray(object[property]) || object[property].length <= index) {
623
- throw 404;
624
- }
625
- // Check permissions
626
- let action = "unknown";
627
- if (ctx.getHttpContext().getMethod() === "GET") {
628
- action = "get_binary";
629
- }
630
- else if (ctx.getHttpContext().getMethod() === "DELETE") {
631
- action = "detach_binary";
632
- }
633
- else if (ctx.getHttpContext().getMethod() === "POST") {
634
- action = "attach_binary";
577
+ async httpRoute(ctx) {
578
+ // First verify if map exist
579
+ let targetStore = this._verifyMapAndStore(ctx);
580
+ // Get the object
581
+ let object = await targetStore.get(ctx.parameter("uid"), ctx);
582
+ if (object === undefined) {
583
+ throw 404;
584
+ }
585
+ let property = ctx.parameter("property");
586
+ let index = ctx.parameter("index");
587
+ // Should be an array
588
+ if (!Array.isArray(object[property]) || object[property].length <= index) {
589
+ throw 404;
590
+ }
591
+ // Check permissions
592
+ let action = "unknown";
593
+ if (ctx.getHttpContext().getMethod() === "GET") {
594
+ action = "get_binary";
595
+ }
596
+ else if (ctx.getHttpContext().getMethod() === "DELETE") {
597
+ action = "detach_binary";
598
+ }
599
+ else if (ctx.getHttpContext().getMethod() === "POST") {
600
+ action = "attach_binary";
601
+ }
602
+ else if (ctx.getHttpContext().getMethod() === "PUT") {
603
+ action = "update_binary_metadata";
604
+ }
605
+ await object.canAct(ctx, action);
606
+ // Now do the action
607
+ if (ctx.getHttpContext().getMethod() === "GET") {
608
+ // Most implementation override this to do a REDIRECT to a GET url
609
+ let file = object[property][index];
610
+ ctx.writeHead(200, {
611
+ "Content-Type": file.mimetype === undefined ? "application/octet-steam" : file.mimetype,
612
+ "Content-Length": file.size
613
+ });
614
+ let readStream = await this.get(file);
615
+ try {
616
+ await new Promise((resolve, reject) => {
617
+ // We replaced all the event handlers with a simple call to readStream.pipe()
618
+ ctx._stream.on("finish", resolve);
619
+ ctx._stream.on("error", reject);
620
+ readStream.pipe(ctx._stream);
621
+ });
635
622
  }
636
- else if (ctx.getHttpContext().getMethod() === "PUT") {
637
- action = "update_binary_metadata";
623
+ catch (err) {
624
+ this.log("ERROR", err);
625
+ throw 500;
638
626
  }
639
- yield object.canAct(ctx, action);
640
- // Now do the action
641
- if (ctx.getHttpContext().getMethod() === "GET") {
642
- // Most implementation override this to do a REDIRECT to a GET url
643
- var file = object[property][index];
644
- ctx.writeHead(200, {
645
- "Content-Type": file.mimetype === undefined ? "application/octet-steam" : file.mimetype,
646
- "Content-Length": file.size
647
- });
648
- let readStream = yield this.get(file);
649
- try {
650
- yield new Promise((resolve, reject) => {
651
- // We replaced all the event handlers with a simple call to readStream.pipe()
652
- ctx._stream.on("finish", resolve);
653
- ctx._stream.on("error", reject);
654
- readStream.pipe(ctx._stream);
655
- });
656
- }
657
- catch (err) {
658
- this.log("ERROR", err);
659
- throw 500;
660
- }
627
+ }
628
+ else {
629
+ if (ctx.getHttpContext().getMethod() === "POST") {
630
+ await this.store(object, property, await this._getFile(ctx), await ctx.getRequestBody());
661
631
  }
662
632
  else {
663
- if (ctx.getHttpContext().getMethod() === "POST") {
664
- yield this.store(object, property, yield this._getFile(ctx), yield ctx.getRequestBody());
633
+ if (object[property][index].hash !== ctx.parameter("hash")) {
634
+ throw 412;
665
635
  }
666
- else {
667
- if (object[property][index].hash !== ctx.parameter("hash")) {
668
- throw 412;
669
- }
670
- if (ctx.getHttpContext().getMethod() === "DELETE") {
671
- yield this.delete(object, property, index);
672
- }
673
- else if (ctx.getHttpContext().getMethod() === "PUT") {
674
- let metadata = yield ctx.getRequestBody();
675
- // Limit metadata to 4kb
676
- if (JSON.stringify(metadata).length >= 4096) {
677
- throw 400;
678
- }
679
- let evt = {
680
- service: this,
681
- object: object[property][index],
682
- target: object
683
- };
684
- yield this.emitSync("Binary.MetadataUpdate", Object.assign(Object.assign({}, evt), { metadata }));
685
- object[property][index].metadata = metadata;
686
- // Update mapper on purpose
687
- yield object.getStore().patch({
688
- [object.__class.getUuidField()]: object.getUuid(),
689
- [property]: object[property].map(b => b.toJSON())
690
- }, false);
691
- yield this.emitSync("Binary.MetadataUpdated", evt);
636
+ if (ctx.getHttpContext().getMethod() === "DELETE") {
637
+ await this.delete(object, property, index);
638
+ }
639
+ else if (ctx.getHttpContext().getMethod() === "PUT") {
640
+ let metadata = await ctx.getRequestBody();
641
+ // Limit metadata to 4kb
642
+ if (JSON.stringify(metadata).length >= 4096) {
643
+ throw 400;
692
644
  }
645
+ let evt = {
646
+ service: this,
647
+ object: object[property][index],
648
+ target: object
649
+ };
650
+ await this.emitSync("Binary.MetadataUpdate", {
651
+ ...evt,
652
+ metadata
653
+ });
654
+ object[property][index].metadata = metadata;
655
+ // Update mapper on purpose
656
+ await object.getStore().patch({
657
+ [object.__class.getUuidField()]: object.getUuid(),
658
+ [property]: object[property].map(b => b.toJSON())
659
+ }, false);
660
+ await this.emitSync("Binary.MetadataUpdated", evt);
693
661
  }
694
662
  }
695
- });
663
+ }
696
664
  }
697
665
  }
698
- exports.Binary = Binary;
666
+ export { Binary };
699
667
  //# sourceMappingURL=binary.js.map