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