@aeriajs/core 0.0.166 → 0.0.168
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/index.d.ts +1 -0
- package/dist/collection/index.js +1 -0
- package/dist/collection/index.mjs +1 -0
- package/dist/collection/isValidCollection.d.ts +3 -0
- package/dist/collection/isValidCollection.js +20 -0
- package/dist/collection/isValidCollection.mjs +7 -0
- package/dist/collection/reference.js +1 -2
- package/dist/collection/reference.mjs +1 -2
- package/dist/collection/traverseDocument.d.ts +1 -1
- package/dist/collection/traverseDocument.js +19 -15
- package/dist/collection/traverseDocument.mjs +19 -15
- package/dist/context.js +3 -2
- package/dist/context.mjs +3 -2
- package/dist/database.d.ts +0 -1
- package/dist/database.js +2 -16
- package/dist/database.mjs +1 -12
- package/package.json +7 -7
package/dist/collection/index.js
CHANGED
|
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./cascadingRemove.js"), exports);
|
|
18
18
|
__exportStar(require("./define.js"), exports);
|
|
19
19
|
__exportStar(require("./description.js"), exports);
|
|
20
|
+
__exportStar(require("./isValidCollection.js"), exports);
|
|
20
21
|
__exportStar(require("./makePagination.js"), exports);
|
|
21
22
|
__exportStar(require("./normalizeProjection.js"), exports);
|
|
22
23
|
__exportStar(require("./preload.js"), exports);
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export * from "./cascadingRemove.mjs";
|
|
3
3
|
export * from "./define.mjs";
|
|
4
4
|
export * from "./description.mjs";
|
|
5
|
+
export * from "./isValidCollection.mjs";
|
|
5
6
|
export * from "./makePagination.mjs";
|
|
6
7
|
export * from "./normalizeProjection.mjs";
|
|
7
8
|
export * from "./preload.mjs";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidCollection = exports.isValidDescription = void 0;
|
|
4
|
+
const isValidDescription = (value) => {
|
|
5
|
+
return !!(value
|
|
6
|
+
&& typeof value === 'object'
|
|
7
|
+
&& '$id' in value
|
|
8
|
+
&& 'properties' in value
|
|
9
|
+
&& value.properties
|
|
10
|
+
&& typeof value.$id === 'string'
|
|
11
|
+
&& typeof value.properties === 'object');
|
|
12
|
+
};
|
|
13
|
+
exports.isValidDescription = isValidDescription;
|
|
14
|
+
const isValidCollection = (value) => {
|
|
15
|
+
return !!(value
|
|
16
|
+
&& typeof value === 'object'
|
|
17
|
+
&& 'description' in value
|
|
18
|
+
&& (0, exports.isValidDescription)(value.description));
|
|
19
|
+
};
|
|
20
|
+
exports.isValidCollection = isValidCollection;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
export const isValidDescription = (value) => {
|
|
3
|
+
return !!(value && typeof value === "object" && "$id" in value && "properties" in value && value.properties && typeof value.$id === "string" && typeof value.properties === "object");
|
|
4
|
+
};
|
|
5
|
+
export const isValidCollection = (value) => {
|
|
6
|
+
return !!(value && typeof value === "object" && "description" in value && isValidDescription(value.description));
|
|
7
|
+
};
|
|
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getLookupPipeline = exports.buildLookupPipeline = exports.recurseSetStage = exports.getReferences = void 0;
|
|
4
4
|
const common_1 = require("@aeriajs/common");
|
|
5
5
|
const assets_js_1 = require("../assets.js");
|
|
6
|
-
const database_js_1 = require("../database.js");
|
|
7
6
|
const getTempName = (path) => {
|
|
8
7
|
return `_${path.join('_')}`;
|
|
9
8
|
};
|
|
@@ -288,7 +287,7 @@ const buildLookupPipeline = (refMap, options = {}) => {
|
|
|
288
287
|
: path.concat(refName).join('.');
|
|
289
288
|
rootPipeline.unshift({
|
|
290
289
|
$lookup: {
|
|
291
|
-
from:
|
|
290
|
+
from: reference.referencedCollection,
|
|
292
291
|
foreignField: '_id',
|
|
293
292
|
localField,
|
|
294
293
|
as: tempName,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { throwIfError, getReferenceProperty } from "@aeriajs/common";
|
|
3
3
|
import { getCollectionAsset } from "../assets.mjs";
|
|
4
|
-
import { prepareCollectionName } from "../database.mjs";
|
|
5
4
|
const getTempName = (path) => {
|
|
6
5
|
return `_${path.join("_")}`;
|
|
7
6
|
};
|
|
@@ -276,7 +275,7 @@ export const buildLookupPipeline = (refMap, options = {}) => {
|
|
|
276
275
|
const localField = reference.isRecursive ? `${getTempName(path)}.${refName}` : path.concat(refName).join(".");
|
|
277
276
|
rootPipeline.unshift({
|
|
278
277
|
$lookup: {
|
|
279
|
-
from:
|
|
278
|
+
from: reference.referencedCollection,
|
|
280
279
|
foreignField: "_id",
|
|
281
280
|
localField,
|
|
282
281
|
as: tempName,
|
|
@@ -25,7 +25,7 @@ export type TraverseNormalized = {
|
|
|
25
25
|
description: Description;
|
|
26
26
|
pipe: <T = unknown>(value: unknown, phaseContext: PhaseContext) => T | Promise<T>;
|
|
27
27
|
};
|
|
28
|
-
export type ValidTempFile = undefined | ObjectId | {
|
|
28
|
+
export type ValidTempFile = null | undefined | ObjectId | {
|
|
29
29
|
tempId: string;
|
|
30
30
|
};
|
|
31
31
|
type PhaseContext = {
|
|
@@ -183,10 +183,13 @@ const validate = (value, ctx) => {
|
|
|
183
183
|
};
|
|
184
184
|
const isValidTempFile = (value) => {
|
|
185
185
|
if (value && typeof value === 'object') {
|
|
186
|
-
|
|
186
|
+
if (value instanceof mongodb_1.ObjectId) {
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
return 'tempId' in value && (typeof value.tempId === 'string' || value.tempId instanceof mongodb_1.ObjectId);
|
|
187
190
|
}
|
|
188
191
|
return !!(value === undefined
|
|
189
|
-
|| value
|
|
192
|
+
|| value === null);
|
|
190
193
|
};
|
|
191
194
|
const moveFiles = async (value, ctx) => {
|
|
192
195
|
if (!('$ref' in ctx.property) || ctx.property.$ref !== 'file') {
|
|
@@ -195,18 +198,18 @@ const moveFiles = async (value, ctx) => {
|
|
|
195
198
|
if (!isValidTempFile(value)) {
|
|
196
199
|
return types_1.Result.error(types_1.TraverseError.InvalidTempfile);
|
|
197
200
|
}
|
|
198
|
-
if (value instanceof mongodb_1.ObjectId) {
|
|
199
|
-
return value;
|
|
200
|
-
}
|
|
201
|
-
if (!ctx.options.context) {
|
|
202
|
-
throw new Error();
|
|
203
|
-
}
|
|
204
201
|
if (!value) {
|
|
205
202
|
if (ctx.root._id && !ctx.isArray) {
|
|
206
203
|
await disposeOldFiles(ctx);
|
|
207
204
|
}
|
|
208
205
|
return null;
|
|
209
206
|
}
|
|
207
|
+
if (value instanceof mongodb_1.ObjectId) {
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
if (!ctx.options.context) {
|
|
211
|
+
throw new Error();
|
|
212
|
+
}
|
|
210
213
|
const tempFile = await ctx.options.context.collections.tempFile.model.findOne({
|
|
211
214
|
_id: new mongodb_1.ObjectId(value.tempId),
|
|
212
215
|
});
|
|
@@ -398,13 +401,14 @@ const recurse = async (target, ctx) => {
|
|
|
398
401
|
return types_1.Result.result(Object.fromEntries(entries));
|
|
399
402
|
};
|
|
400
403
|
const traverseDocument = async (what, description, _options) => {
|
|
401
|
-
const options = Object.assign({}, _options);
|
|
402
|
-
const functions = [];
|
|
403
404
|
if (!what) {
|
|
404
405
|
return types_1.Result.result(what);
|
|
405
406
|
}
|
|
406
|
-
|
|
407
|
-
|
|
407
|
+
const whatCopy = Object.assign({}, what);
|
|
408
|
+
const options = Object.assign({}, _options);
|
|
409
|
+
const functions = [];
|
|
410
|
+
if (!options.validate && Object.keys(whatCopy).length === 0) {
|
|
411
|
+
return types_1.Result.result(whatCopy);
|
|
408
412
|
}
|
|
409
413
|
if (options.recurseDeep) {
|
|
410
414
|
functions.push(recurseDeep);
|
|
@@ -420,7 +424,7 @@ const traverseDocument = async (what, description, _options) => {
|
|
|
420
424
|
if (options.validateRequired) {
|
|
421
425
|
descriptionCopy.required = options.validateRequired;
|
|
422
426
|
}
|
|
423
|
-
const wholenessError = (0, validation_1.validateWholeness)(
|
|
427
|
+
const wholenessError = (0, validation_1.validateWholeness)(whatCopy, descriptionCopy);
|
|
424
428
|
if (wholenessError) {
|
|
425
429
|
return types_1.Result.error(wholenessError);
|
|
426
430
|
}
|
|
@@ -457,8 +461,8 @@ const traverseDocument = async (what, description, _options) => {
|
|
|
457
461
|
},
|
|
458
462
|
}),
|
|
459
463
|
});
|
|
460
|
-
const { error, result } = await recurse(
|
|
461
|
-
root:
|
|
464
|
+
const { error, result } = await recurse(whatCopy, {
|
|
465
|
+
root: whatCopy,
|
|
462
466
|
property: description,
|
|
463
467
|
propPath: '',
|
|
464
468
|
options,
|
|
@@ -149,9 +149,12 @@ const validate = (value, ctx) => {
|
|
|
149
149
|
};
|
|
150
150
|
const isValidTempFile = (value) => {
|
|
151
151
|
if (value && typeof value === "object") {
|
|
152
|
-
|
|
152
|
+
if (value instanceof ObjectId) {
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
return "tempId" in value && (typeof value.tempId === "string" || value.tempId instanceof ObjectId);
|
|
153
156
|
}
|
|
154
|
-
return !!(value === void 0 || value
|
|
157
|
+
return !!(value === void 0 || value === null);
|
|
155
158
|
};
|
|
156
159
|
const moveFiles = async (value, ctx) => {
|
|
157
160
|
if (!("$ref" in ctx.property) || ctx.property.$ref !== "file") {
|
|
@@ -160,18 +163,18 @@ const moveFiles = async (value, ctx) => {
|
|
|
160
163
|
if (!isValidTempFile(value)) {
|
|
161
164
|
return Result.error(TraverseError.InvalidTempfile);
|
|
162
165
|
}
|
|
163
|
-
if (value instanceof ObjectId) {
|
|
164
|
-
return value;
|
|
165
|
-
}
|
|
166
|
-
if (!ctx.options.context) {
|
|
167
|
-
throw new Error();
|
|
168
|
-
}
|
|
169
166
|
if (!value) {
|
|
170
167
|
if (ctx.root._id && !ctx.isArray) {
|
|
171
168
|
await disposeOldFiles(ctx);
|
|
172
169
|
}
|
|
173
170
|
return null;
|
|
174
171
|
}
|
|
172
|
+
if (value instanceof ObjectId) {
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
if (!ctx.options.context) {
|
|
176
|
+
throw new Error();
|
|
177
|
+
}
|
|
175
178
|
const tempFile = await ctx.options.context.collections.tempFile.model.findOne({
|
|
176
179
|
_id: new ObjectId(value.tempId)
|
|
177
180
|
});
|
|
@@ -355,13 +358,14 @@ const recurse = async (target, ctx) => {
|
|
|
355
358
|
return Result.result(Object.fromEntries(entries));
|
|
356
359
|
};
|
|
357
360
|
export const traverseDocument = async (what, description, _options) => {
|
|
358
|
-
const options = Object.assign({}, _options);
|
|
359
|
-
const functions = [];
|
|
360
361
|
if (!what) {
|
|
361
362
|
return Result.result(what);
|
|
362
363
|
}
|
|
363
|
-
|
|
364
|
-
|
|
364
|
+
const whatCopy = Object.assign({}, what);
|
|
365
|
+
const options = Object.assign({}, _options);
|
|
366
|
+
const functions = [];
|
|
367
|
+
if (!options.validate && Object.keys(whatCopy).length === 0) {
|
|
368
|
+
return Result.result(whatCopy);
|
|
365
369
|
}
|
|
366
370
|
if (options.recurseDeep) {
|
|
367
371
|
functions.push(recurseDeep);
|
|
@@ -377,7 +381,7 @@ export const traverseDocument = async (what, description, _options) => {
|
|
|
377
381
|
if (options.validateRequired) {
|
|
378
382
|
descriptionCopy.required = options.validateRequired;
|
|
379
383
|
}
|
|
380
|
-
const wholenessError = validateWholeness(
|
|
384
|
+
const wholenessError = validateWholeness(whatCopy, descriptionCopy);
|
|
381
385
|
if (wholenessError) {
|
|
382
386
|
return Result.error(wholenessError);
|
|
383
387
|
}
|
|
@@ -414,8 +418,8 @@ export const traverseDocument = async (what, description, _options) => {
|
|
|
414
418
|
}
|
|
415
419
|
})
|
|
416
420
|
});
|
|
417
|
-
const { error, result } = await recurse(
|
|
418
|
-
root:
|
|
421
|
+
const { error, result } = await recurse(whatCopy, {
|
|
422
|
+
root: whatCopy,
|
|
419
423
|
property: description,
|
|
420
424
|
propPath: "",
|
|
421
425
|
options
|
package/dist/context.js
CHANGED
|
@@ -39,7 +39,8 @@ const indepthCollection = (collectionName, collections, parentContext) => {
|
|
|
39
39
|
if (typeof functionName !== 'string') {
|
|
40
40
|
throw new Error();
|
|
41
41
|
}
|
|
42
|
-
|
|
42
|
+
const fn = collection.functions?.[functionName];
|
|
43
|
+
if (!fn) {
|
|
43
44
|
return null;
|
|
44
45
|
}
|
|
45
46
|
return async (props, ...args) => {
|
|
@@ -48,7 +49,7 @@ const indepthCollection = (collectionName, collections, parentContext) => {
|
|
|
48
49
|
collectionName,
|
|
49
50
|
inherited: true,
|
|
50
51
|
});
|
|
51
|
-
return
|
|
52
|
+
return fn(props, childContext, ...args);
|
|
52
53
|
};
|
|
53
54
|
},
|
|
54
55
|
});
|
package/dist/context.mjs
CHANGED
|
@@ -12,7 +12,8 @@ const indepthCollection = (collectionName, collections, parentContext) => {
|
|
|
12
12
|
if (typeof functionName !== "string") {
|
|
13
13
|
throw new Error();
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
const fn = collection.functions?.[functionName];
|
|
16
|
+
if (!fn) {
|
|
16
17
|
return null;
|
|
17
18
|
}
|
|
18
19
|
return async (props, ...args) => {
|
|
@@ -21,7 +22,7 @@ const indepthCollection = (collectionName, collections, parentContext) => {
|
|
|
21
22
|
collectionName,
|
|
22
23
|
inherited: true
|
|
23
24
|
});
|
|
24
|
-
return
|
|
25
|
+
return fn(props, childContext, ...args);
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
28
|
});
|
package/dist/database.d.ts
CHANGED
|
@@ -6,5 +6,4 @@ export declare const getDatabase: () => Promise<{
|
|
|
6
6
|
db: ReturnType<MongoClient["db"]> | undefined;
|
|
7
7
|
}>;
|
|
8
8
|
export declare const getDatabaseSync: () => import("mongodb").Db;
|
|
9
|
-
export declare const prepareCollectionName: (collectionName: string) => string;
|
|
10
9
|
export declare const getDatabaseCollection: <TDocument extends Record<string, unknown>>(collectionName: string) => import("mongodb").Collection<PackReferences<TDocument>>;
|
package/dist/database.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getDatabaseCollection = exports.
|
|
26
|
+
exports.getDatabaseCollection = exports.getDatabaseSync = exports.getDatabase = exports.ObjectId = void 0;
|
|
27
27
|
const entrypoint_1 = require("@aeriajs/entrypoint");
|
|
28
28
|
const mongodb_1 = require("mongodb");
|
|
29
29
|
var mongodb_2 = require("mongodb");
|
|
@@ -69,22 +69,8 @@ const getDatabaseSync = () => {
|
|
|
69
69
|
return dbMemo.db;
|
|
70
70
|
};
|
|
71
71
|
exports.getDatabaseSync = getDatabaseSync;
|
|
72
|
-
const prepareCollectionName = (collectionName) => {
|
|
73
|
-
let pluralized;
|
|
74
|
-
if (collectionName.endsWith('y')) {
|
|
75
|
-
pluralized = collectionName.replace(/y$/, 'ies');
|
|
76
|
-
}
|
|
77
|
-
else if (collectionName.endsWith('s')) {
|
|
78
|
-
pluralized = `${collectionName}es`;
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
pluralized = `${collectionName}s`;
|
|
82
|
-
}
|
|
83
|
-
return pluralized.toLowerCase();
|
|
84
|
-
};
|
|
85
|
-
exports.prepareCollectionName = prepareCollectionName;
|
|
86
72
|
const getDatabaseCollection = (collectionName) => {
|
|
87
73
|
const db = (0, exports.getDatabaseSync)();
|
|
88
|
-
return db.collection(
|
|
74
|
+
return db.collection(collectionName);
|
|
89
75
|
};
|
|
90
76
|
exports.getDatabaseCollection = getDatabaseCollection;
|
package/dist/database.mjs
CHANGED
|
@@ -42,18 +42,7 @@ export const getDatabaseSync = () => {
|
|
|
42
42
|
}
|
|
43
43
|
return dbMemo.db;
|
|
44
44
|
};
|
|
45
|
-
export const prepareCollectionName = (collectionName) => {
|
|
46
|
-
let pluralized;
|
|
47
|
-
if (collectionName.endsWith("y")) {
|
|
48
|
-
pluralized = collectionName.replace(/y$/, "ies");
|
|
49
|
-
} else if (collectionName.endsWith("s")) {
|
|
50
|
-
pluralized = `${collectionName}es`;
|
|
51
|
-
} else {
|
|
52
|
-
pluralized = `${collectionName}s`;
|
|
53
|
-
}
|
|
54
|
-
return pluralized.toLowerCase();
|
|
55
|
-
};
|
|
56
45
|
export const getDatabaseCollection = (collectionName) => {
|
|
57
46
|
const db = getDatabaseSync();
|
|
58
|
-
return db.collection(
|
|
47
|
+
return db.collection(collectionName);
|
|
59
48
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.168",
|
|
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.
|
|
45
|
+
"@aeriajs/builtins": "^0.0.168",
|
|
46
|
+
"@aeriajs/common": "^0.0.103",
|
|
47
|
+
"@aeriajs/entrypoint": "^0.0.105",
|
|
48
|
+
"@aeriajs/http": "^0.0.116",
|
|
49
|
+
"@aeriajs/security": "^0.0.168",
|
|
50
50
|
"@aeriajs/types": "^0.0.87",
|
|
51
|
-
"@aeriajs/validation": "^0.0.
|
|
51
|
+
"@aeriajs/validation": "^0.0.106"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"mongodb": "^6.5.0",
|