@aeriajs/builtins 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. package/LICENSE +19 -0
  2. package/README.md +6 -0
  3. package/dist/collections/file/description.d.ts +50 -0
  4. package/dist/collections/file/description.js +70 -0
  5. package/dist/collections/file/description.mjs +258 -0
  6. package/dist/collections/file/download.d.ts +13 -0
  7. package/dist/collections/file/download.js +78 -0
  8. package/dist/collections/file/download.mjs +232 -0
  9. package/dist/collections/file/index.d.ts +1183 -0
  10. package/dist/collections/file/index.js +49 -0
  11. package/dist/collections/file/index.mjs +46 -0
  12. package/dist/collections/file/insert.d.ts +7 -0
  13. package/dist/collections/file/insert.js +44 -0
  14. package/dist/collections/file/insert.mjs +246 -0
  15. package/dist/collections/file/remove.d.ts +3 -0
  16. package/dist/collections/file/remove.js +28 -0
  17. package/dist/collections/file/remove.mjs +184 -0
  18. package/dist/collections/file/removeAll.d.ts +3 -0
  19. package/dist/collections/file/removeAll.js +30 -0
  20. package/dist/collections/file/removeAll.mjs +194 -0
  21. package/dist/collections/index.d.ts +4 -0
  22. package/dist/collections/index.js +20 -0
  23. package/dist/collections/index.mjs +4 -0
  24. package/dist/collections/log/index.d.ts +458 -0
  25. package/dist/collections/log/index.js +46 -0
  26. package/dist/collections/log/index.mjs +45 -0
  27. package/dist/collections/resourceUsage/index.d.ts +57 -0
  28. package/dist/collections/resourceUsage/index.js +19 -0
  29. package/dist/collections/resourceUsage/index.mjs +16 -0
  30. package/dist/collections/user/activate.d.ts +10 -0
  31. package/dist/collections/user/activate.js +65 -0
  32. package/dist/collections/user/activate.mjs +247 -0
  33. package/dist/collections/user/authenticate.d.ts +24 -0
  34. package/dist/collections/user/authenticate.js +103 -0
  35. package/dist/collections/user/authenticate.mjs +398 -0
  36. package/dist/collections/user/createAccount.d.ts +101 -0
  37. package/dist/collections/user/createAccount.js +66 -0
  38. package/dist/collections/user/createAccount.mjs +219 -0
  39. package/dist/collections/user/description.d.ts +103 -0
  40. package/dist/collections/user/description.js +146 -0
  41. package/dist/collections/user/description.mjs +151 -0
  42. package/dist/collections/user/getActivationLink.d.ts +2 -0
  43. package/dist/collections/user/getActivationLink.js +15 -0
  44. package/dist/collections/user/getActivationLink.mjs +156 -0
  45. package/dist/collections/user/getInfo.d.ts +14 -0
  46. package/dist/collections/user/getInfo.js +39 -0
  47. package/dist/collections/user/getInfo.mjs +192 -0
  48. package/dist/collections/user/index.d.ts +3992 -0
  49. package/dist/collections/user/index.js +37 -0
  50. package/dist/collections/user/index.mjs +36 -0
  51. package/dist/collections/user/insert.d.ts +5 -0
  52. package/dist/collections/user/insert.js +35 -0
  53. package/dist/collections/user/insert.mjs +156 -0
  54. package/dist/functions/describe.d.ts +2 -0
  55. package/dist/functions/describe.js +54 -0
  56. package/dist/functions/describe.mjs +302 -0
  57. package/dist/functions/index.d.ts +1 -0
  58. package/dist/functions/index.js +17 -0
  59. package/dist/functions/index.mjs +1 -0
  60. package/dist/index.d.ts +5701 -0
  61. package/dist/index.js +39 -0
  62. package/dist/index.mjs +11 -0
  63. package/package.json +60 -0
