@aeriajs/core 0.0.157 → 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.
- package/dist/collection/traverseDocument.d.ts +12 -4
- package/dist/collection/traverseDocument.js +12 -6
- package/dist/collection/traverseDocument.mjs +12 -6
- package/dist/functions/get.js +1 -0
- package/dist/functions/get.mjs +1 -0
- package/dist/functions/getAll.js +1 -0
- package/dist/functions/getAll.mjs +1 -0
- package/dist/functions/insert.js +7 -9
- package/dist/functions/insert.mjs +7 -8
- package/package.json +8 -8
|
@@ -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,7 +160,10 @@ const autoCast = (value, ctx) => {
|
|
|
160
160
|
};
|
|
161
161
|
const getters = (value, ctx) => {
|
|
162
162
|
if ('getter' in ctx.property) {
|
|
163
|
-
|
|
163
|
+
if (!ctx.options.context) {
|
|
164
|
+
throw new Error;
|
|
165
|
+
}
|
|
166
|
+
return ctx.property.getter(ctx.target, ctx.options.context);
|
|
164
167
|
}
|
|
165
168
|
return value;
|
|
166
169
|
};
|
|
@@ -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
|
}
|
|
@@ -314,7 +317,10 @@ const recurse = async (target, ctx) => {
|
|
|
314
317
|
]);
|
|
315
318
|
}
|
|
316
319
|
if (property) {
|
|
317
|
-
if (
|
|
320
|
+
if (property.hidden) {
|
|
321
|
+
continue;
|
|
322
|
+
}
|
|
323
|
+
if ('getters' in ctx.options && ctx.options.getters && 'getter' in property) {
|
|
318
324
|
if (property.requires) {
|
|
319
325
|
const missing = property.requires.some((requiredPropName) => !(requiredPropName in target));
|
|
320
326
|
if (missing) {
|
|
@@ -393,7 +399,7 @@ const traverseDocument = async (what, description, _options) => {
|
|
|
393
399
|
if (options.autoCast) {
|
|
394
400
|
functions.push(autoCast);
|
|
395
401
|
}
|
|
396
|
-
if (options.getters) {
|
|
402
|
+
if ('getters' in options && options.getters) {
|
|
397
403
|
functions.push(getters);
|
|
398
404
|
}
|
|
399
405
|
if (options.validate) {
|
|
@@ -407,7 +413,7 @@ const traverseDocument = async (what, description, _options) => {
|
|
|
407
413
|
}
|
|
408
414
|
functions.push(validate);
|
|
409
415
|
}
|
|
410
|
-
if (options.moveFiles) {
|
|
416
|
+
if ('moveFiles' in options && options.moveFiles) {
|
|
411
417
|
functions.push(moveFiles);
|
|
412
418
|
}
|
|
413
419
|
let traverseError;
|
|
@@ -126,7 +126,10 @@ const autoCast = (value, ctx) => {
|
|
|
126
126
|
};
|
|
127
127
|
const getters = (value, ctx) => {
|
|
128
128
|
if ("getter" in ctx.property) {
|
|
129
|
-
|
|
129
|
+
if (!ctx.options.context) {
|
|
130
|
+
throw new Error();
|
|
131
|
+
}
|
|
132
|
+
return ctx.property.getter(ctx.target, ctx.options.context);
|
|
130
133
|
}
|
|
131
134
|
return value;
|
|
132
135
|
};
|
|
@@ -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
|
}
|
|
@@ -276,7 +279,10 @@ const recurse = async (target, ctx) => {
|
|
|
276
279
|
]);
|
|
277
280
|
}
|
|
278
281
|
if (property) {
|
|
279
|
-
if (
|
|
282
|
+
if (property.hidden) {
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if ("getters" in ctx.options && ctx.options.getters && "getter" in property) {
|
|
280
286
|
if (property.requires) {
|
|
281
287
|
const missing = property.requires.some((requiredPropName) => !(requiredPropName in target));
|
|
282
288
|
if (missing) {
|
|
@@ -351,7 +357,7 @@ export const traverseDocument = async (what, description, _options) => {
|
|
|
351
357
|
if (options.autoCast) {
|
|
352
358
|
functions.push(autoCast);
|
|
353
359
|
}
|
|
354
|
-
if (options.getters) {
|
|
360
|
+
if ("getters" in options && options.getters) {
|
|
355
361
|
functions.push(getters);
|
|
356
362
|
}
|
|
357
363
|
if (options.validate) {
|
|
@@ -365,7 +371,7 @@ export const traverseDocument = async (what, description, _options) => {
|
|
|
365
371
|
}
|
|
366
372
|
functions.push(validate);
|
|
367
373
|
}
|
|
368
|
-
if (options.moveFiles) {
|
|
374
|
+
if ("moveFiles" in options && options.moveFiles) {
|
|
369
375
|
functions.push(moveFiles);
|
|
370
376
|
}
|
|
371
377
|
let traverseError;
|
package/dist/functions/get.js
CHANGED
package/dist/functions/get.mjs
CHANGED
package/dist/functions/getAll.js
CHANGED
|
@@ -78,6 +78,7 @@ const internalGetAll = async (payload, context) => {
|
|
|
78
78
|
const documents = [];
|
|
79
79
|
for (const doc of result) {
|
|
80
80
|
documents.push((0, common_1.throwIfError)(await (0, index_js_1.traverseDocument)(doc, context.description, {
|
|
81
|
+
context,
|
|
81
82
|
getters: true,
|
|
82
83
|
fromProperties: true,
|
|
83
84
|
recurseReferences: true,
|
|
@@ -76,6 +76,7 @@ const internalGetAll = async (payload, context) => {
|
|
|
76
76
|
const documents = [];
|
|
77
77
|
for (const doc of result) {
|
|
78
78
|
documents.push(throwIfError(await traverseDocument(doc, context.description, {
|
|
79
|
+
context,
|
|
79
80
|
getters: true,
|
|
80
81
|
fromProperties: true,
|
|
81
82
|
recurseReferences: true,
|
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",
|