@aeriajs/core 0.0.88 → 0.0.90
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/assets.js +3 -7
- package/dist/assets.mjs +5 -9
- package/dist/collection/define.d.ts +1 -1
- package/dist/collection/fill.d.ts +2 -0
- package/dist/collection/fill.js +14 -0
- package/dist/collection/fill.mjs +11 -0
- package/dist/collection/index.d.ts +3 -1
- package/dist/collection/index.js +3 -1
- package/dist/collection/index.mjs +3 -1
- package/dist/collection/normalizeProjection.d.ts +2 -0
- package/dist/collection/normalizeProjection.js +22 -0
- package/dist/collection/normalizeProjection.mjs +17 -0
- package/dist/collection/pagination.js +1 -1
- package/dist/collection/pagination.mjs +1 -1
- package/dist/collection/prepareInsert.d.ts +2 -0
- package/dist/collection/prepareInsert.js +46 -0
- package/dist/collection/prepareInsert.mjs +41 -0
- package/dist/collection/reference.js +3 -3
- package/dist/collection/reference.mjs +4 -4
- package/dist/collection/traverseDocument.d.ts +5 -4
- package/dist/collection/traverseDocument.js +16 -15
- package/dist/collection/traverseDocument.mjs +15 -14
- package/dist/context.d.ts +1 -1
- package/dist/context.js +2 -2
- package/dist/context.mjs +3 -3
- package/dist/functions/builtin/count.js +2 -2
- package/dist/functions/builtin/count.mjs +3 -3
- package/dist/functions/builtin/get.d.ts +2 -2
- package/dist/functions/builtin/get.js +7 -4
- package/dist/functions/builtin/get.mjs +8 -5
- package/dist/functions/builtin/getAll.js +3 -3
- package/dist/functions/builtin/getAll.mjs +4 -4
- package/dist/functions/builtin/insert.d.ts +30 -2
- package/dist/functions/builtin/insert.js +52 -19
- package/dist/functions/builtin/insert.mjs +51 -19
- package/dist/functions/builtin/remove.js +6 -5
- package/dist/functions/builtin/remove.mjs +7 -6
- package/dist/functions/builtin/removeAll.js +1 -1
- package/dist/functions/builtin/removeAll.mjs +2 -2
- package/dist/functions/builtin/upload.d.ts +7 -2
- package/dist/functions/builtin/upload.js +9 -2
- package/dist/functions/builtin/upload.mjs +10 -3
- package/dist/use.d.ts +1 -1
- package/package.json +8 -8
- package/dist/collection/utils.d.ts +0 -4
- package/dist/collection/utils.js +0 -89
- package/dist/collection/utils.mjs +0 -76
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { freshItem } from "@aeriajs/common";
|
|
3
|
-
export const normalizeProjection = (properties, description) => {
|
|
4
|
-
const target = Array.from(properties);
|
|
5
|
-
if (target.length === 0) {
|
|
6
|
-
target.push(...Object.keys(description.properties));
|
|
7
|
-
}
|
|
8
|
-
const projection = target.reduce((a, key) => {
|
|
9
|
-
if (key !== "_id" && description.properties[key].hidden) {
|
|
10
|
-
return a;
|
|
11
|
-
}
|
|
12
|
-
return {
|
|
13
|
-
...a,
|
|
14
|
-
[key]: 1
|
|
15
|
-
};
|
|
16
|
-
}, {});
|
|
17
|
-
return Object.keys(projection).length === 0 ? null : projection;
|
|
18
|
-
};
|
|
19
|
-
export const fill = (item, description) => {
|
|
20
|
-
const itemCopy = Object.assign({}, item);
|
|
21
|
-
for (const key in itemCopy) {
|
|
22
|
-
if (itemCopy[key] === null) {
|
|
23
|
-
delete itemCopy[key];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
return Object.assign(freshItem(description), itemCopy);
|
|
27
|
-
};
|
|
28
|
-
export const prepareInsert = (payload, description) => {
|
|
29
|
-
const rest = Object.assign({}, payload);
|
|
30
|
-
const docId = payload._id;
|
|
31
|
-
delete rest._id;
|
|
32
|
-
delete rest.created_at;
|
|
33
|
-
delete rest.updated_at;
|
|
34
|
-
const forbidden = (key) => {
|
|
35
|
-
return description.properties[key].readOnly || description.writable && !description.writable.includes(key);
|
|
36
|
-
};
|
|
37
|
-
const prepareUpdate = () => Object.entries(rest).reduce((a, [key, value]) => {
|
|
38
|
-
if (key[0] === "$") {
|
|
39
|
-
if (!description.writable && docId) {
|
|
40
|
-
a[key] = value;
|
|
41
|
-
}
|
|
42
|
-
return a;
|
|
43
|
-
}
|
|
44
|
-
if (forbidden(key)) {
|
|
45
|
-
return a;
|
|
46
|
-
}
|
|
47
|
-
if (value === null || value === void 0) {
|
|
48
|
-
a.$unset[key] = 1;
|
|
49
|
-
return a;
|
|
50
|
-
}
|
|
51
|
-
a.$set[key] = value;
|
|
52
|
-
return a;
|
|
53
|
-
}, {
|
|
54
|
-
$set: description.defaults || {},
|
|
55
|
-
$unset: {}
|
|
56
|
-
});
|
|
57
|
-
const prepareCreate = () => Object.entries(rest).reduce((a, [key, value]) => {
|
|
58
|
-
if (forbidden(key) || [
|
|
59
|
-
void 0,
|
|
60
|
-
null
|
|
61
|
-
].includes(value)) {
|
|
62
|
-
return a;
|
|
63
|
-
}
|
|
64
|
-
return {
|
|
65
|
-
...a,
|
|
66
|
-
[key]: value
|
|
67
|
-
};
|
|
68
|
-
}, description.defaults || {});
|
|
69
|
-
const what = docId ? prepareUpdate() : prepareCreate();
|
|
70
|
-
Object.keys(what).forEach((k) => {
|
|
71
|
-
if (typeof what[k] === "object" && JSON.stringify(what) === "{}") {
|
|
72
|
-
delete what[k];
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
return what;
|
|
76
|
-
};
|