@aeriajs/core 0.0.158 → 0.0.159
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.
|
@@ -1,19 +1,27 @@
|
|
|
1
1
|
import type { Description, Property, ValidationError, Context } from '@aeriajs/types';
|
|
2
2
|
import { ACError, TraverseError } from '@aeriajs/types';
|
|
3
3
|
import { ObjectId } from 'mongodb';
|
|
4
|
-
export type
|
|
4
|
+
export type TraverseOptionsBase = {
|
|
5
5
|
autoCast?: boolean;
|
|
6
|
-
getters?: boolean;
|
|
7
6
|
validate?: boolean;
|
|
8
7
|
validateRequired?: Description['required'];
|
|
9
|
-
moveFiles?: boolean;
|
|
10
8
|
fromProperties?: boolean;
|
|
11
9
|
allowOperators?: boolean;
|
|
12
10
|
skipUndefined?: boolean;
|
|
13
11
|
recurseDeep?: boolean;
|
|
14
12
|
recurseReferences?: boolean;
|
|
15
|
-
context?: Context;
|
|
16
13
|
};
|
|
14
|
+
export type TraverseOptions = (TraverseOptionsBase & {
|
|
15
|
+
getters?: never;
|
|
16
|
+
moveFiles?: never;
|
|
17
|
+
context?: never;
|
|
18
|
+
}) | (TraverseOptionsBase & {
|
|
19
|
+
getters: true;
|
|
20
|
+
context: Context;
|
|
21
|
+
}) | (TraverseOptionsBase & {
|
|
22
|
+
moveFiles: true;
|
|
23
|
+
context: Context;
|
|
24
|
+
});
|
|
17
25
|
export type TraverseNormalized = {
|
|
18
26
|
description: Description;
|
|
19
27
|
pipe: <T = unknown>(value: unknown, phaseContext: PhaseContext) => T | Promise<T>;
|
|
@@ -160,6 +160,9 @@ const autoCast = (value, ctx) => {
|
|
|
160
160
|
};
|
|
161
161
|
const getters = (value, ctx) => {
|
|
162
162
|
if ('getter' in ctx.property) {
|
|
163
|
+
if (!ctx.options.context) {
|
|
164
|
+
throw new Error;
|
|
165
|
+
}
|
|
163
166
|
return ctx.property.getter(ctx.target, ctx.options.context);
|
|
164
167
|
}
|
|
165
168
|
return value;
|
|
@@ -230,7 +233,7 @@ const recurseDeep = async (value, ctx) => {
|
|
|
230
233
|
});
|
|
231
234
|
items.push(result);
|
|
232
235
|
}
|
|
233
|
-
if (ctx.options.moveFiles && '$ref' in ctx.property.items && ctx.property.items.$ref === 'file') {
|
|
236
|
+
if ('moveFiles' in ctx.options && ctx.options.moveFiles && '$ref' in ctx.property.items && ctx.property.items.$ref === 'file') {
|
|
234
237
|
await disposeOldFiles(ctx, {
|
|
235
238
|
preserveIds: items,
|
|
236
239
|
});
|
|
@@ -251,7 +254,7 @@ const recurse = async (target, ctx) => {
|
|
|
251
254
|
const value = target[propName];
|
|
252
255
|
const property = getProperty(propName, ctx.property);
|
|
253
256
|
if (ctx.options.skipUndefined) {
|
|
254
|
-
if (value === undefined && !(ctx.options.getters && property && 'getter' in property)) {
|
|
257
|
+
if (value === undefined && !('getters' in ctx.options && ctx.options.getters && property && 'getter' in property)) {
|
|
255
258
|
continue;
|
|
256
259
|
}
|
|
257
260
|
}
|
|
@@ -317,7 +320,7 @@ const recurse = async (target, ctx) => {
|
|
|
317
320
|
if (property.hidden) {
|
|
318
321
|
continue;
|
|
319
322
|
}
|
|
320
|
-
if (ctx.options.getters && 'getter' in property) {
|
|
323
|
+
if ('getters' in ctx.options && ctx.options.getters && 'getter' in property) {
|
|
321
324
|
if (property.requires) {
|
|
322
325
|
const missing = property.requires.some((requiredPropName) => !(requiredPropName in target));
|
|
323
326
|
if (missing) {
|
|
@@ -396,7 +399,7 @@ const traverseDocument = async (what, description, _options) => {
|
|
|
396
399
|
if (options.autoCast) {
|
|
397
400
|
functions.push(autoCast);
|
|
398
401
|
}
|
|
399
|
-
if (options.getters) {
|
|
402
|
+
if ('getters' in options && options.getters) {
|
|
400
403
|
functions.push(getters);
|
|
401
404
|
}
|
|
402
405
|
if (options.validate) {
|
|
@@ -410,7 +413,7 @@ const traverseDocument = async (what, description, _options) => {
|
|
|
410
413
|
}
|
|
411
414
|
functions.push(validate);
|
|
412
415
|
}
|
|
413
|
-
if (options.moveFiles) {
|
|
416
|
+
if ('moveFiles' in options && options.moveFiles) {
|
|
414
417
|
functions.push(moveFiles);
|
|
415
418
|
}
|
|
416
419
|
let traverseError;
|
|
@@ -126,6 +126,9 @@ const autoCast = (value, ctx) => {
|
|
|
126
126
|
};
|
|
127
127
|
const getters = (value, ctx) => {
|
|
128
128
|
if ("getter" in ctx.property) {
|
|
129
|
+
if (!ctx.options.context) {
|
|
130
|
+
throw new Error();
|
|
131
|
+
}
|
|
129
132
|
return ctx.property.getter(ctx.target, ctx.options.context);
|
|
130
133
|
}
|
|
131
134
|
return value;
|
|
@@ -196,7 +199,7 @@ const recurseDeep = async (value, ctx) => {
|
|
|
196
199
|
});
|
|
197
200
|
items.push(result);
|
|
198
201
|
}
|
|
199
|
-
if (ctx.options.moveFiles && "$ref" in ctx.property.items && ctx.property.items.$ref === "file") {
|
|
202
|
+
if ("moveFiles" in ctx.options && ctx.options.moveFiles && "$ref" in ctx.property.items && ctx.property.items.$ref === "file") {
|
|
200
203
|
await disposeOldFiles(ctx, {
|
|
201
204
|
preserveIds: items
|
|
202
205
|
});
|
|
@@ -215,7 +218,7 @@ const recurse = async (target, ctx) => {
|
|
|
215
218
|
const value = target[propName];
|
|
216
219
|
const property = getProperty(propName, ctx.property);
|
|
217
220
|
if (ctx.options.skipUndefined) {
|
|
218
|
-
if (value === void 0 && !(ctx.options.getters && property && "getter" in property)) {
|
|
221
|
+
if (value === void 0 && !("getters" in ctx.options && ctx.options.getters && property && "getter" in property)) {
|
|
219
222
|
continue;
|
|
220
223
|
}
|
|
221
224
|
}
|
|
@@ -279,7 +282,7 @@ const recurse = async (target, ctx) => {
|
|
|
279
282
|
if (property.hidden) {
|
|
280
283
|
continue;
|
|
281
284
|
}
|
|
282
|
-
if (ctx.options.getters && "getter" in property) {
|
|
285
|
+
if ("getters" in ctx.options && ctx.options.getters && "getter" in property) {
|
|
283
286
|
if (property.requires) {
|
|
284
287
|
const missing = property.requires.some((requiredPropName) => !(requiredPropName in target));
|
|
285
288
|
if (missing) {
|
|
@@ -354,7 +357,7 @@ export const traverseDocument = async (what, description, _options) => {
|
|
|
354
357
|
if (options.autoCast) {
|
|
355
358
|
functions.push(autoCast);
|
|
356
359
|
}
|
|
357
|
-
if (options.getters) {
|
|
360
|
+
if ("getters" in options && options.getters) {
|
|
358
361
|
functions.push(getters);
|
|
359
362
|
}
|
|
360
363
|
if (options.validate) {
|
|
@@ -368,7 +371,7 @@ export const traverseDocument = async (what, description, _options) => {
|
|
|
368
371
|
}
|
|
369
372
|
functions.push(validate);
|
|
370
373
|
}
|
|
371
|
-
if (options.moveFiles) {
|
|
374
|
+
if ("moveFiles" in options && options.moveFiles) {
|
|
372
375
|
functions.push(moveFiles);
|
|
373
376
|
}
|
|
374
377
|
let traverseError;
|
package/dist/functions/insert.js
CHANGED
|
@@ -70,9 +70,8 @@ const internalInsert = async (payload, context) => {
|
|
|
70
70
|
_id: docId,
|
|
71
71
|
}, content);
|
|
72
72
|
}
|
|
73
|
-
let doc;
|
|
74
73
|
if (context.collection.originalFunctions?.get) {
|
|
75
|
-
|
|
74
|
+
return context.collection.originalFunctions.get({
|
|
76
75
|
filters: {
|
|
77
76
|
_id: newId,
|
|
78
77
|
},
|
|
@@ -80,21 +79,20 @@ const internalInsert = async (payload, context) => {
|
|
|
80
79
|
inherited: true,
|
|
81
80
|
}, context), {
|
|
82
81
|
bypassSecurity: true,
|
|
83
|
-
}));
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
doc = await context.collection.model.findOne({
|
|
87
|
-
_id: newId,
|
|
88
|
-
}, {
|
|
89
|
-
projection,
|
|
90
82
|
});
|
|
91
83
|
}
|
|
84
|
+
const doc = await context.collection.model.findOne({
|
|
85
|
+
_id: newId,
|
|
86
|
+
}, {
|
|
87
|
+
projection,
|
|
88
|
+
});
|
|
92
89
|
if (!doc) {
|
|
93
90
|
return context.error(types_1.HTTPStatus.NotFound, {
|
|
94
91
|
code: types_1.ACError.ResourceNotFound,
|
|
95
92
|
});
|
|
96
93
|
}
|
|
97
94
|
const result = (0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(doc, context.description, {
|
|
95
|
+
context,
|
|
98
96
|
getters: true,
|
|
99
97
|
fromProperties: true,
|
|
100
98
|
recurseReferences: true,
|
|
@@ -60,9 +60,8 @@ const internalInsert = async (payload, context) => {
|
|
|
60
60
|
_id: docId
|
|
61
61
|
}, content);
|
|
62
62
|
}
|
|
63
|
-
let doc;
|
|
64
63
|
if (context.collection.originalFunctions?.get) {
|
|
65
|
-
|
|
64
|
+
return context.collection.originalFunctions.get({
|
|
66
65
|
filters: {
|
|
67
66
|
_id: newId
|
|
68
67
|
}
|
|
@@ -70,20 +69,20 @@ const internalInsert = async (payload, context) => {
|
|
|
70
69
|
inherited: true
|
|
71
70
|
}, context), {
|
|
72
71
|
bypassSecurity: true
|
|
73
|
-
}));
|
|
74
|
-
} else {
|
|
75
|
-
doc = await context.collection.model.findOne({
|
|
76
|
-
_id: newId
|
|
77
|
-
}, {
|
|
78
|
-
projection
|
|
79
72
|
});
|
|
80
73
|
}
|
|
74
|
+
const doc = await context.collection.model.findOne({
|
|
75
|
+
_id: newId
|
|
76
|
+
}, {
|
|
77
|
+
projection
|
|
78
|
+
});
|
|
81
79
|
if (!doc) {
|
|
82
80
|
return context.error(HTTPStatus.NotFound, {
|
|
83
81
|
code: ACError.ResourceNotFound
|
|
84
82
|
});
|
|
85
83
|
}
|
|
86
84
|
const result = throwIfError(await traverseDocument(doc, context.description, {
|
|
85
|
+
context,
|
|
87
86
|
getters: true,
|
|
88
87
|
fromProperties: true,
|
|
89
88
|
recurseReferences: true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.159",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"aeriaMain": "tests/fixtures/aeriaMain.js",
|
|
@@ -42,13 +42,13 @@
|
|
|
42
42
|
"mongodb-memory-server": "^9.2.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"@aeriajs/builtins": "^0.0.
|
|
46
|
-
"@aeriajs/common": "^0.0.
|
|
47
|
-
"@aeriajs/entrypoint": "^0.0.
|
|
48
|
-
"@aeriajs/http": "^0.0.
|
|
49
|
-
"@aeriajs/security": "^0.0.
|
|
50
|
-
"@aeriajs/types": "^0.0.
|
|
51
|
-
"@aeriajs/validation": "^0.0.
|
|
45
|
+
"@aeriajs/builtins": "^0.0.159",
|
|
46
|
+
"@aeriajs/common": "^0.0.96",
|
|
47
|
+
"@aeriajs/entrypoint": "^0.0.98",
|
|
48
|
+
"@aeriajs/http": "^0.0.109",
|
|
49
|
+
"@aeriajs/security": "^0.0.159",
|
|
50
|
+
"@aeriajs/types": "^0.0.82",
|
|
51
|
+
"@aeriajs/validation": "^0.0.99"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"mongodb": "^6.5.0",
|