@aeriajs/core 0.0.276 → 0.0.278

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 (73) hide show
  1. package/dist/__scripts__/postinstall.js +2 -37
  2. package/dist/accessControl.js +14 -18
  3. package/dist/assets.js +25 -31
  4. package/dist/collection/cascadingRemove.js +14 -19
  5. package/dist/collection/define.js +5 -10
  6. package/dist/collection/description.js +2 -7
  7. package/dist/collection/index.js +8 -24
  8. package/dist/collection/makePagination.js +5 -9
  9. package/dist/collection/normalizeProjection.js +1 -5
  10. package/dist/collection/preload.js +13 -18
  11. package/dist/collection/reference.js +19 -26
  12. package/dist/collection/traverseDocument.js +97 -131
  13. package/dist/context.js +16 -53
  14. package/dist/database.js +12 -52
  15. package/dist/endpoints.js +11 -48
  16. package/dist/functions/count.js +11 -15
  17. package/dist/functions/get.js +20 -24
  18. package/dist/functions/getAll.js +8 -12
  19. package/dist/functions/index.js +9 -27
  20. package/dist/functions/insert.js +19 -23
  21. package/dist/functions/remove.js +15 -19
  22. package/dist/functions/removeAll.js +11 -15
  23. package/dist/functions/removeFile.js +7 -11
  24. package/dist/functions/unpaginatedGetAll.js +15 -19
  25. package/dist/functions/upload.js +19 -57
  26. package/dist/index.js +11 -51
  27. package/dist/presets/add.js +1 -4
  28. package/dist/presets/crud.js +1 -4
  29. package/dist/presets/duplicate.js +1 -4
  30. package/dist/presets/index.js +17 -20
  31. package/dist/presets/owned.js +1 -4
  32. package/dist/presets/remove.js +1 -4
  33. package/dist/presets/removeAll.js +1 -4
  34. package/dist/presets/timestamped.js +1 -4
  35. package/dist/presets/view.js +1 -4
  36. package/dist/token.js +7 -15
  37. package/package.json +12 -17
  38. package/dist/__scripts__/postinstall.mjs +0 -50
  39. package/dist/accessControl.mjs +0 -31
  40. package/dist/assets.mjs +0 -67
  41. package/dist/collection/cascadingRemove.mjs +0 -71
  42. package/dist/collection/define.mjs +0 -13
  43. package/dist/collection/description.mjs +0 -8
  44. package/dist/collection/index.mjs +0 -9
  45. package/dist/collection/makePagination.mjs +0 -20
  46. package/dist/collection/normalizeProjection.mjs +0 -17
  47. package/dist/collection/preload.mjs +0 -88
  48. package/dist/collection/reference.mjs +0 -374
  49. package/dist/collection/traverseDocument.mjs +0 -451
  50. package/dist/context.mjs +0 -120
  51. package/dist/database.mjs +0 -49
  52. package/dist/endpoints.mjs +0 -52
  53. package/dist/functions/count.mjs +0 -50
  54. package/dist/functions/get.mjs +0 -89
  55. package/dist/functions/getAll.mjs +0 -14
  56. package/dist/functions/index.mjs +0 -12
  57. package/dist/functions/insert.mjs +0 -102
  58. package/dist/functions/remove.mjs +0 -41
  59. package/dist/functions/removeAll.mjs +0 -40
  60. package/dist/functions/removeFile.mjs +0 -29
  61. package/dist/functions/unpaginatedGetAll.mjs +0 -123
  62. package/dist/functions/upload.mjs +0 -91
  63. package/dist/index.mjs +0 -14
  64. package/dist/presets/add.mjs +0 -12
  65. package/dist/presets/crud.mjs +0 -35
  66. package/dist/presets/duplicate.mjs +0 -11
  67. package/dist/presets/index.mjs +0 -19
  68. package/dist/presets/owned.mjs +0 -9
  69. package/dist/presets/remove.mjs +0 -11
  70. package/dist/presets/removeAll.mjs +0 -11
  71. package/dist/presets/timestamped.mjs +0 -19
  72. package/dist/presets/view.mjs +0 -14
  73. package/dist/token.mjs +0 -31