@@ -0,0 +1,232 @@
1
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
+ }
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(undefined);
27
+ });
28
+ };
29
+ }
30
+ function _ts_generator(thisArg, body) {
31
+ var f, y, t, g, _ = {
32
+ label: 0,
33
+ sent: function() {
34
+ if (t[0] & 1) throw t[1];
35
+ return t[1];
36
+ },
37
+ trys: [],
38
+ ops: []
39
+ };
40
+ return g = {
41
+ next: verb(0),
42
+ "throw": verb(1),
43
+ "return": verb(2)
44
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
+ return this;
46
+ }), g;
47
+ function verb(n) {
48
+ return function(v) {
49
+ return step([
50
+ n,
51
+ v
52
+ ]);
53
+ };
54
+ }
55
+ function step(op) {
56
+ if (f) throw new TypeError("Generator is already executing.");
57
+ while(_)try {
58
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
59
+ if (y = 0, t) op = [
60
+ op[0] & 2,
61
+ t.value
62
+ ];
63
+ switch(op[0]){
64
+ case 0:
65
+ case 1:
66
+ t = op;
67
+ break;
68
+ case 4:
69
+ _.label++;
70
+ return {
71
+ value: op[1],
72
+ done: false
73
+ };
74
+ case 5:
75
+ _.label++;
76
+ y = op[1];
77
+ op = [
78
+ 0
79
+ ];
80
+ continue;
81
+ case 7:
82
+ op = _.ops.pop();
83
+ _.trys.pop();
84
+ continue;
85
+ default:
86
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
+ _ = 0;
88
+ continue;
89
+ }
90
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
+ _.label = op[1];
92
+ break;
93
+ }
94
+ if (op[0] === 6 && _.label < t[1]) {
95
+ _.label = t[1];
96
+ t = op;
97
+ break;
98
+ }
99
+ if (t && _.label < t[2]) {
100
+ _.label = t[2];
101
+ _.ops.push(op);
102
+ break;
103
+ }
104
+ if (t[2]) _.ops.pop();
105
+ _.trys.pop();
106
+ continue;
107
+ }
108
+ op = body.call(thisArg, _);
109
+ } catch (e) {
110
+ op = [
111
+ 6,
112
+ e
113
+ ];
114
+ y = 0;
115
+ } finally{
116
+ f = t = 0;
117
+ }
118
+ if (op[0] & 5) throw op[1];
119
+ return {
120
+ value: op[0] ? op[1] : void 0,
121
+ done: true
122
+ };
123
+ }
124
+ }
125
+ import { ObjectId } from "mongodb";
126
+ import { left } from "@aeriajs/common";
127
+ import fs from "fs";
128
+ export var FileReadError;
129
+ (function(FileReadError) {
130
+ FileReadError["DocumentNotFound"] = "DOCUMENT_NOT_FOUND";
131
+ FileReadError["FileNotFound"] = "FILE_NOT_FOUND";
132
+ })(FileReadError || (FileReadError = {}));
133
+ export var download = function() {
134
+ var _ref = _async_to_generator(function(payload, context) {
135
+ var fileId, _payload_options, options, file, stat, e, range, parts, start, end, chunkSize;
136
+ return _ts_generator(this, function(_state) {
137
+ switch(_state.label){
138
+ case 0:
139
+ fileId = payload.fileId, _payload_options = payload.options, options = _payload_options === void 0 ? [] : _payload_options;
140
+ return [
141
+ 4,
142
+ context.collection.model.findOne({
143
+ _id: new ObjectId(fileId)
144
+ }, {
145
+ projection: {
146
+ absolute_path: 1,
147
+ filename: 1,
148
+ mime: 1
149
+ }
150
+ })
151
+ ];
152
+ case 1:
153
+ file = _state.sent();
154
+ if (!file) {
155
+ if (!payload.noHeaders) {
156
+ context.response.writeHead(404, {
157
+ "content-type": "application/json"
158
+ });
159
+ }
160
+ return [
161
+ 2,
162
+ left("DOCUMENT_NOT_FOUND")
163
+ ];
164
+ }
165
+ _state.label = 2;
166
+ case 2:
167
+ _state.trys.push([
168
+ 2,
169
+ 4,
170
+ ,
171
+ 5
172
+ ]);
173
+ return [
174
+ 4,
175
+ fs.promises.stat(file.absolute_path)
176
+ ];
177
+ case 3:
178
+ stat = _state.sent();
179
+ return [
180
+ 3,
181
+ 5
182
+ ];
183
+ case 4:
184
+ e = _state.sent();
185
+ context.response.writeHead(404, {
186
+ "content-type": "application/json"
187
+ });
188
+ return [
189
+ 2,
190
+ left("FILE_NOT_FOUND")
191
+ ];
192
+ case 5:
193
+ range = context.request.headers.range;
194
+ if (range) {
195
+ parts = range.replace(/bytes=/, "").split("-");
196
+ start = parseInt(parts[0]);
197
+ end = parts[1] ? parseInt(parts[1]) : stat.size - 1;
198
+ chunkSize = end - start + 1;
199
+ if (!payload.noHeaders) {
200
+ context.response.writeHead(206, {
201
+ "accept-ranges": "bytes",
202
+ "content-range": "bytes ".concat(start, "-").concat(end, "/").concat(stat.size),
203
+ "content-length": chunkSize,
204
+ "content-type": file.mime,
205
+ "content-disposition": "".concat(options.includes("download") ? "attachment; " : "", "filename=").concat(encodeURI(file.filename))
206
+ });
207
+ }
208
+ return [
209
+ 2,
210
+ fs.createReadStream(file.absolute_path, {
211
+ start: start,
212
+ end: end
213
+ })
214
+ ];
215
+ }
216
+ if (!payload.noHeaders) {
217
+ context.response.writeHead(200, {
218
+ "content-type": file.mime,
219
+ "content-disposition": "".concat(options.includes("download") ? "attachment; " : "", "filename=").concat(encodeURI(file.filename))
220
+ });
221
+ }
222
+ return [
223
+ 2,
224
+ fs.createReadStream(file.absolute_path)
225
+ ];
226
+ }
227
+ });
228
+ });
229
+ return function download(payload, context) {
230
+ return _ref.apply(this, arguments);
231
+ };
232
+ }();