@aeriajs/core 0.0.115 → 0.0.117
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.d.ts +3 -3
- package/dist/collection/define.d.ts +2 -9
- package/dist/collection/preload.d.ts +1 -2
- package/dist/collection/reference.d.ts +2 -2
- package/dist/collection/traverseDocument.js +32 -25
- package/dist/collection/traverseDocument.mjs +30 -23
- package/dist/database.d.ts +1 -1
- package/dist/functions/builtin/count.d.ts +1 -1
- package/dist/functions/builtin/get.d.ts +1 -1
- package/dist/functions/builtin/getAll.d.ts +1 -1
- package/dist/functions/builtin/insert.d.ts +1 -1
- package/dist/functions/builtin/remove.d.ts +1 -1
- package/package.json +3 -3
package/dist/assets.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Context, Collection, Token } from '@aeriajs/types';
|
|
1
|
+
import type { AssetType, Context, Collection, Token } from '@aeriajs/types';
|
|
2
2
|
import { ACError } from '@aeriajs/types';
|
|
3
|
-
export declare const internalGetCollectionAsset: <TCollectionName extends string, TAssetName extends
|
|
3
|
+
export declare const internalGetCollectionAsset: <TCollectionName extends string, TAssetName extends keyof Collections[TCollectionName] & AssetType>(collectionName: TCollectionName, assetName: TAssetName) => Promise<{
|
|
4
4
|
readonly _tag: "Error";
|
|
5
5
|
readonly error: ACError.ResourceNotFound;
|
|
6
6
|
readonly result: undefined;
|
|
@@ -9,7 +9,7 @@ export declare const internalGetCollectionAsset: <TCollectionName extends string
|
|
|
9
9
|
readonly error: undefined;
|
|
10
10
|
readonly result: NonNullable<Collection[TAssetName]>;
|
|
11
11
|
}>;
|
|
12
|
-
export declare const getCollectionAsset: <TCollectionName extends string, TAssetName extends
|
|
12
|
+
export declare const getCollectionAsset: <TCollectionName extends string, TAssetName extends keyof Collections[TCollectionName] & AssetType>(collectionName: TCollectionName, assetName: TAssetName) => Promise<{
|
|
13
13
|
readonly _tag: "Error";
|
|
14
14
|
readonly error: ACError.ResourceNotFound;
|
|
15
15
|
readonly result: undefined;
|
|
@@ -2,7 +2,7 @@ import type { SchemaWithId, Collection, StrictContext, Contract, ContractToFunct
|
|
|
2
2
|
export type ExtendCollection<TLeftCollection extends Collection, TRightCollection> = Omit<TLeftCollection & TRightCollection, 'item'> & {
|
|
3
3
|
item: SchemaWithId<(TLeftCollection & TRightCollection)['description']>;
|
|
4
4
|
};
|
|
5
|
-
export declare const defineCollection: <TCollection extends
|
|
5
|
+
export declare const defineCollection: <TCollection extends Collection<TCollection extends Collection ? TCollection : never> extends infer Coll ? Omit<Coll, "item" | "description" | "functions" | "exposedFunctions" | "security"> : never, const TDescription extends Description<TDescription>, const TContracts extends { [P in keyof TFunctions]?: Contract; }, const TExposedFunctions extends Partial<Record<keyof TFunctions, AccessCondition>>, const TFunctions extends Record<string, (payload: any, context: StrictContext<any>) => any> & { [P in keyof TContracts | keyof TExposedFunctions]: ContractToFunction<P extends keyof TContracts ? NonNullable<TContracts[P]> : any, StrictContext<P extends keyof TExposedFunctions ? RoleFromAccessCondition<TExposedFunctions[P]> : never, TDescription>>; }>(collection: TCollection & {
|
|
6
6
|
description: TDescription;
|
|
7
7
|
functions?: TFunctions;
|
|
8
8
|
contracts?: TContracts;
|
|
@@ -16,11 +16,4 @@ export declare const defineCollection: <TCollection extends Omit<Collection<TCol
|
|
|
16
16
|
functions: TFunctions;
|
|
17
17
|
contracts: TContracts;
|
|
18
18
|
};
|
|
19
|
-
export declare const extendCollection: <const TLeftCollection extends Collection, const TRightCollection extends {
|
|
20
|
-
description?: Partial<Description> | undefined;
|
|
21
|
-
item?: Partial<any> | undefined;
|
|
22
|
-
security?: Partial<CollectionSecurityPolicy<any> | undefined>;
|
|
23
|
-
functions?: Partial<Record<string, (payload: any, context: import("@aeriajs/types").Context<any>, ...args: any[]) => any> | undefined>;
|
|
24
|
-
contracts?: Partial<Record<string, Contract> | undefined>;
|
|
25
|
-
exposedFunctions?: Partial<Record<string, AccessCondition> | undefined>;
|
|
26
|
-
}>(left: TLeftCollection, right: TRightCollection) => ExtendCollection<TLeftCollection, TRightCollection>;
|
|
19
|
+
export declare const extendCollection: <const TLeftCollection extends Collection, const TRightCollection extends { [P in keyof Collection]?: Partial<Collection[P]>; }>(left: TLeftCollection, right: TRightCollection) => ExtendCollection<TLeftCollection, TRightCollection>;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import type { Description, Property } from '@aeriajs/types';
|
|
3
2
|
import * as presets from '../presets/index.js';
|
|
4
3
|
export type PreloadOptions = {
|
|
@@ -6,7 +5,7 @@ export type PreloadOptions = {
|
|
|
6
5
|
memoize?: boolean;
|
|
7
6
|
timestamps?: boolean;
|
|
8
7
|
};
|
|
9
|
-
export declare const applyPreset: (entry: Partial<Description> | Description[
|
|
8
|
+
export declare const applyPreset: (entry: Partial<Description> | Description["properties"], presetName: keyof typeof presets, parentName?: string) => (Record<string, Property> | Partial<Description>) & ({
|
|
10
9
|
readonly actions: {
|
|
11
10
|
readonly removeAll: {
|
|
12
11
|
readonly label: "action.removeAll";
|
|
@@ -19,6 +19,6 @@ export type BuildLookupOptions = {
|
|
|
19
19
|
memoize?: string;
|
|
20
20
|
project?: string[];
|
|
21
21
|
};
|
|
22
|
-
export declare const getReferences: (properties: FixedObjectProperty[
|
|
22
|
+
export declare const getReferences: (properties: FixedObjectProperty["properties"], options?: GetReferenceOptions) => Promise<{}>;
|
|
23
23
|
export declare const buildLookupPipeline: (referenceMap: ReferenceMap | {}, options: BuildLookupOptions) => Promise<any[]>;
|
|
24
|
-
export declare const getLookupPipeline: (description: Description, _options?: Omit<BuildLookupOptions,
|
|
24
|
+
export declare const getLookupPipeline: (description: Description, _options?: Omit<BuildLookupOptions, "properties">) => Promise<any[]>;
|
|
@@ -269,41 +269,48 @@ const recurse = async (target, ctx) => {
|
|
|
269
269
|
]);
|
|
270
270
|
continue;
|
|
271
271
|
}
|
|
272
|
-
if (!property
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
if (
|
|
277
|
-
|
|
272
|
+
if (!property) {
|
|
273
|
+
if (value && (value.constructor === Object || value.constructor === Array)) {
|
|
274
|
+
// if first propName is preceded by '$' we assume
|
|
275
|
+
// it contains MongoDB query operators
|
|
276
|
+
if (Object.keys(value)[0]?.startsWith('$')) {
|
|
277
|
+
if (!ctx.options.allowOperators) {
|
|
278
|
+
return types_1.Result.error(types_1.ACError.InsecureOperator);
|
|
279
|
+
}
|
|
280
|
+
entries.push([
|
|
281
|
+
propName,
|
|
282
|
+
value,
|
|
283
|
+
]);
|
|
284
|
+
continue;
|
|
278
285
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
value
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
for (const operation of value) {
|
|
288
|
-
const { error, result } = await recurse(operation, ctx);
|
|
289
|
-
if (error) {
|
|
290
|
-
return types_1.Result.error(error);
|
|
286
|
+
if (Array.isArray(value)) {
|
|
287
|
+
const operations = [];
|
|
288
|
+
for (const operation of value) {
|
|
289
|
+
const { error, result } = await recurse(operation, ctx);
|
|
290
|
+
if (error) {
|
|
291
|
+
return types_1.Result.error(error);
|
|
292
|
+
}
|
|
293
|
+
operations.push(result);
|
|
291
294
|
}
|
|
292
|
-
|
|
295
|
+
entries.push([
|
|
296
|
+
propName,
|
|
297
|
+
operations,
|
|
298
|
+
]);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const { error, result: operator } = await recurse(value, ctx);
|
|
302
|
+
if (error) {
|
|
303
|
+
return types_1.Result.error(error);
|
|
293
304
|
}
|
|
294
305
|
entries.push([
|
|
295
306
|
propName,
|
|
296
|
-
|
|
307
|
+
operator,
|
|
297
308
|
]);
|
|
298
309
|
continue;
|
|
299
310
|
}
|
|
300
|
-
const { error, result: operator } = await recurse(value, ctx);
|
|
301
|
-
if (error) {
|
|
302
|
-
return types_1.Result.error(error);
|
|
303
|
-
}
|
|
304
311
|
entries.push([
|
|
305
312
|
propName,
|
|
306
|
-
|
|
313
|
+
value,
|
|
307
314
|
]);
|
|
308
315
|
}
|
|
309
316
|
if (property) {
|
|
@@ -233,39 +233,46 @@ const recurse = async (target, ctx) => {
|
|
|
233
233
|
]);
|
|
234
234
|
continue;
|
|
235
235
|
}
|
|
236
|
-
if (!property
|
|
237
|
-
if (Object.
|
|
238
|
-
if (
|
|
239
|
-
|
|
236
|
+
if (!property) {
|
|
237
|
+
if (value && (value.constructor === Object || value.constructor === Array)) {
|
|
238
|
+
if (Object.keys(value)[0]?.startsWith("$")) {
|
|
239
|
+
if (!ctx.options.allowOperators) {
|
|
240
|
+
return Result.error(ACError.InsecureOperator);
|
|
241
|
+
}
|
|
242
|
+
entries.push([
|
|
243
|
+
propName,
|
|
244
|
+
value
|
|
245
|
+
]);
|
|
246
|
+
continue;
|
|
240
247
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
value
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
for (const operation of value) {
|
|
250
|
-
const { error: error2, result } = await recurse(operation, ctx);
|
|
251
|
-
if (error2) {
|
|
252
|
-
return Result.error(error2);
|
|
248
|
+
if (Array.isArray(value)) {
|
|
249
|
+
const operations = [];
|
|
250
|
+
for (const operation of value) {
|
|
251
|
+
const { error: error2, result } = await recurse(operation, ctx);
|
|
252
|
+
if (error2) {
|
|
253
|
+
return Result.error(error2);
|
|
254
|
+
}
|
|
255
|
+
operations.push(result);
|
|
253
256
|
}
|
|
254
|
-
|
|
257
|
+
entries.push([
|
|
258
|
+
propName,
|
|
259
|
+
operations
|
|
260
|
+
]);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const { error, result: operator } = await recurse(value, ctx);
|
|
264
|
+
if (error) {
|
|
265
|
+
return Result.error(error);
|
|
255
266
|
}
|
|
256
267
|
entries.push([
|
|
257
268
|
propName,
|
|
258
|
-
|
|
269
|
+
operator
|
|
259
270
|
]);
|
|
260
271
|
continue;
|
|
261
272
|
}
|
|
262
|
-
const { error, result: operator } = await recurse(value, ctx);
|
|
263
|
-
if (error) {
|
|
264
|
-
return Result.error(error);
|
|
265
|
-
}
|
|
266
273
|
entries.push([
|
|
267
274
|
propName,
|
|
268
|
-
|
|
275
|
+
value
|
|
269
276
|
]);
|
|
270
277
|
}
|
|
271
278
|
if (property) {
|
package/dist/database.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { MongoClient } from 'mongodb';
|
|
|
3
3
|
export { ObjectId, } from 'mongodb';
|
|
4
4
|
export declare const getDatabase: () => Promise<{
|
|
5
5
|
client: MongoClient;
|
|
6
|
-
db: ReturnType<MongoClient[
|
|
6
|
+
db: ReturnType<MongoClient["db"]> | undefined;
|
|
7
7
|
}>;
|
|
8
8
|
export declare const getDatabaseSync: () => import("mongodb").Db;
|
|
9
9
|
export declare const prepareCollectionName: (collectionName: string) => string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, CountPayload } from '@aeriajs/types';
|
|
2
|
-
export declare const count: <TContext extends Context>(payload: CountPayload<SchemaWithId<
|
|
2
|
+
export declare const count: <TContext extends Context>(payload: CountPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context<any> ? TContext : never) => Promise<{
|
|
3
3
|
readonly _tag: "Result";
|
|
4
4
|
readonly error: undefined;
|
|
5
5
|
readonly result: any;
|
|
@@ -2,4 +2,4 @@ import type { Context, SchemaWithId, GetPayload, GetReturnType } from '@aeriajs/
|
|
|
2
2
|
export type GetOptions = {
|
|
3
3
|
bypassSecurity?: boolean;
|
|
4
4
|
};
|
|
5
|
-
export declare const get: <TContext extends Context>(payload: GetPayload<SchemaWithId<TContext[
|
|
5
|
+
export declare const get: <TContext extends Context>(payload: GetPayload<SchemaWithId<TContext["description"]>>, context: TContext extends Context<any> ? TContext : never, options?: GetOptions) => Promise<GetReturnType<TContext["description"]>>;
|
|
@@ -2,7 +2,7 @@ import type { Context, SchemaWithId, GetAllPayload } from '@aeriajs/types';
|
|
|
2
2
|
export type GetAllOptions = {
|
|
3
3
|
bypassSecurity?: boolean;
|
|
4
4
|
};
|
|
5
|
-
export declare const getAll: <TContext extends Context>(_payload: GetAllPayload<SchemaWithId<
|
|
5
|
+
export declare const getAll: <TContext extends Context>(_payload: GetAllPayload<SchemaWithId<TContext["description"]>> | undefined, context: TContext, options?: GetAllOptions) => Promise<{
|
|
6
6
|
readonly _tag: "Result";
|
|
7
7
|
readonly error: undefined;
|
|
8
8
|
readonly result: SchemaWithId<TContext["description"]>[];
|
|
@@ -33,4 +33,4 @@ export declare const insertErrorSchema: () => {
|
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
35
|
};
|
|
36
|
-
export declare const insert: <TContext extends Context>(payload: InsertPayload<SchemaWithId<TContext[
|
|
36
|
+
export declare const insert: <TContext extends Context>(payload: InsertPayload<SchemaWithId<TContext["description"]>>, context: TContext, options?: InsertOptions) => Promise<InsertReturnType<SchemaWithId<TContext["description"]>>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Context, SchemaWithId, RemovePayload } from '@aeriajs/types';
|
|
2
2
|
import { Result, HTTPStatus, ACError } from '@aeriajs/types';
|
|
3
|
-
export declare const remove: <TContext extends Context>(payload: RemovePayload<SchemaWithId<TContext[
|
|
3
|
+
export declare const remove: <TContext extends Context>(payload: RemovePayload<SchemaWithId<TContext["description"]>>, context: TContext) => Promise<Result.Error<{
|
|
4
4
|
readonly code: ACError.ResourceNotFound;
|
|
5
5
|
} & {
|
|
6
6
|
httpStatus: HTTPStatus.NotFound;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aeriajs/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.117",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"mongodb-memory-server": "^9.2.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
|
-
"@aeriajs/builtins": "^0.0.
|
|
44
|
+
"@aeriajs/builtins": "^0.0.117",
|
|
45
45
|
"@aeriajs/common": "^0.0.74",
|
|
46
46
|
"@aeriajs/entrypoint": "^0.0.76",
|
|
47
47
|
"@aeriajs/http": "^0.0.85",
|
|
48
|
-
"@aeriajs/security": "^0.0.
|
|
48
|
+
"@aeriajs/security": "^0.0.117",
|
|
49
49
|
"@aeriajs/types": "^0.0.64",
|
|
50
50
|
"@aeriajs/validation": "^0.0.77"
|
|
51
51
|
},
|