@@ -1,51 +1,15 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.traverseDocument = void 0;
37
- const path = __importStar(require("node:path"));
38
- const fs = __importStar(require("node:fs/promises"));
39
- const types_1 = require("@aeriajs/types");
40
- const common_1 = require("@aeriajs/common");
41
- const validation_1 = require("@aeriajs/validation");
42
- const entrypoint_1 = require("@aeriajs/entrypoint");
43
- const mongodb_1 = require("mongodb");
44
- const assets_js_1 = require("../assets.js");
45
- const context_js_1 = require("../context.js");
46
- const preload_js_1 = require("./preload.js");
47
- const reference_js_1 = require("./reference.js");
48
- const cascadingRemove_js_1 = require("./cascadingRemove.js");
1
+ import * as path from 'node:path';
2
+ import * as fs from 'node:fs/promises';
3
+ import { Result, ACError, ValidationErrorCode, TraverseError } from '@aeriajs/types';
4
+ import { throwIfError, isReference, getReferenceProperty, getValueFromPath } from '@aeriajs/common';
5
+ import { makeValidationError, validatePropertyWithRefs, validateWholeness } from '@aeriajs/validation';
6
+ import { getCollection } from '@aeriajs/entrypoint';
7
+ import { ObjectId } from 'mongodb';
8
+ import { getCollectionAsset } from '../assets.js';
9
+ import { createContext } from '../context.js';
10
+ import { preloadDescription } from './preload.js';
11
+ import { getReferences } from './reference.js';
12
+ import { preferredRemove } from './cascadingRemove.js';
49
13
  const escapeRegExp = (text) => {
50
14
  return text.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
51
15
  };
@@ -67,25 +31,25 @@ const getProperty = (propName, parentProperty) => {
67
31
  };
