@aeriajs/core 0.0.162 → 0.0.164
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/__scripts__/postinstall.js +1 -1
- package/dist/__scripts__/postinstall.mjs +1 -1
- package/dist/assets.d.ts +2 -2
- package/dist/collection/cascadingRemove.js +4 -6
- package/dist/collection/cascadingRemove.mjs +4 -6
- package/dist/collection/makePagination.js +1 -4
- package/dist/collection/makePagination.mjs +4 -2
- package/dist/collection/prepareInsert.js +2 -2
- package/dist/collection/prepareInsert.mjs +2 -2
- package/dist/collection/traverseDocument.d.ts +1 -1
- package/dist/collection/traverseDocument.js +1 -1
- package/dist/collection/traverseDocument.mjs +1 -1
- package/dist/functions/count.d.ts +2 -5
- package/dist/functions/count.js +1 -1
- package/dist/functions/count.mjs +2 -2
- package/dist/functions/get.js +1 -1
- package/dist/functions/get.mjs +2 -2
- package/dist/functions/getAll.d.ts +2 -9
- package/dist/functions/getAll.js +2 -2
- package/dist/functions/getAll.mjs +3 -3
- package/dist/functions/insert.js +4 -3
- package/dist/functions/insert.mjs +5 -4
- package/package.json +8 -8
|
@@ -32,7 +32,7 @@ import type {} from '@aeriajs/types'
|
|
|
32
32
|
declare global {
|
|
33
33
|
type UnpackCollections<TCollections> = {
|
|
34
34
|
[P in keyof TCollections]: TCollections[P] extends infer Candidate
|
|
35
|
-
? Candidate extends (...args:
|
|
35
|
+
? Candidate extends (...args: unknown[]) => infer Coll
|
|
36
36
|
? Coll
|
|
37
37
|
: Candidate
|
|
38
38
|
: never
|
|
@@ -8,7 +8,7 @@ import type {} from '@aeriajs/types'
|
|
|
8
8
|
declare global {
|
|
9
9
|
type UnpackCollections<TCollections> = {
|
|
10
10
|
[P in keyof TCollections]: TCollections[P] extends infer Candidate
|
|
11
|
-
? Candidate extends (...args:
|
|
11
|
+
? Candidate extends (...args: unknown[]) => infer Coll
|
|
12
12
|
? Coll
|
|
13
13
|
: Candidate
|
|
14
14
|
: never
|
package/dist/assets.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare const getCollectionAsset: <TCollectionName extends string, TAsset
|
|
|
18
18
|
readonly error: undefined;
|
|
19
19
|
readonly result: NonNullable<Collection[TAssetName]>;
|
|
20
20
|
}>;
|
|
21
|
-
export declare const getFunction: <
|
|
21
|
+
export declare const getFunction: <TFunction extends (payload: any, context: Context) => unknown>(collectionName: string, functionName: string, token?: Token, options?: {
|
|
22
22
|
exposedOnly: boolean;
|
|
23
23
|
}) => Promise<{
|
|
24
24
|
readonly _tag: "Error";
|
|
@@ -39,5 +39,5 @@ export declare const getFunction: <TCollectionName extends string, TFunctionName
|
|
|
39
39
|
} | {
|
|
40
40
|
readonly _tag: "Result";
|
|
41
41
|
readonly error: undefined;
|
|
42
|
-
readonly result:
|
|
42
|
+
readonly result: TFunction;
|
|
43
43
|
}>;
|
|
@@ -15,9 +15,8 @@ const preferredRemove = async (targetId, reference, parentContext) => {
|
|
|
15
15
|
collectionName: reference.referencedCollection,
|
|
16
16
|
});
|
|
17
17
|
if (Array.isArray(targetId)) {
|
|
18
|
-
const { result } = await (0, assets_js_1.getFunction)(reference.referencedCollection, 'removeAll');
|
|
19
|
-
if (
|
|
20
|
-
const removeAll = result;
|
|
18
|
+
const { result: removeAll } = await (0, assets_js_1.getFunction)(reference.referencedCollection, 'removeAll');
|
|
19
|
+
if (removeAll) {
|
|
21
20
|
return removeAll({
|
|
22
21
|
filters: targetId,
|
|
23
22
|
}, context);
|
|
@@ -28,9 +27,8 @@ const preferredRemove = async (targetId, reference, parentContext) => {
|
|
|
28
27
|
},
|
|
29
28
|
});
|
|
30
29
|
}
|
|
31
|
-
const { result } = await (0, assets_js_1.getFunction)(reference.referencedCollection, 'remove');
|
|
32
|
-
if (
|
|
33
|
-
const remove = result;
|
|
30
|
+
const { result: remove } = await (0, assets_js_1.getFunction)(reference.referencedCollection, 'remove');
|
|
31
|
+
if (remove) {
|
|
34
32
|
return remove({
|
|
35
33
|
filters: {
|
|
36
34
|
_id: targetId,
|
|
@@ -13,9 +13,8 @@ const preferredRemove = async (targetId, reference, parentContext) => {
|
|
|
13
13
|
collectionName: reference.referencedCollection
|
|
14
14
|
});
|
|
15
15
|
if (Array.isArray(targetId)) {
|
|
16
|
-
const { result:
|
|
17
|
-
if (
|
|
18
|
-
const removeAll = result2;
|
|
16
|
+
const { result: removeAll } = await getFunction(reference.referencedCollection, "removeAll");
|
|
17
|
+
if (removeAll) {
|
|
19
18
|
return removeAll({
|
|
20
19
|
filters: targetId
|
|
21
20
|
}, context);
|
|
@@ -26,9 +25,8 @@ const preferredRemove = async (targetId, reference, parentContext) => {
|
|
|
26
25
|
}
|
|
27
26
|
});
|
|
28
27
|
}
|
|
29
|
-
const { result } = await getFunction(reference.referencedCollection, "remove");
|
|
30
|
-
if (
|
|
31
|
-
const remove = result;
|
|
28
|
+
const { result: remove } = await getFunction(reference.referencedCollection, "remove");
|
|
29
|
+
if (remove) {
|
|
32
30
|
return remove({
|
|
33
31
|
filters: {
|
|
34
32
|
_id: targetId
|
|
@@ -3,10 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.makePagination = void 0;
|
|
4
4
|
const common_1 = require("@aeriajs/common");
|
|
5
5
|
const makePagination = async (payload, documents, context) => {
|
|
6
|
-
const limit = payload
|
|
7
|
-
? payload.limit
|
|
8
|
-
: context.config.paginationLimit;
|
|
9
|
-
const offset = payload.offset || 0;
|
|
6
|
+
const { offset = 0, limit = context.config.defaultPaginationLimit, } = payload;
|
|
10
7
|
const recordsTotal = typeof context.collection.functions.count === 'function'
|
|
11
8
|
? (0, common_1.throwIfError)(await context.collection.functions.count({
|
|
12
9
|
filters: payload.filters,
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { throwIfError } from "@aeriajs/common";
|
|
3
3
|
export const makePagination = async (payload, documents, context) => {
|
|
4
|
-
const
|
|
5
|
-
|
|
4
|
+
const {
|
|
5
|
+
offset = 0,
|
|
6
|
+
limit = context.config.defaultPaginationLimit
|
|
7
|
+
} = payload;
|
|
6
8
|
const recordsTotal = typeof context.collection.functions.count === "function" ? throwIfError(await context.collection.functions.count({
|
|
7
9
|
filters: payload.filters
|
|
8
10
|
})) : await context.collection.model.countDocuments(payload.filters);
|
|
@@ -5,7 +5,7 @@ const prepareCreate = (doc, description) => {
|
|
|
5
5
|
const result = Object.assign({}, description.defaults || {});
|
|
6
6
|
for (const propName in doc) {
|
|
7
7
|
const value = doc[propName];
|
|
8
|
-
if (value ===
|
|
8
|
+
if (value === undefined) {
|
|
9
9
|
continue;
|
|
10
10
|
}
|
|
11
11
|
result[propName] = value;
|
|
@@ -19,7 +19,7 @@ const prepareUpdate = (doc) => {
|
|
|
19
19
|
};
|
|
20
20
|
for (const propName in doc) {
|
|
21
21
|
const value = doc[propName];
|
|
22
|
-
if (value ===
|
|
22
|
+
if (value === undefined) {
|
|
23
23
|
result.$unset[propName] = value;
|
|
24
24
|
continue;
|
|
25
25
|
}
|
|
@@ -3,7 +3,7 @@ const prepareCreate = (doc, description) => {
|
|
|
3
3
|
const result = Object.assign({}, description.defaults || {});
|
|
4
4
|
for (const propName in doc) {
|
|
5
5
|
const value = doc[propName];
|
|
6
|
-
if (value ===
|
|
6
|
+
if (value === void 0) {
|
|
7
7
|
continue;
|
|
8
8
|
}
|
|
9
9
|
result[propName] = value;
|
|
@@ -17,7 +17,7 @@ const prepareUpdate = (doc) => {
|
|
|
17
17
|
};
|
|
18
18
|
for (const propName in doc) {
|
|
19
19
|
const value = doc[propName];
|
|
20
|
-
if (value ===
|
|
20
|
+
if (value === void 0) {
|
|
21
21
|
result.$unset[propName] = value;
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
@@ -39,7 +39,7 @@ type PhaseContext = {
|
|
|
39
39
|
export declare const traverseDocument: <const TWhat extends Record<string, unknown> | null>(what: TWhat, description: Description, _options: TraverseOptions) => Promise<{
|
|
40
40
|
readonly _tag: "Result";
|
|
41
41
|
readonly error: undefined;
|
|
42
|
-
readonly result:
|
|
42
|
+
readonly result: TWhat;
|
|
43
43
|
} | {
|
|
44
44
|
readonly _tag: "Error";
|
|
45
45
|
readonly error: ACError.InsecureOperator | ValidationError | TraverseError;
|
|
@@ -391,7 +391,7 @@ const traverseDocument = async (what, description, _options) => {
|
|
|
391
391
|
return types_1.Result.result(what);
|
|
392
392
|
}
|
|
393
393
|
if (!options.validate && Object.keys(what).length === 0) {
|
|
394
|
-
return types_1.Result.result(
|
|
394
|
+
return types_1.Result.result(what);
|
|
395
395
|
}
|
|
396
396
|
if (options.recurseDeep) {
|
|
397
397
|
functions.push(recurseDeep);
|
|
@@ -349,7 +349,7 @@ export const traverseDocument = async (what, description, _options) => {
|
|
|
349
349
|
return Result.result(what);
|
|
350
350
|
}
|
|
351
351
|
if (!options.validate && Object.keys(what).length === 0) {
|
|
352
|
-
return Result.result(
|
|
352
|
+
return Result.result(what);
|
|
353
353
|
}
|
|
354
354
|
if (options.recurseDeep) {
|
|
355
355
|
functions.push(recurseDeep);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, CountPayload } from '@aeriajs/types';
|
|
2
|
+
import { Result } from '@aeriajs/types';
|
|
2
3
|
export type CountOptions = {
|
|
3
4
|
bypassSecurity?: boolean;
|
|
4
5
|
};
|
|
@@ -6,8 +7,4 @@ export declare const count: <TContext extends Context>(payload: CountPayload<Sch
|
|
|
6
7
|
readonly _tag: "Result";
|
|
7
8
|
readonly error: undefined;
|
|
8
9
|
readonly result: any;
|
|
9
|
-
} |
|
|
10
|
-
readonly _tag: "Error";
|
|
11
|
-
readonly error: import("@aeriajs/types").ACError.InvalidLimit | import("@aeriajs/types").ACError.OwnershipError;
|
|
12
|
-
readonly result: undefined;
|
|
13
|
-
}>;
|
|
10
|
+
} | Result.Error<any>>;
|
package/dist/functions/count.js
CHANGED
|
@@ -46,6 +46,6 @@ const count = async (payload, context, options = {}) => {
|
|
|
46
46
|
if (error) {
|
|
47
47
|
return types_1.Result.error(error);
|
|
48
48
|
}
|
|
49
|
-
return
|
|
49
|
+
return (0, security_1.applyReadMiddlewares)(securedPayload, context, internalCount);
|
|
50
50
|
};
|
|
51
51
|
exports.count = count;
|
package/dist/functions/count.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { useSecurity } from "@aeriajs/security";
|
|
2
|
+
import { useSecurity, applyReadMiddlewares } from "@aeriajs/security";
|
|
3
3
|
import { Result } from "@aeriajs/types";
|
|
4
4
|
import { throwIfError } from "@aeriajs/common";
|
|
5
5
|
import { traverseDocument } from "../collection/index.mjs";
|
|
@@ -40,5 +40,5 @@ export const count = async (payload, context, options = {}) => {
|
|
|
40
40
|
if (error) {
|
|
41
41
|
return Result.error(error);
|
|
42
42
|
}
|
|
43
|
-
return
|
|
43
|
+
return applyReadMiddlewares(securedPayload, context, internalCount);
|
|
44
44
|
};
|
package/dist/functions/get.js
CHANGED
package/dist/functions/get.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { useSecurity } from "@aeriajs/security";
|
|
2
|
+
import { useSecurity, applyReadMiddlewares } from "@aeriajs/security";
|
|
3
3
|
import { Result, HTTPStatus, ACError } from "@aeriajs/types";
|
|
4
4
|
import { throwIfError } from "@aeriajs/common";
|
|
5
5
|
import {
|
|
@@ -70,5 +70,5 @@ export const get = async (payload, context, options = {}) => {
|
|
|
70
70
|
code: error
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
return
|
|
73
|
+
return applyReadMiddlewares(securedPayload, context, internalGet);
|
|
74
74
|
};
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, GetAllPayload } from '@aeriajs/types';
|
|
2
|
+
import { Result } from '@aeriajs/types';
|
|
2
3
|
export type GetAllOptions = {
|
|
3
4
|
bypassSecurity?: boolean;
|
|
4
5
|
};
|
|
5
|
-
export declare const getAll: <TContext extends Context>(payload: GetAllPayload<SchemaWithId<TContext["description"]>> | undefined, context: TContext, options?: GetAllOptions) => Promise<
|
|
6
|
-
readonly _tag: "Error";
|
|
7
|
-
readonly error: import("@aeriajs/types").ACError.InvalidLimit | import("@aeriajs/types").ACError.OwnershipError;
|
|
8
|
-
readonly result: undefined;
|
|
9
|
-
} | {
|
|
10
|
-
readonly _tag: "Result";
|
|
11
|
-
readonly error: undefined;
|
|
12
|
-
readonly result: SchemaWithId<TContext["description"]>[];
|
|
13
|
-
}>;
|
|
6
|
+
export declare const getAll: <TContext extends Context>(payload: GetAllPayload<SchemaWithId<TContext["description"]>> | undefined, context: TContext, options?: GetAllOptions) => Promise<Result.Either<any, any>>;
|
package/dist/functions/getAll.js
CHANGED
|
@@ -6,7 +6,7 @@ const types_1 = require("@aeriajs/types");
|
|
|
6
6
|
const common_1 = require("@aeriajs/common");
|
|
7
7
|
const index_js_1 = require("../collection/index.js");
|
|
8
8
|
const internalGetAll = async (payload, context) => {
|
|
9
|
-
const { limit = context.config.
|
|
9
|
+
const { limit = context.config.defaultPaginationLimit, sort, project, offset = 0, } = payload;
|
|
10
10
|
const filters = payload.filters
|
|
11
11
|
? Object.assign({}, payload.filters)
|
|
12
12
|
: {};
|
|
@@ -99,6 +99,6 @@ const getAll = async (payload, context, options = {}) => {
|
|
|
99
99
|
if (error) {
|
|
100
100
|
return types_1.Result.error(error);
|
|
101
101
|
}
|
|
102
|
-
return
|
|
102
|
+
return (0, security_1.applyReadMiddlewares)(securedPayload, context, internalGetAll);
|
|
103
103
|
};
|
|
104
104
|
exports.getAll = getAll;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
import { useSecurity } from "@aeriajs/security";
|
|
2
|
+
import { useSecurity, applyReadMiddlewares } from "@aeriajs/security";
|
|
3
3
|
import { Result } from "@aeriajs/types";
|
|
4
4
|
import { throwIfError } from "@aeriajs/common";
|
|
5
5
|
import {
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from "../collection/index.mjs";
|
|
11
11
|
const internalGetAll = async (payload, context) => {
|
|
12
12
|
const {
|
|
13
|
-
limit = context.config.
|
|
13
|
+
limit = context.config.defaultPaginationLimit,
|
|
14
14
|
sort,
|
|
15
15
|
project,
|
|
16
16
|
offset = 0
|
|
@@ -97,5 +97,5 @@ export const getAll = async (payload, context, options = {}) => {
|
|
|
97
97
|
if (error) {
|
|
98
98
|
return Result.error(error);
|
|
99
99
|
}
|
|
100
|
-
return
|
|
100
|
+
return applyReadMiddlewares(securedPayload, context, internalGetAll);
|
|
101
101
|
};
|
package/dist/functions/insert.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.insert = exports.insertErrorSchema = void 0;
|
|
4
|
+
const mongodb_1 = require("mongodb");
|
|
4
5
|
const types_1 = require("@aeriajs/types");
|
|
5
6
|
const security_1 = require("@aeriajs/security");
|
|
6
7
|
const common_1 = require("@aeriajs/common");
|
|
@@ -48,7 +49,7 @@ const internalInsert = async (payload, context) => {
|
|
|
48
49
|
details: error.errors,
|
|
49
50
|
});
|
|
50
51
|
}
|
|
51
|
-
const docId = '_id' in what
|
|
52
|
+
const docId = '_id' in what && what._id instanceof mongodb_1.ObjectId
|
|
52
53
|
? what._id
|
|
53
54
|
: null;
|
|
54
55
|
const content = (0, index_js_1.prepareInsert)(what, context.description);
|
|
@@ -68,7 +69,7 @@ const internalInsert = async (payload, context) => {
|
|
|
68
69
|
content.$set ??= {};
|
|
69
70
|
content.$set.updated_at = new Date();
|
|
70
71
|
await context.collection.model.updateOne({
|
|
71
|
-
_id:
|
|
72
|
+
_id: newId,
|
|
72
73
|
}, content);
|
|
73
74
|
}
|
|
74
75
|
if (context.collection.originalFunctions?.get) {
|
|
@@ -111,6 +112,6 @@ const insert = async (payload, context, options = {}) => {
|
|
|
111
112
|
code: error,
|
|
112
113
|
});
|
|
113
114
|
}
|
|
114
|
-
return
|
|
115
|
+
return (0, security_1.applyWriteMiddlewares)(securedPayload, context, internalInsert);
|
|
115
116
|
};
|
|
116
117
|
exports.insert = insert;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
import { ObjectId } from "mongodb";
|
|
2
3
|
import { Result, HTTPStatus, ACError, ValidationErrorCode, TraverseError } from "@aeriajs/types";
|
|
3
|
-
import { useSecurity } from "@aeriajs/security";
|
|
4
|
+
import { useSecurity, applyWriteMiddlewares } from "@aeriajs/security";
|
|
4
5
|
import { throwIfError, endpointErrorSchema } from "@aeriajs/common";
|
|
5
6
|
import { traverseDocument, normalizeProjection, prepareInsert } from "../collection/index.mjs";
|
|
6
7
|
export const insertErrorSchema = () => endpointErrorSchema({
|
|
@@ -43,7 +44,7 @@ const internalInsert = async (payload, context) => {
|
|
|
43
44
|
details: error.errors
|
|
44
45
|
});
|
|
45
46
|
}
|
|
46
|
-
const docId = "_id" in what ? what._id : null;
|
|
47
|
+
const docId = "_id" in what && what._id instanceof ObjectId ? what._id : null;
|
|
47
48
|
const content = prepareInsert(what, context.description);
|
|
48
49
|
const projection = payload.project ? normalizeProjection(payload.project, context.description) : {};
|
|
49
50
|
let newId = docId;
|
|
@@ -58,7 +59,7 @@ const internalInsert = async (payload, context) => {
|
|
|
58
59
|
content.$set ??= {};
|
|
59
60
|
content.$set.updated_at = /* @__PURE__ */ new Date();
|
|
60
61
|
await context.collection.model.updateOne({
|
|
61
|
-
_id:
|
|
62
|
+
_id: newId
|
|
62
63
|
}, content);
|
|
63
64
|
}
|
|
64
65
|
if (context.collection.originalFunctions?.get) {
|
|
@@ -101,5 +102,5 @@ export const insert = async (payload, context, options = {}) => {
|
|
|
101
102
|
code: error
|
|
102
103
|
});
|
|
103
104
|
}
|
|
104
|
-
return
|
|
105
|
+
return applyWriteMiddlewares(securedPayload, context, internalInsert);
|
|
105
106
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.164",
|
|
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.164",
|
|
46
|
+
"@aeriajs/common": "^0.0.100",
|
|
47
|
+
"@aeriajs/entrypoint": "^0.0.102",
|
|
48
|
+
"@aeriajs/http": "^0.0.113",
|
|
49
|
+
"@aeriajs/security": "^0.0.164",
|
|
50
|
+
"@aeriajs/types": "^0.0.86",
|
|
51
|
+
"@aeriajs/validation": "^0.0.103"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"mongodb": "^6.5.0",
|