68
32
  const cleanupReferences = async (value, ctx) => {
69
33
  if (ctx.root._id) {
70
- const refProperty = (0, common_1.getReferenceProperty)(ctx.property);
34
+ const refProperty = getReferenceProperty(ctx.property);
71
35
  if (refProperty && (refProperty.$ref === 'file' || refProperty.inline)) {
72
36
  if (ctx.isArray && !Array.isArray(value)) {
73
- return types_1.Result.result(value);
37
+ return Result.result(value);
74
38
  }
75
39
  const context = ctx.options.context;
76
40
  const doc = await context.collections[ctx.options.description.$id].model.findOne({
77
- _id: new mongodb_1.ObjectId(ctx.root._id),
41
+ _id: new ObjectId(ctx.root._id),
78
42
  }, {
79
43
  projection: {
80
44
  [ctx.propPath]: 1,
81
45
  },
82
46
  });
83
47
  if (!doc) {
84
- return types_1.Result.error(types_1.TraverseError.InvalidDocumentId);
48
+ return Result.error(TraverseError.InvalidDocumentId);
85
49
  }
86
- let referenceIds = (0, common_1.getValueFromPath)(doc, ctx.propPath);
50
+ let referenceIds = getValueFromPath(doc, ctx.propPath);
87
51
  if (!referenceIds) {
88
- return types_1.Result.result(value);
52
+ return Result.result(value);
89
53
  }
90
54
  if (Array.isArray(referenceIds)) {
91
55
  if (!Array.isArray(value)) {
@@ -95,59 +59,62 @@ const cleanupReferences = async (value, ctx) => {
95
59
  }
96
60
  else {
97
61
  if (referenceIds.equals(value)) {
98
- return types_1.Result.result(value);
62
+ return Result.result(value);
99
63
  }
100
64
  }
101
- const refMap = await (0, reference_js_1.getReferences)({
65
+ const refMap = await getReferences({
102
66
  [ctx.propName]: ctx.property,
103
67
  });
104
- await (0, cascadingRemove_js_1.preferredRemove)(referenceIds, refMap[ctx.propName], await (0, context_js_1.createContext)({
68
+ await preferredRemove(referenceIds, refMap[ctx.propName], await createContext({
105
69
  parentContext: context,
106
70
  collectionName: refProperty.$ref,
107
71
  }));
108
72
  }
109
73
  }
110
- return types_1.Result.result(value);
74
+ return Result.result(value);
111
75
  };
112
76
  const autoCast = (value, ctx) => {
113
77
  switch (typeof value) {
114
78
  case 'boolean': {
115
- return types_1.Result.result(!!value);
79
+ return Result.result(!!value);
116
80
  }
117
81
  case 'string': {
118
- if ((0, common_1.isReference)(ctx.property)) {
119
- return types_1.Result.result(mongodb_1.ObjectId.isValid(value)
120
- ? new mongodb_1.ObjectId(value)
82
+ if (isReference(ctx.property)) {
83
+ return Result.result(ObjectId.isValid(value)
84
+ ? new ObjectId(value)
121
85
  : value);
122
86
  }
123
87
  if ('format' in ctx.property) {
124
- if (ctx.property.format === 'date' || ctx.property.format === 'date-time') {
125
- const timestamp = Date.parse(value);
126
- return types_1.Result.result(!Number.isNaN(timestamp)
127
- ? new Date(timestamp)
128
- : null);
88
+ switch (ctx.property.format) {
89
+ case 'date':
90
+ case 'date-time': {
91
+ const timestamp = Date.parse(value);
92
+ return Result.result(!Number.isNaN(timestamp)
93
+ ? new Date(timestamp)
94
+ : null);
95
+ }
129
96
  }
130
97
  }
131
98
  break;
132
99
  }
133
100
  case 'number': {
134
101
  if ('type' in ctx.property && ctx.property.type === 'integer') {
135
- return types_1.Result.result(parseInt(value.toString()));
102
+ return Result.result(parseInt(value.toString()));
136
103
  }
137
104
  if ('format' in ctx.property) {
138
105
  if (ctx.property.format === 'date' || ctx.property.format === 'date-time') {
139
- return types_1.Result.result(new Date(value));
106
+ return Result.result(new Date(value));
140
107
  }
141
108
  }
142
109
  break;
143
110
  }
144
111
  case 'object': {
145
- if (!value || value instanceof mongodb_1.ObjectId) {
146
- return types_1.Result.result(value);
112
+ if (!value || value instanceof ObjectId) {
113
+ return Result.result(value);
147
114
  }
148
115
  if (!('description' in ctx.options) || !ctx.options.recurseDeep) {
149
116
  if (Array.isArray(value)) {
150
- return types_1.Result.result(value.map((v) => (0, common_1.throwIfError)(autoCast(v, ctx))));
117
+ return Result.result(value.map((v) => throwIfError(autoCast(v, ctx))));
151
118
  }
152
119
  if (Object.keys(value).length > 0) {
153
120
  const entries = {};
@@ -158,17 +125,17 @@ const autoCast = (value, ctx) => {
158
125
  if (!subProperty) {
159
126
  continue;
160
127
  }
161
- entries[k] = (0, common_1.throwIfError)(autoCast(v, {
128
+ entries[k] = throwIfError(autoCast(v, {
162
129
  ...ctx,
163
130
  property: subProperty,
164
131
  }));
165
132
  }
166
- return types_1.Result.result(entries);
133
+ return Result.result(entries);
167
134
  }
168
135
  }
169
136
  }
170
137
  }
171
- return types_1.Result.result(value);
138
+ return Result.result(value);
172
139
  };
173
140
  const getters = async (value, ctx) => {
174
141
  if ('getter' in ctx.property) {
@@ -176,95 +143,95 @@ const getters = async (value, ctx) => {
176
143
  throw new Error;
177
144
  }
178
145
  if (!ctx.property.getter) {
179
- return types_1.Result.result(undefined);
146
+ return Result.result(undefined);
180
147
  }
181
- return types_1.Result.result(await ctx.property.getter(ctx.target, ctx.options.context));
148
+ return Result.result(await ctx.property.getter(ctx.target, ctx.options.context));
182
149
  }
183
- return types_1.Result.result(value);
150
+ return Result.result(value);
184
151
  };
185
152
  const validate = async (value, ctx) => {
186
153
  if (ctx.options.recurseDeep) {
187
154
  if ('properties' in ctx.property) {
188
- return types_1.Result.result(value);
155
+ return Result.result(value);
189
156
  }
190
157
  }
191
158
  if ('$ref' in ctx.property && ctx.property.$ref === 'file') {
192
- return types_1.Result.result(value);
159
+ return Result.result(value);
193
160
  }
194
- const { error } = await (0, validation_1.validatePropertyWithRefs)(value, ctx.property, {
161
+ const { error } = await validatePropertyWithRefs(value, ctx.property, {
195
162
  checkObjectIds: true,
196
163
  context: ctx.options.context,
197
- objectIdConstructor: mongodb_1.ObjectId,
164
+ objectIdConstructor: ObjectId,
198
165
  });
199
166
  if (error) {
200
- return types_1.Result.error({
167
+ return Result.error({
201
168
  [ctx.propName]: error,
202
169
  });
203
170
  }
204
- return types_1.Result.result(value);
171
+ return Result.result(value);
205
172
  };
206
173
  const isValidTempFile = (value) => {
207
174
  if (value && typeof value === 'object') {
208
- if (value instanceof mongodb_1.ObjectId) {
175
+ if (value instanceof ObjectId) {
209
176
  return true;
210
177
  }
211
- return 'tempId' in value && (typeof value.tempId === 'string' || value.tempId instanceof mongodb_1.ObjectId);
178
+ return 'tempId' in value && (typeof value.tempId === 'string' || value.tempId instanceof ObjectId);
212
179
  }
213
180
  return !!(value === undefined
214
181
  || value === null);
215
182
  };
216
183
  const isMissingPropertyError = (error) => {
217
- return 'code' in error && error.code === types_1.ValidationErrorCode.MissingProperties;
184
+ return 'code' in error && error.code === ValidationErrorCode.MissingProperties;
218
185
  };
219
186
  const moveFiles = async (value, ctx) => {
220
187
  if (!('$ref' in ctx.property) || ctx.property.$ref !== 'file') {
221
- return types_1.Result.result(value);
188
+ return Result.result(value);
222
189
  }
223
- const tempFileCollection = await (0, entrypoint_1.getCollection)('tempFile');
190
+ const tempFileCollection = await getCollection('tempFile');
224
191
  if (!tempFileCollection) {
225
192
  throw new Error('The "tempFile" collection is absent, yet it is required to upload files.');
226
193
  }
227
194
  if (!isValidTempFile(value)) {
228
- return types_1.Result.error(types_1.TraverseError.InvalidTempfile);
195
+ return Result.error(TraverseError.InvalidTempfile);
229
196
  }
230
197
  if (!value) {
231
- return types_1.Result.result(null);
198
+ return Result.result(null);
232
199
  }
233
- if (value instanceof mongodb_1.ObjectId) {
234
- return types_1.Result.result(value);
200
+ if (value instanceof ObjectId) {
201
+ return Result.result(value);
235
202
  }
236
203
  if (!ctx.options.context) {
237
204
  throw new Error();
238
205
  }
239
206
  const tempFile = await ctx.options.context.collections.tempFile.model.findOne({
240
- _id: new mongodb_1.ObjectId(value.tempId),
207
+ _id: new ObjectId(value.tempId),
241
208
  });
242
209
  if (!tempFile) {
243
- return types_1.Result.error(types_1.TraverseError.InvalidTempfile);
210
+ return Result.error(TraverseError.InvalidTempfile);
244
211
  }
245
212
  const { _id: fileId, ...newFile } = tempFile;
246
213
  newFile.absolute_path = `${ctx.options.context.config.storage.fs}/${tempFile.absolute_path.split(path.sep).at(-1)}`;
247
214
  newFile.owner = ctx.options.context.token.sub;
248
215
  await fs.rename(tempFile.absolute_path, newFile.absolute_path);
249
216
  const file = await ctx.options.context.collections.file.model.insertOne(newFile);
250
- return types_1.Result.result(file.insertedId);
217
+ return Result.result(file.insertedId);
251
218
  };
252
219
  const recurseDeep = async (value, ctx) => {
253
220
  if (!value) {
254
- return types_1.Result.result(value);
221
+ return Result.result(value);
255
222
  }
256
223
  if ('properties' in ctx.property) {
257
224
  if (ctx.options.validateWholeness) {
258
- const wholenessError = (0, validation_1.validateWholeness)(value, ctx.property);
225
+ const wholenessError = validateWholeness(value, ctx.property);
259
226
  if (wholenessError) {
260
- return types_1.Result.error(wholenessError);
227
+ return Result.error(wholenessError);
261
228
  }
262
229
  }
263
230
  return recurse(value, ctx);
264
231
  }
265
232
  if ('items' in ctx.property) {
266
233
  if (!Array.isArray(value)) {
267
- return types_1.Result.result(value);
234
+ return Result.result(value);
268
235
  }
269
236
  const items = [];
270
237
  for (const item of value) {
@@ -277,9 +244,9 @@ const recurseDeep = async (value, ctx) => {
277
244
  items.push(result);
278
245
  }
279
246
  }
280
- return types_1.Result.result(items);
247
+ return Result.result(items);
281
248
  }
282
- return types_1.Result.result(value);
249
+ return Result.result(value);
283
250
  };
284
251
  const recurse = async (target, ctx) => {
285
252
  const entries = {};
@@ -295,7 +262,7 @@ const recurse = async (target, ctx) => {
295
262
  if (propName === '_id') {
296
263
  if (value) {
297
264
  if (ctx.options.autoCast) {
298
- entries[propName] = (0, common_1.throwIfError)(autoCast(value, {
265
+ entries[propName] = throwIfError(autoCast(value, {
299
266
  ...ctx,
300
267
  target,
301
268
  propName,
@@ -320,7 +287,7 @@ const recurse = async (target, ctx) => {
320
287
  for (const key in value) {
321
288
  if (key.startsWith('$')) {
322
289
  if (!ctx.options.allowOperators) {
323
- return types_1.Result.error(types_1.ACError.InsecureOperator);
290
+ return Result.error(ACError.InsecureOperator);
324
291
  }
325
292
  if (key === '$regex' && typeof value[key] === 'string') {
326
293
  if (!ctx.options.noRegExpEscaping) {
@@ -341,7 +308,7 @@ const recurse = async (target, ctx) => {
341
308
  for (const operation of value) {
342
309
  const { error, result } = await recurse(operation, ctx);
343
310
  if (error) {
344
- return types_1.Result.error(error);
311
+ return Result.error(error);
345
312
  }
346
313
  operations.push(result);
347
314
  }
@@ -350,7 +317,7 @@ const recurse = async (target, ctx) => {
350
317
  }
351
318
  const { error, result: operator } = await recurse(value, ctx);
352
319
  if (error) {
353
- return types_1.Result.error(error);
320
+ return Result.error(error);
354
321
  }
355
322
  entries[propName] = operator;
356
323
  continue;
@@ -373,31 +340,31 @@ const recurse = async (target, ctx) => {
373
340
  const propCast = 'items' in property
374
341
  ? property.items
375
342
  : property;
376
- if ('$ref' in propCast && value && !(value instanceof mongodb_1.ObjectId)) {
377
- const targetDescription = await (0, preload_js_1.preloadDescription)((0, common_1.throwIfError)(await (0, assets_js_1.getCollectionAsset)(propCast.$ref, 'description')));
343
+ if ('$ref' in propCast && value && !(value instanceof ObjectId)) {
344
+ const targetDescription = await preloadDescription(throwIfError(await getCollectionAsset(propCast.$ref, 'description')));
378
345
  if (Array.isArray(value)) {
379
346
  const documents = [];
380
347
  for (const elem of value) {
381
- if (elem instanceof mongodb_1.ObjectId) {
348
+ if (elem instanceof ObjectId) {
382
349
  documents.push(elem);
383
350
  continue;
384
351
  }
385
352
  if (typeof elem === 'string') {
386
- documents.push(new mongodb_1.ObjectId(elem));
353
+ documents.push(new ObjectId(elem));
387
354
  continue;
388
355
  }
389
- const { error, result } = await (0, exports.traverseDocument)(elem, targetDescription, ctx.options);
356
+ const { error, result } = await traverseDocument(elem, targetDescription, ctx.options);
390
357
  if (error) {
391
- return types_1.Result.error(error);
358
+ return Result.error(error);
392
359
  }
393
360
  documents.push(result);
394
361
  }
395
362
  entries[propName] = documents;
396
363
  continue;
397
364
  }
398
- const { error, result: doc } = await (0, exports.traverseDocument)(value, targetDescription, ctx.options);
365
+ const { error, result: doc } = await traverseDocument(value, targetDescription, ctx.options);
399
366
  if (error) {
400
- return types_1.Result.error(error);
367
+ return Result.error(error);
401
368
  }
402
369
  entries[propName] = doc;
403
370
  continue;
@@ -417,11 +384,11 @@ const recurse = async (target, ctx) => {
417
384
  }
418
385
  }
419
386
  }
420
- return types_1.Result.result(entries);
387
+ return Result.result(entries);
421
388
  };
422
- const traverseDocument = async (what, description, _options) => {
389
+ export const traverseDocument = async (what, description, _options) => {
423
390
  if (!what) {
424
- return types_1.Result.result(what);
391
+ return Result.result(what);
425
392
  }
426
393
  const whatCopy = Object.assign({}, what);
427
394
  const options = Object.assign({
@@ -429,7 +396,7 @@ const traverseDocument = async (what, description, _options) => {
429
396
  }, _options);
430
397
  const functions = [];
431
398
  if (!options.validate && Object.keys(whatCopy).length === 0) {
432
- return types_1.Result.result(whatCopy);
399
+ return Result.result(whatCopy);
433
400
  }
434
401
  if (options.recurseDeep) {
435
402
  functions.push(recurseDeep);
@@ -442,9 +409,9 @@ const traverseDocument = async (what, description, _options) => {
442
409
  }
443
410
  if (options.validate) {
444
411
  if (options.validateWholeness === true) {
445
- const wholenessError = (0, validation_1.validateWholeness)(whatCopy, options.description);
412
+ const wholenessError = validateWholeness(whatCopy, options.description);
446
413
  if (wholenessError) {
447
- return types_1.Result.error(wholenessError);
414
+ return Result.error(wholenessError);
448
415
  }
449
416
  }
450
417
  functions.push(validate);
@@ -463,19 +430,19 @@ const traverseDocument = async (what, description, _options) => {
463
430
  if (error) {
464
431
  const narrowedError = error;
465
432
  switch (narrowedError) {
466
- case types_1.TraverseError.InvalidDocumentId:
467
- case types_1.TraverseError.InvalidTempfile:
433
+ case TraverseError.InvalidDocumentId:
434
+ case TraverseError.InvalidTempfile:
468
435
  traverseError = narrowedError;
469
436
  break;
470
437
  default: {
471
438
  validationError = narrowedError;
472
439
  }
473
440
  }
474
- return types_1.Result.error(error);
441
+ return Result.error(error);
475
442
  }
476
443
  value = ctx.target[ctx.propName] = result;
477
444
  }
478
- return types_1.Result.result(value);
445
+ return Result.result(value);
479
446
  };
480
447
  const { error, result } = await recurse(whatCopy, {
481
448
  root: whatCopy,
@@ -484,20 +451,19 @@ const traverseDocument = async (what, description, _options) => {
484
451
  options,
485
452
  });
486
453
  if (error) {
487
- return types_1.Result.error(error);
454
+ return Result.error(error);
488
455
  }
489
456
  if (traverseError) {
490
- return types_1.Result.error(traverseError);
457
+ return Result.error(traverseError);
491
458
  }
492
459
  if (validationError) {
493
460
  if (isMissingPropertyError(validationError)) {
494
- return types_1.Result.error(validationError);
461
+ return Result.error(validationError);
495
462
  }
496
- return types_1.Result.error((0, validation_1.makeValidationError)({
497
- code: types_1.ValidationErrorCode.InvalidProperties,
463
+ return Result.error(makeValidationError({
464
+ code: ValidationErrorCode.InvalidProperties,
498
465
  details: validationError,
499
466
  }));
500
467
  }
501
- return types_1.Result.result(result);
468
+ return Result.result(result);
502
469
  };
503
- exports.traverseDocument = traverseDocument;
package/dist/context.js CHANGED
@@ -1,44 +1,8 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.createContext = void 0;
37
- const common_1 = require("@aeriajs/common");
38
- const entrypoint_1 = require("@aeriajs/entrypoint");
39
- const security_1 = require("@aeriajs/security");
40
- const database_js_1 = require("./database.js");
41
- const preload_js_1 = require("./collection/preload.js");
1
+ import { throwIfError, endpointError } from '@aeriajs/common';
2
+ import { getCollections } from '@aeriajs/entrypoint';
3
+ import { limitRate } from '@aeriajs/security';
4
+ import { getDatabaseCollection } from './database.js';
5
+ import { preloadDescription } from './collection/preload.js';
42
6
  const indepthCollection = (collectionName, collections, parentContext) => {
43
7
  const candidate = collections[collectionName];
44
8
  const collection = typeof candidate === 'function'
@@ -54,7 +18,7 @@ const indepthCollection = (collectionName, collections, parentContext) => {
54
18
  return null;
55
19
  }
56
20
  return async (props, ...args) => {
57
- const childContext = await (0, exports.createContext)({
21
+ const childContext = await createContext({
58
22
  parentContext,
59
23
  collectionName,
60
24
  inherited: true,
@@ -65,26 +29,26 @@ const indepthCollection = (collectionName, collections, parentContext) => {
65
29
  });
66
30
  return {
67
31
  ...collection,
68
- context: () => (0, exports.createContext)({
32
+ context: () => createContext({
69
33
  parentContext,
70
34
  collectionName,
71
35
  }),
72
36
  functions: proxiedFunctions,
73
37
  originalFunctions: collection.functions,
74
- model: (0, database_js_1.getDatabaseCollection)(collectionName),
38
+ model: getDatabaseCollection(collectionName),
75
39
  };
76
40
  };
77
41
  const isCollectionContext = (_context, collectionName) => {
78
42
  return !!collectionName;
79
43
  };
80
- const createContext = async (_options) => {
44
+ export const createContext = async (_options) => {
81
45
  const options = _options || {};
82
46
  const { collectionName, parentContext, token = parentContext?.token || {
83
47
  authenticated: false,
84
48
  sub: null,
85
49
  }, } = options;
86
- const { getCollectionAsset } = await Promise.resolve().then(() => __importStar(require('./assets.js')));
87
- const collections = await (0, entrypoint_1.getCollections)();
50
+ const { getCollectionAsset } = await import('./assets.js');
51
+ const collections = await getCollections();
88
52
  let config;
89
53
  if (options.config) {
90
54
  config = options.config;
@@ -124,7 +88,7 @@ const createContext = async (_options) => {
124
88
  },
125
89
  }),
126
90
  log: async (message, details) => {
127
- return (0, database_js_1.getDatabaseCollection)('log').insertOne({
91
+ return getDatabaseCollection('log').insertOne({
128
92
  message,
129
93
  details,
130
94
  context: collectionName,
@@ -133,17 +97,17 @@ const createContext = async (_options) => {
133
97
  });
134
98
  },
135
99
  error: (httpStatus, error) => {
136
- return (0, common_1.endpointError)(Object.assign({
100
+ return endpointError(Object.assign({
137
101
  httpStatus,
138
102
  }, error));
139
103
  },
140
104
  limitRate: (params) => {
141
- return (0, security_1.limitRate)(params, context);
105
+ return limitRate(params, context);
142
106
  },
143
107
  };
144
108
  if (isCollectionContext(context, collectionName) && collectionName) {
145
- const description = (0, common_1.throwIfError)(await getCollectionAsset(collectionName, 'description'));
146
- context.description = await (0, preload_js_1.preloadDescription)(description);
109
+ const description = throwIfError(await getCollectionAsset(collectionName, 'description'));
110
+ context.description = await preloadDescription(description);
147
111
  context.collectionName = collectionName;
148
112
  if (!options.calledFunction && parentContext && 'calledFunction' in parentContext) {
149
113
  context.calledFunction = parentContext.calledFunction;
@@ -155,4 +119,3 @@ const createContext = async (_options) => {
155
119
  }
156
120
  return context;
157
121
  };
158
- exports.createContext = createContext;